From: Bernhard Gschaider <bgschaid@nowhere.at>
To: info-gnus-english@gnu.org
Subject: Re: Changing the "Sender" for the summary buffer
Date: Thu, 30 Aug 2007 22:27:27 +0200 [thread overview]
Message-ID: <d7eb5$46d72836$53409b22$29859@news.inode.at> (raw)
In-Reply-To: <v9myw828m5.fsf@marauder.physik.uni-ulm.de>
Thanks a lot.
Reiner Steib wrote:
> On Thu, Aug 30 2007, Bernhard Gschaider wrote:
>
>> Hi!
>>
>> I have the following thing I want my Gnus to do, but before I set out
>> to try it I want to know whether it can be done with juistifyable
>> effort (my lisp is a bit rusty ....):
>>
>> I'm receiving mails from a message board software (and a filter sorts
>> them into a separate folder). Obviously the sender address is that of
>> the MessageBoard-software. Each mail starts with the message
>> "This was posted by Isidor Pepranek on Tuesday..."
>> (the name variies obviously)
>
> Using `nnmail-prepare-incoming-message-hook' should work, I think.
>
> ,----[ (info "(gnus)Washing Mail") ]
> | `nnmail-prepare-incoming-message-hook'
> | This hook is called narrowed to each message.
> `----
>
> Untested (and a little ugly):
>
> (defun rs-nnmail-fetch-sender-from-body ()
> "Fetch sender's name from body and isert it into the From: header."
> (save-excursion
> (let ((case-fold-search t)
> endofheaders
> name)
> (goto-char (point-min))
> (search-forward "\n\n" nil t)
> (setq endofheaders (1- (point)))
> (re-search-forward "^This was posted by \\(.*\\) on [MTWFS]" nil t)
> (setq name (match-string 1))
> (goto-char endofheaders)
> (beginning-of-line)
> (insert
> (format "From: %s <via-MessageBoard@YourCompany.invalid>\n" name))
> (goto-char (point-min))
> (re-search-forward "^From: ")
> (beginning-of-line)
> (insert "Old-"))))
>
> (add-hook 'nnmail-prepare-incoming-message-hook
> 'rs-nnmail-fetch-sender-from-body)
>
This worked perfectly apart from the fact that I had to insert a test
whether name was non-nil, otherwise all non-matching mails would have
been tagged with a "From: nil <MessageBoard@>". So the finished function
reads:
(defun rs-nnmail-fetch-sender-from-body ()
"Fetch sender's name from body and isert it into the From: header."
(save-excursion
(let ((case-fold-search t)
(endofheaders nil)
name)
(goto-char (point-min))
(search-forward "\n\n" nil t)
(setq endofheaders (1- (point)))
(re-search-forward "^Posted by \\(.*\\) on [MTWFS]" nil t)
(setq name (match-string 1))
(if name (let ()
(goto-char endofheaders)
(beginning-of-line)
(insert
(format "From: %s <no-reply@opencfd.co.uk>\n" name))
(goto-char (point-min))
(re-search-forward "^From: ")
(beginning-of-line)
(insert "Old-"))
))))
(I'm not posting that to show off my weak lisp-skills or to point out
errors in the postings of people that saved me a lot of time by giving
me a good start, but for the sake of the next one who has a similar
problem and knows how to google)
prev parent reply other threads:[~2007-08-30 20:27 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-08-30 8:55 Bernhard Gschaider
2007-08-30 18:13 ` Reiner Steib
2007-08-30 20:27 ` Bernhard Gschaider [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='d7eb5$46d72836$53409b22$29859@news.inode.at' \
--to=bgschaid@nowhere.at \
--cc=info-gnus-english@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).