Subject: Re: bug#22720: 25.0.91; url/eww: add function to delete all cookies

From: Michael Heerdegen <[email-masked]>
Date: Mon, 22 Feb 2016 13:52:21 +0100

Lars Ingebrigtsen <[email-masked]> writes:

> Oh, I see.  I've now added this to the trunk:
> `url-cookie-delete-cookies'.

Thanks!

I guess it would also make sense to be able to keep cookies with
matching domain name.  I tweaked your defun a bit:

#+begin_src emacs-lisp
(defun url-cookie-delete-cookies (&optional regexp keep)
  "Delete all cookies from the cookie store where the domain matches REGEXP.
If REGEXP is nil, all cookies are deleted.
If KEEP is non-nil, delete all cookies where the domain does not
match REGEXP."
  (dolist (variable '(url-cookie-secure-storage url-cookie-storage))
    (if (not regexp)
        (set variable nil)
      (let ((cookies (symbol-value variable))
            (pred (if keep
                      (lambda (cookie) (not (string-match-p regexp (car cookie))))
                    (lambda (cookie) (string-match-p regexp (car cookie))))))
        (dolist (elem cookies)
          (when (funcall pred elem)
            (setq cookies (delq elem cookies))))
        (set variable cookies))))
  (setq url-cookies-changed-since-last-save t)
  (url-cookie-write-file))
#+end_src

WDYT?

Regards,

Michael.