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 by root, Tue Aug 7 13:38:38 2001 UTC vs.
Revision 1.4 by root, Sun Mar 31 20:04:31 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 2001/08/07 13:38:38 root Exp $"; 60char * uuscan_id = "$Id: uuscan.c,v 1.4 2002/03/31 20:04:31 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.
429 } 429 }
430 else { 430 else {
431 /* 431 /*
432 * nothing interesting 432 * nothing interesting
433 */ 433 */
434 variable = NULL; 434 return theheaders;
435 } 435 }
436 436
437 /* 437 /*
438 * okay, so extract the actual data 438 * okay, so extract the actual data
439 */ 439 */
526 char *line=uuscan_sdline, *bhds1=uuscan_sdbhds1, *bhds2=uuscan_sdbhds2; 526 char *line=uuscan_sdline, *bhds1=uuscan_sdbhds1, *bhds2=uuscan_sdbhds2;
527 static char *ptr, *p2, *p3=NULL, *bhdsp, bhl; 527 static char *ptr, *p2, *p3=NULL, *bhdsp, bhl;
528 int isb64[10], isuue[10], isxxe[10], isbhx[10], iscnt; 528 int isb64[10], isuue[10], isxxe[10], isbhx[10], iscnt;
529 int cbb64, cbuue, cbxxe, cbbhx; 529 int cbb64, cbuue, cbxxe, cbbhx;
530 int bhflag=0, vflag, haddh=0, hadct=0; 530 int bhflag=0, vflag, haddh=0, hadct=0;
531 int bhrpc=0, bhnf=0, c, hcount, lcount, blen; 531 int bhrpc=0, bhnf=0, c, hcount, lcount, blen=0;
532 int encoding=0, dflag=0, ctline=42; 532 int encoding=0, dflag=0, ctline=42;
533 int dontcare=0, hadnl=0; 533 int dontcare=0, hadnl=0;
534 long preheaders, oldposition; 534 long preheaders=0, oldposition;
535 long yefilesize=0, yepartends=0;
535 size_t dcc, bhopc; 536 size_t dcc, bhopc;
536 537
537 blen = 0; preheaders = 0; /* calm down gcc */ 538 blen = 0; preheaders = 0; /* calm down gcc */
538 539
539 *errcode = UURET_OK; 540 *errcode = UURET_OK;
555 if (boundary) 556 if (boundary)
556 blen = strlen (boundary); 557 blen = strlen (boundary);
557 558
558 while (!feof (datei)) { 559 while (!feof (datei)) {
559 oldposition = ftell (datei); 560 oldposition = ftell (datei);
560 if (FP_fgets (line, 255, datei) == NULL) 561 if (FP_fgets (line, 299, datei) == NULL)
561 break; 562 break;
562 if (ferror (datei)) 563 if (ferror (datei))
563 break; 564 break;
564 565
565 line[255] = '\0'; /* For Safety of string functions */ 566 line[299] = '\0'; /* For Safety of string functions */
566 567
567 /* 568 /*
568 * Make Busy Polls 569 * Make Busy Polls
569 */ 570 */
570 571
676 result->filename[strlen(result->filename)-1] = '\0'; 677 result->filename[strlen(result->filename)-1] = '\0';
677 678
678 continue; 679 continue;
679 } 680 }
680 681
681 if ((strncmp (line, "end", 3) == 0) && result->uudet != BH_ENCODED) { 682 if ((strncmp (line, "end", 3) == 0) &&
683 result->uudet != BH_ENCODED &&
684 result->uudet != YENC_ENCODED) {
682 if (result->uudet == B64ENCODED && result->begin) 685 if (result->uudet == B64ENCODED && result->begin)
683 result->uudet = XX_ENCODED; 686 result->uudet = XX_ENCODED;
684 687
685 if (result->uudet != B64ENCODED) { 688 if (result->uudet != B64ENCODED) {
686 result->end = 1; 689 result->end = 1;
694 697
695 /* 698 /*
696 * Detect a UUDeview-Style header 699 * Detect a UUDeview-Style header
697 */ 700 */
698 701
699 if (FP_strnicmp (line, "_=_ Part ", 9) == 0) { 702 if (FP_strnicmp (line, "_=_ Part ", 9) == 0 &&
703 result->uudet != YENC_ENCODED) {
700 if (result->uudet) { 704 if (result->uudet) {
701 fseek (datei, oldposition, SEEK_SET); 705 fseek (datei, oldposition, SEEK_SET);
702 break; 706 break;
703 } 707 }
704 result->partno = atoi (line + 8); 708 result->partno = atoi (line + 8);
726 730
727 /* 731 /*
728 * Some reduced MIME handling. Only use if boundary == NULL. Also 732 * Some reduced MIME handling. Only use if boundary == NULL. Also
729 * accept the "X-Orcl-Content-Type" used by some braindead program. 733 * accept the "X-Orcl-Content-Type" used by some braindead program.
730 */ 734 */
731 if (boundary == NULL && !ismime && !uu_more_mime) { 735 if (boundary == NULL && !ismime && !uu_more_mime &&
736 result->uudet != YENC_ENCODED) {
732 if (FP_strnicmp (line, "Content-Type", 12) == 0 || 737 if (FP_strnicmp (line, "Content-Type", 12) == 0 ||
733 FP_strnicmp (line, "X-Orcl-Content-Type", 19) == 0) { 738 FP_strnicmp (line, "X-Orcl-Content-Type", 19) == 0) {
734 /* 739 /*
735 * We use Content-Type to mark a new attachment and split the file. 740 * We use Content-Type to mark a new attachment and split the file.
736 * However, we do not split if we haven't found anything encoded yet. 741 * However, we do not split if we haven't found anything encoded yet.
838 */ 843 */
839 844
840 if (boundary == NULL && !ismime && !uu_more_mime && dflag <= 1 && 845 if (boundary == NULL && !ismime && !uu_more_mime && dflag <= 1 &&
841 line[0] == '-' && line[1] == '-' && strlen(line+2)>10 && 846 line[0] == '-' && line[1] == '-' && strlen(line+2)>10 &&
842 (((ptr = FP_strrstr (line+2, "--")) == NULL) || 847 (((ptr = FP_strrstr (line+2, "--")) == NULL) ||
843 *(ptr+2) != '\012' && *(ptr+2) != '\015') && 848 (*(ptr+2) != '\012' && *(ptr+2) != '\015')) &&
844 FP_strstr (line+2, "_=_") != NULL) { 849 FP_strstr (line+2, "_=_") != NULL) {
845 if (FP_fgets (line, 255, datei) == NULL) { 850 if (FP_fgets (line, 255, datei) == NULL) {
846 break; 851 break;
847 } 852 }
848 if (FP_strnicmp (line, "Content-", 8) == 0) { 853 if (FP_strnicmp (line, "Content-", 8) == 0) {
851 * recognize the boundary on the next call and use it. 856 * recognize the boundary on the next call and use it.
852 */ 857 */
853 fseek (datei, oldposition, SEEK_SET); 858 fseek (datei, oldposition, SEEK_SET);
854 break; 859 break;
855 } 860 }
861 }
862
863 /*
864 * Detection for yEnc encoding
865 */
866
867 if (strncmp (line, "=ybegin ", 8) == 0 &&
868 FP_strstr (line, " size=") != NULL &&
869 FP_strstr (line, " name=") != NULL) {
870 if ((result->begin || result->end) && !uu_more_mime) {
871 fseek (datei, oldposition, SEEK_SET);
872 break;
873 }
874
875 /*
876 * name continues to the end of the line
877 */
878
879 FP_free (result->filename);
880 ptr = FP_strstr (line, " name=") + 6;
881 result->filename = FP_strdup (ptr);
882
883 while (isspace (result->filename[strlen(result->filename)-1]))
884 result->filename[strlen(result->filename)-1] = '\0';
885
886 /*
887 * Determine size
888 */
889
890 ptr = FP_strstr (line, " size=") + 6;
891 yefilesize = atoi (ptr);
892
893 /*
894 * check for multipart file and read =ypart line
895 */
896
897 if ((ptr = FP_strstr (line, " part=")) != NULL) {
898 result->partno = atoi (ptr + 6);
899
900 if (result->partno == 1) {
901 result->begin = 1;
902 }
903
904 if (FP_fgets (line, 255, datei) == NULL) {
905 break;
906 }
907
908 line[255] = '\0';
909
910 if (strncmp (line, "=ypart ", 7) != 0) {
911 break;
912 }
913
914 if ((ptr = FP_strstr (line, " end=")) == NULL) {
915 break;
916 }
917
918 yepartends = atoi (ptr + 5);
919 }
920 else {
921 result->partno = 1;
922 result->begin = 1;
923 }
924
925 /*
926 * Don't want auto-detection
927 */
928
929 result->uudet = YENC_ENCODED;
930 continue;
931 }
932
933 if (strncmp (line, "=yend ", 6) == 0 &&
934 result->uudet == YENC_ENCODED) {
935 if (yepartends == 0 || yepartends >= yefilesize) {
936 result->end = 1;
937 }
938 if (!uu_more_mime)
939 break;
856 } 940 }
857 941
858 /* 942 /*
859 * if we haven't yet found anything encoded, try to find something 943 * if we haven't yet found anything encoded, try to find something
860 */ 944 */
1202 /* Base64 doesn't have begin or end */ 1286 /* Base64 doesn't have begin or end */
1203 if (result->uudet == B64ENCODED) 1287 if (result->uudet == B64ENCODED)
1204 result->begin = result->end = 0; 1288 result->begin = result->end = 0;
1205 1289
1206 /* Base64 and BinHex don't have a file mode */ 1290 /* Base64 and BinHex don't have a file mode */
1207 if (result->uudet == B64ENCODED || result->uudet == BH_ENCODED) 1291 if (result->uudet == B64ENCODED || result->uudet == BH_ENCODED ||
1292 result->uudet == YENC_ENCODED)
1208 result->mode = 6*64+4*8+4; 1293 result->mode = 6*64+4*8+4;
1209 1294
1210 /* 1295 /*
1211 * When strict MIME adherance is set, throw out suspicious attachments 1296 * When strict MIME adherance is set, throw out suspicious attachments
1212 */ 1297 */
1270 1355
1271fileread * 1356fileread *
1272ScanPart (FILE *datei, char *fname, int *errcode) 1357ScanPart (FILE *datei, char *fname, int *errcode)
1273{ 1358{
1274 int ecount, hcount, lcount; 1359 int ecount, hcount, lcount;
1275 int bhflag, begflag, vflag, blen, res; 1360 int bhflag, begflag, vflag, blen=0, res;
1276 long preheaders, prevpos, preenc, before; 1361 long preheaders, prevpos=0, preenc, before;
1277 char *line=uuscan_spline; 1362 char *line=uuscan_spline;
1278 fileread *result; 1363 fileread *result;
1279 char *ptr1, *ptr2; 1364 char *ptr1, *ptr2;
1280 1365
1281 blen = 0; prevpos = 0; /* calm down gcc */ 1366 blen = 0; prevpos = 0; /* calm down gcc */
2000 /* need a restart */ 2085 /* need a restart */
2001 FP_free (result); 2086 FP_free (result);
2002 return NULL; 2087 return NULL;
2003 } 2088 }
2004 } 2089 }
2090
2005 /* 2091 /*
2006 * So this subpart is either plain text or something else. Check 2092 * So this subpart is either plain text or something else. Check
2007 * the Content-Type and Content-Transfer-Encoding. If the latter 2093 * the Content-Type and Content-Transfer-Encoding. If the latter
2008 * is a defined value, we know what to do and just copy everything 2094 * is a defined value, we know what to do and just copy everything
2009 * up to the boundary. 2095 * up to the boundary.
2012 * message to our encoding detection. Otherwise, treat as plain 2098 * message to our encoding detection. Otherwise, treat as plain
2013 * text. 2099 * text.
2014 * This is done because users might `attach' a uuencoded file, which 2100 * This is done because users might `attach' a uuencoded file, which
2015 * would then be correctly typed as `text/plain'. 2101 * would then be correctly typed as `text/plain'.
2016 */ 2102 */
2103
2017 if (FP_stristr (localenv.ctenc, "base64") != NULL) 2104 if (FP_stristr (localenv.ctenc, "base64") != NULL)
2018 result->uudet = B64ENCODED; 2105 result->uudet = B64ENCODED;
2019 else if (FP_stristr (localenv.ctenc, "x-uue") != NULL) 2106 else if (FP_stristr (localenv.ctenc, "x-uue") != NULL) {
2020 result->uudet = UU_ENCODED; 2107 result->uudet = UU_ENCODED;
2108 result->begin = result->end = 1;
2109 }
2110 else if (FP_stristr (localenv.ctenc, "x-yenc") != NULL) {
2111 result->uudet = YENC_ENCODED;
2112 result->begin = result->end = 1;
2113 }
2021 else if (FP_stristr (localenv.ctenc, "quoted-printable") != NULL) 2114 else if (FP_stristr (localenv.ctenc, "quoted-printable") != NULL)
2022 result->uudet = QP_ENCODED; 2115 result->uudet = QP_ENCODED;
2023 else if (FP_stristr (localenv.ctenc, "7bit") != NULL || 2116 else if (FP_stristr (localenv.ctenc, "7bit") != NULL ||
2024 FP_stristr (localenv.ctenc, "8bit") != NULL) 2117 FP_stristr (localenv.ctenc, "8bit") != NULL)
2025 result->uudet = PT_ENCODED; 2118 result->uudet = PT_ENCODED;
2453 2546
2454 if (FP_stristr (localenv.ctenc, "quoted-printable") != NULL) 2547 if (FP_stristr (localenv.ctenc, "quoted-printable") != NULL)
2455 result->uudet = QP_ENCODED; 2548 result->uudet = QP_ENCODED;
2456 else if (FP_stristr (localenv.ctenc, "base64") != NULL) 2549 else if (FP_stristr (localenv.ctenc, "base64") != NULL)
2457 result->uudet = B64ENCODED; 2550 result->uudet = B64ENCODED;
2458 else if (FP_stristr (localenv.ctenc, "x-uue") != NULL) 2551 else if (FP_stristr (localenv.ctenc, "x-uue") != NULL) {
2459 result->uudet = UU_ENCODED; 2552 result->uudet = UU_ENCODED;
2553 result->begin = result->end = 1;
2554 }
2555 else if (FP_stristr (localenv.ctenc, "x-yenc") != NULL) {
2556 result->uudet = YENC_ENCODED;
2557 result->begin = result->end = 1;
2558 }
2460 else if (FP_stristr (localenv.ctenc, "7bit") != NULL || 2559 else if (FP_stristr (localenv.ctenc, "7bit") != NULL ||
2461 FP_stristr (localenv.ctenc, "8bit") != NULL) 2560 FP_stristr (localenv.ctenc, "8bit") != NULL)
2462 result->uudet = PT_ENCODED; 2561 result->uudet = PT_ENCODED;
2463 else if (FP_stristr (localenv.ctype, "multipart") != NULL || 2562 else if (FP_stristr (localenv.ctype, "multipart") != NULL ||
2464 FP_stristr (localenv.ctype, "message") != NULL) 2563 FP_stristr (localenv.ctype, "message") != NULL)
2618 result->maxpno = sstate.envelope.numparts; 2717 result->maxpno = sstate.envelope.numparts;
2619 result->flags = FL_PARTIAL | 2718 result->flags = FL_PARTIAL |
2620 ((res==1 || uu_fast_scanning) ? FL_PROPER : 0) | 2719 ((res==1 || uu_fast_scanning) ? FL_PROPER : 0) |
2621 ((uu_fast_scanning) ? FL_TOEND : 0); 2720 ((uu_fast_scanning) ? FL_TOEND : 0);
2622 result->mimeid = FP_strdup (sstate.envelope.mimeid); 2721 result->mimeid = FP_strdup (sstate.envelope.mimeid);
2722 if (result->partno == 1)
2723 result->begin = 1;
2623 2724
2624 if (uu_fast_scanning) 2725 if (uu_fast_scanning)
2625 result->length = progress.fsize - result->startpos; 2726 result->length = progress.fsize - result->startpos;
2626 else 2727 else
2627 result->length = prevpos - result->startpos; 2728 result->length = prevpos - result->startpos;
2666 * text/plain or a proper Content-Transfer-Encoding. 2767 * text/plain or a proper Content-Transfer-Encoding.
2667 * We also go in here if we have an assigned filename - this means 2768 * We also go in here if we have an assigned filename - this means
2668 * that we've had a Content-Disposition field, and we should probably 2769 * that we've had a Content-Disposition field, and we should probably
2669 * decode a plain-text segment with a filename. 2770 * decode a plain-text segment with a filename.
2670 */ 2771 */
2772
2671 if (sstate.isfolder && sstate.ismime && 2773 if (sstate.isfolder && sstate.ismime &&
2672 sstate.mimestate == MS_BODY && 2774 sstate.mimestate == MS_BODY &&
2673 (FP_stristr (sstate.envelope.ctenc, "quoted-printable") != NULL || 2775 (FP_stristr (sstate.envelope.ctenc, "quoted-printable") != NULL ||
2674 FP_stristr (sstate.envelope.ctenc, "base64") != NULL || 2776 FP_stristr (sstate.envelope.ctenc, "base64") != NULL ||
2675 FP_stristr (sstate.envelope.ctenc, "x-uue") != NULL || 2777 FP_stristr (sstate.envelope.ctenc, "x-uue") != NULL ||
2778 FP_stristr (sstate.envelope.ctenc, "x-yenc") != NULL ||
2676 FP_stristr (sstate.envelope.ctype, "message") != NULL || 2779 FP_stristr (sstate.envelope.ctype, "message") != NULL ||
2677 sstate.envelope.fname != NULL)) { 2780 sstate.envelope.fname != NULL)) {
2678 2781
2679 if (sstate.envelope.subject) 2782 if (sstate.envelope.subject)
2680 result->subject = FP_strdup (sstate.envelope.subject); 2783 result->subject = FP_strdup (sstate.envelope.subject);
2688 2791
2689 if (FP_stristr (sstate.envelope.ctenc, "quoted-printable") != NULL) 2792 if (FP_stristr (sstate.envelope.ctenc, "quoted-printable") != NULL)
2690 result->uudet = QP_ENCODED; 2793 result->uudet = QP_ENCODED;
2691 else if (FP_stristr (sstate.envelope.ctenc, "base64") != NULL) 2794 else if (FP_stristr (sstate.envelope.ctenc, "base64") != NULL)
2692 result->uudet = B64ENCODED; 2795 result->uudet = B64ENCODED;
2693 else if (FP_stristr (sstate.envelope.ctenc, "x-uue") != NULL) 2796 else if (FP_stristr (sstate.envelope.ctenc, "x-uue") != NULL) {
2694 result->uudet = UU_ENCODED; 2797 result->uudet = UU_ENCODED;
2798 result->begin = result->end = 1;
2799 }
2800 else if (FP_stristr (sstate.envelope.ctenc, "x-yenc") != NULL) {
2801 result->uudet = YENC_ENCODED;
2802 }
2695 else if (FP_stristr (sstate.envelope.ctenc, "7bit") != NULL || 2803 else if (FP_stristr (sstate.envelope.ctenc, "7bit") != NULL ||
2696 FP_stristr (sstate.envelope.ctenc, "8bit") != NULL) 2804 FP_stristr (sstate.envelope.ctenc, "8bit") != NULL)
2697 result->uudet = PT_ENCODED; 2805 result->uudet = PT_ENCODED;
2698 else if (FP_stristr (sstate.envelope.ctype, "multipart") != NULL || 2806 else if (FP_stristr (sstate.envelope.ctype, "multipart") != NULL ||
2699 FP_stristr (sstate.envelope.ctype, "message") != NULL || 2807 FP_stristr (sstate.envelope.ctype, "message") != NULL ||
2917 */ 3025 */
2918 ptr1 = line+2; 3026 ptr1 = line+2;
2919 while (*ptr1 && !isspace(*ptr1)) 3027 while (*ptr1 && !isspace(*ptr1))
2920 ptr1++; 3028 ptr1++;
2921 *ptr1 = '\0'; 3029 *ptr1 = '\0';
2922 3030
2923 sstate.envelope.mimevers = FP_strdup ("1.0"); 3031 sstate.envelope.mimevers = FP_strdup ("1.0");
2924 sstate.envelope.boundary = FP_strdup (line+2); 3032 sstate.envelope.boundary = FP_strdup (line+2);
2925 3033
2926 /* 3034 /*
2927 * need restart 3035 * need restart
2928 */ 3036 */
2956 sstate.isfolder = 0; 3064 sstate.isfolder = 0;
2957 sstate.ismime = 0; 3065 sstate.ismime = 0;
2958 UUkillfread (result); 3066 UUkillfread (result);
2959 return NULL; 3067 return NULL;
2960 } 3068 }
3069
2961 /* 3070 /*
2962 * produce result 3071 * produce result
2963 */ 3072 */
3073
2964 if (result->uudet == 0 && uu_handletext) { 3074 if (result->uudet == 0 && uu_handletext) {
2965 result->startpos = before; /* display headers */ 3075 result->startpos = before; /* display headers */
2966 result->uudet = PT_ENCODED; 3076 result->uudet = PT_ENCODED;
2967 result->partno = 1; 3077 result->partno = 1;
2968 } 3078 }
2969 3079
3080 if (result->uudet == YENC_ENCODED && result->filename != NULL) {
3081 /*
3082 * prevent replacing the filename found on the =ybegin line
3083 */
3084 }
2970 if (sstate.envelope.fname) { 3085 else if (sstate.envelope.fname) {
2971 FP_free (result->filename); 3086 FP_free (result->filename);
2972 if ((result->filename = FP_strdup (sstate.envelope.fname)) == NULL) 3087 if ((result->filename = FP_strdup (sstate.envelope.fname)) == NULL)
2973 *errcode = UURET_NOMEM; 3088 *errcode = UURET_NOMEM;
2974 } 3089 }
2975 else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) && 3090 else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) &&
2979 *errcode = UURET_NOMEM; 3094 *errcode = UURET_NOMEM;
2980 } 3095 }
2981 else { 3096 else {
2982 /* assign a filename lateron */ 3097 /* assign a filename lateron */
2983 } 3098 }
3099
2984 if (result->subject == NULL) { 3100 if (result->subject == NULL) {
2985 if (sstate.envelope.subject) 3101 if (sstate.envelope.subject)
2986 result->subject = FP_strdup (sstate.envelope.subject); 3102 result->subject = FP_strdup (sstate.envelope.subject);
2987 } 3103 }
2988 3104

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines