From nobody@FreeBSD.org  Thu Nov  5 10:18:46 2009
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id CC97F106566C
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  5 Nov 2009 10:18:46 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from www.freebsd.org (www.freebsd.org [IPv6:2001:4f8:fff6::21])
	by mx1.freebsd.org (Postfix) with ESMTP id A210D8FC1F
	for <freebsd-gnats-submit@FreeBSD.org>; Thu,  5 Nov 2009 10:18:46 +0000 (UTC)
Received: from www.freebsd.org (localhost [127.0.0.1])
	by www.freebsd.org (8.14.3/8.14.3) with ESMTP id nA5AIjDj045260
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 5 Nov 2009 10:18:45 GMT
	(envelope-from nobody@www.freebsd.org)
Received: (from nobody@localhost)
	by www.freebsd.org (8.14.3/8.14.3/Submit) id nA5AIjIo045257;
	Thu, 5 Nov 2009 10:18:45 GMT
	(envelope-from nobody)
Message-Id: <200911051018.nA5AIjIo045257@www.freebsd.org>
Date: Thu, 5 Nov 2009 10:18:45 GMT
From: Dennis Yusupoff <dyr@smartspb.net>
To: freebsd-gnats-submit@FreeBSD.org
Subject: Patch for adding MAILFROM ability to cron
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         140304
>Category:       bin
>Synopsis:       [patch] add MAILFROM ability to cron(8)
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Thu Nov 05 10:20:05 UTC 2009
>Closed-Date:    
>Last-Modified:  Fri Nov 18 10:00:21 UTC 2011
>Originator:     Dennis Yusupoff
>Release:        7.2-release
>Organization:
Smart-Telecom ISP
>Environment:
FreeBSD Gingema.smartspb.net 7.2-PRERELEASE FreeBSD 7.2-PRERELEASE #1: Mon Oct  5 14:03:54 MSD 2009     root@Gingema.smartspb.net:/usr/obj/usr/src/sys/ROUTER_HOME_NETS  i386

>Description:
After some looking for ability to change sender mail address of cron
daemon I decided to add this feature right in the cron daemon as it
already done with MAILTO since I found nowhere in mailing list reasons
to not do it. :)

I think that it could be useful for many people.  I'm a newbie in C so
any corrections are welcome.
>How-To-Repeat:
Make a patch also :)
>Fix:
Use environment "MAILFOM" in your file crontab for change sender e-mail
or will be used default (username@hostname).

Patch attached with submission follows:

--- do_command.c.orig	2008-08-01 12:13:01.000000000 +0400
+++ do_command.c	2009-11-05 12:57:56.000000000 +0300
@@ -83,7 +83,7 @@
 {
 	int		stdin_pipe[2], stdout_pipe[2];
 	register char	*input_data;
-	char		*usernm, *mailto;
+	char		*usernm, *mailto, *mailfrom;
 	int		children = 0;
 # if defined(LOGIN_CAP)
 	struct passwd	*pwd;
@@ -101,6 +101,7 @@
 	 */
 	usernm = env_get("LOGNAME", e->envp);
 	mailto = env_get("MAILTO", e->envp);
+	mailfrom = env_get("MAILFROM", e->envp);
 
 #ifdef PAM
 	/* use PAM to see if the user's account is available,
@@ -468,6 +469,17 @@
 				else
 					mailto = usernm;
 			}
+			/* get name of sender.  this is MAILFROM if set to a
+			 * valid local username; USER otherwise.
+			 */
+			if (mailfrom == NULL) 
+				/* MAILFROM not present, set to USER
+				 */
+				mailfrom = usernm;
+
+			if (mailfrom && *mailfrom == '\0')
+				mailfrom = NULL;
+
 			if (mailto && *mailto == '\0')
 				mailto = NULL;
 
@@ -488,7 +500,7 @@
 					warn("%s", MAILCMD);
 					(void) _exit(ERROR_EXIT);
 				}
-				fprintf(mail, "From: %s (Cron Daemon)\n", usernm);
+				fprintf(mail, "From: %s (Cron Daemon)\n", mailfrom);
 				fprintf(mail, "To: %s\n", mailto);
 				fprintf(mail, "Subject: Cron <%s@%s> %s\n",
 					usernm, first_word(hostname, "."),


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-www->freebsd-bugs 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Thu Nov 5 14:27:19 UTC 2009 
Responsible-Changed-Why:  
reassign to more appropriate category. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=140304 

From: Dennis Yusupoff <dyr@smartspb.net>
To: bug-followup@FreeBSD.org, dyr@smartspb.net
Cc:  
Subject: Re: bin/140304: [patch] add MAILFROM ability to cron(8)
Date: Fri, 18 Nov 2011 13:59:05 +0400

 This is an OpenPGP/MIME signed message (RFC 2440 and 3156)
 --------------enigEA9C76043970F3E2E1F533F8
 Content-Type: text/plain; charset=UTF-8
 Content-Transfer-Encoding: quoted-printable
 
 Excuse me, but are there any news?! Any problems with commit this change?=
 
 
 --=20
 With best regards,
 Dennis Yusupoff,
 network engineer of
 Smart-Telecom ISP
 Russia, Saint-Petersburg=20
 
 
 
 --------------enigEA9C76043970F3E2E1F533F8
 Content-Type: application/pgp-signature; name="signature.asc"
 Content-Description: OpenPGP digital signature
 Content-Disposition: attachment; filename="signature.asc"
 
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1.4.10 (MingW32)
 Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/
 
 iQEcBAEBAgAGBQJOxixpAAoJEBUTaqBS2NB4zuwH/33Oa9hopFV451VrzpS4Xh23
 4WNdemr2qcbou9HqcOw2dTzTWFLTWnhwI2ux5mbORC04H9k6pT8x72IzhqpwPG+C
 hrxkVrMOlNS98gQRvlcbe3dwfEeP+ZLf48NMAZEk/AqQGPsZKBaG39GNqfSzVJG4
 lP/ZEGm+VInHmz9W8rrNxXFZUir5GfPNtjw7gX5KpSOUqZeY3gg9K7wDHRRsO3Eb
 wwCBrgC/4nY+++LoxU+s2A7roCYj462X6Q3OL8TCxRRSgWF74bRUatvohmtL+D4L
 JPf2yUI7onWtOY3Yw+5NVTuav14Hb1cFNtUoTLtkjkP4caidCjDWQZDOlfM1jhc=
 =xqBS
 -----END PGP SIGNATURE-----
 
 --------------enigEA9C76043970F3E2E1F533F8--
>Unformatted:
