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

Comparing Convert-UUlib/uulib/uuscan.c (file contents):
Revision 1.3.2.1 by root, Sun Mar 31 19:51:30 2002 UTC vs.
Revision 1.3.2.2 by root, Sun Mar 31 19:52:08 2002 UTC

55#include <uudeview.h> 55#include <uudeview.h>
56#include <uuint.h> 56#include <uuint.h>
57#include <fptools.h> 57#include <fptools.h>
58#include <uustring.h> 58#include <uustring.h>
59 59
60char * uuscan_id = "$Id: uuscan.c,v 1.3.2.1 2002/03/31 19:51:30 root Exp $"; 60char * uuscan_id = "$Id: uuscan.c,v 1.3.2.2 2002/03/31 19:52:08 root Exp $";
61 61
62/* 62/*
63 * Header fields we recognize as such. See RFC822. We add "From ", 63 * Header fields we recognize as such. See RFC822. We add "From ",
64 * the usual marker for a beginning of a new message, and a couple 64 * the usual marker for a beginning of a new message, and a couple
65 * of usual MDA, News and MIME headers. 65 * of usual MDA, News and MIME headers.
420 } 420 }
421 else { 421 else {
422 /* 422 /*
423 * nothing interesting 423 * nothing interesting
424 */ 424 */
425 variable = NULL; 425 return theheaders;
426 } 426 }
427 427
428 /* 428 /*
429 * okay, so extract the actual data 429 * okay, so extract the actual data
430 */ 430 */
517 char *line=uuscan_sdline, *bhds1=uuscan_sdbhds1, *bhds2=uuscan_sdbhds2; 517 char *line=uuscan_sdline, *bhds1=uuscan_sdbhds1, *bhds2=uuscan_sdbhds2;
518 static char *ptr, *p2, *p3=NULL, *bhdsp, bhl; 518 static char *ptr, *p2, *p3=NULL, *bhdsp, bhl;
519 int isb64[10], isuue[10], isxxe[10], isbhx[10], iscnt; 519 int isb64[10], isuue[10], isxxe[10], isbhx[10], iscnt;
520 int cbb64, cbuue, cbxxe, cbbhx; 520 int cbb64, cbuue, cbxxe, cbbhx;
521 int bhflag=0, vflag, haddh=0, hadct=0; 521 int bhflag=0, vflag, haddh=0, hadct=0;
522 int bhrpc=0, bhnf=0, c, hcount, lcount, blen; 522 int bhrpc=0, bhnf=0, c, hcount, lcount, blen=0;
523 int encoding=0, dflag=0, ctline=42; 523 int encoding=0, dflag=0, ctline=42;
524 int dontcare=0, hadnl=0; 524 int dontcare=0, hadnl=0;
525 long preheaders, oldposition; 525 long preheaders=0, oldposition;
526 long yefilesize=0, yepartends=0;
526 size_t dcc, bhopc; 527 size_t dcc, bhopc;
527 528
528 *errcode = UURET_OK; 529 *errcode = UURET_OK;
529 (void) UUDecodeLine (NULL, NULL, 0); /* init */ 530 (void) UUDecodeLine (NULL, NULL, 0); /* init */
530 bhdsp = bhds2; 531 bhdsp = bhds2;
544 if (boundary) 545 if (boundary)
545 blen = strlen (boundary); 546 blen = strlen (boundary);
546 547
547 while (!feof (datei)) { 548 while (!feof (datei)) {
548 oldposition = ftell (datei); 549 oldposition = ftell (datei);
549 if (_FP_fgets (line, 255, datei) == NULL) 550 if (_FP_fgets (line, 299, datei) == NULL)
550 break; 551 break;
551 if (ferror (datei)) 552 if (ferror (datei))
552 break; 553 break;
553 554
554 line[255] = '\0'; /* For Safety of string functions */ 555 line[299] = '\0'; /* For Safety of string functions */
555 556
556 /* 557 /*
557 * Make Busy Polls 558 * Make Busy Polls
558 */ 559 */
559 560
665 result->filename[strlen(result->filename)-1] = '\0'; 666 result->filename[strlen(result->filename)-1] = '\0';
666 667
667 continue; 668 continue;
668 } 669 }
669 670
670 if ((strncmp (line, "end", 3) == 0) && result->uudet != BH_ENCODED) { 671 if ((strncmp (line, "end", 3) == 0) &&
672 result->uudet != BH_ENCODED &&
673 result->uudet != YENC_ENCODED) {
671 if (result->uudet == B64ENCODED && result->begin) 674 if (result->uudet == B64ENCODED && result->begin)
672 result->uudet = XX_ENCODED; 675 result->uudet = XX_ENCODED;
673 676
674 if (result->uudet != B64ENCODED) { 677 if (result->uudet != B64ENCODED) {
675 result->end = 1; 678 result->end = 1;
683 686
684 /* 687 /*
685 * Detect a UUDeview-Style header 688 * Detect a UUDeview-Style header
686 */ 689 */
687 690
688 if (_FP_strnicmp (line, "_=_ Part ", 9) == 0) { 691 if (_FP_strnicmp (line, "_=_ Part ", 9) == 0 &&
692 result->uudet != YENC_ENCODED) {
689 if (result->uudet) { 693 if (result->uudet) {
690 fseek (datei, oldposition, SEEK_SET); 694 fseek (datei, oldposition, SEEK_SET);
691 break; 695 break;
692 } 696 }
693 result->partno = atoi (line + 8); 697 result->partno = atoi (line + 8);
715 719
716 /* 720 /*
717 * Some reduced MIME handling. Only use if boundary == NULL. Also 721 * Some reduced MIME handling. Only use if boundary == NULL. Also
718 * accept the "X-Orcl-Content-Type" used by some braindead program. 722 * accept the "X-Orcl-Content-Type" used by some braindead program.
719 */ 723 */
720 if (boundary == NULL && !ismime && !uu_more_mime) { 724 if (boundary == NULL && !ismime && !uu_more_mime &&
725 result->uudet != YENC_ENCODED) {
721 if (_FP_strnicmp (line, "Content-Type", 12) == 0 || 726 if (_FP_strnicmp (line, "Content-Type", 12) == 0 ||
722 _FP_strnicmp (line, "X-Orcl-Content-Type", 19) == 0) { 727 _FP_strnicmp (line, "X-Orcl-Content-Type", 19) == 0) {
723 /* 728 /*
724 * We use Content-Type to mark a new attachment and split the file. 729 * We use Content-Type to mark a new attachment and split the file.
725 * However, we do not split if we haven't found anything encoded yet. 730 * However, we do not split if we haven't found anything encoded yet.
827 */ 832 */
828 833
829 if (boundary == NULL && !ismime && !uu_more_mime && dflag <= 1 && 834 if (boundary == NULL && !ismime && !uu_more_mime && dflag <= 1 &&
830 line[0] == '-' && line[1] == '-' && strlen(line+2)>10 && 835 line[0] == '-' && line[1] == '-' && strlen(line+2)>10 &&
831 (((ptr = _FP_strrstr (line+2, "--")) == NULL) || 836 (((ptr = _FP_strrstr (line+2, "--")) == NULL) ||
832 *(ptr+2) != '\012' && *(ptr+2) != '\015') && 837 (*(ptr+2) != '\012' && *(ptr+2) != '\015')) &&
833 _FP_strstr (line+2, "_=_") != NULL) { 838 _FP_strstr (line+2, "_=_") != NULL) {
834 if (_FP_fgets (line, 255, datei) == NULL) { 839 if (_FP_fgets (line, 255, datei) == NULL) {
835 break; 840 break;
836 } 841 }
837 if (_FP_strnicmp (line, "Content-", 8) == 0) { 842 if (_FP_strnicmp (line, "Content-", 8) == 0) {
840 * recognize the boundary on the next call and use it. 845 * recognize the boundary on the next call and use it.
841 */ 846 */
842 fseek (datei, oldposition, SEEK_SET); 847 fseek (datei, oldposition, SEEK_SET);
843 break; 848 break;
844 } 849 }
850 }
851
852 /*
853 * Detection for yEnc encoding
854 */
855
856 if (strncmp (line, "=ybegin ", 8) == 0 &&
857 _FP_strstr (line, " size=") != NULL &&
858 _FP_strstr (line, " name=") != NULL) {
859 if ((result->begin || result->end) && !uu_more_mime) {
860 fseek (datei, oldposition, SEEK_SET);
861 break;
862 }
863
864 /*
865 * name continues to the end of the line
866 */
867
868 _FP_free (result->filename);
869 ptr = _FP_strstr (line, " name=") + 6;
870 result->filename = _FP_strdup (ptr);
871
872 while (isspace (result->filename[strlen(result->filename)-1]))
873 result->filename[strlen(result->filename)-1] = '\0';
874
875 /*
876 * Determine size
877 */
878
879 ptr = _FP_strstr (line, " size=") + 6;
880 yefilesize = atoi (ptr);
881
882 /*
883 * check for multipart file and read =ypart line
884 */
885
886 if ((ptr = _FP_strstr (line, " part=")) != NULL) {
887 result->partno = atoi (ptr + 6);
888
889 if (result->partno == 1) {
890 result->begin = 1;
891 }
892
893 if (_FP_fgets (line, 255, datei) == NULL) {
894 break;
895 }
896
897 line[255] = '\0';
898
899 if (strncmp (line, "=ypart ", 7) != 0) {
900 break;
901 }
902
903 if ((ptr = _FP_strstr (line, " end=")) == NULL) {
904 break;
905 }
906
907 yepartends = atoi (ptr + 5);
908 }
909 else {
910 result->partno = 1;
911 result->begin = 1;
912 }
913
914 /*
915 * Don't want auto-detection
916 */
917
918 result->uudet = YENC_ENCODED;
919 continue;
920 }
921
922 if (strncmp (line, "=yend ", 6) == 0 &&
923 result->uudet == YENC_ENCODED) {
924 if (yepartends == 0 || yepartends >= yefilesize) {
925 result->end = 1;
926 }
927 if (!uu_more_mime)
928 break;
845 } 929 }
846 930
847 /* 931 /*
848 * if we haven't yet found anything encoded, try to find something 932 * if we haven't yet found anything encoded, try to find something
849 */ 933 */
1191 /* Base64 doesn't have begin or end */ 1275 /* Base64 doesn't have begin or end */
1192 if (result->uudet == B64ENCODED) 1276 if (result->uudet == B64ENCODED)
1193 result->begin = result->end = 0; 1277 result->begin = result->end = 0;
1194 1278
1195 /* Base64 and BinHex don't have a file mode */ 1279 /* Base64 and BinHex don't have a file mode */
1196 if (result->uudet == B64ENCODED || result->uudet == BH_ENCODED) 1280 if (result->uudet == B64ENCODED || result->uudet == BH_ENCODED ||
1281 result->uudet == YENC_ENCODED)
1197 result->mode = 6*64+4*8+4; 1282 result->mode = 6*64+4*8+4;
1198 1283
1199 /* 1284 /*
1200 * When strict MIME adherance is set, throw out suspicious attachments 1285 * When strict MIME adherance is set, throw out suspicious attachments
1201 */ 1286 */
1259 1344
1260fileread * 1345fileread *
1261ScanPart (FILE *datei, char *fname, int *errcode) 1346ScanPart (FILE *datei, char *fname, int *errcode)
1262{ 1347{
1263 int ecount, hcount, lcount; 1348 int ecount, hcount, lcount;
1264 int bhflag, begflag, vflag, blen, res; 1349 int bhflag, begflag, vflag, blen=0, res;
1265 long preheaders, prevpos, preenc, before; 1350 long preheaders, prevpos=0, preenc, before;
1266 char *line=uuscan_spline; 1351 char *line=uuscan_spline;
1267 fileread *result; 1352 fileread *result;
1268 char *ptr1, *ptr2; 1353 char *ptr1, *ptr2;
1269 1354
1270 (void) UUDecodeLine (NULL, NULL, 0); /* init */ 1355 (void) UUDecodeLine (NULL, NULL, 0); /* init */
1986 /* need a restart */ 2071 /* need a restart */
1987 _FP_free (result); 2072 _FP_free (result);
1988 return NULL; 2073 return NULL;
1989 } 2074 }
1990 } 2075 }
2076
1991 /* 2077 /*
1992 * So this subpart is either plain text or something else. Check 2078 * So this subpart is either plain text or something else. Check
1993 * the Content-Type and Content-Transfer-Encoding. If the latter 2079 * the Content-Type and Content-Transfer-Encoding. If the latter
1994 * is a defined value, we know what to do and just copy everything 2080 * is a defined value, we know what to do and just copy everything
1995 * up to the boundary. 2081 * up to the boundary.
1998 * message to our encoding detection. Otherwise, treat as plain 2084 * message to our encoding detection. Otherwise, treat as plain
1999 * text. 2085 * text.
2000 * This is done because users might `attach' a uuencoded file, which 2086 * This is done because users might `attach' a uuencoded file, which
2001 * would then be correctly typed as `text/plain'. 2087 * would then be correctly typed as `text/plain'.
2002 */ 2088 */
2089
2003 if (_FP_stristr (localenv.ctenc, "base64") != NULL) 2090 if (_FP_stristr (localenv.ctenc, "base64") != NULL)
2004 result->uudet = B64ENCODED; 2091 result->uudet = B64ENCODED;
2005 else if (_FP_stristr (localenv.ctenc, "x-uue") != NULL) 2092 else if (_FP_stristr (localenv.ctenc, "x-uue") != NULL) {
2006 result->uudet = UU_ENCODED; 2093 result->uudet = UU_ENCODED;
2094 result->begin = result->end = 1;
2095 }
2096 else if (_FP_stristr (localenv.ctenc, "x-yenc") != NULL) {
2097 result->uudet = YENC_ENCODED;
2098 result->begin = result->end = 1;
2099 }
2007 else if (_FP_stristr (localenv.ctenc, "quoted-printable") != NULL) 2100 else if (_FP_stristr (localenv.ctenc, "quoted-printable") != NULL)
2008 result->uudet = QP_ENCODED; 2101 result->uudet = QP_ENCODED;
2009 else if (_FP_stristr (localenv.ctenc, "7bit") != NULL || 2102 else if (_FP_stristr (localenv.ctenc, "7bit") != NULL ||
2010 _FP_stristr (localenv.ctenc, "8bit") != NULL) 2103 _FP_stristr (localenv.ctenc, "8bit") != NULL)
2011 result->uudet = PT_ENCODED; 2104 result->uudet = PT_ENCODED;
2439 2532
2440 if (_FP_stristr (localenv.ctenc, "quoted-printable") != NULL) 2533 if (_FP_stristr (localenv.ctenc, "quoted-printable") != NULL)
2441 result->uudet = QP_ENCODED; 2534 result->uudet = QP_ENCODED;
2442 else if (_FP_stristr (localenv.ctenc, "base64") != NULL) 2535 else if (_FP_stristr (localenv.ctenc, "base64") != NULL)
2443 result->uudet = B64ENCODED; 2536 result->uudet = B64ENCODED;
2444 else if (_FP_stristr (localenv.ctenc, "x-uue") != NULL) 2537 else if (_FP_stristr (localenv.ctenc, "x-uue") != NULL) {
2445 result->uudet = UU_ENCODED; 2538 result->uudet = UU_ENCODED;
2539 result->begin = result->end = 1;
2540 }
2541 else if (_FP_stristr (localenv.ctenc, "x-yenc") != NULL) {
2542 result->uudet = YENC_ENCODED;
2543 result->begin = result->end = 1;
2544 }
2446 else if (_FP_stristr (localenv.ctenc, "7bit") != NULL || 2545 else if (_FP_stristr (localenv.ctenc, "7bit") != NULL ||
2447 _FP_stristr (localenv.ctenc, "8bit") != NULL) 2546 _FP_stristr (localenv.ctenc, "8bit") != NULL)
2448 result->uudet = PT_ENCODED; 2547 result->uudet = PT_ENCODED;
2449 else if (_FP_stristr (localenv.ctype, "multipart") != NULL || 2548 else if (_FP_stristr (localenv.ctype, "multipart") != NULL ||
2450 _FP_stristr (localenv.ctype, "message") != NULL) 2549 _FP_stristr (localenv.ctype, "message") != NULL)
2604 result->maxpno = sstate.envelope.numparts; 2703 result->maxpno = sstate.envelope.numparts;
2605 result->flags = FL_PARTIAL | 2704 result->flags = FL_PARTIAL |
2606 ((res==1 || uu_fast_scanning) ? FL_PROPER : 0) | 2705 ((res==1 || uu_fast_scanning) ? FL_PROPER : 0) |
2607 ((uu_fast_scanning) ? FL_TOEND : 0); 2706 ((uu_fast_scanning) ? FL_TOEND : 0);
2608 result->mimeid = _FP_strdup (sstate.envelope.mimeid); 2707 result->mimeid = _FP_strdup (sstate.envelope.mimeid);
2708 if (result->partno == 1)
2709 result->begin = 1;
2609 2710
2610 if (uu_fast_scanning) 2711 if (uu_fast_scanning)
2611 result->length = progress.fsize - result->startpos; 2712 result->length = progress.fsize - result->startpos;
2612 else 2713 else
2613 result->length = prevpos - result->startpos; 2714 result->length = prevpos - result->startpos;
2652 * text/plain or a proper Content-Transfer-Encoding. 2753 * text/plain or a proper Content-Transfer-Encoding.
2653 * We also go in here if we have an assigned filename - this means 2754 * We also go in here if we have an assigned filename - this means
2654 * that we've had a Content-Disposition field, and we should probably 2755 * that we've had a Content-Disposition field, and we should probably
2655 * decode a plain-text segment with a filename. 2756 * decode a plain-text segment with a filename.
2656 */ 2757 */
2758
2657 if (sstate.isfolder && sstate.ismime && 2759 if (sstate.isfolder && sstate.ismime &&
2658 sstate.mimestate == MS_BODY && 2760 sstate.mimestate == MS_BODY &&
2659 (_FP_stristr (sstate.envelope.ctenc, "quoted-printable") != NULL || 2761 (_FP_stristr (sstate.envelope.ctenc, "quoted-printable") != NULL ||
2660 _FP_stristr (sstate.envelope.ctenc, "base64") != NULL || 2762 _FP_stristr (sstate.envelope.ctenc, "base64") != NULL ||
2661 _FP_stristr (sstate.envelope.ctenc, "x-uue") != NULL || 2763 _FP_stristr (sstate.envelope.ctenc, "x-uue") != NULL ||
2764 _FP_stristr (sstate.envelope.ctenc, "x-yenc") != NULL ||
2662 _FP_stristr (sstate.envelope.ctype, "message") != NULL || 2765 _FP_stristr (sstate.envelope.ctype, "message") != NULL ||
2663 sstate.envelope.fname != NULL)) { 2766 sstate.envelope.fname != NULL)) {
2664 2767
2665 if (sstate.envelope.subject) 2768 if (sstate.envelope.subject)
2666 result->subject = _FP_strdup (sstate.envelope.subject); 2769 result->subject = _FP_strdup (sstate.envelope.subject);
2674 2777
2675 if (_FP_stristr (sstate.envelope.ctenc, "quoted-printable") != NULL) 2778 if (_FP_stristr (sstate.envelope.ctenc, "quoted-printable") != NULL)
2676 result->uudet = QP_ENCODED; 2779 result->uudet = QP_ENCODED;
2677 else if (_FP_stristr (sstate.envelope.ctenc, "base64") != NULL) 2780 else if (_FP_stristr (sstate.envelope.ctenc, "base64") != NULL)
2678 result->uudet = B64ENCODED; 2781 result->uudet = B64ENCODED;
2679 else if (_FP_stristr (sstate.envelope.ctenc, "x-uue") != NULL) 2782 else if (_FP_stristr (sstate.envelope.ctenc, "x-uue") != NULL) {
2680 result->uudet = UU_ENCODED; 2783 result->uudet = UU_ENCODED;
2784 result->begin = result->end = 1;
2785 }
2786 else if (_FP_stristr (sstate.envelope.ctenc, "x-yenc") != NULL) {
2787 result->uudet = YENC_ENCODED;
2788 }
2681 else if (_FP_stristr (sstate.envelope.ctenc, "7bit") != NULL || 2789 else if (_FP_stristr (sstate.envelope.ctenc, "7bit") != NULL ||
2682 _FP_stristr (sstate.envelope.ctenc, "8bit") != NULL) 2790 _FP_stristr (sstate.envelope.ctenc, "8bit") != NULL)
2683 result->uudet = PT_ENCODED; 2791 result->uudet = PT_ENCODED;
2684 else if (_FP_stristr (sstate.envelope.ctype, "multipart") != NULL || 2792 else if (_FP_stristr (sstate.envelope.ctype, "multipart") != NULL ||
2685 _FP_stristr (sstate.envelope.ctype, "message") != NULL || 2793 _FP_stristr (sstate.envelope.ctype, "message") != NULL ||
2903 */ 3011 */
2904 ptr1 = line+2; 3012 ptr1 = line+2;
2905 while (*ptr1 && !isspace(*ptr1)) 3013 while (*ptr1 && !isspace(*ptr1))
2906 ptr1++; 3014 ptr1++;
2907 *ptr1 = '\0'; 3015 *ptr1 = '\0';
2908 3016
3017 sstate.envelope.mimevers = _FP_strdup ("1.0");
2909 sstate.envelope.boundary = _FP_strdup (line+2); 3018 sstate.envelope.boundary = _FP_strdup (line+2);
2910 3019
2911 /* 3020 /*
2912 * need restart 3021 * need restart
2913 */ 3022 */
2941 sstate.isfolder = 0; 3050 sstate.isfolder = 0;
2942 sstate.ismime = 0; 3051 sstate.ismime = 0;
2943 UUkillfread (result); 3052 UUkillfread (result);
2944 return NULL; 3053 return NULL;
2945 } 3054 }
3055
2946 /* 3056 /*
2947 * produce result 3057 * produce result
2948 */ 3058 */
3059
2949 if (result->uudet == 0 && uu_handletext) { 3060 if (result->uudet == 0 && uu_handletext) {
2950 result->startpos = before; /* display headers */ 3061 result->startpos = before; /* display headers */
2951 result->uudet = PT_ENCODED; 3062 result->uudet = PT_ENCODED;
2952 result->partno = 1; 3063 result->partno = 1;
2953 } 3064 }
2954 3065
3066 if (result->uudet == YENC_ENCODED && result->filename != NULL) {
3067 /*
3068 * prevent replacing the filename found on the =ybegin line
3069 */
3070 }
2955 if (sstate.envelope.fname) { 3071 else if (sstate.envelope.fname) {
2956 _FP_free (result->filename); 3072 _FP_free (result->filename);
2957 if ((result->filename = _FP_strdup (sstate.envelope.fname)) == NULL) 3073 if ((result->filename = _FP_strdup (sstate.envelope.fname)) == NULL)
2958 *errcode = UURET_NOMEM; 3074 *errcode = UURET_NOMEM;
2959 } 3075 }
2960 else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) && 3076 else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) &&
2964 *errcode = UURET_NOMEM; 3080 *errcode = UURET_NOMEM;
2965 } 3081 }
2966 else { 3082 else {
2967 /* assign a filename lateron */ 3083 /* assign a filename lateron */
2968 } 3084 }
3085
2969 if (result->subject == NULL) { 3086 if (result->subject == NULL) {
2970 if (sstate.envelope.subject) 3087 if (sstate.envelope.subject)
2971 result->subject = _FP_strdup (sstate.envelope.subject); 3088 result->subject = _FP_strdup (sstate.envelope.subject);
2972 } 3089 }
2973 3090

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines