Announcements and discussions for Gnus, the GNU Emacs Usenet newsreader
 help / color / mirror / Atom feed
* Changing the "Sender" for the summary buffer
@ 2007-08-30  8:55 Bernhard Gschaider
  2007-08-30 18:13 ` Reiner Steib
  0 siblings, 1 reply; 3+ messages in thread
From: Bernhard Gschaider @ 2007-08-30  8:55 UTC (permalink / raw)
  To: info-gnus-english


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)

Now what I would like to achive is that in the summary-buffer of the
folder for the Sender-Name instead of the MessageBoard-name the name
of the poster is displayed.

I have some vague ideas how this can be achieved (something with a
hook on that group that filters the name from the message body and a
local gnus-summary-line-format format), but I'm lacking experience
with Gnus-programming, so it would take me days just to figure out
where to look. 

Can somebody give me a hint how this could be done? Just something
like "look at variable foo, implement hook bar for the buffer".

One of the key questions for me is: Can it only be done by generating
a new mail-header when filtering the mail (thus changing the messages
on disk) or can it be done during the displaying of the summary
buffer?

Of course if somebody has already done something similar and would be
so kind to share it (I can adapt it) I would be very grateful

Bernhard

-- 
Writing software is more fun than working.

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

* Re: Changing the "Sender" for the summary buffer
  2007-08-30  8:55 Changing the "Sender" for the summary buffer Bernhard Gschaider
@ 2007-08-30 18:13 ` Reiner Steib
  2007-08-30 20:27   ` Bernhard Gschaider
  0 siblings, 1 reply; 3+ messages in thread
From: Reiner Steib @ 2007-08-30 18:13 UTC (permalink / raw)
  To: info-gnus-english

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)
>
> Now what I would like to achive is that in the summary-buffer of the
> folder for the Sender-Name instead of the MessageBoard-name the name
> of the poster is displayed.
[...]
> Can somebody give me a hint how this could be done? Just something
> like "look at variable foo, implement hook bar for the buffer".
>
> One of the key questions for me is: Can it only be done by generating
> a new mail-header when filtering the mail (thus changing the messages
> on disk) or can it be done during the displaying of the summary
> buffer?

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)

You could also do it with procmail.  The following procmail recipe
extracts a line from the body and puts it in the Subject.  You need to
modify From instead.  The original header is renamed to "Old-Subject",
see procmailrc(5) or procmailex(5) for details.

,----[ Original ]
| Subject:      CNN Breaking News
| 
| -- Some relevant stuff
| ads, ads, ...
| more ads.
`----

,----[ Modified ]
| Subject: Some relevant stuff
| 
| -- Some relevant stuff
| ads, ads, ...
| more ads.
`----

--8<---------------cut here---------------start------------->8---
  :0
  * ^From: .*@(|.*\.)CNN.COM
  * < 5000
  {
    # Add a Subject to CNN Breaking News
    :0 BHf
    * ^From:.*BreakingNews
    * ^Subject:.*CNN Breaking News
    * ^-- \/.*
    | formail -i "Subject: $MATCH"
  }
  #
  :0
  * ^From: .*@(|.*\.)CNN.COM
  $NEWS_SPOOL_IN/local.newsletters.cnn.breakingnews
--8<---------------cut here---------------end--------------->8---

Bye, Reiner.
-- 
       ,,,
      (o o)
---ooO-(_)-Ooo---  |  PGP key available  |  http://rsteib.home.pages.de/

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

* Re: Changing the "Sender" for the summary buffer
  2007-08-30 18:13 ` Reiner Steib
@ 2007-08-30 20:27   ` Bernhard Gschaider
  0 siblings, 0 replies; 3+ messages in thread
From: Bernhard Gschaider @ 2007-08-30 20:27 UTC (permalink / raw)
  To: info-gnus-english

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)

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

end of thread, other threads:[~2007-08-30 20:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-08-30  8:55 Changing the "Sender" for the summary buffer Bernhard Gschaider
2007-08-30 18:13 ` Reiner Steib
2007-08-30 20:27   ` Bernhard Gschaider

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