procmail
[Top] [All Lists]

Re: Help: running a C program when mail arrives

1996-08-08 13:39:10
    > How can I run a C program after I recieve a message.  

This is pretty easy.  Please read the man page for procmailrc for details.
Say the C program is called "foo".  This following recipe will run "foo"
for each incoming message.

    :0
    | foo

    > I have tried multiple differant things.

Such as??  It is very difficult to give specific corrections, when there
are no examples for input.

    > I do not want to pipe my message to this program.

So.. don't.  Procmail makes the incoming message available on STDIN for
every command it invokes.  It is up to the program to use STDIN or not,
or redirect it.

If the program "foo" (above) doesn't use STDIN, then the recipe would
still be the same:

    :0
    | foo

If "foo" does something with STDIN, and you don't want the mail being
available to "foo", just redirect STDIN from /dev/null or whatever is
appropriate. 

    :0
    | foo </dev/null

    > Also when procmail saves a message to a folder it seems to add an
    > extra line to the file, is there any way to disable this.  Thanks.

If, by folder, you mean a non-MH style folder, then the "extra line" may
be the separator between consecutive mail messages.  Without this
separator, some mailers cannot properly separate multiple messages in
the same folder.

MH-style folders, on the other hand, are directories.  And the messages
are stored in sequentially numbered filenames (ie: dir/1, dir/2, dir/3,
etc.).  There should be no "extra line" at the end of these files,
unless you are saving only the headers and its separator line.   

For example, if you use the "h" flag on a file-saving recipe, then
you'll get a blank line at the end of the headers--this blank line
defines the end of the message headers.

    :0h
    dir/savedmail/.

Will write the incoming messages into a unique, sequentially numbered
file in the directory "dir/savedmail", and the file will have a blank
line at the end because only the headers are being saved.

If you are not sure how procmail works, try using the following skeleton
procmailrc file, with the sample mail message as input.  You can modify
this little test recipe file to suit your needs.

testrc
============================= cut here ===================================
VERBOSE=yes
LOGABSTRACT=all
SENDMAIL=true                   # just in case

# Place test recipes here

# Show that testout has a blank line at the end of the headers
:0h
testout

# This recipe shows the current mail headers in the log, but not
# the blank line separator [WHY?].
:0h
LOG=|cat

# This recipe shows the current mail body in the log
:0b
LOG=|cat

#Show the entire message
:0
LOG=|cat

# Cause procmail to stop, and not do anything else with the mail
HOST

============================= cut here ===================================

If your input mail is called "testmail", then run procmail like this:

    procmail -m testrc < testmail

and watch STDOUT for procmail logging output.

Hope this helps.
_____________________________________________________________________
Alan Stebbens           <stebbens(_at_)sgi(_dot_)com>             (415) 933-6437
Digital TV, Silicon Interactive Group,  Silicon Graphics, Inc.  (SGI)
M/S:9L991,     2011 N. Shoreline Blvd.,     Mountain View, CA   94043
PGP Key Fingerprint: 94 A7 4B AB 1C F0 4D 92  DD BC B5 D7 11 A0 DC B3

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