On Wed, 24 Sep 1997 10:18:56 +0200 (CEST),
Antonio Colella <acll(_at_)linux02> wrote:
1)Select all incoming mail which contains _only one_ attachment
2)Verify the name of the file attached;
MIME, which I presume you are talking about, is slightly quirky in
that there are often several ways to accomplish the same thing. If you
want a really general solution, there are situations such as messages
embedded inside other messages to look out for. Etcetera. Samples from
the messages you want to process would be a good help.
Here's a sketch to get you started:
# Check that there is at most one Content-type: application/octet-stream
:0B
* 2^0
* -1^1 ^Content-type:[ ]*application/octet-stream
{
# Okay, if there is one, grab its file name
:0B
* ^Content-type:[ ]*application/octet-stream;[ ]*name="\/[^"]+
{
# If the name is "grubor.txt", extract it
:0
* MATCH ?? ^^grubor\.txt^^
| metamail -w
}
}
Caution: I haven't tested this, or done anything like it ever.
And this doesn't solve the following problems:
* metamail is a lousy tool. You should probably break down and write
a Perl script to do the MIME processing if doing it exactly as you
want it is important. munpack is slightly better, but still not
very feature-rich or versatile.
* metamail will just use the given file name. You could pass it all
through sed first to rename the file to what you want to call it.
A better solution, IMHO, would be to save the whole message to an
MH folder and let Procmail just give it a number, which will turn
up in LASTFOLDER, then continue processing after that, perhaps in
the background or from a cron job.
* MIME allows, at least in principle, rather free-form headers (by
implication; the definition is in RFC822). In practice you almost
never see this used, so you could say it's "safe" to assume you
will only receive machine-generated headers that the above recipe
will catch (depending on your situation)
To the best of my knowledge, there are no really good MIME extraction
tools out there. The MIME FAQ has pointers to more information,
perhaps you'll be able to find something you can use. (Pointers to
better tools gladly accepted. I have only briefly looked at metamail
and munpack.)
if it's the right name extract it in a subdirectory and give it a
name like xxx.n where n is a progressive number, acknoledge to the
sender with this number in the body of the message
otherwise discard the message and reply to the sender.
There are several "otherwise" branches. I'd assume you only want to
auto-respond in the case when there was a file attachment but it had
the wrong name? Anyhow, suitable code is available from many examples.
(Hint: formail -rt)
Please reply to colella(_at_)magritte(_dot_)sci(_dot_)uniroma1(_dot_)it
Please fix your return address. You may have to recompile Pine.
See <http://www.netusa.net/~eli/faqs/addressing.html>
/* era */
Pointers to relevant parts of the MIME FAQ can be found at
<http://www.iki.fi/~era/procmail/links.html> near the end.
--
Paparazzi of the Net: No matter what you do to protect your privacy,
they'll hunt you down and spam you. <http://www.iki.fi/~era/spam/>