summaryrefslogtreecommitdiffstats
path: root/main/busybox/0001-sendmail-automatically-determine-sender-if-not-speci.patch
blob: 8b6df8ad96b78ba00259fc1ace05bce952b5e483 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
From a2a978538c82999dc7d4018827e0f96188a135de Mon Sep 17 00:00:00 2001
From: Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi>
Date: Wed, 22 Jan 2014 00:41:49 +0200
Subject: [PATCH] sendmail: automatically determine sender if not specified

Make the -f option optional. If not given, construct the sender
address from the username and fully qualified hostname.

This is required to interoperate with the cron applet.
---
 mailutils/sendmail.c | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/mailutils/sendmail.c b/mailutils/sendmail.c
index b5aa1d1..b99c42f 100644
--- a/mailutils/sendmail.c
+++ b/mailutils/sendmail.c
@@ -199,8 +199,8 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv)
 	G.fp0 = xfdopen_for_read(3);
 
 	// parse options
-	// -v is a counter, -f is required. -H and -S are mutually exclusive, -a is a list
-	opt_complementary = "vv:f:w+:H--S:S--H:a::";
+	// -v is a counter, -H and -S are mutually exclusive, -a is a list
+	opt_complementary = "vv:w+:H--S:S--H:a::";
 	// N.B. since -H and -S are mutually exclusive they do not interfere in opt_connect
 	// -a is for ssmtp (http://downloads.openwrt.org/people/nico/man/man8/ssmtp.8.html) compatibility,
 	// it is still under development.
@@ -279,7 +279,6 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv)
 	// we should start with modern EHLO
 	if (250 != smtp_checkp("EHLO %s", host, -1))
 		smtp_checkp("HELO %s", host, 250);
-	free(host);
 
 	// perform authentication
 	if (opts & OPT_a) {
@@ -305,12 +304,11 @@ int sendmail_main(int argc UNUSED_PARAM, char **argv)
 	//	file descriptor (e.g. 4), or again from a secured file.
 
 	// got no sender address? -> use system username as a resort
-	// N.B. we marked -f as required option!
-	//if (!G.user) {
-	//	// N.B. IMHO getenv("USER") can be way easily spoofed!
-	//	G.user = xuid2uname(getuid());
-	//	opt_from = xasprintf("%s@%s", G.user, domain);
-	//}
+	if (!G.user) G.user = xuid2uname(getuid());
+	if (!opt_from)
+		opt_from = xasprintf("%s@%s", G.user, xgethostbyname(host)->h_name);
+	free(host);
+
 	smtp_checkp("MAIL FROM:<%s>", opt_from, 250);
 
 	// process message
-- 
1.8.3.1