procmail
[Top] [All Lists]

Re: Procmail to Fax

1999-09-05 02:46:35
On Sat, 04 Sep 1999 12:01:51 -0700, "Wilkerson, Richard"
<rcwilk(_at_)dreamgate(_dot_)com> wrote:
With the rise of free-fax by email, I would like to have my clients
be able to email in to an autoresponder to get faxed back a text
file.
[I don't know why they prefer it to email, dead trees don't dream]

(Maybe they're on a dialup and hook up only occasionally to send and
receive mail, and don't want to wait for the reply until they poll the
next time, and pay money for downloading your reply. I guess the
latter isn't a big issue in the US, where local calls are typically
not metered, though.)

One of the easiest services is 
remote-printer(_dot_)senders_name(_at_)14157779999tpc(_dot_)int
where "14157779999" is the fax number  and "senders_name" can be
anything.

(I'm not familiar with TPC's policies. If I were them I'd be a bit
miffed about this cost-shifting operation. How about getting your own
fax modem for this? You can get an old 9,600 or 14,400 bps modem dirt
cheap these days -- perhaps even for free. That's all you'll need for
fax traffic.)

my recipie at this time can only send back via email to the sender:

That's because you tell it to. >;-)

 :0
* ^X-Rcpt-To(_dot_)*info(_at_)asdreams\(_dot_)org
* !^X-Loop: webmaster(_at_)asdreams(_dot_)org
* !^FROM_DAEMON
| (formail -r ; cat ../infofiles/help_file) | $SENDMAIL -oi -t

Putting aside for the moment the phone number extraction, the simple
change you need is to construct different headers. formail -r is for
generating reply headers; use something else (such as echo) if that's
not what you want.

    :0
    *   ^X-Rcpt-To: info(_at_)asdreams\(_dot_)org
    * ! ^X-Loop: webmaster(_at_)asdreams\(_dot_)org
    * ! ^FROM_DAEMON
    *   somehow extract the phone number into NUMBER
    | ( echo "To: remote-printer(_dot_)asd-fax(_at_)$NUMBER(_dot_)tpc(_dot_)int 
; \
        cat ../infofiles/help_file ) | $SENDMAIL -oi -t

You can keep some canned headers in help_file to simplify this recipe.
For example, it should probably contain "X-Loop: 
webmaster(_at_)asdreams(_dot_)org"
near the beginning (and an empty line after these additional headers
to separate the headers from the body).

How can I adust this to also
1. read the subject line for a phone number (and preferably strip any
parentheses,  (404)  lines  404-3333  or blanks  404 3333)
and then
2. put that number/string in the OUTGOING mailto: 
3. A third option would take the name in the body of the email if
present and put it in sender_name   or just  substitute something like
"asd-fax"  if not present

This is one of those classic "how would you do it outside of Procmail?"
replies. Write a script which does this and passes the results back to
Procmail.

I think something to replace the echo command above would be a good
idea; something that works more or less like formail -r but, of
course, generates a different To: address (and does whatever other
processing you want -- perhaps there should be some sort of rate
limiting to make sure the same person doesn't order the fax more than
once a day, for example; or if you go with TPC's service, perhaps you
want to be polite and make sure you don't send more than, say, five
faxes a day, ever).

Then you instead end up with a recipe like

    :0
    *  ^X-Rcpt-To: info(_at_)asdreams\(_dot_)org
    * !^X-Loop: webmaster(_at_)asdreams\(_dot_)org
    * !^FROM_DAEMON
    *  ^Subject:.*\/[0-9][-0-9_.()      ]+
    | your_script_here "$MATCH" ../infofiles/help_file | $SENDMAIL -oi -t
    
where the stuff on the Subject condition makes sure there is at least
one digit in the Subject header, followed by one or more digits,
interpunction, and whitespace (the last four characters are space,
tab, closing square bracket, plus). Those are grabbed into MATCH and
the result is passed to the script as the first argument; the second
argument is the name of a file to include.

A quick stab at your_script_here might be something like

    #!/usr/local/bin/perl -w   # hi Stan :-)

    $number = $ARGV[0];
    $number =~ y/0-9//dc;  # zap everything but the numerics

    while (<>)             # loop over input message's lines
    {
        if (! $body)  # we are in the headers
        {
            $body = 1 if (/^$/); # end of headers -- start scanning in body
            next;
        }
        else         # we are looking at the body
        {
            $name = $_;
            $name =~ s/[ \t]+/_/g; change whitespace into underscores
            last;    # we only wanted to look at the first line anyway
        }
    }

    $name = "asd-fax" if ($name =~ m/^_*$/); # replace empty or bogus name
                   # Seriously, this ^^^^ is a weird injured upright smiley
    print <<HERE;
    To: remote-printer(_dot_)$name\(_at_)$number(_dot_)tpc(_dot_)int
    Subject: asdreams info fax
    X-Loop: webmaster\(_at_)asdreams(_dot_)org

    HERE

    if (!open (FILE, $ARGV[1]))
    {
        print "error: Could not open file $ARGV[1]\n";
    }
    else
    {
        print <FILE>;
        close (FILE);
    }

    __END__

This is not very graceful, as it's completely off the top of my head.
Some things will be easier and more natural if you move more
intelligence into the script, and return an error from the script if
there was a problem of some sort. (Then you don't have to pass in the
Subject from Procmail, the script can take care of looking for the
numbers in the Subject line, and prevent stuff such as joke faxes to
911 or 555-1212. formail doesn't worry a lot about getting incorrect
input when you run formail -r because it doesn't have to -- if you
pass in a valid message, it can return a valid return message, no
questions asked, zero down, work at home.)

The flow would then become something like

    :0
    * your conditions again
    {
        :0fw
        | your_improved_script_here ../infofiles/help_file

        :0e:
        autoresponder-failures

        :0
        ! -t
    }

The save I put in after the error is kind of dangerous, you have to
remember to look in autoresponder-failures every once in a while to
see what went wrong with those messages. It would probably be better
to forward those failed requests to postmaster or something instead
(or in addition to saving them here).

Again, I'd suggest buying a fax modem so you can run this locally
instead. The basic recipe should still look more or less like this
(only simpler; you just need to figure out how to send a fax from the
command line and then plonk the same command into your .procmailrc).

Hope this helps,

/* era */

I have secretly assumed that ^X-Rcpt-To: info(_at_)asdreams\(_dot_)org is more
correct than what you originally had there.

-- 
 Too much to say to fit into this .signature anyway: <http://www.iki.fi/era/>
  Fight spam in Europe: <http://www.euro.cauce.org/> * Sign the EU petition

<Prev in Thread] Current Thread [Next in Thread>
  • Procmail to Fax, Wilkerson, Richard
    • Re: Procmail to Fax, era eriksson <=