hacker has asked for the wisdom of the Perl Monks concerning the following question:
Right now, the code below works for the first test (testing for 'help' in the Subject line). I'm wondering if there's a way to do this by parsing out objects from the body, given a user's email to this address. Basically they'd send a message like:
I then need to parse out the objects passed after the keys (url, depth, title, though there are about 40 possible modifiers). I can do this with split on the ':' there, and I can enforce a specific format for the email, but I'm not sure of the "right" process to actually parsing keys and values out of the body of an incoming message.To: er@foo.bar From: Joe User <juser@somewhere.com> Subject: Anything url: http://www.domain.com/ depth: 3 title: This is my title
Are there any modules that can help me here? I already have all the content/HTML parsing and generation code worked out, so that's not a problem.
Has anyone done something like this? Are there any security/processor issues with this? This will not be executing system commands, so that isn't an issue, but it will be passing commands into a wrapper script (which already works) and operating on them through this wrapper.
I need to expand this to allow parsing the keys and values passed in the body of the message. Once I have those parsed out, I need to then build a file which contains the results of this "run" of the wrapper script, tar'd up into a binary file, and sent as an attachment to the user as a reply to their original email.
My code so far looks like this, and works in this very limited scope.
use strict; use diagnostics; use warnings; use Date::Manip; use Mail::Mailer; my $date = UnixDate("today","%T on %b %e, %Y."); my $logfile = "/var/log/foo.bar.log"; my $mailer = Mail::Mailer->new(); my $admin = "admin\@foo.bar"; my $server_from = "\"Foo Reflector\" <er\@foo.bar>"; my $a = 1; my ($body, # entire message $message_header, # headers of message $message_body, # just the body itself $help, # help context ); while (<>) { my $line = $_; my $from = $line if /^From: /; help() if (/Subject.*?help.*/i); $body .= $line; $a++; } ($message_header = $body) =~ s/(.*?)\n\n.*/$1/s; ($message_body = $body) =~ s/.*?\n\n(.*)/$1/s; mail_admin(); open (LOGFILE, ">>$logfile") or die "$!"; print LOGFILE "-"x20, "\n"; print LOGFILE "$date - complete $0\n"; close LOGFILE; ########################################## # # Mail the administrator # ########################################## sub mail_admin { my $from =~ s/From: (.*)/$1/; chop($from); my $mailer->open({ From => $server_from, To => $from, Cc => $admin, Subject => "Test at $date", }) or die "Can't open $!\n"; print $mailer<<END_O_MAIL; $body $help ........................................... : The Email Server -+- er\@foo.bar : : for help, type HELP in the subject line : ........................................... END_O_MAIL $mailer->close; } ########################################## # # Display reponse to Help # ########################################## sub help { $help = " This is the help file. Thanks for needing help. If this had this been Real Help(tm), it would have helped. "; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(jeffa) Re: Email-based Content Generation Reflector
by jeffa (Bishop) on Jul 15, 2002 at 15:55 UTC | |
|
Re: Email-based Content Generation Reflector
by Fastolfe (Vicar) on Jul 15, 2002 at 18:03 UTC |