{"thread":{"id":"23413","subject":"[PATCH v3 2/4] send-email: Don't use FQDNs without a '.'","startedAt":"2010-04-10T14:53:52Z","lastAt":"2010-04-10T20:02:00Z","messageCount":6,"participants":["Brian Gernhardt","Junio C Hamano"],"isPatch":true,"patchVersion":3,"patchTotal":4},"messages":[{"id":"139159","messageId":"1270911236-32476-1-git-send-email-brian@gernhardtsoftware.com","threadId":"23413","inReplyTo":null,"subject":"[PATCH v3 0/4] send-email: --smtp-domain improvements","fromName":"Brian Gernhardt","fromEmail":"brian@gernhardtsoftware.com","sentAt":"2010-04-10T14:53:52Z","receivedAt":"2010-04-10T14:53:52Z","isPatch":true,"sender":{"key":"brian@gernhardtsoftware.com","avatar":"https://avatars.githubusercontent.com/u/133455?v=4"},"body":"Next iteration of my small series of fixes to --smtp-domain.\n\nChanges since v2:\n\n1/4: Added a patch that standardizes on a single bracket style for subs.\n\n2/4: Fixed the style of valid_fqdn() and calls to it.\n\n4/4: Remove default variable and significantly improve commit message.\n\nMany thanks to Jakub Narebski for his repeated suggestions.\n\nBrian Gernhardt (4):\n  send-email: Cleanup { style\n  send-email: Don't use FQDNs without a '.'\n  Document send-email --smtp-domain\n  send-email: Cleanup smtp-domain and add config\n\n Documentation/config.txt         |    1 +\n Documentation/git-send-email.txt |    7 +++++\n git-send-email.perl              |   48 +++++++++++++++++--------------------\n 3 files changed, 30 insertions(+), 26 deletions(-)\n"},{"id":"139157","messageId":"1270911236-32476-2-git-send-email-brian@gernhardtsoftware.com","threadId":"23413","inReplyTo":"1270911236-32476-1-git-send-email-brian@gernhardtsoftware.com","subject":"[PATCH v3 1/4] send-email: Cleanup { style","fromName":"Brian Gernhardt","fromEmail":"brian@gernhardtsoftware.com","sentAt":"2010-04-10T14:53:53Z","receivedAt":"2010-04-10T14:53:53Z","isPatch":true,"sender":{"key":"brian@gernhardtsoftware.com","avatar":"https://avatars.githubusercontent.com/u/133455?v=4"},"body":"As Jakub Narebski pointed out on the list, Perl code usually prefers\n\n  sub func {\n  }\n\nover\n\n  sub func\n  {\n  }\n\ngit-send-email.perl is somewhat inconsistent in its style, with 23\nsubroutines using the first style and 6 using the second.  Convert the\nfew odd subroutines so that the code matches normal Perl style.\n\nSigned-off-by: Brian Gernhardt <brian@gernhardtsoftware.com>\n---\n git-send-email.perl |   18 ++++++------------\n 1 files changed, 6 insertions(+), 12 deletions(-)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex ce569a9..26fe624 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -761,8 +761,7 @@ sub extract_valid_address {\n # We'll setup a template for the message id, using the \"from\" address:\n \n my ($message_id_stamp, $message_id_serial);\n-sub make_message_id\n-{\n+sub make_message_id {\n \tmy $uniq;\n \tif (!defined $message_id_stamp) {\n \t\t$message_id_stamp = sprintf(\"%s-%s\", time, $$);\n@@ -817,8 +816,7 @@ sub is_rfc2047_quoted {\n }\n \n # use the simplest quoting being able to handle the recipient\n-sub sanitize_address\n-{\n+sub sanitize_address {\n \tmy ($recipient) = @_;\n \tmy ($recipient_name, $recipient_addr) = ($recipient =~ /^(.*?)\\s*(<.*)/);\n \n@@ -863,8 +861,7 @@ sub sanitize_address\n # This maildomain*() code is based on ideas in Perl library Test::Reporter\n # /usr/share/perl5/Test/Reporter/Mail/Util.pm ==> sub _maildomain ()\n \n-sub maildomain_net\n-{\n+sub maildomain_net {\n \tmy $maildomain;\n \n \tif (eval { require Net::Domain; 1 }) {\n@@ -876,8 +873,7 @@ sub maildomain_net\n \treturn $maildomain;\n }\n \n-sub maildomain_mta\n-{\n+sub maildomain_mta {\n \tmy $maildomain;\n \n \tif (eval { require Net::SMTP; 1 }) {\n@@ -898,8 +894,7 @@ sub maildomain_mta\n \treturn $maildomain;\n }\n \n-sub maildomain\n-{\n+sub maildomain {\n \treturn maildomain_net() || maildomain_mta() || $mail_domain_default;\n }\n \n@@ -907,8 +902,7 @@ sub maildomain\n # In actuality, the whole program dies when there\n # is an error sending a message.\n \n-sub send_message\n-{\n+sub send_message {\n \tmy @recipients = unique_email_list(@to);\n \t@cc = (grep { my $cc = extract_valid_address($_);\n \t\t      not grep { $cc eq $_ } @recipients\n-- \n1.7.1.rc0.251.g42f41\n"},{"id":"139156","messageId":"1270911236-32476-3-git-send-email-brian@gernhardtsoftware.com","threadId":"23413","inReplyTo":"1270911236-32476-1-git-send-email-brian@gernhardtsoftware.com","subject":"[PATCH v3 2/4] send-email: Don't use FQDNs without a '.'","fromName":"Brian Gernhardt","fromEmail":"brian@gernhardtsoftware.com","sentAt":"2010-04-10T14:53:54Z","receivedAt":"2010-04-10T14:53:54Z","isPatch":true,"sender":{"key":"brian@gernhardtsoftware.com","avatar":"https://avatars.githubusercontent.com/u/133455?v=4"},"body":"Although Net::Domain::domainname attempts to be very thorough, the\nhost's configuration can still refuse to give a FQDN.  Check to see if\nwhat we receive contains a dot as a basic sanity check.\n\nSince the same condition is used twice and getting complex, let's move\nit to a new function.\n\nSigned-off-by: Brian Gernhardt <brian@gernhardtsoftware.com>\n---\n git-send-email.perl |   11 +++++++----\n 1 files changed, 7 insertions(+), 4 deletions(-)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 26fe624..1e9bec1 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -861,13 +861,17 @@ sub sanitize_address {\n # This maildomain*() code is based on ideas in Perl library Test::Reporter\n # /usr/share/perl5/Test/Reporter/Mail/Util.pm ==> sub _maildomain ()\n \n+sub valid_fqdn {\n+\tmy $domain = shift;\n+\treturn !($^O eq 'darwin' && $domain =~ /\\.local$/) && $domain =~ /\\./;\n+}\n+\n sub maildomain_net {\n \tmy $maildomain;\n \n \tif (eval { require Net::Domain; 1 }) {\n \t\tmy $domain = Net::Domain::domainname();\n-\t\t$maildomain = $domain\n-\t\t\tunless $^O eq 'darwin' && $domain =~ /\\.local$/;\n+\t\t$maildomain = $domain if valid_fqdn($domain);\n \t}\n \n \treturn $maildomain;\n@@ -883,8 +887,7 @@ sub maildomain_mta {\n \t\t\t\tmy $domain = $smtp->domain;\n \t\t\t\t$smtp->quit;\n \n-\t\t\t\t$maildomain = $domain\n-\t\t\t\t\tunless $^O eq 'darwin' && $domain =~ /\\.local$/;\n+\t\t\t\t$maildomain = $domain if valid_fqdn($domain);\n \n \t\t\t\tlast if $maildomain;\n \t\t\t}\n-- \n1.7.1.rc0.251.g42f41\n"},{"id":"139158","messageId":"1270911236-32476-4-git-send-email-brian@gernhardtsoftware.com","threadId":"23413","inReplyTo":"1270911236-32476-1-git-send-email-brian@gernhardtsoftware.com","subject":"[PATCH v3 3/4] Document send-email --smtp-domain","fromName":"Brian Gernhardt","fromEmail":"brian@gernhardtsoftware.com","sentAt":"2010-04-10T14:53:55Z","receivedAt":"2010-04-10T14:53:55Z","isPatch":true,"sender":{"key":"brian@gernhardtsoftware.com","avatar":"https://avatars.githubusercontent.com/u/133455?v=4"},"body":"Signed-off-by: Brian Gernhardt <brian@gernhardtsoftware.com>\n---\n Documentation/git-send-email.txt |    6 ++++++\n 1 files changed, 6 insertions(+), 0 deletions(-)\n\ndiff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt\nindex ced35b2..f171471 100644\n--- a/Documentation/git-send-email.txt\n+++ b/Documentation/git-send-email.txt\n@@ -119,6 +119,12 @@ Sending\n \tvalue reverts to plain SMTP.  Default is the value of\n \t'sendemail.smtpencryption'.\n \n+--smtp-domain=<FQDN>::\n+\tSpecifies the Fully Qualified Domain Name (FQDN) used in the\n+\tHELO/EHLO command to the SMTP server.  Some servers require the\n+\tFQDN to match your IP address.  If not set, git send-email attempts\n+\tto determine your FQDN automatically.\n+\n --smtp-pass[=<password>]::\n \tPassword for SMTP-AUTH. The argument is optional: If no\n \targument is specified, then the empty string is used as\n-- \n1.7.1.rc0.251.g42f41\n"},{"id":"139160","messageId":"1270911236-32476-5-git-send-email-brian@gernhardtsoftware.com","threadId":"23413","inReplyTo":"1270911236-32476-1-git-send-email-brian@gernhardtsoftware.com","subject":"[PATCH v3 4/4] send-email: Cleanup smtp-domain and add config","fromName":"Brian Gernhardt","fromEmail":"brian@gernhardtsoftware.com","sentAt":"2010-04-10T14:53:56Z","receivedAt":"2010-04-10T14:53:56Z","isPatch":true,"sender":{"key":"brian@gernhardtsoftware.com","avatar":"https://avatars.githubusercontent.com/u/133455?v=4"},"body":"The way the code stored --smtp-domain was unlike its handling of other\nsimilar options.  Bring it in line with the others by:\n\n- Renaming $mail_domain to $smtp_domain to match the command line\n  option. Also move its declaration from near the top of the file to\n  near other option variables.\n\n- Removing $mail_domain_default.  The variable was used once and only\n  served to move the default away from where it gets used.\n\n- Adding a sendemail.smtpdomain config option.  smtp-domain was the\n  only SMTP configuration option that couldn't be set in the user's\n  .gitconfig.\n\nSigned-off-by: Brian Gernhardt <brian@gernhardtsoftware.com>\n---\n Documentation/config.txt         |    1 +\n Documentation/git-send-email.txt |    3 ++-\n git-send-email.perl              |   19 +++++++++----------\n 3 files changed, 12 insertions(+), 11 deletions(-)\n\ndiff --git a/Documentation/config.txt b/Documentation/config.txt\nindex 626b19a..b755beb 100644\n--- a/Documentation/config.txt\n+++ b/Documentation/config.txt\n@@ -1651,6 +1651,7 @@ sendemail.smtppass::\n sendemail.suppresscc::\n sendemail.suppressfrom::\n sendemail.to::\n+sendemail.smtpdomain::\n sendemail.smtpserver::\n sendemail.smtpserverport::\n sendemail.smtpuser::\ndiff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt\nindex f171471..288a4ec 100644\n--- a/Documentation/git-send-email.txt\n+++ b/Documentation/git-send-email.txt\n@@ -123,7 +123,8 @@ Sending\n \tSpecifies the Fully Qualified Domain Name (FQDN) used in the\n \tHELO/EHLO command to the SMTP server.  Some servers require the\n \tFQDN to match your IP address.  If not set, git send-email attempts\n-\tto determine your FQDN automatically.\n+\tto determine your FQDN automatically.  Default is the value of\n+\t'sendemail.smtpdomain'.\n \n --smtp-pass[=<password>]::\n \tPassword for SMTP-AUTH. The argument is optional: If no\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 1e9bec1..111c981 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -132,8 +132,6 @@ my $have_email_valid = eval { require Email::Valid; 1 };\n my $have_mail_address = eval { require Mail::Address; 1 };\n my $smtp;\n my $auth;\n-my $mail_domain_default = \"localhost.localdomain\";\n-my $mail_domain;\n \n sub unique_email_list(@);\n sub cleanup_compose_files();\n@@ -190,7 +188,7 @@ sub do_edit {\n # Variables with corresponding config settings\n my ($thread, $chain_reply_to, $suppress_from, $signed_off_by_cc, $cc_cmd);\n my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_encryption);\n-my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts);\n+my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts, $smtp_domain);\n my ($validate, $confirm);\n my (@suppress_cc);\n \n@@ -212,6 +210,7 @@ my %config_settings = (\n     \"smtpserverport\" => \\$smtp_server_port,\n     \"smtpuser\" => \\$smtp_authuser,\n     \"smtppass\" => \\$smtp_authpass,\n+\t\"smtpdomain\" => \\$smtp_domain,\n     \"to\" => \\@to,\n     \"cc\" => \\@initial_cc,\n     \"cccmd\" => \\$cc_cmd,\n@@ -283,7 +282,7 @@ my $rc = GetOptions(\"sender|from=s\" => \\$sender,\n \t\t    \"smtp-ssl\" => sub { $smtp_encryption = 'ssl' },\n \t\t    \"smtp-encryption=s\" => \\$smtp_encryption,\n \t\t    \"smtp-debug:i\" => \\$debug_net_smtp,\n-\t\t    \"smtp-domain:s\" => \\$mail_domain,\n+\t\t    \"smtp-domain:s\" => \\$smtp_domain,\n \t\t    \"identity=s\" => \\$identity,\n \t\t    \"annotate\" => \\$annotate,\n \t\t    \"compose\" => \\$compose,\n@@ -898,7 +897,7 @@ sub maildomain_mta {\n }\n \n sub maildomain {\n-\treturn maildomain_net() || maildomain_mta() || $mail_domain_default;\n+\treturn maildomain_net() || maildomain_mta() || 'localhost.localdomain';\n }\n \n # Returns 1 if the message was sent, and 0 otherwise.\n@@ -1002,18 +1001,18 @@ X-Mailer: git-send-email $gitversion\n \t\tif ($smtp_encryption eq 'ssl') {\n \t\t\t$smtp_server_port ||= 465; # ssmtp\n \t\t\trequire Net::SMTP::SSL;\n-\t\t\t$mail_domain ||= maildomain();\n+\t\t\t$smtp_domain ||= maildomain();\n \t\t\t$smtp ||= Net::SMTP::SSL->new($smtp_server,\n-\t\t\t\t\t\t      Hello => $mail_domain,\n+\t\t\t\t\t\t      Hello => $smtp_domain,\n \t\t\t\t\t\t      Port => $smtp_server_port);\n \t\t}\n \t\telse {\n \t\t\trequire Net::SMTP;\n-\t\t\t$mail_domain ||= maildomain();\n+\t\t\t$smtp_domain ||= maildomain();\n \t\t\t$smtp ||= Net::SMTP->new((defined $smtp_server_port)\n \t\t\t\t\t\t ? \"$smtp_server:$smtp_server_port\"\n \t\t\t\t\t\t : $smtp_server,\n-\t\t\t\t\t\t Hello => $mail_domain,\n+\t\t\t\t\t\t Hello => $smtp_domain,\n \t\t\t\t\t\t Debug => $debug_net_smtp);\n \t\t\tif ($smtp_encryption eq 'tls' && $smtp) {\n \t\t\t\trequire Net::SMTP::SSL;\n@@ -1036,7 +1035,7 @@ X-Mailer: git-send-email $gitversion\n \t\t\tdie \"Unable to initialize SMTP properly. Check config and use --smtp-debug. \",\n \t\t\t    \"VALUES: server=$smtp_server \",\n \t\t\t    \"encryption=$smtp_encryption \",\n-\t\t\t    \"maildomain=$mail_domain\",\n+\t\t\t    \"hello=$smtp_domain\",\n \t\t\t    defined $smtp_server_port ? \"port=$smtp_server_port\" : \"\";\n \t\t}\n \n-- \n1.7.1.rc0.251.g42f41\n"},{"id":"139193","messageId":"7v633zvzyf.fsf@alter.siamese.dyndns.org","threadId":"23413","inReplyTo":"1270911236-32476-2-git-send-email-brian@gernhardtsoftware.com","subject":"Re: [PATCH v3 1/4] send-email: Cleanup { style","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-04-10T20:02:00Z","receivedAt":"2010-04-10T20:02:00Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Thanks; will queue all four of them.\n"}]}