summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--doc/misc/url.texi6
-rw-r--r--etc/NEWS5
-rw-r--r--lisp/url/url-cookie.el13
3 files changed, 24 insertions, 0 deletions
diff --git a/doc/misc/url.texi b/doc/misc/url.texi
index c46859968a..14a4c96cc4 100644
--- a/doc/misc/url.texi
+++ b/doc/misc/url.texi
@@ -417,6 +417,12 @@ cookies, if there are any. You can remove a cookie using the
@kbd{C-k} (@code{url-cookie-delete}) command.
@end defun
+@defun url-cookie-delete-cookies &optional regexp
+This function takes a regular expression as its parameters and deletes
+all cookies from that domain. If @var{regexp} is @code{nil}, delete
+all cookies.
+@end defun
+
@defopt url-cookie-file
The file in which cookies are stored, defaulting to @file{cookies} in
the directory specified by @code{url-configuration-directory}.
diff --git a/etc/NEWS b/etc/NEWS
index 9f0fb8d694..bad9519188 100644
--- a/etc/NEWS
+++ b/etc/NEWS
@@ -1040,6 +1040,11 @@ we should not be queried about things like TLS certificate validity.
plist will contain a :peer element that has the output of
`gnutls-peer-status' (if Emacs is built with GnuTLS support).
++++
+*** The new function `url-cookie-delete-cookie' can be used to
+programmatically delete all cookies, or cookies from a specific
+domain.
+
** Tramp
+++
diff --git a/lisp/url/url-cookie.el b/lisp/url/url-cookie.el
index 4c7366adc8..a4b7a58fdf 100644
--- a/lisp/url/url-cookie.el
+++ b/lisp/url/url-cookie.el
@@ -353,6 +353,19 @@ to run the `url-cookie-setup-save-timer' function manually."
url-cookie-save-interval
#'url-cookie-write-file))))
+(defun url-cookie-delete-cookies (&optional regexp)
+ "Delete all cookies from the cookie store where the domain matches REGEXP.
+If REGEXP is nil, all cookies are deleted."
+ (dolist (variable '(url-cookie-secure-storage url-cookie-storage))
+ (let ((cookies (symbol-value variable)))
+ (dolist (elem cookies)
+ (when (or (null regexp)
+ (string-match regexp (car elem)))
+ (setq cookies (delq elem cookies))))
+ (set variable cookies)))
+ (setq url-cookies-changed-since-last-save t)
+ (url-cookie-write-file))
+
;;; Mode for listing and editing cookies.
(defun url-cookie-list ()