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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.