From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.emacs.gnus.user/9604 Path: news.gmane.org!not-for-mail From: Bernhard Gschaider Newsgroups: gmane.emacs.gnus.user Subject: Re: Changing the "Sender" for the summary buffer Date: Thu, 30 Aug 2007 22:27:27 +0200 Message-ID: References: <87abs9fll5.fsf@workstation001.office.ice-sf.at> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1188511214 9045 80.91.229.12 (30 Aug 2007 22:00:14 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 30 Aug 2007 22:00:14 +0000 (UTC) To: info-gnus-english@gnu.org Original-X-From: info-gnus-english-bounces+gegu-info-gnus-english=m.gmane.org@gnu.org Fri Aug 31 00:00:13 2007 Return-path: Envelope-to: gegu-info-gnus-english@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1IQs3h-0001ds-22 for gegu-info-gnus-english@m.gmane.org; Fri, 31 Aug 2007 00:00:13 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IQs3g-0001Ta-N0 for gegu-info-gnus-english@m.gmane.org; Thu, 30 Aug 2007 18:00:12 -0400 Original-Path: shelby.stanford.edu!headwall.stanford.edu!newshub.sdsu.edu!newsfeed.freenet.de!newsfeed01.chello.at!newsfeed02.chello.at!news.inode.at.POSTED!not-for-mail User-Agent: Thunderbird 1.5.0.9 (X11/20070317) Original-Newsgroups: gnu.emacs.gnus In-Reply-To: Original-X-Complaints-To: abuse@inode.at Original-Lines: 81 Original-NNTP-Posting-Host: 83.64.155.34 (83.64.155.34) Original-NNTP-Posting-Date: Thu, 30 Aug 2007 22:27:34 +0200 Original-X-Trace: d7eb546d72836f6e53e8729859 Original-Xref: shelby.stanford.edu gnu.emacs.gnus:79805 X-Mailman-Approved-At: Thu, 30 Aug 2007 18:00:00 -0400 X-BeenThere: info-gnus-english@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Announcements and discussions for GNUS, the GNU Emacs Usenet newsreader \(in English\)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: info-gnus-english-bounces+gegu-info-gnus-english=m.gmane.org@gnu.org Errors-To: info-gnus-english-bounces+gegu-info-gnus-english=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.gnus.user:9604 Archived-At: 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 \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 ". 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 \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)