Package: mpack / 1.6-8

01-legacy.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
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
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
--- mpack-1.6.orig/unixunpk.man
+++ mpack-1.6/unixunpk.man
@@ -50,7 +50,7 @@
 appends ".1", ".2", etc to find a nonexistent file.
 .TP
 .B \-q
-Be quiet.  Supresses messages about saving partial messages and about
+Be quiet.  Suppresses messages about saving partial messages and about
 messages with no interesting information.
 .TP
 .B \-t
@@ -107,7 +107,7 @@
 .SH ENVIRONMENT
 .TP
 .B TMPDIR
-Directory to store temporary files.  Default is /usr/tmp.
+Directory to store temporary files.  Default is /var/tmp.
 .SH FILES
 .TP
 .B $TMPDIR/m-prts-$USER/
--- mpack-1.6.orig/part.c
+++ mpack-1.6/part.c
@@ -27,6 +27,7 @@
  */
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 
 #include "part.h"
@@ -58,7 +59,7 @@
 /*
  * Close and free 'part'.
  */
-int part_close(struct part *part)
+void part_close(struct part *part)
 {
     fclose(part->infile);
     if (part->buf) free(part->buf);
@@ -77,8 +78,7 @@
 /*
  * Add to 'part' the multipart boundary 'boundary'.
  */
-int
-part_addboundary(struct part *part, char *boundary)
+void part_addboundary(struct part *part, char *boundary)
 {
     /* Grow boundary array if necessary */
     if (part->boundary_num == part->boundary_alloc) {
@@ -165,8 +165,7 @@
  * Leaves room in the input buffer to push back an additional single
  * character using the prot_ungetc() macro.
  */
-int
-part_ungets(char *s, struct part *part)
+void part_ungets(char *s, struct part *part)
 {
     int len = strlen(s);
     int i;
--- mpack-1.6.orig/decode.c
+++ mpack-1.6/decode.c
@@ -26,8 +26,10 @@
  * SOFTWARE.  */
 
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
+#include <unistd.h>
 #include "xmalloc.h"
 #include "common.h"
 #include "part.h"
@@ -37,6 +39,19 @@
 extern FILE *os_newtypedfile(char *fname, char *contentType, int flags, params contentParams);
 extern FILE *os_createnewfile(char *fname);
 extern char *md5contextTo64(MD5_CTX *context);
+extern void warn(char *s);
+extern void os_perror(char *str);
+extern void chat(char *s);
+extern void os_donewithdir(char *dir);
+extern void os_warnMD5mismatch(void);
+extern void os_closetypedfile(FILE *outfile);
+
+extern int part_depth(struct part *part);
+extern void part_ungets(char *s, struct part *part);
+extern void part_close(struct part *part);
+extern int part_fill(struct part *part);
+extern void part_addboundary(struct part *part, char *boundary);
+extern int part_readboundary(struct part *part);
 
 /* The possible content transfer encodings */
 enum encoding { enc_none, enc_qp, enc_base64 };
@@ -49,6 +64,17 @@
 void from64(struct part *inpart, FILE *outfile, char **digestp, int suppressCR);
 void fromqp(struct part *inpart, FILE *outfile, char **digestp);
 void fromnone(struct part *inpart, FILE *outfile, char **digestp);
+int handlePartial(struct part *inpart, char *headers, params contentParams,
+		  int extractText);
+int ignoreMessage(struct part *inpart);
+int handleMultipart(struct part *inpart, char *contentType,
+		    params contentParams, int extractText);
+int handleUuencode(struct part *inpart, char *subject, int extractText);
+int handleText(struct part *inpart, enum encoding contentEncoding);
+int saveToFile(struct part *inpart, int inAppleDouble, char *contentType,
+	       params contentParams, enum encoding contentEncoding,
+	       char *contentDisposition, char *contentMD5);
+
 /*
  * Read and handle an RFC 822 message from the body-part 'inpart'.
  */
@@ -545,8 +571,8 @@
 	SkipWhitespace(&disposition);
 	if (!disposition) return 0;
 
-	/* If we're looking at a ";", we found what we're looking for */
-	if (*disposition++ == ';') break;
+	/* If we're looking at a "=", we found what we're looking for */
+	if (*disposition++ == '=') break;
     }
 
     SkipWhitespace(&disposition);
@@ -624,7 +650,7 @@
     }
     thispart = atoi(p);
 
-    if (p = getParam(contentParams, "total")) {
+    if ((p = getParam(contentParams, "total"))) {
 	nparts = atoi(p);
 	if (nparts <= 0) {
 	    warn("partial message has invalid number of parts");
@@ -643,7 +669,7 @@
     else {
 	/* Try to retrieve number of parts from reassembly directory */
 	sprintf(buf, "%sCT", dir);
-	if (partfile = fopen(buf, "r")) {
+	if ((partfile = fopen(buf, "r"))) {
 	    if (fgets(buf, sizeof(buf), partfile)) {
 		nparts = atoi(buf);
 		if (nparts < 0) nparts = 0;
--- mpack-1.6.orig/unixpk.man
+++ mpack-1.6/unixpk.man
@@ -4,6 +4,9 @@
 .SH SYNOPSIS
 .B mpack
 [
+.B \-a
+]
+[
 .B \-s
 .I subject
 ]
@@ -24,6 +27,9 @@
 .br
 .B mpack
 [
+.B \-a
+]
+[
 .B \-s
 .I subject
 ]
@@ -45,6 +51,9 @@
 .br
 .B mpack
 [
+.B \-a
+]
+[
 .B \-s
 .I subject
 ]
@@ -74,6 +83,10 @@
 .PP
 .SH OPTIONS
 .TP
+.BI \-a
+Set the Content-Disposition to attachment.  If \-a is not used
+the Content-Disposition is inline.
+.TP
 .BI \-s " subject"
 Set the 
 .B Subject
@@ -136,7 +149,7 @@
 .SH ENVIRONMENT
 .TP
 .B TMPDIR
-Directory to store temporary files.  Default is /usr/tmp.
+Directory to store temporary files.  Default is /var/tmp.
 .TP
 .B SPLITSIZE
 Default value of the -m switch.
--- mpack-1.6.orig/xmalloc.c
+++ mpack-1.6/xmalloc.c
@@ -23,14 +23,14 @@
  * SOFTWARE.
  */
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
-extern char *malloc(), *realloc();
 
 char *xmalloc (int size)
 {
     char *ret;
 
-    if (ret = malloc((unsigned) size))
+    if ((ret = malloc((unsigned) size)))
       return ret;
 
     fprintf(stderr, "Memory exhausted\n");
@@ -43,7 +43,7 @@
     char *ret;
 
     /* xrealloc (NULL, size) behaves like xmalloc (size), as in ANSI C */
-    if (ret = !ptr ? malloc ((unsigned) size) : realloc (ptr, (unsigned) size))
+    if ((ret = !ptr ? malloc ((unsigned) size) : realloc (ptr, (unsigned) size)))
       return ret;
 
     fprintf(stderr, "Memory exhausted\n");
--- mpack-1.6.orig/codes.c
+++ mpack-1.6/codes.c
@@ -128,7 +128,7 @@
     int nbytes;
     
     MD5Init(&context);
-    while (nbytes = fread(buf, 1, sizeof(buf), infile)) {
+    while ((nbytes = fread(buf, 1, sizeof(buf), infile))) {
 	length += nbytes;
 	MD5Update(&context, buf, nbytes);
     }
--- mpack-1.6.orig/unixos.c
+++ mpack-1.6/unixos.c
@@ -23,24 +23,30 @@
  * SOFTWARE.
  */
 #include <stdio.h>
+#include <stdlib.h>
 #include <ctype.h>
 #include <string.h>
 #include <errno.h>
 #include <sys/types.h>
+#include <sys/stat.h>
 #include <sys/param.h>
+#include <time.h>
 #include <netdb.h>
 #include <fcntl.h>
+#include <unistd.h>
 #include "xmalloc.h"
 #include "common.h"
 #include "part.h"
 
+extern void warn(char *s);
+
 #ifndef MAXHOSTNAMELEN
 #define MAXHOSTNAMELEN 64
 #endif
 
+#ifndef errno
 extern int errno;
-extern char *malloc();
-extern char *getenv();
+#endif
 
 int overwrite_files = 0;
 int didchat;
@@ -76,7 +82,7 @@
     }
 
     result = malloc(25+strlen(hostname));
-    sprintf(result, "%d.%d@%s", pid, curtime++, hostname);
+    sprintf(result, "%d.%lu@%s", pid, (unsigned long) curtime++, hostname);
     return result;
 }
 
@@ -90,7 +96,7 @@
 	strcpy(buf, getenv("TMPDIR"));
     }
     else {
-	strcpy(buf, "/usr/tmp");
+	strcpy(buf, "/var/tmp");
     }
     strcat(buf, "/m-prts-");
     p = getenv("USER");
@@ -137,7 +143,14 @@
     FILE *ret;
      
 #ifdef O_EXCL
-    fd=open(fname, O_RDWR|O_CREAT|O_EXCL, 0644);
+    struct stat statbuf;
+
+    if ((stat(fname, &statbuf) == 0) && (S_ISCHR(statbuf.st_mode))) {
+	fd=open(fname, O_RDWR);
+    }
+    else {
+	fd=open(fname, O_RDWR|O_CREAT|O_EXCL, 0644);
+    }
 #else
     fd=open(fname, O_RDWR|O_CREAT|O_TRUNC, 0644);
 #endif
@@ -194,7 +207,7 @@
 	do {
 	    if (outfile) fclose(outfile);
 	    sprintf(buf, "part%d", ++filesuffix);
-	} while (outfile = fopen(buf, "r"));
+	} while ((outfile = fopen(buf, "r")));
 	fname = buf;
     }
     else if (!overwrite_files && (outfile = fopen(fname, "r"))) {
@@ -202,7 +215,7 @@
 	    fclose(outfile);
 	    sprintf(buf, "%s.%d", fname, ++filesuffix);
 	 
-	} while (outfile = fopen(buf, "r"));
+	} while ((outfile = fopen(buf, "r")));
 	fname = buf;
     }
 
@@ -228,7 +241,7 @@
 
     p = strchr(descfname, '/');
     if (!p) p = descfname;
-    if (p = strrchr(p, '.')) *p = '\0';
+    if ((p = strrchr(p, '.'))) *p = '\0';
 
     strcat(descfname, ".desc");
     (void) rename(TEMPFILENAME, descfname);
--- mpack-1.6.orig/unixunpk.c
+++ mpack-1.6/unixunpk.c
@@ -23,17 +23,19 @@
  * SOFTWARE.
  */
 #include <stdio.h>
+#include <stdlib.h>
+#include <getopt.h>
+#include <unistd.h>
 #include "version.h"
 #include "part.h"
 
-extern int optind;
-extern char *optarg;
-
 extern int overwrite_files;
 extern int didchat;
 int quiet;
 
 void usage(void);
+int handleMessage(struct part *inpart, char *defaultContentType,
+		  int inAppleDouble, int extractText);
 
 int main(int argc, char **argv)
 {
@@ -100,7 +102,7 @@
 
 void usage(void) {
     fprintf(stderr, "munpack version %s\n", MPACK_VERSION);
-    fprintf(stderr, "usage: munpack [-f] [-q] [-C directory] [files...]\n");
+    fprintf(stderr, "usage: munpack [-f] [-q] [-t] [-C directory] [files...]\n");
     exit(1);
 }
 
--- mpack-1.6.orig/magic.c
+++ mpack-1.6/magic.c
@@ -23,6 +23,7 @@
  * SOFTWARE.
  */
 #include <stdio.h>
+#include <string.h>
 
 /* Description of the various file formats and their magic numbers */
 struct magic {
--- mpack-1.6.orig/uudecode.c
+++ mpack-1.6/uudecode.c
@@ -23,8 +23,10 @@
  * SOFTWARE.
  */
 #include <stdio.h>
+#include <stdlib.h>
 #include <ctype.h>
 #include <string.h>
+#include <unistd.h>
 #include "xmalloc.h"
 #include "common.h"
 #include "part.h"
@@ -32,9 +34,25 @@
 extern char *os_idtodir(char *id);
 extern FILE *os_newtypedfile(char *fname, char *contentType, int flags, params contentParams);
 extern FILE *os_createnewfile(char *fname);
+extern int os_binhex(struct part *inpart, int part, int nparts);
+extern void os_closetypedfile(FILE *outfile);
+extern void os_donewithdir(char *dir);
+extern void os_perror(char *str);
+extern void chat(char *s);
+
+extern void part_ungets(char *s, struct part *part);
+extern void part_close(struct part *part);
+extern int handleMessage(struct part *inpart, char *defaultContentType,
+			 int inAppleDouble, int extractText);
 
 static FILE *startDescFile(char *fname);
+static void uudecodeline(char *line, FILE *outfile);
 
+int parseSubject(char *subject, char **fnamep, int *partp, int *npartsp);
+int saveUuFile(struct part *inpart, char *fname, int part, int nparts,
+	       char *firstline);
+int descEnd(char *line);
+int uudecodefiles(char *dir, int nparts);
 
 /* Length of a normal uuencoded line, including newline */
 #define UULENGTH 62
@@ -266,7 +284,7 @@
 	}
 	else if (part == 1 && fname && !descfile &&
 		 !strncasecmp(buf, "x-file-desc: ", 13)) {
-	    if (descfile = startDescFile(fname)) {
+	    if ((descfile = startDescFile(fname))) {
 		fputs(buf+13, descfile);
 		fclose(descfile);
 		descfile = 0;
@@ -454,7 +472,7 @@
     /* Retrieve any previously saved number of the last part */
     if (nparts == 0) {
 	sprintf(buf, "%sCT", dir);
-	if (partfile = fopen(buf, "r")) {
+	if ((partfile = fopen(buf, "r"))) {
 	    if (fgets(buf, sizeof(buf), partfile)) {
 		nparts = atoi(buf);
 		if (nparts < 0) nparts = 0;
@@ -722,7 +740,7 @@
 		if (!*fname) return 1;
 
 		/* Guess the content-type of common filename extensions */
-		if (p = strrchr(fname, '.')) {
+		if ((p = strrchr(fname, '.'))) {
 		    if (!strcasecmp(p, ".gif")) contentType = "image/gif";
 		    if (!strcasecmp(p, ".jpg")) contentType = "image/jpeg";
 		    if (!strcasecmp(p, ".jpeg")) contentType = "image/jpeg";
@@ -826,7 +844,7 @@
 /*
  * Decode a uuencoded line to 'outfile'
  */
-int uudecodeline(char *line, FILE *outfile)
+static void uudecodeline(char *line, FILE *outfile)
 {
     int c, len;
 
@@ -845,7 +863,6 @@
 	}
 	line += 4;
     }
-    return;
 }
 
     
--- mpack-1.6.orig/md5.h
+++ mpack-1.6/md5.h
@@ -34,14 +34,16 @@
 #define PROTOTYPES 0
 #endif
 
+#include <stdint.h>
+
 /* POINTER defines a generic pointer type */
 typedef unsigned char *POINTER;
 
 /* UINT2 defines a two byte word */
-typedef unsigned short int UINT2;
+typedef uint16_t UINT2;
 
 /* UINT4 defines a four byte word */
-typedef unsigned long int UINT4;
+typedef uint32_t UINT4;
 
 /* PROTO_LIST is defined depending on how PROTOTYPES is defined above.
 If using PROTOTYPES, then PROTO_LIST returns the list, otherwise it
--- mpack-1.6.orig/mkreadme.pl
+++ mpack-1.6/mkreadme.pl
@@ -413,7 +413,7 @@
 =unix
      TMPDIR
           Root of directory to store partial messages awaiting 
-          reassembly.  Default is "/usr/tmp".   Partial messages
+          reassembly.  Default is "/var/tmp".   Partial messages
 	  are stored in subdirectories of $TMPDIR/m-prts-$USER/
 
 =pc os2
--- mpack-1.6.orig/README.unix
+++ mpack-1.6/README.unix
@@ -188,7 +188,7 @@
 
      TMPDIR
           Root of directory to store partial messages awaiting 
-          reassembly.  Default is "/usr/tmp".   Partial messages
+          reassembly.  Default is "/var/tmp".   Partial messages
 	  are stored in subdirectories of $TMPDIR/m-prts-$USER/
 
 
--- mpack-1.6.orig/unixpk.c
+++ mpack-1.6/unixpk.c
@@ -23,23 +23,28 @@
  * SOFTWARE.
  */
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 #include <errno.h>
+#include <getopt.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <unistd.h>
 #include "common.h"
 #include "version.h"
 #include "xmalloc.h"
 
 #define MAXADDRESS 100
 
-extern char *getenv();
-
-extern int errno;
-extern int optind;
-extern char *optarg;
+extern int attachment;
 
 void usage(void);
 void sendmail(FILE *infile, char **addr, int start);
 void inews(FILE *infile);
+void os_perror(char *str);
+int encode(FILE *infile, FILE *applefile, char *fname, FILE *descfile,
+	   char *subject, char *headers, long int maxsize,
+	   char *typeoverride, char *outfname);
 
 int main(int argc, char **argv)
 {
@@ -64,7 +69,7 @@
 	maxsize = atoi(p);
     }
 
-    while ((opt = getopt(argc, argv, "s:d:m:c:o:n:")) != EOF) {
+    while ((opt = getopt(argc, argv, "as:d:m:c:o:n:")) != EOF) {
 	switch (opt) {
 	case 's':
 	    subject = optarg;
@@ -90,6 +95,10 @@
 	    newsgroups = optarg;
 	    break;
 
+	case 'a':
+	    attachment = 1;
+	    break;
+
 	default:
 	    usage();
 
@@ -155,7 +164,7 @@
 	    fprintf(stderr, "A subject is required\n");
 	    usage();
 	}
-	if (p = strchr(sbuf, '\n')) *p = '\0';
+	if ((p = strchr(sbuf, '\n'))) *p = '\0';
 	subject = sbuf;
     }	
 
@@ -164,7 +173,7 @@
 	    strcpy(fnamebuf, getenv("TMPDIR"));
 	}
 	else {
-	    strcpy(fnamebuf, "/usr/tmp");
+	    strcpy(fnamebuf, "/var/tmp");
 	}
 	strcat(fnamebuf, "/mpackXXXXXX");
 	mktemp(fnamebuf);
--- mpack-1.6.orig/encode.c
+++ mpack-1.6/encode.c
@@ -23,14 +23,18 @@
  * SOFTWARE.
  */
 #include <stdio.h>
+#include <stdlib.h>
 #include <string.h>
 
 extern char *magic_look(FILE *infile);
 extern char *os_genid(void);
 extern FILE *os_createnewfile(char *fname);
 extern char *md5digest(FILE *infile, long int *len);
+extern void os_perror(char *str);
+extern int to64(FILE *infile, FILE *outfile, long int limit);
 
 #define NUMREFERENCES 4
+int attachment;
 
 /*
  * Encode a file into one or more MIME messages, each
@@ -43,7 +47,7 @@
     char *type;
     FILE *outfile;
     char *cleanfname, *p;
-    char *digest, *appledigest;
+    char *digest, *appledigest = NULL;
     long filesize, l, written;
     int thispart, numparts = 1;
     int wrotefiletype = 0;
@@ -57,12 +61,12 @@
     /* This filename-cleaning knowledge will probably
      * be moved to the os layer in a future version.
      */
-    if (p = strrchr(cleanfname, '.')) cleanfname = p+1;
+    if ((p = strrchr(cleanfname, '.'))) cleanfname = p+1;
 #else
-    if (p = strrchr(cleanfname, '/')) cleanfname = p+1;
-    if (p = strrchr(cleanfname, '\\')) cleanfname = p+1;
+    if ((p = strrchr(cleanfname, '/'))) cleanfname = p+1;
+    if ((p = strrchr(cleanfname, '\\'))) cleanfname = p+1;
 #endif
-    if (p = strrchr(cleanfname, ':')) cleanfname = p+1;
+    if ((p = strrchr(cleanfname, ':'))) cleanfname = p+1;
 
     /* Find file type */
     if (typeoverride) {
@@ -189,8 +193,8 @@
 	"Content-Type: multipart/appledouble; boundary=\"=\"; name=\"%s\"\n",
 			cleanfname);
 		fprintf(outfile,
-			"Content-Disposition: inline; filename=\"%s\"\n",
-			cleanfname);
+			"Content-Disposition: %s; filename=\"%s\"\n",
+		        attachment ? "attachment" : "inline", cleanfname);
 		fprintf(outfile, "\n\n--=\n");
 		fprintf(outfile, "Content-Type: application/applefile\n");
 		fprintf(outfile, "Content-Transfer-Encoding: base64\n");
@@ -219,8 +223,8 @@
 	    fprintf(outfile, "Content-Type: %s; name=\"%s\"\n", type,
 		    cleanfname);
 	    fprintf(outfile, "Content-Transfer-Encoding: base64\n");
-	    fprintf(outfile, "Content-Disposition: inline; filename=\"%s\"\n",
-		    cleanfname);
+	    fprintf(outfile, "Content-Disposition: %s; filename=\"%s\"\n",
+		    attachment ? "attachment" : "inline", cleanfname);
 	    fprintf(outfile, "Content-MD5: %s\n\n", digest);
 	    free(digest);
 	    written += 80;