Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Dealing with "Detachments"

by jlongino (Parson)
on Oct 24, 2002 at 15:13 UTC ( #207739=note: print w/ replies, xml ) Need Help??


in reply to Dealing with "Detachments"

I think that if you want to work with attachments that Mail::Internet isn't going to be much help. Maybe the best course of action would be to find out why MIME::Parser isn't working for you. Is it possible that the message you're receiving doesn't comply fully with RFC822 standards?

Also, since I suspect you'll need a different method for getting your message from the mailserver, can you use Mail::POP3Client or Mail::IMAPClient to get the message?

If you can send me a sample E-mail I'll try a few things and let you know what I find. The process might take a few hours though since I'd probably have to wait until lunch to take a look at it.

--Jim


Comment on Re: Dealing with "Detachments"
Re: Dealing with "Detachments"
by hacker (Priest) on Oct 24, 2002 at 20:54 UTC
    Also, since I suspect you'll need a different method for getting your message from the mailserver, can you use Mail::POP3Client or Mail::IMAPClient to get the message?

    The problem with this approach is that I'm not getting a message from a server here. I literally receive the email message directly, via an /etc/mail/aliases line that references it as such:

    script-email-addr: "|/var/perl/myscript.pl"

    There is no mailbox, port, daemon, or process involved (other than my perl script), and in fact, the message is never actually written to disk anywhere by the MDA. I receive it as a stream of bytes, directly into the script doing the processing of the message. Basically looks like this:

    my $message = new Mail::Internet ([<>]); my $from = $message->get('From'); my $subject = $message->get('Subject'); my $received = $message->get('Received'); my @body = @{$message->body()};

    From here, I can grok the bits of the message, everything except the attachment. That's the missing link I need to solve to implement this next feature. Ideas?

      heh! I'm doing almost exactly the same thing. I tested this and it works for me:
      use strict; use warnings; use MIME::Parser; ## my alias line: ## menu: \menu, "|/usr/perl/mime.parser.p" ## '\menu' keeps a copy in the inbox for account menu my $parser = new MIME::Parser; ## The secret here is that the directory must pre-exist ## and must be writable by the daemon that runs the ## parsing script. In my case user=daemon group=other ## I determined the correct values by initially making ## /tmp/mimemail using permissions 777. $parser->output_dir("/tmp/mimemail"); my $entity = $parser->read(\*STDIN) or die "\n\nCouldn't parse MIME stream\n\n";
      For actual use I'd create the directory internally from the program and then remove it when finished. You'll also want to come up with some dynamic means of choosing the directory name since you don't want to try and delete the directory while another instance of the program is trying to write to it.

      All you have to do now is figure out how to scarf the other portions of the original message using MIME::Parser before resending with MIME::Lite.

      --Jim

        For actual use I'd create the directory internally from the program and then remove it when finished. You'll also want to come up with some dynamic means of choosing the directory name since you don't want to try and delete the directory while another instance of the program is trying to write to it.

        I've got that figured out perfectly, in fact. I'm currently doing the following:

        use strict; # the usual suspects use Date::Manip; # date functions use Digest::MD5 qw(md5_hex); # convert date to md5 use File::Path; # mkpath/rmtree my $workpath = "/var/lib/pler"; # yes, pler =) my $date = UnixDate("today","%b %e, %Y at %T"); my $md5file = md5_hex($date); sub grok_data { # not the real name mkpath(["$workpath/$md5file"], 0, 0711); ... process data rmtree(["$workpath/$md5file"], 0, 1); }

        So far, this works flawlessly in another script that deals with the template as a file, but I'm converging the two separate scripts (and their functionality) into one, switchable by keys found inside the template.

        Thanks for the tips, I'll give this a try today.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://207739]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2014-08-30 12:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (293 votes), past polls