- $attributes{filename} = $attachment;
- $attributes{filename} =~ s:.*\Q$self->{fileid}\E:: if $self->{fileid};
- $attributes{filename} =~ s:.*/::g;
- $attachment_content = eval { read_file($attachment) };
+ $attributes{Path} = $attachment;
+ $attributes{Filename} = $attachment;
+ $attributes{Filename} =~ s:.*\Q$self->{fileid}\E:: if $self->{fileid};
+ $attributes{Filename} =~ s:.*/::g;
+
+ my $application = ($attachment =~ /(^\w+$)|\.(html|text|txt|sql)$/) ? 'text' : 'application';
+ $attributes{Type} = File::MimeInfo::Magic::magic($attachment);
+ $attributes{Type} ||= "${application}/$self->{format}" if $self->{format};
+ $attributes{Type} ||= 'application/octet-stream';
+ $attachment_content = eval { read_file($attachment) } if $email_journal > 1;