{"thread":{"id":"9760","subject":"[PATCH] send-email: Add support for SSL and SMTP-AUTH","startedAt":"2007-09-02T18:06:25Z","lastAt":"2007-09-03T07:58:45Z","messageCount":3,"participants":["Douglas Stockwell","Wincent Colaiuta","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"52291","messageId":"11887563853329-git-send-email-doug@11011.net","threadId":"9760","inReplyTo":null,"subject":"[PATCH] send-email: Add support for SSL and SMTP-AUTH","fromName":"Douglas Stockwell","fromEmail":"doug@11011.net","sentAt":"2007-09-02T18:06:25Z","receivedAt":"2007-09-02T18:06:25Z","isPatch":true,"sender":{"key":"doug@11011.net","avatar":"https://gravatar.com/avatar/c9662328271b711eeb534c6a1ec17bb36278acd3170655ca622bde24e221ca87?d=mp&s=160"},"body":"Allows username and password to be given using --smtp-user\nand --smtp-pass. SSL use is flagged by --smtp-ssl. These are\nbacked by corresponding defaults in the git configuration file.\n\nThis implements Junio's 'mail identity' suggestion in a slightly\nmore generalised manner. --identity=$identity, backed by\nsendemail.identity indicates that the configuration subsection\n[sendemail \"$identity\"] should take priority over the [sendemail]\nsection for all configuration values.\n\nSigned-off-by: Douglas Stockwell <doug@11011.net>\n---\n Documentation/git-send-email.txt |   35 +++++++++++++-\n git-send-email.perl              |  101 ++++++++++++++++++++++++++++----------\n 2 files changed, 109 insertions(+), 27 deletions(-)\n\ndiff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt\nindex 16bfd7b..1ec61af 100644\n--- a/Documentation/git-send-email.txt\n+++ b/Documentation/git-send-email.txt\n@@ -75,6 +75,12 @@ The --cc option must be repeated for each user you want on the cc list.\n \tMake git-send-email less verbose.  One line per email should be\n \tall that is output.\n \n+--identity::\n+\tA configuration identity. When given, causes values in the\n+\t'sendemail.<identity>' subsection to take precedence over\n+\tvalues in the 'sendemail' section. The default identity is\n+\tthe value of 'sendemail.identity'.\n+\n --smtp-server::\n \tIf set, specifies the outgoing SMTP server to use (e.g.\n \t`smtp.example.com` or a raw IP address).  Alternatively it can\n@@ -85,6 +91,17 @@ The --cc option must be repeated for each user you want on the cc list.\n \t`/usr/lib/sendmail` if such program is available, or\n \t`localhost` otherwise.\n \n+--smtp-user, --smtp-pass::\n+\tUsername and password for SMTP-AUTH. Defaults are the values of\n+\tthe configuration values 'sendemail.smtpuser' and\n+\t'sendemail.smtppass', but see also 'sendemail.identity'.\n+\tIf not set, authentication is not attempted.\n+\n+--smtp-ssl::\n+\tIf set, connects to the SMTP server using SSL.\n+\tDefault is the value of the 'sendemail.smtpssl' configuration value;\n+\tif that is unspecified, does not use SSL.\n+\n --subject::\n \tSpecify the initial subject of the email thread.\n \tOnly necessary if --compose is also set.  If --compose\n@@ -122,6 +139,13 @@ The --to option must be repeated for each user you want on the to list.\n \n CONFIGURATION\n -------------\n+sendemail.identity::\n+\tThe default configuration identity. When specified,\n+\t'sendemail.<identity>.<item>' will have higher precedence than\n+\t'sendemail.<item>'. This is useful to declare multiple SMTP\n+\tidentities and to hoist sensitive authentication information\n+\tout of the repository and into the global configuation file.\n+\n sendemail.aliasesfile::\n \tTo avoid typing long email addresses, point this to one or more\n \temail aliases files.  You must also supply 'sendemail.aliasfiletype'.\n@@ -141,7 +165,16 @@ sendemail.chainreplyto::\n \tparameter.\n \n sendemail.smtpserver::\n-\tDefault smtp server to use.\n+\tDefault SMTP server to use.\n+\n+sendemail.smtpuser::\n+\tDefault SMTP-AUTH username.\n+\n+sendemail.smtppass::\n+\tDefault SMTP-AUTH password.\n+\n+sendemail.smtpssl::\n+\tBoolean value specifying the default to the '--smtp-ssl' parameter.\n \n Author\n ------\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex e0b7d12..dd7560b 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -73,9 +73,18 @@ Options:\n    --signed-off-cc Automatically add email addresses that appear in\n                  Signed-off-by: or Cc: lines to the cc: list. Defaults to on.\n \n+   --identity     The configuration identity, a subsection to prioritise over\n+                  the default section.\n+\n    --smtp-server  If set, specifies the outgoing SMTP server to use.\n                   Defaults to localhost.\n \n+   --smtp-user    The username for SMTP-AUTH.\n+\n+   --smtp-pass    The password for SMTP-AUTH.\n+\n+   --smtp-ssl     If set, connects to the SMTP server using SSL.\n+\n    --suppress-from Suppress sending emails to yourself if your address\n                   appears in a From: line. Defaults to off.\n \n@@ -145,7 +154,6 @@ my $compose_filename = \".msg.$$\";\n my (@to,@cc,@initial_cc,@bcclist,@xh,\n \t$initial_reply_to,$initial_subject,@files,$author,$sender,$compose,$time);\n \n-my $smtp_server;\n my $envelope_sender;\n \n # Example reply to:\n@@ -164,24 +172,26 @@ my ($quiet, $dry_run) = (0, 0);\n \n # Variables with corresponding config settings\n my ($thread, $chain_reply_to, $suppress_from, $signed_off_cc, $cc_cmd);\n+my ($smtp_server, $smtp_authuser, $smtp_authpass, $smtp_ssl);\n+my ($identity, $aliasfiletype, @alias_files);\n \n-my %config_settings = (\n+my %config_bool_settings = (\n     \"thread\" => [\\$thread, 1],\n     \"chainreplyto\" => [\\$chain_reply_to, 1],\n     \"suppressfrom\" => [\\$suppress_from, 0],\n     \"signedoffcc\" => [\\$signed_off_cc, 1],\n-    \"cccmd\" => [\\$cc_cmd, \"\"],\n+    \"smtpssl\" => [\\$smtp_ssl, 0],\n );\n \n-foreach my $setting (keys %config_settings) {\n-    my $config = $repo->config_bool(\"sendemail.$setting\");\n-    ${$config_settings{$setting}->[0]} = (defined $config) ? $config : $config_settings{$setting}->[1];\n-}\n-\n-@bcclist = $repo->config('sendemail.bcc');\n-if (!@bcclist or !$bcclist[0]) {\n-    @bcclist = ();\n-}\n+my %config_settings = (\n+    \"smtpserver\" => \\$smtp_server,\n+    \"smtpuser\" => \\$smtp_authuser,\n+    \"smtppass\" => \\$smtp_authpass,\n+    \"cccmd\" => \\$cc_cmd,\n+    \"aliasfiletype\" => \\$aliasfiletype,\n+    \"bcc\" => \\@bcclist,\n+    \"aliasesfile\" => \\@alias_files,\n+);\n \n # Begin by accumulating all the variables (defined above), that we will end up\n # needing, first, from the command line:\n@@ -194,6 +204,10 @@ my $rc = GetOptions(\"sender|from=s\" => \\$sender,\n \t\t    \"bcc=s\" => \\@bcclist,\n \t\t    \"chain-reply-to!\" => \\$chain_reply_to,\n \t\t    \"smtp-server=s\" => \\$smtp_server,\n+\t\t    \"smtp-user=s\" => \\$smtp_authuser,\n+\t\t    \"smtp-pass=s\" => \\$smtp_authpass,\n+\t\t    \"smtp-ssl!\" => \\$smtp_ssl,\n+\t\t    \"identity=s\" => \\$identity,\n \t\t    \"compose\" => \\$compose,\n \t\t    \"quiet\" => \\$quiet,\n \t\t    \"cc-cmd=s\" => \\$cc_cmd,\n@@ -208,6 +222,43 @@ unless ($rc) {\n     usage();\n }\n \n+# Now, let's fill any that aren't set in with defaults:\n+\n+sub read_config {\n+\tmy ($prefix) = @_;\n+\n+\tforeach my $setting (keys %config_bool_settings) {\n+\t\tmy $target = $config_bool_settings{$setting}->[0];\n+\t\t$$target = $repo->config_bool(\"$prefix.$setting\") unless (defined $$target);\n+\t}\n+\n+\tforeach my $setting (keys %config_settings) {\n+\t\tmy $target = $config_settings{$setting};\n+\t\tif (ref($target) eq \"ARRAY\") {\n+\t\t\tunless (@$target) {\n+\t\t\t\tmy @values = $repo->config(\"$prefix.$setting\");\n+\t\t\t\t@$target = @values if (@values && defined $values[0]);\n+\t\t\t}\n+\t\t}\n+\t\telse {\n+\t\t\t$$target = $repo->config(\"$prefix.$setting\") unless (defined $$target);\n+\t\t}\n+\t}\n+}\n+\n+# read configuration from [sendemail \"$identity\"], fall back on [sendemail]\n+$identity = $repo->config(\"sendemail.identity\") unless (defined $identity);\n+read_config(\"sendemail.$identity\") if (defined $identity);\n+read_config(\"sendemail\");\n+\n+# fall back on builtin bool defaults\n+foreach my $setting (values %config_bool_settings) {\n+\t${$setting->[0]} = $setting->[1] unless (defined (${$setting->[0]}));\n+}\n+\n+my ($repoauthor) = $repo->ident_person('author');\n+my ($repocommitter) = $repo->ident_person('committer');\n+\n # Verify the user input\n \n foreach my $entry (@to) {\n@@ -222,14 +273,7 @@ foreach my $entry (@bcclist) {\n \tdie \"Comma in --bcclist entry: $entry'\\n\" unless $entry !~ m/,/;\n }\n \n-# Now, let's fill any that aren't set in with defaults:\n-\n-my ($repoauthor) = $repo->ident_person('author');\n-my ($repocommitter) = $repo->ident_person('committer');\n-\n my %aliases;\n-my @alias_files = $repo->config('sendemail.aliasesfile');\n-my $aliasfiletype = $repo->config('sendemail.aliasfiletype');\n my %parse_alias = (\n \t# multiline formats can be supported in the future\n \tmutt => sub { my $fh = shift; while (<$fh>) {\n@@ -320,10 +364,7 @@ if ($thread && !defined $initial_reply_to && $prompting) {\n \t$initial_reply_to =~ s/(^\\s+|\\s+$)//g;\n }\n \n-if (!$smtp_server) {\n-\t$smtp_server = $repo->config('sendemail.smtpserver');\n-}\n-if (!$smtp_server) {\n+if (!defined $smtp_server) {\n \tforeach (qw( /usr/sbin/sendmail /usr/lib/sendmail )) {\n \t\tif (-x $_) {\n \t\t\t$smtp_server = $_;\n@@ -553,8 +594,16 @@ X-Mailer: git-send-email $gitversion\n \t\tprint $sm \"$header\\n$message\";\n \t\tclose $sm or die $?;\n \t} else {\n-\t\trequire Net::SMTP;\n-\t\t$smtp ||= Net::SMTP->new( $smtp_server );\n+\t\tif ($smtp_ssl) {\n+\t\t\trequire Net::SMTP::SSL;\n+\t\t\t$smtp ||= Net::SMTP::SSL->new( $smtp_server, Port => 465 );\n+\t\t}\n+\t\telse {\n+\t\t\trequire Net::SMTP;\n+\t\t\t$smtp ||= Net::SMTP->new( $smtp_server );\n+\t\t}\n+\t\t$smtp->auth( $smtp_authuser, $smtp_authpass )\n+\t\t\tor die $smtp->message if (defined $smtp_authuser);\n \t\t$smtp->mail( $raw_from ) or die $smtp->message;\n \t\t$smtp->to( @recipients ) or die $smtp->message;\n \t\t$smtp->data or die $smtp->message;\n@@ -661,7 +710,7 @@ foreach my $t (@files) {\n \t}\n \tclose F;\n \n-\tif ($cc_cmd ne \"\") {\n+\tif (defined $cc_cmd) {\n \t\topen(F, \"$cc_cmd $t |\")\n \t\t\tor die \"(cc-cmd) Could not execute '$cc_cmd'\";\n \t\twhile(<F>) {\n-- \n1.5.3.1.gc752\n"},{"id":"52303","messageId":"8C6EBB4A-5E0D-485B-A0C4-E5C0C8038D03@wincent.com","threadId":"9760","inReplyTo":"11887563853329-git-send-email-doug@11011.net","subject":"Re: [PATCH] send-email: Add support for SSL and SMTP-AUTH","fromName":"Wincent Colaiuta","fromEmail":"win@wincent.com","sentAt":"2007-09-03T06:48:09Z","receivedAt":"2007-09-03T06:48:09Z","isPatch":true,"sender":{"key":"greg@hurrell.net","avatar":"https://avatars.githubusercontent.com/u/7074?v=4"},"body":"El 2/9/2007, a las 20:06, Douglas Stockwell escribió:\n\n> Allows username and password to be given using --smtp-user\n> and --smtp-pass. SSL use is flagged by --smtp-ssl. These are\n> backed by corresponding defaults in the git configuration file.\n>\n> This implements Junio's 'mail identity' suggestion in a slightly\n> more generalised manner. --identity=$identity, backed by\n> sendemail.identity indicates that the configuration subsection\n> [sendemail \"$identity\"] should take priority over the [sendemail]\n> section for all configuration values.\n\nThis will be really useful to me in my current set-up. I'll test it  \nhere locally and let you know if I can find any problems.\n\nCheers,\nWincent\n"},{"id":"52309","messageId":"7vwsv8mb7u.fsf@gitster.siamese.dyndns.org","threadId":"9760","inReplyTo":"11887563853329-git-send-email-doug@11011.net","subject":"Re: [PATCH] send-email: Add support for SSL and SMTP-AUTH","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2007-09-03T07:58:45Z","receivedAt":"2007-09-03T07:58:45Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Douglas Stockwell <doug@11011.net> writes:\n\n> Allows username and password to be given using --smtp-user\n> and --smtp-pass. SSL use is flagged by --smtp-ssl. These are\n> backed by corresponding defaults in the git configuration file.\n>\n> This implements Junio's 'mail identity' suggestion in a slightly\n> more generalised manner. --identity=$identity, backed by\n> sendemail.identity indicates that the configuration subsection\n> [sendemail \"$identity\"] should take priority over the [sendemail]\n> section for all configuration values.\n\nEven better than what I suggested, doing a lot more with the\nsame identity mechanism.  I think it often is the case that\n\"when I work on this project, I send e-mail as this user to talk\nwith that server to send e-mail, and that server happens to talk\nsmtps so use that\", and a single \"identity\" setting is a good\nway to capture that.  Very nice.\n"}]}