Harry Putnam | 3 Mar 17:21 2010

Using $SENDMAIL $SENDMAILFLAGS

I've used this statement for yrs in ~/procmailrc

 :0 
  * ^To: user <at> host.some.com
    |$SENDMAIL $SENDMAILFLAGS reader <at> newsguy.com

But don't really know the details of what it really does.

I've run into a problem where I've set a filter on my Mail server
(newsguy.com) to delete messages not addressed to me.

On a remote machine... a cron job when it completes, sends mail to
simply `USERNAME'... so USERNAME on that machine is sent mail
From: root <at> host.some.com 
To: USER <at> host.some.com

The filter above sends the message on to reader <at> newsguy.com

I'm only guessing here, as to how the newsguy filtering works:
  OK, but my filter at newsguy is deleting these messages.  Apparently
  they are still addresses to user <at> host.some.com so they are seen as
  not being to my newsguy address.

But I assumed the 

  |$SENDMAIL $SENDMAILFLAGS reader <at> newsguy.com

Rewrote the To: line so it would be reader <at> newsguy.com

What are the details of what the clause:
(Continue reading)

Charles Gregory | 3 Mar 17:29 2010

Re: Using $SENDMAIL $SENDMAILFLAGS

On Wed, 3 Mar 2010, Harry Putnam wrote:
> :0
>  * ^To: user <at> host.some.com
>    |$SENDMAIL $SENDMAILFLAGS reader <at> newsguy.com

You can either use 'formail' to change your 'To:' header
(via a 'filter' in procmailrc), or you can adjust the receiving filter so 
that it whitelists mail from the mail server doing the forwarding
(by filtering for the appropriate 'Received' header).

- C

Re: Using $SENDMAIL $SENDMAILFLAGS

At 10:21 2010-03-03 -0600, Harry Putnam wrote:
>I've used this statement for yrs in ~/procmailrc
>
>  :0
>   * ^To: user <at> host.some.com
>     |$SENDMAIL $SENDMAILFLAGS reader <at> newsguy.com
>
>But don't really know the details of what it really does.

SENDMAIL is set to the path to the binary for the MSA.  SENDMAILFLAGS are 
the flags commonly used to invoke it.  Normally, you shouldn't need to PIPE 
it. use ! (forward):

:0
* ^To: user <at> host\.example\.com
! reader <at> newsguy.com

! basically invokeds $SENDMAIL $SENDMAILFLAGS _address_  Note that because 
! is doing this, you can specifiy MSA flags right after the ! - everything 
needn't bee an address.

Having the two variables however is very handy.  My sandbox configuration 
for example redefines $SENDMAIL to point to a helper script, which merely 
emits the message and commandline arguments to a logging mailbox - very 
useful for testing forward and remailing recipes without having to hack 
anything in the recipe itself (which is a leading way to introduce 
errors).  Thus, when testing a recipe which generates mails, no actual mail 
is introduced to the real MSA - but I can review the logs to see how the 
MSA would have been invoked, and was was being handed to it.

(Continue reading)

Harry Putnam | 5 Mar 01:35 2010

How to set a VARIABLE value with a filter

I think I've done this before but can't find it in old .procmailrcs.

If I wanted to filter certain line in the body and re-write them back 
to the message, but in the header... 

1) extract something from body into a variable seen by procmail
2) Remove all subject headers
3) Insert new subject header with the VAR from 1 folded under it.

example of desired result:

  `Subject: my incoming subject
       -folded material that was extracted from body
       -more of the same'     

I'm thinking something like the code below.  No doubt poorly written
but hopefully the intent will be apparent.

  :0
  * ^Subject:\/.*$
   {
     { 
      :0 cb
        ## Here I want the output of somescript to become the value
        ##  of a variable procmail is aware of.   
        | somescript

#        ## These concoctions below do not get the desired result
#        myvar=|somescript
#        |myvar=$(somescript)          
(Continue reading)

Harry Putnam | 5 Mar 01:13 2010

Re: Using $SENDMAIL $SENDMAILFLAGS

Charles Gregory <cgregory <at> hwcn.org> writes:

> On Wed, 3 Mar 2010, Harry Putnam wrote:
>> :0
>>  * ^To: user <at> host.some.com
>>    |$SENDMAIL $SENDMAILFLAGS reader <at> newsguy.com
>
> You can either use 'formail' to change your 'To:' header
> (via a 'filter' in procmailrc), or you can adjust the receiving filter
> so that it whitelists mail from the mail server doing the forwarding
> (by filtering for the appropriate 'Received' header).

Thanks... 

[...]

Harry wrote:
>>But I assumed the
>>
>>   |$SENDMAIL $SENDMAILFLAGS reader <at> newsguy.com
>>
>>Rewrote the To: line so it would be reader <at> newsguy.com

Sean replied:
> No, the address specified on the commandline is treated as a BCC.

Theres' what I was after...

> If you want to rewrite the to, pipe it through formail to do so, THEN
> forward it (but be wary of using arguments to sendmail to "parse the
(Continue reading)

Patrick Plattes | 5 Mar 14:52 2010

Mail forwarding with regex

hello list :-),

i'm new here and i'm really not a guru of procmail, so i hope its not
a boring question to you i want to ask. i have two domains foo.net and
bar.net. now i wan't to map A to B. So everything to user <at> foo.net
should be forwarded to user <at> bar.net. i don't have any access to the
mailserver config, so i want to do somethink like this:

:0H
* ^TO(.*) <at> foo.net
! $1 <at> bar.net

user1 <at> foo.net -> user1 <at> bar.net
user2 <at> foo.net -> user2 <at> bar.net
user3 <at> foo.net -> user3 <at> bar.net
user4 <at> foo.net -> user4 <at> bar.net
user5 <at> foo.net -> user5 <at> bar.net
user6 <at> foo.net -> user6 <at> bar.net
user7 <at> foo.net -> user7 <at> bar.net
user8 <at> foo.net -> user8 <at> bar.net
user9 <at> foo.net -> user9 <at> bar.net
user10 <at> foo.net -> user10 <at> bar.net
user11 <at> foo.net -> user11 <at> bar.net

thanks,
 patrick

--

-- 
Niemann + Frey GmbH
Adolf-Dembach-Str. 24
(Continue reading)

Michelle Konzack | 5 Mar 19:23 2010
Picon

Re: How to set a VARIABLE value with a filter


TMP_VAR1=`somescript`
TMP_VAR2=`formail -czX Subject:`

:0fw
| formail -a "${TMP_VAR2} ${TMP_VAR2}"

NOTE:  Do not use "\n" in a message header but let formail do the job.

Thanks, Greetings and nice Day/Evening
    Michelle Konzack
    Systemadministrator
    24V Electronic Engineer
    Tamay Dogan Network
    Debian GNU/Linux Consultant

--

-- 
Linux-User #280138 with the Linux Counter, http://counter.li.org/
##################### Debian GNU/Linux Consultant #####################
<http://www.tamay-dogan.net/>                 Michelle Konzack
<http://www.can4linux.org/>                   Apt. 917
<http://www.flexray4linux.org/>               50, rue de Soultz
Jabber linux4michelle <at> jabber.ccc.de           67100 Strabourg/France
IRC    #Debian (irc.icq.com)                  Tel. DE: +49 177 9351947
ICQ    #328449886                             Tel. FR: +33  6  61925193
LuKreme | 5 Mar 19:40 2010

Re: Mail forwarding with regex

On 05-Mar-10 06:52, Patrick Plattes wrote:
> hello list :-),
>
> i'm new here and i'm really not a guru of procmail, so i hope its not
> a boring question to you i want to ask. i have two domains foo.net and
> bar.net. now i wan't to map A to B. So everything to user <at> foo.net
> should be forwarded to user <at> bar.net.

First off, procmail is not an MTA. this *will* cause problems.

> :0H
> * ^TO(.*) <at> foo.net
> ! $1 <at> bar.net

$1 is the first argument from the commandline invocation, it is not what 
you want. Something like this (untested) should work, or at least get 
you in the right direction

WS=" 	" #space and tab

         :0
         * $ ^To:[$WS]+\/[^$WS].*
         { TO=$MATCH }

         :0
         * TO ?? ^\/[^ <at> ]+
         { TO_USER=$MATCH }

         :0
         * TO ?? example\.com
(Continue reading)

Christopher L. Barnard | 5 Mar 20:08 2010

why is this not right?

I am attempting a multi-check rule.  It is not working correctly.  I am
seeing two errors in my logfile.

In my rc.maillist file, the rule should be:

If the subject: line matches, then the email should go in different mail
folders depending upon the From: line.  If the From: line does not
match, go into the everything-else bucket.

(Thats one huge line for the ^Subject, my mailer is trying to be helpful
and injecting <cr> into this email)

rc.maillist snippet:

:0:
* ^Subject:.*(Distribution List for Vault|Tapes brought onsite|Vault Status|Repo
rt to Accompany off-site Media|Picking List for Robot|Picking List for Vault|Det
ailed Distribution List|Off-site Inventory|cleaning stats|problems log) {

  * ^From:.*<root <at> rudun-nbmaster00
  /opt/home/cbarnard/bkup.rudu-nbmaster-vault

  * ^From:.*dmznb
  /opt/home/cbarnard/bkup-dmznb-vault

  * ^From:.*nbmaster.cc1.rpslmc.edu
  /opt/home/cbarnard/bkup-nbmaster-vault

}

(Continue reading)

Charles Gregory | 5 Mar 20:06 2010

Re: Mail forwarding with regex

On Fri, 5 Mar 2010, LuKreme wrote:
> First off, procmail is not an MTA. this *will* cause problems.

+1

> Something like this (untested) should work, or at least get you in the 
> right direction

Given the tendency for various mail clients to use almost anything for a 
'To' header, including multiple recipients, mailing list addresses, etc,
the OP's best bet is to find the header inserted by the MTA for the 
actual recipient of that e-mail. In my postfix, the header is 
"Delivered-To:".

Keep in mind that mail forwarded internally may have multiple Delivered-To 
headers, but ignoring that case, it should be as simple as:

: 0
* ^Delivered-To: .*\ <at> example.com
* ^Delivered-To: \/[^\ <at> ]+
! $MATCH <at> example.net

- Charles

Gmane