I am using postfix to call a perl script so as to store emails in a database. The emails are in different code pages. UTF8 Windows 1256 etc and I my not even know ahead of time which code page. I can parse that information out of the start of the subject line using:
my $subject = $email_in->header("subject");
my @charset_test = split(/=\?/,$subject);
my @charset = split(/\?B\?/,$charset_test[1]);
Using Email:: Simple I am able to get the parts of the headers and the body but I am hitting difficulties in decoding from Base64 and then using the character set that the email is in and post it to the database fields. So far all the fields I am populating are nonsense.
I would be grateful for any pointers
Thanks
# read email pipe input and put it in a variable $mbox to be # parsed
#
my $mbox = "";
while (<STDIN>) {
$mbox = $mbox .$_ ;
}
# Parsing out variables
#
my $email_in = Email::Simple->new($mbox);
my $from_raw = $email_in->header("From");
my $to = $email_in->header("To");
my $subject = $email_in->header("subject");
my $body = $email_in->body;
$body = decode_base64($body); # Translate the contents of the email from Mime base 64
my @from_add = Email::Address->parse($from_raw); #removes all extra data that can confuse the search so as to only look at the pure email address.
my @from_name = split(/</,$from_raw); #extracts the first part of the email address to get the name shown on the email.
my $from = $from_add[0]->address; #extract only the x@x
I note also that if I try to do $subject=decode_base64($subject); I get an empty string. In reply to parsing emails to send to database by Tearlach
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |