I decided to pick up a script I wrote awhile ago, and get it back on track. I wrote a little about it in Dealing with "Detachments". Here's the issue:

The script is an alias in /etc/mail/aliases, so that incoming mail sent to this address, is sent to my script and processed. Originally, the script required that the key=value pairs in this script had to occur in the body of the message itself, in a template I parse with Config::General. I've added the capability to attach the template to the message itself as an attachment (easier for Outlook/Windows users, apparently). So far, so good.

What I'm trying to do now, is "detach" that attachment, store it in a scalar I can manipulate (or even write it to disk, for the moment. I can deal with IO::Scalar on it later to omit the disk hit). When I detach the file, using MIME::Parser, I have a few options, each with their own confusing quirks:

The code I'm using looks like this:

my $md5file = md5_hex($date); my $workpath = "/var/lib/pler"; my $date = UnixDate("today","%b %e, %Y at %T"); my $parser = new MIME::Parser; $parser->output_dir("$workpath"); $parser->output_prefix("$md5file"); my $filer = $parser->filer; $filer->ignore_filename(0); my $entity = $parser->read(\*STDIN);

What I'd like, ideally, is to have the attachment "detached", and named as "$md5file-originalfile.extension", so I can then manipulate it and handle it as a normal file or file-handle-in-a-scalar.

  1. How do I get the original filename back when detaching?
  2. If I'm using output_under(), how do I know what that long string of numbers (it's not the PID) in the directory name is?
  3. Why do I see those *.txt files as 0-byte or 1-byte files? What is their purpose, if the "real" attachment is in a separate file all its own?
  4. Is there another (better/more-suited) module for this task?
  5. I'm also using Mail::Internet to split the message envelope up so I can get the "From:", "To:" "Subject:" and body out of the message. Should I use MIME::Parser for all of these in one shot? Or should I use both?

Color me confusigated.


In reply to Detachments II: The Sequel by hacker

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.