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.2 by root, Mon Jun 11 20:42:37 2001 UTC vs.
Revision 1.2.2.5 by root, Sun Apr 18 19:55:46 2004 UTC

44 44
45#include <uudeview.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#include <crc32.h>
49 50
50/* for braindead systems */ 51/* for braindead systems */
51#ifndef SEEK_SET 52#ifndef SEEK_SET
52#ifdef L_BEGIN 53#ifdef L_BEGIN
53#define SEEK_SET L_BEGIN 54#define SEEK_SET L_BEGIN
54#else 55#else
55#define SEEK_SET 0 56#define SEEK_SET 0
56#endif 57#endif
57#endif 58#endif
58 59
59char * uuencode_id = "$Id: uuencode.c,v 1.2 2001/06/11 20:42:37 root Exp $"; 60char * uuencode_id = "$Id: uuencode.c,v 1.2.2.5 2004/04/18 19:55:46 root Exp $";
60 61
61#if 0 62#if 0
62/* 63/*
63 * the End-Of-Line string. MIME enforces CRLF, so that's what we use. Some 64 * 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 65 * implementations of uudecode will complain about a missing end line, since
108 */ 109 */
109 110
110#define CTE_UUENC "x-uuencode" 111#define CTE_UUENC "x-uuencode"
111#define CTE_XXENC "x-xxencode" 112#define CTE_XXENC "x-xxencode"
112#define CTE_BINHEX "x-binhex" 113#define CTE_BINHEX "x-binhex"
114#define CTE_YENC "x-yenc"
113 115
114#define CTE_TYPE(y) (((y)==B64ENCODED) ? "Base64" : \ 116#define CTE_TYPE(y) (((y)==B64ENCODED) ? "Base64" : \
115 ((y)==UU_ENCODED) ? CTE_UUENC : \ 117 ((y)==UU_ENCODED) ? CTE_UUENC : \
116 ((y)==XX_ENCODED) ? CTE_XXENC : \ 118 ((y)==XX_ENCODED) ? CTE_XXENC : \
117 ((y)==PT_ENCODED) ? "8bit" : \ 119 ((y)==PT_ENCODED) ? "8bit" : \
118 ((y)==QP_ENCODED) ? "quoted-printable" : \ 120 ((y)==QP_ENCODED) ? "quoted-printable" : \
119 ((y)==BH_ENCODED) ? CTE_BINHEX : "x-oops") 121 ((y)==BH_ENCODED) ? CTE_BINHEX : \
122 ((y)==YENC_ENCODED) ? CTE_YENC : "x-oops")
120 123
121/* 124/*
122 * encoding tables 125 * encoding tables
123 */ 126 */
124 127
212 215
213/* 216/*
214 * encoded bytes per line 217 * encoded bytes per line
215 */ 218 */
216 219
217static int bpl[5] = { 0, 45, 57, 45, 45 }; 220static int bpl[8] = { 0, 45, 57, 45, 45, 0, 0, 128 };
218 221
219/* 222/*
220 * tables 223 * tables
221 */ 224 */
222 225
238/* 241/*
239 * Encode one part of the data stream 242 * Encode one part of the data stream
240 */ 243 */
241 244
242static int 245static int
243UUEncodeStream (FILE *outfile, FILE *infile, int encoding, long linperfile) 246UUEncodeStream (FILE *outfile, FILE *infile, int encoding, long linperfile, crc32_t *crc, crc32_t *pcrc)
244{ 247{
245 uchar *itemp = (uchar *) uuestr_itemp; 248 unsigned char *itemp = (char *) uuestr_itemp;
246 uchar *otemp = (uchar *) uuestr_otemp; 249 unsigned char *otemp = (char *) uuestr_otemp;
247 unsigned char *optr, *table, *tptr; 250 unsigned char *optr, *table, *tptr;
248 int index, count; 251 int index, count;
249 long line=0; 252 long line=0;
250 size_t llen; 253 size_t llen;
251 254
252 if (outfile==NULL || infile==NULL || 255 if (outfile==NULL || infile==NULL ||
253 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& 256 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
254 encoding!=PT_ENCODED&&encoding!=QP_ENCODED)) { 257 encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) {
255 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 258 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
256 uustring (S_PARM_CHECK), "UUEncodeStream()"); 259 uustring (S_PARM_CHECK), "UUEncodeStream()");
257 return UURET_ILLVAL; 260 return UURET_ILLVAL;
258 } 261 }
259 262
262 * read line oriented. 265 * read line oriented.
263 */ 266 */
264 267
265 if (encoding == PT_ENCODED || encoding == QP_ENCODED) { 268 if (encoding == PT_ENCODED || encoding == QP_ENCODED) {
266 while (!feof (infile) && (linperfile <= 0 || line < linperfile)) { 269 while (!feof (infile) && (linperfile <= 0 || line < linperfile)) {
267 if (FP_fgets (itemp, 255, infile) == NULL) { 270 if (_FP_fgets (itemp, 255, infile) == NULL) {
268 break; 271 break;
269 } 272 }
270 273
271 itemp[255] = '\0'; 274 itemp[255] = '\0';
272 count = strlen (itemp); 275 count = strlen (itemp);
375 * line break. 378 * line break.
376 */ 379 */
377 380
378 if (itemp[index+1] != 0 && itemp[index+1] != '\n' && 381 if (itemp[index+1] != 0 && itemp[index+1] != '\n' &&
379 (llen >= 75 || 382 (llen >= 75 ||
380 !((itemp[index+1] >= 33 && itemp[index+1] <= 60) || 383 (!((itemp[index+1] >= 33 && itemp[index+1] <= 60) ||
381 (itemp[index+1] >= 62 && itemp[index+1] <= 126)) && 384 (itemp[index+1] >= 62 && itemp[index+1] <= 126)) &&
382 llen >= 73)) { 385 llen >= 73))) {
383 386
384 *optr++ = '='; 387 *optr++ = '=';
385 llen++; 388 llen++;
386 389
387 if (fwrite (otemp, 1, llen, outfile) != llen || 390 if (fwrite (otemp, 1, llen, outfile) != llen ||
401 404
402 return UURET_OK; 405 return UURET_OK;
403 } 406 }
404 407
405 /* 408 /*
409 * Special handling for yEnc
410 */
411
412 if (encoding == YENC_ENCODED) {
413 llen = 0;
414 optr = otemp;
415
416 while (!feof (infile) && (linperfile <= 0 || line < linperfile)) {
417 if ((count = fread (itemp, 1, 128, infile)) != 128) {
418 if (count == 0) {
419 break;
420 }
421 else if (ferror (infile)) {
422 return UURET_IOERR;
423 }
424 }
425
426 if (pcrc)
427 *pcrc = crc32(*pcrc, itemp, count);
428 if (crc)
429 *crc = crc32(*crc, itemp, count);
430
431 line++;
432
433 /*
434 * Busy Callback
435 */
436
437 if (UUBUSYPOLL(ftell(infile)-progress.foffset,progress.fsize)) {
438 UUMessage (uuencode_id, __LINE__, UUMSG_NOTE,
439 uustring (S_ENCODE_CANCEL));
440 return UURET_CANCEL;
441 }
442
443 for (index=0; index<count; index++) {
444 if (llen > 127) {
445 if (fwrite (otemp, 1, llen, outfile) != llen ||
446 fwrite ((char *) eolstring, 1,
447 strlen(eolstring), outfile) != strlen (eolstring)) {
448 return UURET_IOERR;
449 }
450 llen = 0;
451 optr = otemp;
452 }
453
454 switch ((char) ((int) itemp[index] + 42)) {
455 case '\0':
456 case '\t':
457 case '\n':
458 case '\r':
459 case '=':
460 case '\033':
461 *optr++ = '=';
462 *optr++ = (char) ((int) itemp[index] + 42 + 64);
463 llen += 2;
464 break;
465
466 case '.':
467 if (llen == 0) {
468 *optr++ = '=';
469 *optr++ = (char) ((int) itemp[index] + 42 + 64);
470 llen += 2;
471 }
472 else {
473 *optr++ = (char) ((int) itemp[index] + 42);
474 llen++;
475 }
476 break;
477
478 default:
479 *optr++ = (char) ((int) itemp[index] + 42);
480 llen++;
481 break;
482 }
483 }
484 }
485
486 /*
487 * write last line
488 */
489
490 if (llen) {
491 if (fwrite (otemp, 1, llen, outfile) != llen ||
492 fwrite ((char *) eolstring, 1,
493 strlen(eolstring), outfile) != strlen (eolstring)) {
494 return UURET_IOERR;
495 }
496 }
497
498 return UURET_OK;
499 }
500
501 /*
406 * Handling for binary encodings 502 * Handling for binary encodings
407 */ 503 */
408 504
409 /* 505 /*
410 * select charset 506 * select charset
450 546
451 /* 547 /*
452 * Main encoding 548 * Main encoding
453 */ 549 */
454 550
455 if (encoding == UU_ENCODED || encoding == XX_ENCODED ||
456 encoding == B64ENCODED) {
457 for (index=0; index<=count-3; index+=3, llen+=4) { 551 for (index=0; index<=count-3; index+=3, llen+=4) {
458 *optr++ = table[itemp[index] >> 2]; 552 *optr++ = table[itemp[index] >> 2];
459 *optr++ = table[((itemp[index ] & 0x03) << 4)|(itemp[index+1] >> 4)]; 553 *optr++ = table[((itemp[index ] & 0x03) << 4)|(itemp[index+1] >> 4)];
460 *optr++ = table[((itemp[index+1] & 0x0f) << 2)|(itemp[index+2] >> 6)]; 554 *optr++ = table[((itemp[index+1] & 0x0f) << 2)|(itemp[index+2] >> 6)];
461 *optr++ = table[ itemp[index+2] & 0x3f]; 555 *optr++ = table[ itemp[index+2] & 0x3f];
462 }
463 } 556 }
464 557
465 /* 558 /*
466 * Special handling for incomplete lines 559 * Special handling for incomplete lines
467 */ 560 */
532 mimemap *miter=mimetable; 625 mimemap *miter=mimetable;
533 struct stat finfo; 626 struct stat finfo;
534 int res, themode; 627 int res, themode;
535 FILE *theifile; 628 FILE *theifile;
536 char *ptr; 629 char *ptr;
630 crc32_t crc;
631 crc32_t *crcptr=NULL;
537 632
538 if (outfile==NULL || 633 if (outfile==NULL ||
539 (infile == NULL && infname==NULL) || 634 (infile == NULL && infname==NULL) ||
540 (outfname==NULL && infname==NULL) || 635 (outfname==NULL && infname==NULL) ||
541 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& 636 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
542 encoding!=PT_ENCODED&&encoding!=QP_ENCODED)) { 637 encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) {
543 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 638 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
544 uustring (S_PARM_CHECK), "UUEncodeMulti()"); 639 uustring (S_PARM_CHECK), "UUEncodeMulti()");
545 return UURET_ILLVAL; 640 return UURET_ILLVAL;
546 } 641 }
547 642
573 progress.fsize = (long) finfo.st_size; 668 progress.fsize = (long) finfo.st_size;
574 } 669 }
575 theifile = infile; 670 theifile = infile;
576 } 671 }
577 672
578 if (progress.fsize <= 0) 673 if (progress.fsize < 0)
579 progress.fsize = -1; 674 progress.fsize = -1;
580 675
581 FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256); 676 _FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256);
582 677
583 progress.partno = 1; 678 progress.partno = 1;
584 progress.numparts = 1; 679 progress.numparts = 1;
585 progress.percent = 0; 680 progress.percent = 0;
586 progress.foffset = 0; 681 progress.foffset = 0;
591 * looking at the file's extension. If it is unknown, default to 686 * looking at the file's extension. If it is unknown, default to
592 * Application/Octet-Stream 687 * Application/Octet-Stream
593 */ 688 */
594 689
595 if (mimetype == NULL) { 690 if (mimetype == NULL) {
596 if ((ptr = FP_strrchr ((outfname)?outfname:infname, '.'))) { 691 if ((ptr = _FP_strrchr ((outfname)?outfname:infname, '.'))) {
597 while (miter->extension && FP_stricmp (ptr+1, miter->extension) != 0) 692 while (miter->extension && _FP_stricmp (ptr+1, miter->extension) != 0)
598 miter++; 693 miter++;
599 mimetype = miter->mimetype; 694 mimetype = miter->mimetype;
600 } 695 }
601 } 696 }
602 697
606 701
607 /* 702 /*
608 * print sub-header 703 * print sub-header
609 */ 704 */
610 705
706 if (encoding != YENC_ENCODED) {
611 fprintf (outfile, "Content-Type: %s%s", 707 fprintf (outfile, "Content-Type: %s%s",
612 (mimetype)?mimetype:"Application/Octet-Stream", 708 (mimetype)?mimetype:"Application/Octet-Stream",
613 eolstring); 709 eolstring);
614 fprintf (outfile, "Content-Transfer-Encoding: %s%s", 710 fprintf (outfile, "Content-Transfer-Encoding: %s%s",
615 CTE_TYPE(encoding), eolstring); 711 CTE_TYPE(encoding), eolstring);
616 fprintf (outfile, "Content-Disposition: attachment; filename=\"%s\"%s", 712 fprintf (outfile, "Content-Disposition: attachment; filename=\"%s\"%s",
617 UUFNameFilter ((outfname)?outfname:infname), eolstring); 713 UUFNameFilter ((outfname)?outfname:infname), eolstring);
618 fprintf (outfile, "%s", eolstring); 714 fprintf (outfile, "%s", eolstring);
715 }
619 716
620 if (encoding == UU_ENCODED || encoding == XX_ENCODED) { 717 if (encoding == UU_ENCODED || encoding == XX_ENCODED) {
621 fprintf (outfile, "begin %o %s%s", 718 fprintf (outfile, "begin %o %s%s",
622 (themode) ? themode : 0644, 719 (themode) ? themode : 0644,
623 UUFNameFilter ((outfname)?outfname:infname), 720 UUFNameFilter ((outfname)?outfname:infname),
624 eolstring); 721 eolstring);
625 } 722 }
723 else if (encoding == YENC_ENCODED) {
724 crc = crc32(0L, Z_NULL, 0);
725 crcptr = &crc;
726 if (progress.fsize == -1) {
727 fprintf (outfile, "=ybegin line=128 name=%s%s",
728 UUFNameFilter ((outfname)?outfname:infname),
729 eolstring);
730 }
731 else {
732 fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s",
733 progress.fsize,
734 UUFNameFilter ((outfname)?outfname:infname),
735 eolstring);
736 }
737 }
738
626 if ((res = UUEncodeStream (outfile, theifile, encoding, 0)) != UURET_OK) { 739 if ((res = UUEncodeStream (outfile, theifile, encoding, 0, crcptr, NULL)) != UURET_OK) {
627 if (res != UURET_CANCEL) { 740 if (res != UURET_CANCEL) {
628 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 741 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
629 uustring (S_ERR_ENCODING), 742 uustring (S_ERR_ENCODING),
630 UUFNameFilter ((infname)?infname:outfname), 743 UUFNameFilter ((infname)?infname:outfname),
631 (res==UURET_IOERR)?strerror(uu_errno):UUstrerror(res)); 744 (res==UURET_IOERR)?strerror(uu_errno):UUstrerror(res));
632 } 745 }
633 progress.action = 0; 746 progress.action = 0;
634 return res; 747 return res;
635 } 748 }
749
636 if (encoding == UU_ENCODED || encoding == XX_ENCODED) { 750 if (encoding == UU_ENCODED || encoding == XX_ENCODED) {
637 fprintf (outfile, "%c%s", 751 fprintf (outfile, "%c%s",
638 (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0], 752 (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0],
639 eolstring); 753 eolstring);
640 fprintf (outfile, "end%s", eolstring); 754 fprintf (outfile, "end%s", eolstring);
641 } 755 }
756 else if (encoding == YENC_ENCODED) {
757 if (progress.fsize == -1) {
758 fprintf (outfile, "=yend crc32=%08lx%s",
759 crc,
760 eolstring);
761 }
762 else {
763 fprintf (outfile, "=yend size=%ld crc32=%08lx%s",
764 progress.fsize,
765 crc,
766 eolstring);
767 }
768 }
769
642 /* 770 /*
643 * empty line at end does no harm 771 * empty line at end does no harm
644 */ 772 */
773
645 fprintf (outfile, "%s", eolstring); 774 fprintf (outfile, "%s", eolstring);
646 775
647 if (infile==NULL) 776 if (infile==NULL)
648 fclose (theifile); 777 fclose (theifile);
649 778
657 786
658int UUEXPORT 787int UUEXPORT
659UUEncodePartial (FILE *outfile, FILE *infile, 788UUEncodePartial (FILE *outfile, FILE *infile,
660 char *infname, int encoding, 789 char *infname, int encoding,
661 char *outfname, char *mimetype, 790 char *outfname, char *mimetype,
662 int filemode, int partno, long linperfile) 791 int filemode, int partno, long linperfile,
792 crc32_t *crcptr)
663{ 793{
664 mimemap *miter=mimetable; 794 mimemap *miter=mimetable;
665 static FILE *theifile; 795 static FILE *theifile;
666 int themode, numparts; 796 int themode, numparts;
667 struct stat finfo; 797 struct stat finfo;
668 long thesize; 798 long thesize;
669 char *ptr; 799 char *ptr;
670 int res; 800 int res;
801 crc32_t pcrc;
802 crc32_t *pcrcptr=NULL;
671 803
672 if ((outfname==NULL&&infname==NULL) || partno<=0 || 804 if ((outfname==NULL&&infname==NULL) || partno<=0 ||
673 (infile == NULL&&infname==NULL) || outfile==NULL || 805 (infile == NULL&&infname==NULL) || outfile==NULL ||
674 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& 806 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
675 encoding!=PT_ENCODED&&encoding!=QP_ENCODED)) { 807 encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) {
676 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 808 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
677 uustring (S_PARM_CHECK), "UUEncodePartial()"); 809 uustring (S_PARM_CHECK), "UUEncodePartial()");
678 return UURET_ILLVAL; 810 return UURET_ILLVAL;
679 } 811 }
680 812
711 if (fstat (fileno (infile), &finfo) != 0) { 843 if (fstat (fileno (infile), &finfo) != 0) {
712 UUMessage (uuencode_id, __LINE__, UUMSG_WARNING, 844 UUMessage (uuencode_id, __LINE__, UUMSG_WARNING,
713 uustring (S_STAT_ONE_PART)); 845 uustring (S_STAT_ONE_PART));
714 numparts = 1; 846 numparts = 1;
715 themode = (filemode)?filemode:0644; 847 themode = (filemode)?filemode:0644;
716 thesize = 0; 848 thesize = -1;
717 } 849 }
718 else { 850 else {
719 if (linperfile <= 0) 851 if (linperfile <= 0)
720 numparts = 1; 852 numparts = 1;
721 else 853 else
726 thesize = (long) finfo.st_size; 858 thesize = (long) finfo.st_size;
727 } 859 }
728 theifile = infile; 860 theifile = infile;
729 } 861 }
730 862
731 FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256); 863 _FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256);
732 864
733 progress.totsize = (thesize>0) ? thesize : -1; 865 progress.totsize = (thesize>=0) ? thesize : -1;
734 progress.partno = 1; 866 progress.partno = 1;
735 progress.numparts = numparts; 867 progress.numparts = numparts;
736 progress.percent = 0; 868 progress.percent = 0;
737 progress.foffset = 0; 869 progress.foffset = 0;
738 870
741 * looking at the file's extension. If it is unknown, default to 873 * looking at the file's extension. If it is unknown, default to
742 * Application/Octet-Stream 874 * Application/Octet-Stream
743 */ 875 */
744 876
745 if (mimetype == NULL) { 877 if (mimetype == NULL) {
746 if ((ptr = FP_strrchr ((outfname)?outfname:infname, '.'))) { 878 if ((ptr = _FP_strrchr ((outfname)?outfname:infname, '.'))) {
747 while (miter->extension && FP_stricmp (ptr+1, miter->extension) != 0) 879 while (miter->extension && _FP_stricmp (ptr+1, miter->extension) != 0)
748 miter++; 880 miter++;
749 mimetype = miter->mimetype; 881 mimetype = miter->mimetype;
750 } 882 }
751 } 883 }
752 884
756 888
757 /* 889 /*
758 * print sub-header 890 * print sub-header
759 */ 891 */
760 892
893 if (encoding != YENC_ENCODED) {
761 fprintf (outfile, "MIME-Version: 1.0%s", eolstring); 894 fprintf (outfile, "MIME-Version: 1.0%s", eolstring);
762 fprintf (outfile, "Content-Type: %s%s", 895 fprintf (outfile, "Content-Type: %s%s",
763 (mimetype)?mimetype:"Application/Octet-Stream", 896 (mimetype)?mimetype:"Application/Octet-Stream",
764 eolstring); 897 eolstring);
765 fprintf (outfile, "Content-Transfer-Encoding: %s%s", 898 fprintf (outfile, "Content-Transfer-Encoding: %s%s",
766 CTE_TYPE(encoding), eolstring); 899 CTE_TYPE(encoding), eolstring);
767 fprintf (outfile, "Content-Disposition: attachment; filename=\"%s\"%s", 900 fprintf (outfile, "Content-Disposition: attachment; filename=\"%s\"%s",
768 UUFNameFilter ((outfname)?outfname:infname), eolstring); 901 UUFNameFilter ((outfname)?outfname:infname), eolstring);
902 }
903
769 fprintf (outfile, "%s", eolstring); 904 fprintf (outfile, "%s", eolstring);
770 905
771 /* 906 /*
772 * for the first part of UU or XX messages, print a begin line 907 * for the first part of UU or XX messages, print a begin line
773 */ 908 */
909
774 if (encoding == UU_ENCODED || encoding == XX_ENCODED) { 910 if (encoding == UU_ENCODED || encoding == XX_ENCODED) {
775 fprintf (outfile, "begin %o %s%s", 911 fprintf (outfile, "begin %o %s%s",
776 (themode) ? themode : ((filemode)?filemode:0644), 912 (themode) ? themode : ((filemode)?filemode:0644),
777 UUFNameFilter ((outfname)?outfname:infname), eolstring); 913 UUFNameFilter ((outfname)?outfname:infname), eolstring);
914 }
915 }
916 if (encoding == YENC_ENCODED) {
917 pcrc = crc32(0L, Z_NULL, 0);
918 pcrcptr = &pcrc;
919 if (numparts != 1) {
920 if (progress.totsize == -1) {
921 fprintf (outfile, "=ybegin part=%d line=128 name=%s%s",
922 partno,
923 UUFNameFilter ((outfname)?outfname:infname),
924 eolstring);
925 }
926 else {
927 fprintf (outfile, "=ybegin part=%d line=128 size=%ld name=%s%s",
928 partno,
929 progress.totsize,
930 UUFNameFilter ((outfname)?outfname:infname),
931 eolstring);
932 }
933
934 fprintf (outfile, "=ypart begin=%d end=%d%s",
935 (partno-1)*linperfile*128+1,
936 (partno*linperfile*128) < progress.totsize ?
937 (partno*linperfile*128) : progress.totsize,
938 eolstring);
939 }
940 else {
941 if (progress.totsize == -1) {
942 fprintf (outfile, "=ybegin line=128 name=%s%s",
943 UUFNameFilter ((outfname)?outfname:infname),
944 eolstring);
945 }
946 else {
947 fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s",
948 progress.totsize,
949 UUFNameFilter ((outfname)?outfname:infname),
950 eolstring);
951 }
778 } 952 }
779 } 953 }
780 954
781 /* 955 /*
782 * update progress information 956 * update progress information
795 else 969 else
796 progress.fsize = linperfile*bpl[encoding]; 970 progress.fsize = linperfile*bpl[encoding];
797 971
798 progress.action = UUACT_ENCODING; 972 progress.action = UUACT_ENCODING;
799 973
800 if ((res = UUEncodeStream (outfile, theifile, 974 if ((res = UUEncodeStream (outfile, theifile, encoding, linperfile,
801 encoding, linperfile)) != UURET_OK) { 975 crcptr, pcrcptr)) != UURET_OK) {
802 if (infile==NULL) fclose (theifile); 976 if (infile==NULL) fclose (theifile);
803 if (res != UURET_CANCEL) { 977 if (res != UURET_CANCEL) {
804 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 978 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
805 uustring (S_ERR_ENCODING), 979 uustring (S_ERR_ENCODING),
806 UUFNameFilter ((outfname)?outfname:infname), 980 UUFNameFilter ((outfname)?outfname:infname),
807 (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res)); 981 (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res));
808 } 982 }
809 progress.action = 0; 983 progress.action = 0;
810 return res; 984 return res;
811 } 985 }
986
812 /* 987 /*
813 * print end line 988 * print end line
814 */ 989 */
990
815 if (feof (theifile) && 991 if (feof (theifile) &&
816 (encoding == UU_ENCODED || encoding == XX_ENCODED)) { 992 (encoding == UU_ENCODED || encoding == XX_ENCODED)) {
817 fprintf (outfile, "%c%s", 993 fprintf (outfile, "%c%s",
818 (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0], 994 (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0],
819 eolstring); 995 eolstring);
820 fprintf (outfile, "end%s", eolstring); 996 fprintf (outfile, "end%s", eolstring);
997 }
998 else if (encoding == YENC_ENCODED) {
999 if (numparts != 1) {
1000 fprintf (outfile, "=yend size=%d part=%d pcrc32=%08lx",
1001 (partno*linperfile*128) < progress.totsize ?
1002 linperfile*128 : (progress.totsize-(partno-1)*linperfile*128),
1003 partno,
1004 pcrc);
1005 }
1006 else {
1007 fprintf (outfile, "=yend size=%d",
1008 progress.totsize);
1009 }
1010 if (feof (theifile))
1011 fprintf (outfile, " crc32=%08lx", *crcptr);
1012 fprintf (outfile, "%s", eolstring);
821 } 1013 }
822 1014
823 /* 1015 /*
824 * empty line at end does no harm 1016 * empty line at end does no harm
825 */ 1017 */
860{ 1052{
861 struct stat finfo; 1053 struct stat finfo;
862 FILE *theifile; 1054 FILE *theifile;
863 int themode; 1055 int themode;
864 int res; 1056 int res;
1057 crc32_t crc;
1058 crc32_t *crcptr=NULL;
865 1059
866 if (outfile==NULL || 1060 if (outfile==NULL ||
867 (infile == NULL&&infname==NULL) || 1061 (infile == NULL&&infname==NULL) ||
868 (outfname==NULL&&infname==NULL) || 1062 (outfname==NULL&&infname==NULL) ||
869 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& 1063 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
870 encoding!=PT_ENCODED&&encoding!=QP_ENCODED)) { 1064 encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) {
871 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1065 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
872 uustring (S_PARM_CHECK), "UUEncodeToStream()"); 1066 uustring (S_PARM_CHECK), "UUEncodeToStream()");
873 return UURET_ILLVAL; 1067 return UURET_ILLVAL;
874 } 1068 }
875 1069
902 progress.fsize = (long) finfo.st_size; 1096 progress.fsize = (long) finfo.st_size;
903 } 1097 }
904 theifile = infile; 1098 theifile = infile;
905 } 1099 }
906 1100
907 if (progress.fsize <= 0) 1101 if (progress.fsize < 0)
908 progress.fsize = -1; 1102 progress.fsize = -1;
909 1103
910 FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256); 1104 _FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256);
911 1105
912 progress.partno = 1; 1106 progress.partno = 1;
913 progress.numparts = 1; 1107 progress.numparts = 1;
914 progress.percent = 0; 1108 progress.percent = 0;
915 progress.foffset = 0; 1109 progress.foffset = 0;
919 fprintf (outfile, "begin %o %s%s", 1113 fprintf (outfile, "begin %o %s%s",
920 (themode) ? themode : 0644, 1114 (themode) ? themode : 0644,
921 UUFNameFilter ((outfname)?outfname:infname), 1115 UUFNameFilter ((outfname)?outfname:infname),
922 eolstring); 1116 eolstring);
923 } 1117 }
1118 else if (encoding == YENC_ENCODED) {
1119 crc = crc32(0L, Z_NULL, 0);
1120 crcptr = &crc;
1121 if (progress.fsize == -1) {
1122 fprintf (outfile, "=ybegin line=128 name=%s%s",
1123 UUFNameFilter ((outfname)?outfname:infname),
1124 eolstring);
1125 }
1126 else {
1127 fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s",
1128 progress.fsize,
1129 UUFNameFilter ((outfname)?outfname:infname),
1130 eolstring);
1131 }
1132 }
1133
924 if ((res = UUEncodeStream (outfile, theifile, encoding, 0)) != UURET_OK) { 1134 if ((res = UUEncodeStream (outfile, theifile, encoding, 0, crcptr, NULL)) != UURET_OK) {
925 if (res != UURET_CANCEL) { 1135 if (res != UURET_CANCEL) {
926 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1136 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
927 uustring (S_ERR_ENCODING), 1137 uustring (S_ERR_ENCODING),
928 UUFNameFilter ((infname)?infname:outfname), 1138 UUFNameFilter ((infname)?infname:outfname),
929 (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res)); 1139 (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res));
930 } 1140 }
931 progress.action = 0; 1141 progress.action = 0;
932 return res; 1142 return res;
933 } 1143 }
1144
934 if (encoding == UU_ENCODED || encoding == XX_ENCODED) { 1145 if (encoding == UU_ENCODED || encoding == XX_ENCODED) {
935 fprintf (outfile, "%c%s", 1146 fprintf (outfile, "%c%s",
936 (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0], 1147 (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0],
937 eolstring); 1148 eolstring);
938 fprintf (outfile, "end%s", eolstring); 1149 fprintf (outfile, "end%s", eolstring);
939 } 1150 }
1151 else if (encoding == YENC_ENCODED) {
1152 if (progress.fsize == -1) {
1153 fprintf (outfile, "=yend crc32=%08lx%s",
1154 crc,
1155 eolstring);
1156 }
1157 else {
1158 fprintf (outfile, "=yend size=%ld crc32=%08lx%s",
1159 progress.fsize,
1160 crc,
1161 eolstring);
1162 }
1163 }
1164
940 /* 1165 /*
941 * empty line at end does no harm 1166 * empty line at end does no harm
942 */ 1167 */
1168
943 fprintf (outfile, "%s", eolstring); 1169 fprintf (outfile, "%s", eolstring);
944 1170
945 if (infile==NULL) fclose (theifile); 1171 if (infile==NULL) fclose (theifile);
946 progress.action = 0; 1172 progress.action = 0;
947 1173
958{ 1184{
959 int part, numparts, len, filemode, res; 1185 int part, numparts, len, filemode, res;
960 char *oname=NULL, *optr, *ptr; 1186 char *oname=NULL, *optr, *ptr;
961 FILE *theifile, *outfile; 1187 FILE *theifile, *outfile;
962 struct stat finfo; 1188 struct stat finfo;
1189 crc32_t pcrc, crc;
1190 crc32_t *pcrcptr=NULL, *crcptr=NULL;
963 1191
964 if ((diskname==NULL&&infname==NULL) || 1192 if ((diskname==NULL&&infname==NULL) ||
965 (outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) || 1193 (outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) ||
966 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& 1194 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
967 encoding!=PT_ENCODED&&encoding!=QP_ENCODED)) { 1195 encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) {
968 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1196 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
969 uustring (S_PARM_CHECK), "UUEncodeToFile()"); 1197 uustring (S_PARM_CHECK), "UUEncodeToFile()");
970 return UURET_ILLVAL; 1198 return UURET_ILLVAL;
971 } 1199 }
972 1200
1014 /* 1242 /*
1015 * optr points after the last dot, so that we can print the part number 1243 * optr points after the last dot, so that we can print the part number
1016 * there. 1244 * there.
1017 */ 1245 */
1018 1246
1019 optr = FP_strrchr (oname, '.'); 1247 optr = _FP_strrchr (oname, '.');
1020 if (optr==NULL || strchr (optr, '/')!=NULL || strchr (optr, '\\')!=NULL) { 1248 if (optr==NULL || strchr (optr, '/')!=NULL || strchr (optr, '\\')!=NULL) {
1021 optr = oname + strlen (oname); 1249 optr = oname + strlen (oname);
1022 *optr++ = '.'; 1250 *optr++ = '.';
1023 } 1251 }
1024 else if (optr==oname || *(optr-1)=='/' || *(optr-1)=='\\') { 1252 else if (optr==oname || *(optr-1)=='/' || *(optr-1)=='\\') {
1033 if (infile==NULL) { 1261 if (infile==NULL) {
1034 if (stat (infname, &finfo) == -1) { 1262 if (stat (infname, &finfo) == -1) {
1035 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1263 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
1036 uustring (S_NOT_STAT_FILE), 1264 uustring (S_NOT_STAT_FILE),
1037 infname, strerror (uu_errno=errno)); 1265 infname, strerror (uu_errno=errno));
1038 FP_free (oname); 1266 _FP_free (oname);
1039 return UURET_IOERR; 1267 return UURET_IOERR;
1040 } 1268 }
1041 if ((theifile = fopen (infname, "rb")) == NULL) { 1269 if ((theifile = fopen (infname, "rb")) == NULL) {
1042 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1270 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
1043 uustring (S_NOT_OPEN_FILE), 1271 uustring (S_NOT_OPEN_FILE),
1044 infname, strerror (uu_errno=errno)); 1272 infname, strerror (uu_errno=errno));
1045 FP_free (oname); 1273 _FP_free (oname);
1046 return UURET_IOERR; 1274 return UURET_IOERR;
1047 } 1275 }
1048 if (linperfile <= 0) 1276 if (linperfile <= 0)
1049 numparts = 1; 1277 numparts = 1;
1050 else 1278 else
1072 progress.totsize = -1; 1300 progress.totsize = -1;
1073 } 1301 }
1074 theifile = infile; 1302 theifile = infile;
1075 } 1303 }
1076 1304
1077 FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256); 1305 _FP_strncpy (progress.curfile, (outfname)?outfname:infname, 256);
1078 1306
1079 progress.totsize = (progress.totsize<=0) ? -1 : progress.totsize; 1307 progress.totsize = (progress.totsize<0) ? -1 : progress.totsize;
1080 progress.numparts = numparts; 1308 progress.numparts = numparts;
1081 1309
1082 for (part=1; !feof (theifile); part++) { 1310 for (part=1; !feof (theifile); part++) {
1083 /* 1311 /*
1084 * Attach extension 1312 * Attach extension
1130 if (infile==NULL) fclose (theifile); 1358 if (infile==NULL) fclose (theifile);
1131 progress.action = 0; 1359 progress.action = 0;
1132 free (oname); 1360 free (oname);
1133 return UURET_IOERR; 1361 return UURET_IOERR;
1134 } 1362 }
1363
1364 if (encoding != YENC_ENCODED) {
1135 fprintf (outfile, "%s", eolstring); 1365 fprintf (outfile, "%s", eolstring);
1136 fprintf (outfile, "_=_ %s", eolstring); 1366 fprintf (outfile, "_=_ %s", eolstring);
1137 if (numparts == -1) 1367 if (numparts == -1)
1138 fprintf (outfile, "_=_ Part %03d of file %s%s", 1368 fprintf (outfile, "_=_ Part %03d of file %s%s",
1139 part, UUFNameFilter ((outfname)?outfname:infname), 1369 part, UUFNameFilter ((outfname)?outfname:infname),
1140 eolstring); 1370 eolstring);
1141 else 1371 else
1142 fprintf (outfile, "_=_ Part %03d of %03d of file %s%s", 1372 fprintf (outfile, "_=_ Part %03d of %03d of file %s%s",
1143 part, numparts, 1373 part, numparts,
1144 UUFNameFilter ((outfname)?outfname:infname), 1374 UUFNameFilter ((outfname)?outfname:infname),
1145 eolstring); 1375 eolstring);
1146 fprintf (outfile, "_=_ %s", eolstring); 1376 fprintf (outfile, "_=_ %s", eolstring);
1147 fprintf (outfile, "%s", eolstring); 1377 fprintf (outfile, "%s", eolstring);
1378 }
1148 1379
1149 if (part==1 && (encoding == UU_ENCODED || encoding == XX_ENCODED)) { 1380 if (part==1 && (encoding == UU_ENCODED || encoding == XX_ENCODED)) {
1150 fprintf (outfile, "begin %o %s%s", 1381 fprintf (outfile, "begin %o %s%s",
1151 (filemode)?filemode : 0644, 1382 (filemode)?filemode : 0644,
1152 UUFNameFilter ((outfname)?outfname:infname), 1383 UUFNameFilter ((outfname)?outfname:infname),
1153 eolstring); 1384 eolstring);
1154 } 1385 }
1386 else if (encoding == YENC_ENCODED) {
1387 if (!crcptr) {
1388 crc = crc32(0L, Z_NULL, 0);
1389 crcptr = &crc;
1390 }
1391 pcrc = crc32(0L, Z_NULL, 0);
1392 pcrcptr = &pcrc;
1393 if (numparts != 1) {
1394 if (progress.totsize == -1) {
1395 fprintf (outfile, "=ybegin part=%d line=128 name=%s%s",
1396 part,
1397 UUFNameFilter ((outfname)?outfname:infname),
1398 eolstring);
1399 }
1400 else {
1401 fprintf (outfile, "=ybegin part=%d line=128 size=%ld name=%s%s",
1402 part,
1403 progress.totsize,
1404 UUFNameFilter ((outfname)?outfname:infname),
1405 eolstring);
1406 }
1407
1408 fprintf (outfile, "=ypart begin=%d end=%d%s",
1409 (part-1)*linperfile*128+1,
1410 (part*linperfile*128) < progress.totsize ?
1411 (part*linperfile*128) : progress.totsize,
1412 eolstring);
1413 }
1414 else {
1415 if (progress.totsize == -1) {
1416 fprintf (outfile, "=ybegin line=128 name=%s%s",
1417 UUFNameFilter ((outfname)?outfname:infname),
1418 eolstring);
1419 }
1420 else {
1421 fprintf (outfile, "=ybegin line=128 size=%ld name=%s%s",
1422 progress.totsize,
1423 UUFNameFilter ((outfname)?outfname:infname),
1424 eolstring);
1425 }
1426 }
1427 }
1428
1155 if ((res = UUEncodeStream (outfile, theifile, 1429 if ((res = UUEncodeStream (outfile, theifile,
1156 encoding, linperfile)) != UURET_OK) { 1430 encoding, linperfile, crcptr, pcrcptr)) != UURET_OK) {
1157 if (res != UURET_CANCEL) { 1431 if (res != UURET_CANCEL) {
1158 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1432 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
1159 uustring (S_ERR_ENCODING), 1433 uustring (S_ERR_ENCODING),
1160 UUFNameFilter ((infname)?infname:outfname), 1434 UUFNameFilter ((infname)?infname:outfname),
1161 (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res)); 1435 (res==UURET_IOERR)?strerror(uu_errno):UUstrerror (res));
1162 } 1436 }
1163 if (infile==NULL) fclose (theifile); 1437 if (infile==NULL) fclose (theifile);
1164 progress.action = 0; 1438 progress.action = 0;
1165 fclose (outfile); 1439 fclose (outfile);
1166 unlink (oname); 1440 unlink (oname);
1167 FP_free (oname); 1441 _FP_free (oname);
1168 return res; 1442 return res;
1169 } 1443 }
1444
1170 if (feof (theifile) && 1445 if (feof (theifile) &&
1171 (encoding == UU_ENCODED || encoding == XX_ENCODED)) { 1446 (encoding == UU_ENCODED || encoding == XX_ENCODED)) {
1172 fprintf (outfile, "%c%s", 1447 fprintf (outfile, "%c%s",
1173 (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0], 1448 (encoding==UU_ENCODED) ? UUEncodeTable[0] : XXEncodeTable[0],
1174 eolstring); 1449 eolstring);
1175 fprintf (outfile, "end%s", eolstring); 1450 fprintf (outfile, "end%s", eolstring);
1176 } 1451 }
1452 else if (encoding == YENC_ENCODED) {
1453 if (numparts != 1) {
1454 fprintf (outfile, "=yend size=%d part=%d pcrc32=%08lx",
1455 (part*linperfile*128) < progress.totsize ?
1456 linperfile*128 : (progress.totsize-(part-1)*linperfile*128),
1457 part,
1458 pcrc);
1459 }
1460 else {
1461 fprintf (outfile, "=yend size=%d",
1462 progress.totsize);
1463 }
1464 if (feof (theifile))
1465 fprintf (outfile, " crc32=%08lx", crc);
1466 fprintf (outfile, "%s", eolstring);
1467 }
1468
1177 /* 1469 /*
1178 * empty line at end does no harm 1470 * empty line at end does no harm
1179 */ 1471 */
1472
1180 fprintf (outfile, "%s", eolstring); 1473 fprintf (outfile, "%s", eolstring);
1181 fclose (outfile); 1474 fclose (outfile);
1182 } 1475 }
1476
1183 if (infile==NULL) fclose (theifile); 1477 if (infile==NULL) fclose (theifile);
1184 progress.action = 0; 1478 progress.action = 0;
1185 FP_free (oname); 1479 _FP_free (oname);
1186 return UURET_OK; 1480 return UURET_OK;
1187} 1481}
1188 1482
1189/* 1483/*
1190 * Encode a MIME Mail message or Newsgroup posting and send to a 1484 * Encode a MIME Mail message or Newsgroup posting and send to a
1220 char *mimetype, *ptr; 1514 char *mimetype, *ptr;
1221 int res, len; 1515 int res, len;
1222 1516
1223 if ((outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) || 1517 if ((outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) ||
1224 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& 1518 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
1225 encoding!=PT_ENCODED&&encoding!=QP_ENCODED)) { 1519 encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) {
1226 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1520 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
1227 uustring (S_PARM_CHECK), "UUE_PrepSingle()"); 1521 uustring (S_PARM_CHECK), "UUE_PrepSingle()");
1228 return UURET_ILLVAL; 1522 return UURET_ILLVAL;
1229 } 1523 }
1230 1524
1231 oname = UUFNameFilter ((outfname)?outfname:infname); 1525 oname = UUFNameFilter ((outfname)?outfname:infname);
1232 len = ((subject)?strlen(subject):0) + strlen(oname) + 40; 1526 len = ((subject)?strlen(subject):0) + strlen(oname) + 40;
1233 1527
1234 if ((ptr = FP_strrchr (oname, '.'))) { 1528 if ((ptr = _FP_strrchr (oname, '.'))) {
1235 while (miter->extension && FP_stricmp (ptr+1, miter->extension) != 0) 1529 while (miter->extension && _FP_stricmp (ptr+1, miter->extension) != 0)
1236 miter++; 1530 miter++;
1237 mimetype = miter->mimetype; 1531 mimetype = miter->mimetype;
1238 } 1532 }
1239 else 1533 else
1240 mimetype = NULL; 1534 mimetype = NULL;
1247 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1541 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
1248 uustring (S_OUT_OF_MEMORY), len); 1542 uustring (S_OUT_OF_MEMORY), len);
1249 return UURET_NOMEM; 1543 return UURET_NOMEM;
1250 } 1544 }
1251 1545
1546 if (encoding == YENC_ENCODED) {
1252 if (subject) 1547 if (subject)
1548 sprintf (subline, "- %s - %s (001/001)", oname, subject);
1549 else
1550 sprintf (subline, "- %s - (001/001)", oname);
1551 }
1552 else {
1553 if (subject)
1253 sprintf (subline, "%s (001/001) - [ %s ]", subject, oname); 1554 sprintf (subline, "%s (001/001) - [ %s ]", subject, oname);
1254 else 1555 else
1255 sprintf (subline, "[ %s ] (001/001)", oname); 1556 sprintf (subline, "[ %s ] (001/001)", oname);
1557 }
1256 1558
1257 if (from) { 1559 if (from) {
1258 fprintf (outfile, "From: %s%s", from, eolstring); 1560 fprintf (outfile, "From: %s%s", from, eolstring);
1259 } 1561 }
1260 if (destination) { 1562 if (destination) {
1267 1569
1268 if (replyto) { 1570 if (replyto) {
1269 fprintf (outfile, "Reply-To: %s%s", replyto, eolstring); 1571 fprintf (outfile, "Reply-To: %s%s", replyto, eolstring);
1270 } 1572 }
1271 1573
1574 if (encoding != YENC_ENCODED) {
1272 fprintf (outfile, "MIME-Version: 1.0%s", eolstring); 1575 fprintf (outfile, "MIME-Version: 1.0%s", eolstring);
1273 fprintf (outfile, "Content-Type: %s; name=\"%s\"%s", 1576 fprintf (outfile, "Content-Type: %s; name=\"%s\"%s",
1274 (mimetype)?mimetype:"Application/Octet-Stream", 1577 (mimetype)?mimetype:"Application/Octet-Stream",
1275 UUFNameFilter ((outfname)?outfname:infname), 1578 UUFNameFilter ((outfname)?outfname:infname),
1276 eolstring); 1579 eolstring);
1277 fprintf (outfile, "Content-Transfer-Encoding: %s%s", 1580 fprintf (outfile, "Content-Transfer-Encoding: %s%s",
1278 CTE_TYPE(encoding), eolstring); 1581 CTE_TYPE(encoding), eolstring);
1582 }
1583
1279 fprintf (outfile, "%s", eolstring); 1584 fprintf (outfile, "%s", eolstring);
1280 1585
1281 res = UUEncodeToStream (outfile, infile, infname, encoding, 1586 res = UUEncodeToStream (outfile, infile, infname, encoding,
1282 outfname, filemode); 1587 outfname, filemode);
1283 1588
1284 FP_free (subline); 1589 _FP_free (subline);
1285 return res; 1590 return res;
1286} 1591}
1287 1592
1288int UUEXPORT 1593int UUEXPORT
1289UUE_PrepPartial (FILE *outfile, FILE *infile, 1594UUE_PrepPartial (FILE *outfile, FILE *infile,
1316 static FILE *theifile; 1621 static FILE *theifile;
1317 struct stat finfo; 1622 struct stat finfo;
1318 char *subline, *oname; 1623 char *subline, *oname;
1319 long thesize; 1624 long thesize;
1320 int res, len; 1625 int res, len;
1626 static crc32_t crc;
1627 crc32_t *crcptr=NULL;
1321 1628
1322 if ((outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) || 1629 if ((outfname==NULL&&infname==NULL) || (infile==NULL&&infname==NULL) ||
1323 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&& 1630 (encoding!=UU_ENCODED&&encoding!=XX_ENCODED&&encoding!=B64ENCODED&&
1324 encoding!=PT_ENCODED&&encoding!=QP_ENCODED)) { 1631 encoding!=PT_ENCODED&&encoding!=QP_ENCODED&&encoding!=YENC_ENCODED)) {
1325 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1632 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
1326 uustring (S_PARM_CHECK), "UUE_PrepPartial()"); 1633 uustring (S_PARM_CHECK), "UUE_PrepPartial()");
1327 return UURET_ILLVAL; 1634 return UURET_ILLVAL;
1328 } 1635 }
1329 1636
1331 len = ((subject)?strlen(subject):0) + strlen (oname) + 40; 1638 len = ((subject)?strlen(subject):0) + strlen (oname) + 40;
1332 1639
1333 /* 1640 /*
1334 * if first part, get information about the file 1641 * if first part, get information about the file
1335 */ 1642 */
1643
1336 if (partno == 1) { 1644 if (partno == 1) {
1337 if (infile==NULL) { 1645 if (infile==NULL) {
1338 if (stat (infname, &finfo) == -1) { 1646 if (stat (infname, &finfo) == -1) {
1339 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR, 1647 UUMessage (uuencode_id, __LINE__, UUMSG_ERROR,
1340 uustring (S_NOT_STAT_FILE), 1648 uustring (S_NOT_STAT_FILE),
1361 if (filesize <= 0) { 1669 if (filesize <= 0) {
1362 UUMessage (uuencode_id, __LINE__, UUMSG_WARNING, 1670 UUMessage (uuencode_id, __LINE__, UUMSG_WARNING,
1363 uustring (S_STAT_ONE_PART)); 1671 uustring (S_STAT_ONE_PART));
1364 numparts = 1; 1672 numparts = 1;
1365 themode = (filemode)?filemode:0644; 1673 themode = (filemode)?filemode:0644;
1366 thesize = 0; 1674 thesize = -1;
1367 } 1675 }
1368 else { 1676 else {
1369 if (linperfile <= 0) 1677 if (linperfile <= 0)
1370 numparts = 1; 1678 numparts = 1;
1371 else 1679 else
1386 filemode = (int) finfo.st_mode & 0777; 1694 filemode = (int) finfo.st_mode & 0777;
1387 thesize = (long) finfo.st_size; 1695 thesize = (long) finfo.st_size;
1388 } 1696 }
1389 theifile = infile; 1697 theifile = infile;
1390 } 1698 }
1699
1391 /* 1700 /*
1392 * if there's one part only, don't use Message/Partial 1701 * if there's one part only, don't use Message/Partial
1393 */ 1702 */
1394 1703
1395 if (numparts == 1) { 1704 if (numparts == 1) {
1400 } 1709 }
1401 1710
1402 /* 1711 /*
1403 * we also need a unique ID 1712 * we also need a unique ID
1404 */ 1713 */
1714
1405 sprintf (mimeid, "UUDV-%ld.%ld.%s", 1715 sprintf (mimeid, "UUDV-%ld.%ld.%s",
1406 (long) time(NULL), thesize, 1716 (long) time(NULL), thesize,
1407 (strlen(oname)>16)?"oops":oname); 1717 (strlen(oname)>16)?"oops":oname);
1408 } 1718 }
1409 1719
1412 uustring (S_OUT_OF_MEMORY), len); 1722 uustring (S_OUT_OF_MEMORY), len);
1413 if (infile==NULL) fclose (theifile); 1723 if (infile==NULL) fclose (theifile);
1414 return UURET_NOMEM; 1724 return UURET_NOMEM;
1415 } 1725 }
1416 1726
1727
1728 if (encoding == YENC_ENCODED) {
1729 if (partno == 1)
1730 crc = crc32(0L, Z_NULL, 0);
1731 crcptr = &crc;
1417 if (subject) 1732 if (subject)
1733 sprintf (subline, "- %s - %s (%03d/%03d)", oname, subject,
1734 partno, numparts);
1735 else
1736 sprintf (subline, "- %s - (%03d/%03d)", oname,
1737 partno, numparts);
1738 }
1739 else {
1740 if (subject)
1418 sprintf (subline, "%s (%03d/%03d) - [ %s ]", 1741 sprintf (subline, "%s (%03d/%03d) - [ %s ]",
1419 subject, partno, numparts, oname); 1742 subject, partno, numparts, oname);
1420 else 1743 else
1421 sprintf (subline, "[ %s ] (%03d/%03d)", 1744 sprintf (subline, "[ %s ] (%03d/%03d)",
1422 oname, partno, numparts); 1745 oname, partno, numparts);
1746 }
1423 1747
1424 if (from) { 1748 if (from) {
1425 fprintf (outfile, "From: %s%s", from, eolstring); 1749 fprintf (outfile, "From: %s%s", from, eolstring);
1426 } 1750 }
1427 1751
1435 1759
1436 if (replyto) { 1760 if (replyto) {
1437 fprintf (outfile, "Reply-To: %s%s", replyto, eolstring); 1761 fprintf (outfile, "Reply-To: %s%s", replyto, eolstring);
1438 } 1762 }
1439 1763
1764 if (encoding != YENC_ENCODED) {
1440 fprintf (outfile, "MIME-Version: 1.0%s", eolstring); 1765 fprintf (outfile, "MIME-Version: 1.0%s", eolstring);
1441 fprintf (outfile, "Content-Type: Message/Partial; number=%d; total=%d;%s", 1766 fprintf (outfile, "Content-Type: Message/Partial; number=%d; total=%d;%s",
1442 partno, numparts, eolstring); 1767 partno, numparts, eolstring);
1443 fprintf (outfile, "\tid=\"%s\"%s", 1768 fprintf (outfile, "\tid=\"%s\"%s",
1444 mimeid, eolstring); 1769 mimeid, eolstring);
1770 }
1771
1445 fprintf (outfile, "%s", eolstring); 1772 fprintf (outfile, "%s", eolstring);
1446 1773
1447 res = UUEncodePartial (outfile, theifile, 1774 res = UUEncodePartial (outfile, theifile,
1448 infname, encoding, 1775 infname, encoding,
1449 (outfname)?outfname:infname, NULL, 1776 (outfname)?outfname:infname, NULL,
1450 themode, partno, linperfile); 1777 themode, partno, linperfile, crcptr);
1451 1778
1452 FP_free (subline); 1779 _FP_free (subline);
1453 1780
1454 if (infile==NULL) { 1781 if (infile==NULL) {
1455 if (res != UURET_OK) { 1782 if (res != UURET_OK) {
1456 fclose (theifile); 1783 fclose (theifile);
1457 return res; 1784 return res;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines