Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

email parsing problem?

by Octavian (Monk)
on Dec 10, 2003 at 19:34 UTC ( [id://313827]=perlquestion: print w/replies, xml ) Need Help??

Octavian has asked for the wisdom of the Perl Monks concerning the following question:

Ok, I have what I thought would be a simple concept turning into a real pain. Basically, the thought is this: A user from wherever sends an email to our HPUX machine (using perl 5.6.1) with a file attached to the email. The HPUX machine has an alias that calls a perl script. This perl script simply throws STDIN into an array, and prints out the contents to a file. such as:
@stuffin = <STDIN>; open(tofile,">/tmp/filename"); foreach $line(@stuffin) { print tofile "$line"; } close tofile;
now, for normal text files, works like a charm....but we now have people that are trying to send us xml stuff (of which I dont know hardly anything about), and for some reason, several characters are being replaced with other chars, causing it to not work correctly...an example is:
xmlns="http://www.com" xmlns:xsi="http://www.foo.com"
becomes
xmlns3D"http://www.com" =xmlns:xsi3D"http://www.foo.com"
any ideas why stuff like 3D gets put in there, and how to I get rid of that stuff?

Replies are listed 'Best First'.
Re: email parsing problem?
by holo (Monk) on Dec 10, 2003 at 20:12 UTC

    You are parsing data incorrectly (try long lines or lines starting with "--" to get a bunch of email-control characters.

    Use Mail::Message to get attachments out of the email and manipulate mime types better.

    use Mail::Message; my $fromline = <STDIN>; my $msg = Mail::Message->read(\*STDIN); if($msg->isMultipart) { for($msg->body->parts) { open(my $tofile,">/tmp/filename") or die "Error opening tmpfile: $!"; $_->print($tofile); close $tofile; # print } }

    As you might guess, multiple attachments are also handled correctly.

      That looks like a pretty good idea, we dont have Mail::Message installed though...so its not gonna help..I will see about getting that module, but making a change to our version of perl takes forever (yes, I work for the government)
      the only related modules we do have are (I searched for MIME and Mail):
      MIME::Base64 MIME::QuotedPrint Mail::Sender
        *sigh* I work for an extension of a State government. I feel your pain.

        At times like this, the adage "it's easier to apologize than get permission" might serve you well. YMMV.

        If things get any worse, I'll have to ask you to stop helping me.

Re: email parsing problem?
by hanenkamp (Pilgrim) on Dec 10, 2003 at 19:54 UTC

    This is happening because the emails are in Quoted-Printable format. You may want to look into filtering via MIME::QuotedPrint.

      well, I added the :
      use MIME::QuotedPrint;
      line, and changed:
      print tomail "$line\n";
      to use:
      $decoded = MIME::QuotedPrint::decode($line); print tomail "$decoded";
      and still no joy...I have a feeling this is the way to go, but I am not grasping the concept or something...

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://313827]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (1)
As of 2024-04-18 23:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found