@@ -3,7 +3,7 @@ use strict;
3
3
4
4
# textmail - mail filter to replace MS Word/HTML attachments with plain text
5
5
#
6
- # Copyright (C) 2003-2007 raf <raf@raf.org>
6
+ # Copyright (C) 2003-2007, 2011 raf <raf@raf.org>
7
7
#
8
8
# This program is free software; you can redistribute it and/or modify
9
9
# it under the terms of the GNU General Public License as published by
@@ -20,7 +20,7 @@ use strict;
20
20
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
21
# or visit http://www.gnu.org/copyleft/gpl.html
22
22
#
23
- # 20070803 raf <raf@raf.org>
23
+ # 20110321 raf <raf@raf.org>
24
24
25
25
=head1 NAME
26
26
@@ -661,7 +661,7 @@ sub newmail # rfc2822, rfc2045, rfc2046, rfc2183 (also rfc3282, rfc3066, rfc2424
661
661
my $type = $a {type } || (exists $a {parts } ? ' multipart/mixed' : exists $a {message } ? ' message/rfc822' : ' text/plain' );
662
662
my $multi = $type =~ / ^multipart\/ /i ;
663
663
my $msg = $type =~ / ^message\/ rfc822$ /i ;
664
- ($a {body }, $a {modified }, $a {read }, $a {size }) = (do { local $/ ; my $b = <F>; close F; $b }, exists $a {modified } ? $a {modified } : rfc822date((stat _)[9]), exists $a {read } ? $a {read } : rfc822date((stat _)[8]), (stat _)[7]) if exists $a {filename } && !exists $a {body } && !exists $a {message } && !exists $a {parts } && -r $a {filename } && stat ($a {filename }) && open F, $a {filename };
664
+ ($a {body }, $a {created }, $a { modified }, $a {read }, $a {size }) = (do { local $/ ; my $b = <F>; close F; $b }, exists $a { created } ? $a { created } : rfc822date(( stat _)[9]) , exists $a {modified } ? $a {modified } : rfc822date((stat _)[9]), exists $a {read } ? $a {read } : rfc822date((stat _)[8]), (stat _)[7]) if exists $a {filename } && !exists $a {body } && !exists $a {message } && !exists $a {parts } && -r $a {filename } && stat ($a {filename }) && open F, $a {filename };
665
665
($a {filename }) = $a {filename } =~ / ([^\\\/ ]+)$ / if $a {filename };
666
666
my $bound = $multi ? join ' ' , map { substr $bchar , int (rand (length $bchar )), 1 } 0..30 : ' ' ;
667
667
my $disp = $a {disposition } || ($type =~ / ^(?:text\/ |message\/ rfc822)/i ? ' inline' : ' attachment' );
@@ -673,7 +673,7 @@ sub newmail # rfc2822, rfc2045, rfc2046, rfc2183 (also rfc3282, rfc3066, rfc2424
673
673
use Sys::Hostname; append_header($m , " Message-ID: <@{[time]}.$$ .@{[++$unique ]}\@ @{[hostname]}>" ) if grep { / ^(?:date|from|sender|reply-to)$ /i } keys %a and !grep { / ^message-id$ /i } keys %a ;
674
674
append_header($m , " Content-Type: $type " . ($bound ? newparam(' boundary' , $bound ) : ' ' ) . ($char =~ / ^us-ascii$ /i ? ' ' : newparam(' charset' , $char ))) unless $type =~ / ^text\/ plain$ /i && $char =~ / ^us-ascii$ /i ;
675
675
append_header($m , " Content-Transfer-Encoding: $enc " ) unless $enc =~ / ^7bit$ /i ;
676
- append_header($m , " Content-Disposition: $disp " . ($a {filename } ? newparam(' filename' , $a {filename }) : ' ' ) . ($a {size } ? newparam(' size' , $a {size }) : ' ' )) if $a {filename } || $a {size };
676
+ append_header($m , " Content-Disposition: $disp " . ($a {filename } ? newparam(' filename' , $a {filename }) : ' ' ) . ($a {size } ? newparam(' size' , $a {size }) : ' ' ) . ( $a { created } ? newparam( ' creation-date ' , $a { created }) : ' ' ) . ( $a { modified } ? newparam( ' modification-date ' , $a { modified }) : ' ' ) . ( $a { read } ? newparam( ' read-date ' , $a { read }) : ' ' )) if $a {filename } || $a {size } || $a { created } || $a { modified } || $a { read };
677
677
append_header($m , " Content-@{[ucfirst $_ ]}: $a {$_ }" ) for grep { $a {$_ } } qw( description language duration location base features alternative) ;
678
678
append_header($m , " Content-@{[uc $_ ]}: $a {$_ }" ) for grep { $a {$_ } } qw( id md5) ;
679
679
($m -> {mime_type }, $m -> {mime_boundary }, $m -> {mime_parts }) = ($type =~ / ^\s *([\w\/ .-]+)/ , $bound , $a {parts } || []) if $multi ;
@@ -738,7 +738,9 @@ sub encode_quoted_printable
738
738
$quoted =~ s/([^!-<>-~ \t $binary ])/sprintf '=%02X', ord $1 /eg;
739
739
$quoted =~ s/((?:[^\r\n ]{73,75})(?=[=])|(?:[^\r\n ]{75}(?=[ \t ]))|(?:[^\r\n ]{75})(?=[^\r\n ]{2})|(?:[^\r\n ]{75})(?=[^\r\n ]$) )/$1 =\n /g;
740
740
$quoted =~ s/([ \t ])$/sprintf '=%02X', ord $1 /emg;
741
- $quoted .= "=\n " unless $quoted =~ /\n $/ ;
741
+ # Python and mutt both behave as though this is wrong
742
+ #$quoted .= "=\n " unless $quoted =~ /\n $/ ;
743
+ $quoted .= "\n ";
742
744
return $quoted ;
743
745
}
744
746
@@ -1226,9 +1228,45 @@ sub debase64
1226
1228
my $type = mimetype($entity );
1227
1229
return $entity unless $type =~ /^text\/ /i && encoding($entity ) =~ /^base64$/i;
1228
1230
my $body = body($entity ); $body =~ tr/\r //d;
1229
- my $name = filename($entity );
1231
+ my $filename = param($entity , 'content-disposition', 'filename') || param($entity , 'content-type', 'name');
1232
+ my ($disposition ) = header($entity , 'content-disposition');
1233
+ $disposition =~ s/;.*// if defined $disposition ;
1234
+ my $size = param($entity , 'content-disposition', 'size');
1235
+ my $created = param($entity , 'content-disposition', 'creation-date');
1236
+ my $modified = param($entity , 'content-disposition', 'modification-date');
1237
+ my $read = param($entity , 'content-disposition', 'read-date');
1238
+ my $charset = param($entity , 'content-type', 'charset');
1239
+ my ($description ) = header($entity , 'content-description');
1240
+ my ($language ) = header($entity , 'content-language');
1241
+ my ($duration ) = header($entity , 'content-duration');
1242
+ my ($location ) = header($entity , 'content-location');
1243
+ my ($base ) = header($entity , 'content-base');
1244
+ my ($features ) = header($entity , 'content-features');
1245
+ my ($alternative ) = header($entity , 'content-alternative');
1246
+ my ($id ) = header($entity , 'content-id');
1247
+ my ($md5 ) = header($entity , 'content-md5');
1230
1248
my $mbox = $entity ->{mbox} if exists $entity ->{mbox};
1231
- return newmail(type => $type , body => $body , (defined $name ? (name => $name ) : ()), (defined $mbox ? (mbox => $mbox ) : ()));
1249
+ return newmail(
1250
+ type => $type ,
1251
+ body => $body ,
1252
+ (defined $filename ? (filename => $filename ) : ()),
1253
+ (defined $disposition ? (disposition => $disposition ) : ()),
1254
+ (defined $charset ? (charset => $charset ) : ()),
1255
+ (defined $size ? (size => $size ) : ()),
1256
+ (defined $created ? (created => $created ) : ()),
1257
+ (defined $modified ? (modified => $modified ) : ()),
1258
+ (defined $read ? (read => $read ) : ()),
1259
+ (defined $description ? (description => $description ) : ()),
1260
+ (defined $language ? (language => $language ) : ()),
1261
+ (defined $duration ? (duration => $duration ) : ()),
1262
+ (defined $location ? (location => $location ) : ()),
1263
+ (defined $base ? (base => $base ) : ()),
1264
+ (defined $features ? (features => $features ) : ()),
1265
+ (defined $alternative ? (alternative => $alternative ) : ()),
1266
+ (defined $id ? (id => $id ) : ()),
1267
+ (defined $md5 ? (md5 => $md5 ) : ()),
1268
+ (defined $mbox ? (mbox => $mbox ) : ())
1269
+ );
1232
1270
}
1233
1271
1234
1272
# Parse a data file
0 commit comments