ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/Convert-UUlib/uulib/uuencode.c
(Generate patch)

Comparing Convert-UUlib/uulib/uuencode.c (file contents):
Revision 1.1 by root, Mon Jun 11 19:48:58 2001 UTC vs.
Revision 1.2 by root, Mon Jun 11 20:42:37 2001 UTC

1/* 1/*
2 * This file is part of uudeview, the simple and friendly multi-part multi- 2 * This file is part of uudeview, the simple and friendly multi-part multi-
3 * file uudecoder program (c) 1994 by Frank Pilhofer. The author may be 3 * file uudecoder program (c) 1994-2001 by Frank Pilhofer. The author may
4 * contacted by his email address, fp@informatik.uni-frankfurt.de 4 * be contacted at fp@fpx.de
5 * 5 *
6 * This program is free software; you can redistribute it and/or modify 6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or 8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version. 9 * (at your option) any later version.
40#endif 40#endif
41#ifdef HAVE_ERRNO_H 41#ifdef HAVE_ERRNO_H
42#include <errno.h> 42#include <errno.h>
43#endif 43#endif
44 44
45#include <uulib.h> 45#include <uudeview.h>
46#include <uuint.h> 46#include <uuint.h>
47#include <fptools.h> 47#include <fptools.h>
48#include <uustring.h> 48#include <uustring.h>
49 49
50/* for braindead systems */ 50/* for braindead systems */
54#else 54#else
55#define SEEK_SET 0 55#define SEEK_SET 0
56#endif 56#endif
57#endif 57#endif
58 58
59char * uuencode_id = "$Id: uuencode.c,v 1.1 2001/06/11 19:48:58 root Exp $"; 59char * uuencode_id = "$Id: uuencode.c,v 1.2 2001/06/11 20:42:37 root Exp $";
60 60
61#if 0 61#if 0
62/* 62/*
63 * the End-Of-Line string. MIME enforces CRLF, so that's what we use. Some 63 * the End-Of-Line string. MIME enforces CRLF, so that's what we use. Some
64 * implementations of uudecode will complain about a missing end line, since 64 * implementations of uudecode will complain about a missing end line, since
112#define CTE_BINHEX "x-binhex" 112#define CTE_BINHEX "x-binhex"
113 113
114#define CTE_TYPE(y) (((y)==B64ENCODED) ? "Base64" : \ 114#define CTE_TYPE(y) (((y)==B64ENCODED) ? "Base64" : \
115 ((y)==UU_ENCODED) ? CTE_UUENC : \ 115 ((y)==UU_ENCODED) ? CTE_UUENC : \
116 ((y)==XX_ENCODED) ? CTE_XXENC : \ 116 ((y)==XX_ENCODED) ? CTE_XXENC : \
117 ((y)==PT_ENCODED) ? "8bit" : \
118 ((y)==QP_ENCODED) ? "quoted-printable" : \
117 ((y)==BH_ENCODED) ? CTE_BINHEX : "x-oops") 119 ((y)==BH_ENCODED) ? CTE_BINHEX : "x-oops")
118 120
119/* 121/*
120 * encoding tables 122 * encoding tables
121 */ 123 */
161 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 163 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
162 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R', 164 'J', 'K', 'L', 'M', 'N', 'P', 'Q', 'R',
163 'S', 'T', 'U', 'V', 'X', 'Y', 'Z', '[', 165 'S', 'T', 'U', 'V', 'X', 'Y', 'Z', '[',
164 '`', 'a', 'b', 'c', 'd', 'e', 'f', 'h', 166 '`', 'a', 'b', 'c', 'd', 'e', 'f', 'h',
165 'i', 'j', 'k', 'l', 'm', 'p', 'q', 'r' 167 'i', 'j', 'k', 'l', 'm', 'p', 'q', 'r'
166}; 168};
169
170unsigned char HexEncodeTable[16] = {
171 '0', '1', '2', '3', '4', '5', '6', '7',
172 '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
173};
167 174
168typedef struct { 175typedef struct {
169 char *extension; 176 char *extension;
170 char *mimetype; 177 char *mimetype;
171} mimemap; 178} mimemap;
189 { "mov", "video/quicktime" }, /* Apple Quicktime */ 196 { "mov", "video/quicktime" }, /* Apple Quicktime */
190 { "qt", "video/quicktime" }, /* Also infrequently used */ 197 { "qt", "video/quicktime" }, /* Also infrequently used */
191 { "mpeg", "video/mpeg" }, /* Motion Picture Expert Group */ 198 { "mpeg", "video/mpeg" }, /* Motion Picture Expert Group */
192 { "mpg", "video/mpeg" }, 199 { "mpg", "video/mpeg" },
193 { "mp2", "video/mpeg" }, /* dito, MPEG-2 encoded files */ 200 { "mp2", "video/mpeg" }, /* dito, MPEG-2 encoded files */
194 { "mp3", "video/mpeg" }, /* dito, MPEG-3 encoded files */ 201 { "mp3", "audio/mpeg" }, /* dito, MPEG-3 encoded files */
195 { "ps", "application/postscript" }, /* Postscript Language */ 202 { "ps", "application/postscript" }, /* Postscript Language */
196 { "zip", "application/zip" }, /* ZIP archive */ 203 { "zip", "application/zip" }, /* ZIP archive */
197 { "doc", "application/msword"},/* assume Microsoft Word */ 204 { "doc", "application/msword"},/* assume Microsoft Word */
198 { NULL, NULL } 205 { NULL, NULL }
199}; 206};
241 int index, count; 248 int index, count;
242 long line=0; 249 long line=0;
243 size_t llen; 250 size_t llen;
244 251
245 if (outfile==NULL || infile==NULL || 252 if (outfile==NULL || infile==NULL ||
246 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED)) { 253 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
254 encoding!=PT_ENCODED&&encoding!=QP_ENCODED)) {
247 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 255 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
248 uustring (S_PARM_CHECK), "UUEncodeStream()"); 256 uustring (S_PARM_CHECK), "UUEncodeStream()");
249 return UURET_ILLVAL; 257 return UURET_ILLVAL;
250 } 258 }
251 259
260 /*
261 * Special handling for plain text and quoted printable. Text is
262 * read line oriented.
263 */
264
265 if (encoding == PT_ENCODED || encoding == QP_ENCODED) {
266 while (!feof (infile) && (linperfile <= 0 || line < linperfile)) {
267 if (FP_fgets (itemp, 255, infile) == NULL) {
268 break;
269 }
270
271 itemp[255] = '\0';
272 count = strlen (itemp);
273
274 llen = 0;
275 optr = otemp;
276
277 /*
278 * Busy Callback
279 */
280
281 if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize)) {
282 UUMessage (uuencode_id, __LINE__, UUMSG_NOTE,
283 uustring (S_ENCODE_CANCEL));
284 return UURET_CANCEL;
285 }
286
287 if (encoding == PT_ENCODED) {
288 /*
289 * If there is a line feed, replace by eolstring
290 */
291 if (count > 0 && itemp[count-1] == '\n') {
292 itemp[--count] = '\0';
293 if (fwrite (itemp, 1, count, outfile) != count ||
294 fwrite ((char *) eolstring, 1,
295 strlen(eolstring), outfile) != strlen (eolstring)) {
296 return UURET_IOERR;
297 }
298 }
299 else {
300 if (fwrite (itemp, 1, count, outfile) != llen) {
301 return UURET_IOERR;
302 }
303 }
304 }
305 else if (encoding == QP_ENCODED) {
306 for (index=0; index<count; index++) {
307 if (llen == 0 && itemp[index] == '.') {
308 /*
309 * Special rule: encode '.' at the beginning of a line, so
310 * that some mailers aren't confused.
311 */
312 *optr++ = '=';
313 *optr++ = HexEncodeTable[itemp[index] >> 4];
314 *optr++ = HexEncodeTable[itemp[index] & 0x0f];
315 llen += 3;
316 }
317 else if ((itemp[index] >= 33 && itemp[index] <= 60) ||
318 (itemp[index] >= 62 && itemp[index] <= 126) ||
319 itemp[index] == 9 || itemp[index] == 32) {
320 *optr++ = itemp[index];
321 llen++;
322 }
323 else if (itemp[index] == '\n') {
324 /*
325 * If the last character before EOL was a space or tab,
326 * we must encode it. If llen > 74, there's no space to do
327 * that, so generate a soft line break instead.
328 */
329
330 if (index>0 && (itemp[index-1] == 9 || itemp[index-1] == 32)) {
331 *(optr-1) = '=';
332 if (llen <= 74) {
333 *optr++ = HexEncodeTable[itemp[index-1] >> 4];
334 *optr++ = HexEncodeTable[itemp[index-1] & 0x0f];
335 llen += 2;
336 }
337 }
338
339 if (fwrite (otemp, 1, llen, outfile) != llen ||
340 fwrite ((char *) eolstring, 1,
341 strlen(eolstring), outfile) != strlen (eolstring)) {
342 return UURET_IOERR;
343 }
344
345 /*
346 * Fix the soft line break condition from above
347 */
348
349 if (index>0 && (itemp[index-1] == 9 || itemp[index-1] == 32) &&
350 *(optr-1) == '=') {
351 otemp[0] = '=';
352 otemp[1] = HexEncodeTable[itemp[index-1] >> 4];
353 otemp[2] = HexEncodeTable[itemp[index-1] & 0x0f];
354
355 if (fwrite (otemp, 1, 3, outfile) != 3 ||
356 fwrite ((char *) eolstring, 1,
357 strlen(eolstring), outfile) != strlen (eolstring)) {
358 return UURET_IOERR;
359 }
360 }
361
362 optr = otemp;
363 llen = 0;
364 }
365 else {
366 *optr++ = '=';
367 *optr++ = HexEncodeTable[itemp[index] >> 4];
368 *optr++ = HexEncodeTable[itemp[index] & 0x0f];
369 llen += 3;
370 }
371
372 /*
373 * Lines must be shorter than 76 characters (not counting CRLF).
374 * If the line grows longer than that, we must include a soft
375 * line break.
376 */
377
378 if (itemp[index+1] != 0 && itemp[index+1] != '\n' &&
379 (llen >= 75 ||
380 !((itemp[index+1] >= 33 && itemp[index+1] <= 60) ||
381 (itemp[index+1] >= 62 && itemp[index+1] <= 126)) &&
382 llen >= 73)) {
383
384 *optr++ = '=';
385 llen++;
386
387 if (fwrite (otemp, 1, llen, outfile) != llen ||
388 fwrite ((char *) eolstring, 1,
389 strlen(eolstring), outfile) != strlen (eolstring)) {
390 return UURET_IOERR;
391 }
392
393 optr = otemp;
394 llen = 0;
395 }
396 }
397 }
398
399 line++;
400 }
401
402 return UURET_OK;
403 }
404
405 /*
406 * Handling for binary encodings
407 */
252 408
253 /* 409 /*
254 * select charset 410 * select charset
255 */ 411 */
256 412
257 table = etables[encoding]; 413 table = etables[encoding];
258 414
259 if (table==NULL || bpl[encoding]==0) { 415 if (table==NULL || bpl[encoding]==0) {
260 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 416 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
261 uustring (S_PARM_CHECK), "UUEncodeStream()"); 417 uustring (S_PARM_CHECK), "UUEncodeStream()");
262 return UURET_ILLVAL; 418 return UURET_ILLVAL;
263 } 419 }
264 420
265 while (!feof (infile) && (linperfile <= 0 || line < linperfile)) { 421 while (!feof (infile) && (linperfile <= 0 || line < linperfile)) {
266 if ((count = fread (itemp, 1, bpl[encoding], infile)) != bpl[encoding]) { 422 if ((count = fread (itemp, 1, bpl[encoding], infile)) != bpl[encoding]) {
267 if (count == 0) 423 if (count == 0)
268 break; 424 break;
269 else if (ferror (infile)) 425 else if (ferror (infile))
270 return UURET_IOERR; 426 return UURET_IOERR;
271 } 427 }
428
272 optr = otemp; 429 optr = otemp;
273 llen = 0; 430 llen = 0;
274 431
275 /* 432 /*
276 * Busy Callback 433 * Busy Callback
283 } 440 }
284 441
285 /* 442 /*
286 * for UU and XX, encode the number of bytes as first character 443 * for UU and XX, encode the number of bytes as first character
287 */ 444 */
445
288 if (encoding == UU_ENCODED || encoding == XX_ENCODED) { 446 if (encoding == UU_ENCODED || encoding == XX_ENCODED) {
289 *optr++ = table[count]; 447 *optr++ = table[count];
290 llen++; 448 llen++;
291 } 449 }
292 450
451 /*
452 * Main encoding
453 */
454
455 if (encoding == UU_ENCODED || encoding == XX_ENCODED ||
456 encoding == B64ENCODED) {
293 for (index=0; index<=count-3; index+=3, llen+=4) { 457 for (index=0; index<=count-3; index+=3, llen+=4) {
294 *optr++ = table[itemp[index] >> 2]; 458 *optr++ = table[itemp[index] >> 2];
295 *optr++ = table[((itemp[index ] & 0x03) << 4) | (itemp[index+1] >> 4)]; 459 *optr++ = table[((itemp[index ] & 0x03) << 4)|(itemp[index+1] >> 4)];
296 *optr++ = table[((itemp[index+1] & 0x0f) << 2) | (itemp[index+2] >> 6)]; 460 *optr++ = table[((itemp[index+1] & 0x0f) << 2)|(itemp[index+2] >> 6)];
297 *optr++ = table[ itemp[index+2] & 0x3f]; 461 *optr++ = table[ itemp[index+2] & 0x3f];
462 }
298 } 463 }
299 464
300 /* 465 /*
301 * Special handling for incomplete lines 466 * Special handling for incomplete lines
302 */ 467 */
468
303 if (index != count) { 469 if (index != count) {
304 if (encoding == B64ENCODED) { 470 if (encoding == B64ENCODED) {
305 if (count - index == 2) { 471 if (count - index == 2) {
306 *optr++ = table[itemp[index] >> 2]; 472 *optr++ = table[itemp[index] >> 2];
307 *optr++ = table[((itemp[index ] & 0x03) << 4) | 473 *optr++ = table[((itemp[index ] & 0x03) << 4) |
315 *optr++ = '='; 481 *optr++ = '=';
316 *optr++ = '='; 482 *optr++ = '=';
317 } 483 }
318 llen += 4; 484 llen += 4;
319 } 485 }
320 else { 486 else if (encoding == UU_ENCODED || encoding == XX_ENCODED) {
321 if (count - index == 2) { 487 if (count - index == 2) {
322 *optr++ = table[itemp[index] >> 2]; 488 *optr++ = table[itemp[index] >> 2];
323 *optr++ = table[((itemp[index ] & 0x03) << 4) | 489 *optr++ = table[((itemp[index ] & 0x03) << 4) |
324 ( itemp[index+1] >> 4)]; 490 ( itemp[index+1] >> 4)];
325 *optr++ = table[((itemp[index+1] & 0x0f) << 2)]; 491 *optr++ = table[((itemp[index+1] & 0x0f) << 2)];
332 *optr++ = table[0]; 498 *optr++ = table[0];
333 } 499 }
334 llen += 4; 500 llen += 4;
335 } 501 }
336 } 502 }
503
337 /* 504 /*
338 * end of line 505 * end of line
339 */ 506 */
507
340 tptr = eolstring; 508 tptr = eolstring;
341 509
342 while (*tptr) 510 while (*tptr)
343 *optr++ = *tptr++; 511 *optr++ = *tptr++;
344 512
368 char *ptr; 536 char *ptr;
369 537
370 if (outfile==NULL || 538 if (outfile==NULL ||
371 (infile == NULL && infname==NULL) || 539 (infile == NULL && infname==NULL) ||
372 (outfname==NULL && infname==NULL) || 540 (outfname==NULL && infname==NULL) ||
373 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED)) { 541 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
542 encoding!=PT_ENCODED&&encoding!=QP_ENCODED)) {
374 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 543 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
375 uustring (S_PARM_CHECK), "UUEncodeMulti()"); 544 uustring (S_PARM_CHECK), "UUEncodeMulti()");
376 return UURET_ILLVAL; 545 return UURET_ILLVAL;
377 } 546 }
378 547
428 while (miter->extension && FP_stricmp (ptr+1, miter->extension) != 0) 597 while (miter->extension && FP_stricmp (ptr+1, miter->extension) != 0)
429 miter++; 598 miter++;
430 mimetype = miter->mimetype; 599 mimetype = miter->mimetype;
431 } 600 }
432 } 601 }
602
603 if (mimetype == NULL && (encoding == PT_ENCODED || encoding == QP_ENCODED)) {
604 mimetype = "text/plain";
605 }
606
433 /* 607 /*
434 * print sub-header 608 * print sub-header
435 */ 609 */
436 610
437 fprintf (outfile, "Content-Type: %s%s", 611 fprintf (outfile, "Content-Type: %s%s",
495 char *ptr; 669 char *ptr;
496 int res; 670 int res;
497 671
498 if ((outfname==NULL&&infname==NULL) || partno<=0 || 672 if ((outfname==NULL&&infname==NULL) || partno<=0 ||
499 (infile == NULL&&infname==NULL) || outfile==NULL || 673 (infile == NULL&&infname==NULL) || outfile==NULL ||
500 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED)) { 674 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
675 encoding!=PT_ENCODED&&encoding!=QP_ENCODED)) {
501 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 676 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
502 uustring (S_PARM_CHECK), "UUEncodePartial()"); 677 uustring (S_PARM_CHECK), "UUEncodePartial()");
503 return UURET_ILLVAL; 678 return UURET_ILLVAL;
504 } 679 }
505 680
572 while (miter->extension && FP_stricmp (ptr+1, miter->extension) != 0) 747 while (miter->extension && FP_stricmp (ptr+1, miter->extension) != 0)
573 miter++; 748 miter++;
574 mimetype = miter->mimetype; 749 mimetype = miter->mimetype;
575 } 750 }
576 } 751 }
752
753 if (mimetype == NULL && (encoding==PT_ENCODED || encoding==QP_ENCODED)) {
754 mimetype = "text/plain";
755 }
756
577 /* 757 /*
578 * print sub-header 758 * print sub-header
579 */ 759 */
580 760
581 fprintf (outfile, "MIME-Version: 1.0%s", eolstring); 761 fprintf (outfile, "MIME-Version: 1.0%s", eolstring);
637 fprintf (outfile, "%c%s", 817 fprintf (outfile, "%c%s",
638 (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0], 818 (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0],
639 eolstring); 819 eolstring);
640 fprintf (outfile, "end%s", eolstring); 820 fprintf (outfile, "end%s", eolstring);
641 } 821 }
822
642 /* 823 /*
643 * empty line at end does no harm 824 * empty line at end does no harm
644 */ 825 */
826
827 if (encoding != PT_ENCODED && encoding != QP_ENCODED) {
645 fprintf (outfile, "%s", eolstring); 828 fprintf (outfile, "%s", eolstring);
829 }
646 830
647 if (infile==NULL) { 831 if (infile==NULL) {
648 if (res != UURET_OK) { 832 if (res != UURET_OK) {
649 progress.action = 0; 833 progress.action = 0;
650 fclose (theifile); 834 fclose (theifile);
680 int res; 864 int res;
681 865
682 if (outfile==NULL || 866 if (outfile==NULL ||
683 (infile == NULL&&infname==NULL) || 867 (infile == NULL&&infname==NULL) ||
684 (outfname==NULL&&infname==NULL) || 868 (outfname==NULL&&infname==NULL) ||
685 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED)) { 869 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
870 encoding!=PT_ENCODED&&encoding!=QP_ENCODED)) {
686 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 871 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
687 uustring (S_PARM_CHECK), "UUEncodeToStream()"); 872 uustring (S_PARM_CHECK), "UUEncodeToStream()");
688 return UURET_ILLVAL; 873 return UURET_ILLVAL;
689 } 874 }
690 875
776 FILE *theifile, *outfile; 961 FILE *theifile, *outfile;
777 struct stat finfo; 962 struct stat finfo;
778 963
779 if ((diskname==NULL&&infname==NULL) || 964 if ((diskname==NULL&&infname==NULL) ||
780 (outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) || 965 (outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) ||
781 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED)) { 966 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
967 encoding!=PT_ENCODED&&encoding!=QP_ENCODED)) {
782 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 968 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
783 uustring (S_PARM_CHECK), "UUEncodeToFile()"); 969 uustring (S_PARM_CHECK), "UUEncodeToFile()");
784 return UURET_ILLVAL; 970 return UURET_ILLVAL;
785 } 971 }
786 972
1011 char *infname, int encoding, 1197 char *infname, int encoding,
1012 char *outfname, int filemode, 1198 char *outfname, int filemode,
1013 char *destination, char *from, 1199 char *destination, char *from,
1014 char *subject, int isemail) 1200 char *subject, int isemail)
1015{ 1201{
1202 return UUE_PrepSingleExt (outfile, infile,
1203 infname, encoding,
1204 outfname, filemode,
1205 destination, from,
1206 subject, NULL,
1207 isemail);
1208}
1209
1210int UUEXPORT
1211UUE_PrepSingleExt (FILE *outfile, FILE *infile,
1212 char *infname, int encoding,
1213 char *outfname, int filemode,
1214 char *destination, char *from,
1215 char *subject, char *replyto,
1216 int isemail)
1217{
1016 mimemap *miter=mimetable; 1218 mimemap *miter=mimetable;
1017 char *subline, *oname; 1219 char *subline, *oname;
1018 char *mimetype, *ptr; 1220 char *mimetype, *ptr;
1019 int res, len; 1221 int res, len;
1020 1222
1021 if ((outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) || 1223 if ((outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) ||
1022 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED)) { 1224 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
1225 encoding!=PT_ENCODED&&encoding!=QP_ENCODED)) {
1023 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1226 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
1024 uustring (S_PARM_CHECK), "UUE_PrepSingle()"); 1227 uustring (S_PARM_CHECK), "UUE_PrepSingle()");
1025 return UURET_ILLVAL; 1228 return UURET_ILLVAL;
1026 } 1229 }
1027 1230
1034 mimetype = miter->mimetype; 1237 mimetype = miter->mimetype;
1035 } 1238 }
1036 else 1239 else
1037 mimetype = NULL; 1240 mimetype = NULL;
1038 1241
1242 if (mimetype == NULL && (encoding == PT_ENCODED || encoding == QP_ENCODED)) {
1243 mimetype = "text/plain";
1244 }
1245
1039 if ((subline = (char *) malloc (len)) == NULL) { 1246 if ((subline = (char *) malloc (len)) == NULL) {
1040 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1247 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
1041 uustring (S_OUT_OF_MEMORY), len); 1248 uustring (S_OUT_OF_MEMORY), len);
1042 return UURET_NOMEM; 1249 return UURET_NOMEM;
1043 } 1250 }
1045 if (subject) 1252 if (subject)
1046 sprintf (subline, "%s (001/001) - [ %s ]", subject, oname); 1253 sprintf (subline, "%s (001/001) - [ %s ]", subject, oname);
1047 else 1254 else
1048 sprintf (subline, "[ %s ] (001/001)", oname); 1255 sprintf (subline, "[ %s ] (001/001)", oname);
1049 1256
1050 fprintf (outfile, "Subject: %s%s", subline, eolstring);
1051
1052 if (from) { 1257 if (from) {
1053 fprintf (outfile, "From: %s%s", from, eolstring); 1258 fprintf (outfile, "From: %s%s", from, eolstring);
1054 } 1259 }
1055 if (destination) { 1260 if (destination) {
1056 fprintf (outfile, "%s: %s%s", 1261 fprintf (outfile, "%s: %s%s",
1057 (isemail)?"To":"Newsgroups", 1262 (isemail)?"To":"Newsgroups",
1058 destination, eolstring); 1263 destination, eolstring);
1059 } 1264 }
1265
1266 fprintf (outfile, "Subject: %s%s", subline, eolstring);
1267
1268 if (replyto) {
1269 fprintf (outfile, "Reply-To: %s%s", replyto, eolstring);
1270 }
1271
1060 fprintf (outfile, "MIME-Version: 1.0%s", eolstring); 1272 fprintf (outfile, "MIME-Version: 1.0%s", eolstring);
1061 fprintf (outfile, "Content-Type: %s; name=\"%s\"%s", 1273 fprintf (outfile, "Content-Type: %s; name=\"%s\"%s",
1062 (mimetype)?mimetype:"Application/Octet-Stream", 1274 (mimetype)?mimetype:"Application/Octet-Stream",
1063 UUFNameFilter ((outfname)?outfname:infname), 1275 UUFNameFilter ((outfname)?outfname:infname),
1064 eolstring); 1276 eolstring);
1079 char *outfname, int filemode, 1291 char *outfname, int filemode,
1080 int partno, long linperfile, long filesize, 1292 int partno, long linperfile, long filesize,
1081 char *destination, char *from, char *subject, 1293 char *destination, char *from, char *subject,
1082 int isemail) 1294 int isemail)
1083{ 1295{
1296 return UUE_PrepPartialExt (outfile, infile,
1297 infname, encoding,
1298 outfname, filemode,
1299 partno, linperfile, filesize,
1300 destination,
1301 from, subject, NULL,
1302 isemail);
1303}
1304
1305int UUEXPORT
1306UUE_PrepPartialExt (FILE *outfile, FILE *infile,
1307 char *infname, int encoding,
1308 char *outfname, int filemode,
1309 int partno, long linperfile, long filesize,
1310 char *destination,
1311 char *from, char *subject, char *replyto,
1312 int isemail)
1313{
1084 static int numparts, themode; 1314 static int numparts, themode;
1085 static char mimeid[64]; 1315 static char mimeid[64];
1086 static FILE *theifile; 1316 static FILE *theifile;
1087 struct stat finfo; 1317 struct stat finfo;
1088 char *subline, *oname; 1318 char *subline, *oname;
1089 long thesize; 1319 long thesize;
1090 int res, len; 1320 int res, len;
1091 1321
1092 if ((outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) || 1322 if ((outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) ||
1093 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED)) { 1323 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
1324 encoding!=PT_ENCODED&&encoding!=QP_ENCODED)) {
1094 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1325 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
1095 uustring (S_PARM_CHECK), "UUE_PrepPartial()"); 1326 uustring (S_PARM_CHECK), "UUE_PrepPartial()");
1096 return UURET_ILLVAL; 1327 return UURET_ILLVAL;
1097 } 1328 }
1098 1329
1161 * if there's one part only, don't use Message/Partial 1392 * if there's one part only, don't use Message/Partial
1162 */ 1393 */
1163 1394
1164 if (numparts == 1) { 1395 if (numparts == 1) {
1165 if (infile==NULL) fclose (theifile); 1396 if (infile==NULL) fclose (theifile);
1166 return UUE_PrepSingle (outfile, infile, infname, encoding, 1397 return UUE_PrepSingleExt (outfile, infile, infname, encoding,
1167 outfname, filemode, destination, 1398 outfname, filemode, destination,
1168 from, subject, isemail); 1399 from, subject, replyto, isemail);
1169 } 1400 }
1170 1401
1171 /* 1402 /*
1172 * we also need a unique ID 1403 * we also need a unique ID
1173 */ 1404 */
1188 subject, partno, numparts, oname); 1419 subject, partno, numparts, oname);
1189 else 1420 else
1190 sprintf (subline, "[ %s ] (%03d/%03d)", 1421 sprintf (subline, "[ %s ] (%03d/%03d)",
1191 oname, partno, numparts); 1422 oname, partno, numparts);
1192 1423
1193 fprintf (outfile, "Subject: %s%s", subline, eolstring);
1194
1195 if (from) { 1424 if (from) {
1196 fprintf (outfile, "From: %s%s", from, eolstring); 1425 fprintf (outfile, "From: %s%s", from, eolstring);
1197 } 1426 }
1427
1198 if (destination) { 1428 if (destination) {
1199 fprintf (outfile, "%s: %s%s", 1429 fprintf (outfile, "%s: %s%s",
1200 (isemail)?"To":"Newsgroups", 1430 (isemail)?"To":"Newsgroups",
1201 destination, eolstring); 1431 destination, eolstring);
1202 } 1432 }
1433
1434 fprintf (outfile, "Subject: %s%s", subline, eolstring);
1435
1436 if (replyto) {
1437 fprintf (outfile, "Reply-To: %s%s", replyto, eolstring);
1438 }
1439
1203 fprintf (outfile, "MIME-Version: 1.0%s", eolstring); 1440 fprintf (outfile, "MIME-Version: 1.0%s", eolstring);
1204 fprintf (outfile, "Content-Type: Message/Partial; number=%d; total=%d;%s", 1441 fprintf (outfile, "Content-Type: Message/Partial; number=%d; total=%d;%s",
1205 partno, numparts, eolstring); 1442 partno, numparts, eolstring);
1206 fprintf (outfile, "\tid=\"%s\"%s", 1443 fprintf (outfile, "\tid=\"%s\"%s",
1207 mimeid, eolstring); 1444 mimeid, eolstring);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines