Skip to content

Commit 3cc21bc

Browse files
committed
20110321
- Added Content-Disposition creation-date/modification-date/read-date parameters - Preserved odd Content-* headers and Content-Disposition parameters (if recoding base64)
1 parent c69ac07 commit 3cc21bc

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

CHANGELOG

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
20110321
2+
3+
- Added Content-Disposition creation-date/modification-date/read-date parameters
4+
- Preserved odd Content-* headers and Content-Disposition parameters (if recoding base64)
5+
16
20070803
27

38
- Set LANG=C when generating the manpage

textmail

Lines changed: 45 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use strict;
33

44
# textmail - mail filter to replace MS Word/HTML attachments with plain text
55
#
6-
# Copyright (C) 2003-2007 raf <raf@raf.org>
6+
# Copyright (C) 2003-2007, 2011 raf <raf@raf.org>
77
#
88
# This program is free software; you can redistribute it and/or modify
99
# it under the terms of the GNU General Public License as published by
@@ -20,7 +20,7 @@ use strict;
2020
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
2121
# or visit http://www.gnu.org/copyleft/gpl.html
2222
#
23-
# 20070803 raf <raf@raf.org>
23+
# 20110321 raf <raf@raf.org>
2424

2525
=head1 NAME
2626
@@ -661,7 +661,7 @@ sub newmail # rfc2822, rfc2045, rfc2046, rfc2183 (also rfc3282, rfc3066, rfc2424
661661
my $type = $a{type} || (exists $a{parts} ? 'multipart/mixed' : exists $a{message} ? 'message/rfc822' : 'text/plain');
662662
my $multi = $type =~ /^multipart\//i;
663663
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};
665665
($a{filename}) = $a{filename} =~ /([^\\\/]+)$/ if $a{filename};
666666
my $bound = $multi ? join '', map { substr $bchar, int(rand(length $bchar)), 1 } 0..30 : '';
667667
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
673673
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;
674674
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;
675675
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};
677677
append_header($m, "Content-@{[ucfirst $_]}: $a{$_}") for grep { $a{$_} } qw(description language duration location base features alternative);
678678
append_header($m, "Content-@{[uc $_]}: $a{$_}") for grep { $a{$_} } qw(id md5);
679679
($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
738738
$quoted =~ s/([^!-<>-~ \t$binary])/sprintf '=%02X', ord $1/eg;
739739
$quoted =~ s/((?:[^\r\n]{73,75})(?=[=])|(?:[^\r\n]{75}(?=[ \t]))|(?:[^\r\n]{75})(?=[^\r\n]{2})|(?:[^\r\n]{75})(?=[^\r\n]$))/$1=\n/g;
740740
$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";
742744
return $quoted;
743745
}
744746
@@ -1226,9 +1228,45 @@ sub debase64
12261228
my $type = mimetype($entity);
12271229
return $entity unless $type =~ /^text\//i && encoding($entity) =~ /^base64$/i;
12281230
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');
12301248
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+
);
12321270
}
12331271
12341272
# Parse a data file

0 commit comments

Comments
 (0)