[Mimedefang] Extracting the contents of a text attachment
Paul Whittney
pwhittney at net.arrivetech.com
Thu Jun 2 11:41:32 EDT 2005
Jeffrey,
That sounds more a job for a perl script, using the MIMETools modules, rather
than a MimeDefang section, reduces the stress on the mail relay box.
Change the sender to systemEmail instead of all the local admins (or
perhaps get mimedefang to rewrite the recipient), and using a sendmail
alias, pipe it through perl (using the 'safe to execute' directories
that sendmail trusts) and get the perl script to email it your
local admins..
Something like:
#---- perl script, and definitions before this... ----
# Read in stdin
while (<>) {
chomp;
# record the line
%data->{$count++} = "$_";
if (!$senderValid && (m/^From:\s*/)) {
# There is a valid From: line in the message
if (m/([\w\d-\+\.]*\@[\w\d-\+\.]*)/) {
# SQL connection to check if they are allowed, or something
$senderValid=1;
$sender="$1";
}
}
}
#.... more checks....
# output data...
open (MAILPROG,"|/usr/sbin/sendmail -fbounce-null $address");
print MAILPROG "To: $address\n";
print MAILPROG "Subject: $subject\n\n";
print MAILPROG "heres the data....\n\n";
foreach $item (0 .. $count-1) {
print MAILPROG "$item; ".%data->{"$item"}."\n";
}
print MAILPROG "\n-------------- end ----------------\n";
print MAILPROG ".\n";
close MAILPROG;
# -------- end of script -------------
I use a form of this in a script that parses exchange server output,
and then emails it to the local admins in a formatted text body, but
the data is an attachment, and I only want sum's of data, not all the
1meg of output.
I use MIME::Parser (but there might be better ways):
my $parser = new MIME::Parser;
$parser->output_dir("/tmp");
$parser->output_prefix("exchangeData");
$entity = $parser->parse(\*STDIN) or die "parse failed\n";
($date) = ( $entity->head()->get('Date') || ("Unknown Date") );
Major issues are checking if it came from a valid source, so check
for the headers, and certain tell-tale signs in the from addresses,
as well as banning certain IP's..
Also, scripts could run from a procmailrc file too:
:0:
* ^From:.*"Some System Name" <.*-SA at .*>
* ^Subject:.*Some Subject will be here
* !^Received:.*from localhost
| /my/location/perl/myProgram.pl --addressList pwhittney,someoneelse
-Paul
--
Paul Whittney ArriveTech, Inc.
Network Specialist / Systems Engineer / |670 West 36th Street,
/--|Erie, PA, 16508, USA
PWhittney [at] arrivetech.com (Main) / |www.arrivetech.com
PWhittney [at] net.arrivetech.com (Aux) / |Tel: 814 868 3306
On Thu, Jun 02, 2005 at 10:14:43AM -0400, Jeffrey wrote:
> I am trying to figure out a way to remove the text from within a text
> attachment and have that text appended to the body of the message, while
> also dropping the attachment. The reason for this is that we have a system
> that sends emails with particular info within a text file, but it is
> annoying having to then open the text file when we would rather have it in
> the body of the original message.
>
> Any thoughts?
>
> Thanks!
>
> Jeffrey
More information about the MIMEDefang
mailing list