LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 06-12-2019, 05:29 AM   #1
Klaipedaville
Member
 
Registered: Mar 2013
Posts: 99

Rep: Reputation: Disabled
Procmail Recipe Advice


I have a recipe that cannot seem to match the address.

I tried these:

Code:
* ^From.*address9\@gmail\.com

* ^From.*address9@gmail.com

* ^From.*address\[0-9\]\@gmail\.com

* ^From.*address\d\@gmail\.com

* ^From.*address\d@gmail.com
but none of the above-mentioned works... I am totally lost. It looks like regular expressions have its own logic and patterns in procmail.

The address to match has this 9 at the end and it's gmail.com When I put any other email address into this * ^From.* field it works OK, but this one doesn't... Here is my full recipe. The conditions to match are: to add a tag [New Report] when it comes from address9@gmail.com and the subject field is empty. I would really be thankful if somebody could advise please, as I am about to go nuts trying to understand where is the mistake here.

Code:
:0 fhw
* ^From.*address9\@gmail\.com 
* ^Subject:\/.+
| /usr/bin/formail -i "Subject: [New Report]$MATCH"
Would also be grateful for any pointers how to trouble shoot it. Many thanks in advance!
 
Old 06-12-2019, 09:15 AM   #2
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.6
Posts: 3,066

Rep: Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069
Quote:
Originally Posted by Klaipedaville View Post
I have a recipe that cannot seem to match the address.

I tried these:

Code:
* ^From.*address9\@gmail\.com

* ^From.*address9@gmail.com

* ^From.*address\[0-9\]\@gmail\.com

* ^From.*address\d\@gmail\.com

* ^From.*address\d@gmail.com
but none of the above-mentioned works... I am totally lost. It looks like regular expressions have its own logic and patterns in procmail.

The address to match has this 9 at the end and it's gmail.com When I put any other email address into this * ^From.* field it works OK, but this one doesn't... Here is my full recipe. The conditions to match are: to add a tag [New Report] when it comes from address9@gmail.com and the subject field is empty. I would really be thankful if somebody could advise please, as I am about to go nuts trying to understand where is the mistake here.

Code:
:0 fhw
* ^From.*address9\@gmail\.com 
* ^Subject:\/.+
| /usr/bin/formail -i "Subject: [New Report]$MATCH"
Would also be grateful for any pointers how to trouble shoot it. Many thanks in advance!
The From test looks OK to me. What happens if you take out the Subject test that you're ANDing?
It looks to me like that is trying to match a line like:
Subject:/asdfasdf
Not an empty line. Try
Code:
* ^Subject:$
for an empty line
...although in a test I just ran, an email with no Subject line did not have a Subject header at all...
so maybe
Code:
* !^Subject
?? not tested...
Anyway, try without theSubject test at all to insure that the From test is working, first...

Last edited by scasey; 06-12-2019 at 09:18 AM.
 
Old 06-12-2019, 10:42 AM   #3
Klaipedaville
Member
 
Registered: Mar 2013
Posts: 99

Original Poster
Rep: Reputation: Disabled
Quote:
Anyway, try without the Subject test at all to insure that the From test is working, first...
Thank you for replying. Appreciate.

I had already tested it without the subject field before I posted my question here. It works well. That is if there is no subject in my code then there is no original subject that was typed in by the sender at all. There is just my tag added instead of a subject.

Last edited by Klaipedaville; 06-12-2019 at 10:44 AM.
 
Old 06-12-2019, 11:15 AM   #4
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.6
Posts: 3,066

Rep: Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069
Quote:
Originally Posted by Klaipedaville View Post
Thank you for replying. Appreciate.

I had already tested it without the subject field before I posted my question here. It works well. That is if there is no subject in my code then there is no original subject that was typed in by the sender at all. There is just my tag added instead of a subject.
I'm sorry...without the subject line the From filter works? In that case, it's the Subject recipe that's broken, not the From recipe.

Did I miss something?
 
Old 06-12-2019, 11:48 AM   #5
Klaipedaville
Member
 
Registered: Mar 2013
Posts: 99

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by scasey View Post
I'm sorry...without the subject line the From filter works? In that case, it's the Subject recipe that's broken, not the From recipe.

Did I miss something?
Right. I wish I knew. It's quite confusing. The matter is that the procmail's logs say that the problem is in From (no match found). Then if there is no subject field in my code then it works but 1.) it doesn't match my conditions and 2.) it doesn't match the email address I target. All the other email addresses work (I tested it on another 10 email addresses). Plus, it has different logic or patterns or whatever it is called in procmail. For example this is one is correct for regular expressions address9\@gmail\.com but it's incorrect for procmail's regular expressions. The correct line for procmail will be address9@gmail\.com ...that is why I seek help. The problem is complex.

Last edited by Klaipedaville; 06-12-2019 at 12:10 PM.
 
Old 06-12-2019, 12:18 PM   #6
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.6
Posts: 3,066

Rep: Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069
Quote:
Originally Posted by Klaipedaville View Post
Right. I wish I knew. It's quite confusing. The matter is that the procmail's logs say that the problem is in From (no match found). Then if there is no subject field in my code then works but 1.) it doesn't match my conditions and 2.) it doesn't match the email address I target. All the other email addresses work (I tested it on another 10 email addresses). Plus, it has different logic or patterns or whatever it is called in procmail. For example this is one is correct for regular expressions address9\@gmail\.com but it's incorrect for procmail's regular expressions. The correct line for procmail will be address9@gmail\.com ...that is why I seek help. The problem is complex.
I'm sorry. You're not making sense (to me)...
"If there is no subject field in my code then works but doesn't match..." ???
If it doesn't match, how is it that it works?

I don't use the flags (fwh) you're using. Perhaps try it without those?
Did you try the changes I suggested to the Subject recipe? What happened?

Do the logs say No Match Found when ONLY the From recipe is present?

Last edited by scasey; 06-12-2019 at 12:21 PM.
 
Old 06-12-2019, 02:22 PM   #7
Klaipedaville
Member
 
Registered: Mar 2013
Posts: 99

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by scasey View Post
I'm sorry. You're not making sense (to me)...
"If there is no subject field in my code then works but doesn't match..." ???
If it doesn't match, how is it that it works?

I don't use the flags (fwh) you're using. Perhaps try it without those?
Did you try the changes I suggested to the Subject recipe? What happened?

Do the logs say No Match Found when ONLY the From recipe is present?
I am sorry I didn't make myself clear enough. It doesn't match the specific email address I need it to match in this from field. However, it matches similar addresses I tried for testing purposes. It doesn't work with address9@gmail.com (the one that I need) but it works OK with email5@domain.com (similar email address). This is why I said it worked generally but it doesn't match the condition (email address) that I need.

Thank you for your suggestions, I'll definitely give them a try but I don't think they'll match an empty subject field in procmail. It's a bit different in procmail as far as I understand it now. I am thinking about something like this
Code:
* ^Subject:[    ]*\/.*$
All in all I guess the problem is in both From and Subject... somewhere...
 
Old 06-12-2019, 02:45 PM   #8
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.6
Posts: 3,066

Rep: Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069
Yes, the regex in procmail has some differences and limitations, but matching an email address is pretty straightforward.

Code:
* ^From.*address9\@gmail\.com
is what I use to match email addresses. It works just fine.
Since you say
Code:
email5\@domain\.com
works, there must be something in the gmail From: line that's not being acconted for.

Try this:
Comment out the recipe - or the action -, so there are no changes made to the email, then look at the From: line as it looks before processing.
A test I ran sending from Thunderbird through gmail to my server looks like this:
Code:
From: User Realname <user@gmail.com>
which is a pretty typical from line that would match that pattern.

Another thing I often use is to just match what's unique, so if this is the only time email comes with address9 as the user, I often will do something like
Code:
* ^From.*address9
to get a match. Fewer opportunities for typos.

Every test I've tried with no subject just doesn't have a Subject: line in the header, so matching on any string with "Subject:" as part of the text is not going to work. That may be a Thunderbird thing, but, again, look at the raw header to see what's there that you're trying to match. If there's no header line at all, then
Code:
* !^Subject:
should match, but I've not tested that.

Edit: PS. Still don't understand why you have a literal "/" in your Subject match...

Last edited by scasey; 06-12-2019 at 02:50 PM.
 
Old 06-12-2019, 03:15 PM   #9
Klaipedaville
Member
 
Registered: Mar 2013
Posts: 99

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by scasey View Post
Yes, the regex in procmail has some differences and limitations, but matching an email address is pretty straightforward...
Edit: PS. Still don't understand why you have a literal "/" in your Subject match...
This is not a literal in procmail. That's \/ a special operator to declare the matching string into the variable $MATCH and then to output it:

Code:
* ^Subject:\/.+
| /usr/bin/formail -i "Subject: [New Report]$MATCH"
 
Old 06-12-2019, 03:22 PM   #10
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.6
Posts: 3,066

Rep: Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069
Quote:
Originally Posted by Klaipedaville View Post
This is not a literal in procmail. That's \/ a special operator to declare the matching string into the variable $MATCH and then to output it:

Code:
* ^Subject:\/.+
| /usr/bin/formail -i "Subject: [New Report]$MATCH"
Ahh. Missed that in the docs...but then they're pretty comprehensive. Thanks for clarifying.

I'm still a bit confused, I guess. If you test only the From line, you get a match, true or false?
 
Old 06-12-2019, 03:33 PM   #11
Klaipedaville
Member
 
Registered: Mar 2013
Posts: 99

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by scasey View Post
Ahh. Missed that in the docs...but then they're pretty comprehensive. Thanks for clarifying.
Don't mention it

Quote:
Originally Posted by scasey View Post
I'm still a bit confused, I guess. If you test only the From line, you get a match, true or false?
I am confused too. I am thinking there is something else... somewhere. OK. Again. When I test only the From filed for address9@gmail.com it says, "No Match Found" but when I test only the From field for email5@domain.com is says "matched".
 
Old 06-12-2019, 03:49 PM   #12
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.6
Posts: 3,066

Rep: Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069
Quote:
Originally Posted by Klaipedaville View Post
Don't mention it


I am confused too. I am thinking there is something else... somewhere. OK. Again. When I test only the From filed for address9@gmail.com it says, "No Match Found" but when I test only the From field for email5@domain.com is says "matched".
OK. Thank you.
Now let's look at the actual From: line in the gmail email headers, please - preferably before it gets processed by procmail.
Certainly you should obfuscate as necessary, but would like to see the entire unprocessed line otherwise.
 
Old 06-12-2019, 10:14 PM   #13
Klaipedaville
Member
 
Registered: Mar 2013
Posts: 99

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by scasey View Post
OK. Thank you.
Now let's look at the actual From: line in the gmail email headers, please - preferably before it gets processed by procmail.
Certainly you should obfuscate as necessary, but would like to see the entire unprocessed line otherwise.
Ohh.. sorry overlooked you last response. Would you like me to post here the entire header of the email that comes from address9@gmail.com?

P.S. none of your solutions and none of my ideas worked. This darn email address is some kind of a CIA or FBA thing, it's just freakin' unmatchable.. grrrr.. )))

Last edited by Klaipedaville; 06-12-2019 at 10:29 PM.
 
Old 06-12-2019, 10:40 PM   #14
scasey
Senior Member
 
Registered: Feb 2013
Location: Tucson, AZ, USA
Distribution: CentOS 7.6
Posts: 3,066

Rep: Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069Reputation: 1069
Quote:
Originally Posted by Klaipedaville View Post
Ohh.. sorry overlooked you last response. Would you like me to post here the entire header of the email that comes from address9@gmail.com?

P.S. none of your solutions and none of my ideas worked. This darn email address is some kind of a CIA or FBA thing, it's just freakin' unmatchable.. grrrr.. )))
Yes, The entire header would be most useful to look at...
 
Old 06-12-2019, 11:39 PM   #15
Klaipedaville
Member
 
Registered: Mar 2013
Posts: 99

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by scasey View Post
Yes, The entire header would be most useful to look at...
Ok. Here goes:

Code:
Return-Path: <address9@gmail.com> 
X-Original-To: mail@mail.com 
Delivered-To: mail@mail.com 
Received: by klaipedaville.info (WindTalker, from userid 9000) 	
id E38C1F93A1; Thu, 13 Jun 2019 06:20:14 +0300 (EEST) 
X-Spam-Checker-Version: SpamAssassin on klaipedaville 
X-Spam-Level:  
X-Spam-Status: No, score=0.0 required=4.0 tests=FREEMAIL_FROM,HTML_MESSAGE,
 	RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham version=3.3.2 
Received-SPF: pass (gmail.com ... _spf.google.com: Sender is authorized to use 'address9@gmail.com' in 'mfrom' identity (mechanism 'include:_netblocks.google.com' matched)) receiver=klaipedaville; identity=mailfrom; 
envelope-from="address9@gmail.com"; helo=mail-wr1-f48.google.com; client-ip=209.85.221.48
Received: from mail-wr1-f48.google.com (mail-wr1-f48.google.com [209.85.221.48])
 	by klaipedaville.info (WindTalker) with ESMTPS id 3C7EFF93A1
 	for <mail@mail.com>; Thu, 13 Jun 2019 06:20:06 +0300 (EEST) 
Received: by mail-wr1-f48.google.com with SMTP id d18so19018199wrs.5
         for <mail@mail.com>; Wed, 12 Jun 2019 20:20:06 -0700 (PDT) 
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
         d=gmail.com; s=20161025;
         h=mime-version:from:date:message-id:subject:to;
         bh=Q0YHH9YC+BQN3FFWpBBMm4KJDqmtd13aEhHS9VeBc0c=;
         b=nMOacBrlkSYFmRzurtVLWuDUdv+S+L7OWgPcO+oaHAZ7ra6wHuXMbFX3R3Okyg6UBT          e9u71A09gIHUqN5g60hEDPYXZsHfizWTPaxyiwfjLlIeTCt461qNPCBj0KIOmU0A3Iqw          
DMIxLm6L/BHSo14pYX9QAVwAlwYsTJZoE+tdET7WePtMkzwxbx9Q0TQbtIyByKXFcKWS          
KQPIP3MoaDSLd3AfKsnqx18mLrq0/5xg6eItRz9n0D5F8Wlv5T1y6xc8nFABHCNTrHQ/          
dp8148FpRqEQDMaIcUEdMjmyM5ka129wuYzi57rF2dluSGGNjibqsBb8AMLjmfKjZag0          
1Hlw== 
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
         d=1e100.net; s=20161025;
         h=x-gm-message-state:mime-version:from:date:message-id:subject:to;
         bh=Q0YHH9YC+BQN3FFWpBBMm4KJDqmtd13aEhHS9VeBc0c=;
         b=ZcFNtxxF8a6nOz09nBu6+m29/0zHoB5SO4zl0Vz2Wu46gkvpxIZRFjqeAmiOKZ/TWZ          gWPT1XG3CI7Vkv9V/Y5Puy7uiqp65o72CKVVhLAKuxc235Cxz8niL1IH+FlShncCwAiy          
34Lnfy0KaJSBr+J4N7T9B9cFs0YVB43JgKvI9PCEDIiOPZThSBaweAnMhlodDxpaRQyi          
Lkdzf6ttl42CrLj2FeOJZn9hPlQupCOI4CRFv1xqJ0pqt14fpTOqth3N6k/gABbMB82S          
cHT+DitjWRtfXwHmzW3ysiqL694Yqf2HgudJ92Bf5PIE/Dm1hE6wxSJQy8n8gv01Wg/W          
uZVg== 
X-Gm-Message-State: APjAAAVEeoBNpcfIaQlrequ3HT6a27Q/m85VGFe93PCq/yq8gUUEoFEW
 	VjE5GVnIvu03k0EpL/vIlYzuLsQLkGIXRFJzLi02DA== 
X-Google-Smtp-Source: 
APXvYqyHMiCriRZg5S7tuhapcxvf0VX74qiOtj2dsCKlGY5UJVyayNKXDplhNHxmRlM6W2XIruAxptq+zxtE+AAGfss= 
X-Received: by 2002:adf:ff84:: with SMTP id j4mr31223854wrr.151.1560396004490;
  Wed, 12 Jun 2019 20:20:04 -0700 (PDT)
 MIME-Version: 1.0 Received: by 2002:a1c:7718:0:0:0:0:0 with HTTP; Wed, 12 Jun 2019 20:20:03  -0700 (PDT)
 Received: by 2002:a1c:7718:0:0:0:0:0 with HTTP; Wed, 12 Jun 2019 20:20:03  -0700 (PDT) 
From: Name Lastname <address9@gmail.com> 
Date: Thu, 13 Jun 2019 15:20:03 +1200 Message-ID: <CADxD3vfeP2bk=jHT2xX-onTy7PJb0AU_udLinB_8AeGxGrY2eQ@mail.gmail.com> 
Subject:  
To: Me <mail@mail.com> 
Content-Type: multipart/alternative; boundary="0000000000008e8119058b2c01da" 
X-Virus-Scanned: clamav-milter at klaipedaville 
X-Virus-Status: Clean  

--0000000000008e8119058b2c01da
 Content-Type: text/plain; charset="UTF-8"
 
Some body field text here

 --0000000000008e8119058b2c01da 
Content-Type: text/html; charset="UTF-8"  

<p dir="ltr">Some text here.<br> 
Some body field text here.<br> 
Some body field text here.<br> 
Some body field text here </p>

  --0000000000008e8119058b2c01da--
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Three actions in a recipe of Procmail Borelian Linux - Software 1 11-11-2012 06:48 AM
procmail; recipe help; returning notification on overly large emails TheLinuxDuck Programming 2 02-05-2010 01:28 AM
Procmail recipe jebix666 Linux - General 1 06-09-2005 01:43 PM
procmail recipe for charset conversion Peff Linux - Software 0 07-13-2004 02:40 AM
procmail recipe not working? theLIGHT Linux - Software 3 11-18-2002 10:04 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 04:12 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration