1

When Gmail forwards an email to an external address, it apparently inserts the forwarded address into the FROM line. So an email being forwarded to username@school.edu by username@gmail.com becomes:

username+caf_=username=school.edu@gmail.com 

I'm having trouble matching this resulting FROM address in procmail. I've tried these match patterns with no success:

:0
* ^From:.*username\+caf_=username=school.edu@gmail.com
/dev/null

:0
* ^From:.*username.*@gmail.com
/dev/null

The second pattern should match anything between username and @gmail.com, but its failure makes me think that procmail is having trouble processing the FROM string to be searched and that the problem is not with the match pattern at all. Note that the procmail log sees and reports the modified FROM address without any issues, just like it does with any email that didn't match the pattern.

Any ideas on how to match these types of forwarded gmail addresses? Thanks.

Here's the abbreviated header of the email in question:

From username+caf_=username=school.edu@gmail.com Sat Nov 10 11:26:24 2018
X-Received: by 2002:a2e:1241:: with SMTP id --;
        Sat, 10 Nov 2018 11:25:20 -0800 (PST)
X-Forwarded-To: username@school.edu
X-Forwarded-For: username@gmail.com username@school.edu
Delivered-To: username@gmail.com
X-Google-Smtp-Source: --
X-Received: by 2002:ac8:7598:: with SMTP id s24mr13601716qtq.6.1541877918711;
        Sat, 10 Nov 2018 11:25:18 -0800 (PST)
From: someuser <someuser@someagency.gov>
Date: Sat, 10 Nov 2018 14:24:59 -0500
To: username@someagency.gov
Subject: TEXT
User-Agent: Heirloom mailx 12.4 7/29/08
  • 1
    Could you add the headers of an example email? (Or at least the `From: email@address` line? It is hard to tell why X isn't matching Y without the X. – Tim Nov 20 '18 at 17:34
  • Seconded - are you talking about the envelope sender, the `From:` address in the headers, or perhaps something like `Sender:`? – tripleee Nov 20 '18 at 18:31
  • Also, having a condition without an action is a syntax error. If this is your actual recipe file, perhaps the problem is a symptom of this error, rather than an actual regex problem. An excerpt from Procmail's log might be good to include, especially if it contains an actual error message. – tripleee Nov 20 '18 at 18:33
  • Procmail reads _only_ the headers, not the envelope! – Michael Hampton Nov 20 '18 at 20:22

1 Answers1

1

Thanks for all of the comments. The suggestion to post the full header led me to the solution to this problem. As you can see from the header, the gmail account doing the forwarding is listed as:

From username+caf_=username=school@gmail.com Sat Nov 10 11:26:24 2018

This is the line that appears in the procmail log and originally threw me off. Note that my original match pattern was searching for:

:0
* ^From:.*username\+caf_=username=school.edu@gmail.com
/dev/null

It appears that the colon does not exist between "FROM" and the email address doing the forwarding. On the other hand, the line specifying the original sender later in the header does conform to the colon syntax, appearing as:

From: someuser <someuser@someagency.gov>

So to catch forwarded messages, you need to either match the forwarding email account without a colon as:

:0
* ^From.*username\+caf_=username=school.edu@gmail.com
/dev/null

or match the original sender with a colon as:

:0
* ^From:.*someuser@someagency.gov
/dev/null

Thanks again for the help!

  • 1
    The so-called `From_` line reveals the envelope sender. It is not a proper header at all, though Procmail will generate it if necessary. See http://www.iki.fi/era/procmail/mini-faq.html#from-- – tripleee Nov 21 '18 at 05:38