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

[PATCH] Use /etc/mailname for the hostname part of the email address.

From
MKMatt Kraai <kraai@ftbfs.org>
Date
Jul 7, 2007, 02:21 UTC
Message-ID
<11837748652889-git-send-email-kraai@ftbfs.org>
From: Matt Kraai <kraai@asturias.ftbfs.org>

/etc/mailname contains the hostname to be used on outgoing email messages generated locally on Debian systems (cf. http://www.debian.org/doc/debian-policy/ch-customized-programs.html). If it available, use it instead of gethostname or gethostbyname.

Signed-off-by: Matt Kraai <kraai@ftbfs.org>
---
	If this is only appropriate for the Debian package, I
	apologize.  Please let me know if this is the case and I'll
	submit it to the Debian maintainer.
 ident.c |   26 +++++++++++++++++++++++++-
 1 files changed, 25 insertions(+), 1 deletions(-)
diff --git a/ident.c b/ident.c
index 6612d17..3d05ae2 100644
--- a/ident.c
+++ b/ident.c
@@ -43,6 +43,27 @@ static void copy_gecos(const struct passwd *w, char *name, size_t sz)
 
 }
 
+static int getmailname(char *name, size_t len)
+{
+	FILE *f = fopen("/etc/mailname", "r");
+	int i;
+
+	if (!f)
+		return -1;
+	if (!fgets(name, len, f)) {
+		fclose(f);
+		return -1;
+	}
+	fclose(f);
+	for (i = 0; !isspace(name[i]); i++)
+		;
+	if (name[i - 1] != '.')
+		name[i] = '\0';
+	else
+		name[i - 1] = '\0';
+	return 0;
+}
+
 static void copy_email(const struct passwd *pw)
 {
 	/*
@@ -54,7 +75,10 @@ static void copy_email(const struct passwd *pw)
 		die("Your sysadmin must hate you!");
 	memcpy(git_default_email, pw->pw_name, len);
 	git_default_email[len++] = '@';
-	gethostname(git_default_email + len, sizeof(git_default_email) - len);
+	if (getmailname(git_default_email + len,
+			sizeof(git_default_email) - len) < 0)
+		gethostname(git_default_email + len,
+			    sizeof(git_default_email) - len);
 	if (!strchr(git_default_email+len, '.')) {
 		struct hostent *he = gethostbyname(git_default_email + len);
 		char *domainname;
-- 
1.5.2.3
Next: Linus Torvalds
Message 1 of 3 in “Use /etc/mailname for the hostname part of the email address.”
  1. Use /etc/mailname for the hostname part of the email address.Matt Kraai, Jul 7, 2007
  2. Linus TorvaldsJul 7, 2007
  3. Junio C HamanoJul 7, 2007

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.