procmail
[Top] [All Lists]

Re: From: header ignored by formail -r

2005-09-27 04:29:07
On Mon, Sep 26, 2005 at 11:57:07AM -0600, Lloyd Standish wrote:

I have a question:  Under what circumstances will formail -r
(which determines a mail's return address) fail to use the
address in the "From:" header, and use instead the "return path"
address?

Lloyd,

For comparison, take note of what formail's man page says about the
-t switch:


  -t  Trust the sender to have  used  a  valid  return  address  in  his
      header.   This  causes formail to select the header sender instead
      of the envelope sender for the reply.  This option should be  used
      when  generating auto-reply headers from news articles or when the
      sender of the message is expecting a reply.

We can test with and without -t for a better understanding.


First, I constructed some headers from a real message I sent myself
and then edited.  I put unique identifiers on each relevant line:

   From dman+from_(_at_)nomotek(_dot_)com  Tue Sep 27 12:26:38 2005
   Return-Path: <dman+return-path(_at_)nomotek(_dot_)com>
   X-Original-To: dman+x-original-to(_at_)nomotek(_dot_)com
   Delivered-To: dman+delivered-to(_at_)panix(_dot_)com
   Date: Tue, 27 Sep 2005 12:26:34 +0200
   From: Dallman Ross <dman+from(_at_)nomotek(_dot_)com>
   To: dman+to(_at_)nomotek(_dot_)com
   Reply-To: dman+reply-to(_at_)nomotek(_dot_)com
   Sender: dman+sender(_at_)nomotek(_dot_)com
   Subject: test headers under formail
   Message-ID: 
<20050927102634(_dot_)GA16597dman+message-id(_at_)nomotek(_dot_)com>
   Content-Type: text/plain; charset=us-ascii

Running that through "formail -r", we get:

   12:42pm [~/Mail] 543[1]> formail -r < headertest 
  To: dman+from_(_at_)nomotek(_dot_)com
  Subject: Re: test headers under formail
  References: 
<20050927102634(_dot_)GA16597dman+message-id(_at_)nomotek(_dot_)com>
  In-Reply-To: 
<20050927102634(_dot_)GA16597dman+message-id(_at_)nomotek(_dot_)com>

So it uses the From_ line to set the reply address, even when there
is a Reply-To and a Sender field.

Trying with "formail -rt", we get:

   12:43pm [~/Mail] 545[1]> formail -rt < headertest
  To: dman+reply-to(_at_)nomotek(_dot_)com
  Subject: Re: test headers under formail
  References: 
<20050927102634(_dot_)GA16597dman+message-id(_at_)nomotek(_dot_)com>
  In-Reply-To: 
<20050927102634(_dot_)GA16597dman+message-id(_at_)nomotek(_dot_)com>

That prefers the Reply-To, if it's there.


Let me remove it from my headers and try again:

   12:44pm [~/Mail] 548[0]> formail -rt < headertest
  To: dman+from(_at_)nomotek(_dot_)com
  Subject: Re: test headers under formail
  References: 
<20050927102634(_dot_)GA16597dman+message-id(_at_)nomotek(_dot_)com>
  In-Reply-To: 
<20050927102634(_dot_)GA16597dman+message-id(_at_)nomotek(_dot_)com>

Next in preference was the From (not From_) header.  So let's
remove it:

   12:46pm [~/Mail] 551[0]> formail -rt < headertest
  To: dman+sender(_at_)nomotek(_dot_)com
  Subject: Re: test headers under formail
  References: 
<20050927102634(_dot_)GA16597dman+message-id(_at_)nomotek(_dot_)com>
  In-Reply-To: 
<20050927102634(_dot_)GA16597dman+message-id(_at_)nomotek(_dot_)com>

Sender was next.  Removing it:

  [84.169.200.211 -> panix5] {dman} [1.17]
   12:46pm [~/Mail] 555[1]> formail -rt < headertest
  To: dman+return-path(_at_)nomotek(_dot_)com
  Subject: Re: test headers under formail
  References: 
<20050927102634(_dot_)GA16597dman+message-id(_at_)nomotek(_dot_)com>
  In-Reply-To: 
<20050927102634(_dot_)GA16597dman+message-id(_at_)nomotek(_dot_)com>


Return-Path.  Remove it:

   12:47pm [~/Mail] 558[0]> formail -rt < headertest
  To: dman+from_(_at_)nomotek(_dot_)com
  Subject: Re: test headers under formail
  References: 
<20050927102634(_dot_)GA16597dman+message-id(_at_)nomotek(_dot_)com>
  In-Reply-To: 
<20050927102634(_dot_)GA16597dman+message-id(_at_)nomotek(_dot_)com>

Good.  Finally we're back to the From_ header.

Recapping, with the -t switch, we prefer reply-address headers
in this order:


    Reply-To
    From
    Sender
    Return-Path
    From_

(And without the -t, we just went right for the From_.)

RFC 2822 has more - everything there should be to know, actually -
about expected reply action.

Btw, one can use the order to construct a procmail-only (no formail)
preferential-address parser.  I learned this trick from procmail
master Rik Kabel about six years ago, off-list, when my procmail-fu
was much, much less.  He hasn't posted here in a long, long time,
unfortunately.  Whitespace that follows carets Inside square
brackets below comprises a space and a tab.


   :0
   * !    ^Reply-To:.*\/[^      ]+(_at_)[^      ]+[.][a-z][a-z]+
   * !        ^From:.*\/[^      ]+(_at_)[^      ]+[.][a-z][a-z]+
   * !      ^Sender:.*\/[^      ]+(_at_)[^      ]+[.][a-z][a-z]+
   * ! ^Return-Path:.*\/[^      ]+(_at_)[^      ]+[.][a-z][a-z]+
   * !       ^^From .*\/[^      ]+(_at_)[^      ]+[.][a-z][a-z]+
   { }

   :0 E
   { REPLY_TO = $MATCH }


We probably don't need the fancy regex and could just go with

   ! ^Header:.*\/[^     ]+

in most these cases; From_ and Reply-To are exceptions,
though, and so we might as well just use the regex all the way
down the line.

Let's test.  In between each test, I edited the header sample and
removed the last match:

 1:09pm [~/Mail] 579[0]> sh -c "procmail -m DEFAULT=/dev/null \
                 VERBOSE=y rt.rc 2>&1" < headertest | grep Y_T
procmail: Assigning "REPLY_TO=dman+reply-to(_at_)nomotek(_dot_)com"
--
 1:09pm [~/Mail] 581[0]> sh -c "procmail -m DEFAULT=/dev/null \
                 VERBOSE=y rt.rc 2>&1" < headertest | grep Y_T
procmail: Assigning "REPLY_TO=<dman+from(_at_)nomotek(_dot_)com"
--
 1:09pm [~/Mail] 583[0]> sh -c "procmail -m DEFAULT=/dev/null \
                 VERBOSE=y rt.rc 2>&1" < headertest | grep Y_T
procmail: Assigning "REPLY_TO=dman+sender(_at_)nomotek(_dot_)com"
--
 1:10pm [~/Mail] 585[0]> sh -c "procmail -m DEFAULT=/dev/null \
                 VERBOSE=y rt.rc 2>&1" < headertest | grep Y_T
procmail: Assigning "REPLY_TO=<dman+return-path(_at_)nomotek(_dot_)com"
--
 1:10pm [~/Mail] 587[0]> sh -c "procmail -m DEFAULT=/dev/null \
                 VERBOSE=y rt.rc 2>&1" < headertest | grep Y_T
procmail: Assigning "REPLY_TO=dman+from_(_at_)nomotek(_dot_)com"

One can also add a level of abstraction with
a var that makes it look simpler:

 ADDR_PARSER = '.*\/[^  ]+(_at_)[^      ]+[.][a-z][a-z]+'

 :0
 * $ !    ^Reply-To:$ADDR_PARSER
 * $ !        ^From:$ADDR_PARSER
 * $ !      ^Sender:$ADDR_PARSER
 * $ ! ^Return-Path:$ADDR_PARSER
 * $ !       ^^From $ADDR_PARSER
 { }

 : E
 { REPLY_TO = $MATCH }

-- 
dman

____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>