Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
* posting-styles and bbdb "from"
@ 2009-02-11 20:45 Richard Riley
  2009-02-12 13:19 ` David
       [not found] ` <mailman.549.1234444786.31690.info-gnus-english@gnu.org>
  0 siblings, 2 replies; 7+ messages in thread
From: Richard Riley @ 2009-02-11 20:45 UTC (permalink / raw)
  To: info-gnus-english


I was wondering if anyone has a solution for setting the
gnus-posting-style address based on a "email-from" field or similar on a
contacts bbdb record?

e.g

I use profile A for email C1, and profile B for emailing C2.


-- 
 important and urgent problems of the technology of today are no longer the satisfactions of the primary needs or of archetypal wishes, but the reparation of the evils and damages by the technology of yesterday.  ~Dennis Gabor, Innovations:  Scientific, Technological and Social, 1970

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: posting-styles and bbdb "from"
  2009-02-11 20:45 posting-styles and bbdb "from" Richard Riley
@ 2009-02-12 13:19 ` David
       [not found] ` <mailman.549.1234444786.31690.info-gnus-english@gnu.org>
  1 sibling, 0 replies; 7+ messages in thread
From: David @ 2009-02-12 13:19 UTC (permalink / raw)
  To: info-gnus-english

Richard Riley <rileyrgdev@gmail.com> writes:
> I was wondering if anyone has a solution for setting the
> gnus-posting-style address based on a "email-from" field or similar on a
> contacts bbdb record?

Put the following function in your .gnus:

(defun DE-bbdb-match-field-recipient (field regexp)
  "Match FIELD for recipient against REGEXP.
FIELD must be a symbol, e.g. 'gnus-private."
  (let (who rec)
    (when (and
	   (gnus-buffer-live-p gnus-article-copy)
	   (setq who
		 (with-current-buffer gnus-article-copy
		   (save-restriction
		     (nnheader-narrow-to-headers)
		     (or (message-fetch-field "reply-to")
			 (message-fetch-field "from")))))
	   (setq rec
		 (bbdb-search-simple
		  nil
		  (cadr (gnus-extract-address-components who)))))
      (string-match regexp (bbdb-get-field rec field)))))

Then you can use this function in gnus-posting-styles as follows:

(setq gnus-posting-styles
      '(
	((DE-bbdb-match-field-recipient 'gnus-private "work")
	 (signature-file "~/work-sig.txt")
	 (address "address@work"))
	((DE-bbdb-match-field-recipient 'gnus-private "other")
	 (signature-file "~/other-sig.txt")
	 (address "address@other"))
         ;; default rule
	((DE-bbdb-match-field-recipient 'gnus-private "")
	 (address "address@default"))))

I use the 'gnus-private field, since I also do mail splitting via BBDB,
but you can use any field you want, of course.

-David

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: posting-styles and bbdb "from"
       [not found] ` <mailman.549.1234444786.31690.info-gnus-english@gnu.org>
@ 2009-02-12 15:43   ` Richard Riley
  2009-02-12 17:13     ` Richard Riley
                       ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Richard Riley @ 2009-02-12 15:43 UTC (permalink / raw)
  To: info-gnus-english

David <de_bb@arcor.de> writes:

> Richard Riley <rileyrgdev@gmail.com> writes:
>> I was wondering if anyone has a solution for setting the
>> gnus-posting-style address based on a "email-from" field or similar on a
>> contacts bbdb record?
>
> Put the following function in your .gnus:

Hi David,

I got it going. Great. I did have to define my own symbol though e.g

(setq email-type (make-symbol "email-type"))

Now, the question I have, having checked the posting styles manual, is
how best to optimise something like this?


(setq gnus-posting-styles
      `(
	(,(rx(or "DevelopmentEmail" "emacs" ))
	 (name "Richard Riley")
	 (address "rileyrgdev@googlemail.com")
	 (from "Richard Riley <rileyrgdev@gmail.com>")
	 )
	((DE-bbdb-match-field-recipient 'email-type "dev")
	 (name "Richard Riley")
	 (address "rileyrgdev@googlemail.com")
	 (from "Richard Riley <rileyrgdev@gmail.com>")
	 )))

I understand that the first clause ",(rx.." produces a match string
(regexp) which is later evaluated against the group name. The second
searches for the email-type field and matches it is type "dev".

But how could I combine them so as not to have to repeat the other
forms?

regards

r.

	


>
> (defun DE-bbdb-match-field-recipient (field regexp)
>   "Match FIELD for recipient against REGEXP.
> FIELD must be a symbol, e.g. 'gnus-private."
>   (let (who rec)
>     (when (and
> 	   (gnus-buffer-live-p gnus-article-copy)
> 	   (setq who
> 		 (with-current-buffer gnus-article-copy
> 		   (save-restriction
> 		     (nnheader-narrow-to-headers)
> 		     (or (message-fetch-field "reply-to")
> 			 (message-fetch-field "from")))))
> 	   (setq rec
> 		 (bbdb-search-simple
> 		  nil
> 		  (cadr (gnus-extract-address-components who)))))
>       (string-match regexp (bbdb-get-field rec field)))))
>
> Then you can use this function in gnus-posting-styles as follows:
>
> (setq gnus-posting-styles
>       '(
> 	((DE-bbdb-match-field-recipient 'gnus-private "work")
> 	 (signature-file "~/work-sig.txt")
> 	 (address "address@work"))
> 	((DE-bbdb-match-field-recipient 'gnus-private "other")
> 	 (signature-file "~/other-sig.txt")
> 	 (address "address@other"))
>          ;; default rule
> 	((DE-bbdb-match-field-recipient 'gnus-private "")
> 	 (address "address@default"))))
>
> I use the 'gnus-private field, since I also do mail splitting via BBDB,
> but you can use any field you want, of course.
>
> -David
>
>
>

-- 
 important and urgent problems of the technology of today are no longer the satisfactions of the primary needs or of archetypal wishes, but the reparation of the evils and damages by the technology of yesterday.  ~Dennis Gabor, Innovations:  Scientific, Technological and Social, 1970

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: posting-styles and bbdb "from"
  2009-02-12 15:43   ` Richard Riley
@ 2009-02-12 17:13     ` Richard Riley
  2009-02-12 22:56       ` David
  2009-02-12 17:43     ` David
       [not found]     ` <mailman.572.1234460598.31690.info-gnus-english@gnu.org>
  2 siblings, 1 reply; 7+ messages in thread
From: Richard Riley @ 2009-02-12 17:13 UTC (permalink / raw)
  To: info-gnus-english


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?

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: posting-styles and bbdb "from"
  2009-02-12 15:43   ` Richard Riley
  2009-02-12 17:13     ` Richard Riley
@ 2009-02-12 17:43     ` David
       [not found]     ` <mailman.572.1234460598.31690.info-gnus-english@gnu.org>
  2 siblings, 0 replies; 7+ messages in thread
From: David @ 2009-02-12 17:43 UTC (permalink / raw)
  To: info-gnus-english

Richard Riley <rileyrgdev@gmail.com> writes:
> David <de_bb@arcor.de> writes:
>> Richard Riley <rileyrgdev@gmail.com> writes:
>>> I was wondering if anyone has a solution for setting the
>>> gnus-posting-style address based on a "email-from" field or similar on a
>>> contacts bbdb record?
>>
>> Put the following function in your .gnus:
>
> Hi David,
>
> I got it going. Great. I did have to define my own symbol though e.g
>
> (setq email-type (make-symbol "email-type"))

I don't understand why this would be necessary. What kind of error do
you get when you omit this? 

You have to create the field in the BBDB, of course.

> I understand that the first clause ",(rx.." produces a match string
> (regexp) which is later evaluated against the group name. The second
> searches for the email-type field and matches it is type "dev".
>
> But how could I combine them so as not to have to repeat the other
> forms?

You could try something like (untested)

(setq gnus-posting-styles
      '(
        ((or (string-match (rx (or "DevelopmentEmail" "emacs" ))
                            gnus-newsgroup-name)
	     (DE-bbdb-match-field-recipient 'email-type "GWDG"))
	  (name "Richard Riley")
          (address "rileyrgdev@googlemail.com")
          (from "Richard Riley <rileyrgdev@gmail.com>"))))

-David

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: posting-styles and bbdb "from"
  2009-02-12 17:13     ` Richard Riley
@ 2009-02-12 22:56       ` David
  0 siblings, 0 replies; 7+ messages in thread
From: David @ 2009-02-12 22:56 UTC (permalink / raw)
  To: info-gnus-english

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: posting-styles and bbdb "from"
       [not found]     ` <mailman.572.1234460598.31690.info-gnus-english@gnu.org>
@ 2009-02-13  4:28       ` Richard Riley
  0 siblings, 0 replies; 7+ messages in thread
From: Richard Riley @ 2009-02-13  4:28 UTC (permalink / raw)
  To: info-gnus-english

David <de_bb@arcor.de> writes:

> Richard Riley <rileyrgdev@gmail.com> writes:
>> David <de_bb@arcor.de> writes:
>>> Richard Riley <rileyrgdev@gmail.com> writes:
>>>> I was wondering if anyone has a solution for setting the
>>>> gnus-posting-style address based on a "email-from" field or similar on a
>>>> contacts bbdb record?
>>>
>>> Put the following function in your .gnus:
>>
>> Hi David,
>>
>> I got it going. Great. I did have to define my own symbol though e.g
>>
>> (setq email-type (make-symbol "email-type"))
>
> I don't understand why this would be necessary. What kind of error do
> you get when you omit this? 
>
> You have to create the field in the BBDB, of course.

Yup, something else must have been up - I removed it and it all works fine.

>
>> I understand that the first clause ",(rx.." produces a match string
>> (regexp) which is later evaluated against the group name. The second
>> searches for the email-type field and matches it is type "dev".
>>
>> But how could I combine them so as not to have to repeat the other
>> forms?
>
> You could try something like (untested)
>
> (setq gnus-posting-styles
>       '(
>         ((or (string-match (rx (or "DevelopmentEmail" "emacs" ))
>                             gnus-newsgroup-name)
> 	     (DE-bbdb-match-field-recipient 'email-type "GWDG"))
> 	  (name "Richard Riley")
>           (address "rileyrgdev@googlemail.com")
>           (from "Richard Riley <rileyrgdev@gmail.com>"))))
>
> -David

Great - works wonderfully.

many thanks,

r.


-- 
 important and urgent problems of the technology of today are no longer the satisfactions of the primary needs or of archetypal wishes, but the reparation of the evils and damages by the technology of yesterday.  ~Dennis Gabor, Innovations:  Scientific, Technological and Social, 1970

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2009-02-13  4:28 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-02-11 20:45 posting-styles and bbdb "from" Richard Riley
2009-02-12 13:19 ` David
     [not found] ` <mailman.549.1234444786.31690.info-gnus-english@gnu.org>
2009-02-12 15:43   ` Richard Riley
2009-02-12 17:13     ` Richard Riley
2009-02-12 22:56       ` David
2009-02-12 17:43     ` David
     [not found]     ` <mailman.572.1234460598.31690.info-gnus-english@gnu.org>
2009-02-13  4:28       ` Richard Riley

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).