procmail
[Top] [All Lists]

Re: Recipe setup...

1997-11-29 12:18:00
On Sat, 29 Nov 1997, Jason Lixfeld wrote:
SHELL=/bin/sh
PATH=/bin:/usr/bin
MAILDIR=$HOME/mail      #you'd better make sure it exists
LOGFILE=$HOME/.procmail.log   #recommended
#VERBOSE=yes

:0 D
*
{  
SUB=`formail -x Subject: | awk '{print $1}' | sed s/:/""/`  
}

In the recipe above, what is the * for? If there is no condition to
test for, there is no need for that line at all. And if there are no
conditions to test that use procmail's internal egrep, then the D flag
is moot as well. 

Secondly, be aware that your awk\sed routine grabs any leading subject
word, stripping a trailing colon if there is one. Therefore if subject
is "Re: Your mail" then the recipe below delivers to a filename
"/home/admin/mail/Re".

Now, there is no need to use a recipe, unless there are conditions to
test for. You can replace the entire recipe above with one line:

SUB=`formail -x Subject: | awk '{print $1}' | sed s/:/""/`

:0 c
/home/admin/mail/$SUB

:0 c
/tmp/admin.mail.backup

You should add a colon after the 'c' flag on the recipe above and to
make procmail use filelocking on the files written to. Otherwise you
risk corruption of those files. You see, each mail processed begins
it's own run of procmail. There can be multiple processes of the same
script, and simultaneous attempts to write to the files. So you need
file locking, thus:

:0 c:

:0 Ah
| mkdir /webhome/server/htdocs/archive/$SUB ; \
chmod 755 /webhome/server/htdocs/archive/$SUB ; \
/usr/local/bin/mhonarc -outdir /webhome/server/htdocs/archive/$SUB \
/home/admin/mail/$SUB ; \
/bin/chmod 644 /webhome/server/htdocs/archive/*/*

The above recipe probably should _not_ do filelocking within procmail
if mhonarc uses filelocking, and I think it does, from reading
mhonarc's helpfile. If procmail locked a file that monarch wanted to
lock, you'd likely cause hung processes and get in trouble with your
admin.          ;-) 

David Hunt


Thats it! :)  It works, thanks all!  Any questions?! =P

On Sat, 29 Nov 1997, no-mailbox wrote:

On Sat, 29 Nov 1997, Jason Lixfeld wrote:
:0 D
*
{
SUB=`formail -x Subject: | awk '{print $1}' | sed s/:/""/`
}

Is there a condition to be satisfied above? If not you don't need to
use the * to start a test of a condition.

:0 c
* ^Subject:.*\<$SUB\>
/home/admin/mail/$SUB 

procmail: No match on "^Subject:.*\<$SUB }"
procmail: Locking "/var/spool/mail/admin.lock"
procmail: Error while writing to "/var/spool/mail/_rv2Gsuntzu.ad"

Could you be more specific about what sort of strings there are to be
matched? If you are just trying to find mail Subject: "BSDI:"? or is
there a set of possible keywords that get filed? When I run your
awk\sed command it just reduces a string 'STRING: whatever" to
"STRING".

To get the contents of a subject field into a variable use:
     SUBJECT=`formail -zx"Subject:"`
You can manipulate the contents of the var a number of different ways.
I think you could so the same thing your awk\sed command does with:
     SUBLEADER=`formail -zx"Subject:|cut -d: -f1`
You can then test the var in a recipe condition line for a certain
leader, eg. TEST:
     * $ SUBLEADER ?? '^TEST$'

To find a particular subject-leader, eg. "TEST:", and file a copy of
that mail in the file ~/home/mail/TEST" while letting the original
continue through procmail for delivery elsewhere, do this: 
(You don't need to capture the subject into a variable for this.)
( [^  ] contains a carat, a tab, and a space.)
     :0 cD:
     * ^Subject:[^    ]*TEST:
     /$HOME/mail/TEST

To file mail by a variety of fixed subject LEADERS:
     :0 cD:
     * ^Subject:[^    ]*(LEADER1|LEADER2|LEADER3|LEADER4):
     * ^Subject:[^    ]*\/(LEADER1|LEADER2|LEADER3|LEADER4)
     /$HOME/mail/$MATCH

Condition 1 above first checks for a leading word in the subject
matching any of the leaders followed by a colon. Condition 2 is less
picky, but captures the leader into a special var named MATCH without
capturing anything else, like the colon. You could use only the second
condition, but it could get LEADER without the colon.

With some more specifics I might be able to suggest something
particularly suited to your specific goals.

David Hunt


The above, broken part is where I try to save the message to the file
called the variable which was created above (procmail: Assigning
"SUB=BSDI").  Technically, I should be able to assign the directory
by some method similar to what is written in the :0 c portion of the
recipe.

Anyone know how I can do that?!  Does everyone see what I'm trying to do?

On Fri, 28 Nov 1997, no-mailbox wrote:

On Fri, 28 Nov 1997, Jason Lixfeld wrote:

Jason,
I think the problem is the first recipe. You cant set  avariable in an
action line like you did because it gets executed in a subshell. You
have to use curly-braces and drop the flags. Your first recipe
modified:

## IE: message comes in with subject of "BSDI: TEST" >
## writes subject to $DETAILS variable: BSDI
:0 D
*
{  DETAILS=`formail -x Subject: | awk '{print $1}' | sed s/:/" "/`  }

I dont' know awk and sed well, but it seems to simply reduce the
subject line to the first word, minus the colon. You could use this: 
:0 D
* ^Subject:[       ]*BSDI: TEST
{  DETAILS=BSDI }

Of course, that only demonstrates the job. You'd have to customize for
your needs. There are other ways to do this, but I'd have to
understand the needs better.

The next recipe copies to a file named BSDI. You need to use a fulll
path, and procmail does not recognize tilde. I'm guessing ~admin is a
typo for ~/admin so then the recipe is:
## finds messages with BSDI in subject and copies to ~admin/mail/BSDI
:0 c
* ^Subject:.*\<$DETAILS\>
$HOME/admin/mail/$DETAILS

Good Luck!
David Hunt

:0 Ah
## Mhonarc then archives all new mail within /home/admin/mail/BSDI file,
#chmods (not proprietary to procmail), then nukes the old box BSDI so 
when
#mhonarc runs again, all it has to do is archive the newest message, and
#not all of them.
| mhonarc -outdir /webhome/server/htdocs/archive 
/home/admin/mail/$DETAIL\
; chmod 755 /webhome/server/htdocs/archive/* ; rm -rf \
/home/admin/mail/$DETAIL

It doesn't work.  I'm not sure if procmail can accept variables or not,
but anyone who can understand the above recipe, please see if their is
anything wrong with it.  BTW:  The commnets that are added into the
procmailrc were added for this email only.

Thanks in advance!

Regards,

Jason A. Lixfeld

.oO
System Administrator [Level 4]
TUCOWS Interactive Inc. o/a Internet Direct
Moo... "A Different Kind of Internet Company"
Oo.

jlixfeld(_at_)idirect(_dot_)ca  \
              \  jlixfeld(_at_)idirect(_dot_)com





Regards,

   Jason A. Lixfeld

.oO
System Administrator [Level 4]
TUCOWS Interactive Inc. o/a Internet Direct
Moo... "A Different Kind of Internet Company"
Oo.

jlixfeld(_at_)idirect(_dot_)ca  \
                 \  jlixfeld(_at_)idirect(_dot_)com





Regards,

      Jason A. Lixfeld

.oO
System Administrator [Level 4]
TUCOWS Interactive Inc. o/a Internet Direct
Moo... "A Different Kind of Internet Company"
Oo.

jlixfeld(_at_)idirect(_dot_)ca  \
                    \  jlixfeld(_at_)idirect(_dot_)com






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