[Mimedefang] Eml Attachments

Nathan Findley nathan at zenlok.com
Mon Nov 21 20:57:15 EST 2011

On 11/18/2011 03:15 PM, Nathan Findley wrote:
> Hi all,
> How would I save an eml attachment on an incoming mail? Does this look
> reasonable on a basic level?
> sub filter_multipart ($$$$) {
> my($entity, $fname, $ext, $type) = @_;
> open FH, ">/tmp/copy.eml" or die $!;
> if (re_match($entity, '\.eml') and ($type eq "message/rfc822")) {
> $entity->print_body(FH);
> }
> close FH;
> }

This is what I ended up doing:

if (re_match($entity, '\.eml') and ($type eq "message/rfc822")) {
my $inputmsg = "$CWD/NMS";
open FH, ">$inputmsg" or return action_bounce('IO ERROR '.__PACKAGE__.' 
close FH;
system("/bin/sed -i 1,2d $inputmsg");

I am using sed because printing the contents of the entity leaves a 
couple of lines at the top of the resulting file that will cause mail 
readers to not recognize the file as a proper eml. If there is a way to 
immediately write to disk without those two top lines, it would be nice 
to know.



More information about the MIMEDefang mailing list