-sub add_text_body {
- my ($enc_msg, $part, $part_nr) = @_;
- return '' if $part->subparts;
+sub attach_link ($$$$) {
+ my ($upfx, $ct, $p, $fn) = @_;
+ my ($part, $depth, @idx) = @$p;
+ my $nl = $idx[-1] > 1 ? "\n" : '';
+ my $idx = join('.', @idx);
+ my $size = bytes::length($part->body);
+ $ct ||= 'text/plain';
+ $ct =~ s/;.*//; # no attributes
+ $ct = ascii_html($ct);
+ my $desc = $part->header('Content-Description');
+ $desc = $fn unless defined $desc;
+ $desc = '' unless defined $desc;
+ my $sfn;
+ if (defined $fn && $fn =~ /\A[[:alnum:]][\w\.-]+[[:alnum:]]\z/) {
+ $sfn = $fn;
+ } elsif ($ct eq 'text/plain') {
+ $sfn = 'a.txt';
+ } else {
+ $sfn = 'a.bin';
+ }
+ my @ret = qq($nl<a\nhref="$upfx$idx-$sfn">[-- Attachment #$idx: );
+ my $ts = "Type: $ct, Size: $size bytes";
+ push(@ret, ($desc eq '') ? "$ts --]" : "$desc --]\n[-- $ts --]");
+ join('', @ret, '</a>');
+}