Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
* How to parse "To" and "Cc" headers?
@ 2009-01-29 20:41 Teemu Likonen
  2009-01-29 22:16 ` Cor
  0 siblings, 1 reply; 7+ messages in thread
From: Teemu Likonen @ 2009-01-29 20:41 UTC (permalink / raw)
  To: info-gnus-english

Is there a function in Gnus (or elsewhere in Emacs) for parsing "To" and
"Cc" headers in the buffer?

My goal is to make my custom message-citation-line-function use Finnish
or English/international citation line depending on the recipient
addresses of the message.

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

* Re: How to parse "To" and "Cc" headers?
  2009-01-29 20:41 How to parse "To" and "Cc" headers? Teemu Likonen
@ 2009-01-29 22:16 ` Cor
  2009-01-30  6:26   ` Teemu Likonen
  0 siblings, 1 reply; 7+ messages in thread
From: Cor @ 2009-01-29 22:16 UTC (permalink / raw)
  To: info-gnus-english

Some entity, AKA Teemu Likonen <tlikonen@iki.fi>,
wrote this mindboggling stuff:
(selectively-snipped-or-not-p)

> Is there a function in Gnus (or elsewhere in Emacs) for parsing "To" and
> "Cc" headers in the buffer?
>
> My goal is to make my custom message-citation-line-function use Finnish
> or English/international citation line depending on the recipient
> addresses of the message.

My-cite-line function in my .gnus.el that generated the cite line above:

;(defun message-insert-citation-line ()
;  "Insert a simple citation line."
;  (when message-reply-headers
;    (insert "Some entity, AKA " (mail-header-from message-reply-headers)",
;wrote this mindboggling stuff:
;(selectively-snipped-or-not-p)\n\n")))



You could add an if clause with an regular-expression to test if there
is a .fi address or other domains//addresses to be addressed in finnish.

The cite-line-code could be change to:

;(defun message-insert-citation-line ()
;  "Insert a simple citation line."
;  (when message-reply-headers


;; The new stuff added :

   ;;; ( if (eq mail-header-from "\.fi$" (

       "if the FROM: has an .fi do  the first thing" 
   ;;; (insert "Some Finnish  " (mail-header-from message-reply-headers)",
   ;;; more Finnisch Text: \n\n")

       "else do this thing" 
   ;;; (insert "Some English   " (mail-header-from message-reply-headers)",
   ;;; more English  Text: \n\n"))))))


NOT tested, but the scratch-buffer did not complain sofar,
I know no finnish at all, but you get the idea ;-)


Cor
-- 
	The only difference between GOD and me is that GOD has mercy  
	    It is your right to restrict my rights in your house
             but if you try that in my house you could get shot 
    		        My other cheek is a .40 JHP

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

* Re: How to parse "To" and "Cc" headers?
  2009-01-29 22:16 ` Cor
@ 2009-01-30  6:26   ` Teemu Likonen
  2009-01-30 15:27     ` Ted Zlatanov
  0 siblings, 1 reply; 7+ messages in thread
From: Teemu Likonen @ 2009-01-30  6:26 UTC (permalink / raw)
  To: info-gnus-english

On 2009-01-29 22:16 (+0000), Cor wrote:

> ;;; (insert "Some Finnish  " (mail-header-from message-reply-headers)",

I'm familiar with "(mail-header-from message-reply-headers)" and I use
it for getting the person's name that I'm quoting. I was hoping for a
function which parses all the addresses in "To" and "Cc" fields because
I think the whole audience of the message matters when deciding the
language and format of the citation line.

But if there isn't such function, well, it's not a big problem. I have a
semi-automatic solution already implemented and I think my international
cite line (see above) is quite fine too.

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

* Re: How to parse "To" and "Cc" headers?
  2009-01-30  6:26   ` Teemu Likonen
@ 2009-01-30 15:27     ` Ted Zlatanov
  2009-01-31  6:09       ` Teemu Likonen
  0 siblings, 1 reply; 7+ messages in thread
From: Ted Zlatanov @ 2009-01-30 15:27 UTC (permalink / raw)
  To: info-gnus-english

On Fri, 30 Jan 2009 06:26:07 GMT Teemu Likonen <tlikonen@iki.fi> wrote: 

TL> On 2009-01-29 22:16 (+0000), Cor wrote:
>> ;;; (insert "Some Finnish  " (mail-header-from message-reply-headers)",

TL> I'm familiar with "(mail-header-from message-reply-headers)" and I use
TL> it for getting the person's name that I'm quoting. I was hoping for a
TL> function which parses all the addresses in "To" and "Cc" fields because
TL> I think the whole audience of the message matters when deciding the
TL> language and format of the citation line.

I think you want mail-extract-address-components.  It returns a list of
name-address pairs.  You know how to get the whole To: and Cc: lines, I
assume.

Ted

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

* Re: How to parse "To" and "Cc" headers?
  2009-01-30 15:27     ` Ted Zlatanov
@ 2009-01-31  6:09       ` Teemu Likonen
  2009-02-02 16:08         ` Ted Zlatanov
  0 siblings, 1 reply; 7+ messages in thread
From: Teemu Likonen @ 2009-01-31  6:09 UTC (permalink / raw)
  To: info-gnus-english

On 2009-01-30 09:27 (-0600), Ted Zlatanov wrote:

> I think you want mail-extract-address-components.  It returns a list of
> name-address pairs.  You know how to get the whole To: and Cc: lines, I
> assume.

Thanks! So to answer my original question, below is a code which returns
a list consisting strings of email addresses: ("person@somewhere"
"someoneelse@invalid" "user@isp.invalid"). The address list is
constructed from To and Cc fields.


(save-excursion
  (goto-char (point-min))
  (let (recipients
        (to-lst
         (mail-extract-address-components
          (or (cdr (assoc 'to (mail-header-extract-no-properties))) "")
          'all))
        (cc-lst
         (mail-extract-address-components
          (or (cdr (assoc 'cc (mail-header-extract-no-properties))) "")
          'all)))
    (dolist (item (append to-lst cc-lst) recipients)
      (add-to-list 'recipients
                   (nth 1 item)))))

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

* Re: How to parse "To" and "Cc" headers?
  2009-01-31  6:09       ` Teemu Likonen
@ 2009-02-02 16:08         ` Ted Zlatanov
  2009-02-03 13:11           ` Teemu Likonen
  0 siblings, 1 reply; 7+ messages in thread
From: Ted Zlatanov @ 2009-02-02 16:08 UTC (permalink / raw)
  To: info-gnus-english

On Sat, 31 Jan 2009 06:09:12 GMT Teemu Likonen <tlikonen@iki.fi> wrote: 

TL>     (dolist (item (append to-lst cc-lst) recipients)
TL>       (add-to-list 'recipients
TL>                    (nth 1 item)))))

You may be able to simplify this to just a (mapcar(append(...))) call
using `cadr'.

Ted

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

* Re: How to parse "To" and "Cc" headers?
  2009-02-02 16:08         ` Ted Zlatanov
@ 2009-02-03 13:11           ` Teemu Likonen
  0 siblings, 0 replies; 7+ messages in thread
From: Teemu Likonen @ 2009-02-03 13:11 UTC (permalink / raw)
  To: info-gnus-english

On 2009-02-02 10:08 (-0600), Ted Zlatanov wrote:

> On Sat, 31 Jan 2009 06:09:12 GMT Teemu Likonen <tlikonen@iki.fi> wrote: 
>
> TL>     (dolist (item (append to-lst cc-lst) recipients)
> TL>       (add-to-list 'recipients
> TL>                    (nth 1 item)))))
>
> You may be able to simplify this to just a (mapcar(append(...))) call
> using `cadr'.

Ah, true:

    (mapcar 'cadr (append cc-lst to-lst))

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

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

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-01-29 20:41 How to parse "To" and "Cc" headers? Teemu Likonen
2009-01-29 22:16 ` Cor
2009-01-30  6:26   ` Teemu Likonen
2009-01-30 15:27     ` Ted Zlatanov
2009-01-31  6:09       ` Teemu Likonen
2009-02-02 16:08         ` Ted Zlatanov
2009-02-03 13:11           ` Teemu Likonen

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).