Hi I know that 'mail-header-from extract information from the from field, but is there something similar for the CC field. I cannot not find anything similar. Regards Uwe Brauer
Uwe Brauer <oub@mat.ucm.es> writes:
> Hi
>
> I know that 'mail-header-from extract information from the from field,
> but is there something similar for the CC field. I cannot not find
> anything similar.
In general you can use `gnus-fetch-original-field' to get any header you
want, specified as a string. So;
(gnus-fetch-original-field "cc")
Looks like it's case-insensitive...
On Mär 12 2021, Uwe Brauer wrote:
> I know that 'mail-header-from extract information from the from field,
> but is there something similar for the CC field.
Since it is part of the extra headers, you can use mail-header-extra.
Andreas.
--
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1
"And now for something completely different."
Andreas Schwab <schwab@linux-m68k.org> writes:
> On Mär 12 2021, Uwe Brauer wrote:
>
>> I know that 'mail-header-from extract information from the from field,
>> but is there something similar for the CC field.
>
> Since it is part of the extra headers, you can use mail-header-extra.
Right, this is a useful distinction -- if you pull it out of the mail
header you can get it from the basic Summary buffer header data, without
having to load the article. `gnus-fetch-original-field' can get any
header from the article, but will always download it first.
[-- Attachment #1: Type: text/plain, Size: 910 bytes --] >>> "EA" == Eric Abrahamsen <eric@ericabrahamsen.net> writes: > Uwe Brauer <oub@mat.ucm.es> writes: >> Hi >> >> I know that 'mail-header-from extract information from the from field, >> but is there something similar for the CC field. I cannot not find >> anything similar. > In general you can use `gnus-fetch-original-field' to get any header you > want, specified as a string. So; > (gnus-fetch-original-field "cc") Great that works as expected (I use this for org-capture) So For example Cc: user1 <user1@gmail.com>, user2 <user2@gmx.net> Extracts user1 <user1@gmail.com>, user2 <user2@gmx.net> Has to be expected. Would it be possible to extract Ccname user1 ccfrom user1@gmail.com Separately. The problem however might be if there, as in the above case more than one entry, seems difficult to obtain each name and each address separately, no? Uwe [-- Attachment #2: smime.p7s --] [-- Type: application/pkcs7-signature, Size: 5673 bytes --]
>>>>> On Fri, 12 Mar 2021 22:59:44 +0100, Uwe Brauer <oub@mat.ucm.es> said:
Uwe> Cc: user1 <user1@gmail.com>, user2 <user2@gmx.net>
Uwe> Extracts user1 <user1@gmail.com>, user2 <user2@gmx.net>
Uwe> Has to be expected.
Uwe> Would it be possible to extract
Uwe> Ccname user1
Uwe> ccfrom user1@gmail.com
(mail-header-parse-addresses "user1 <user1@gmail.com>, user2 <user2@gmx.net>")
=> (("user1@gmail.com" . "user1") ("user2@gmx.net" . "user2"))
Robert
--
[-- Attachment #1: Type: text/plain, Size: 613 bytes --] >>> "EA" == Eric Abrahamsen <eric@ericabrahamsen.net> writes: > Uwe Brauer <oub@mat.ucm.es> writes: >> Hi >> >> I know that 'mail-header-from extract information from the from field, >> but is there something similar for the CC field. I cannot not find >> anything similar. > In general you can use `gnus-fetch-original-field' to get any header you > want, specified as a string. So; > (gnus-fetch-original-field "cc") That works fine for ascii, but I just got that result =?UTF-8?Q?Marta_Gonz=C3=A1lez?= <user@ucm.es> That does not happen for org-capture with %:fromname Any ideas? [-- Attachment #2: smime.p7s --] [-- Type: application/pkcs7-signature, Size: 5673 bytes --]
[-- Attachment #1: Type: text/plain, Size: 358 bytes --] >>> "AS" == Andreas Schwab <schwab@linux-m68k.org> writes: > On Mär 12 2021, Uwe Brauer wrote: >> I know that 'mail-header-from extract information from the from field, >> but is there something similar for the CC field. > Since it is part of the extra headers, you can use mail-header-extra. So the syntax would be (mail-header-extra "cc") ? [-- Attachment #2: smime.p7s --] [-- Type: application/pkcs7-signature, Size: 5673 bytes --]
Uwe Brauer <oub@mat.ucm.es> writes:
>>>> "AS" == Andreas Schwab <schwab@linux-m68k.org> writes:
>
>> On Mär 12 2021, Uwe Brauer wrote:
>>> I know that 'mail-header-from extract information from the from field,
>>> but is there something similar for the CC field.
>
>> Since it is part of the extra headers, you can use mail-header-extra.
>
> So the syntax would be (mail-header-extra "cc")
No, you need to get a handle to the appropriate header first; there's
more than one way to do that. If point is on the message in question,
you could use:
(cdr (assoc 'Cc (mail-header-extra
(gnus-number-to-header
(gnus-summary-article-number)))))
I don't think (?) there's any other sort of "header for article under
point" function.
So it's a little more code, but like I said it doesn't require
downloading and parsing the full text of the article, if that's an
issue.
Eric
Uwe Brauer <oub@mat.ucm.es> writes:
>>>> "EA" == Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> Uwe Brauer <oub@mat.ucm.es> writes:
>>> Hi
>>>
>>> I know that 'mail-header-from extract information from the from field,
>>> but is there something similar for the CC field. I cannot not find
>>> anything similar.
>
>> In general you can use `gnus-fetch-original-field' to get any header you
>> want, specified as a string. So;
>
>> (gnus-fetch-original-field "cc")
>
> That works fine for ascii, but I just got that result
>
> =?UTF-8?Q?Marta_Gonz=C3=A1lez?= <user@ucm.es>
>
> That does not happen for org-capture with %:fromname
>
> Any ideas?
(mail-decode-encoded-address-string
(gnus-fetch-original-field "cc"))
There are some other `mail-decode-encoded-*' functions for other uses.
Eric
[-- Attachment #1: Type: text/plain, Size: 1670 bytes --] >>> "EA" == Eric Abrahamsen <eric@ericabrahamsen.net> writes: > Uwe Brauer <oub@mat.ucm.es> writes: >>>>> "EA" == Eric Abrahamsen <eric@ericabrahamsen.net> writes: >> >>> Uwe Brauer <oub@mat.ucm.es> writes: >>> Hi >>> >>> I know that 'mail-header-from extract information from the from field, >>> but is there something similar for the CC field. I cannot not find >>> anything similar. >> >>> In general you can use `gnus-fetch-original-field' to get any header you >>> want, specified as a string. So; >> >>> (gnus-fetch-original-field "cc") >> >> That works fine for ascii, but I just got that result >> >> =?UTF-8?Q?Marta_Gonz=C3=A1lez?= <user@ucm.es> >> >> That does not happen for org-capture with %:fromname >> >> Any ideas? > (mail-decode-encoded-address-string > (gnus-fetch-original-field "cc")) > There are some other `mail-decode-encoded-*' functions for other uses. Thanks but it does not work Here it is what I did (defun my-extract-cc () (interactive) (mail-decode-encoded-address-string (gnus-fetch-original-field "cc"))) ("mg" "Annu:Grupos:Ejercicios" table-line (file+headline "~/ALLES/HGs/tex/vorlesungen/HGAnnu/Ejercios-Alumnos-Grupos/2021/Ejercios-Teoria21.org" "Exercicios Annu21") "| | | | | %:fromname|%:fromaddress | %:subject| %(my-extract-cc) |%^{Hoja|1|2|3|4|5|6|7}|%^{Exercicio|1|} | %a|%:date | " :prepend t :empty-lines 1 :unnarrowed t ) But then I obtained. | | | | | %![Error: (wrong-type-argument stringp nil)] |1|2 | I tried to debug the function but nothing strange happened. I am really puzzled. Uwe [-- Attachment #2: smime.p7s --] [-- Type: application/pkcs7-signature, Size: 5673 bytes --]
Uwe Brauer <oub@mat.ucm.es> writes:
>>>> "EA" == Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>
>> Uwe Brauer <oub@mat.ucm.es> writes:
>>>>>> "EA" == Eric Abrahamsen <eric@ericabrahamsen.net> writes:
>>>
>>>> Uwe Brauer <oub@mat.ucm.es> writes:
>>>> Hi
>>>>
>>>> I know that 'mail-header-from extract information from the from field,
>>>> but is there something similar for the CC field. I cannot not find
>>>> anything similar.
>>>
>>>> In general you can use `gnus-fetch-original-field' to get any header you
>>>> want, specified as a string. So;
>>>
>>>> (gnus-fetch-original-field "cc")
>>>
>>> That works fine for ascii, but I just got that result
>>>
>>> =?UTF-8?Q?Marta_Gonz=C3=A1lez?= <user@ucm.es>
>>>
>>> That does not happen for org-capture with %:fromname
>>>
>>> Any ideas?
>
>> (mail-decode-encoded-address-string
>> (gnus-fetch-original-field "cc"))
>
>> There are some other `mail-decode-encoded-*' functions for other uses.
>
>
> Thanks but it does not work
>
> Here it is what I did
>
>
> (defun my-extract-cc ()
> (interactive)
> (mail-decode-encoded-address-string
> (gnus-fetch-original-field "cc")))
> ("mg" "Annu:Grupos:Ejercicios"
> table-line (file+headline "~/ALLES/HGs/tex/vorlesungen/HGAnnu/Ejercios-Alumnos-Grupos/2021/Ejercios-Teoria21.org" "Exercicios Annu21")
> "| | | | | %:fromname|%:fromaddress | %:subject| %(my-extract-cc) |%^{Hoja|1|2|3|4|5|6|7}|%^{Exercicio|1|} | %a|%:date | " :prepend t :empty-lines 1 :unnarrowed t
> )
>
>
> But then I obtained.
>
>
> | | | | | %![Error: (wrong-type-argument stringp nil)] |1|2 |
>
>
> I tried to debug the function but nothing strange happened. I am really
> puzzled.
Looks like the %(expr) escapes are evaluated in the *Capture* buffer,
not the buffer where you started the capture. You might have to do:
(defun my-extract-cc ()
(interactive)
(with-current-buffer (org-capture-get :original-buffer)
(mail-decode-encoded-address-string
(gnus-fetch-original-field "cc"))))
[-- Attachment #1: Type: text/plain, Size: 426 bytes --] > Uwe Brauer <oub@mat.ucm.es> writes: > Looks like the %(expr) escapes are evaluated in the *Capture* buffer, > not the buffer where you started the capture. You might have to do: > (defun my-extract-cc () > (interactive) > (with-current-buffer (org-capture-get :original-buffer) > (mail-decode-encoded-address-string > (gnus-fetch-original-field "cc")))) Thanks! That was the solution. Ha you saved my day! [-- Attachment #2: smime.p7s --] [-- Type: application/pkcs7-signature, Size: 5673 bytes --]
Uwe Brauer <oub@mat.ucm.es> writes:
>> Uwe Brauer <oub@mat.ucm.es> writes:
>
>> Looks like the %(expr) escapes are evaluated in the *Capture* buffer,
>> not the buffer where you started the capture. You might have to do:
>
>> (defun my-extract-cc ()
>> (interactive)
>> (with-current-buffer (org-capture-get :original-buffer)
>> (mail-decode-encoded-address-string
>> (gnus-fetch-original-field "cc"))))
>
>
> Thanks! That was the solution. Ha you saved my day!
Glad to help!
[-- Attachment #1: Type: text/plain, Size: 729 bytes --] > Uwe Brauer <oub@mat.ucm.es> writes: > Looks like the %(expr) escapes are evaluated in the *Capture* buffer, > not the buffer where you started the capture. You might have to do: > (defun my-extract-cc () > (interactive) > (with-current-buffer (org-capture-get :original-buffer) > (mail-decode-encoded-address-string > (gnus-fetch-original-field "cc")))) I just realized that I might use that template, even for messages with empty CC fields, however in that case my template will fail. How can I add something like (if cc-non-empty (with-current-buffer (org-capture-get :original-buffer) (mail-decode-encoded-address-string (gnus-fetch-original-field "cc")))) thanks [-- Attachment #2: smime.p7s --] [-- Type: application/pkcs7-signature, Size: 5673 bytes --]
Uwe Brauer <oub@mat.ucm.es> writes:
>> Uwe Brauer <oub@mat.ucm.es> writes:
>
>> Looks like the %(expr) escapes are evaluated in the *Capture* buffer,
>> not the buffer where you started the capture. You might have to do:
>
>> (defun my-extract-cc ()
>> (interactive)
>> (with-current-buffer (org-capture-get :original-buffer)
>> (mail-decode-encoded-address-string
>> (gnus-fetch-original-field "cc"))))
>
> I just realized that I might use that template, even for messages with
> empty CC fields, however in that case my template will fail.
>
> How can I add something like
>
> (if cc-non-empty
> (with-current-buffer (org-capture-get :original-buffer)
> (mail-decode-encoded-address-string
> (gnus-fetch-original-field "cc"))))
>
> thanks
You'll just have to let-bind the cc field and then check it. (Or
`when-let', if your Emacs has that.) You can put this inside the
`with-current-buffer':
(let ((cc (gnus-fetch-original-field "cc")))
(if cc (mail-decode-encoded-address-string cc)
""))
[-- Attachment #1: Type: text/plain, Size: 345 bytes --] > Uwe Brauer <oub@mat.ucm.es> writes: > You'll just have to let-bind the cc field and then check it. (Or > `when-let', if your Emacs has that.) You can put this inside the > `with-current-buffer': > (let ((cc (gnus-fetch-original-field "cc"))) > (if cc (mail-decode-encoded-address-string cc) > "")) Thanks, that was extremely useful [-- Attachment #2: smime.p7s --] [-- Type: application/pkcs7-signature, Size: 5673 bytes --]
Uwe Brauer wrote: > So > > For example > > Cc: user1 <user1@gmail.com>, user2 <user2@gmx.net> > > Extracts user1 <user1@gmail.com>, user2 <user2@gmx.net> > > Has to be expected. > > Would it be possible to extract > > Ccname user1 > ccfrom user1@gmail.com I once did something similar: ;;; -*- lexical-binding: t -*- ;;; ;;; this file: ;;; http://user.it.uu.se/~embe8573/emacs-init/match-data-format.el ;;; https://dataswamp.org/~incal/emacs-init/match-data-format.el (defun make-match-list (num string) (let ((match (match-string num string))) (when match (cons match (make-match-list (1+ num) string))) )) (defun match-data-format (data match format-str) (save-match-data (string-match match data) (apply #'message format-str (make-match-list 1 data)) )) (when nil (match-data-format "From: Joe Hacker <get@this.data>" "\\(.*\\): *\\(.*[[:alnum:]]\\) *<\\(.*\\)>" "header is: %s\nname is: %s\ne-mail is: %s") ) ; ^eval me ;; output from eval'd command: ;; ;; header is: From ;; name is: Joe Hacker ;; e-mail is: get@this.data -- underground experts united http://user.it.uu.se/~embe8573 https://dataswamp.org/~incal