info-gnus-english
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: posting-styles and bbdb "from"


From: David
Subject: Re: posting-styles and bbdb "from"
Date: Thu, 12 Feb 2009 23:56:16 +0100
User-agent: Gnus/5.110011 (No Gnus v0.11) Emacs/23.0.60 (gnu/linux)

Richard Riley <rileyrgdev@gmail.com> writes:
> Also, the next extension to this great addition would be to set the
> fields based on the "to" address when creating an email. i.e when I
> complete the "to:" field in a new email the
> DE-bbdb-match-field-recipient, or similar, is called to enable the
> initialisation of the other fields based on posting style.
>
> Is this possible?

Actually, I did a small hack for this some time ago. It's not pretty,
but it works. You would have to adapt it to your needs, though.

--8<---------------cut here---------------start------------->8---
;Automatically set From-Adress according to gnus-private in BBDB
(defun DE-message-change-from (newfrom)
  (save-excursion
    (message-position-on-field "from")
    (beginning-of-line)
    (delete-region (point) (progn (end-of-line) (point)))
    (insert "From: ") (insert newfrom)))

(defun DE-message-completion ()
    (bbdb-complete-name)
    (DE-message-change-from-with-bbdb))

(defun DE-message-change-from-with-bbdb ()
  (interactive)
  (save-excursion
    (let ((who (message-fetch-field "to")))
      (when who
        (let ((rec (bbdb-search-simple nil (cadr 
(gnus-extract-address-components who)))))
          (when rec
            (let ((gpriv (bbdb-get-field rec 'gnus-private))
                  (autocc (bbdb-get-field rec 'auto-cc)))
              (if (string-match "work" gpriv)
                  (DE-message-change-from "David <david@work>")
                (DE-message-change-from "David <david@private>"))
              (when (> (length autocc) 0)
                (message-add-header (concat "Cc: " autocc))))))))))
--8<---------------cut here---------------end--------------->8---

This function checks for the 'gnus-private field, string-matches it
against "work" and changes the From-header accordingly. It also checks
the field 'auto-cc and includes all addresses it finds there in a Cc
header (it should delete them again for following completions, but I
never got around to do that since I use that feature rarely).

You then have to use this completion function for the header fields
where it makes sense:

--8<---------------cut here---------------start------------->8---
(setq message-completion-alist
      '(
        ("^\\(Newsgroups\\|Followup-To\\|Posted-To\\|Gcc\\):" . 
message-expand-group)
        ("^\\(Resent-\\)?\\(To\\|B?Cc\\):" . DE-message-completion)
        ("^\\(Reply-To\\|From\\|Mail-Followup-To\\|Mail-Copies-To\\):" . 
message-expand-name)
        ("^\\(Disposition-Notification-To\\|Return-Receipt-To\\):" . 
message-expand-name)
        ))
--8<---------------cut here---------------end--------------->8---

-David





reply via email to

[Prev in Thread] Current Thread [Next in Thread]