#!/usr/bin/perl use strict; use warnings; use Data::Dumper; sub __readFile; sub __getHeaders; sub __updateMailBody; ### Config my $pre_dir = "/tmp/mqueue"; my $post_dir = "/tmp/mqueue_processed"; # Two parts of one email, hardcoded for testing my @mail_parts = ("$pre_dir/qfj5RAnuBt013914", "$pre_dir/dfj5RAnuBt013914"); ## files with "dxx" hold the mail content my $out_file = $mail_parts[1]; my $mail_content; foreach (@mail_parts){ $mail_content = __readFile($_); my $mail_headers = __getHeaders($mail_content); } sub __readFile($){ undef $/; my $part = shift; my $part_data; open(FH, "< $part"); $part_data .= ; close (FH); return $part_data; } sub __getHeaders($){ my $mail = shift; my $msg_id = $1 if ($mail =~ m{H\?\?Message-ID\: \<(.*?)\>}); my $from = $1 if ($mail =~ m{H\?\?From\: \"(.*?)\"}); my $content_type = $1 if ($mail =~ m{H\?\?Content-Type\:\s(.*?);}); #print $msg_id . " ". $from ." " .$content_type; if ($content_type eq "text/html"){ __updateMailBody($mail); } } sub __updateMailBody($){ my $mail = shift; #my @mail = $mail; #get the part between my $stripped_part = $2 if ($mail =~ /\(.*?)\<\/body\>/sgm); print $stripped_part."\n"; ## Add the image tag after tag ## Adding an image this way will work.. once the Sendmail sends the email ..?? my $line_to_add = "
/tmp/ATT135859.gif "; open(OUT, "> $post_dir/$out_file"); ## Add code to add the image onto the top of $stripped_part ## and write out the full content to the original filename (dfj5RAnuBt01391) ## into $post_dir ## Add code for the same close(OUT); }