@matheusbsbs / matheus-bagliano / commits / 134550fe21
Fork 0

git-send-email.perl - try to give real name of the calling host to HELO/EHLO

Add new functions maildomain_net(), maildomain_mta() and maildomain(), which return FQDN where possible for use in send_message(). The value is passed to Net::SMTP HELO/EHLO handshake. The domain name can also be set via new --smtp-domain option. The default value in Net::SMTP may not get through: Net::SMTP=GLOB(0x267ec28)>>> EHLO localhost.localdomain Net::SMTP=GLOB(0x267ec28)<<< 550 EHLO argument does not match calling host whereas using the FQDN that matches the IP, the result is: Net::SMTP=GLOB(0x15b8e80)>>> EHLO host.example.com Net::SMTP=GLOB(0x15b8e80)<<< 250-host.example.com Hello host.example.com [192.168.1.7] The maildomain*() code is based on ideas in Perl library Test::Reporter by Graham Barr <gbarr@pobox.com> and Mark Overmeer <mailtools@overmeer.net> released under the same terms as Perl itself. Signed-off-by: Jari Aalto <jari.aalto@cante.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jari Aalto committed Mar 14, 2010 at 17:16 UTC 134550fe21f2c70519b32cada993bfd0c644925b
1 file changed +67 -1
git-send-email.perl
+67 -1
@@ -64,6 +64,7 @@ git send-email [options] <file | directory | rev-list options >
64 --smtp-pass <str> * Password for SMTP-AUTH; not necessary.
65 --smtp-encryption <str> * tls or ssl; anything else disables.
66 --smtp-ssl * Deprecated. Use '--smtp-encryption ssl'.
67 + --smtp-domain <str> * The domain name sent to HELO/EHLO handshake
68 --smtp-debug <0|1> * Disable, enable Net::SMTP debug.
69
70 Automating:
@@ -131,6 +132,8 @@ my $have_email_valid = eval { require Email::Valid; 1 };
132 my $have_mail_address = eval { require Mail::Address; 1 };
133 my $smtp;
134 my $auth;
135 +my $mail_domain_default = "localhost.localdomain";
136 +my $mail_domain;
137
138 sub unique_email_list(@);
139 sub cleanup_compose_files();
@@ -274,6 +277,7 @@ my $rc = GetOptions("sender|from=s" => \$sender,
277 "smtp-ssl" => sub { $smtp_encryption = 'ssl' },
278 "smtp-encryption=s" => \$smtp_encryption,
279 "smtp-debug:i" => \$debug_net_smtp,
280 + "smtp-domain:s" => \$mail_domain,
281 "identity=s" => \$identity,
282 "annotate" => \$annotate,
283 "compose" => \$compose,
@@ -834,6 +838,62 @@ sub sanitize_address
838
839 }
840
841 +# Returns the local Fully Qualified Domain Name (FQDN) if available.
842 +#
843 +# Tightly configured MTAa require that a caller sends a real DNS
844 +# domain name that corresponds the IP address in the HELO/EHLO
845 +# handshake. This is used to verify the connection and prevent
846 +# spammers from trying to hide their identity. If the DNS and IP don't
847 +# match, the receiveing MTA may deny the connection.
848 +#
849 +# Here is a deny example of Net::SMTP with the default "localhost.localdomain"
850 +#
851 +# Net::SMTP=GLOB(0x267ec28)>>> EHLO localhost.localdomain
852 +# Net::SMTP=GLOB(0x267ec28)<<< 550 EHLO argument does not match calling host
853 +#
854 +# This maildomain*() code is based on ideas in Perl library Test::Reporter
855 +# /usr/share/perl5/Test/Reporter/Mail/Util.pm ==> sub _maildomain ()
856 +
857 +sub maildomain_net
858 +{
859 + my $maildomain;
860 +
861 + if (eval { require Net::Domain; 1 }) {
862 + my $domain = Net::Domain::domainname();
863 + $maildomain = $domain
864 + unless $^O eq 'darwin' && $domain =~ /\.local$/;
865 + }
866 +
867 + return $maildomain;
868 +}
869 +
870 +sub maildomain_mta
871 +{
872 + my $maildomain;
873 +
874 + if (eval { require Net::SMTP; 1 }) {
875 + for my $host (qw(mailhost localhost)) {
876 + my $smtp = Net::SMTP->new($host);
877 + if (defined $smtp) {
878 + my $domain = $smtp->domain;
879 + $smtp->quit;
880 +
881 + $maildomain = $domain
882 + unless $^O eq 'darwin' && $domain =~ /\.local$/;
883 +
884 + last if $maildomain;
885 + }
886 + }
887 + }
888 +
889 + return $maildomain;
890 +}
891 +
892 +sub maildomain
893 +{
894 + return maildomain_net() || maildomain_mta() || $mail_domain_default;
895 +}
896 +
897 # Returns 1 if the message was sent, and 0 otherwise.
898 # In actuality, the whole program dies when there
899 # is an error sending a message.
@@ -936,13 +996,18 @@ X-Mailer: git-send-email $gitversion
996 if ($smtp_encryption eq 'ssl') {
997 $smtp_server_port ||= 465; # ssmtp
998 require Net::SMTP::SSL;
939 - $smtp ||= Net::SMTP::SSL->new($smtp_server, Port => $smtp_server_port);
999 + $mail_domain ||= maildomain();
1000 + $smtp ||= Net::SMTP::SSL->new($smtp_server,
1001 + Hello => $mail_domain,
1002 + Port => $smtp_server_port);
1003 }
1004 else {
1005 require Net::SMTP;
1006 + $mail_domain ||= maildomain();
1007 $smtp ||= Net::SMTP->new((defined $smtp_server_port)
1008 ? "$smtp_server:$smtp_server_port"
1009 : $smtp_server,
1010 + Hello => $mail_domain,
1011 Debug => $debug_net_smtp);
1012 if ($smtp_encryption eq 'tls' && $smtp) {
1013 require Net::SMTP::SSL;
@@ -965,6 +1030,7 @@ X-Mailer: git-send-email $gitversion
1030 die "Unable to initialize SMTP properly. Check config and use --smtp-debug. ",
1031 "VALUES: server=$smtp_server ",
1032 "encryption=$smtp_encryption ",
1033 + "maildomain=$mail_domain",
1034 defined $smtp_server_port ? "port=$smtp_server_port" : "";
1035 }
1036