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

I created a Perl script to file incoming e-mails in our task management system using Email::MIME. For the most part it has been working well, but I hit a problem recently where the text attachment was filed instead of the text body of the e-mail. It only occurred from one client and doesn't occur when I try to reproduce it.
if ($parsed->xpath_exists('//plain')) { @nodes = $parsed->xpath_findnodes('//plain'); $text_part = $nodes[0]; $body=$text_part->body; }
The e-mail had two text parts, but I can't figure out why it didn't select the first in this case. Message (without headers and HTML)
--=_mixed 007E16738825776F_= Content-Type: multipart/alternative; boundary="=_alternative 007E16738 +825776F_=" --=_alternative 007E16738825776F_= Content-Type: text/plain; charset="US-ASCII" This was the body text --=_alternative 007E16738825776F_=-- --=_mixed 007E16738825776F_= Content-Type: text/plain; name="6014969_S02500.txt" Content-Disposition: attachment; filename="6014969_S02500.txt" Content-Transfer-Encoding: quoted-printable This is a text file attachment --=_mixed 007E16738825776F_=--
Any ideas would be greatly appreciated. Let me know if you need more code or more of the data.

Replies are listed 'Best First'.
Re: Using Email::MIME
by choroba (Cardinal) on Aug 13, 2010 at 21:57 UTC
    Never used Email::MIME, but I am a bit familiar with xpath. Maybe //plain[1] instead of //plain would help?
      That worked for the problematic e-mail, but with that change the other e-mails didn't get read in. Actually I had to use plain[0]. However for an e-mail without attachments, this just fails. So I thought I could search for "plain[0]" first and then "plain", but that seemed to just use the "plain" logic.