how to check for blank or missing "TO" address with procmail?

how to check for blank or missing "TO" address with procmail?

am 07.12.2005 03:52:41 von morguns

i'm trying to make a procmail recipe to filter messages that don't have
a to or cc address. i'm starting simple by checking only the "TO"
field, but not having any success. look at this simple recipe:

:0:
* 1^0 ^TO([ ]$|$)
* 1^0 !^TO
file
# note: the brackets contain a "space" and a "tab"

this does not work. can someone clue me in? thanks.

Re: how to check for blank or missing "TO" address with procmail?

am 07.12.2005 07:47:00 von Garen Erdoisa

morguns wrote:
> i'm trying to make a procmail recipe to filter messages that don't have
> a to or cc address. i'm starting simple by checking only the "TO"
> field, but not having any success. look at this simple recipe:
>
> :0:
> * 1^0 ^TO([ ]$|$)
> * 1^0 !^TO
> file
> # note: the brackets contain a "space" and a "tab"
>
> this does not work. can someone clue me in? thanks.
>

# One or more of the following should do the trick:

:0:
* ! ^(To|Cc):
bcc.incoming

:0:
* ! ^(To|Cc): .*youremail@example\.com.*
bcc.incoming

:0:
* ! ^(To|Cc): .*Your Real Name .*
bcc.incoming


If you want to get fancier about it, you could put a list of email
address patterns you wish to accept into a file and do it this way:

MYEMAIL=${HOME}/.myemail

:0:
* ? test -f ${MYEMAIL} && (${FORMAIL} -zxTo: -zxCc: |fgrep -i -f ${MYEMAIL})
| ${FORMAIL} -A"X-Folder: Default" >>${DEFAULT}

# else
:0E:
bcc.incoming

Garen

Re: how to check for blank or missing "TO" address with procmail?

am 08.12.2005 00:32:57 von morguns

thx for the reply Garen, but still no joy. for some context, i should
explain that i'm filtering email for several domains. one address is a
catchall for all of the domains; it's this catchall account that's
getting spam. them sneaky spammers leave the "To" and "CC" fields blank
and instead "BCC" addresses like foipuas@domain.com. i have spam
software installed and it's catching _almost_ all spam, but
occasionally some get past the spam software.

my goal is to create a procmail filter that will catch these occasional
messages. your first suggestion would work perfect if it was testing
for a blank subject, but it doesn't work for the "To" and/or "CC"
fields. your other suggestions don't test for _blank_ "To" and "CC"
fields, so they miss the mark.

thanks anyway, your input is sincerely appreciated.

Re: how to check for blank or missing "TO" address with procmail?

am 08.12.2005 00:51:00 von Garen Erdoisa

morguns wrote:
> thx for the reply Garen, but still no joy. for some context, i should
> explain that i'm filtering email for several domains. one address is a
> catchall for all of the domains; it's this catchall account that's
> getting spam. them sneaky spammers leave the "To" and "CC" fields blank
> and instead "BCC" addresses like foipuas@domain.com. i have spam
> software installed and it's catching _almost_ all spam, but
> occasionally some get past the spam software.
>
> my goal is to create a procmail filter that will catch these occasional
> messages. your first suggestion would work perfect if it was testing
> for a blank subject, but it doesn't work for the "To" and/or "CC"
> fields. your other suggestions don't test for _blank_ "To" and "CC"
> fields, so they miss the mark.
>
> thanks anyway, your input is sincerely appreciated.
>
Ok I see your problem.

In this situation you could use the following, presuming the To: or Cc:
headers are present, but empty.

The "\/" string in the below example is specific to procmail and tells
procmail to load the procmail MATCH variable with the contents of the
regular expression following that mark point. Thus, the following recipe
will load the MATCH variable with an empty string if there really is
nothing in those fields.

The [ \t]* part says to ignore any leading spaces or tabs before your
mark point for the match.

The * STRING ?? ^^^^ part tests for an empty string condition.
That nested recipe says to file the email in "file" if "STRING" variable
is empty.


:0
* ^(To|Cc):[ \t]*\/$
{
STRING=${MATCH}
:0
* STRING ?? ^^^^
file
}

Re: how to check for blank or missing "TO" address with procmail?

am 08.12.2005 01:04:17 von Garen Erdoisa

Garen Erdoisa wrote:
> morguns wrote:
>
>> thx for the reply Garen, but still no joy. for some context, i should
>> explain that i'm filtering email for several domains. one address is a
>> catchall for all of the domains; it's this catchall account that's
>> getting spam. them sneaky spammers leave the "To" and "CC" fields blank
>> and instead "BCC" addresses like foipuas@domain.com. i have spam
>> software installed and it's catching _almost_ all spam, but
>> occasionally some get past the spam software.
>>
>> my goal is to create a procmail filter that will catch these occasional
>> messages. your first suggestion would work perfect if it was testing
>> for a blank subject, but it doesn't work for the "To" and/or "CC"
>> fields. your other suggestions don't test for _blank_ "To" and "CC"
>> fields, so they miss the mark.
>>
>> thanks anyway, your input is sincerely appreciated.
>>
> Ok I see your problem.
>
> In this situation you could use the following, presuming the To: or Cc:
> headers are present, but empty.
>
> The "\/" string in the below example is specific to procmail and tells
> procmail to load the procmail MATCH variable with the contents of the
> regular expression following that mark point. Thus, the following recipe
> will load the MATCH variable with an empty string if there really is
> nothing in those fields.
>
> The [ \t]* part says to ignore any leading spaces or tabs before your
> mark point for the match.
>
> The * STRING ?? ^^^^ part tests for an empty string condition.
> That nested recipe says to file the email in "file" if "STRING" variable
> is empty.
>
>
> :0
> * ^(To|Cc):[ \t]*\/$
> {
> STRING=${MATCH}
> :0
> * STRING ?? ^^^^
> file
> }
>

Some more thoughts on this. This would probabally be better for your
specific case.

#Initialize the variables.

TOADDRESS=''
CCADDRESS=''

# extract the To: address list
:0
* ^To:[ \t]*\/
{ TOADDRESS=${MATCH} }

# extract the Cc: address list
:0
* ^Cc:[ \t]*\/
{ CCADDRESS=${MATCH} }

# If both the To: and Cc: address fields are empty, file the email
:0:
* TOADDRESS ?? ^^^^
* CCADDRESS ?? ^^^^
file