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;
}

You are specifically dealing with multipart code so where to implement this for that is likely in filter or filter_multipart.

However, here's a routine with some nice tricks that I think is more kosher to using the mime tools to get the attachment and save it somewhere:

    if (re_match($entity, '\.png')) {
my $sizelimit = 32*1024; #max size of a png attachment you want to check in bytes

      #IF SIZE OF ATTACHMENT LESS THAN THE SIZELIMIT
      my $bh = $entity->bodyhandle();
      if (defined($bh)) {
        my $path = $bh->path();
        if (defined($path)) {
          if (-s $path <= $sizelimit) {

            my ($dest_file) = $entity->head->recommended_filename();
            $dest_file =~ s/[^-_\.!A-Z0-9]//ig;
            $dest_file =~ s/\.\.//ig;
            md_syslog( 'info', "Archive PNG - $dest_file.");
            if (-d '/var/spool/MD-PNGFiles') {
&File::Copy::copy($path, "/var/spool/MD-PNGFiles/$QueueID-$dest_file");
            }
          }
        }
      }
    }

Note, add/create sub filter_initialize {
  use File::Copy;
}

Regards,
KAM

_______________________________________________
NOTE: If there is a disclaimer or other legal boilerplate in the above
message, it is NULL AND VOID.  You may ignore it.

Visit http://www.mimedefang.org and http://www.roaringpenguin.com
MIMEDefang mailing list [email protected]
http://lists.roaringpenguin.com/mailman/listinfo/mimedefang

Reply via email to