[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Automatically "Unsubscribed list post" in certain groups
From: |
Teemu Likonen |
Subject: |
Re: Automatically "Unsubscribed list post" in certain groups |
Date: |
Tue, 05 Apr 2011 21:02:43 +0300 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.2 (gnu/linux) |
* 2011-04-05T18:34:33+03:00 * Teemu Likonen wrote:
> There are certain groups in which I want to have C-c C-f C-a
> (message-generate-unsubscribed-mail-followup-to) executed
> automatically when composing a new post or a reply.
>
> I know that there are a number of hooks for message-mode. I could hack a
> hook function to automatically parse the headers and detect if the
> message is going to certain mailing list. If so, it would call
> message-generate-unsubscribed-mail-followup-to function.
>
> But is there already a framework for this kind of things?
OK, I don't know it there is a better built-in way but I implemented the
solution I described above. This checks if any item in a regexp list
matches to any of the To or Cc addresses. If yes, it generates an
unsubscribed M-F-T field.
(add-hook 'message-setup-hook #'tl-mail-followup-to)
(defun tl-mail-followup-to ()
(save-excursion
(goto-char (point-min))
(let ((mailing-lists '("some@mailing\\.list\\.org"
"other@list\\.com")))
(catch 'quit
(dolist (target (tl-gnus-list-target-addresses))
(dolist (ml mailing-lists)
(when (string-match ml target)
(message-generate-unsubscribed-mail-followup-to t)
(throw 'quit t))))))))
(defun tl-gnus-list-target-addresses ()
"Return all To and Cc addresses from the current buffer."
(save-excursion
(goto-char (point-min))
(let* ((header-alist (mail-header-extract-no-properties))
(to (mail-extract-address-components
(or (cdr (assq 'to header-alist)) "") t))
(cc (mail-extract-address-components
(or (cdr (assq 'cc header-alist)) "") t)))
(mapcar #'cadr (append to cc)))))