user4292942
user4292942

Reputation:

Decode base64 from “content-disposition: attachment” body part

I am trying to extract message body using procmail be it in the message or in an attachment, but I got first two characters from below:

:0B
* ^()[a-z]+[0-9]+[^\+]
{ msgID = "$MATCH" }
:0B
* ^Content-Disposition: *attachment.*(($)[a-z0-9].*)*($)($)\/[a-z]+[0-9]+
| base64 --decode
{ msgID = "$MATCH" }

The decoding of base64 is not working, it's either not matching as whole condition, or assigning LASTFOLDER=base64 --decode"

See also my earlier question

Upvotes: 0

Views: 1590

Answers (1)

tripleee
tripleee

Reputation: 189317

You can't have two actions on a single recipe. Where you have

:0B
* ^stuff\/more stuff
{ msgid="$MATCH" }
| base64 --decode

the second line is a syntax error. I'm guessing you mean something like

:0B
* ^stuff\/more stuff
{
     msgid="$MATCH"
     :0
     | base64 --decode
}

See? If you need more than one action, add a pair of braces (don't forget the closing braces at the end!) around another group of recipes as the action section. Maybe see also http://www.iki.fi/era/procmail/quickref.html

But in your case, you apparently want to extract the token base64 decoded, so the code you are looking for would be

:0B
* ^Content-Disposition: *attachment.*(($)[a-z0-9].*)*($)($)\/[a-z]+[0-9]+
{ msgID=`echo "$MATCH" | base64 --decode` }

Notice also that you cannot have a space around the equals sign. And the regex is incorrect for arbitrary base64; plus and slash are also among the allowed characters, and equals at the end. Change the part after \/ to [a-z0-9/+]+=*

Upvotes: 1

Related Questions