procmail
[Top] [All Lists]

Re: Renaming file attachments (read: metacharacters are evil)

2002-01-05 14:24:05

This is untested but may get you started


:0
*   ^Mime-Version: 1.0
* ! ^Content-Type:.*Text/Plain
{

        :0 B
        * ^Content-Disposition: attachment.*filename=
        * ^Content-Type:.*name=\/
        {
                # Remove and " marks from the $MATCH
                FILENAME=`echo $MATCH | tr -d '"'`
        
                # Change spaces to _ and then delete any characters you do
                # not want, like  this: tr -d 'BAD1|BAD2|BAD3' where BAD1..3 
            # is a single character
                NEWNAME=`echo $FILENAME | tr ' ' '_' | tr -d '/|\|%'`
        
# Watch for linewrap... that SED line below is ONE long line
:0 fb w
| sed "/Content-Type:/,/Content-Disposition:/ { 
s/name=\"$FILENAME\"/name=\"$NEWNAME\"/g }"
        
        }

}



_______________________________________________
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>