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

Hi Monks

I'm using the Mail::MboxParser::Mail module to get an email from STDIN eg.
my $msg = Mail::MboxParser::Mail->new([<STDIN>],[<STDIN>]);
In my code i have used the code:
my %mail = ( To => $msg->from->{email}, From => "$listname-admin\@myhost.com", Subject => 'User Subscribed Message => "The email address $email, has b +een subscribed to the $listname mailing list\n" );
The email which is being passed to this script, is a reply to an email sent in the same way from a different sub.

This code will work fine with all email clients that i've seen except for outlook express.
Outlook express tackles "reply"ing to emails in a different way to most mail clients.
Has anyone had a similar problem with Outlook Express emails, and does anyone know of a work around?
Maybe i could read the email from STDIN and use regex's to parse the email and make it a more suitable format.

Any suggestions would be much appreciated.

Neil Archibald
- /dev/IT -

Replies are listed 'Best First'.
Re: Outlook Express Reply Function
by Thelonius (Priest) on Jul 02, 2003 at 12:15 UTC
    Your problem is that you are passing the entire message (header + body) in as the header in this line:
    my $msg = Mail::MboxParser::Mail->new([<STDIN>],[<STDIN>]);
    The first [<STDIN>] will read in the whole message and create a list of all the lines. Any "From:" lines that are found in the body are going to be counted as header "FromL" lines, so the parser creates an array of all of them.

    There are several solutions. You could do this:

    my $msgtext; { local $/; $msgtext = <STDIN> } my ($header, $body) = split /\n\r?\n/, $msgtext, 2; my $msg = Mail::MboxParser::Mail->new($header, $body);
    or the more memory-efficient:
    my @headerlines; while (<STDIN>) { last if /^\r?\n/; push @headerlines, $_; } my $msg = Mail::MboxParser::Mail->new(\@headerlines, "");
    If you wanted the body, you could change that last line to:
    my $msg = Mail::MboxParser::Mail->new(\@headerlines, [<STDIN>]);
    I should say that most subscription processes require some specific code in the body and for good reason. For example, the "reply" you get may be just a vacaction message. Also, people could maliciously sign up others for a subscription just by sending two messages with the same forged "From:" line.
      Thanks a lot for your reply, it was very useful and informative. :-)

      Neil Archibald
      - /dev/IT -
Re: Outlook Express Reply Function
by Foggy Bottoms (Monk) on Jul 02, 2003 at 10:01 UTC
    I've worked quite a bit with Outlook but not the express one. Have you had a look at the object model for further reference ? I know you can test to see which sofware you're using and depending on the software choose the appropriate code.
    It seems to me you're not using OLE at all. It would probably make it all easier if you had a look at Win32::OLE and Outlook's object model (that is if Express uses the same). Once you access OLE properties, it's really easy to access the reply address. Try this piece of code :
    if ( my $outlook = Win32::OLE->GetActiveObject('Outlook.Application +'))# connect to outlook application { if (defined ($outlook->ActiveInspector())) { my $activeEmail= $outlook->ActiveInspector()->{CurrentItem}; if ($activeEmail->{Class}==olMail) # if we're dealing with an + email item { my $emailProperties; $emailProperties->{Recipients} =$activeEmail->{Recipien +ts}; $emailProperties->{ReplyRecipients} =$activeEmail->{Rep +lyRecipients}->ResolveAll(); } } }

    Good luck...