From 2a6584984b8fe14d9f71531a552be56dabd6b4bf Mon Sep 17 00:00:00 2001 From: Jules Bonnard Date: Fri, 14 Feb 2025 17:50:58 +0100 Subject: [PATCH 1/2] add option to set content-id for each attachment except body --- swaks | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/swaks b/swaks index f01105bb..79c07a28 100755 --- a/swaks +++ b/swaks @@ -2300,6 +2300,10 @@ sub get_option_struct { cfgs => OP_ARG_REQ, okey => 'attach_type', akey => 'attach_accum', type => 'list', }, # A file to attach + { opts => ['attach-id'], suffix => ':s', + cfgs => OP_ARG_REQ, + okey => 'attach_id', akey => 'attach_accum', type => 'list', }, + # A file to attach { opts => ['attach'], suffix => ':s', cfgs => OP_ARG_REQ|OP_FROM_FILE, okey => 'attach_attach', akey => 'attach_accum', type => 'list', }, @@ -3300,6 +3304,7 @@ sub process_args { # first text/plain part my $mime_type = '%SWAKS_DEFAULT_MIMETYTPE%'; my $next_name = undef(); + my $next_id = undef(); my %parts = ( body => [], rest => [] ); $bound = "----=_MIME_BOUNDARY_000_$$"; foreach my $part (@$attach_accum) { @@ -3309,12 +3314,16 @@ sub process_args { elsif ($part eq 'attach_name') { $next_name = get_arg($part, $o); } + elsif ($part eq 'attach_id') { + $next_id = get_arg($part, $o); + } elsif ($part eq 'attach_body') { if ($mime_type eq '%SWAKS_DEFAULT_MIMETYTPE%') { $mime_type = 'text/plain'; } push(@{$parts{body}}, { body => get_arg($part, $o), type => $mime_type }); $next_name = undef(); # can't set filename for body, unset next_name so random attachment doesn't get it + $next_id = undef(); # can't set id for body $mime_type = '%SWAKS_DEFAULT_MIMETYTPE%'; # after each body, reset the default mime type } elsif ($part eq 'attach_attach') { @@ -3334,6 +3343,10 @@ sub process_args { $tpart->{name} =~ s|^.*/([^/]+)$|$1|; } } + if (defined($next_id)) { + $tpart->{id} = $next_id; + $next_id = undef(); + } push(@{$parts{rest}}, $tpart); } else { ptrans(12, "Error processing attach args, unknown type $part when processing attachment options"); @@ -3890,6 +3903,9 @@ sub encode_mime_part { $text .= "Content-Disposition: attachment\n"; } } + if ($part->{id}) { + $text .= "Content-ID: $part->{id}\n" + } $text .= "Content-Transfer-Encoding: BASE64\n" . "\n" . eb64($part->{body}, "\n") . "\n"; } From 808f31803ef5cb795386a80fcfb742907e431fae Mon Sep 17 00:00:00 2001 From: Jules Bonnard Date: Fri, 14 Feb 2025 17:51:53 +0100 Subject: [PATCH 2/2] describe new optional argument to set content-id for each attachment --- RELEASE/doc/ref.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/RELEASE/doc/ref.txt b/RELEASE/doc/ref.txt index 5bc1999f..5ac6afc5 100644 --- a/RELEASE/doc/ref.txt +++ b/RELEASE/doc/ref.txt @@ -1378,6 +1378,14 @@ DATA OPTIONS this option, it causes no filename information to be included for the next MIME part, even if Swaks could generate it from the local file name. (Arg-Optional) + + --attach-id [] + This option sets the Content-ID that will be included in the MIME part + created for the next "--attach" option. This Content-ID can then be referenced + in the HTML body using cid:contentID. If no argument is set for + this option, it causes no Content-ID information to be included for + the next MIME part, even if Swaks could generate it from the local + file name. (Arg-Optional) -ah, --add-header
This option allows headers to be added to the DATA. If