I have been trying to write a small email parsing filter.
Here is the how it should work:
- server recieves email and pipes it to the email filter
- the filter strips the to, from, subject and body from the email.
- if the body is of type mime, it is decoded and any attachments can be saved to a local directory.
- a response email is generated notifying the sender it their email was received and then the original email is simple sent to /dev/null. no need to save it locally.
I have been attempting to use Email::Filter... so far, I have it able to receive the email, send a response using Mail::Sendmail and then dump the message to /dev/null. So far so good. Here is my problem, i can't get it to write to a log file and i have been trying to figure out how to parse the body and save files locally. (for example, an jpeg image).
Here is my lil code so far:
use Email::Filter;
use Mail::Sendmail;
BEGIN {
$mail = Email::Filter->new();
$mail->exit(0);
}
my $to = $mail->to;
my $from = $mail->from;
my $subject = $mail->subject;
my $body = $mail->body;
open (LOG, qq|>>MAIL.txt|);
print LOG qq|TO => $to\n|;
print LOG qq|FROM => $from\n|;
print LOG qq|SUBJECT => $subject\n|;
print LOG qq|BODY => $body\n|;
close (LOG);
END {
my %hash = (
to => $from
, from => 'foo@bar.com'
, subject => 'Mail recieved'
, body => 'Your message has been received'
, smtp => 'foobar.com'
);
open(ERROR, qq|>>ERROR.txt|);
sendmail(%hash) or print ERROR qq|Couldn't send mail... $!\n|;
#uncomment following lines for debugging only
print ERROR qq|$Mail::Sendmail::error \n|;
print ERROR qq|\$Mail::Sendmail::log says:\n$Mail::Sendmail::log\n
+|;
close (ERROR);
$mail->exit(1);
$mail->accept('/dev/null');
}
any suggestions?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.