From: Christian Kastner <ckk@kvr.at>
Date: Fri, 15 Jan 2016 23:12:35 +0100
Subject: Add option to include FQDN in email

Add an option -n to with which the daemon can be instructed to include the FQDN
in the subject when sending mails.

Bug-Debian: https://bugs.debian.org/570423
Forwarded: no
Last-Update: 2015-01-16
---
 cron.8       | 4 ++++
 cron.c       | 8 ++++++--
 cron.h       | 2 ++
 do_command.c | 3 ++-
 4 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/cron.8 b/cron.8
index 77cb100..e1d6736 100644
--- a/cron.8
+++ b/cron.8
@@ -41,6 +41,10 @@ Enable LSB compliant names for /etc/cron.d files.  This setting, however, does
 not affect the parsing of files under /etc/cron.hourly, /etc/cron.daily,
 /etc/cron.weekly or /etc/cron.monthly.
 .TP
+.B \-n
+Include the FQDN in the subject when sending mails.  By default, cron will
+abbreviate the hostname.
+.TP
 .B \-L loglevel
 Tell cron what to log about \fBjobs\fR (errors are logged regardless of this
 value) as the sum of the following values:
diff --git a/cron.c b/cron.c
index 673134a..613e7bf 100644
--- a/cron.c
+++ b/cron.c
@@ -448,9 +448,9 @@ sighup_handler(int x) {
 
 
 #if DEBUGGING
-const char *getoptarg = "flL:x:";
+const char *getoptarg = "flL:nx:";
 #else
-const char *getoptarg = "flL:";
+const char *getoptarg = "flL:n";
 #endif
 
 static void
@@ -463,6 +463,7 @@ parse_args(argc, argv)
 	stay_foreground = 0;
 	lsbsysinit_mode = 0;
 	log_level = 1;
+	fqdn_in_subject = 0;
 
 	while (EOF != (argch = getopt(argc, argv, getoptarg))) {
 		switch (argch) {
@@ -477,6 +478,9 @@ parse_args(argc, argv)
 		case 'L':
 			log_level = atoi(optarg);
 			break;
+		case 'n':
+			fqdn_in_subject = 1;
+			break;
 #if DEBUGGING
 		case 'x':
 			if (!set_debug_flags(optarg))
diff --git a/cron.h b/cron.h
index 94b8e04..b58753d 100644
--- a/cron.h
+++ b/cron.h
@@ -308,6 +308,7 @@ static long GMToff;
 int	stay_foreground;
 int	lsbsysinit_mode;
 int	log_level;
+int	fqdn_in_subject;
 
 char	cron_default_mail_charset[MAX_ENVSTR] = "";
 
@@ -325,6 +326,7 @@ extern	char	*copyright[],
 		*ProgramName;
 extern	int	lsbsysinit_mode;
 extern	int	log_level;
+extern	int	fqdn_in_subject;
 extern	int	LineNumber;
 extern	time_t	StartTime;
 extern  time_min timeRunning;
diff --git a/do_command.c b/do_command.c
index e024995..a469347 100644
--- a/do_command.c
+++ b/do_command.c
@@ -537,7 +537,8 @@ child_process(e, u)
 	fprintf(mail, "From: root (Cron Daemon)\n");
 	fprintf(mail, "To: %s\n", mailto);
 	fprintf(mail, "Subject: Cron <%s@%s> %s%s\n",
-			usernm, first_word(hostname, "."),
+			usernm,
+			fqdn_in_subject ? hostname : first_word(hostname, "."),
 			e->cmd, status?" (failed)":"");
 # if defined(MAIL_DATE)
 	fprintf(mail, "Date: %s\n",
