The files starting with d will hold the mail bodyP217031 T566755281 MDeferred: Connection timed out during user open with zeus Sgeo Ramy@zeus H?P?return-path: <geo> Hreceived: by george (0.13 (NL support)/0.01) id AA00269; Thu, 17 Dec 87 10:01:21 CST H?D?date: Thu, 17 Dec 87 10:01:21 CST H?F?From: geo Hmessage-id: <8712171601.AA00269@george> HTo: amy@zeus H??X-Accept-Language: en-us, en H??MIME-Version: 1.0 H??Subject: Hello .. its a test html mail H??Content-Type: text/html; charset=ISO-8859-1 H??Content-Transfer-Encoding: 7bit
If a user sent a mail to my host, then I'll be having 2 parts of the email in the /var/spool/mqueue, with the following format:<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Typ +e"> <title></title> </head> <body bgcolor="#ffffff" text="#000000"> Hi shobs,<br> its test mail for html !!<br> <h1>THE PENGUIN</h1> <h2>OPEN SOURCE PRODUCTS</h2> <h3>MIMEDefang</h3> <p>...</p> <br> </body> </html>
Can someone let me know how to get the matching email parts..and also how to update the email part with the embedded image data on top and bottom of the mail part..?#!/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/dfj5RAnuBt013 +914"); ## 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 .= <FH>; 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 <body> </body> my $stripped_part = $2 if ($mail =~ /\<body(.*?)\>(.*?)\<\/body\>/sg +m); print $stripped_part."\n"; ## Add the image tag after <body> tag ## Adding an image this way will work.. once the Sendmail sends the +email ..?? my $line_to_add = "<div><image>/tmp/ATT135859.gif </image </div>"; 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 (dfj5RAnu +Bt01391) ## into $post_dir ## Add code for the same close(OUT); }
In reply to Manipulating mail parts from Sendmail's queue by chanakya
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |