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

[PATCH v3 1/3] send-mail: improve checks for valid_fqdn

From
Aditya Garg <gargaditya08@live.com>
Date
May 5, 2025, 15:23 UTC
Message-ID
<PN3PR01MB95971B8A202ADEA412010B35B88E2@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM>
In-Reply-To
<PN3PR01MB9597BD33DB2C4F3BE9E5F4C6B88E2@PN3PR01MB9597.INDPRD01.PROD.OUTLOOK.COM>

The current implementation of a valid Fully Qualified Domain Name is not that strict. It just checks whether it has a dot (.) and if using macOS, it should not end with .local. As per RFC1035[1], from what I understood, the following checks need to be done:

- The domain must contain atleast one dot
- Each label (separated by dots) must be 1-63 characters long
- Labels must start and end with an alphanumeric character
- Labels can contain alphanumeric characters and hyphens
Here are some examples of valid and invalid labels:

'example.com', # Valid 'sub.example.com', # Valid 'my-domain.org', # Valid 'localhost', # Invalid (no dot) 'MacBook..', # Invalid (double dots) '-example.com', # Invalid (starts with a hyphen) 'example-.com', # Invalid (ends with a hyphen) 'example..com', # Invalid (double dots) 'example', # Invalid (no TLD) 'example.local', # Invalid on macOS 'valid-domain.co.uk', # Valid '123.example.com', # Valid 'example.com.', # Invalid (trailing dot) 'toolonglabeltoolonglabeltoolonglabeltoolonglabeltoolonglabeltoolonglabel.com', # Invalid (label > 63 chars)

Due to current implementation, I was not able to send emails from Ubuntu. Upon debugging, I found that the SMTP domain was coming out to be "MacBook.." and was being considered as valid. As a result the script was failing. The debug logs with the failed script are below:

Net::SMTP>>> Net::SMTP(3.15) Net::SMTP>>> Net::Cmd(3.15) Net::SMTP>>> Exporter(5.77) Net::SMTP>>> IO::Socket::IP(0.4101) Net::SMTP>>> IO::Socket(1.52) Net::SMTP>>> IO::Handle(1.52) Net::SMTP=GLOB(0x5db4351225f8)<<< 220 BMXPR01CA0083.outlook.office365.com Microsoft ESMTP MAIL Service ready at Sat, 26 Apr 2025 18:06:30 +0000 [08DD842467C8274D] Net::SMTP=GLOB(0x5db4351225f8)>>> EHLO MacBook.. Net::SMTP=GLOB(0x5db4351225f8)<<< 501 5.5.4 Invalid domain name [BMXPR01CA0083.INDPRD01.PROD.OUTLOOK.COM 2025-04-26T18:06:35.781Z 08DD842467C8274D] Net::SMTP=GLOB(0x5db4351225f8)>>> HELO MacBook.. Net::SMTP=GLOB(0x5db4351225f8)<<< 501 5.5.4 Invalid domain name [BMXPR01CA0083.INDPRD01.PROD.OUTLOOK.COM 2025-04-26T18:06:40.828Z 08DD842467C8274D] Unable to initialize SMTP properly. Check config and use --smtp-debug. VALUES: server=smtp.office365.com encryption=tls hello=MacBook.. port=587 at ../git-send-email.perl line 1727.

With this patch, it was fixed and was being considered as an invalid domain. Logs after this patch:

Net::SMTP>>> Net::SMTP(3.15) Net::SMTP>>> Net::Cmd(3.15) Net::SMTP>>> Exporter(5.77) Net::SMTP>>> IO::Socket::IP(0.4101) Net::SMTP>>> IO::Socket(1.52) Net::SMTP>>> IO::Handle(1.52) Net::SMTP=GLOB(0x58c8af71e930)<<< 220 PN4P287CA0064.outlook.office365.com Microsoft ESMTP MAIL Service ready at Sat, 26 Apr 2025 18:08:13 +0000 [08DD84B323498C1A] Net::SMTP=GLOB(0x58c8af71e930)>>> EHLO localhost.localdomain Net::SMTP=GLOB(0x58c8af71e930)<<< 250-PN4P287CA0064.outlook.office365.com Hello [2401:4900:a052:31f0:9beb:e613:56e8:f897] Net::SMTP=GLOB(0x58c8af71e930)<<< 250-SIZE 157286400 Net::SMTP=GLOB(0x58c8af71e930)<<< 250-PIPELINING Net::SMTP=GLOB(0x58c8af71e930)<<< 250-DSN Net::SMTP=GLOB(0x58c8af71e930)<<< 250-ENHANCEDSTATUSCODES Net::SMTP=GLOB(0x58c8af71e930)<<< 250-STARTTLS Net::SMTP=GLOB(0x58c8af71e930)<<< 250-8BITMIME Net::SMTP=GLOB(0x58c8af71e930)<<< 250-BINARYMIME Net::SMTP=GLOB(0x58c8af71e930)<<< 250-CHUNKING Net::SMTP=GLOB(0x58c8af71e930)<<< 250 SMTPUTF8 Net::SMTP=GLOB(0x58c8af71e930)>>> STARTTLS Net::SMTP=GLOB(0x58c8af71e930)<<< 220 2.0.0 SMTP server ready Net::SMTP::_SSL=GLOB(0x58c8af71e930)>>> EHLO localhost.localdomain Net::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-PN4P287CA0064.outlook.office365.com Hello [2401:4900:a052:31f0:9beb:e613:56e8:f897] Net::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-SIZE 157286400 Net::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-PIPELINING Net::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-DSN Net::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-ENHANCEDSTATUSCODES Net::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-AUTH LOGIN XOAUTH2 Net::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-8BITMIME Net::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-BINARYMIME Net::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-CHUNKING Net::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250 SMTPUTF8 Net::SMTP::_SSL=GLOB(0x58c8af71e930)>>> EHLO localhost.localdomain Net::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-PN4P287CA0064.outlook.office365.com Hello [2401:4900:a052:31f0:9beb:e613:56e8:f897] Net::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-SIZE 157286400 Net::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-PIPELINING Net::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-DSN Net::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-ENHANCEDSTATUSCODES Net::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-AUTH LOGIN XOAUTH2 Net::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-8BITMIME Net::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-BINARYMIME Net::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250-CHUNKING Net::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 250 SMTPUTF8 Net::SMTP::_SSL=GLOB(0x58c8af71e930)>>> AUTH XOAUTH2 (OAuth2 access token removed for security) Net::SMTP::_SSL=GLOB(0x58c8af71e930)<<< 235 2.7.0 Authentication successful

[1]: https://datatracker.ietf.org/doc/html/rfc1035
Signed-off-by: Aditya Garg <gargaditya08@live.com>
---
 git-send-email.perl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/git-send-email.perl b/git-send-email.perl
index 4215f8f7e9..4c143e24bf 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -1359,7 +1359,8 @@ sub process_address_list {
 
 sub valid_fqdn {
 	my $domain = shift;
-	return defined $domain && !($^O eq 'darwin' && $domain =~ /\.local$/) && $domain =~ /\./;
+	return defined $domain && !($^O eq 'darwin' && $domain =~ /\.local$/)
+		&& $domain  =~ /^(?!-)[A-Za-z0-9-]{1,63}(?<!-)(\.[A-Za-z0-9-]{1,63})+$/;
 }
 
 sub maildomain_net {
-- 
2.49.0
Previous: Aditya GargNext: Junio C Hamano
Message 16 of 68 in “Improve checks for valid_fqdn in send-email and update documentation”
  1. 0/3 Improve checks for valid_fqdn in send-email and update documentationAditya Garg, May 4, 2025
  2. 1/3 send-mail: improve checks for valid_fqdnAditya Garg, May 4, 2025
  3. Kristoffer HaugsbakkMay 4, 2025
  4. Aditya GargMay 4, 2025
  5. Kristoffer HaugsbakkMay 4, 2025
  6. 2/3 docs: improve send-email documentationAditya Garg, May 4, 2025
  7. 3/3 docs: add credential helper for outlook and gmail in OAuth list of helpersAditya Garg, May 4, 2025
  8. 0/3 Improve checks for valid_fqdn in send-email and update documentationAditya Garg, May 5, 2025
  9. 1/3 send-mail: improve checks for valid_fqdnAditya Garg, May 5, 2025
  10. 2/3 docs: improve send-email documentationAditya Garg, May 5, 2025
  11. Junio C HamanoMay 5, 2025
  12. Aditya GargMay 5, 2025
  13. 3/3 docs: add credential helper for outlook and gmail in OAuth list of helpersAditya Garg, May 5, 2025
  14. 0/3 Improve checks for valid_fqdn in send-email and update documentationAditya Garg, May 5, 2025
  15. 3/3 docs: add credential helper for outlook and gmail in OAuth list of helpersAditya Garg, May 5, 2025
  16. 1/3 send-mail: improve checks for valid_fqdnAditya Garg, May 5, 2025
  17. Junio C HamanoMay 5, 2025
  18. Aditya GargMay 6, 2025
  19. Aditya GargMay 6, 2025
  20. Aditya GargMay 6, 2025
  21. Junio C HamanoMay 6, 2025
  22. Junio C HamanoMay 6, 2025
  23. Aditya GargMay 6, 2025
  24. Aditya GargMay 6, 2025
  25. Junio C HamanoMay 6, 2025
  26. 2/3 docs: improve send-email documentationAditya Garg, May 5, 2025
  27. Junio C HamanoMay 5, 2025
  28. Aditya GargMay 6, 2025
  29. 0/3 Improve checks for valid_fqdn in send-email and update documentationAditya Garg, May 7, 2025
  30. 1/3 send-mail: improve checks for valid_fqdnAditya Garg, May 7, 2025
  31. Aditya GargMay 7, 2025
  32. Junio C HamanoMay 7, 2025
  33. Aditya GargMay 8, 2025
  34. 2/3 docs: improve send-email documentationAditya Garg, May 7, 2025
  35. Junio C HamanoMay 7, 2025
  36. Aditya GargMay 8, 2025
  37. Junio C HamanoMay 8, 2025
  38. Aditya GargMay 8, 2025
  39. Junio C HamanoMay 8, 2025
  40. Aditya GargMay 8, 2025
  41. Junio C HamanoMay 8, 2025
  42. Aditya GargMay 8, 2025
  43. Aditya GargMay 8, 2025
  44. 3/3 docs: add credential helper for outlook and gmail in OAuth list of helpersAditya Garg, May 7, 2025
  45. 0/3 Improve checks for valid_fqdn in send-email and update documentationAditya Garg, May 8, 2025
  46. 1/3 send-mail: improve checks for valid_fqdnAditya Garg, May 8, 2025
  47. 2/3 docs: improve send-email documentationAditya Garg, May 8, 2025
  48. 3/3 docs: add credential helper for outlook and gmail in OAuth list of helpersAditya Garg, May 8, 2025
  49. 0/3 Improve checks for valid_fqdn in send-email and update documentationAditya Garg, May 8, 2025
  50. 1/3 send-mail: improve checks for valid_fqdnAditya Garg, May 8, 2025
  51. 2/3 docs: improve send-email documentationAditya Garg, May 8, 2025
  52. 3/3 docs: add credential helper for outlook and gmail in OAuth list of helpersAditya Garg, May 8, 2025
  53. Junio C HamanoMay 8, 2025
  54. send-email: try to get fqdn by running hostname --fqdn on Linux and macOSAditya Garg, May 9, 2025
  55. Junio C HamanoMay 9, 2025
  56. send-email: try to get fqdn by running hostname --fqdn on Linux and macOSAditya Garg, May 10, 2025
  57. Julian SwagemakersMay 12, 2025
  58. Aditya GargMay 12, 2025
  59. Junio C HamanoMay 12, 2025
  60. Aditya GargMay 12, 2025
  61. Junio C HamanoMay 12, 2025
  62. Aditya GargMay 12, 2025
  63. Eric SunshineMay 12, 2025
  64. Junio C HamanoMay 12, 2025
  65. Aditya GargMay 13, 2025
  66. Junio C HamanoMay 12, 2025
  67. send-email: try to get fqdn by running hostname -f on Linux and macOSAditya Garg, May 12, 2025
  68. send-email: try to get fqdn by running hostname -f on Linux and macOSAditya Garg, May 12, 2025

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.