dynamicnet
09-09-2009, 10:40 AM
Greetings:
RE: Seeking Perl or PHP examples of email interception on the mail server itself.
I've complete access to our mail servers, and I'm looking to write a small Perl or PHP application which can intercept an email to a specific email box, and from there do the following:
Determine if the email is plain text or HTML/MIME-based with or without an attachment.
Insert one to several lines into the email in such a way it does not break any content encoding.
We are using qmail/vpopmail, so I know how to use a .qmail forward file where I can get info from STDIN and pipe out to STDOUT to feed into the actual mail box.
What I've been having trouble with is the inserting of the text so it comes in the body after any content endcoding start but before the content encoding end.
Can anyone share any good Perl or PHP libraries, code, etc. for handling this endeavor?
If it helps, this is some quick and dirty Perl code I drafted up which does work with plain text, but not with HTML/MIME et al:
use strict;
use Mail::Internet;
my $message = new Mail::Internet \*STDIN;
my $from = $message->head->get("From");
my $domain = (split(/@/, $from))[1];
$domain = (split(/>/,$domain))[0];
my $customer_id = '##hs_customer_id:' . $domain . '##' . "\n\n";
my $body = $message->body();
my $first_line = shift(@{$body});
my $second_line = shift(@{$body});
unshift(@{$body}, $customer_id);
unshift(@{$body}, $second_line);
unshift(@{$body}, $first_line);
$message->body($body);
$message->print( \*STDOUT );
close($message);
exit (99);
Thank you.
RE: Seeking Perl or PHP examples of email interception on the mail server itself.
I've complete access to our mail servers, and I'm looking to write a small Perl or PHP application which can intercept an email to a specific email box, and from there do the following:
Determine if the email is plain text or HTML/MIME-based with or without an attachment.
Insert one to several lines into the email in such a way it does not break any content encoding.
We are using qmail/vpopmail, so I know how to use a .qmail forward file where I can get info from STDIN and pipe out to STDOUT to feed into the actual mail box.
What I've been having trouble with is the inserting of the text so it comes in the body after any content endcoding start but before the content encoding end.
Can anyone share any good Perl or PHP libraries, code, etc. for handling this endeavor?
If it helps, this is some quick and dirty Perl code I drafted up which does work with plain text, but not with HTML/MIME et al:
use strict;
use Mail::Internet;
my $message = new Mail::Internet \*STDIN;
my $from = $message->head->get("From");
my $domain = (split(/@/, $from))[1];
$domain = (split(/>/,$domain))[0];
my $customer_id = '##hs_customer_id:' . $domain . '##' . "\n\n";
my $body = $message->body();
my $first_line = shift(@{$body});
my $second_line = shift(@{$body});
unshift(@{$body}, $customer_id);
unshift(@{$body}, $second_line);
unshift(@{$body}, $first_line);
$message->body($body);
$message->print( \*STDOUT );
close($message);
exit (99);
Thank you.
