Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use MIME::Entity and MIME::Parser from MIME::Tools instead of Email::MIME #217

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ jobs:
DBD::mysql
Net::IP
Socket6
Email::MIME
MIME::Entity
MIME::Parser
Net::SMTPS
XML::LibXML
Email::Sender
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ jobs:
DBD::mysql
Net::IP
Socket6
Email::MIME
MIME::Entity
MIME::Parser
Net::HTTP
Net::SMTPS
XML::LibXML
Expand Down
5 changes: 4 additions & 1 deletion Build.PL
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ my $module_build_args = {
"DBD::SQLite" => "1.31",
"DBIx::Simple" => "1.35",
"Data::Dumper" => 0,
"Email::MIME" => 0,
"Email::Sender" => 0,
"Email::Sender::Simple" => "1.300032",
"Email::Simple" => 0,
Expand All @@ -50,6 +49,10 @@ my $module_build_args = {
"IO::Socket::SSL" => 0,
"IO::Uncompress::Gunzip" => 0,
"IO::Uncompress::Unzip" => 0,
"Mail::Field" => 0,
"Mail::Internet" => 0,
"MIME::Entity" => 0,
"MIME::Parser" => 0,
"Net::DNS::Resolver" => 0,
"Net::IDN::Encode" => 0,
"Net::IP" => 0,
Expand Down
5 changes: 4 additions & 1 deletion META.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
"DBD::SQLite" : "1.31",
"DBIx::Simple" : "1.35",
"Data::Dumper" : "0",
"Email::MIME" : "0",
"Email::Sender" : "0",
"Email::Sender::Simple" : "1.300032",
"Email::Simple" : "0",
Expand All @@ -54,6 +53,10 @@
"IO::Socket::SSL" : "0",
"IO::Uncompress::Gunzip" : "0",
"IO::Uncompress::Unzip" : "0",
"Mail::Field" : "0",
"Mail::Internet" : "0",
"MIME::Entity" : "0",
"MIME::Parser" : "0",
"Net::DNS::Resolver" : "0",
"Net::IDN::Encode" : "0",
"Net::IP" : "0",
Expand Down
5 changes: 4 additions & 1 deletion META.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ requires:
DBD::SQLite: '1.31'
DBIx::Simple: '1.35'
Data::Dumper: '0'
Email::MIME: '0'
Email::Sender: '0'
Email::Sender::Simple: '1.300032'
Email::Simple: '0'
Expand All @@ -131,6 +130,10 @@ requires:
IO::Socket::SSL: '0'
IO::Uncompress::Gunzip: '0'
IO::Uncompress::Unzip: '0'
Mail::Field : '0'
Mail::Internet : '0'
MIME::Entity: '0'
MIME::Parser: '0'
Net::DNS::Resolver: '0'
Net::IDN::Encode: '0'
Net::IP: '0'
Expand Down
5 changes: 4 additions & 1 deletion Makefile.PL
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ my %META = (
"DBD::SQLite" => "1.31",
"DBIx::Simple" => "1.35",
"Data::Dumper" => 0,
"Email::MIME" => 0,
"Email::Sender" => 0,
"Email::Sender::Simple" => "1.300032",
"Email::Simple" => 0,
Expand All @@ -70,6 +69,10 @@ my %META = (
"IO::Socket::SSL" => 0,
"IO::Uncompress::Gunzip" => 0,
"IO::Uncompress::Unzip" => 0,
"Mail::Field" => 0,
"Mail::Internet" => 0,
"MIME::Entity" => 0,
"MIME::Parser" => 0,
"Net::DNS::Resolver" => 0,
"Net::IDN::Encode" => 0,
"Net::IP" => 0,
Expand Down
10 changes: 6 additions & 4 deletions lib/Mail/DMARC/Report/Receive.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ our $VERSION = '1.20240214';

use Carp;
use Data::Dumper;
use Email::MIME;
use MIME::Parser;
use Email::Simple;
use Encode;
use IO::Uncompress::Unzip;
Expand Down Expand Up @@ -137,8 +137,10 @@ sub from_email_simple {
};

my $rep_type;
foreach my $part ( Email::MIME->new( $email->as_string )->parts ) {
my ($c_type) = split /;/, $part->content_type || '';
my $parser = MIME::Parser->new;
foreach my $part ( $parser->parse( $email->as_string )->parts_DFS ) {
next if defined(!$part->bodyhandle); # something to process
my ($c_type) = split /;/, $part->effective_type || '';
next if $c_type eq 'text/plain';
if ( $c_type eq 'text/rfc822-headers' ) {
warn "TODO: handle forensic reports\n"; ## no critic (Carp)
Expand All @@ -151,7 +153,7 @@ sub from_email_simple {
next;
}
my $bigger;
my $filename = $part->{ct}{attributes}{name} || '';
my $filename = $part->head->recommended_filename || $part->bodyhandle->path || '';

if ( $c_type eq 'application/zip' || $c_type eq 'application/x-zip-compressed' ) {
$self->get_submitter_from_filename( $filename );
Expand Down
84 changes: 36 additions & 48 deletions lib/Mail/DMARC/Report/Send/SMTP.pm
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ our $VERSION = '1.20240214';

use Carp;
use English '-no_match_vars';
use Email::MIME;
use MIME::Entity;
#use Mail::Sender; # something to consider
use Sys::Hostname;
use POSIX;
Expand Down Expand Up @@ -115,24 +115,20 @@ sub get_filename {
sub assemble_too_big_message_object {
my ( $self, $to, $body ) = @_;

my @parts = Email::MIME->create(
attributes => {
content_type => "text/plain",
disposition => "inline",
charset => "US-ASCII",
},
body => $body,
) or croak "unable to add body!";

my $email = Email::MIME->create(
header_str => [
From => $self->config->{organization}{email},
To => $to,
Date => $self->get_timestamp_rfc2822,
Subject => 'DMARC too big report',
],
parts => [@parts],
) or croak "unable to assemble message\n";
my $email = MIME::Entity->build(
Type => "multipart/mixed",
From => $self->config->{organization}{email},
To => $to,
Date => $self->get_timestamp_rfc2822,
Subject => 'DMARC too big report'
) or croak "unable to create header!";

$email->attach(
Type => "text/plain",
Disposition => "inline",
Charset => "US-ASCII",
Data => $body,
) or croak "unable to add body and assemble message!";

return $email;
}
Expand All @@ -146,35 +142,27 @@ sub assemble_message_object {
my $cf = 'gzip';
$filename .= $cf eq 'gzip' ? '.gz' : '.zip';

my @parts = Email::MIME->create(
attributes => {
content_type => "text/plain",
disposition => "inline",
charset => "US-ASCII",
},
body => $self->human_summary( $agg_ref ),
) or croak "unable to add body!";

push @parts,
Email::MIME->create(
attributes => {
filename => $filename,
content_type => "application/$cf",
encoding => "base64",
name => $filename,
},
body => $shrunk,
) or croak "unable to add report!";

my $email = Email::MIME->create(
header_str => [
From => $self->config->{organization}{email},
To => $to,
Date => $self->get_timestamp_rfc2822,
Subject => $self->get_subject( $agg_ref ),
],
parts => [@parts],
) or croak "unable to assemble message\n";
my $email = MIME::Entity->build(
Type => "multipart/mixed",
From => $self->config->{organization}{email},
To => $to,
Date => $self->get_timestamp_rfc2822,
Subject => $self->get_subject( $agg_ref )
) or croak "unable to create header!";

$email->attach(
Type => "text/plain",
Disposition => "inline",
Charset => "US-ASCII",
Data => \$self->human_summary( $agg_ref ),
) or croak "unable to add body to message!";

$email->attach(
Type => "application/$cf",
Encoding => "base64",
Filename => $filename,
Data => \$shrunk,
) or croak "unable to add report to message!";

return $email;
}
Expand Down
Loading