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.21 by root, Sun Feb 9 15:06:43 2020 UTC vs.
Revision 1.22 by root, Thu Dec 10 22:49:15 2020 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.21 2020/02/09 15:06:43 root Exp $"; 60char * uuscan_id = "$Id: uuscan.c,v 1.22 2020/12/10 22:49:15 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.
84 LSTR ("From"), LSTR ("Sender"), LSTR ("Resent-Reply-To"), LSTR ("Resent-From"), 84 LSTR ("From"), LSTR ("Sender"), LSTR ("Resent-Reply-To"), LSTR ("Resent-From"),
85 LSTR ("Resent-Sender"), LSTR ("Date"), LSTR ("Resent-Date"), LSTR ("To"), 85 LSTR ("Resent-Sender"), LSTR ("Date"), LSTR ("Resent-Date"), LSTR ("To"),
86 LSTR ("Resent-To"), LSTR ("Cc"), LSTR ("Bcc"), LSTR ("Resent-bcc"), 86 LSTR ("Resent-To"), LSTR ("Cc"), LSTR ("Bcc"), LSTR ("Resent-bcc"),
87 LSTR ("Message-ID"), LSTR ("Resent-Message-Id"), LSTR ("In-Reply-To"), 87 LSTR ("Message-ID"), LSTR ("Resent-Message-Id"), LSTR ("In-Reply-To"),
88 LSTR ("References"), LSTR ("Keywords"), LSTR ("Subject"), LSTR ("Comments"), 88 LSTR ("References"), LSTR ("Keywords"), LSTR ("Subject"), LSTR ("Comments"),
89 89
90 LSTR ("Delivery-Date"), LSTR ("Posted-Date"), LSTR ("Received-Date"), 90 LSTR ("Delivery-Date"), LSTR ("Posted-Date"), LSTR ("Received-Date"),
91 LSTR ("Precedence"), 91 LSTR ("Precedence"),
92 92
93 LSTR ("Path"), LSTR ("Newsgroups"), LSTR ("Organization"), LSTR ("Lines"), 93 LSTR ("Path"), LSTR ("Newsgroups"), LSTR ("Organization"), LSTR ("Lines"),
94 LSTR ("NNTP-Posting-Host"), 94 LSTR ("NNTP-Posting-Host"),
95 95
96 /* knownminehaders */ 96 /* knownminehaders */
97 LSTR ("Mime-Version"), LSTR ("Content-Transfer-Encoding"), 97 LSTR ("Mime-Version"), LSTR ("Content-Transfer-Encoding"),
98 LSTR ("Content-Type"), LSTR ("Content-Disposition"), 98 LSTR ("Content-Type"), LSTR ("Content-Disposition"),
99 LSTR ("Content-Description"), LSTR ("Content-Length") 99 LSTR ("Content-Description"), LSTR ("Content-Length")
100}; 100};
101 101
102/* 102/*
103 * for MIME (plaintext) parts without filename 103 * for MIME (plaintext) parts without filename
695 } 695 }
696 else { 696 else {
697 dontcare=0; 697 dontcare=0;
698 } 698 }
699 699
700 if (boundary != NULL && 700 if (boundary != NULL &&
701 line[0] == '-' && line[1] == '-' && 701 line[0] == '-' && line[1] == '-' &&
702 strncmp (line+2, boundary, blen) == 0) { 702 strncmp (line+2, boundary, blen) == 0) {
703 fseek (datei, oldposition, SEEK_SET); 703 fseek (datei, oldposition, SEEK_SET);
704 break; 704 break;
705 } 705 }
724 result->uudet == B64ENCODED || 724 result->uudet == B64ENCODED ||
725 result->uudet == BH_ENCODED) && !uu_more_mime) { 725 result->uudet == BH_ENCODED) && !uu_more_mime) {
726 fseek (datei, oldposition, SEEK_SET); 726 fseek (datei, oldposition, SEEK_SET);
727 break; 727 break;
728 } 728 }
729 729
730 if (*line == '<') 730 if (*line == '<')
731 ptr = line + 10; 731 ptr = line + 10;
732 else 732 else
733 ptr = line + 5; 733 ptr = line + 5;
734 734
735 while (*ptr == ' ') ptr++; 735 while (*ptr == ' ') ptr++;
736 while (isdigit (*ptr)) 736 while (isdigit (*ptr))
737 result->mode = result->mode * 8 + *ptr++ - '0'; 737 result->mode = result->mode * 8 + *ptr++ - '0';
738 while (*ptr == ' ') ptr++; 738 while (*ptr == ' ') ptr++;
739 739
740 /* 740 /*
741 * We may have picked up a filename from a uuenview-style header 741 * We may have picked up a filename from a uuenview-style header
779 result->partno = atoi (line + 8); 779 result->partno = atoi (line + 8);
780 if ((ptr = _FP_stristr (line, "of file ")) != NULL) { 780 if ((ptr = _FP_stristr (line, "of file ")) != NULL) {
781 ptr += 8; 781 ptr += 8;
782 while (isspace (*ptr)) ptr++; 782 while (isspace (*ptr)) ptr++;
783 p2 = ptr; 783 p2 = ptr;
784 while (isalnum(*p2) || 784 while (isalnum(*p2) ||
785 *p2 == '.' || *p2=='_' || *p2 == '-' || 785 *p2 == '.' || *p2=='_' || *p2 == '-' ||
786 *p2 == '!' || *p2=='@' || *p2 == '$') 786 *p2 == '!' || *p2=='@' || *p2 == '$')
787 p2++; 787 p2++;
788 c = *p2; *p2 = '\0'; 788 c = *p2; *p2 = '\0';
789 if (p2 != ptr && result->filename == NULL) 789 if (p2 != ptr && result->filename == NULL)
853 result->filename = _FP_strdup (ptr+1); 853 result->filename = _FP_strdup (ptr+1);
854 *p2 = c; 854 *p2 = c;
855 } 855 }
856 else { 856 else {
857 p2 = ptr; 857 p2 = ptr;
858 while (isalnum(*p2) || 858 while (isalnum(*p2) ||
859 *p2 == '.' || *p2=='_' || *p2 == '-' || 859 *p2 == '.' || *p2=='_' || *p2 == '-' ||
860 *p2 == '!' || *p2=='@' || *p2 == '$') 860 *p2 == '!' || *p2=='@' || *p2 == '$')
861 p2++; 861 p2++;
862 c = *p2; *p2 = '\0'; 862 c = *p2; *p2 = '\0';
863 if (p2 != ptr && result->filename == NULL) 863 if (p2 != ptr && result->filename == NULL)
887 _FP_free (result->mimeid); 887 _FP_free (result->mimeid);
888 result->mimeid = _FP_strdup (ptr); 888 result->mimeid = _FP_strdup (ptr);
889 *p2 = c; 889 *p2 = c;
890 } 890 }
891 } 891 }
892 892
893 /* 893 /*
894 * Handling for very short Base64 files. 894 * Handling for very short Base64 files.
895 */ 895 */
896 if (uu_tinyb64 && !ismime && !uu_more_mime) { 896 if (uu_tinyb64 && !ismime && !uu_more_mime) {
897 if (line[0] == '-' && line[1] == '-') { 897 if (line[0] == '-' && line[1] == '-') {
898 if (dflag && (encoding==B64ENCODED || result->uudet==B64ENCODED)) { 898 if (dflag && (encoding==B64ENCODED || result->uudet==B64ENCODED)) {
919 (((ptr = _FP_strrstr (line+2, "--")) == NULL) || 919 (((ptr = _FP_strrstr (line+2, "--")) == NULL) ||
920 ptr[2]) && 920 ptr[2]) &&
921 _FP_strstr (line+2, "_=_") != NULL) { 921 _FP_strstr (line+2, "_=_") != NULL) {
922 922
923 long oldposition = ftell (datei); /* refresh oldpositition so the comment below becomes true */ 923 long oldposition = ftell (datei); /* refresh oldpositition so the comment below becomes true */
924 924
925 if (_FP_fgets (line, 1024, datei) == NULL) { 925 if (_FP_fgets (line, 1024, datei) == NULL) {
926 break; 926 break;
927 } 927 }
928 if (_FP_strnicmp (line, "Content-", 8) == 0) { 928 if (_FP_strnicmp (line, "Content-", 8) == 0) {
929 /* 929 /*
947 } 947 }
948 948
949 /* 949 /*
950 * name continues to the end of the line 950 * name continues to the end of the line
951 */ 951 */
952 952
953 ptr = _FP_strstr (line, " name=") + 6; 953 ptr = _FP_strstr (line, " name=") + 6;
954 954
955 /* newsbin pro 5.0 (at least) is braindamaged enough to put (null) here */ 955 /* newsbin pro 5.0 (at least) is braindamaged enough to put (null) here */
956 /* create something sensible, trust a windows program to fuck it up */ 956 /* create something sensible, trust a windows program to fuck it up */
957 if (strncmp (ptr, "(null)", 6)) 957 if (strncmp (ptr, "(null)", 6))
998 } 998 }
999 999
1000 if ((ptr = _FP_strstr (line, " end=")) == NULL) { 1000 if ((ptr = _FP_strstr (line, " end=")) == NULL) {
1001 break; 1001 break;
1002 } 1002 }
1003 1003
1004 yepartends = atoi (ptr + 5); 1004 yepartends = atoi (ptr + 5);
1005 } 1005 }
1006 else { 1006 else {
1007 result->partno = 1; 1007 result->partno = 1;
1008 result->begin = 1; 1008 result->begin = 1;
1295 * in the outer loop 1295 * in the outer loop
1296 */ 1296 */
1297 1297
1298 continue; 1298 continue;
1299 } 1299 }
1300 1300
1301 /* 1301 /*
1302 * Select the encoding with the best "history" 1302 * Select the encoding with the best "history"
1303 */ 1303 */
1304 1304
1305 cbb64 = isb64[(iscnt-1)%10]; 1305 cbb64 = isb64[(iscnt-1)%10];
1734 prevpos = ftell (datei); 1734 prevpos = ftell (datei);
1735 preheaders = ftell (datei); 1735 preheaders = ftell (datei);
1736 1736
1737 blen = strlen (sstate.envelope.boundary); 1737 blen = strlen (sstate.envelope.boundary);
1738 lcount = 0; 1738 lcount = 0;
1739 1739
1740 while (!feof (datei)) { 1740 while (!feof (datei)) {
1741 if (_FP_fgets (line, 1024, datei) == NULL) 1741 if (_FP_fgets (line, 1024, datei) == NULL)
1742 break; 1742 break;
1743 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 1743 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
1744 if (line[0] == '-' && line[1] == '-' && 1744 if (line[0] == '-' && line[1] == '-' &&
1912 (void) ScanHeaderLine (datei, line); 1912 (void) ScanHeaderLine (datei, line);
1913 if (hcount == 0) { 1913 if (hcount == 0) {
1914 preheaders = prevpos; 1914 preheaders = prevpos;
1915 lcount = 0; 1915 lcount = 0;
1916 } 1916 }
1917 hcount++; 1917 hcount++;
1918 lcount++; 1918 lcount++;
1919 1919
1920 if (hcount >= hlcount.restart) { 1920 if (hcount >= hlcount.restart) {
1921 /* okay, new headers */ 1921 /* okay, new headers */
1922 break; 1922 break;
2066 * evaluate its Content-Type and Content-Transfer-Encoding. If this 2066 * evaluate its Content-Type and Content-Transfer-Encoding. If this
2067 * is another Multipart/something, push the current state onto our 2067 * is another Multipart/something, push the current state onto our
2068 * stack and dive into the new environment, starting with another 2068 * stack and dive into the new environment, starting with another
2069 * preamble. 2069 * preamble.
2070 */ 2070 */
2071 2071
2072 if (sstate.ismime && sstate.mimestate == MS_SUBPART) { 2072 if (sstate.ismime && sstate.mimestate == MS_SUBPART) {
2073 memset (&localenv, 0, sizeof (headers)); 2073 memset (&localenv, 0, sizeof (headers));
2074 result->startpos = ftell (datei); 2074 result->startpos = ftell (datei);
2075 prevpos = ftell (datei); 2075 prevpos = ftell (datei);
2076 hcount = 0; 2076 hcount = 0;
2097 UUkillheaders (&(multistack[mssdepth].envelope)); 2097 UUkillheaders (&(multistack[mssdepth].envelope));
2098 _FP_free (multistack[mssdepth].source); 2098 _FP_free (multistack[mssdepth].source);
2099 } 2099 }
2100 sstate.isfolder = 0; 2100 sstate.isfolder = 0;
2101 sstate.ismime = 0; 2101 sstate.ismime = 0;
2102 2102
2103 UUkillheaders (&localenv); 2103 UUkillheaders (&localenv);
2104 *errcode = UURET_NOMEM; 2104 *errcode = UURET_NOMEM;
2105 _FP_free (result); 2105 _FP_free (result);
2106 return NULL; 2106 return NULL;
2107 } 2107 }
2108 2108
2109 /* Scan subheader. But what if there is no subheader? */ 2109 /* Scan subheader. But what if there is no subheader? */
2110 hcount = 0; 2110 hcount = 0;
2111 lcount = 0; 2111 lcount = 0;
2112 preheaders = prevpos; 2112 preheaders = prevpos;
2113 2113
2114 if (_FP_fgets (line, 1024, datei) == NULL) { 2114 if (_FP_fgets (line, 1024, datei) == NULL) {
2115 sstate.isfolder = 0; 2115 sstate.isfolder = 0;
2116 sstate.ismime = 0; 2116 sstate.ismime = 0;
2117 while (mssdepth) { 2117 while (mssdepth) {
2118 mssdepth--; 2118 mssdepth--;
2230 */ 2230 */
2231 result->startpos = ftell (datei); 2231 result->startpos = ftell (datei);
2232 prevpos = ftell (datei); 2232 prevpos = ftell (datei);
2233 blen = strlen (sstate.envelope.boundary); 2233 blen = strlen (sstate.envelope.boundary);
2234 lcount = 0; 2234 lcount = 0;
2235 2235
2236 while (!feof (datei)) { 2236 while (!feof (datei)) {
2237 if (_FP_fgets (line, 1024, datei) == NULL) 2237 if (_FP_fgets (line, 1024, datei) == NULL)
2238 break; 2238 break;
2239 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 2239 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
2240 line[255] = '\0'; 2240 line[255] = '\0';
2429 sstate.mimestate = MS_SUBPART; 2429 sstate.mimestate = MS_SUBPART;
2430 } 2430 }
2431 else { 2431 else {
2432 UUMessage (uuscan_id, __LINE__, UUMSG_WARNING, 2432 UUMessage (uuscan_id, __LINE__, UUMSG_WARNING,
2433 uustring (S_MIME_B_NOT_FOUND)); 2433 uustring (S_MIME_B_NOT_FOUND));
2434 2434
2435 while (mssdepth) { 2435 while (mssdepth) {
2436 mssdepth--; 2436 mssdepth--;
2437 UUkillheaders (&(multistack[mssdepth].envelope)); 2437 UUkillheaders (&(multistack[mssdepth].envelope));
2438 _FP_free (multistack[mssdepth].source); 2438 _FP_free (multistack[mssdepth].source);
2439 } 2439 }
2449 2449
2450 /* 2450 /*
2451 * Retry, listening to headers this time 2451 * Retry, listening to headers this time
2452 */ 2452 */
2453 fseek (datei, result->startpos, SEEK_SET); 2453 fseek (datei, result->startpos, SEEK_SET);
2454 2454
2455 UUkillfread (result); 2455 UUkillfread (result);
2456 if ((result = (fileread *) malloc (sizeof (fileread))) == NULL) { 2456 if ((result = (fileread *) malloc (sizeof (fileread))) == NULL) {
2457 *errcode = UURET_NOMEM; 2457 *errcode = UURET_NOMEM;
2458 sstate.isfolder = 0; 2458 sstate.isfolder = 0;
2459 sstate.ismime = 0; 2459 sstate.ismime = 0;
2555 2555
2556 /* 2556 /*
2557 * kill local envelope 2557 * kill local envelope
2558 */ 2558 */
2559 UUkillheaders (&localenv); 2559 UUkillheaders (&localenv);
2560 2560
2561 return result; 2561 return result;
2562 } 2562 }
2563 2563
2564 /* 2564 /*
2565 * All right, so we're not in a Multipart message. Phew, took quite 2565 * All right, so we're not in a Multipart message. Phew, took quite
2698 if (!IsLineEmpty (line)) { 2698 if (!IsLineEmpty (line)) {
2699 break; 2699 break;
2700 } 2700 }
2701 } 2701 }
2702 2702
2703 while (!feof (datei) && !IsLineEmpty (line)) { 2703 while (!feof (datei) && !IsLineEmpty (line)) {
2704 if (IsKnownHeader (line)) 2704 if (IsKnownHeader (line))
2705 hcount++; 2705 hcount++;
2706 lcount++; 2706 lcount++;
2707 if (lcount > WAITHEADER && hcount < hlcount.afternl) 2707 if (lcount > WAITHEADER && hcount < hlcount.afternl)
2708 break; 2708 break;
2799 if (sstate.envelope.subject) 2799 if (sstate.envelope.subject)
2800 result->subject = _FP_strdup (sstate.envelope.subject); 2800 result->subject = _FP_strdup (sstate.envelope.subject);
2801 } 2801 }
2802 result->partno = sstate.envelope.partno; 2802 result->partno = sstate.envelope.partno;
2803 result->maxpno = sstate.envelope.numparts; 2803 result->maxpno = sstate.envelope.numparts;
2804 result->flags = FL_PARTIAL | 2804 result->flags = FL_PARTIAL |
2805 ((res==1 || uu_fast_scanning) ? FL_PROPER : 0) | 2805 ((res==1 || uu_fast_scanning) ? FL_PROPER : 0) |
2806 ((uu_fast_scanning) ? FL_TOEND : 0); 2806 ((uu_fast_scanning) ? FL_TOEND : 0);
2807 result->mimeid = _FP_strdup (sstate.envelope.mimeid); 2807 result->mimeid = _FP_strdup (sstate.envelope.mimeid);
2808 if (result->partno == 1) 2808 if (result->partno == 1)
2809 result->begin = 1; 2809 result->begin = 1;
2828 * new headers found 2828 * new headers found
2829 */ 2829 */
2830 sstate.isfolder = 1; 2830 sstate.isfolder = 1;
2831 sstate.ismime = 0; 2831 sstate.ismime = 0;
2832 sstate.mimestate = MS_HEADERS; 2832 sstate.mimestate = MS_HEADERS;
2833 2833
2834 UUkillheaders (&sstate.envelope); 2834 UUkillheaders (&sstate.envelope);
2835 memset (&sstate.envelope, 0, sizeof (headers)); 2835 memset (&sstate.envelope, 0, sizeof (headers));
2836 } 2836 }
2837 else { 2837 else {
2838 /* 2838 /*
2931 if (!IsLineEmpty (line)) { 2931 if (!IsLineEmpty (line)) {
2932 break; 2932 break;
2933 } 2933 }
2934 } 2934 }
2935 2935
2936 while (!feof (datei) && !IsLineEmpty (line)) { 2936 while (!feof (datei) && !IsLineEmpty (line)) {
2937 if (IsKnownHeader (line)) 2937 if (IsKnownHeader (line))
2938 hcount++; 2938 hcount++;
2939 lcount++; 2939 lcount++;
2940 if (lcount > WAITHEADER && hcount < hlcount.afternl) 2940 if (lcount > WAITHEADER && hcount < hlcount.afternl)
2941 break; 2941 break;
3108 ptr1++; 3108 ptr1++;
3109 *ptr1 = '\0'; 3109 *ptr1 = '\0';
3110 3110
3111 sstate.envelope.mimevers = _FP_strdup ("1.0"); 3111 sstate.envelope.mimevers = _FP_strdup ("1.0");
3112 sstate.envelope.boundary = _FP_strdup (line+2); 3112 sstate.envelope.boundary = _FP_strdup (line+2);
3113 3113
3114 /* 3114 /*
3115 * need restart 3115 * need restart
3116 */ 3116 */
3117 3117
3118 fseek (datei, prevpos, SEEK_SET); 3118 fseek (datei, prevpos, SEEK_SET);
3119 3119
3120 _FP_free (result); 3120 _FP_free (result);
3121 return NULL; 3121 return NULL;
3122 } 3122 }
3123 } 3123 }
3124 fseek (datei, prevpos, SEEK_SET); 3124 fseek (datei, prevpos, SEEK_SET);
3136 if (sstate.envelope.from) 3136 if (sstate.envelope.from)
3137 result->origin = _FP_strdup (sstate.envelope.from); 3137 result->origin = _FP_strdup (sstate.envelope.from);
3138 3138
3139 if (sstate.envelope.ctype) 3139 if (sstate.envelope.ctype)
3140 result->mimetype = _FP_strdup (sstate.envelope.ctype); 3140 result->mimetype = _FP_strdup (sstate.envelope.ctype);
3141 3141
3142 if ((res=ScanData (datei, fname, errcode, NULL, 3142 if ((res=ScanData (datei, fname, errcode, NULL,
3143 sstate.ismime, 1, result))==-1) { 3143 sstate.ismime, 1, result))==-1) {
3144 /* oops, something went wrong */ 3144 /* oops, something went wrong */
3145 sstate.isfolder = 0; 3145 sstate.isfolder = 0;
3146 sstate.ismime = 0; 3146 sstate.ismime = 0;
3147 UUkillfread (result); 3147 UUkillfread (result);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines