git: add realName inside From field

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 <email>

format.
This commit is contained in:
Léo DUBOIN 2024-05-06 08:17:53 +02:00 committed by GitHub
parent 3dfe05aa9b
commit 2b87a11125
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 11 additions and 10 deletions

View file

@ -392,7 +392,7 @@ in {
nameValuePair "sendemail.${name}" (if account.msmtp.enable then { nameValuePair "sendemail.${name}" (if account.msmtp.enable then {
smtpServer = "${pkgs.msmtp}/bin/msmtp"; smtpServer = "${pkgs.msmtp}/bin/msmtp";
envelopeSender = "auto"; envelopeSender = "auto";
from = address; from = "${realName} <${address}>";
} else } else
{ {
smtpEncryption = if smtp.tls.enable then smtpEncryption = if smtp.tls.enable then
@ -407,7 +407,7 @@ in {
mkIf smtp.tls.enable (toString smtp.tls.certificatesFile); mkIf smtp.tls.enable (toString smtp.tls.certificatesFile);
smtpServer = smtp.host; smtpServer = smtp.host;
smtpUser = userName; smtpUser = userName;
from = address; from = "${realName} <${address}>";
} // optionalAttrs (smtp.port != null) { } // optionalAttrs (smtp.port != null) {
smtpServerPort = smtp.port; smtpServerPort = smtp.port;
}); });

View file

@ -1,12 +1,12 @@
[sendemail "hm-account"] [sendemail "hm-account"]
from = "hm@example.org" from = "H. M. Test Jr. <hm@example.org>"
smtpEncryption = "tls" smtpEncryption = "tls"
smtpServer = "smtp.example.org" smtpServer = "smtp.example.org"
smtpSslCertPath = "/etc/test/certificates.crt" smtpSslCertPath = "/etc/test/certificates.crt"
smtpUser = "home.manager.jr" smtpUser = "home.manager.jr"
[sendemail "hm@example.com"] [sendemail "hm@example.com"]
from = "hm@example.com" from = "H. M. Test <hm@example.com>"
smtpEncryption = "ssl" smtpEncryption = "ssl"
smtpServer = "smtp.example.com" smtpServer = "smtp.example.com"
smtpSslCertPath = "/etc/ssl/certs/ca-certificates.crt" smtpSslCertPath = "/etc/ssl/certs/ca-certificates.crt"

View file

@ -33,8 +33,8 @@ with lib;
./git-with-email-expected.conf ./git-with-email-expected.conf
} }
assertGitConfig "sendemail.hm@example.com.from" "hm@example.com" assertGitConfig "sendemail.hm@example.com.from" "H. M. Test <hm@example.com>"
assertGitConfig "sendemail.hm-account.from" "hm@example.org" assertGitConfig "sendemail.hm-account.from" "H. M. Test Jr. <hm@example.org>"
''; '';
}; };
} }

View file

@ -1,5 +1,5 @@
[sendemail "hm-account"] [sendemail "hm-account"]
from = "hm@example.org" from = "H. M. Test Jr. <hm@example.org>"
smtpEncryption = "tls" smtpEncryption = "tls"
smtpServer = "smtp.example.org" smtpServer = "smtp.example.org"
smtpSslCertPath = "/etc/ssl/certs/ca-certificates.crt" smtpSslCertPath = "/etc/ssl/certs/ca-certificates.crt"
@ -7,7 +7,7 @@
[sendemail "hm@example.com"] [sendemail "hm@example.com"]
envelopeSender = "auto" envelopeSender = "auto"
from = "hm@example.com" from = "H. M. Test <hm@example.com>"
smtpServer = "@msmtp@/bin/msmtp" smtpServer = "@msmtp@/bin/msmtp"
[user] [user]

View file

@ -7,6 +7,7 @@ with lib;
config = { config = {
accounts.email.accounts."hm@example.com".msmtp.enable = true; accounts.email.accounts."hm@example.com".msmtp.enable = true;
programs.git = { programs.git = {
enable = true; enable = true;
package = pkgs.gitMinimal; package = pkgs.gitMinimal;
@ -33,8 +34,8 @@ with lib;
assertFileContent home-files/.config/git/config \ assertFileContent home-files/.config/git/config \
${./git-with-msmtp-expected.conf} ${./git-with-msmtp-expected.conf}
assertGitConfig "sendemail.hm@example.com.from" "hm@example.com" assertGitConfig "sendemail.hm@example.com.from" "H. M. Test <hm@example.com>"
assertGitConfig "sendemail.hm-account.from" "hm@example.org" assertGitConfig "sendemail.hm-account.from" "H. M. Test Jr. <hm@example.org>"
assertGitConfig "sendemail.hm@example.com.smtpServer" "${pkgs.msmtp}/bin/msmtp" assertGitConfig "sendemail.hm@example.com.smtpServer" "${pkgs.msmtp}/bin/msmtp"
assertGitConfig "sendemail.hm@example.com.envelopeSender" "auto" assertGitConfig "sendemail.hm@example.com.envelopeSender" "auto"
''; '';