procmail
[Top] [All Lists]

Re: Detaching e-mail attachment to a folder automatically

2005-06-22 09:09:35
OK, again,

Am 2005-06-21 13:14:10, schrieb Michelle Konzack:
Am 2005-06-21 08:02:32, schrieb mandeep:
Hi,
    I receive a .DAT file as an attachment once or twice a day in my

Are this the winmail.dat files or does the Files
have each time differen names you get a message?

If it is the first one ("winmail.dat"), you need to rename it using
'date +s%' for example:

----8<----------------------------------------------------------
:0 i
* ^To:(_dot_)*mandeep(_at_)somedomaine(_dot_)tld
* ^Content-Type:.*multipart/mixed
* B ?? filename=winmail\.dat
|/path/to/your/script
----8<----------------------------------------------------------

    1)  it check for the right E-mail address
    2)  check whether the message is a multipart/mixed
    3)  check whether in teh BODY of the message is a
        "filename=.*\.dat" string
    4)  and if the above three conditions are true, 
        pipe the Message through the script

And then in your script you write:

----8<----------------------------------------------------------
#!/bin/bash

# because 'munpack' extract all Files of a message we create
# a temporary directory where we can extract our stuff
mkdir -p /tmp/mandeep

# Make it read/write only to us as owner
chmod 700 /tmp/mandeep

# now we pipe the Message through 'munpack' which decode the
# files into our temporary directory
cat /dev/stdin |/usr/bin/munpack -q -C /tmp/mandeep/

# now we move the winmail.dat to our final destination with
# a new name
mv /tmp/mandeep/winmail.dat $HOME/.dat/`date +%s`.dat

# finaly we remove the temporary directory with its content
rm -rf /tmp/mandeep
----8<----------------------------------------------------------

Thats all, if you receive only those WINMAIL.DAT files from a
Windows-Box.

If you get *.dat files with an uniq name, you should:

----8<----------------------------------------------------------
:0 i
* ^To:(_dot_)*mandeep(_at_)somedomaine(_dot_)tld
* ^Content-Type:.*multipart/mixed
* B ?? filename=.*\.dat
|/path/to/your/script
----8<----------------------------------------------------------

and for the script

----8<----------------------------------------------------------
#!/bin/bash

# because 'munpack' extract all Files of a message we create
# a temporary directory where we can extract our stuff
mkdir -p /tmp/mandeep

# Make it read/write only to us as owner
chmod 700 /tmp/mandeep

# now we pipe the Message through 'munpack' which decode the
# files into our temporary directory
cat /dev/stdin |/usr/bin/munpack -q -C /tmp/mandeep/

# now we move the *.dat file(s) to our final destination
mv /tmp/mandeep/*.dat $HOME/.dat/

# finaly we remove the temporary directory with its content
rm -rf /tmp/mandeep
----8<----------------------------------------------------------

Greetings
Michelle

-- 
Linux-User #280138 with the Linux Counter, http://counter.li.org/
Michelle Konzack   Apt. 917                  ICQ #328449886
                   50, rue de Soultz         MSM LinuxMichi
0033/3/88452356    67100 Strasbourg/France   IRC #Debian (irc.icq.com)


____________________________________________________________
procmail mailing list   Procmail homepage: http://www.procmail.org/
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

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