… | |
… | |
15 | */ |
15 | */ |
16 | |
16 | |
17 | /* |
17 | /* |
18 | * These are very central functions of UUDeview. Here, we scan a file |
18 | * These are very central functions of UUDeview. Here, we scan a file |
19 | * and decide whether it contains encoded data or not. ScanPart() must |
19 | * and decide whether it contains encoded data or not. ScanPart() must |
20 | * be called repeatedly on the same file until feof(file). Each time, |
20 | * be called repeatedly on the same file until FP_feof(file). Each time, |
21 | * it returns information about the next part found within. |
21 | * it returns information about the next part found within. |
22 | */ |
22 | */ |
23 | |
23 | |
24 | #ifdef HAVE_CONFIG_H |
24 | #ifdef HAVE_CONFIG_H |
25 | #include "config.h" |
25 | #include "config.h" |
… | |
… | |
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 | |
60 | char * uuscan_id = "$Id: uuscan.c,v 1.22 2020/12/10 22:49:15 root Exp $"; |
60 | char * uuscan_id = "$Id: uuscan.c,v 1.23 2020/12/11 20:09:23 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. |
… | |
… | |
185 | char *ptr2, *p2, *p3; |
185 | char *ptr2, *p2, *p3; |
186 | int llength, c; |
186 | int llength, c; |
187 | long curpos; |
187 | long curpos; |
188 | |
188 | |
189 | if (initial) { |
189 | if (initial) { |
190 | _FP_strncpy (uuscan_shlline, initial, 1024); |
190 | FP_strncpy (uuscan_shlline, initial, 1024); |
191 | } else { |
191 | } else { |
192 | /* read first line */ |
192 | /* read first line */ |
193 | if (feof (datei) || ferror (datei)) |
193 | if (FP_feof (datei) || ferror (datei)) |
194 | return NULL; |
194 | return NULL; |
195 | if (_FP_fgets (uuscan_shlline, 1024, datei) == NULL) |
195 | if (FP_fgets (uuscan_shlline, 1024, datei) == NULL) |
196 | return NULL; |
196 | return NULL; |
197 | } |
197 | } |
198 | |
198 | |
199 | llength = strlen (uuscan_shlline); |
199 | llength = strlen (uuscan_shlline); |
200 | |
200 | |
… | |
… | |
204 | ptr--; llength--; |
204 | ptr--; llength--; |
205 | } |
205 | } |
206 | if (llength == 0) |
206 | if (llength == 0) |
207 | return uuscan_shlline; |
207 | return uuscan_shlline; |
208 | |
208 | |
209 | while (!feof (datei)) { |
209 | while (!FP_feof (datei)) { |
210 | c = _FP_fgetc (datei); |
210 | c = FP_getc (datei); |
211 | if (c == EOF) |
211 | if (c == EOF) |
212 | break; |
212 | break; |
213 | |
213 | |
214 | if (c != ' ' && c != '\t') |
214 | if (c != ' ' && c != '\t') |
215 | { |
215 | { |
216 | ungetc (c, datei); |
216 | ungetc (c, datei); |
217 | break; |
217 | break; |
218 | } |
218 | } |
219 | |
219 | |
220 | while (!feof (datei) && (c == ' ' || c == '\t')) |
220 | while (!FP_feof (datei) && (c == ' ' || c == '\t')) |
221 | c = _FP_fgetc (datei); |
221 | c = FP_getc (datei); |
222 | |
222 | |
223 | if (!feof (datei)) |
223 | if (!FP_feof (datei)) |
224 | ungetc (c, datei); /* push back for fgets() */ |
224 | ungetc (c, datei); /* push back for fgets() */ |
225 | else |
225 | else |
226 | break; |
226 | break; |
227 | |
227 | |
228 | /* read next line */ |
228 | /* read next line */ |
229 | curpos = ftell (datei); |
229 | curpos = ftell (datei); |
230 | if (_FP_fgets (uugen_inbuffer, 1024, datei) == NULL) |
230 | if (FP_fgets (uugen_inbuffer, 1024, datei) == NULL) |
231 | break; |
231 | break; |
232 | |
232 | |
233 | if (IsLineEmpty (uugen_inbuffer)) { /* oops */ |
233 | if (IsLineEmpty (uugen_inbuffer)) { /* oops */ |
234 | fseek (datei, curpos, SEEK_SET); |
234 | fseek (datei, curpos, SEEK_SET); |
235 | break; |
235 | break; |
236 | } |
236 | } |
237 | |
237 | |
238 | _FP_strncpy (ptr, uugen_inbuffer, 1024-llength); |
238 | FP_strncpy (ptr, uugen_inbuffer, 1024-llength); |
239 | |
239 | |
240 | c = strlen (ptr); |
240 | c = strlen (ptr); |
241 | |
241 | |
242 | /* |
242 | /* |
243 | * strip whitespace |
243 | * strip whitespace |
… | |
… | |
408 | value = 0; delimit = 0; /* calm down gcc */ |
408 | value = 0; delimit = 0; /* calm down gcc */ |
409 | |
409 | |
410 | if (line == NULL) |
410 | if (line == NULL) |
411 | return theheaders; |
411 | return theheaders; |
412 | |
412 | |
413 | if (_FP_strnicmp (line, "From:", 5) == 0) { |
413 | if (FP_strnicmp (line, "From:", 5) == 0) { |
414 | if (theheaders->from) return theheaders; |
414 | if (theheaders->from) return theheaders; |
415 | variable = &theheaders->from; |
415 | variable = &theheaders->from; |
416 | value = line+5; |
416 | value = line+5; |
417 | delimit = 0; |
417 | delimit = 0; |
418 | } |
418 | } |
419 | else if (_FP_strnicmp (line, "Subject:", 8) == 0) { |
419 | else if (FP_strnicmp (line, "Subject:", 8) == 0) { |
420 | if (theheaders->subject) return theheaders; |
420 | if (theheaders->subject) return theheaders; |
421 | variable = &theheaders->subject; |
421 | variable = &theheaders->subject; |
422 | value = line+8; |
422 | value = line+8; |
423 | delimit = 0; |
423 | delimit = 0; |
424 | } |
424 | } |
425 | else if (_FP_strnicmp (line, "To:", 3) == 0) { |
425 | else if (FP_strnicmp (line, "To:", 3) == 0) { |
426 | if (theheaders->rcpt) return theheaders; |
426 | if (theheaders->rcpt) return theheaders; |
427 | variable = &theheaders->rcpt; |
427 | variable = &theheaders->rcpt; |
428 | value = line+3; |
428 | value = line+3; |
429 | delimit = 0; |
429 | delimit = 0; |
430 | } |
430 | } |
431 | else if (_FP_strnicmp (line, "Date:", 5) == 0) { |
431 | else if (FP_strnicmp (line, "Date:", 5) == 0) { |
432 | if (theheaders->date) return theheaders; |
432 | if (theheaders->date) return theheaders; |
433 | variable = &theheaders->date; |
433 | variable = &theheaders->date; |
434 | value = line+5; |
434 | value = line+5; |
435 | delimit = 0; |
435 | delimit = 0; |
436 | } |
436 | } |
437 | else if (_FP_strnicmp (line, "Mime-Version:", 13) == 0) { |
437 | else if (FP_strnicmp (line, "Mime-Version:", 13) == 0) { |
438 | if (theheaders->mimevers) return theheaders; |
438 | if (theheaders->mimevers) return theheaders; |
439 | variable = &theheaders->mimevers; |
439 | variable = &theheaders->mimevers; |
440 | value = line+13; |
440 | value = line+13; |
441 | delimit = 0; |
441 | delimit = 0; |
442 | } |
442 | } |
443 | else if (_FP_strnicmp (line, "Content-Type:", 13) == 0) { |
443 | else if (FP_strnicmp (line, "Content-Type:", 13) == 0) { |
444 | if (theheaders->ctype) return theheaders; |
444 | if (theheaders->ctype) return theheaders; |
445 | variable = &theheaders->ctype; |
445 | variable = &theheaders->ctype; |
446 | value = line+13; |
446 | value = line+13; |
447 | delimit = ';'; |
447 | delimit = ';'; |
448 | |
448 | |
449 | /* we can probably extract more information */ |
449 | /* we can probably extract more information */ |
450 | if ((ptr = _FP_stristr (line, "boundary")) != NULL) { |
450 | if ((ptr = FP_stristr (line, "boundary")) != NULL) { |
451 | if ((thenew = ParseValue (ptr))) { |
451 | if ((thenew = ParseValue (ptr))) { |
452 | if (theheaders->boundary) free (theheaders->boundary); |
452 | if (theheaders->boundary) free (theheaders->boundary); |
453 | theheaders->boundary = _FP_strdup (thenew); |
453 | theheaders->boundary = FP_strdup (thenew); |
454 | } |
|
|
455 | } |
454 | } |
|
|
455 | } |
456 | if ((ptr = _FP_stristr (line, "name")) != NULL) { |
456 | if ((ptr = FP_stristr (line, "name")) != NULL) { |
457 | if ((thenew = ParseValue (ptr))) { |
457 | if ((thenew = ParseValue (ptr))) { |
458 | if (theheaders->fname) free (theheaders->fname); |
458 | if (theheaders->fname) free (theheaders->fname); |
459 | theheaders->fname = _FP_strdup (thenew); |
459 | theheaders->fname = FP_strdup (thenew); |
460 | } |
|
|
461 | } |
460 | } |
|
|
461 | } |
462 | if ((ptr = _FP_stristr (line, "id")) != NULL) { |
462 | if ((ptr = FP_stristr (line, "id")) != NULL) { |
463 | if ((thenew = ParseValue (ptr))) { |
463 | if ((thenew = ParseValue (ptr))) { |
464 | if (theheaders->mimeid) free (theheaders->mimeid); |
464 | if (theheaders->mimeid) free (theheaders->mimeid); |
465 | theheaders->mimeid = _FP_strdup (thenew); |
465 | theheaders->mimeid = FP_strdup (thenew); |
466 | } |
|
|
467 | } |
466 | } |
|
|
467 | } |
468 | if ((ptr = _FP_stristr (line, "number")) != NULL) { |
468 | if ((ptr = FP_stristr (line, "number")) != NULL) { |
469 | if ((thenew = ParseValue (ptr))) { |
469 | if ((thenew = ParseValue (ptr))) { |
470 | theheaders->partno = atoi (thenew); |
470 | theheaders->partno = atoi (thenew); |
471 | } |
471 | } |
472 | } |
472 | } |
473 | if ((ptr = _FP_stristr (line, "total")) != NULL) { |
473 | if ((ptr = FP_stristr (line, "total")) != NULL) { |
474 | if ((thenew = ParseValue (ptr))) { |
474 | if ((thenew = ParseValue (ptr))) { |
475 | theheaders->numparts = atoi (thenew); |
475 | theheaders->numparts = atoi (thenew); |
476 | } |
476 | } |
477 | } |
477 | } |
478 | } |
478 | } |
479 | else if (_FP_strnicmp (line, "Content-Transfer-Encoding:", 26) == 0) { |
479 | else if (FP_strnicmp (line, "Content-Transfer-Encoding:", 26) == 0) { |
480 | if (theheaders->ctenc) return theheaders; |
480 | if (theheaders->ctenc) return theheaders; |
481 | variable = &theheaders->ctenc; |
481 | variable = &theheaders->ctenc; |
482 | value = line+26; |
482 | value = line+26; |
483 | delimit = ';'; |
483 | delimit = ';'; |
484 | } |
484 | } |
485 | else if (_FP_strnicmp (line, "Content-Disposition:", 20) == 0) { |
485 | else if (FP_strnicmp (line, "Content-Disposition:", 20) == 0) { |
486 | /* |
486 | /* |
487 | * Some encoders mention the original filename as parameter to |
487 | * Some encoders mention the original filename as parameter to |
488 | * Content-Type, others as parameter to Content-Disposition. We |
488 | * Content-Type, others as parameter to Content-Disposition. We |
489 | * do prefer the first solution, but accept this situation, too. |
489 | * do prefer the first solution, but accept this situation, too. |
490 | * TODO: Read RFC1806 |
490 | * TODO: Read RFC1806 |
491 | */ |
491 | */ |
492 | if ((ptr = _FP_stristr (line, "name")) != NULL) { |
492 | if ((ptr = FP_stristr (line, "name")) != NULL) { |
493 | if (theheaders->fname == NULL && (thenew=ParseValue(ptr)) != NULL) { |
493 | if (theheaders->fname == NULL && (thenew=ParseValue(ptr)) != NULL) { |
494 | theheaders->fname = _FP_strdup (thenew); |
494 | theheaders->fname = FP_strdup (thenew); |
495 | } |
495 | } |
496 | } |
496 | } |
497 | variable = NULL; |
497 | variable = NULL; |
498 | } |
498 | } |
499 | else { |
499 | else { |
… | |
… | |
520 | while (length && isspace(*(ptr-1))) { |
520 | while (length && isspace(*(ptr-1))) { |
521 | ptr--; length--; |
521 | ptr--; length--; |
522 | } |
522 | } |
523 | *ptr = '\0'; |
523 | *ptr = '\0'; |
524 | |
524 | |
525 | if ((*variable = _FP_strdup (uuscan_phtext)) == NULL) |
525 | if ((*variable = FP_strdup (uuscan_phtext)) == NULL) |
526 | return NULL; |
526 | return NULL; |
527 | } |
527 | } |
528 | |
528 | |
529 | return theheaders; |
529 | return theheaders; |
530 | } |
530 | } |
… | |
… | |
552 | return 0; |
552 | return 0; |
553 | |
553 | |
554 | len = sep - line; /* length of part before ':' */ |
554 | len = sep - line; /* length of part before ':' */ |
555 | |
555 | |
556 | for (i = 0; i < sizeof (knownheaders) / sizeof (knownheaders [0]); ++i) |
556 | for (i = 0; i < sizeof (knownheaders) / sizeof (knownheaders [0]); ++i) |
557 | if (len == knownheaders [i].len && _FP_strnicmp (line, knownheaders [i].str, len) == 0) |
557 | if (len == knownheaders [i].len && FP_strnicmp (line, knownheaders [i].str, len) == 0) |
558 | return 1; |
558 | return 1; |
559 | |
559 | |
560 | return 0; |
560 | return 0; |
561 | } |
561 | } |
562 | |
562 | |
… | |
… | |
567 | int |
567 | int |
568 | UUScanHeader (FILE *datei, headers *envelope) |
568 | UUScanHeader (FILE *datei, headers *envelope) |
569 | { |
569 | { |
570 | char *ptr; |
570 | char *ptr; |
571 | |
571 | |
572 | while (!feof (datei)) { |
572 | while (!FP_feof (datei)) { |
573 | if ((ptr = ScanHeaderLine (datei, NULL)) == NULL) |
573 | if ((ptr = ScanHeaderLine (datei, NULL)) == NULL) |
574 | break; |
574 | break; |
575 | if (*ptr == '\0') |
575 | if (*ptr == '\0') |
576 | break; |
576 | break; |
577 | ParseHeader (envelope, ptr); |
577 | ParseHeader (envelope, ptr); |
… | |
… | |
611 | |
611 | |
612 | *errcode = UURET_OK; |
612 | *errcode = UURET_OK; |
613 | (void) UUDecodeLine (NULL, NULL, 0); /* init */ |
613 | (void) UUDecodeLine (NULL, NULL, 0); /* init */ |
614 | bhdsp = bhds2; |
614 | bhdsp = bhds2; |
615 | |
615 | |
616 | if (datei == NULL || feof (datei)) |
616 | if (datei == NULL || FP_feof (datei)) |
617 | return -1; |
617 | return -1; |
618 | |
618 | |
619 | result->startpos = ftell (datei); |
619 | result->startpos = ftell (datei); |
620 | hcount = lcount = 0; |
620 | hcount = lcount = 0; |
621 | |
621 | |
… | |
… | |
627 | iscnt = 0; |
627 | iscnt = 0; |
628 | |
628 | |
629 | if (boundary) |
629 | if (boundary) |
630 | blen = strlen (boundary); |
630 | blen = strlen (boundary); |
631 | |
631 | |
632 | while (!feof (datei)) { |
632 | while (!FP_feof (datei)) { |
633 | oldposition = ftell (datei); |
633 | oldposition = ftell (datei); |
634 | if (_FP_fgets (line, 1024, datei) == NULL) |
634 | if (FP_fgets (line, 1024, datei) == NULL) |
635 | break; |
635 | break; |
636 | if (ferror (datei)) |
636 | if (ferror (datei)) |
637 | break; |
637 | break; |
638 | |
638 | |
639 | /* |
639 | /* |
… | |
… | |
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 | } |
706 | if (boundary != NULL && line[0] == 'C' && line[1] == 'o' && |
706 | if (boundary != NULL && line[0] == 'C' && line[1] == 'o' && |
707 | _FP_strnicmp (line, "Content-Type:", 13) == 0) { |
707 | FP_strnicmp (line, "Content-Type:", 13) == 0) { |
708 | ptr = ScanHeaderLine (datei, line); |
708 | ptr = ScanHeaderLine (datei, line); |
709 | p2 = (ptr)?_FP_stristr(ptr,"boundary"):NULL; |
709 | p2 = (ptr)?FP_stristr(ptr,"boundary"):NULL; |
710 | p3 = (p2)?ParseValue(p2):NULL; |
710 | p3 = (p2)?ParseValue(p2):NULL; |
711 | |
711 | |
712 | if (p3 && strcmp (p3, boundary) == 0) { |
712 | if (p3 && strcmp (p3, boundary) == 0) { |
713 | fseek (datei, oldposition, SEEK_SET); |
713 | fseek (datei, oldposition, SEEK_SET); |
714 | break; |
714 | break; |
… | |
… | |
717 | p3 = NULL; |
717 | p3 = NULL; |
718 | } |
718 | } |
719 | } |
719 | } |
720 | |
720 | |
721 | if (strncmp (line, "begin ", 6) == 0 || |
721 | if (strncmp (line, "begin ", 6) == 0 || |
722 | _FP_strnicmp (line, "<pre>begin ", 11) == 0) { |
722 | FP_strnicmp (line, "<pre>begin ", 11) == 0) { |
723 | if ((result->begin || result->end || |
723 | if ((result->begin || result->end || |
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; |
… | |
… | |
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 |
742 | */ |
742 | */ |
743 | _FP_free (result->filename); |
743 | FP_free (result->filename); |
744 | result->filename = _FP_strdup (ptr); |
744 | result->filename = FP_strdup (ptr); |
745 | result->begin = 1; |
745 | result->begin = 1; |
746 | |
746 | |
747 | while (isspace (result->filename[strlen(result->filename)-1])) |
747 | while (isspace (result->filename[strlen(result->filename)-1])) |
748 | result->filename[strlen(result->filename)-1] = '\0'; |
748 | result->filename[strlen(result->filename)-1] = '\0'; |
749 | |
749 | |
… | |
… | |
768 | |
768 | |
769 | /* |
769 | /* |
770 | * Detect a UUDeview-Style header |
770 | * Detect a UUDeview-Style header |
771 | */ |
771 | */ |
772 | |
772 | |
773 | if (_FP_strnicmp (line, "_=_ Part ", 9) == 0 && |
773 | if (FP_strnicmp (line, "_=_ Part ", 9) == 0 && |
774 | result->uudet != YENC_ENCODED) { |
774 | result->uudet != YENC_ENCODED) { |
775 | if (result->uudet) { |
775 | if (result->uudet) { |
776 | fseek (datei, oldposition, SEEK_SET); |
776 | fseek (datei, oldposition, SEEK_SET); |
777 | break; |
777 | break; |
778 | } |
778 | } |
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) |
790 | result->filename = _FP_strdup (ptr); |
790 | result->filename = FP_strdup (ptr); |
791 | else if (p2 - ptr > 5 && strchr (ptr, '.') != NULL) { |
791 | else if (p2 - ptr > 5 && strchr (ptr, '.') != NULL) { |
792 | /* |
792 | /* |
793 | * This file name looks good, too. Let's use it |
793 | * This file name looks good, too. Let's use it |
794 | */ |
794 | */ |
795 | _FP_free (result->filename); |
795 | FP_free (result->filename); |
796 | result->filename = _FP_strdup (ptr); |
796 | result->filename = FP_strdup (ptr); |
797 | } |
797 | } |
798 | *p2 = c; |
798 | *p2 = c; |
799 | } |
799 | } |
800 | } |
800 | } |
801 | |
801 | |
… | |
… | |
803 | * Some reduced MIME handling. Only use if boundary == NULL. Also |
803 | * Some reduced MIME handling. Only use if boundary == NULL. Also |
804 | * accept the "X-Orcl-Content-Type" used by some braindead program. |
804 | * accept the "X-Orcl-Content-Type" used by some braindead program. |
805 | */ |
805 | */ |
806 | if (boundary == NULL && !ismime && !uu_more_mime && |
806 | if (boundary == NULL && !ismime && !uu_more_mime && |
807 | result->uudet != YENC_ENCODED) { |
807 | result->uudet != YENC_ENCODED) { |
808 | if (_FP_strnicmp (line, "Content-Type", 12) == 0 || |
808 | if (FP_strnicmp (line, "Content-Type", 12) == 0 || |
809 | _FP_strnicmp (line, "X-Orcl-Content-Type", 19) == 0) { |
809 | FP_strnicmp (line, "X-Orcl-Content-Type", 19) == 0) { |
810 | /* |
810 | /* |
811 | * We use Content-Type to mark a new attachment and split the file. |
811 | * We use Content-Type to mark a new attachment and split the file. |
812 | * However, we do not split if we haven't found anything encoded yet. |
812 | * However, we do not split if we haven't found anything encoded yet. |
813 | */ |
813 | */ |
814 | if (result->uudet) { |
814 | if (result->uudet) { |
… | |
… | |
820 | while (isspace (*ptr)) ptr++; |
820 | while (isspace (*ptr)) ptr++; |
821 | p2 = ptr; |
821 | p2 = ptr; |
822 | while (*p2 && !isspace (*p2) && *p2 != ';') p2++; |
822 | while (*p2 && !isspace (*p2) && *p2 != ';') p2++; |
823 | c = *p2; *p2 = '\0'; |
823 | c = *p2; *p2 = '\0'; |
824 | if (p2 != ptr) { |
824 | if (p2 != ptr) { |
825 | _FP_free (result->mimetype); |
825 | FP_free (result->mimetype); |
826 | result->mimetype = _FP_strdup (ptr); |
826 | result->mimetype = FP_strdup (ptr); |
827 | } |
827 | } |
828 | *p2 = c; |
828 | *p2 = c; |
829 | } |
829 | } |
830 | ctline=0; |
830 | ctline=0; |
831 | hadct=1; |
831 | hadct=1; |
832 | } |
832 | } |
833 | if ((ptr = _FP_stristr (line, "number=")) && ctline<4) { |
833 | if ((ptr = FP_stristr (line, "number=")) && ctline<4) { |
834 | ptr += 7; if (*ptr == '"') ptr++; |
834 | ptr += 7; if (*ptr == '"') ptr++; |
835 | result->partno = atoi (ptr); |
835 | result->partno = atoi (ptr); |
836 | } |
836 | } |
837 | if ((ptr = _FP_stristr (line, "total=")) && ctline<4) { |
837 | if ((ptr = FP_stristr (line, "total=")) && ctline<4) { |
838 | ptr += 6; if (*ptr == '"') ptr++; |
838 | ptr += 6; if (*ptr == '"') ptr++; |
839 | result->maxpno = atoi (ptr); |
839 | result->maxpno = atoi (ptr); |
840 | } |
840 | } |
841 | if ((ptr = _FP_stristr (line, "name=")) && ctline<4) { |
841 | if ((ptr = FP_stristr (line, "name=")) && ctline<4) { |
842 | ptr += 5; |
842 | ptr += 5; |
843 | while (isspace (*ptr)) ptr++; |
843 | while (isspace (*ptr)) ptr++; |
844 | if (*ptr == '"' && *(ptr+1) && (p2 = strchr (ptr+2, '"')) != NULL) { |
844 | if (*ptr == '"' && *(ptr+1) && (p2 = strchr (ptr+2, '"')) != NULL) { |
845 | c = *p2; *p2 = '\0'; |
845 | c = *p2; *p2 = '\0'; |
846 | _FP_free (result->filename); |
846 | FP_free (result->filename); |
847 | result->filename = _FP_strdup (ptr+1); |
847 | result->filename = FP_strdup (ptr+1); |
848 | *p2 = c; |
848 | *p2 = c; |
849 | } |
849 | } |
850 | else if (*ptr=='\''&&*(ptr+1)&&(p2 = strchr(ptr+2, '\'')) != NULL) { |
850 | else if (*ptr=='\''&&*(ptr+1)&&(p2 = strchr(ptr+2, '\'')) != NULL) { |
851 | c = *p2; *p2 = '\0'; |
851 | c = *p2; *p2 = '\0'; |
852 | _FP_free (result->filename); |
852 | FP_free (result->filename); |
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) |
864 | result->filename = _FP_strdup (ptr); |
864 | result->filename = FP_strdup (ptr); |
865 | else if (p2 - ptr > 5 && strchr (ptr, '.') != NULL) { |
865 | else if (p2 - ptr > 5 && strchr (ptr, '.') != NULL) { |
866 | /* |
866 | /* |
867 | * This file name looks good, too. Let's use it |
867 | * This file name looks good, too. Let's use it |
868 | */ |
868 | */ |
869 | _FP_free (result->filename); |
869 | FP_free (result->filename); |
870 | result->filename = _FP_strdup (ptr); |
870 | result->filename = FP_strdup (ptr); |
871 | } |
871 | } |
872 | *p2 = c; |
872 | *p2 = c; |
873 | } |
873 | } |
874 | } |
874 | } |
875 | if ((ptr = _FP_stristr (line, "id=")) && ctline<4) { |
875 | if ((ptr = FP_stristr (line, "id=")) && ctline<4) { |
876 | p2 = ptr += 3; |
876 | p2 = ptr += 3; |
877 | if (*p2 == '"') { |
877 | if (*p2 == '"') { |
878 | p2 = strchr (++ptr, '"'); |
878 | p2 = strchr (++ptr, '"'); |
879 | } |
879 | } |
880 | else { |
880 | else { |
… | |
… | |
882 | p2++; |
882 | p2++; |
883 | } |
883 | } |
884 | if (p2 && *p2 && p2!=ptr) { |
884 | if (p2 && *p2 && p2!=ptr) { |
885 | c = *p2; *p2 = '\0'; |
885 | c = *p2; *p2 = '\0'; |
886 | if (result->mimeid) |
886 | if (result->mimeid) |
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 | /* |
… | |
… | |
914 | * a boundary, followed by a Content-* line, try to use it. |
914 | * a boundary, followed by a Content-* line, try to use it. |
915 | */ |
915 | */ |
916 | |
916 | |
917 | if (boundary == NULL && !ismime && !uu_more_mime && dflag <= 1 && |
917 | if (boundary == NULL && !ismime && !uu_more_mime && dflag <= 1 && |
918 | line[0] == '-' && line[1] == '-' && strlen(line+2)>10 && |
918 | line[0] == '-' && line[1] == '-' && strlen(line+2)>10 && |
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 | /* |
930 | * Okay, let's do it. This breaks out of ScanData. ScanPart will |
930 | * Okay, let's do it. This breaks out of ScanData. ScanPart will |
931 | * recognize the boundary on the next call and use it. |
931 | * recognize the boundary on the next call and use it. |
932 | */ |
932 | */ |
933 | fseek (datei, oldposition, SEEK_SET); |
933 | fseek (datei, oldposition, SEEK_SET); |
… | |
… | |
938 | /* |
938 | /* |
939 | * Detection for yEnc encoding |
939 | * Detection for yEnc encoding |
940 | */ |
940 | */ |
941 | |
941 | |
942 | if (strncmp (line, "=ybegin ", 8) == 0 && |
942 | if (strncmp (line, "=ybegin ", 8) == 0 && |
943 | _FP_strstr (line, " name=") != NULL) { |
943 | FP_strstr (line, " name=") != NULL) { |
944 | if ((result->begin || result->end || result->uudet) && !uu_more_mime) { |
944 | if ((result->begin || result->end || result->uudet) && !uu_more_mime) { |
945 | fseek (datei, oldposition, SEEK_SET); |
945 | fseek (datei, oldposition, SEEK_SET); |
946 | break; |
946 | break; |
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)) |
958 | { |
958 | { |
959 | _FP_free (result->filename); |
959 | FP_free (result->filename); |
960 | result->filename = _FP_strdup (ptr); |
960 | result->filename = FP_strdup (ptr); |
961 | |
961 | |
962 | while (isspace (result->filename[strlen(result->filename)-1])) |
962 | while (isspace (result->filename[strlen(result->filename)-1])) |
963 | result->filename[strlen(result->filename)-1] = '\0'; |
963 | result->filename[strlen(result->filename)-1] = '\0'; |
964 | } |
964 | } |
965 | |
965 | |
966 | /* |
966 | /* |
967 | * Determine size |
967 | * Determine size |
968 | */ |
968 | */ |
969 | |
969 | |
970 | if ((ptr = _FP_strstr (line, " size=")) != NULL) { |
970 | if ((ptr = FP_strstr (line, " size=")) != NULL) { |
971 | ptr += 6; |
971 | ptr += 6; |
972 | result->yefilesize = atoi (ptr); |
972 | result->yefilesize = atoi (ptr); |
973 | } |
973 | } |
974 | else { |
974 | else { |
975 | result->yefilesize = -1; |
975 | result->yefilesize = -1; |
… | |
… | |
977 | |
977 | |
978 | /* |
978 | /* |
979 | * check for multipart file and read =ypart line |
979 | * check for multipart file and read =ypart line |
980 | */ |
980 | */ |
981 | |
981 | |
982 | if ((ptr = _FP_strstr (line, " part=")) != NULL) { |
982 | if ((ptr = FP_strstr (line, " part=")) != NULL) { |
983 | result->partno = atoi (ptr + 6); |
983 | result->partno = atoi (ptr + 6); |
984 | |
984 | |
985 | if (result->partno == 1) { |
985 | if (result->partno == 1) { |
986 | result->begin = 1; |
986 | result->begin = 1; |
987 | } |
987 | } |
988 | |
988 | |
989 | if ((ptr = _FP_strstr (line, " total="))) |
989 | if ((ptr = FP_strstr (line, " total="))) |
990 | result->maxpno = atoi (ptr + 7); |
990 | result->maxpno = atoi (ptr + 7); |
991 | |
991 | |
992 | if (_FP_fgets (line, 1024, datei) == NULL) { |
992 | if (FP_fgets (line, 1024, datei) == NULL) { |
993 | break; |
993 | break; |
994 | } |
994 | } |
995 | |
995 | |
996 | if (strncmp (line, "=ypart ", 7) != 0) { |
996 | if (strncmp (line, "=ypart ", 7) != 0) { |
997 | break; |
997 | break; |
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 | } |
… | |
… | |
1111 | } |
1111 | } |
1112 | if ((bhdsp-bhds2) > (int) bhds2[0] && bhds2[0]>0 && |
1112 | if ((bhdsp-bhds2) > (int) bhds2[0] && bhds2[0]>0 && |
1113 | result->filename==NULL) { |
1113 | result->filename==NULL) { |
1114 | memcpy (bhds1, bhds2+1, (int) bhds2[0]); |
1114 | memcpy (bhds1, bhds2+1, (int) bhds2[0]); |
1115 | bhds1[(int)bhds2[0]]='\0'; |
1115 | bhds1[(int)bhds2[0]]='\0'; |
1116 | result->filename = _FP_strdup (bhds1); |
1116 | result->filename = FP_strdup (bhds1); |
1117 | bhnf = 1; |
1117 | bhnf = 1; |
1118 | } |
1118 | } |
1119 | else if (bhdsp-bhds2 >= 256 && bhds2[0]>0) { |
1119 | else if (bhdsp-bhds2 >= 256 && bhds2[0]>0) { |
1120 | memcpy (bhds1, bhds2+1, 255); |
1120 | memcpy (bhds1, bhds2+1, 255); |
1121 | bhds1[255] = '\0'; |
1121 | bhds1[255] = '\0'; |
1122 | result->filename = _FP_strdup (bhds1); |
1122 | result->filename = FP_strdup (bhds1); |
1123 | bhnf = 1; |
1123 | bhnf = 1; |
1124 | } |
1124 | } |
1125 | else if (bhds2[0] <= 0) |
1125 | else if (bhds2[0] <= 0) |
1126 | bhnf = 1; |
1126 | bhnf = 1; |
1127 | } |
1127 | } |
… | |
… | |
1196 | * an "end" |
1196 | * an "end" |
1197 | */ |
1197 | */ |
1198 | |
1198 | |
1199 | hcount = lcount = 0; |
1199 | hcount = lcount = 0; |
1200 | |
1200 | |
1201 | while (!feof (datei)) { |
1201 | while (!FP_feof (datei)) { |
1202 | /* |
1202 | /* |
1203 | * Make Busy Polls |
1203 | * Make Busy Polls |
1204 | */ |
1204 | */ |
1205 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) { |
1205 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) { |
1206 | UUMessage (uuscan_id, __LINE__, UUMSG_NOTE, |
1206 | UUMessage (uuscan_id, __LINE__, UUMSG_NOTE, |
… | |
… | |
1208 | *errcode = UURET_CANCEL; |
1208 | *errcode = UURET_CANCEL; |
1209 | break; |
1209 | break; |
1210 | } |
1210 | } |
1211 | |
1211 | |
1212 | oldposition = ftell (datei); |
1212 | oldposition = ftell (datei); |
1213 | if (_FP_fgets (line, 1024, datei) == NULL) |
1213 | if (FP_fgets (line, 1024, datei) == NULL) |
1214 | break; |
1214 | break; |
1215 | if (ferror (datei)) |
1215 | if (ferror (datei)) |
1216 | break; |
1216 | break; |
1217 | |
1217 | |
1218 | /* |
1218 | /* |
… | |
… | |
1374 | } |
1374 | } |
1375 | } /* if (!uudet) */ |
1375 | } /* if (!uudet) */ |
1376 | /* |
1376 | /* |
1377 | * End of scanning loop |
1377 | * End of scanning loop |
1378 | */ |
1378 | */ |
1379 | } /* while (!feof (datei)) */ |
1379 | } /* while (!FP_feof (datei)) */ |
1380 | |
1380 | |
1381 | if (feof (datei)) |
1381 | if (FP_feof (datei)) |
1382 | oldposition = ftell (datei); |
1382 | oldposition = ftell (datei); |
1383 | |
1383 | |
1384 | if (dflag && encoding == B64ENCODED && haddh) |
1384 | if (dflag && encoding == B64ENCODED && haddh) |
1385 | result->uudet = B64ENCODED; |
1385 | result->uudet = B64ENCODED; |
1386 | else if (dflag && encoding == BH_ENCODED) |
1386 | else if (dflag && encoding == BH_ENCODED) |
… | |
… | |
1445 | if (boundary && line[0] == '-' && line[1] == '-' && |
1445 | if (boundary && line[0] == '-' && line[1] == '-' && |
1446 | strncmp (line+2, boundary, blen) == 0) |
1446 | strncmp (line+2, boundary, blen) == 0) |
1447 | return 2; |
1447 | return 2; |
1448 | else if (boundary && p3 && |
1448 | else if (boundary && p3 && |
1449 | line[0] == 'C' && line[1] == 'o' && |
1449 | line[0] == 'C' && line[1] == 'o' && |
1450 | _FP_strnicmp (line, "Content-Type:", 13) == 0 && |
1450 | FP_strnicmp (line, "Content-Type:", 13) == 0 && |
1451 | strcmp (p3, boundary) == 0) |
1451 | strcmp (p3, boundary) == 0) |
1452 | return 2; |
1452 | return 2; |
1453 | else if (IsKnownHeader (line)) |
1453 | else if (IsKnownHeader (line)) |
1454 | return 1; |
1454 | return 1; |
1455 | |
1455 | |
… | |
… | |
1469 | char *line=uuscan_spline; |
1469 | char *line=uuscan_spline; |
1470 | fileread *result; |
1470 | fileread *result; |
1471 | char *ptr1, *ptr2; |
1471 | char *ptr1, *ptr2; |
1472 | |
1472 | |
1473 | (void) UUDecodeLine (NULL, NULL, 0); /* init */ |
1473 | (void) UUDecodeLine (NULL, NULL, 0); /* init */ |
1474 | if (datei == NULL || feof (datei)) { |
1474 | if (datei == NULL || FP_feof (datei)) { |
1475 | *errcode = UURET_OK; |
1475 | *errcode = UURET_OK; |
1476 | return NULL; |
1476 | return NULL; |
1477 | } |
1477 | } |
1478 | |
1478 | |
1479 | *errcode = UURET_OK; |
1479 | *errcode = UURET_OK; |
… | |
… | |
1495 | /* mimseqno = 1; */ |
1495 | /* mimseqno = 1; */ |
1496 | |
1496 | |
1497 | while (mssdepth) { |
1497 | while (mssdepth) { |
1498 | mssdepth--; |
1498 | mssdepth--; |
1499 | UUkillheaders (&(multistack[mssdepth].envelope)); |
1499 | UUkillheaders (&(multistack[mssdepth].envelope)); |
1500 | _FP_free (multistack[mssdepth].source); |
1500 | FP_free (multistack[mssdepth].source); |
1501 | } |
1501 | } |
1502 | |
1502 | |
1503 | UUkillheaders (&sstate.envelope); |
1503 | UUkillheaders (&sstate.envelope); |
1504 | memset (&sstate.envelope, 0, sizeof (headers)); |
1504 | memset (&sstate.envelope, 0, sizeof (headers)); |
1505 | |
1505 | |
1506 | _FP_free (sstate.source); |
1506 | FP_free (sstate.source); |
1507 | if ((sstate.source = _FP_strdup (fname)) == NULL) { |
1507 | if ((sstate.source = FP_strdup (fname)) == NULL) { |
1508 | *errcode = UURET_NOMEM; |
1508 | *errcode = UURET_NOMEM; |
1509 | _FP_free (result); |
1509 | FP_free (result); |
1510 | return NULL; |
1510 | return NULL; |
1511 | } |
1511 | } |
1512 | |
1512 | |
1513 | /* ignore empty lines at the beginning of a file */ |
1513 | /* ignore empty lines at the beginning of a file */ |
1514 | preheaders = ftell (datei); |
1514 | preheaders = ftell (datei); |
1515 | while (!feof (datei)) { |
1515 | while (!FP_feof (datei)) { |
1516 | if (UUBUSYPOLL(preheaders,progress.fsize)) SPCANCEL(); |
1516 | if (UUBUSYPOLL(preheaders,progress.fsize)) SPCANCEL(); |
1517 | if (_FP_fgets (line, 1024, datei) == NULL) |
1517 | if (FP_fgets (line, 1024, datei) == NULL) |
1518 | break; |
1518 | break; |
1519 | if (!IsLineEmpty (line)) { |
1519 | if (!IsLineEmpty (line)) { |
1520 | fseek (datei, preheaders, SEEK_SET); |
1520 | fseek (datei, preheaders, SEEK_SET); |
1521 | break; |
1521 | break; |
1522 | } |
1522 | } |
1523 | preheaders = ftell (datei); |
1523 | preheaders = ftell (datei); |
1524 | } |
1524 | } |
1525 | } |
1525 | } |
1526 | |
1526 | |
1527 | if (ferror(datei) || feof(datei)) { |
1527 | if (ferror(datei) || FP_feof(datei)) { |
1528 | _FP_free (result); |
1528 | FP_free (result); |
1529 | return NULL; |
1529 | return NULL; |
1530 | } |
1530 | } |
1531 | |
1531 | |
1532 | /* |
1532 | /* |
1533 | * If we are confident that this is a mail folder and are at the |
1533 | * If we are confident that this is a mail folder and are at the |
… | |
… | |
1545 | */ |
1545 | */ |
1546 | |
1546 | |
1547 | while (mssdepth) { |
1547 | while (mssdepth) { |
1548 | mssdepth--; |
1548 | mssdepth--; |
1549 | UUkillheaders (&(multistack[mssdepth].envelope)); |
1549 | UUkillheaders (&(multistack[mssdepth].envelope)); |
1550 | _FP_free (multistack[mssdepth].source); |
1550 | FP_free (multistack[mssdepth].source); |
1551 | } |
1551 | } |
1552 | |
1552 | |
1553 | prevpos = ftell (datei); |
1553 | prevpos = ftell (datei); |
1554 | if (_FP_fgets (line, 1024, datei) == NULL) { |
1554 | if (FP_fgets (line, 1024, datei) == NULL) { |
1555 | _FP_free (result); |
1555 | FP_free (result); |
1556 | return NULL; |
1556 | return NULL; |
1557 | } |
1557 | } |
1558 | |
1558 | |
1559 | /* |
1559 | /* |
1560 | * Special handling for AOL folder files, which start off with a boundary. |
1560 | * Special handling for AOL folder files, which start off with a boundary. |
… | |
… | |
1562 | * Note that the rest of the scanning code becomes suspicious if a boun- |
1562 | * Note that the rest of the scanning code becomes suspicious if a boun- |
1563 | * dary does never appear in a file -- this should save us from grave |
1563 | * dary does never appear in a file -- this should save us from grave |
1564 | * false detection errors |
1564 | * false detection errors |
1565 | */ |
1565 | */ |
1566 | |
1566 | |
1567 | if (!feof (datei) && line[0] == '-' && line[1] == '-' && line[2]) { |
1567 | if (!FP_feof (datei) && line[0] == '-' && line[1] == '-' && line[2]) { |
1568 | sstate.ismime = 1; |
1568 | sstate.ismime = 1; |
1569 | sstate.envelope.mimevers = _FP_strdup ("1.0"); |
1569 | sstate.envelope.mimevers = FP_strdup ("1.0"); |
1570 | sstate.envelope.boundary = _FP_strdup (line+2); |
1570 | sstate.envelope.boundary = FP_strdup (line+2); |
1571 | sstate.envelope.ctype = _FP_strdup ("multipart/mixed"); |
1571 | sstate.envelope.ctype = FP_strdup ("multipart/mixed"); |
1572 | sstate.mimestate = MS_SUBPART; |
1572 | sstate.mimestate = MS_SUBPART; |
1573 | |
1573 | |
1574 | *errcode = UURET_CONT; |
1574 | *errcode = UURET_CONT; |
1575 | _FP_free (result); |
1575 | FP_free (result); |
1576 | return NULL; |
1576 | return NULL; |
1577 | } |
1577 | } |
1578 | |
1578 | |
1579 | /* |
1579 | /* |
1580 | * Normal behavior: look for a RFC 822 header |
1580 | * Normal behavior: look for a RFC 822 header |
1581 | */ |
1581 | */ |
1582 | |
1582 | |
1583 | while (!feof (datei) && !IsLineEmpty (line)) { |
1583 | while (!FP_feof (datei) && !IsLineEmpty (line)) { |
1584 | if (IsKnownHeader (line)) |
1584 | if (IsKnownHeader (line)) |
1585 | hcount++; |
1585 | hcount++; |
1586 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
1586 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
1587 | if (IsHeaderLine (line)) { |
1587 | if (IsHeaderLine (line)) { |
1588 | ptr1 = ScanHeaderLine (datei, line); |
1588 | ptr1 = ScanHeaderLine (datei, line); |
1589 | if (ParseHeader (&sstate.envelope, ptr1) == NULL) { |
1589 | if (ParseHeader (&sstate.envelope, ptr1) == NULL) { |
1590 | *errcode = UURET_NOMEM; |
1590 | *errcode = UURET_NOMEM; |
1591 | _FP_free (result); |
1591 | FP_free (result); |
1592 | return NULL; |
1592 | return NULL; |
1593 | } |
1593 | } |
1594 | } |
1594 | } |
1595 | /* |
1595 | /* |
1596 | * if we've read too many lines without finding headers, then |
1596 | * if we've read too many lines without finding headers, then |
… | |
… | |
1601 | fseek (datei, prevpos, SEEK_SET); |
1601 | fseek (datei, prevpos, SEEK_SET); |
1602 | line[0] = '\0'; |
1602 | line[0] = '\0'; |
1603 | break; |
1603 | break; |
1604 | } |
1604 | } |
1605 | |
1605 | |
1606 | if (_FP_fgets (line, 1024, datei) == NULL) { |
1606 | if (FP_fgets (line, 1024, datei) == NULL) { |
1607 | /* If we are at eof without finding headers, there probably isn't */ |
1607 | /* If we are at eof without finding headers, there probably isn't */ |
1608 | if (hcount < hlcount.afternl) |
1608 | if (hcount < hlcount.afternl) |
1609 | fseek (datei, prevpos, SEEK_SET); |
1609 | fseek (datei, prevpos, SEEK_SET); |
1610 | break; |
1610 | break; |
1611 | } |
1611 | } |
1612 | } |
1612 | } |
1613 | |
1613 | |
1614 | /* skip empty lines */ |
1614 | /* skip empty lines */ |
1615 | prevpos = ftell (datei); |
1615 | prevpos = ftell (datei); |
1616 | if (IsLineEmpty (line)) { |
1616 | if (IsLineEmpty (line)) { |
1617 | while (!feof (datei)) { |
1617 | while (!FP_feof (datei)) { |
1618 | if (_FP_fgets (line, 1024, datei) == NULL) |
1618 | if (FP_fgets (line, 1024, datei) == NULL) |
1619 | break; |
1619 | break; |
1620 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
1620 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
1621 | if (!IsLineEmpty (line)) { |
1621 | if (!IsLineEmpty (line)) { |
1622 | fseek (datei, prevpos, SEEK_SET); |
1622 | fseek (datei, prevpos, SEEK_SET); |
1623 | break; |
1623 | break; |
… | |
… | |
1637 | sstate.envelope.ctenc == NULL && |
1637 | sstate.envelope.ctenc == NULL && |
1638 | IsKnownHeader (line)) { |
1638 | IsKnownHeader (line)) { |
1639 | /* |
1639 | /* |
1640 | * see above |
1640 | * see above |
1641 | */ |
1641 | */ |
1642 | _FP_fgets (line, 1024, datei); |
1642 | FP_fgets (line, 1024, datei); |
1643 | |
1643 | |
1644 | while (!feof (datei) && !IsLineEmpty (line)) { |
1644 | while (!FP_feof (datei) && !IsLineEmpty (line)) { |
1645 | if (IsKnownHeader (line)) |
1645 | if (IsKnownHeader (line)) |
1646 | hcount++; |
1646 | hcount++; |
1647 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
1647 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
1648 | ptr1 = ScanHeaderLine (datei, line); |
1648 | ptr1 = ScanHeaderLine (datei, line); |
1649 | if (ParseHeader (&sstate.envelope, ptr1) == NULL) { |
1649 | if (ParseHeader (&sstate.envelope, ptr1) == NULL) { |
1650 | *errcode = UURET_NOMEM; |
1650 | *errcode = UURET_NOMEM; |
1651 | _FP_free (result); |
1651 | FP_free (result); |
1652 | return NULL; |
1652 | return NULL; |
1653 | } |
1653 | } |
1654 | |
1654 | |
1655 | if (_FP_fgets (line, 1024, datei) == NULL) |
1655 | if (FP_fgets (line, 1024, datei) == NULL) |
1656 | break; |
1656 | break; |
1657 | } |
1657 | } |
1658 | /* skip empty lines */ |
1658 | /* skip empty lines */ |
1659 | prevpos = ftell (datei); |
1659 | prevpos = ftell (datei); |
1660 | while (!feof (datei)) { |
1660 | while (!FP_feof (datei)) { |
1661 | if (_FP_fgets (line, 1024, datei) == NULL) |
1661 | if (FP_fgets (line, 1024, datei) == NULL) |
1662 | break; |
1662 | break; |
1663 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
1663 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
1664 | if (!IsLineEmpty (line)) { |
1664 | if (!IsLineEmpty (line)) { |
1665 | fseek (datei, prevpos, SEEK_SET); |
1665 | fseek (datei, prevpos, SEEK_SET); |
1666 | break; |
1666 | break; |
… | |
… | |
1675 | * MIME message |
1675 | * MIME message |
1676 | * if mimevers is not set but there are other well-known MIME |
1676 | * if mimevers is not set but there are other well-known MIME |
1677 | * headers, don't be too picky about it. |
1677 | * headers, don't be too picky about it. |
1678 | */ |
1678 | */ |
1679 | if (sstate.envelope.ctype && sstate.envelope.mimevers==NULL && |
1679 | if (sstate.envelope.ctype && sstate.envelope.mimevers==NULL && |
1680 | _FP_stristr (sstate.envelope.ctype, "multipart") != NULL && |
1680 | FP_stristr (sstate.envelope.ctype, "multipart") != NULL && |
1681 | sstate.envelope.boundary != NULL) { |
1681 | sstate.envelope.boundary != NULL) { |
1682 | sstate.envelope.mimevers = _FP_strdup ("1.0"); |
1682 | sstate.envelope.mimevers = FP_strdup ("1.0"); |
1683 | hcount = hlcount.afternl; |
1683 | hcount = hlcount.afternl; |
1684 | } |
1684 | } |
1685 | else if (sstate.envelope.mimevers==NULL && sstate.envelope.ctype && |
1685 | else if (sstate.envelope.mimevers==NULL && sstate.envelope.ctype && |
1686 | sstate.envelope.fname && sstate.envelope.ctenc) { |
1686 | sstate.envelope.fname && sstate.envelope.ctenc) { |
1687 | sstate.envelope.mimevers = _FP_strdup ("1.0"); |
1687 | sstate.envelope.mimevers = FP_strdup ("1.0"); |
1688 | hcount = hlcount.afternl; |
1688 | hcount = hlcount.afternl; |
1689 | } |
1689 | } |
1690 | |
1690 | |
1691 | if (sstate.envelope.mimevers != NULL) { |
1691 | if (sstate.envelope.mimevers != NULL) { |
1692 | /* this is a MIME file. check the Content-Type */ |
1692 | /* this is a MIME file. check the Content-Type */ |
1693 | sstate.ismime = 1; |
1693 | sstate.ismime = 1; |
1694 | if (_FP_stristr (sstate.envelope.ctype, "multipart") != NULL) { |
1694 | if (FP_stristr (sstate.envelope.ctype, "multipart") != NULL) { |
1695 | if (sstate.envelope.boundary == NULL) { |
1695 | if (sstate.envelope.boundary == NULL) { |
1696 | UUMessage (uuscan_id, __LINE__, UUMSG_WARNING, |
1696 | UUMessage (uuscan_id, __LINE__, UUMSG_WARNING, |
1697 | uustring (S_MIME_NO_BOUNDARY)); |
1697 | uustring (S_MIME_NO_BOUNDARY)); |
1698 | sstate.mimestate = MS_BODY; |
1698 | sstate.mimestate = MS_BODY; |
1699 | _FP_free (sstate.envelope.ctype); |
1699 | FP_free (sstate.envelope.ctype); |
1700 | sstate.envelope.ctype = _FP_strdup ("text/plain"); |
1700 | sstate.envelope.ctype = FP_strdup ("text/plain"); |
1701 | } |
1701 | } |
1702 | else { |
1702 | else { |
1703 | sstate.mimestate = MS_PREAMBLE; |
1703 | sstate.mimestate = MS_PREAMBLE; |
1704 | } |
1704 | } |
1705 | } |
1705 | } |
… | |
… | |
1713 | sstate.isfolder = 0; |
1713 | sstate.isfolder = 0; |
1714 | sstate.ismime = 0; |
1714 | sstate.ismime = 0; |
1715 | } |
1715 | } |
1716 | } |
1716 | } |
1717 | |
1717 | |
1718 | if (feof (datei) || ferror (datei)) { /* oops */ |
1718 | if (FP_feof (datei) || ferror (datei)) { /* oops */ |
1719 | _FP_free (result); |
1719 | FP_free (result); |
1720 | return NULL; |
1720 | return NULL; |
1721 | } |
1721 | } |
1722 | |
1722 | |
1723 | /* |
1723 | /* |
1724 | * Handle MIME stuff |
1724 | * Handle MIME stuff |
… | |
… | |
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 (!FP_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] == '-' && |
1745 | strncmp (line+2, sstate.envelope.boundary, blen) == 0) |
1745 | strncmp (line+2, sstate.envelope.boundary, blen) == 0) |
1746 | break; |
1746 | break; |
1747 | if (!IsLineEmpty (line)) |
1747 | if (!IsLineEmpty (line)) |
1748 | lcount++; |
1748 | lcount++; |
1749 | |
1749 | |
1750 | prevpos = ftell (datei); |
1750 | prevpos = ftell (datei); |
1751 | } |
1751 | } |
1752 | if (feof (datei) || ferror (datei)) { |
1752 | if (FP_feof (datei) || ferror (datei)) { |
1753 | UUMessage (uuscan_id, __LINE__, UUMSG_WARNING, |
1753 | UUMessage (uuscan_id, __LINE__, UUMSG_WARNING, |
1754 | uustring (S_MIME_B_NOT_FOUND)); |
1754 | uustring (S_MIME_B_NOT_FOUND)); |
1755 | /* |
1755 | /* |
1756 | * restart and try again; don't restart if uu_fast_scanning |
1756 | * restart and try again; don't restart if uu_fast_scanning |
1757 | */ |
1757 | */ |
… | |
… | |
1761 | |
1761 | |
1762 | if (!uu_fast_scanning) { |
1762 | if (!uu_fast_scanning) { |
1763 | *errcode = UURET_CONT; |
1763 | *errcode = UURET_CONT; |
1764 | fseek (datei, preheaders, SEEK_SET); |
1764 | fseek (datei, preheaders, SEEK_SET); |
1765 | } |
1765 | } |
1766 | _FP_free (result); |
1766 | FP_free (result); |
1767 | return NULL; |
1767 | return NULL; |
1768 | } |
1768 | } |
1769 | if (line[0] == '-' && line[1] == '-' && |
1769 | if (line[0] == '-' && line[1] == '-' && |
1770 | strncmp (line+2, sstate.envelope.boundary, blen) == 0) { |
1770 | strncmp (line+2, sstate.envelope.boundary, blen) == 0) { |
1771 | ptr1 = line + 2 + blen; |
1771 | ptr1 = line + 2 + blen; |
… | |
… | |
1789 | |
1789 | |
1790 | if (!uu_fast_scanning) { |
1790 | if (!uu_fast_scanning) { |
1791 | *errcode = UURET_CONT; |
1791 | *errcode = UURET_CONT; |
1792 | fseek (datei, preheaders, SEEK_SET); |
1792 | fseek (datei, preheaders, SEEK_SET); |
1793 | } |
1793 | } |
1794 | _FP_free (result); |
1794 | FP_free (result); |
1795 | return NULL; |
1795 | return NULL; |
1796 | } |
1796 | } |
1797 | /* produce result if uu_usepreamble is set */ |
1797 | /* produce result if uu_usepreamble is set */ |
1798 | if (uu_usepreamble && lcount) { |
1798 | if (uu_usepreamble && lcount) { |
1799 | sprintf (line, "%04d.txt", ++mimseqno); |
1799 | sprintf (line, "%04d.txt", ++mimseqno); |
1800 | result->subject = _FP_strdup (sstate.envelope.subject); |
1800 | result->subject = FP_strdup (sstate.envelope.subject); |
1801 | result->filename = _FP_strdup (line); |
1801 | result->filename = FP_strdup (line); |
1802 | result->origin = _FP_strdup (sstate.envelope.from); |
1802 | result->origin = FP_strdup (sstate.envelope.from); |
1803 | result->mimeid = _FP_strdup (sstate.envelope.mimeid); |
1803 | result->mimeid = FP_strdup (sstate.envelope.mimeid); |
1804 | result->mimetype = _FP_strdup ("text/plain"); |
1804 | result->mimetype = FP_strdup ("text/plain"); |
1805 | result->mode = 0644; |
1805 | result->mode = 0644; |
1806 | result->uudet = PT_ENCODED; /* plain text */ |
1806 | result->uudet = PT_ENCODED; /* plain text */ |
1807 | result->sfname = _FP_strdup (fname); |
1807 | result->sfname = FP_strdup (fname); |
1808 | result->flags = FL_SINGLE | FL_PROPER; |
1808 | result->flags = FL_SINGLE | FL_PROPER; |
1809 | /* result->startpos set from above */ |
1809 | /* result->startpos set from above */ |
1810 | result->length = prevpos - result->startpos; |
1810 | result->length = prevpos - result->startpos; |
1811 | result->partno = 1; |
1811 | result->partno = 1; |
1812 | |
1812 | |
… | |
… | |
1823 | /* MIME message, let's continue */ |
1823 | /* MIME message, let's continue */ |
1824 | if (*errcode == UURET_OK) |
1824 | if (*errcode == UURET_OK) |
1825 | *errcode = UURET_CONT; |
1825 | *errcode = UURET_CONT; |
1826 | |
1826 | |
1827 | /* otherwise, just return NULL */ |
1827 | /* otherwise, just return NULL */ |
1828 | _FP_free (result); |
1828 | FP_free (result); |
1829 | return NULL; |
1829 | return NULL; |
1830 | } |
1830 | } |
1831 | |
1831 | |
1832 | /* |
1832 | /* |
1833 | * Read Epilogue, the plain text after the last boundary. |
1833 | * Read Epilogue, the plain text after the last boundary. |
… | |
… | |
1859 | */ |
1859 | */ |
1860 | if (uu_fast_scanning && mssdepth == 0) { |
1860 | if (uu_fast_scanning && mssdepth == 0) { |
1861 | /* |
1861 | /* |
1862 | * check if the epilogue is empty |
1862 | * check if the epilogue is empty |
1863 | */ |
1863 | */ |
1864 | while (!feof (datei) && !ferror (datei) && lcount<10 && res==0) { |
1864 | while (!FP_feof (datei) && !ferror (datei) && lcount<10 && res==0) { |
1865 | if (_FP_fgets (line, 1024, datei) == NULL) |
1865 | if (FP_fgets (line, 1024, datei) == NULL) |
1866 | break; |
1866 | break; |
1867 | if (!IsLineEmpty (line)) |
1867 | if (!IsLineEmpty (line)) |
1868 | res++; |
1868 | res++; |
1869 | lcount++; |
1869 | lcount++; |
1870 | } |
1870 | } |
1871 | if (uu_usepreamble && res) { |
1871 | if (uu_usepreamble && res) { |
1872 | sprintf (line, "%04d.txt", ++mimseqno); |
1872 | sprintf (line, "%04d.txt", ++mimseqno); |
1873 | result->subject = _FP_strdup (sstate.envelope.subject); |
1873 | result->subject = FP_strdup (sstate.envelope.subject); |
1874 | result->filename = _FP_strdup (line); |
1874 | result->filename = FP_strdup (line); |
1875 | result->origin = _FP_strdup (sstate.envelope.from); |
1875 | result->origin = FP_strdup (sstate.envelope.from); |
1876 | result->mimeid = _FP_strdup (sstate.envelope.mimeid); |
1876 | result->mimeid = FP_strdup (sstate.envelope.mimeid); |
1877 | result->mimetype = _FP_strdup ("text/plain"); |
1877 | result->mimetype = FP_strdup ("text/plain"); |
1878 | result->mode = 0644; |
1878 | result->mode = 0644; |
1879 | result->uudet = PT_ENCODED; /* plain text */ |
1879 | result->uudet = PT_ENCODED; /* plain text */ |
1880 | result->sfname = _FP_strdup (fname); |
1880 | result->sfname = FP_strdup (fname); |
1881 | result->flags = FL_SINGLE | FL_PROPER | FL_TOEND; |
1881 | result->flags = FL_SINGLE | FL_PROPER | FL_TOEND; |
1882 | result->partno = 1; |
1882 | result->partno = 1; |
1883 | /* result->startpos set from above */ |
1883 | /* result->startpos set from above */ |
1884 | result->length = progress.fsize - result->startpos; |
1884 | result->length = progress.fsize - result->startpos; |
1885 | |
1885 | |
… | |
… | |
1888 | *errcode = UURET_NOMEM; |
1888 | *errcode = UURET_NOMEM; |
1889 | } |
1889 | } |
1890 | |
1890 | |
1891 | return result; |
1891 | return result; |
1892 | } |
1892 | } |
1893 | _FP_free (result); |
1893 | FP_free (result); |
1894 | return NULL; |
1894 | return NULL; |
1895 | } |
1895 | } |
1896 | |
1896 | |
1897 | if (mssdepth > 0) |
1897 | if (mssdepth > 0) |
1898 | blen = strlen (multistack[mssdepth-1].envelope.boundary); |
1898 | blen = strlen (multistack[mssdepth-1].envelope.boundary); |
1899 | |
1899 | |
1900 | while (!feof (datei)) { |
1900 | while (!FP_feof (datei)) { |
1901 | if (_FP_fgets (line, 1024, datei) == NULL) |
1901 | if (FP_fgets (line, 1024, datei) == NULL) |
1902 | break; |
1902 | break; |
1903 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
1903 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
1904 | /* check for parent boundary */ |
1904 | /* check for parent boundary */ |
1905 | if (mssdepth > 0 && line[0] == '-' && line[1] == '-' && |
1905 | if (mssdepth > 0 && line[0] == '-' && line[1] == '-' && |
1906 | strncmp (line+2, |
1906 | strncmp (line+2, |
… | |
… | |
1934 | } |
1934 | } |
1935 | |
1935 | |
1936 | /* check for begin and encoded data only at outermost level */ |
1936 | /* check for begin and encoded data only at outermost level */ |
1937 | if (mssdepth == 0 && !uu_more_mime) { |
1937 | if (mssdepth == 0 && !uu_more_mime) { |
1938 | if (strncmp (line, "begin ", 6) == 0 || |
1938 | if (strncmp (line, "begin ", 6) == 0 || |
1939 | _FP_strnicmp (line, "<pre>begin ", 11) == 0) { |
1939 | FP_strnicmp (line, "<pre>begin ", 11) == 0) { |
1940 | preenc = prevpos; |
1940 | preenc = prevpos; |
1941 | begflag = 1; |
1941 | begflag = 1; |
1942 | } |
1942 | } |
1943 | else if (strncmp (line, "end", 3) == 0 && begflag) { |
1943 | else if (strncmp (line, "end", 3) == 0 && begflag) { |
1944 | ecount = ELC_COUNT; |
1944 | ecount = ELC_COUNT; |
… | |
… | |
1976 | strncmp (line+2, |
1976 | strncmp (line+2, |
1977 | multistack[mssdepth-1].envelope.boundary, blen) == 0) { |
1977 | multistack[mssdepth-1].envelope.boundary, blen) == 0) { |
1978 | /* restore previous state */ |
1978 | /* restore previous state */ |
1979 | mssdepth--; |
1979 | mssdepth--; |
1980 | UUkillheaders (&sstate.envelope); |
1980 | UUkillheaders (&sstate.envelope); |
1981 | _FP_free (sstate.source); |
1981 | FP_free (sstate.source); |
1982 | memcpy (&sstate, &(multistack[mssdepth]), sizeof (scanstate)); |
1982 | memcpy (&sstate, &(multistack[mssdepth]), sizeof (scanstate)); |
1983 | |
1983 | |
1984 | ptr1 = line + 2 + strlen (sstate.envelope.boundary); |
1984 | ptr1 = line + 2 + strlen (sstate.envelope.boundary); |
1985 | |
1985 | |
1986 | if (*ptr1 == '-' && *(ptr1+1) == '-') { |
1986 | if (*ptr1 == '-' && *(ptr1+1) == '-') { |
… | |
… | |
2003 | sstate.mimestate = MS_BODY; |
2003 | sstate.mimestate = MS_BODY; |
2004 | |
2004 | |
2005 | while (mssdepth) { |
2005 | while (mssdepth) { |
2006 | mssdepth--; |
2006 | mssdepth--; |
2007 | UUkillheaders (&(multistack[mssdepth].envelope)); |
2007 | UUkillheaders (&(multistack[mssdepth].envelope)); |
2008 | _FP_free (multistack[mssdepth].source); |
2008 | FP_free (multistack[mssdepth].source); |
2009 | } |
2009 | } |
2010 | |
2010 | |
2011 | if (!uu_fast_scanning) { |
2011 | if (!uu_fast_scanning) { |
2012 | *errcode = UURET_CONT; |
2012 | *errcode = UURET_CONT; |
2013 | fseek (datei, preheaders, SEEK_SET); |
2013 | fseek (datei, preheaders, SEEK_SET); |
2014 | } |
2014 | } |
2015 | _FP_free (result); |
2015 | FP_free (result); |
2016 | return NULL; |
2016 | return NULL; |
2017 | } |
2017 | } |
2018 | else if (IsKnownHeader (line)) { |
2018 | else if (IsKnownHeader (line)) { |
2019 | /* new message follows */ |
2019 | /* new message follows */ |
2020 | sstate.isfolder = 1; |
2020 | sstate.isfolder = 1; |
… | |
… | |
2033 | } |
2033 | } |
2034 | |
2034 | |
2035 | /* produce result if uu_usepreamble is set */ |
2035 | /* produce result if uu_usepreamble is set */ |
2036 | if (uu_usepreamble && res) { |
2036 | if (uu_usepreamble && res) { |
2037 | sprintf (line, "%04d.txt", ++mimseqno); |
2037 | sprintf (line, "%04d.txt", ++mimseqno); |
2038 | result->subject = _FP_strdup (sstate.envelope.subject); |
2038 | result->subject = FP_strdup (sstate.envelope.subject); |
2039 | result->filename = _FP_strdup (line); |
2039 | result->filename = FP_strdup (line); |
2040 | result->origin = _FP_strdup (sstate.envelope.from); |
2040 | result->origin = FP_strdup (sstate.envelope.from); |
2041 | result->mimeid = _FP_strdup (sstate.envelope.mimeid); |
2041 | result->mimeid = FP_strdup (sstate.envelope.mimeid); |
2042 | result->mimetype = _FP_strdup ("text/plain"); |
2042 | result->mimetype = FP_strdup ("text/plain"); |
2043 | result->mode = 0644; |
2043 | result->mode = 0644; |
2044 | result->uudet = PT_ENCODED; /* plain text */ |
2044 | result->uudet = PT_ENCODED; /* plain text */ |
2045 | result->sfname = _FP_strdup (fname); |
2045 | result->sfname = FP_strdup (fname); |
2046 | result->flags = FL_SINGLE | FL_PROPER; |
2046 | result->flags = FL_SINGLE | FL_PROPER; |
2047 | result->partno = 1; |
2047 | result->partno = 1; |
2048 | /* result->startpos set from above */ |
2048 | /* result->startpos set from above */ |
2049 | /* result->length set from above */ |
2049 | /* result->length set from above */ |
2050 | |
2050 | |
… | |
… | |
2054 | } |
2054 | } |
2055 | |
2055 | |
2056 | return result; |
2056 | return result; |
2057 | } |
2057 | } |
2058 | /* otherwise, just return NULL */ |
2058 | /* otherwise, just return NULL */ |
2059 | _FP_free (result); |
2059 | FP_free (result); |
2060 | return NULL; |
2060 | return NULL; |
2061 | } |
2061 | } |
2062 | |
2062 | |
2063 | /* |
2063 | /* |
2064 | * Scan a new part from a Multipart message. Check for a new local |
2064 | * Scan a new part from a Multipart message. Check for a new local |
… | |
… | |
2078 | |
2078 | |
2079 | /* |
2079 | /* |
2080 | * Duplicate some data from outer envelope |
2080 | * Duplicate some data from outer envelope |
2081 | */ |
2081 | */ |
2082 | |
2082 | |
2083 | localenv.mimevers = _FP_strdup (sstate.envelope.mimevers); |
2083 | localenv.mimevers = FP_strdup (sstate.envelope.mimevers); |
2084 | localenv.from = _FP_strdup (sstate.envelope.from); |
2084 | localenv.from = FP_strdup (sstate.envelope.from); |
2085 | localenv.subject = _FP_strdup (sstate.envelope.subject); |
2085 | localenv.subject = FP_strdup (sstate.envelope.subject); |
2086 | localenv.rcpt = _FP_strdup (sstate.envelope.rcpt); |
2086 | localenv.rcpt = FP_strdup (sstate.envelope.rcpt); |
2087 | localenv.date = _FP_strdup (sstate.envelope.date); |
2087 | localenv.date = FP_strdup (sstate.envelope.date); |
2088 | |
2088 | |
2089 | if ((sstate.envelope.mimevers != NULL && localenv.mimevers == NULL) || |
2089 | if ((sstate.envelope.mimevers != NULL && localenv.mimevers == NULL) || |
2090 | (sstate.envelope.from != NULL && localenv.from == NULL) || |
2090 | (sstate.envelope.from != NULL && localenv.from == NULL) || |
2091 | (sstate.envelope.subject != NULL && localenv.subject == NULL) || |
2091 | (sstate.envelope.subject != NULL && localenv.subject == NULL) || |
2092 | (sstate.envelope.rcpt != NULL && localenv.rcpt == NULL) || |
2092 | (sstate.envelope.rcpt != NULL && localenv.rcpt == NULL) || |
2093 | (sstate.envelope.date != NULL && localenv.date == NULL)) { |
2093 | (sstate.envelope.date != NULL && localenv.date == NULL)) { |
2094 | |
2094 | |
2095 | while (mssdepth) { |
2095 | while (mssdepth) { |
2096 | mssdepth--; |
2096 | mssdepth--; |
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--; |
2119 | UUkillheaders (&(multistack[mssdepth].envelope)); |
2119 | UUkillheaders (&(multistack[mssdepth].envelope)); |
2120 | _FP_free (multistack[mssdepth].source); |
2120 | FP_free (multistack[mssdepth].source); |
2121 | } |
2121 | } |
2122 | UUkillheaders (&localenv); |
2122 | UUkillheaders (&localenv); |
2123 | _FP_free (result); |
2123 | FP_free (result); |
2124 | return NULL; |
2124 | return NULL; |
2125 | } |
2125 | } |
2126 | |
2126 | |
2127 | while (!feof (datei) && !IsLineEmpty (line)) { |
2127 | while (!FP_feof (datei) && !IsLineEmpty (line)) { |
2128 | if (IsKnownHeader (line)) |
2128 | if (IsKnownHeader (line)) |
2129 | hcount++; |
2129 | hcount++; |
2130 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
2130 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
2131 | if (lcount > WAITHEADER && hcount == 0) { |
2131 | if (lcount > WAITHEADER && hcount == 0) { |
2132 | fseek (datei, preheaders, SEEK_SET); |
2132 | fseek (datei, preheaders, SEEK_SET); |
… | |
… | |
2140 | if (line[0] == '-' && line[1] == '-') |
2140 | if (line[0] == '-' && line[1] == '-') |
2141 | break; |
2141 | break; |
2142 | |
2142 | |
2143 | prevpos = ftell (datei); |
2143 | prevpos = ftell (datei); |
2144 | |
2144 | |
2145 | if (_FP_fgets (line, 1024, datei) == NULL) |
2145 | if (FP_fgets (line, 1024, datei) == NULL) |
2146 | break; |
2146 | break; |
2147 | lcount++; |
2147 | lcount++; |
2148 | } |
2148 | } |
2149 | if (line[0] == '-' && line[1] == '-') { |
2149 | if (line[0] == '-' && line[1] == '-') { |
2150 | /* |
2150 | /* |
… | |
… | |
2153 | * boundary, so that it gets handled below |
2153 | * boundary, so that it gets handled below |
2154 | */ |
2154 | */ |
2155 | fseek (datei, prevpos, SEEK_SET); |
2155 | fseek (datei, prevpos, SEEK_SET); |
2156 | } |
2156 | } |
2157 | |
2157 | |
2158 | if (_FP_stristr (localenv.ctype, "multipart") != NULL) { |
2158 | if (FP_stristr (localenv.ctype, "multipart") != NULL) { |
2159 | /* oh no, not again */ |
2159 | /* oh no, not again */ |
2160 | if (mssdepth >= MSMAXDEPTH) { |
2160 | if (mssdepth >= MSMAXDEPTH) { |
2161 | /* Argh, what an isane message. Treat as plain text */ |
2161 | /* Argh, what an isane message. Treat as plain text */ |
2162 | UUMessage (uuscan_id, __LINE__, UUMSG_WARNING, |
2162 | UUMessage (uuscan_id, __LINE__, UUMSG_WARNING, |
2163 | uustring (S_MIME_MULTI_DEPTH)); |
2163 | uustring (S_MIME_MULTI_DEPTH)); |
… | |
… | |
2169 | else { |
2169 | else { |
2170 | memcpy (&multistack[mssdepth], &sstate, sizeof (scanstate)); |
2170 | memcpy (&multistack[mssdepth], &sstate, sizeof (scanstate)); |
2171 | memcpy (&sstate.envelope, &localenv, sizeof (headers)); |
2171 | memcpy (&sstate.envelope, &localenv, sizeof (headers)); |
2172 | memset (&localenv, 0, sizeof (headers)); |
2172 | memset (&localenv, 0, sizeof (headers)); |
2173 | sstate.mimestate = MS_PREAMBLE; |
2173 | sstate.mimestate = MS_PREAMBLE; |
2174 | if ((sstate.source = _FP_strdup (sstate.source)) == NULL) |
2174 | if ((sstate.source = FP_strdup (sstate.source)) == NULL) |
2175 | *errcode = UURET_NOMEM; |
2175 | *errcode = UURET_NOMEM; |
2176 | |
2176 | |
2177 | if (*errcode == UURET_OK) |
2177 | if (*errcode == UURET_OK) |
2178 | *errcode = UURET_CONT; |
2178 | *errcode = UURET_CONT; |
2179 | |
2179 | |
2180 | mssdepth++; |
2180 | mssdepth++; |
2181 | /* need a restart */ |
2181 | /* need a restart */ |
2182 | _FP_free (result); |
2182 | FP_free (result); |
2183 | return NULL; |
2183 | return NULL; |
2184 | } |
2184 | } |
2185 | } |
2185 | } |
2186 | |
2186 | |
2187 | /* |
2187 | /* |
… | |
… | |
2195 | * text. |
2195 | * text. |
2196 | * This is done because users might `attach' a uuencoded file, which |
2196 | * This is done because users might `attach' a uuencoded file, which |
2197 | * would then be correctly typed as `text/plain'. |
2197 | * would then be correctly typed as `text/plain'. |
2198 | */ |
2198 | */ |
2199 | |
2199 | |
2200 | if (_FP_stristr (localenv.ctenc, "base64") != NULL) |
2200 | if (FP_stristr (localenv.ctenc, "base64") != NULL) |
2201 | result->uudet = B64ENCODED; |
2201 | result->uudet = B64ENCODED; |
2202 | else if (_FP_stristr (localenv.ctenc, "x-uue") != NULL) { |
2202 | else if (FP_stristr (localenv.ctenc, "x-uue") != NULL) { |
2203 | result->uudet = UU_ENCODED; |
2203 | result->uudet = UU_ENCODED; |
2204 | result->begin = result->end = 1; |
2204 | result->begin = result->end = 1; |
2205 | } |
2205 | } |
2206 | else if (_FP_stristr (localenv.ctenc, "x-yenc") != NULL) { |
2206 | else if (FP_stristr (localenv.ctenc, "x-yenc") != NULL) { |
2207 | result->uudet = YENC_ENCODED; |
2207 | result->uudet = YENC_ENCODED; |
2208 | result->begin = result->end = 1; |
2208 | result->begin = result->end = 1; |
2209 | } |
2209 | } |
2210 | else if (_FP_stristr (localenv.ctenc, "quoted-printable") != NULL) |
2210 | else if (FP_stristr (localenv.ctenc, "quoted-printable") != NULL) |
2211 | result->uudet = QP_ENCODED; |
2211 | result->uudet = QP_ENCODED; |
2212 | else if (_FP_stristr (localenv.ctenc, "7bit") != NULL || |
2212 | else if (FP_stristr (localenv.ctenc, "7bit") != NULL || |
2213 | _FP_stristr (localenv.ctenc, "8bit") != NULL) |
2213 | FP_stristr (localenv.ctenc, "8bit") != NULL) |
2214 | result->uudet = PT_ENCODED; |
2214 | result->uudet = PT_ENCODED; |
2215 | else if (_FP_stristr (localenv.ctype, "multipart") != NULL || |
2215 | else if (FP_stristr (localenv.ctype, "multipart") != NULL || |
2216 | _FP_stristr (localenv.ctype, "message") != NULL) |
2216 | FP_stristr (localenv.ctype, "message") != NULL) |
2217 | result->uudet = PT_ENCODED; |
2217 | result->uudet = PT_ENCODED; |
2218 | |
2218 | |
2219 | /* |
2219 | /* |
2220 | * If we're switched to MIME-only mode, handle as text |
2220 | * If we're switched to MIME-only mode, handle as text |
2221 | */ |
2221 | */ |
… | |
… | |
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 (!FP_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'; |
2241 | if (line[0] == '-' && line[1] == '-' && |
2241 | if (line[0] == '-' && line[1] == '-' && |
2242 | strncmp (line+2, sstate.envelope.boundary, blen) == 0) |
2242 | strncmp (line+2, sstate.envelope.boundary, blen) == 0) |
… | |
… | |
2249 | * This check here doesn't cover folded header lines, but we don't |
2249 | * This check here doesn't cover folded header lines, but we don't |
2250 | * want to slow down scanning too much. We just check for |
2250 | * want to slow down scanning too much. We just check for |
2251 | * Content-Type: multipart/... boundary="same-boundary" |
2251 | * Content-Type: multipart/... boundary="same-boundary" |
2252 | */ |
2252 | */ |
2253 | if (line[0] == 'C' && line[1] == 'o' && |
2253 | if (line[0] == 'C' && line[1] == 'o' && |
2254 | _FP_strnicmp (line, "Content-Type:", 13) == 0) { |
2254 | FP_strnicmp (line, "Content-Type:", 13) == 0) { |
2255 | ptr1 = ScanHeaderLine (datei, line); |
2255 | ptr1 = ScanHeaderLine (datei, line); |
2256 | ptr2 = (ptr1)?_FP_stristr(ptr1,"boundary"):NULL; |
2256 | ptr2 = (ptr1)?FP_stristr(ptr1,"boundary"):NULL; |
2257 | ptr1 = (ptr2)?ParseValue(ptr2):NULL; |
2257 | ptr1 = (ptr2)?ParseValue(ptr2):NULL; |
2258 | if (ptr1 && strcmp (ptr1, sstate.envelope.boundary) == 0) |
2258 | if (ptr1 && strcmp (ptr1, sstate.envelope.boundary) == 0) |
2259 | break; |
2259 | break; |
2260 | for (res=0; ptr1 && res<mssdepth; res++) |
2260 | for (res=0; ptr1 && res<mssdepth; res++) |
2261 | if (strcmp (ptr1, multistack[res].envelope.boundary) == 0) |
2261 | if (strcmp (ptr1, multistack[res].envelope.boundary) == 0) |
… | |
… | |
2280 | uustring (S_MIME_B_NOT_FOUND)); |
2280 | uustring (S_MIME_B_NOT_FOUND)); |
2281 | |
2281 | |
2282 | while (mssdepth) { |
2282 | while (mssdepth) { |
2283 | mssdepth--; |
2283 | mssdepth--; |
2284 | UUkillheaders (&(multistack[mssdepth].envelope)); |
2284 | UUkillheaders (&(multistack[mssdepth].envelope)); |
2285 | _FP_free (multistack[mssdepth].source); |
2285 | FP_free (multistack[mssdepth].source); |
2286 | } |
2286 | } |
2287 | /* |
2287 | /* |
2288 | * Don't retry if uu_fast_scanning |
2288 | * Don't retry if uu_fast_scanning |
2289 | */ |
2289 | */ |
2290 | |
2290 | |
2291 | if (uu_fast_scanning) { |
2291 | if (uu_fast_scanning) { |
2292 | UUkillheaders (&localenv); |
2292 | UUkillheaders (&localenv); |
2293 | sstate.isfolder = 0; |
2293 | sstate.isfolder = 0; |
2294 | sstate.ismime = 0; |
2294 | sstate.ismime = 0; |
2295 | sstate.mimestate = MS_BODY; |
2295 | sstate.mimestate = MS_BODY; |
2296 | _FP_free (result); |
2296 | FP_free (result); |
2297 | return NULL; |
2297 | return NULL; |
2298 | } |
2298 | } |
2299 | |
2299 | |
2300 | /* |
2300 | /* |
2301 | * Retry, but listening to headers this time |
2301 | * Retry, but listening to headers this time |
… | |
… | |
2335 | } |
2335 | } |
2336 | /* produce result if uu_handletext is set */ |
2336 | /* produce result if uu_handletext is set */ |
2337 | /* or if the file is explicitely named */ |
2337 | /* or if the file is explicitely named */ |
2338 | if (result->uudet == B64ENCODED || lcount) { |
2338 | if (result->uudet == B64ENCODED || lcount) { |
2339 | if (localenv.fname) { |
2339 | if (localenv.fname) { |
2340 | _FP_free (result->filename); |
2340 | FP_free (result->filename); |
2341 | if ((result->filename = _FP_strdup (localenv.fname)) == NULL) |
2341 | if ((result->filename = FP_strdup (localenv.fname)) == NULL) |
2342 | *errcode = UURET_NOMEM; |
2342 | *errcode = UURET_NOMEM; |
2343 | } |
2343 | } |
2344 | else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) && |
2344 | else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) && |
2345 | result->filename == NULL && uu_handletext) { |
2345 | result->filename == NULL && uu_handletext) { |
2346 | sprintf (line, "%04d.txt", ++mimseqno); |
2346 | sprintf (line, "%04d.txt", ++mimseqno); |
2347 | if ((result->filename = _FP_strdup (line)) == NULL) |
2347 | if ((result->filename = FP_strdup (line)) == NULL) |
2348 | *errcode = UURET_NOMEM; |
2348 | *errcode = UURET_NOMEM; |
2349 | } |
2349 | } |
2350 | result->subject = _FP_strdup (localenv.subject); |
2350 | result->subject = FP_strdup (localenv.subject); |
2351 | result->origin = _FP_strdup (localenv.from); |
2351 | result->origin = FP_strdup (localenv.from); |
2352 | result->mimeid = _FP_strdup (localenv.mimeid); |
2352 | result->mimeid = FP_strdup (localenv.mimeid); |
2353 | result->mimetype = _FP_strdup (localenv.ctype); |
2353 | result->mimetype = FP_strdup (localenv.ctype); |
2354 | result->mode = 0644; |
2354 | result->mode = 0644; |
2355 | result->sfname = _FP_strdup (fname); |
2355 | result->sfname = FP_strdup (fname); |
2356 | result->flags = FL_SINGLE | FL_PROPER; |
2356 | result->flags = FL_SINGLE | FL_PROPER; |
2357 | result->partno = 1; |
2357 | result->partno = 1; |
2358 | /* result->uudet determined above */ |
2358 | /* result->uudet determined above */ |
2359 | /* result->startpos set from above */ |
2359 | /* result->startpos set from above */ |
2360 | result->length = prevpos - result->startpos; |
2360 | result->length = prevpos - result->startpos; |
… | |
… | |
2364 | *errcode = UURET_NOMEM; |
2364 | *errcode = UURET_NOMEM; |
2365 | } |
2365 | } |
2366 | } |
2366 | } |
2367 | else { |
2367 | else { |
2368 | /* don't produce a result */ |
2368 | /* don't produce a result */ |
2369 | _FP_free (result); |
2369 | FP_free (result); |
2370 | result = NULL; |
2370 | result = NULL; |
2371 | } |
2371 | } |
2372 | if (*errcode == UURET_OK) |
2372 | if (*errcode == UURET_OK) |
2373 | *errcode = UURET_CONT; |
2373 | *errcode = UURET_CONT; |
2374 | /* |
2374 | /* |
… | |
… | |
2398 | * we should really be at a boundary here, but check again |
2398 | * we should really be at a boundary here, but check again |
2399 | */ |
2399 | */ |
2400 | blen = strlen (sstate.envelope.boundary); |
2400 | blen = strlen (sstate.envelope.boundary); |
2401 | prevpos = ftell (datei); |
2401 | prevpos = ftell (datei); |
2402 | |
2402 | |
2403 | while (!feof (datei)) { |
2403 | while (!FP_feof (datei)) { |
2404 | if (_FP_fgets (line, 1024, datei) == NULL) |
2404 | if (FP_fgets (line, 1024, datei) == NULL) |
2405 | break; |
2405 | break; |
2406 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
2406 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
2407 | if (line[0] == '-' && line[1] == '-' && |
2407 | if (line[0] == '-' && line[1] == '-' && |
2408 | strncmp (line+2, sstate.envelope.boundary, blen) == 0) |
2408 | strncmp (line+2, sstate.envelope.boundary, blen) == 0) |
2409 | break; |
2409 | break; |
2410 | if (line[0] == 'C' && line[1] == 'o' && |
2410 | if (line[0] == 'C' && line[1] == 'o' && |
2411 | _FP_strnicmp (line, "Content-Type:", 13) == 0) { |
2411 | FP_strnicmp (line, "Content-Type:", 13) == 0) { |
2412 | ptr1 = ScanHeaderLine (datei, line); |
2412 | ptr1 = ScanHeaderLine (datei, line); |
2413 | ptr2 = (ptr1)?_FP_stristr(ptr1,"boundary"):NULL; |
2413 | ptr2 = (ptr1)?FP_stristr(ptr1,"boundary"):NULL; |
2414 | ptr1 = (ptr2)?ParseValue(ptr2):NULL; |
2414 | ptr1 = (ptr2)?ParseValue(ptr2):NULL; |
2415 | if (ptr1 && strcmp (ptr1, sstate.envelope.boundary) == 0) |
2415 | if (ptr1 && strcmp (ptr1, sstate.envelope.boundary) == 0) |
2416 | break; |
2416 | break; |
2417 | } |
2417 | } |
2418 | prevpos = ftell (datei); |
2418 | prevpos = ftell (datei); |
… | |
… | |
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 | } |
2440 | |
2440 | |
2441 | if (uu_fast_scanning) { |
2441 | if (uu_fast_scanning) { |
2442 | UUkillheaders (&localenv); |
2442 | UUkillheaders (&localenv); |
2443 | sstate.isfolder = 0; |
2443 | sstate.isfolder = 0; |
2444 | sstate.ismime = 0; |
2444 | sstate.ismime = 0; |
2445 | sstate.mimestate = MS_BODY; |
2445 | sstate.mimestate = MS_BODY; |
2446 | _FP_free (result); |
2446 | FP_free (result); |
2447 | return NULL; |
2447 | return NULL; |
2448 | } |
2448 | } |
2449 | |
2449 | |
2450 | /* |
2450 | /* |
2451 | * Retry, listening to headers this time |
2451 | * Retry, listening to headers this time |
… | |
… | |
2490 | * it doesn't hold up, handle as plain text instead. |
2490 | * it doesn't hold up, handle as plain text instead. |
2491 | */ |
2491 | */ |
2492 | |
2492 | |
2493 | if (sstate.ismime && sstate.mimestate == MS_SUBPART && |
2493 | if (sstate.ismime && sstate.mimestate == MS_SUBPART && |
2494 | strcmp (localenv.mimevers, "1.0") == 0 && |
2494 | strcmp (localenv.mimevers, "1.0") == 0 && |
2495 | _FP_stristr (localenv.ctype, "text") != NULL && |
2495 | FP_stristr (localenv.ctype, "text") != NULL && |
2496 | !uu_desperate) { |
2496 | !uu_desperate) { |
2497 | if (result->uudet == UU_ENCODED && !(result->begin || result->end)) { |
2497 | if (result->uudet == UU_ENCODED && !(result->begin || result->end)) { |
2498 | result->uudet = 0; |
2498 | result->uudet = 0; |
2499 | } |
2499 | } |
2500 | } |
2500 | } |
… | |
… | |
2506 | if (result->uudet == 0) { |
2506 | if (result->uudet == 0) { |
2507 | result->uudet = PT_ENCODED; /* plain text */ |
2507 | result->uudet = PT_ENCODED; /* plain text */ |
2508 | } |
2508 | } |
2509 | |
2509 | |
2510 | if (localenv.fname) { |
2510 | if (localenv.fname) { |
2511 | _FP_free (result->filename); |
2511 | FP_free (result->filename); |
2512 | if ((result->filename = _FP_strdup (localenv.fname)) == NULL) |
2512 | if ((result->filename = FP_strdup (localenv.fname)) == NULL) |
2513 | *errcode = UURET_NOMEM; |
2513 | *errcode = UURET_NOMEM; |
2514 | } |
2514 | } |
2515 | else if ((result->uudet==QP_ENCODED || result->uudet==PT_ENCODED) && |
2515 | else if ((result->uudet==QP_ENCODED || result->uudet==PT_ENCODED) && |
2516 | result->filename==NULL && uu_handletext) { |
2516 | result->filename==NULL && uu_handletext) { |
2517 | sprintf (line, "%04d.txt", ++mimseqno); |
2517 | sprintf (line, "%04d.txt", ++mimseqno); |
2518 | if ((result->filename = _FP_strdup (line)) == NULL) |
2518 | if ((result->filename = FP_strdup (line)) == NULL) |
2519 | *errcode = UURET_NOMEM; |
2519 | *errcode = UURET_NOMEM; |
2520 | } |
2520 | } |
2521 | else { |
2521 | else { |
2522 | /* assign a filename lateron */ |
2522 | /* assign a filename lateron */ |
2523 | } |
2523 | } |
2524 | if (result->mimetype) _FP_free (result->mimetype); |
2524 | if (result->mimetype) FP_free (result->mimetype); |
2525 | if (result->uudet) { |
2525 | if (result->uudet) { |
2526 | if (_FP_stristr (localenv.ctype, "text") != NULL && |
2526 | if (FP_stristr (localenv.ctype, "text") != NULL && |
2527 | result->uudet != QP_ENCODED && result->uudet != PT_ENCODED) |
2527 | result->uudet != QP_ENCODED && result->uudet != PT_ENCODED) |
2528 | result->mimetype = NULL; /* better don't set it */ |
2528 | result->mimetype = NULL; /* better don't set it */ |
2529 | else |
2529 | else |
2530 | result->mimetype = _FP_strdup (localenv.ctype); |
2530 | result->mimetype = FP_strdup (localenv.ctype); |
2531 | } |
2531 | } |
2532 | if (result->origin) _FP_free (result->origin); |
2532 | if (result->origin) FP_free (result->origin); |
2533 | result->origin = _FP_strdup (localenv.from); |
2533 | result->origin = FP_strdup (localenv.from); |
2534 | |
2534 | |
2535 | if (result->subject) _FP_free (result->subject); |
2535 | if (result->subject) FP_free (result->subject); |
2536 | result->subject = _FP_strdup (localenv.subject); |
2536 | result->subject = FP_strdup (localenv.subject); |
2537 | |
2537 | |
2538 | if (result->sfname == NULL) |
2538 | if (result->sfname == NULL) |
2539 | if ((result->sfname = _FP_strdup (fname)) == NULL) |
2539 | if ((result->sfname = FP_strdup (fname)) == NULL) |
2540 | *errcode = UURET_NOMEM; |
2540 | *errcode = UURET_NOMEM; |
2541 | |
2541 | |
2542 | result->length = prevpos - result->startpos; |
2542 | result->length = prevpos - result->startpos; |
2543 | result->flags = FL_SINGLE | FL_PROPER; |
2543 | result->flags = FL_SINGLE | FL_PROPER; |
2544 | result->partno = 1; |
2544 | result->partno = 1; |
… | |
… | |
2566 | * long to figure this out. But this might still be a MIME message |
2566 | * long to figure this out. But this might still be a MIME message |
2567 | * body. And if it's a message/partial, we need more special handling |
2567 | * body. And if it's a message/partial, we need more special handling |
2568 | */ |
2568 | */ |
2569 | |
2569 | |
2570 | if (sstate.isfolder && sstate.ismime && sstate.mimestate == MS_BODY && |
2570 | if (sstate.isfolder && sstate.ismime && sstate.mimestate == MS_BODY && |
2571 | _FP_stristr (sstate.envelope.ctype, "message") != NULL && |
2571 | FP_stristr (sstate.envelope.ctype, "message") != NULL && |
2572 | _FP_stristr (sstate.envelope.ctype, "partial") != NULL) { |
2572 | FP_stristr (sstate.envelope.ctype, "partial") != NULL) { |
2573 | |
2573 | |
2574 | result->startpos = ftell (datei); |
2574 | result->startpos = ftell (datei); |
2575 | |
2575 | |
2576 | if (sstate.envelope.partno == 1) { |
2576 | if (sstate.envelope.partno == 1) { |
2577 | /* read local envelope */ |
2577 | /* read local envelope */ |
2578 | UUkillheaders (&localenv); |
2578 | UUkillheaders (&localenv); |
2579 | memset (&localenv, 0, sizeof (headers)); |
2579 | memset (&localenv, 0, sizeof (headers)); |
2580 | |
2580 | |
2581 | /* skip over blank lines first */ |
2581 | /* skip over blank lines first */ |
2582 | prevpos = ftell (datei); |
2582 | prevpos = ftell (datei); |
2583 | while (!feof (datei)) { |
2583 | while (!FP_feof (datei)) { |
2584 | if (_FP_fgets (line, 1024, datei) == NULL) |
2584 | if (FP_fgets (line, 1024, datei) == NULL) |
2585 | break; |
2585 | break; |
2586 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
2586 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
2587 | if (!IsLineEmpty (line)) |
2587 | if (!IsLineEmpty (line)) |
2588 | break; |
2588 | break; |
2589 | prevpos = ftell (datei); |
2589 | prevpos = ftell (datei); |
… | |
… | |
2591 | /* Next, read header. But what if there is no subheader? */ |
2591 | /* Next, read header. But what if there is no subheader? */ |
2592 | hcount = 0; |
2592 | hcount = 0; |
2593 | lcount = 0; |
2593 | lcount = 0; |
2594 | preheaders = prevpos; |
2594 | preheaders = prevpos; |
2595 | |
2595 | |
2596 | while (!feof (datei) && !IsLineEmpty (line)) { |
2596 | while (!FP_feof (datei) && !IsLineEmpty (line)) { |
2597 | if (IsKnownHeader (line)) |
2597 | if (IsKnownHeader (line)) |
2598 | hcount++; |
2598 | hcount++; |
2599 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
2599 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
2600 | if (lcount > WAITHEADER && hcount == 0) { |
2600 | if (lcount > WAITHEADER && hcount == 0) { |
2601 | fseek (datei, preheaders, SEEK_SET); |
2601 | fseek (datei, preheaders, SEEK_SET); |
… | |
… | |
2603 | } |
2603 | } |
2604 | ptr1 = ScanHeaderLine (datei, line); |
2604 | ptr1 = ScanHeaderLine (datei, line); |
2605 | if (ParseHeader (&localenv, ptr1) == NULL) |
2605 | if (ParseHeader (&localenv, ptr1) == NULL) |
2606 | *errcode = UURET_NOMEM; |
2606 | *errcode = UURET_NOMEM; |
2607 | |
2607 | |
2608 | if (_FP_fgets (line, 1024, datei) == NULL) |
2608 | if (FP_fgets (line, 1024, datei) == NULL) |
2609 | break; |
2609 | break; |
2610 | lcount++; |
2610 | lcount++; |
2611 | } |
2611 | } |
2612 | prevpos = ftell (datei); |
2612 | prevpos = ftell (datei); |
2613 | /* |
2613 | /* |
2614 | * Examine local header. We're mostly interested in the Content-Type |
2614 | * Examine local header. We're mostly interested in the Content-Type |
2615 | * and the Content-Transfer-Encoding. |
2615 | * and the Content-Transfer-Encoding. |
2616 | */ |
2616 | */ |
2617 | if (_FP_stristr (localenv.ctype, "multipart") != NULL) { |
2617 | if (FP_stristr (localenv.ctype, "multipart") != NULL) { |
2618 | UUMessage (uuscan_id, __LINE__, UUMSG_WARNING, |
2618 | UUMessage (uuscan_id, __LINE__, UUMSG_WARNING, |
2619 | uustring (S_MIME_PART_MULTI)); |
2619 | uustring (S_MIME_PART_MULTI)); |
2620 | } |
2620 | } |
2621 | if (localenv.subject) |
2621 | if (localenv.subject) |
2622 | result->subject = _FP_strdup (localenv.subject); |
2622 | result->subject = FP_strdup (localenv.subject); |
2623 | else |
2623 | else |
2624 | result->subject = _FP_strdup (sstate.envelope.subject); |
2624 | result->subject = FP_strdup (sstate.envelope.subject); |
2625 | |
2625 | |
2626 | if (localenv.from) |
2626 | if (localenv.from) |
2627 | result->origin = _FP_strdup (localenv.from); |
2627 | result->origin = FP_strdup (localenv.from); |
2628 | else |
2628 | else |
2629 | result->origin = _FP_strdup (sstate.envelope.from); |
2629 | result->origin = FP_strdup (sstate.envelope.from); |
2630 | |
2630 | |
2631 | if (localenv.ctype) |
2631 | if (localenv.ctype) |
2632 | result->mimetype = _FP_strdup (localenv.ctype); |
2632 | result->mimetype = FP_strdup (localenv.ctype); |
2633 | else |
2633 | else |
2634 | result->mimetype = _FP_strdup ("text/plain"); |
2634 | result->mimetype = FP_strdup ("text/plain"); |
2635 | |
2635 | |
2636 | if (_FP_stristr (localenv.ctenc, "quoted-printable") != NULL) |
2636 | if (FP_stristr (localenv.ctenc, "quoted-printable") != NULL) |
2637 | result->uudet = QP_ENCODED; |
2637 | result->uudet = QP_ENCODED; |
2638 | else if (_FP_stristr (localenv.ctenc, "base64") != NULL) |
2638 | else if (FP_stristr (localenv.ctenc, "base64") != NULL) |
2639 | result->uudet = B64ENCODED; |
2639 | result->uudet = B64ENCODED; |
2640 | else if (_FP_stristr (localenv.ctenc, "x-uue") != NULL) { |
2640 | else if (FP_stristr (localenv.ctenc, "x-uue") != NULL) { |
2641 | result->uudet = UU_ENCODED; |
2641 | result->uudet = UU_ENCODED; |
2642 | result->begin = result->end = 1; |
2642 | result->begin = result->end = 1; |
2643 | } |
2643 | } |
2644 | else if (_FP_stristr (localenv.ctenc, "x-yenc") != NULL) { |
2644 | else if (FP_stristr (localenv.ctenc, "x-yenc") != NULL) { |
2645 | result->uudet = YENC_ENCODED; |
2645 | result->uudet = YENC_ENCODED; |
2646 | result->begin = result->end = 1; |
2646 | result->begin = result->end = 1; |
2647 | } |
2647 | } |
2648 | else if (_FP_stristr (localenv.ctenc, "7bit") != NULL || |
2648 | else if (FP_stristr (localenv.ctenc, "7bit") != NULL || |
2649 | _FP_stristr (localenv.ctenc, "8bit") != NULL) |
2649 | FP_stristr (localenv.ctenc, "8bit") != NULL) |
2650 | result->uudet = PT_ENCODED; |
2650 | result->uudet = PT_ENCODED; |
2651 | else if (_FP_stristr (localenv.ctype, "multipart") != NULL || |
2651 | else if (FP_stristr (localenv.ctype, "multipart") != NULL || |
2652 | _FP_stristr (localenv.ctype, "message") != NULL) |
2652 | FP_stristr (localenv.ctype, "message") != NULL) |
2653 | result->uudet = PT_ENCODED; |
2653 | result->uudet = PT_ENCODED; |
2654 | |
2654 | |
2655 | /* |
2655 | /* |
2656 | * If we're switched to MIME-only mode, handle as text |
2656 | * If we're switched to MIME-only mode, handle as text |
2657 | */ |
2657 | */ |
… | |
… | |
2684 | } |
2684 | } |
2685 | else if (result->uudet != 0) { |
2685 | else if (result->uudet != 0) { |
2686 | hcount = lcount = 0; |
2686 | hcount = lcount = 0; |
2687 | prevpos = ftell (datei); |
2687 | prevpos = ftell (datei); |
2688 | |
2688 | |
2689 | if (_FP_stristr (localenv.ctype, "message") != NULL && |
2689 | if (FP_stristr (localenv.ctype, "message") != NULL && |
2690 | _FP_stristr (localenv.ctype, "rfc822") != NULL) { |
2690 | FP_stristr (localenv.ctype, "rfc822") != NULL) { |
2691 | /* |
2691 | /* |
2692 | * skip over empty lines and local header |
2692 | * skip over empty lines and local header |
2693 | */ |
2693 | */ |
2694 | preheaders = ftell (datei); |
2694 | preheaders = ftell (datei); |
2695 | while (!feof (datei)) { |
2695 | while (!FP_feof (datei)) { |
2696 | if (_FP_fgets (line, 1024, datei) == NULL) |
2696 | if (FP_fgets (line, 1024, datei) == NULL) |
2697 | break; |
2697 | break; |
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 (!FP_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; |
2709 | |
2709 | |
2710 | if (_FP_fgets (line, 1024, datei) == NULL) |
2710 | if (FP_fgets (line, 1024, datei) == NULL) |
2711 | break; |
2711 | break; |
2712 | } |
2712 | } |
2713 | if (hcount < hlcount.afternl) |
2713 | if (hcount < hlcount.afternl) |
2714 | fseek (datei, preheaders, SEEK_SET); |
2714 | fseek (datei, preheaders, SEEK_SET); |
2715 | hcount = lcount = 0; |
2715 | hcount = lcount = 0; |
… | |
… | |
2717 | |
2717 | |
2718 | /* |
2718 | /* |
2719 | * look for next header |
2719 | * look for next header |
2720 | */ |
2720 | */ |
2721 | |
2721 | |
2722 | while (!feof (datei)) { |
2722 | while (!FP_feof (datei)) { |
2723 | if (_FP_fgets (line, 1024, datei) == NULL) |
2723 | if (FP_fgets (line, 1024, datei) == NULL) |
2724 | break; |
2724 | break; |
2725 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
2725 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
2726 | if (ferror (datei)) |
2726 | if (ferror (datei)) |
2727 | break; |
2727 | break; |
2728 | |
2728 | |
… | |
… | |
2775 | } |
2775 | } |
2776 | /* |
2776 | /* |
2777 | * produce result |
2777 | * produce result |
2778 | */ |
2778 | */ |
2779 | if (localenv.fname) { |
2779 | if (localenv.fname) { |
2780 | _FP_free (result->filename); |
2780 | FP_free (result->filename); |
2781 | if ((result->filename = _FP_strdup (localenv.fname)) == NULL) |
2781 | if ((result->filename = FP_strdup (localenv.fname)) == NULL) |
2782 | *errcode = UURET_NOMEM; |
2782 | *errcode = UURET_NOMEM; |
2783 | } |
2783 | } |
2784 | else if (sstate.envelope.fname) { |
2784 | else if (sstate.envelope.fname) { |
2785 | _FP_free (result->filename); |
2785 | FP_free (result->filename); |
2786 | if ((result->filename = _FP_strdup (sstate.envelope.fname)) == NULL) |
2786 | if ((result->filename = FP_strdup (sstate.envelope.fname)) == NULL) |
2787 | *errcode = UURET_NOMEM; |
2787 | *errcode = UURET_NOMEM; |
2788 | } |
2788 | } |
2789 | else if ((result->uudet==QP_ENCODED || result->uudet==PT_ENCODED) && |
2789 | else if ((result->uudet==QP_ENCODED || result->uudet==PT_ENCODED) && |
2790 | result->filename == NULL) { |
2790 | result->filename == NULL) { |
2791 | sprintf (line, "%04d.txt", ++mimseqno); |
2791 | sprintf (line, "%04d.txt", ++mimseqno); |
2792 | if ((result->filename = _FP_strdup (line)) == NULL) |
2792 | if ((result->filename = FP_strdup (line)) == NULL) |
2793 | *errcode = UURET_NOMEM; |
2793 | *errcode = UURET_NOMEM; |
2794 | } |
2794 | } |
2795 | else { |
2795 | else { |
2796 | /* assign a filename lateron */ |
2796 | /* assign a filename lateron */ |
2797 | } |
2797 | } |
2798 | if (result->subject == NULL) { |
2798 | if (result->subject == NULL) { |
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; |
2810 | |
2810 | |
2811 | if (uu_fast_scanning) |
2811 | if (uu_fast_scanning) |
2812 | result->length = progress.fsize - result->startpos; |
2812 | result->length = progress.fsize - result->startpos; |
2813 | else |
2813 | else |
2814 | result->length = prevpos - result->startpos; |
2814 | result->length = prevpos - result->startpos; |
2815 | |
2815 | |
2816 | if (result->sfname == NULL) |
2816 | if (result->sfname == NULL) |
2817 | result->sfname = _FP_strdup (fname); |
2817 | result->sfname = FP_strdup (fname); |
2818 | |
2818 | |
2819 | if (result->mode == 0) |
2819 | if (result->mode == 0) |
2820 | result->mode = 0644; |
2820 | result->mode = 0644; |
2821 | |
2821 | |
2822 | /* |
2822 | /* |
… | |
… | |
2856 | * decode a plain-text segment with a filename. |
2856 | * decode a plain-text segment with a filename. |
2857 | */ |
2857 | */ |
2858 | |
2858 | |
2859 | if (sstate.isfolder && sstate.ismime && |
2859 | if (sstate.isfolder && sstate.ismime && |
2860 | sstate.mimestate == MS_BODY && |
2860 | sstate.mimestate == MS_BODY && |
2861 | (_FP_stristr (sstate.envelope.ctenc, "quoted-printable") != NULL || |
2861 | (FP_stristr (sstate.envelope.ctenc, "quoted-printable") != NULL || |
2862 | _FP_stristr (sstate.envelope.ctenc, "base64") != NULL || |
2862 | FP_stristr (sstate.envelope.ctenc, "base64") != NULL || |
2863 | _FP_stristr (sstate.envelope.ctenc, "x-uue") != NULL || |
2863 | FP_stristr (sstate.envelope.ctenc, "x-uue") != NULL || |
2864 | _FP_stristr (sstate.envelope.ctenc, "x-yenc") != NULL || |
2864 | FP_stristr (sstate.envelope.ctenc, "x-yenc") != NULL || |
2865 | _FP_stristr (sstate.envelope.ctype, "message") != NULL || |
2865 | FP_stristr (sstate.envelope.ctype, "message") != NULL || |
2866 | sstate.envelope.fname != NULL)) { |
2866 | sstate.envelope.fname != NULL)) { |
2867 | |
2867 | |
2868 | if (sstate.envelope.subject) |
2868 | if (sstate.envelope.subject) |
2869 | result->subject = _FP_strdup (sstate.envelope.subject); |
2869 | result->subject = FP_strdup (sstate.envelope.subject); |
2870 | if (sstate.envelope.from) |
2870 | if (sstate.envelope.from) |
2871 | result->origin = _FP_strdup (sstate.envelope.from); |
2871 | result->origin = FP_strdup (sstate.envelope.from); |
2872 | |
2872 | |
2873 | if (sstate.envelope.ctype) |
2873 | if (sstate.envelope.ctype) |
2874 | result->mimetype = _FP_strdup (sstate.envelope.ctype); |
2874 | result->mimetype = FP_strdup (sstate.envelope.ctype); |
2875 | else |
2875 | else |
2876 | result->mimetype = _FP_strdup ("text/plain"); |
2876 | result->mimetype = FP_strdup ("text/plain"); |
2877 | |
2877 | |
2878 | if (_FP_stristr (sstate.envelope.ctenc, "quoted-printable") != NULL) |
2878 | if (FP_stristr (sstate.envelope.ctenc, "quoted-printable") != NULL) |
2879 | result->uudet = QP_ENCODED; |
2879 | result->uudet = QP_ENCODED; |
2880 | else if (_FP_stristr (sstate.envelope.ctenc, "base64") != NULL) |
2880 | else if (FP_stristr (sstate.envelope.ctenc, "base64") != NULL) |
2881 | result->uudet = B64ENCODED; |
2881 | result->uudet = B64ENCODED; |
2882 | else if (_FP_stristr (sstate.envelope.ctenc, "x-uue") != NULL) { |
2882 | else if (FP_stristr (sstate.envelope.ctenc, "x-uue") != NULL) { |
2883 | result->uudet = UU_ENCODED; |
2883 | result->uudet = UU_ENCODED; |
2884 | result->begin = result->end = 1; |
2884 | result->begin = result->end = 1; |
2885 | } |
2885 | } |
2886 | else if (_FP_stristr (sstate.envelope.ctenc, "x-yenc") != NULL) { |
2886 | else if (FP_stristr (sstate.envelope.ctenc, "x-yenc") != NULL) { |
2887 | result->uudet = YENC_ENCODED; |
2887 | result->uudet = YENC_ENCODED; |
2888 | } |
2888 | } |
2889 | else if (_FP_stristr (sstate.envelope.ctenc, "7bit") != NULL || |
2889 | else if (FP_stristr (sstate.envelope.ctenc, "7bit") != NULL || |
2890 | _FP_stristr (sstate.envelope.ctenc, "8bit") != NULL) |
2890 | FP_stristr (sstate.envelope.ctenc, "8bit") != NULL) |
2891 | result->uudet = PT_ENCODED; |
2891 | result->uudet = PT_ENCODED; |
2892 | else if (_FP_stristr (sstate.envelope.ctype, "multipart") != NULL || |
2892 | else if (FP_stristr (sstate.envelope.ctype, "multipart") != NULL || |
2893 | _FP_stristr (sstate.envelope.ctype, "message") != NULL || |
2893 | FP_stristr (sstate.envelope.ctype, "message") != NULL || |
2894 | sstate.envelope.fname != NULL) |
2894 | sstate.envelope.fname != NULL) |
2895 | result->uudet = PT_ENCODED; |
2895 | result->uudet = PT_ENCODED; |
2896 | |
2896 | |
2897 | /* |
2897 | /* |
2898 | * If we're switched to MIME-only mode, handle as text |
2898 | * If we're switched to MIME-only mode, handle as text |
… | |
… | |
2917 | } |
2917 | } |
2918 | else if (result->uudet != 0) { |
2918 | else if (result->uudet != 0) { |
2919 | hcount = lcount = 0; |
2919 | hcount = lcount = 0; |
2920 | prevpos = ftell (datei); |
2920 | prevpos = ftell (datei); |
2921 | |
2921 | |
2922 | if (_FP_stristr (sstate.envelope.ctype, "message") != NULL && |
2922 | if (FP_stristr (sstate.envelope.ctype, "message") != NULL && |
2923 | _FP_stristr (sstate.envelope.ctype, "rfc822") != NULL) { |
2923 | FP_stristr (sstate.envelope.ctype, "rfc822") != NULL) { |
2924 | /* |
2924 | /* |
2925 | * skip over empty lines and local header |
2925 | * skip over empty lines and local header |
2926 | */ |
2926 | */ |
2927 | preheaders = ftell (datei); |
2927 | preheaders = ftell (datei); |
2928 | while (!feof (datei)) { |
2928 | while (!FP_feof (datei)) { |
2929 | if (_FP_fgets (line, 1024, datei) == NULL) |
2929 | if (FP_fgets (line, 1024, datei) == NULL) |
2930 | break; |
2930 | break; |
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 (!FP_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; |
2942 | |
2942 | |
2943 | if (_FP_fgets (line, 1024, datei) == NULL) |
2943 | if (FP_fgets (line, 1024, datei) == NULL) |
2944 | break; |
2944 | break; |
2945 | } |
2945 | } |
2946 | if (hcount < hlcount.afternl) |
2946 | if (hcount < hlcount.afternl) |
2947 | fseek (datei, preheaders, SEEK_SET); |
2947 | fseek (datei, preheaders, SEEK_SET); |
2948 | hcount = lcount = 0; |
2948 | hcount = lcount = 0; |
… | |
… | |
2950 | |
2950 | |
2951 | /* |
2951 | /* |
2952 | * look for next header |
2952 | * look for next header |
2953 | */ |
2953 | */ |
2954 | |
2954 | |
2955 | while (!feof (datei)) { |
2955 | while (!FP_feof (datei)) { |
2956 | if (_FP_fgets (line, 1024, datei) == NULL) |
2956 | if (FP_fgets (line, 1024, datei) == NULL) |
2957 | break; |
2957 | break; |
2958 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
2958 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
2959 | if (ferror (datei)) |
2959 | if (ferror (datei)) |
2960 | break; |
2960 | break; |
2961 | |
2961 | |
… | |
… | |
3006 | } |
3006 | } |
3007 | /* |
3007 | /* |
3008 | * produce result |
3008 | * produce result |
3009 | */ |
3009 | */ |
3010 | if (sstate.envelope.fname) { |
3010 | if (sstate.envelope.fname) { |
3011 | _FP_free (result->filename); |
3011 | FP_free (result->filename); |
3012 | if ((result->filename = _FP_strdup (sstate.envelope.fname)) == NULL) |
3012 | if ((result->filename = FP_strdup (sstate.envelope.fname)) == NULL) |
3013 | *errcode = UURET_NOMEM; |
3013 | *errcode = UURET_NOMEM; |
3014 | } |
3014 | } |
3015 | else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) && |
3015 | else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) && |
3016 | result->filename == NULL) { |
3016 | result->filename == NULL) { |
3017 | sprintf (line, "%04d.txt", ++mimseqno); |
3017 | sprintf (line, "%04d.txt", ++mimseqno); |
3018 | if ((result->filename = _FP_strdup (line)) == NULL) |
3018 | if ((result->filename = FP_strdup (line)) == NULL) |
3019 | *errcode = UURET_NOMEM; |
3019 | *errcode = UURET_NOMEM; |
3020 | } |
3020 | } |
3021 | else { |
3021 | else { |
3022 | /* assign a filename lateron */ |
3022 | /* assign a filename lateron */ |
3023 | } |
3023 | } |
3024 | if (result->subject == NULL) { |
3024 | if (result->subject == NULL) { |
3025 | if (sstate.envelope.subject) |
3025 | if (sstate.envelope.subject) |
3026 | result->subject = _FP_strdup (sstate.envelope.subject); |
3026 | result->subject = FP_strdup (sstate.envelope.subject); |
3027 | } |
3027 | } |
3028 | result->flags = ((res==1||uu_fast_scanning)?FL_PROPER:0) | |
3028 | result->flags = ((res==1||uu_fast_scanning)?FL_PROPER:0) | |
3029 | ((uu_fast_scanning) ? FL_TOEND : 0); |
3029 | ((uu_fast_scanning) ? FL_TOEND : 0); |
3030 | result->mimeid = _FP_strdup (sstate.envelope.mimeid); |
3030 | result->mimeid = FP_strdup (sstate.envelope.mimeid); |
3031 | |
3031 | |
3032 | if (uu_fast_scanning) |
3032 | if (uu_fast_scanning) |
3033 | result->length = progress.fsize - result->startpos; |
3033 | result->length = progress.fsize - result->startpos; |
3034 | else |
3034 | else |
3035 | result->length = prevpos - result->startpos; |
3035 | result->length = prevpos - result->startpos; |
3036 | |
3036 | |
3037 | if (result->sfname == NULL) |
3037 | if (result->sfname == NULL) |
3038 | result->sfname = _FP_strdup (fname); |
3038 | result->sfname = FP_strdup (fname); |
3039 | |
3039 | |
3040 | if (result->mode == 0) |
3040 | if (result->mode == 0) |
3041 | result->mode = 0644; |
3041 | result->mode = 0644; |
3042 | |
3042 | |
3043 | /* |
3043 | /* |
… | |
… | |
3076 | * and if the following line is a proper Content-Type header. BTW, |
3076 | * and if the following line is a proper Content-Type header. BTW, |
3077 | * we know that sstate.envelope.boundary is NULL, or we wouldn't |
3077 | * we know that sstate.envelope.boundary is NULL, or we wouldn't |
3078 | * be here! |
3078 | * be here! |
3079 | */ |
3079 | */ |
3080 | |
3080 | |
3081 | if ((!sstate.envelope.ctype || _FP_stristr (sstate.envelope.ctype, "multipart")) |
3081 | if ((!sstate.envelope.ctype || FP_stristr (sstate.envelope.ctype, "multipart")) |
3082 | && !uu_more_mime) { |
3082 | && !uu_more_mime) { |
3083 | prevpos = ftell (datei); |
3083 | prevpos = ftell (datei); |
3084 | while (!feof (datei)) { |
3084 | while (!FP_feof (datei)) { |
3085 | if (_FP_fgets (line, 1024, datei) == NULL) |
3085 | if (FP_fgets (line, 1024, datei) == NULL) |
3086 | break; |
3086 | break; |
3087 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
3087 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
3088 | if (!IsLineEmpty (line)) |
3088 | if (!IsLineEmpty (line)) |
3089 | break; |
3089 | break; |
3090 | } |
3090 | } |
3091 | if (line[0] == '-' && line[1] == '-' && |
3091 | if (line[0] == '-' && line[1] == '-' && |
3092 | !IsLineEmpty (line+2) && !feof (datei)) { |
3092 | !IsLineEmpty (line+2) && !FP_feof (datei)) { |
3093 | ptr1 = _FP_strrstr (line+2, "--"); |
3093 | ptr1 = FP_strrstr (line+2, "--"); |
3094 | ptr2 = ScanHeaderLine (datei, NULL); |
3094 | ptr2 = ScanHeaderLine (datei, NULL); |
3095 | if ((ptr1 == NULL || ptr1[2]) && |
3095 | if ((ptr1 == NULL || ptr1[2]) && |
3096 | ptr2 && _FP_strnicmp (ptr2, "Content-", 8) == 0) { |
3096 | ptr2 && FP_strnicmp (ptr2, "Content-", 8) == 0) { |
3097 | /* |
3097 | /* |
3098 | * hmm, okay, let's do it! |
3098 | * hmm, okay, let's do it! |
3099 | */ |
3099 | */ |
3100 | sstate.isfolder = 1; |
3100 | sstate.isfolder = 1; |
3101 | sstate.ismime = 1; |
3101 | sstate.ismime = 1; |
… | |
… | |
3106 | ptr1 = line+2; |
3106 | ptr1 = line+2; |
3107 | while (*ptr1 && !isspace(*ptr1)) |
3107 | while (*ptr1 && !isspace(*ptr1)) |
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); |
3125 | } |
3125 | } |
… | |
… | |
3129 | * Freestyle time. Anyway, if this seems to be a Mime message, |
3129 | * Freestyle time. Anyway, if this seems to be a Mime message, |
3130 | * don't allow the minimal Base64 handling. |
3130 | * don't allow the minimal Base64 handling. |
3131 | */ |
3131 | */ |
3132 | |
3132 | |
3133 | if (sstate.envelope.subject) |
3133 | if (sstate.envelope.subject) |
3134 | result->subject = _FP_strdup (sstate.envelope.subject); |
3134 | result->subject = FP_strdup (sstate.envelope.subject); |
3135 | |
3135 | |
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; |
… | |
… | |
3162 | /* |
3162 | /* |
3163 | * prevent replacing the filename found on the =ybegin line |
3163 | * prevent replacing the filename found on the =ybegin line |
3164 | */ |
3164 | */ |
3165 | } |
3165 | } |
3166 | else if (sstate.envelope.fname) { |
3166 | else if (sstate.envelope.fname) { |
3167 | _FP_free (result->filename); |
3167 | FP_free (result->filename); |
3168 | if ((result->filename = _FP_strdup (sstate.envelope.fname)) == NULL) |
3168 | if ((result->filename = FP_strdup (sstate.envelope.fname)) == NULL) |
3169 | *errcode = UURET_NOMEM; |
3169 | *errcode = UURET_NOMEM; |
3170 | } |
3170 | } |
3171 | else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) && |
3171 | else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) && |
3172 | result->filename == NULL) { |
3172 | result->filename == NULL) { |
3173 | sprintf (line, "%04d.txt", ++mimseqno); |
3173 | sprintf (line, "%04d.txt", ++mimseqno); |
3174 | if ((result->filename = _FP_strdup (line)) == NULL) |
3174 | if ((result->filename = FP_strdup (line)) == NULL) |
3175 | *errcode = UURET_NOMEM; |
3175 | *errcode = UURET_NOMEM; |
3176 | } |
3176 | } |
3177 | else { |
3177 | else { |
3178 | /* assign a filename lateron */ |
3178 | /* assign a filename lateron */ |
3179 | } |
3179 | } |
3180 | |
3180 | |
3181 | if (result->subject == NULL) { |
3181 | if (result->subject == NULL) { |
3182 | if (sstate.envelope.subject) |
3182 | if (sstate.envelope.subject) |
3183 | result->subject = _FP_strdup (sstate.envelope.subject); |
3183 | result->subject = FP_strdup (sstate.envelope.subject); |
3184 | } |
3184 | } |
3185 | |
3185 | |
3186 | result->flags = (result->uudet==PT_ENCODED)?FL_SINGLE:0; |
3186 | result->flags = (result->uudet==PT_ENCODED)?FL_SINGLE:0; |
3187 | result->mimeid = _FP_strdup (sstate.envelope.mimeid); |
3187 | result->mimeid = FP_strdup (sstate.envelope.mimeid); |
3188 | result->length = ftell (datei) - result->startpos; |
3188 | result->length = ftell (datei) - result->startpos; |
3189 | |
3189 | |
3190 | if (result->mode == 0) |
3190 | if (result->mode == 0) |
3191 | result->mode = 0644; |
3191 | result->mode = 0644; |
3192 | |
3192 | |
3193 | if (result->sfname == NULL) |
3193 | if (result->sfname == NULL) |
3194 | result->sfname = _FP_strdup (fname); |
3194 | result->sfname = FP_strdup (fname); |
3195 | |
3195 | |
3196 | if (res == 1) { |
3196 | if (res == 1) { |
3197 | /* |
3197 | /* |
3198 | * new headers found |
3198 | * new headers found |
3199 | */ |
3199 | */ |
… | |
… | |
3222 | UUkillheaders (&localenv); |
3222 | UUkillheaders (&localenv); |
3223 | |
3223 | |
3224 | while (mssdepth) { |
3224 | while (mssdepth) { |
3225 | mssdepth--; |
3225 | mssdepth--; |
3226 | UUkillheaders (&(multistack[mssdepth].envelope)); |
3226 | UUkillheaders (&(multistack[mssdepth].envelope)); |
3227 | _FP_free (multistack[mssdepth].source); |
3227 | FP_free (multistack[mssdepth].source); |
3228 | } |
3228 | } |
3229 | |
3229 | |
3230 | return NULL; |
3230 | return NULL; |
3231 | } |
3231 | } |
3232 | |
3232 | |