Package: bsd-mailx / 8.1.2-0.20141216cvs-2

04-Add-custom-header.patch Patch series | download
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
From: Martin Schulze <joey@kuolema.Infodrom.North.DE>
Date: Tue, 9 Jun 1998 22:42:19 +0200
Subject: 04 Add custom header.

Provide a possibility to add custom header fields such as
"X-Loop: This service" or "X-Generated: via cron"
(Closes: Bug#23356, Bug#13756).
---
 def.h    |  1 +
 extern.h |  2 +-
 mail.1   |  8 +++++++-
 main.c   | 24 +++++++++++++++++++++---
 send.c   |  6 +++++-
 5 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/def.h b/def.h
index af2ecce..1905d00 100644
--- a/def.h
+++ b/def.h
@@ -179,6 +179,7 @@ struct headline {
 struct header {
 	struct name *h_to;		/* Dynamic "To:" string */
 	char *h_subject;		/* Subject string */
+	char *h_header;			/* Additional header string */
 	struct name *h_cc;		/* Carbon copies string */
 	struct name *h_bcc;		/* Blind carbon copies */
 	struct name *h_smopts;		/* Sendmail options */
diff --git a/extern.h b/extern.h
index 714f48c..febe362 100644
--- a/extern.h
+++ b/extern.h
@@ -164,7 +164,7 @@ void	 load(char *);
 struct var *
 	 lookup(char *);
 int	 mail (struct name *, struct name *, struct name *, struct name *,
-	       char *);
+	       char *, char *);
 void	 mail1(struct header *, int);
 void	 makemessage(FILE *, int);
 void	 mark(int);
diff --git a/mail.1 b/mail.1
index ebb7f90..be1653e 100644
--- a/mail.1
+++ b/mail.1
@@ -41,6 +41,7 @@
 .Nm mail
 .Bk -words
 .Op Fl dEIinv
+.Op Fl a Ar header
 .Op Fl b Ar bcc-addr
 .Op Fl c Ar cc-addr
 .Op Fl s Ar subject
@@ -62,6 +63,11 @@ with lines replaced by messages.
 .Pp
 The options are as follows:
 .Bl -tag -width Ds
+.It Fl a
+Specify additional header fields on the command line such as "X-Loop:
+foo@bar" etc.  You have to use quotes if the string contains spaces.
+This argument may be specified more than once, the headers will then
+be concatenated.
 .It Fl b Ar bcc-addr
 Send blind carbon copies to
 .Ar bcc-addr .
@@ -1239,7 +1245,7 @@ and are not supported by this implementation of
 .Nm mailx .
 .Pp
 The flags
-.Op Fl bcdEIv
+.Op Fl abcdEIv
 are extensions to the specification.
 .Sh HISTORY
 A
diff --git a/main.c b/main.c
index cdfa7c5..c0553b0 100644
--- a/main.c
+++ b/main.c
@@ -50,6 +50,7 @@ main(int argc, char **argv)
 	int i;
 	struct name *to, *cc, *bcc, *smopts;
 	char *subject;
+	char *header = NULL;
 	char *ef;
 	char nosrc = 0;
 	char *rc;
@@ -89,7 +90,7 @@ main(int argc, char **argv)
 	bcc = NULL;
 	smopts = NULL;
 	subject = NULL;
-	while ((i = getopt(argc, argv, "EIN:b:c:dfins:u:v")) != -1) {
+	while ((i = getopt(argc, argv, "EIN:a:b:c:defins:u:v")) != -1) {
 		switch (i) {
 		case 'u':
 			/*
@@ -120,6 +121,22 @@ main(int argc, char **argv)
 			 */
 			subject = optarg;
 			break;
+
+		case 'a':
+			/*
+			 * Give additional header fields for sending from
+			 * non terminal
+			 */
+			if (header == NULL) {
+				if ((header = (char *)malloc(strlen(optarg)+1)) != NULL)
+					strcpy(header, optarg);
+                        } else {
+				if ((header = (char *)realloc(header, strlen(optarg)+strlen(header)+2)) != NULL) {
+					strcat(header, "\n");
+					strcat(header, optarg);
+				}
+			}
+			break;
 		case 'f':
 			/*
 			 * User is specifying file to "edit" with Mail,
@@ -165,6 +182,7 @@ main(int argc, char **argv)
 			 */
 			bcc = cat(bcc, nalloc(optarg, GBCC));
 			break;
+		case 'e':
 		case 'E':
 			/*
 			 * Don't send messages with an empty body.
@@ -216,7 +234,7 @@ main(int argc, char **argv)
 		rc = "~/.mailrc";
 	load(expand(rc));
 	if (!rcvmode) {
-		mail(to, cc, bcc, smopts, subject);
+		mail(to, cc, bcc, smopts, subject, header);
 		/*
 		 * why wait?
 		 */
@@ -284,7 +302,7 @@ static void
 usage(void)
 {
 
-	fprintf(stderr, "usage: %s [-dEIinv] [-b bcc-addr] [-c cc-addr] "
+	fprintf(stderr, "usage: %s [-dEIinv] [-a header] [-b bcc-addr] [-c cc-addr] "
 	    "[-s subject] to-addr ...\n", __progname);
 	fprintf(stderr, "       %s [-dEIiNnv] -f [name]\n", __progname);
 	fprintf(stderr, "       %s [-dEIiNnv] [-u user]\n", __progname);
diff --git a/send.c b/send.c
index e8084fd..e79d9dc 100644
--- a/send.c
+++ b/send.c
@@ -280,12 +280,13 @@ statusput(struct message *mp, FILE *obuf, char *prefix)
  */
 int
 mail(struct name *to, struct name *cc, struct name *bcc, struct name *smopts,
-     char *subject)
+     char *subject, char *header)
 {
 	struct header head;
 
 	head.h_to = to;
 	head.h_subject = subject;
+	head.h_header = header;
 	head.h_cc = cc;
 	head.h_bcc = bcc;
 	head.h_smopts = smopts;
@@ -306,6 +307,7 @@ sendmail(void *v)
 
 	head.h_to = extract(str, GTO);
 	head.h_subject = NULL;
+	head.h_header = NULL;
 	head.h_cc = NULL;
 	head.h_bcc = NULL;
 	head.h_smopts = NULL;
@@ -510,6 +512,8 @@ puthead(struct header *hp, FILE *fo, int w)
 	if (hp->h_bcc != NULL && w & GBCC)
 		fmt("Bcc:", hp->h_bcc, fo, w&GCOMMA), gotcha++;
 */
+	if (hp->h_header != NULL && w)
+		fprintf(fo, "%s\n", hp->h_header), gotcha++;
 	if (gotcha && w & GNL)
 		(void)putc('\n', fo);
 	return(0);