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

Fix: content-type and type= argument in <MIMEArgs> were not properly handled. #22

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion examples/mha-p7m
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ $mhonarc::CBRawMessageBodyRead = sub {
if ($sub_header->{'content-type'}) {
# Make sure update mhonarc's meta field for content-type
my $ctype = $sub_header->{'content-type'}[0];
if ($ctype =~ m%^\s*([\w\-\./]+)%) {
if ($ctype =~ m%^\s*([\w\!\#\$\&\-\^.+/]+)%) {
$fields->{'x-mha-content-type'} = $1;
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/mhasiteinit-p7m.pl
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ package mhonarc_site_init;
if ($sub_header->{'content-type'}) {
# Make sure update mhonarc's meta field for content-type
my $ctype = $sub_header->{'content-type'}[0];
if ($ctype =~ m%^\s*([\w\-\./]+)%) {
if ($ctype =~ m%^\s*([\w\!\#\$\&\-\^.+/]+)%) {
$fields->{'x-mha-content-type'} = $1;
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/mhamain.pl
Original file line number Diff line number Diff line change
Expand Up @@ -959,7 +959,8 @@ sub read_mail_header {
## Get Content-Type ##
##------------------##
if (defined($fields->{'content-type'})) {
($ctype = $fields->{'content-type'}[0]) =~ m%^\s*([\w\-\./]+)%;
($ctype = $fields->{'content-type'}[0]) =~
m%^\s*([\w\!\#\$\&\-\^.+/]+)%;
$ctype = lc($1 || 'text/plain');
} else {
$ctype = 'text/plain';
Expand Down
17 changes: 10 additions & 7 deletions lib/mhexternal.pl
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ sub filter {
$args = '' unless defined($args);
my $name = '';
my $ctype = '';
my $type = '';
my $inline = 0;
my $inext = '';
my $intype = '';
Expand All @@ -136,10 +135,10 @@ sub filter {

## Get content-type
if (!defined($ctype = $fields->{'x-mha-content-type'})) {
($ctype) = $fields->{'content-type'}[0] =~ m%^\s*([\w\-\./]+)%;
($ctype) =
$fields->{'content-type'}[0] =~ m%^\s*([\w\!\#\$\&\-\^.+/]+)%;
$ctype =~ tr/A-Z/a-z/;
}
$type = (mhonarc::get_mime_ext($ctype))[1];

## Get disposition
my ($disp, $nameparm, $raw_name, $html_name) =
Expand Down Expand Up @@ -172,6 +171,7 @@ sub filter {
## Check if extension and type description passed in
if ($args =~ /\bext=(\S+)/i) { $inext = $1; $inext =~ s/['"]//g; }
if ($args =~ /\btype="([^"]+)"/i) { $intype = $1; }
$intype ||= (mhonarc::get_mime_ext($ctype))[1];

## Check if utilizing extension from mail header defined filename
if ($dispext && $usenameext) {
Expand Down Expand Up @@ -229,8 +229,11 @@ sub filter {
. mhonarc::htmlize($fields->{'content-description'}[0])
. "</p>\n"
if (defined $fields{'content-description'});
$ret .= qq|<p><a href="$urlfile" $target><img src="$urlfile" |
. qq|alt="$type"></a></p>\n|;
$ret .=
qq|<p><a href="$urlfile" $target><img src="$urlfile" |
. qq|alt="|
. mhonarc::htmlize($intype)
. qq|"></a></p>\n|;

} else {
my $is_mesg = $ctype =~ /^message\//;
Expand All @@ -242,8 +245,8 @@ sub filter {
$namelabel = readmail::MAILdecode_1522_str($1);
$desc .= 'Message attachment';
} else {
$desc .= mhonarc::htmlize($fields->{'content-description'}[0])
|| $type;
$desc .= mhonarc::htmlize($fields->{'content-description'}[0]
|| $intype);
if ($nameparm) {
#$namelabel = mhonarc::htmlize($nameparm);
$namelabel = $html_name;
Expand Down
2 changes: 1 addition & 1 deletion lib/mhmimetypes.pl
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ sub write_attachment {
}

my $ctype = 'application/octet-stream';
if ($content =~ m%^\s*([\w\-\./]+)%) {
if ($content =~ m%^\s*([\w\!\#\$\&\-\^.+/]+)%) {
$ctype = $1;
}

Expand Down
3 changes: 2 additions & 1 deletion lib/mhnull.pl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ package m2h_null;

sub filter {
my ($fields, $data, $isdecode, $args) = @_;
my ($ctype) = $fields->{'content-type'}[0] =~ m%^\s*([\w\-\./]+)%;
my ($ctype) =
$fields->{'content-type'}[0] =~ m%^\s*([\w\!\#\$\&\-\^.+/]+)%;
my ($disp, $nameparm, $raw_name, $html_name) =
readmail::MAILhead_get_disposition($fields, 1);
join("",
Expand Down
3 changes: 2 additions & 1 deletion lib/mhtxtenrich.pl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ sub filter {
$args = "" unless defined($args);

## Get content-type
my ($ctype) = $fields->{'content-type'}[0] =~ m%^\s*([\w\-\./]+)%;
my ($ctype) =
$fields->{'content-type'}[0] =~ m%^\s*([\w\!\#\$\&\-\^.+/]+)%;
my $richtext = $ctype =~ /\btext\/richtext\b/i;

if (defined($charcnv) && defined(&$charcnv)) {
Expand Down
2 changes: 1 addition & 1 deletion lib/mhtxthtml.pl
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ sub resolve_cid {
my $ctype = $href->{'fields'}{'x-mha-content-type'};
if (!defined($ctype)) {
$ctype = $href->{'fields'}{'content-type'}[0];
($ctype) = $ctype =~ m{^\s*([\w\-\./]+)};
($ctype) = $ctype =~ m%^\s*([\w\!\#\$\&\-\^.+/]+)%;
}
return "" if readmail::MAILis_excluded($ctype);

Expand Down
9 changes: 5 additions & 4 deletions lib/readmail.pl
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,9 @@ sub MAILread_body {
$content = $fields->{'content-type'}->[0];
}
$content = 'text/plain' unless $content;
($ctype) = $content =~ m%^\s*([\w\-\./]+)%; # Extract content-type
$ctype =~ tr/A-Z/a-z/; # Convert to lowercase
($ctype) =
$content =~ m%^\s*([\w\!\#\$\&\-\^.+/]+)%; # Extract content-type
$ctype =~ tr/A-Z/a-z/; # Convert to lowercase
if ($ctype =~ m%/%) { # Extract base and sub types
($type, $subtype) = split(/\//, $ctype, 2);
} elsif ($ctype =~ /text/i) {
Expand Down Expand Up @@ -1293,10 +1294,10 @@ sub extract_ctype {
return 'text/plain';
}
if (ref($_[0])) {
$_[0][0] =~ m|^\s*([\w\-\./]+)|;
$_[0][0] =~ m%^\s*([\w\!\#\$\&\-\^.+/]+)%;
return lc($1);
}
$_[0] =~ m|^\s*([\w\-\./]+)|;
$_[0] =~ m%^\s*([\w\!\#\$\&\-\^.+/]+)%;
lc($1);
}

Expand Down