procmail
[Top] [All Lists]

un-MIME email (esp. HTML and attachments)

2001-04-06 21:16:26


NOTE: I wrapped the following to stay under 70 characters using \
but two lines were too long to do that... the 'This message contains' line and
the 'sed '/^Contatn-Type: / line


You can see the normal formatted version at
http://www.peak.org/~luomat/procmail/antimime.txt


The idea is to remove all MIME stuff, including attachments, which are written
to a password-protected private Web directory

Corrections/improvements/Questions welcome!!

new! the line:
sed '/^Content-Type: /,/^filename=/ { s/name="[[:punct:]]*/name="/g }'

should sanitize any malformed filename that begins with ../ or any such
nonsense.


Tim


#####################################################################
:0
*   ^Mime-Version: 1.0
* ! ^Content-Type:.*Text/Plain
{
#####################################################################
:0
*   ^Content-Type:.*text/html
{
# See notes 1
:0 w fb
|sed -e :a -e 's/<[^>]*>//g;/</N;//ba' |\
cat -s | metamail -q -x 2>&1 |\
fgrep -v 'metamail: Ignoring invalid mailcap entry:'|\
sed -e 's/&copy;\|&#149;\|&nbsp;\|&quot;\|&amp;/ /g' \
-e 's#Warning: Cannot freopen /dev/tty to stdin##g' \
-e 's/=$/ /g' -e 's/=20$//g'
}
#####################################################################
:0E
*   ^Content-type: *\/[^ ].*
{
#change UMASK to chmod 644 for the files that metamail creates
UMASK=022

# Use metamail to filter the body / the 'sed' is in case of an error,
# usually for HTML only messages
:0 w fb
| sed '/^Content-Type: /,/^filename=/ { s/name="[[:punct:]]*/name="/g }' |\
metamail -q -x -b -c "${MATCH}"  2>&1 |\
sed 's#^Warning: Cannot freopen /dev/tty to stdin##g ;\
/^metamail: Ignoring invalid mailcap.*/,1d '

#Change the UMASK back to chmod 600
UMASK=077

:0 fb w
* B ?? ^This message contains (raw digital data|data in an unrecognized format)
* B ?? ^which is being decoded and written to the file named
* B ?? ^If you do not want this data, you probably should delete that file.
* B ?? ^Wrote file
| sed "/^This message contains/,/Wrote file/ \
{  /This message/,/If you do not want/d; \
s/ /%20/g ; s#.*/#ATTACHMENT:\n\t$METAMAILURL/#g}"
}
#####################################################################

# Remove the MIME headers to make sure we don't confuse any mailers
:0 w fh
| formail -I"Content-Type:" \
-I"MIME-Version:" -I"Content-Transfer-Encoding:" \
-A"X-Note: mime-HTML altered"

}

# END OF RECIPE


_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>
  • un-MIME email (esp. HTML and attachments), Timothy J. Luoma <=