Decrypt the utf8 message according to ISO-8859-1 with the text in the .procmailrc file

Set up a simple procmail recipe that would forward mail if it found the text "ABC Store: New Order" in the subject.

:0 * ^(To|From).* abc@cdefgh.com * ^Subject:.*ABC Store: New Order* { 

Unfortunately, the subject field in the mail message received from the mail server was contained in the syntax of the MIME-encoded word.

Subject: =? UTF-8? B QUJDIFN0b3JlOiBOZXcgT3JkZXI =? =

The above question is charset utf-8 ISO-8859-1. So it was interesting if there were any mechanisms / scripts / utilities for parsing this and converting to string format so that I could apply my procmail filter.

+7
email encoding perl utf8-decode procmail
source share
2 answers

You can use perl one liner to decode Subject: before setting up the procmail variable.

 # Store "may be encoded" Subject: into $SUBJECT after conversion to ISO-8859-1 :0 h * ^Subject:.*=\? SUBJECT=| formail -cXSubject: | perl -MEncode=from_to -pe 'from_to $_, "MIME-Header", "iso-8859-1"' # Store all remaining cases of Subject: into $SUBJECT :0 hE SUBJECT=| formail -cXSubject: # trigger recipe based also on $SUBJECT content :0 * ^(To|From).* abc@cdefgh.com * SUBJECT ?? ^Subject:.*ABC Store: New Order { .... } 
+9
source share

You must use MIME::EncWords .

Like this

 use strict; use warnings; use 5.010; use MIME::EncWords 'decode_mimewords'; my $subject = '=?UTF-8?B?QUJDIFN0b3JlOiBOZXcgT3JkZXI=?='; my $decoded = decode_mimewords($subject); say $decoded; 

Exit

 ABC Store: New Order 
+1
source share

All Articles