Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Procmail and extracting attachments

735 views
Skip to first unread message

Holly J. Sommer

unread,
Nov 7, 1998, 3:00:00 AM11/7/98
to
Greetings. I've RFTM'ed enough to get half of a coordinated pair of
scripts
to work. What the two scripts are to do is this:

Localhost:
regularly mail off an updating jpg to a remote account (code below)
Remote host:
upon receipt of the email, extract the attached jpg to a specific
directory

Obviously, sendmail is used for the first (called through a perl
script), and from
what I can gather, I should use procmail for the second, but I'm
completely
unfamiliar with procmail. I've done a pretty good amount of searching on

DejaNews and the web, and the closest I can find in articles addressing
this
is in dealing with stripping out MIME content which isn't text/plain,
before
passing it on to a listserv.

If anyone can point me towards, or provide me with a recipe for
extracting
and moving the attachment to a pre-defined directory, I'd appreciate it
:)
The remote machine is running Linux, fwiw.

Thanks!

-Holly

-->Local mailing script <--
#!/usr/bin/perl
# Mailjpg, by Holly Sommer (c) 1998
# Mimencodes a file, and sends it to a recipient
#
# Handy for firewalls that don't allow ftp PUT or passive ftp
connections

$date = `date`;
$boundarydate = $date;
$boundarydate =~ s/(\s+)/_/g;
$encodedpic = `mimencode -b testpic.jpg`;
open (MAIL, "| /usr/sbin/sendmail -t") || die "Can't open sendmail!\n";
print MAIL<<"END1";
To: remoteaccount\@some.net
From: updater\@another.net (Images)
Mime-Version: 1.0
Content-Type:
multipart/mixed;boundary="============_-$boundarydate==_============"

--============_-$boundarydate==_============
Content-Type: IMAGE/jpeg; name="new.jpg"
Content-Transfer-Encoding: BASE64
Content-Description: Updated jpeg

END1
print MAIL $encodedpic;
print MAIL "\n--============_-$boundarydate==_============--\n\n";
close (MAIL);

<--Local mailing script -->

--
"Brevity is the soul of wit, and the essence of lingerie."
-George Will, commencement address to Washington University 15.5.98


Holly J. Sommer

unread,
Nov 7, 1998, 3:00:00 AM11/7/98
to

Ken J. Wright

unread,
Nov 10, 1998, 3:00:00 AM11/10/98
to Holly J. Sommer
Holly,

Here are some simple sample files for you to get started. I'm not an
expert. Just did some "follow the leader" to get what I needed ;-)

This is the .procmailrc file in user's home directory. getxls is just a
shell script that shuffles some files, as metamail will place files in
the /tmp directory.
----------------------------------------------------------
# procmail filter to extract excel spreadsheet
:0
*^To:.*user@domain
|/usr/bin/metamail -r -x -q -w; /var/local/excel/getxls
----------------------------------------------------------

This is the .forward file in the user's home directory
----------------------------------------------------------
"|IFS=' '&&exec /usr/bin/procmail||exit 75"
----------------------------------------------------------

metamail does the work of extracting the attachment. Read the man page &
play a bit & you should get the idea. Also the 'aliases' section of the
sendmail man page helps with some of the .forward syntax. The procmail
man pages give samples

Cheers!

Ken

Holly Sommer

unread,
Nov 11, 1998, 3:00:00 AM11/11/98
to
Holly J. Sommer wrote:

> Greetings. I've RFTM'ed enough to get half of a coordinated pair of
> scripts to work. What the two scripts are to do is this:
>
> Localhost:
> regularly mail off an updating jpg to a remote account (code below)
> Remote host:
> upon receipt of the email, extract the attached jpg to a specific
> directory

Well, more research turned up the answer on my own, and since nobody has
nibbled here, I figured I may as well post the answer.

In short, procmail *itself* wouldn't do the extraction. Rather, I set it
up to make a decision about whether the incoming mail is one which
requires extraction (grepping on a specific line, like say, Subject:, if
you know the subject line ahead of time, for a match) and then pipes it
to an external script, to run the extraction process.

In my particular case, I set up the external script to read through the
in-bound mail line by line until hit hits the Content-type: headers of
the attachment, and then it stores the base64-encoded into a local
array, and when finished (ie: reaches the closing MIME boundary tag) is
feeds the array to mimencode -u )

Pretty nifty set of automation :) Anyone interested in the exact details
can email me.

-Holly

0 new messages