From 2e339cc6daf6b603778c4168b6e7a64b5edacc02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C3=A9o=20DUBOIN?= Date: Fri, 26 Apr 2024 23:01:04 +0200 Subject: [PATCH] git: sendemail: add realName inside From field MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We currently have no way of specifying the sender's name inside the From field, making a patch sent through `git send-email` appear as coming from "xxx@domain.com". In this commit we make this field follow the standard `realName ` format, whenever applicable. Signed-off-by: Léo DUBOIN --- modules/programs/git.nix | 5 ++++- tests/modules/programs/git/git-with-email-expected.conf | 2 +- tests/modules/programs/git/git-with-email.nix | 8 +++++--- tests/modules/programs/git/git-with-msmtp-expected.conf | 2 +- tests/modules/programs/git/git-with-msmtp.nix | 8 ++++++-- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/modules/programs/git.nix b/modules/programs/git.nix index 53728060..b3e552bd 100644 --- a/modules/programs/git.nix +++ b/modules/programs/git.nix @@ -407,7 +407,10 @@ in { mkIf smtp.tls.enable (toString smtp.tls.certificatesFile); smtpServer = smtp.host; smtpUser = userName; - from = address; + from = if (builtins.stringLength realName == 0) then + address + else + "${realName} <${address}>"; } // optionalAttrs (smtp.port != null) { smtpServerPort = smtp.port; }); diff --git a/tests/modules/programs/git/git-with-email-expected.conf b/tests/modules/programs/git/git-with-email-expected.conf index c34ab1d7..f10e43e4 100644 --- a/tests/modules/programs/git/git-with-email-expected.conf +++ b/tests/modules/programs/git/git-with-email-expected.conf @@ -6,7 +6,7 @@ smtpUser = "home.manager.jr" [sendemail "hm@example.com"] - from = "hm@example.com" + from = "H. M. Test " smtpEncryption = "ssl" smtpServer = "smtp.example.com" smtpSslCertPath = "/etc/ssl/certs/ca-certificates.crt" diff --git a/tests/modules/programs/git/git-with-email.nix b/tests/modules/programs/git/git-with-email.nix index ec18ecb9..82fcd17a 100644 --- a/tests/modules/programs/git/git-with-email.nix +++ b/tests/modules/programs/git/git-with-email.nix @@ -6,8 +6,10 @@ with lib; imports = [ ../../accounts/email-test-accounts.nix ]; config = { - accounts.email.accounts.hm-account.smtp.tls.certificatesFile = - "/etc/test/certificates.crt"; + accounts.email.accounts.hm-account = { + smtp.tls.certificatesFile = "/etc/test/certificates.crt"; + realName = mkForce ""; + }; programs.git = { enable = true; package = pkgs.gitMinimal; @@ -33,7 +35,7 @@ with lib; ./git-with-email-expected.conf } - assertGitConfig "sendemail.hm@example.com.from" "hm@example.com" + assertGitConfig "sendemail.hm@example.com.from" "H. M. Test " assertGitConfig "sendemail.hm-account.from" "hm@example.org" ''; }; diff --git a/tests/modules/programs/git/git-with-msmtp-expected.conf b/tests/modules/programs/git/git-with-msmtp-expected.conf index 1f2c7b79..e837d14a 100644 --- a/tests/modules/programs/git/git-with-msmtp-expected.conf +++ b/tests/modules/programs/git/git-with-msmtp-expected.conf @@ -1,5 +1,5 @@ [sendemail "hm-account"] - from = "hm@example.org" + from = "H. M. Test Jr. " smtpEncryption = "tls" smtpServer = "smtp.example.org" smtpSslCertPath = "/etc/ssl/certs/ca-certificates.crt" diff --git a/tests/modules/programs/git/git-with-msmtp.nix b/tests/modules/programs/git/git-with-msmtp.nix index dc6ba465..85d12723 100644 --- a/tests/modules/programs/git/git-with-msmtp.nix +++ b/tests/modules/programs/git/git-with-msmtp.nix @@ -6,7 +6,11 @@ with lib; imports = [ ../../accounts/email-test-accounts.nix ]; config = { - accounts.email.accounts."hm@example.com".msmtp.enable = true; + accounts.email.accounts."hm@example.com" = { + msmtp.enable = true; + realName = mkForce ""; + }; + programs.git = { enable = true; package = pkgs.gitMinimal; @@ -34,7 +38,7 @@ with lib; ${./git-with-msmtp-expected.conf} assertGitConfig "sendemail.hm@example.com.from" "hm@example.com" - assertGitConfig "sendemail.hm-account.from" "hm@example.org" + assertGitConfig "sendemail.hm-account.from" "H. M. Test Jr. " assertGitConfig "sendemail.hm@example.com.smtpServer" "${pkgs.msmtp}/bin/msmtp" assertGitConfig "sendemail.hm@example.com.envelopeSender" "auto" '';