Permalink
Browse files

New --add-header and --replace-header options.

  • Loading branch information...
1 parent 3691b4d commit b606106db1c4dec04f567bd6ab1c9e92ac3e4045 @mludvig committed Mar 30, 2012
Showing with 21 additions and 0 deletions.
  1. +21 −0 smtp-cli
View
21 smtp-cli
@@ -12,6 +12,7 @@ my $version = "3.0+git";
#
# ChangeLog:
# * Version 3.1 (???)
+# - New --add-header and --replace-header options.
#
# * Version 3.0 (2012-01-24)
# - Support for server SSL verification agains CA root cert.
@@ -86,6 +87,7 @@ my ($user, $pass, $host, $port, $addr_family,
$missing_modules_ok, $missing_modules_count,
$subject, $body_plain, $body_html, $charset, $print_only,
@attachments, @attachments_inline,
+ @add_headers, @replace_headers,
$ssl_ca_file, $ssl_ca_path,
$sock, $built_message);
@@ -137,6 +139,8 @@ GetOptions (
'charset=s' => \$charset,
'attachment|attach=s' => \@attachments,
'attachment-inline|attach-inline=s' => \@attachments_inline,
+ 'add-header=s' => \@add_headers,
+ 'replace-header=s' => \@replace_headers,
'print-only' => \$print_only,
'missing-modules-ok' => \$missing_modules_ok,
'ssl-ca-file=s' => \$ssl_ca_file,
@@ -830,6 +834,16 @@ sub build_message
$message->replace("Subject" => $subject);
$message->replace("X-Mailer" => "smtp-cli $version, see http://smtp-cli.logix.cz");
$message->replace("Message-ID" => time()."-".int(rand(999999))."\@smtp-cli");
+ for my $header (@add_headers) {
+ my ($hdr, $val) = ($header =~ /^([^:]+):\s*(.*)$/);
+ die("Not a valid header format: ${header}\n") if (not $hdr or not $val);
+ $message->add($hdr => $val);
+ }
+ for my $header (@replace_headers) {
+ my ($hdr, $val) = ($header =~ /^([^:]+):\s*(.*)$/);
+ die("Not a valid header format: ${header}\n") if (not $hdr or not $val);
+ $message->replace($hdr => $val);
+ }
return $message;
}
@@ -948,6 +962,13 @@ Usage: smtp-cli [--options]
in the 'body-html' contents.
See --attach for details about MIME-Type.
Can be used multiple times.
+ --add-header=\"Header: value\"
+ --replace-header=\"Header: value\"
+ Add or Replace pretty much any header in the
+ email. For example set a different Mailer
+ label with: --replace-header=\"X-Mailer: Blah\"
+ or add a completely custom header with
+ --add-header=\"X-Something: foo bar\".
--print-only Dump the composed MIME message to standard
output. This is useful mainly for debugging
or in the case you need to run the message

0 comments on commit b606106

Please sign in to comment.