summaryrefslogtreecommitdiff
path: root/mail/metamail/patches/patch-ai
blob: 6b5b9c3b179a9449e796c15cbe63276f47dd80cb (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
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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
$NetBSD: patch-ai,v 1.4 2015/11/08 20:51:59 dholland Exp $

- clean up junk decls that exist in headers, and include the right headers
- use fgets instead of gets
- fix printf to always have format
- when executing a child metamail, propagate the parents options as much as
  possible
- use termios instead of termio/sgtty

--- metamail/metamail.c.orig	1994-02-17 01:57:19.000000000 +0000
+++ metamail/metamail.c
@@ -46,12 +46,8 @@ extern char *mktemp(char *);
 #include <signal.h>
 
 #ifndef AMIGA
-#ifdef SYSV
-#include <termio.h>
+#include <termios.h>
 #include <unistd.h>
-#else /* SYSV */
-#include <sgtty.h>
-#endif /* SYSV */
 #endif /* AMIGA */
 #endif /* MICROSOFT */
 #endif /* BORLAND */
@@ -83,7 +79,7 @@ extern char *MkRmScript();
 #define MAX_FILE_NAME_SIZE 256
 #define WRITE_BINARY	"w"
 #else /* AMIGA */
-extern char **environ, *gets();
+extern char **environ;
 #define CATCOMMAND  "cat"
 #define CATTEMPLATE "cat %s"
 #define METAMAIL    "metamail"
@@ -100,15 +96,14 @@ extern char **environ, *gets();
 #define CMDSIZE 1200 /* Maximum size of command to execute */
 
 #define LINE_BUF_SIZE       2000
-#ifndef MICROSOFT
-extern char *malloc();
-extern char *realloc();
-#endif
-extern char *getenv();
-extern char *index();
-extern char *rindex();
+#include <string.h>
+#include <stdlib.h>
+
 char fileToDelete[MAX_FILE_NAME_SIZE];
 
+void PauseForUser(void);
+void maybephead(char *);
+
 char *FindParam();
 extern FILE *popen();
 static char *nomem = "Out of memory!";
@@ -151,6 +146,32 @@ int MightAskBeforeExecuting = 1,
     JustWriteFiles = 0,
     ProcessingErrors = 0;
 
+static const char *
+makeoptions(void)
+{
+    static char buf[1024];
+    buf[0] = 0;
+    if (!MightAskBeforeExecuting)
+	strlcat(buf, " -d", sizeof(buf));
+    if (DefinitelyNotTty && MustNotBeTty)
+	strlcat(buf, " -x", sizeof(buf));
+    if (MaybePageOutput)
+	strlcat(buf, MustPageOutput ? " -P" : " -p", sizeof(buf));
+    if (EatLeadingNewlines)
+	strlcat(buf, " -e", sizeof(buf));
+    if (!PrintSomeHeaders && Quiet)
+	strlcat(buf, " -q", sizeof(buf));
+    if (DoInBackground)
+	strlcat(buf, " -B", sizeof(buf));
+    if (!Is822Format)
+	strlcat(buf, " -b", sizeof(buf));
+    if (PrintingMode)
+	strlcat(buf, " -h", sizeof(buf));
+    if (JustWriteFiles)
+	strlcat(buf, " -w", sizeof(buf));
+    return buf;
+}
+
 char *ContentType = NULL,
     *ContentEncoding = NULL,
     *MailerName = "unknown",
@@ -497,8 +518,9 @@ int nestingdepth;
         if (IsAlternative) {
             if (WroteSquirrelFile) {
                 int retcode; 
-                char Cmd[TMPFILE_NAME_SIZE + 15];
-                sprintf(Cmd, "%s %s", METAMAIL, NewSquirrelFile);
+                char Cmd[TMPFILE_NAME_SIZE + 15 + 1024];
+                snprintf(Cmd, sizeof(Cmd), "%s %s %s", METAMAIL, makeoptions(),
+		    NewSquirrelFile);
                 fflush(stdout); fflush(stderr);
                 retcode = system(Cmd);
 #ifdef MSDOS
@@ -579,7 +601,7 @@ int nestingdepth;
                                 int overwriteans = -1;
                                 do {
                                     printf("File %s exists.  Do you want to overwrite it (y/n) ?\n", Fname);
-                                    s = gets(AnsBuf);
+				    s = fgets(AnsBuf, sizeof(AnsBuf), stdin);
                                     if (!s) {
                                         overwriteans = 0;
                                     } else {
@@ -1202,9 +1224,9 @@ char *SquirrelFile;
     fprintf(outfp, "Content-type: %s", ContentType);
     for (j=0; j<CParamsUsed; ++j) {
         fprintf(outfp, " ; ");
-        fprintf(outfp, CParams[j]);
+        fprintf(outfp, "%s", CParams[j]);
         fprintf(outfp, " = ");
-        fprintf(outfp, CParamValues[j]);
+        fprintf(outfp, "%s", CParamValues[j]);
     }
     fprintf(outfp, "\n\n"); 
     TranslateInputToOutput(InputFP, outfp, EncodingCode, ContentType);
@@ -1823,7 +1845,7 @@ char *ctype, *progname, *label;
         } else {
             printf("This message contains '%s'-format data.\nDo you want to view it using the '%s' command (y/n) [y] ? ", ctype, ShortCommand(progname));
         }
-        s = gets(AnsBuf);
+	s = fgets(AnsBuf, sizeof(AnsBuf), stdin);
         if (!s) return(0); /* EOF */
 	while (s && *s && isspace((unsigned char) *s)) ++s;
 	if (*s == 'y' || *s == 'Y' || !*s || *s == '\n') return(1);
@@ -1900,7 +1922,7 @@ char *hdr;
 }
 
 /* check the header given to see if it matches any in the KeyHeadList */
-maybephead(hdr)
+void maybephead(hdr)
 char *hdr;
 {
     char *s;
@@ -2022,7 +2044,8 @@ int ShowLeadingWhitespace;
     if (lc2strcmp(charset, PrevCharset)) {
         char *s2, *charsetinuse;
 
-        strcpy(PrevCharset, charset);
+        strncpy(PrevCharset, charset, sizeof(PrevCharset));
+	PrevCharset[sizeof(PrevCharset) - 1] = '\0';
         for (s2=PrevCharset; *s2; ++s2) {
             if (isupper((unsigned char) *s2)) *s2 = tolower((unsigned char) *s2);
         }
@@ -2032,7 +2055,7 @@ int ShowLeadingWhitespace;
         }
     }
     if (ecode == ENCODING_NONE) {
-        printf(txt+1);
+        printf("%s", txt+1);
     } else {
         /* What follows is REALLY bogus, but all my encoding stuff is pipe-oriented right now... */
         MkTmpFileName(TmpFile);
@@ -2375,41 +2398,25 @@ char *Prefix;
 
 int HasSavedTtyState=0;
 #if !defined(AMIGA) && !defined(MSDOS)
-#ifdef SYSV
-static struct termio MyTtyStateIn, MyTtyStateOut;
-#else
-static struct sgttyb MyTtyStateIn, MyTtyStateOut;
-#endif
+static struct termios MyTtyStateIn, MyTtyStateOut;
 #endif
 
 SaveTtyState() {
     /* Bogus -- would like a good portable way to reset the terminal state here */
 #if !defined(AMIGA) && !defined(MSDOS)
-#ifdef SYSV
-    ioctl(fileno(stdin), TCGETA, &MyTtyStateIn);
-    ioctl(fileno(stdout), TCGETA, &MyTtyStateOut);
-#else
-    gtty(fileno(stdin), &MyTtyStateIn);
-    gtty(fileno(stdout), &MyTtyStateOut);
-#endif
+    tcgetattr(fileno(stdin), &MyTtyStateIn);
+    tcgetattr(fileno(stdout), &MyTtyStateOut);
     HasSavedTtyState = 1;
 #endif
 }
 
 RestoreTtyState() {
 #if !defined(AMIGA) && !defined(MSDOS)
-#ifdef SYSV
-    if (HasSavedTtyState) {
-        ioctl(fileno(stdout), TCSETA, &MyTtyStateOut);
-        ioctl(fileno(stdin), TCSETA, &MyTtyStateIn);
-    }
-#else
     if (HasSavedTtyState) {
-        stty(fileno(stdout), &MyTtyStateOut);
-        stty(fileno(stdin), &MyTtyStateIn);
+        tcsetattr(fileno(stdout), TCSANOW, &MyTtyStateOut);
+        tcsetattr(fileno(stdin), TCSANOW, &MyTtyStateIn);
     }
 #endif
-#endif
 }
 
 NeedToAskBeforeExecuting(type)
@@ -2655,12 +2662,12 @@ char *s2;
 #endif
 }
 
-PauseForUser() {
+void PauseForUser() {
 #if defined(MSDOS) || defined(AMIGA)
     char Buf[100];
 #endif
 
-    if (DefinitelyNotTty || MustNotBeTty) return;	
+    if (DefinitelyNotTty || MustNotBeTty) return;
 #if defined(MSDOS) || defined(AMIGA)
     printf("Press RETURN to go on\n");
     gets(Buf);
@@ -2681,21 +2688,14 @@ PauseForUser() {
 
 StartRawStdin() {
 #if !defined(AMIGA) && !defined(MSDOS)
-#ifdef SYSV
-    struct termio   orterm, fterm;
-    ioctl(0, TCGETA, &orterm);	/* get current (i.e. cooked) termio */
+    struct termios   orterm, fterm;
+    tcgetattr(0, &orterm);	/* get current (i.e. cooked) termio */
     fterm = orterm;		/* get termio to modify */
 
     fterm.c_lflag &= ~ICANON;	/* clear ICANON giving raw mode */
     fterm.c_cc[VMIN] = 1;	/* set MIN char count to 1 */
     fterm.c_cc[VTIME] = 0;	/* set NO time limit */
-    return ioctl(0, TCSETAW, &fterm);	/* modify termio for raw mode */
-#else
-    struct sgttyb ts;
-    gtty(fileno(stdin), &ts);
-    ts.sg_flags |= RAW;
-    return stty(fileno(stdin), &ts);
-#endif
+    return tcsetattr(0, TCSADRAIN, &fterm);	/* modify termio for raw mode */
 #else
     return(-1);
 #endif