git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH RFC 09/10] send-email: Minor cleanup of $smtp_server usage and send_message()

From
Michael Witten <mfwitten@gmail.com>
Date
Apr 11, 2009, 19:08 UTC
Message-ID
<1239476908-25944-9-git-send-email-mfwitten@gmail.com>
In-Reply-To
<1239476908-25944-8-git-send-email-mfwitten@gmail.com>

Note that the output has been changed; the server return code now appears after the `(Sendmail|Server):' line, rather than after the headers.

Signed-off-by: Michael Witten <mfwitten@gmail.com>
---
 Documentation/git-send-email.txt |    3 +-
 git-send-email.perl              |   39 +++++++++++++++++++++++--------------
 2 files changed, 26 insertions(+), 16 deletions(-)
diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt
index f0c2e7b..07c831e 100644
--- a/Documentation/git-send-email.txt
+++ b/Documentation/git-send-email.txt
@@ -135,7 +135,8 @@ user is prompted for a password while the input is masked for privacy.
 	be specified by the 'sendemail.smtpserver' configuration
 	option; the built-in default is `/usr/sbin/sendmail` or
 	`/usr/lib/sendmail` if such program is available, or
-	`localhost` otherwise.
+	`127.0.0.1` otherwise. Also, if <host> is the empty string,
+	then a built-in default is used.
 
 --smtp-server-port=<port>::
 	Specifies a port different from the default port (SMTP
diff --git a/git-send-email.perl b/git-send-email.perl
index c26a1b5..e771720 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -196,7 +196,8 @@ sub do_edit {
 
 # Variables with corresponding config settings
 my ($sleep, $thread, $chain_reply_to, $suppress_from, $signed_off_by_cc, $cc_cmd);
-my ($smtp_server, $smtp_server_port, $smtp_authuser, $smtp_encryption);
+my ($smtp_server, $smtp_server_is_a_command);
+my ($smtp_server_port, $smtp_authuser, $smtp_encryption);
 my ($identity, $aliasfiletype, @alias_files, @smtp_host_parts);
 my ($validate, $confirm);
 my (@suppress_cc);
@@ -761,14 +762,18 @@ if (defined $initial_reply_to) {
 	$initial_reply_to = "<$initial_reply_to>" if $initial_reply_to ne '';
 }
 
-if (!defined $smtp_server) {
+if (defined $smtp_server and $smtp_server ne '') {
+	$smtp_server_is_a_command = ($smtp_server =~ m{^/});
+} else {
 	foreach (qw( /usr/sbin/sendmail /usr/lib/sendmail )) {
 		if (-x $_) {
 			$smtp_server = $_;
+			$smtp_server_is_a_command = 1;
 			last;
 		}
 	}
-	$smtp_server ||= 'localhost'; # could be 127.0.0.1, too... *shrug*
+	$smtp_server_is_a_command = 0;
+	$smtp_server ||= '127.0.0.1';
 }
 
 if ($compose && $compose > 0) {
@@ -977,7 +982,7 @@ X-Mailer: git-send-email $gitversion
 
 	if ($dry_run) {
 		# We don't want to send the email.
-	} elsif ($smtp_server =~ m#^/#) {
+	} elsif ($smtp_server_is_a_command) {
 		my $pid = open my $sm, '|-';
 		defined $pid or die $!;
 		if (!$pid) {
@@ -1053,24 +1058,28 @@ X-Mailer: git-send-email $gitversion
 		$smtp->dataend() or die $smtp->message;
 		$smtp->code =~ /250|200/ or die "Failed to send $subject\n".$smtp->message;
 	}
+
+	print 'Dry-' if $dry_run;
+
 	if ($quiet) {
-		printf (($dry_run ? "Dry-" : "")."Sent %s\n", $subject);
+		print "Sent $subject\n";
 	} else {
-		print (($dry_run ? "Dry-" : "")."OK. Log says:\n");
-		if ($smtp_server !~ m#^/#) {
+		print "OK. Log says:\n";
+
+		if ($smtp_server_is_a_command) {
+			print "Sendmail: $smtp_server ".join(' ',@sendmail_parameters)."\n";
+			print "Result: OK\n";
+		} else {
 			print "Server: $smtp_server\n";
+
+			$dry_run and print "Result: OK\n" or
+			print "Result: ", $smtp->code, ' ', ($smtp->message =~ /\n([^\n]+\n)$/s), "\n";
+
 			print "MAIL FROM:<$raw_from>\n";
 			print "RCPT TO:".join(',',(map { "<$_>" } @recipients))."\n";
-		} else {
-			print "Sendmail: $smtp_server ".join(' ',@sendmail_parameters)."\n";
 		}
+
 		print $header, "\n";
-		if ($smtp) {
-			print "Result: ", $smtp->code, ' ',
-				($smtp->message =~ /\n([^\n]+\n)$/s), "\n";
-		} else {
-			print "Result: OK\n";
-		}
 	}
 
 	return 1;
-- 
1.6.2.2.479.g2aec
Previous: Michael WittenNext: Michael Witten
Message 9 of 23 in “Docs: send-email: Put options back into alphabetical order”
  1. 01/10 Docs: send-email: Put options back into alphabetical orderMichael Witten, Apr 11, 2009
  2. 02/10 Docs: send-email: Remove superfluous information in CONFIGURATIONMichael Witten, Apr 11, 2009
  3. 03/10 send-email: Cleanup the usage text and docs a bitMichael Witten, Apr 11, 2009
  4. 04/10 send-email: --smtp-server-port should take an integerMichael Witten, Apr 11, 2009
  5. 05/10 send-email: Handle "GIT:" rather than "GIT: " during --composeMichael Witten, Apr 11, 2009
  6. 06/10 send-email: References: should only reference what is actually sentMichael Witten, Apr 11, 2009
  7. 07/10 send-email: Remove horrible mix of tabs and spacesMichael Witten, Apr 11, 2009
  8. 08/10 send-email: Add --sleep for email throttlingMichael Witten, Apr 11, 2009
  9. 09/10 send-email: Minor cleanup of $smtp_server usage and send_message()Michael Witten, Apr 11, 2009
  10. 10/10 send-email: --compose takes optional argument to existing fileMichael Witten, Apr 11, 2009
  11. Sverre RabbelierApr 11, 2009
  12. Michael WittenApr 11, 2009
  13. Stephen BoydApr 11, 2009
  14. Michael WittenApr 11, 2009
  15. Jay SoffianApr 12, 2009
  16. Michael WittenApr 12, 2009
  17. Sverre RabbelierApr 11, 2009
  18. Michael WittenApr 11, 2009
  19. Miles BaderApr 13, 2009
  20. Michael WittenApr 13, 2009
  21. Stephen BoydApr 11, 2009
  22. Michael WittenApr 11, 2009
  23. Stephen BoydApr 11, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.