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

Comparing Convert-UUlib/uulib/uuscan.c (file contents):
Revision 1.4 by root, Sun Mar 31 20:04:31 2002 UTC vs.
Revision 1.5 by root, Sun Mar 31 20:08:42 2002 UTC

55#include <uudeview.h> 55#include <uudeview.h>
56#include <uuint.h> 56#include <uuint.h>
57#include <fptools.h> 57#include <fptools.h>
58#include <uustring.h> 58#include <uustring.h>
59 59
60char * uuscan_id = "$Id: uuscan.c,v 1.4 2002/03/31 20:04:31 root Exp $"; 60char * uuscan_id = "$Id: uuscan.c,v 1.5 2002/03/31 20:08:42 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.
160 int llength, c; 160 int llength, c;
161 long curpos; 161 long curpos;
162 int hadcr; 162 int hadcr;
163 163
164 if (initial) { 164 if (initial) {
165 FP_strncpy (uuscan_shlline, initial, 1024); 165 _FP_strncpy (uuscan_shlline, initial, 1024);
166 } 166 }
167 else { 167 else {
168 /* read first line */ 168 /* read first line */
169 if (feof (datei) || ferror (datei)) 169 if (feof (datei) || ferror (datei))
170 return NULL; 170 return NULL;
171 if (FP_fgets (uuscan_shlline, 1023, datei) == NULL) 171 if (_FP_fgets (uuscan_shlline, 1023, datei) == NULL)
172 return NULL; 172 return NULL;
173 uuscan_shlline[1023] = '\0'; 173 uuscan_shlline[1023] = '\0';
174 } 174 }
175 175
176 llength = strlen (uuscan_shlline); 176 llength = strlen (uuscan_shlline);
219 if (feof (datei)) 219 if (feof (datei))
220 break; 220 break;
221 221
222 /* read next line */ 222 /* read next line */
223 curpos = ftell (datei); 223 curpos = ftell (datei);
224 if (FP_fgets (uugen_inbuffer, 255, datei) == NULL) 224 if (_FP_fgets (uugen_inbuffer, 255, datei) == NULL)
225 break; 225 break;
226 uugen_inbuffer[255] = '\0'; 226 uugen_inbuffer[255] = '\0';
227 227
228 if (IsLineEmpty (uugen_inbuffer)) { /* oops */ 228 if (IsLineEmpty (uugen_inbuffer)) { /* oops */
229 fseek (datei, curpos, SEEK_SET); 229 fseek (datei, curpos, SEEK_SET);
230 break; 230 break;
231 } 231 }
232 232
233 FP_strncpy (ptr, uugen_inbuffer, 1024-llength); 233 _FP_strncpy (ptr, uugen_inbuffer, 1024-llength);
234 234
235 /* 235 /*
236 * see if line was terminated with CR. Otherwise, it continues ... 236 * see if line was terminated with CR. Otherwise, it continues ...
237 */ 237 */
238 c = strlen (ptr); 238 c = strlen (ptr);
339 value = 0; delimit = 0; /* calm down gcc */ 339 value = 0; delimit = 0; /* calm down gcc */
340 340
341 if (line == NULL) 341 if (line == NULL)
342 return theheaders; 342 return theheaders;
343 343
344 if (FP_strnicmp (line, "From:", 5) == 0) { 344 if (_FP_strnicmp (line, "From:", 5) == 0) {
345 if (theheaders->from) return theheaders; 345 if (theheaders->from) return theheaders;
346 variable = &theheaders->from; 346 variable = &theheaders->from;
347 value = line+5; 347 value = line+5;
348 delimit = 0; 348 delimit = 0;
349 } 349 }
350 else if (FP_strnicmp (line, "Subject:", 8) == 0) { 350 else if (_FP_strnicmp (line, "Subject:", 8) == 0) {
351 if (theheaders->subject) return theheaders; 351 if (theheaders->subject) return theheaders;
352 variable = &theheaders->subject; 352 variable = &theheaders->subject;
353 value = line+8; 353 value = line+8;
354 delimit = 0; 354 delimit = 0;
355 } 355 }
356 else if (FP_strnicmp (line, "To:", 3) == 0) { 356 else if (_FP_strnicmp (line, "To:", 3) == 0) {
357 if (theheaders->rcpt) return theheaders; 357 if (theheaders->rcpt) return theheaders;
358 variable = &theheaders->rcpt; 358 variable = &theheaders->rcpt;
359 value = line+3; 359 value = line+3;
360 delimit = 0; 360 delimit = 0;
361 } 361 }
362 else if (FP_strnicmp (line, "Date:", 5) == 0) { 362 else if (_FP_strnicmp (line, "Date:", 5) == 0) {
363 if (theheaders->date) return theheaders; 363 if (theheaders->date) return theheaders;
364 variable = &theheaders->date; 364 variable = &theheaders->date;
365 value = line+5; 365 value = line+5;
366 delimit = 0; 366 delimit = 0;
367 } 367 }
368 else if (FP_strnicmp (line, "Mime-Version:", 13) == 0) { 368 else if (_FP_strnicmp (line, "Mime-Version:", 13) == 0) {
369 if (theheaders->mimevers) return theheaders; 369 if (theheaders->mimevers) return theheaders;
370 variable = &theheaders->mimevers; 370 variable = &theheaders->mimevers;
371 value = line+13; 371 value = line+13;
372 delimit = 0; 372 delimit = 0;
373 } 373 }
374 else if (FP_strnicmp (line, "Content-Type:", 13) == 0) { 374 else if (_FP_strnicmp (line, "Content-Type:", 13) == 0) {
375 if (theheaders->ctype) return theheaders; 375 if (theheaders->ctype) return theheaders;
376 variable = &theheaders->ctype; 376 variable = &theheaders->ctype;
377 value = line+13; 377 value = line+13;
378 delimit = ';'; 378 delimit = ';';
379 379
380 /* we can probably extract more information */ 380 /* we can probably extract more information */
381 if ((ptr = FP_stristr (line, "boundary")) != NULL) { 381 if ((ptr = _FP_stristr (line, "boundary")) != NULL) {
382 if ((thenew = ParseValue (ptr))) { 382 if ((thenew = ParseValue (ptr))) {
383 if (theheaders->boundary) free (theheaders->boundary); 383 if (theheaders->boundary) free (theheaders->boundary);
384 theheaders->boundary = FP_strdup (thenew); 384 theheaders->boundary = _FP_strdup (thenew);
385 }
386 } 385 }
386 }
387 if ((ptr = FP_stristr (line, "name")) != NULL) { 387 if ((ptr = _FP_stristr (line, "name")) != NULL) {
388 if ((thenew = ParseValue (ptr))) { 388 if ((thenew = ParseValue (ptr))) {
389 if (theheaders->fname) free (theheaders->fname); 389 if (theheaders->fname) free (theheaders->fname);
390 theheaders->fname = FP_strdup (thenew); 390 theheaders->fname = _FP_strdup (thenew);
391 }
392 } 391 }
392 }
393 if ((ptr = FP_stristr (line, "id")) != NULL) { 393 if ((ptr = _FP_stristr (line, "id")) != NULL) {
394 if ((thenew = ParseValue (ptr))) { 394 if ((thenew = ParseValue (ptr))) {
395 if (theheaders->mimeid) free (theheaders->mimeid); 395 if (theheaders->mimeid) free (theheaders->mimeid);
396 theheaders->mimeid = FP_strdup (thenew); 396 theheaders->mimeid = _FP_strdup (thenew);
397 }
398 } 397 }
398 }
399 if ((ptr = FP_stristr (line, "number")) != NULL) { 399 if ((ptr = _FP_stristr (line, "number")) != NULL) {
400 if ((thenew = ParseValue (ptr))) { 400 if ((thenew = ParseValue (ptr))) {
401 theheaders->partno = atoi (thenew); 401 theheaders->partno = atoi (thenew);
402 } 402 }
403 } 403 }
404 if ((ptr = FP_stristr (line, "total")) != NULL) { 404 if ((ptr = _FP_stristr (line, "total")) != NULL) {
405 if ((thenew = ParseValue (ptr))) { 405 if ((thenew = ParseValue (ptr))) {
406 theheaders->numparts = atoi (thenew); 406 theheaders->numparts = atoi (thenew);
407 } 407 }
408 } 408 }
409 } 409 }
410 else if (FP_strnicmp (line, "Content-Transfer-Encoding:", 26) == 0) { 410 else if (_FP_strnicmp (line, "Content-Transfer-Encoding:", 26) == 0) {
411 if (theheaders->ctenc) return theheaders; 411 if (theheaders->ctenc) return theheaders;
412 variable = &theheaders->ctenc; 412 variable = &theheaders->ctenc;
413 value = line+26; 413 value = line+26;
414 delimit = ';'; 414 delimit = ';';
415 } 415 }
416 else if (FP_strnicmp (line, "Content-Disposition:", 20) == 0) { 416 else if (_FP_strnicmp (line, "Content-Disposition:", 20) == 0) {
417 /* 417 /*
418 * Some encoders mention the original filename as parameter to 418 * Some encoders mention the original filename as parameter to
419 * Content-Type, others as parameter to Content-Disposition. We 419 * Content-Type, others as parameter to Content-Disposition. We
420 * do prefer the first solution, but accept this situation, too. 420 * do prefer the first solution, but accept this situation, too.
421 * TODO: Read RFC1806 421 * TODO: Read RFC1806
422 */ 422 */
423 if ((ptr = FP_stristr (line, "name")) != NULL) { 423 if ((ptr = _FP_stristr (line, "name")) != NULL) {
424 if (theheaders->fname == NULL && (thenew=ParseValue(ptr)) != NULL) { 424 if (theheaders->fname == NULL && (thenew=ParseValue(ptr)) != NULL) {
425 theheaders->fname = FP_strdup (thenew); 425 theheaders->fname = _FP_strdup (thenew);
426 } 426 }
427 } 427 }
428 variable = NULL; 428 variable = NULL;
429 } 429 }
430 else { 430 else {
451 while (length && isspace(*(ptr-1))) { 451 while (length && isspace(*(ptr-1))) {
452 ptr--; length--; 452 ptr--; length--;
453 } 453 }
454 *ptr = '\0'; 454 *ptr = '\0';
455 455
456 if ((*variable = FP_strdup (uuscan_phtext)) == NULL) 456 if ((*variable = _FP_strdup (uuscan_phtext)) == NULL)
457 return NULL; 457 return NULL;
458 } 458 }
459 459
460 return theheaders; 460 return theheaders;
461} 461}
468IsKnownHeader (char *line) 468IsKnownHeader (char *line)
469{ 469{
470 char **iter = knownmsgheaders; 470 char **iter = knownmsgheaders;
471 471
472 while (iter && *iter) { 472 while (iter && *iter) {
473 if (FP_strnicmp (line, *iter, strlen (*iter)) == 0) 473 if (_FP_strnicmp (line, *iter, strlen (*iter)) == 0)
474 return 1; 474 return 1;
475 iter++; 475 iter++;
476 } 476 }
477 477
478 iter = knownmimeheaders; 478 iter = knownmimeheaders;
479 479
480 while (iter && *iter) { 480 while (iter && *iter) {
481 if (FP_strnicmp (line, *iter, strlen (*iter)) == 0) 481 if (_FP_strnicmp (line, *iter, strlen (*iter)) == 0)
482 return 2; 482 return 2;
483 iter++; 483 iter++;
484 } 484 }
485 485
486 return 0; 486 return 0;
556 if (boundary) 556 if (boundary)
557 blen = strlen (boundary); 557 blen = strlen (boundary);
558 558
559 while (!feof (datei)) { 559 while (!feof (datei)) {
560 oldposition = ftell (datei); 560 oldposition = ftell (datei);
561 if (FP_fgets (line, 299, datei) == NULL) 561 if (_FP_fgets (line, 299, datei) == NULL)
562 break; 562 break;
563 if (ferror (datei)) 563 if (ferror (datei))
564 break; 564 break;
565 565
566 line[299] = '\0'; /* For Safety of string functions */ 566 line[299] = '\0'; /* For Safety of string functions */
631 strncmp (line+2, boundary, blen) == 0) { 631 strncmp (line+2, boundary, blen) == 0) {
632 fseek (datei, oldposition, SEEK_SET); 632 fseek (datei, oldposition, SEEK_SET);
633 break; 633 break;
634 } 634 }
635 if (boundary != NULL && line[0] == 'C' && line[1] == 'o' && 635 if (boundary != NULL && line[0] == 'C' && line[1] == 'o' &&
636 FP_strnicmp (line, "Content-Type:", 13) == 0) { 636 _FP_strnicmp (line, "Content-Type:", 13) == 0) {
637 ptr = ScanHeaderLine (datei, line); 637 ptr = ScanHeaderLine (datei, line);
638 p2 = (ptr)?FP_stristr(ptr,"boundary"):NULL; 638 p2 = (ptr)?_FP_stristr(ptr,"boundary"):NULL;
639 p3 = (p2)?ParseValue(p2):NULL; 639 p3 = (p2)?ParseValue(p2):NULL;
640 640
641 if (p3 && strcmp (p3, boundary) == 0) { 641 if (p3 && strcmp (p3, boundary) == 0) {
642 fseek (datei, oldposition, SEEK_SET); 642 fseek (datei, oldposition, SEEK_SET);
643 break; 643 break;
646 p3 = NULL; 646 p3 = NULL;
647 } 647 }
648 } 648 }
649 649
650 if (strncmp (line, "begin ", 6) == 0 || 650 if (strncmp (line, "begin ", 6) == 0 ||
651 FP_strnicmp (line, "<pre>begin ", 11) == 0) { 651 _FP_strnicmp (line, "<pre>begin ", 11) == 0) {
652 if ((result->begin || result->end || 652 if ((result->begin || result->end ||
653 result->uudet == B64ENCODED || 653 result->uudet == B64ENCODED ||
654 result->uudet == BH_ENCODED) && !uu_more_mime) { 654 result->uudet == BH_ENCODED) && !uu_more_mime) {
655 fseek (datei, oldposition, SEEK_SET); 655 fseek (datei, oldposition, SEEK_SET);
656 break; 656 break;
667 while (*ptr == ' ') ptr++; 667 while (*ptr == ' ') ptr++;
668 668
669 /* 669 /*
670 * We may have picked up a filename from a uuenview-style header 670 * We may have picked up a filename from a uuenview-style header
671 */ 671 */
672 FP_free (result->filename); 672 _FP_free (result->filename);
673 result->filename = FP_strdup (ptr); 673 result->filename = _FP_strdup (ptr);
674 result->begin = 1; 674 result->begin = 1;
675 675
676 while (isspace (result->filename[strlen(result->filename)-1])) 676 while (isspace (result->filename[strlen(result->filename)-1]))
677 result->filename[strlen(result->filename)-1] = '\0'; 677 result->filename[strlen(result->filename)-1] = '\0';
678 678
697 697
698 /* 698 /*
699 * Detect a UUDeview-Style header 699 * Detect a UUDeview-Style header
700 */ 700 */
701 701
702 if (FP_strnicmp (line, "_=_ Part ", 9) == 0 && 702 if (_FP_strnicmp (line, "_=_ Part ", 9) == 0 &&
703 result->uudet != YENC_ENCODED) { 703 result->uudet != YENC_ENCODED) {
704 if (result->uudet) { 704 if (result->uudet) {
705 fseek (datei, oldposition, SEEK_SET); 705 fseek (datei, oldposition, SEEK_SET);
706 break; 706 break;
707 } 707 }
708 result->partno = atoi (line + 8); 708 result->partno = atoi (line + 8);
709 if ((ptr = FP_stristr (line, "of file ")) != NULL) { 709 if ((ptr = _FP_stristr (line, "of file ")) != NULL) {
710 ptr += 8; 710 ptr += 8;
711 while (isspace (*ptr)) ptr++; 711 while (isspace (*ptr)) ptr++;
712 p2 = ptr; 712 p2 = ptr;
713 while (isalnum(*p2) || 713 while (isalnum(*p2) ||
714 *p2 == '.' || *p2=='_' || *p2 == '-' || 714 *p2 == '.' || *p2=='_' || *p2 == '-' ||
715 *p2 == '!' || *p2=='@' || *p2 == '$') 715 *p2 == '!' || *p2=='@' || *p2 == '$')
716 p2++; 716 p2++;
717 c = *p2; *p2 = '\0'; 717 c = *p2; *p2 = '\0';
718 if (p2 != ptr && result->filename == NULL) 718 if (p2 != ptr && result->filename == NULL)
719 result->filename = FP_strdup (ptr); 719 result->filename = _FP_strdup (ptr);
720 else if (p2 - ptr > 5 && strchr (ptr, '.') != NULL) { 720 else if (p2 - ptr > 5 && strchr (ptr, '.') != NULL) {
721 /* 721 /*
722 * This file name looks good, too. Let's use it 722 * This file name looks good, too. Let's use it
723 */ 723 */
724 FP_free (result->filename); 724 _FP_free (result->filename);
725 result->filename = FP_strdup (ptr); 725 result->filename = _FP_strdup (ptr);
726 } 726 }
727 *p2 = c; 727 *p2 = c;
728 } 728 }
729 } 729 }
730 730
732 * Some reduced MIME handling. Only use if boundary == NULL. Also 732 * Some reduced MIME handling. Only use if boundary == NULL. Also
733 * accept the "X-Orcl-Content-Type" used by some braindead program. 733 * accept the "X-Orcl-Content-Type" used by some braindead program.
734 */ 734 */
735 if (boundary == NULL && !ismime && !uu_more_mime && 735 if (boundary == NULL && !ismime && !uu_more_mime &&
736 result->uudet != YENC_ENCODED) { 736 result->uudet != YENC_ENCODED) {
737 if (FP_strnicmp (line, "Content-Type", 12) == 0 || 737 if (_FP_strnicmp (line, "Content-Type", 12) == 0 ||
738 FP_strnicmp (line, "X-Orcl-Content-Type", 19) == 0) { 738 _FP_strnicmp (line, "X-Orcl-Content-Type", 19) == 0) {
739 /* 739 /*
740 * We use Content-Type to mark a new attachment and split the file. 740 * We use Content-Type to mark a new attachment and split the file.
741 * However, we do not split if we haven't found anything encoded yet. 741 * However, we do not split if we haven't found anything encoded yet.
742 */ 742 */
743 if (result->uudet) { 743 if (result->uudet) {
748 ptr++; 748 ptr++;
749 while (isspace (*ptr)) ptr++; p2 = ptr; 749 while (isspace (*ptr)) ptr++; p2 = ptr;
750 while (!isspace (*p2) && *p2 != ';') p2++; 750 while (!isspace (*p2) && *p2 != ';') p2++;
751 c = *p2; *p2 = '\0'; 751 c = *p2; *p2 = '\0';
752 if (p2 != ptr) { 752 if (p2 != ptr) {
753 FP_free (result->mimetype); 753 _FP_free (result->mimetype);
754 result->mimetype = FP_strdup (ptr); 754 result->mimetype = _FP_strdup (ptr);
755 } 755 }
756 *p2 = c; 756 *p2 = c;
757 } 757 }
758 ctline=0; 758 ctline=0;
759 hadct=1; 759 hadct=1;
760 } 760 }
761 if ((ptr = FP_stristr (line, "number=")) && ctline<4) { 761 if ((ptr = _FP_stristr (line, "number=")) && ctline<4) {
762 ptr += 7; if (*ptr == '"') ptr++; 762 ptr += 7; if (*ptr == '"') ptr++;
763 result->partno = atoi (ptr); 763 result->partno = atoi (ptr);
764 } 764 }
765 if ((ptr = FP_stristr (line, "total=")) && ctline<4) { 765 if ((ptr = _FP_stristr (line, "total=")) && ctline<4) {
766 ptr += 6; if (*ptr == '"') ptr++; 766 ptr += 6; if (*ptr == '"') ptr++;
767 result->maxpno = atoi (ptr); 767 result->maxpno = atoi (ptr);
768 } 768 }
769 if ((ptr = FP_stristr (line, "name=")) && ctline<4) { 769 if ((ptr = _FP_stristr (line, "name=")) && ctline<4) {
770 ptr += 5; 770 ptr += 5;
771 while (isspace (*ptr)) ptr++; 771 while (isspace (*ptr)) ptr++;
772 if (*ptr == '"' && *(ptr+1) && (p2 = strchr (ptr+2, '"')) != NULL) { 772 if (*ptr == '"' && *(ptr+1) && (p2 = strchr (ptr+2, '"')) != NULL) {
773 c = *p2; *p2 = '\0'; 773 c = *p2; *p2 = '\0';
774 FP_free (result->filename); 774 _FP_free (result->filename);
775 result->filename = FP_strdup (ptr+1); 775 result->filename = _FP_strdup (ptr+1);
776 *p2 = c; 776 *p2 = c;
777 } 777 }
778 else if (*ptr=='\''&&*(ptr+1)&&(p2 = strchr(ptr+2, '\'')) != NULL) { 778 else if (*ptr=='\''&&*(ptr+1)&&(p2 = strchr(ptr+2, '\'')) != NULL) {
779 c = *p2; *p2 = '\0'; 779 c = *p2; *p2 = '\0';
780 FP_free (result->filename); 780 _FP_free (result->filename);
781 result->filename = FP_strdup (ptr+1); 781 result->filename = _FP_strdup (ptr+1);
782 *p2 = c; 782 *p2 = c;
783 } 783 }
784 else { 784 else {
785 p2 = ptr; 785 p2 = ptr;
786 while (isalnum(*p2) || 786 while (isalnum(*p2) ||
787 *p2 == '.' || *p2=='_' || *p2 == '-' || 787 *p2 == '.' || *p2=='_' || *p2 == '-' ||
788 *p2 == '!' || *p2=='@' || *p2 == '$') 788 *p2 == '!' || *p2=='@' || *p2 == '$')
789 p2++; 789 p2++;
790 c = *p2; *p2 = '\0'; 790 c = *p2; *p2 = '\0';
791 if (p2 != ptr && result->filename == NULL) 791 if (p2 != ptr && result->filename == NULL)
792 result->filename = FP_strdup (ptr); 792 result->filename = _FP_strdup (ptr);
793 else if (p2 - ptr > 5 && strchr (ptr, '.') != NULL) { 793 else if (p2 - ptr > 5 && strchr (ptr, '.') != NULL) {
794 /* 794 /*
795 * This file name looks good, too. Let's use it 795 * This file name looks good, too. Let's use it
796 */ 796 */
797 FP_free (result->filename); 797 _FP_free (result->filename);
798 result->filename = FP_strdup (ptr); 798 result->filename = _FP_strdup (ptr);
799 } 799 }
800 *p2 = c; 800 *p2 = c;
801 } 801 }
802 } 802 }
803 if ((ptr = FP_stristr (line, "id=")) && ctline<4) { 803 if ((ptr = _FP_stristr (line, "id=")) && ctline<4) {
804 p2 = ptr += 3; 804 p2 = ptr += 3;
805 if (*p2 == '"') { 805 if (*p2 == '"') {
806 p2 = strchr (++ptr, '"'); 806 p2 = strchr (++ptr, '"');
807 } 807 }
808 else { 808 else {
810 p2++; 810 p2++;
811 } 811 }
812 if (p2 && *p2 && p2!=ptr) { 812 if (p2 && *p2 && p2!=ptr) {
813 c = *p2; *p2 = '\0'; 813 c = *p2; *p2 = '\0';
814 if (result->mimeid) 814 if (result->mimeid)
815 FP_free (result->mimeid); 815 _FP_free (result->mimeid);
816 result->mimeid = FP_strdup (ptr); 816 result->mimeid = _FP_strdup (ptr);
817 *p2 = c; 817 *p2 = c;
818 } 818 }
819 } 819 }
820 820
821 /* 821 /*
842 * a boundary, followed by a Content-* line, try to use it. 842 * a boundary, followed by a Content-* line, try to use it.
843 */ 843 */
844 844
845 if (boundary == NULL && !ismime && !uu_more_mime && dflag <= 1 && 845 if (boundary == NULL && !ismime && !uu_more_mime && dflag <= 1 &&
846 line[0] == '-' && line[1] == '-' && strlen(line+2)>10 && 846 line[0] == '-' && line[1] == '-' && strlen(line+2)>10 &&
847 (((ptr = FP_strrstr (line+2, "--")) == NULL) || 847 (((ptr = _FP_strrstr (line+2, "--")) == NULL) ||
848 (*(ptr+2) != '\012' && *(ptr+2) != '\015')) && 848 (*(ptr+2) != '\012' && *(ptr+2) != '\015')) &&
849 FP_strstr (line+2, "_=_") != NULL) { 849 _FP_strstr (line+2, "_=_") != NULL) {
850 if (FP_fgets (line, 255, datei) == NULL) { 850 if (_FP_fgets (line, 255, datei) == NULL) {
851 break; 851 break;
852 } 852 }
853 if (FP_strnicmp (line, "Content-", 8) == 0) { 853 if (_FP_strnicmp (line, "Content-", 8) == 0) {
854 /* 854 /*
855 * Okay, let's do it. This breaks out of ScanData. ScanPart will 855 * Okay, let's do it. This breaks out of ScanData. ScanPart will
856 * recognize the boundary on the next call and use it. 856 * recognize the boundary on the next call and use it.
857 */ 857 */
858 fseek (datei, oldposition, SEEK_SET); 858 fseek (datei, oldposition, SEEK_SET);
863 /* 863 /*
864 * Detection for yEnc encoding 864 * Detection for yEnc encoding
865 */ 865 */
866 866
867 if (strncmp (line, "=ybegin ", 8) == 0 && 867 if (strncmp (line, "=ybegin ", 8) == 0 &&
868 FP_strstr (line, " size=") != NULL && 868 _FP_strstr (line, " size=") != NULL &&
869 FP_strstr (line, " name=") != NULL) { 869 _FP_strstr (line, " name=") != NULL) {
870 if ((result->begin || result->end) && !uu_more_mime) { 870 if ((result->begin || result->end) && !uu_more_mime) {
871 fseek (datei, oldposition, SEEK_SET); 871 fseek (datei, oldposition, SEEK_SET);
872 break; 872 break;
873 } 873 }
874 874
875 /* 875 /*
876 * name continues to the end of the line 876 * name continues to the end of the line
877 */ 877 */
878 878
879 FP_free (result->filename); 879 _FP_free (result->filename);
880 ptr = FP_strstr (line, " name=") + 6; 880 ptr = _FP_strstr (line, " name=") + 6;
881 result->filename = FP_strdup (ptr); 881 result->filename = _FP_strdup (ptr);
882 882
883 while (isspace (result->filename[strlen(result->filename)-1])) 883 while (isspace (result->filename[strlen(result->filename)-1]))
884 result->filename[strlen(result->filename)-1] = '\0'; 884 result->filename[strlen(result->filename)-1] = '\0';
885 885
886 /* 886 /*
887 * Determine size 887 * Determine size
888 */ 888 */
889 889
890 ptr = FP_strstr (line, " size=") + 6; 890 ptr = _FP_strstr (line, " size=") + 6;
891 yefilesize = atoi (ptr); 891 yefilesize = atoi (ptr);
892 892
893 /* 893 /*
894 * check for multipart file and read =ypart line 894 * check for multipart file and read =ypart line
895 */ 895 */
896 896
897 if ((ptr = FP_strstr (line, " part=")) != NULL) { 897 if ((ptr = _FP_strstr (line, " part=")) != NULL) {
898 result->partno = atoi (ptr + 6); 898 result->partno = atoi (ptr + 6);
899 899
900 if (result->partno == 1) { 900 if (result->partno == 1) {
901 result->begin = 1; 901 result->begin = 1;
902 } 902 }
903 903
904 if (FP_fgets (line, 255, datei) == NULL) { 904 if (_FP_fgets (line, 255, datei) == NULL) {
905 break; 905 break;
906 } 906 }
907 907
908 line[255] = '\0'; 908 line[255] = '\0';
909 909
910 if (strncmp (line, "=ypart ", 7) != 0) { 910 if (strncmp (line, "=ypart ", 7) != 0) {
911 break; 911 break;
912 } 912 }
913 913
914 if ((ptr = FP_strstr (line, " end=")) == NULL) { 914 if ((ptr = _FP_strstr (line, " end=")) == NULL) {
915 break; 915 break;
916 } 916 }
917 917
918 yepartends = atoi (ptr + 5); 918 yepartends = atoi (ptr + 5);
919 } 919 }
1018 } 1018 }
1019 if ((bhdsp-bhds2) > (int) bhds2[0] && bhds2[0]>0 && 1019 if ((bhdsp-bhds2) > (int) bhds2[0] && bhds2[0]>0 &&
1020 result->filename==NULL) { 1020 result->filename==NULL) {
1021 memcpy (bhds1, bhds2+1, (int) bhds2[0]); 1021 memcpy (bhds1, bhds2+1, (int) bhds2[0]);
1022 bhds1[(int)bhds2[0]]='\0'; 1022 bhds1[(int)bhds2[0]]='\0';
1023 result->filename = FP_strdup (bhds1); 1023 result->filename = _FP_strdup (bhds1);
1024 bhnf = 1; 1024 bhnf = 1;
1025 } 1025 }
1026 else if (bhdsp-bhds2 >= 256 && bhds2[0]>0) { 1026 else if (bhdsp-bhds2 >= 256 && bhds2[0]>0) {
1027 memcpy (bhds1, bhds2+1, 255); 1027 memcpy (bhds1, bhds2+1, 255);
1028 bhds1[255] = '\0'; 1028 bhds1[255] = '\0';
1029 result->filename = FP_strdup (bhds1); 1029 result->filename = _FP_strdup (bhds1);
1030 bhnf = 1; 1030 bhnf = 1;
1031 } 1031 }
1032 else if (bhds2[0] <= 0) 1032 else if (bhds2[0] <= 0)
1033 bhnf = 1; 1033 bhnf = 1;
1034 } 1034 }
1099 *errcode = UURET_CANCEL; 1099 *errcode = UURET_CANCEL;
1100 break; 1100 break;
1101 } 1101 }
1102 1102
1103 oldposition = ftell (datei); 1103 oldposition = ftell (datei);
1104 if (FP_fgets (line, 255, datei) == NULL) 1104 if (_FP_fgets (line, 255, datei) == NULL)
1105 break; 1105 break;
1106 if (ferror (datei)) 1106 if (ferror (datei))
1107 break; 1107 break;
1108 1108
1109 line[255] = '\0'; 1109 line[255] = '\0';
1338 if (boundary && line[0] == '-' && line[1] == '-' && 1338 if (boundary && line[0] == '-' && line[1] == '-' &&
1339 strncmp (line+2, boundary, blen) == 0) 1339 strncmp (line+2, boundary, blen) == 0)
1340 return 2; 1340 return 2;
1341 else if (boundary && p3 && 1341 else if (boundary && p3 &&
1342 line[0] == 'C' && line[1] == 'o' && 1342 line[0] == 'C' && line[1] == 'o' &&
1343 FP_strnicmp (line, "Content-Type:", 13) == 0 && 1343 _FP_strnicmp (line, "Content-Type:", 13) == 0 &&
1344 strcmp (p3, boundary) == 0) 1344 strcmp (p3, boundary) == 0)
1345 return 2; 1345 return 2;
1346 else if (IsKnownHeader (line)) 1346 else if (IsKnownHeader (line))
1347 return 1; 1347 return 1;
1348 1348
1390 /* mimseqno = 1; */ 1390 /* mimseqno = 1; */
1391 1391
1392 while (mssdepth) { 1392 while (mssdepth) {
1393 mssdepth--; 1393 mssdepth--;
1394 UUkillheaders (&(multistack[mssdepth].envelope)); 1394 UUkillheaders (&(multistack[mssdepth].envelope));
1395 FP_free (multistack[mssdepth].source); 1395 _FP_free (multistack[mssdepth].source);
1396 } 1396 }
1397 1397
1398 UUkillheaders (&sstate.envelope); 1398 UUkillheaders (&sstate.envelope);
1399 memset (&sstate.envelope, 0, sizeof (headers)); 1399 memset (&sstate.envelope, 0, sizeof (headers));
1400 1400
1401 FP_free (sstate.source); 1401 _FP_free (sstate.source);
1402 if ((sstate.source = FP_strdup (fname)) == NULL) { 1402 if ((sstate.source = _FP_strdup (fname)) == NULL) {
1403 *errcode = UURET_NOMEM; 1403 *errcode = UURET_NOMEM;
1404 FP_free (result); 1404 _FP_free (result);
1405 return NULL; 1405 return NULL;
1406 } 1406 }
1407 1407
1408 /* ignore empty lines at the beginning of a file */ 1408 /* ignore empty lines at the beginning of a file */
1409 preheaders = ftell (datei); 1409 preheaders = ftell (datei);
1410 while (!feof (datei)) { 1410 while (!feof (datei)) {
1411 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 1411 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
1412 if (FP_fgets (line, 255, datei) == NULL) 1412 if (_FP_fgets (line, 255, datei) == NULL)
1413 break; 1413 break;
1414 if (!IsLineEmpty (line)) { 1414 if (!IsLineEmpty (line)) {
1415 fseek (datei, preheaders, SEEK_SET); 1415 fseek (datei, preheaders, SEEK_SET);
1416 line[255] = '\0'; 1416 line[255] = '\0';
1417 break; 1417 break;
1419 preheaders = ftell (datei); 1419 preheaders = ftell (datei);
1420 } 1420 }
1421 } 1421 }
1422 1422
1423 if (ferror(datei) || feof(datei)) { 1423 if (ferror(datei) || feof(datei)) {
1424 FP_free (result); 1424 _FP_free (result);
1425 return NULL; 1425 return NULL;
1426 } 1426 }
1427 1427
1428 /* 1428 /*
1429 * If we are confident that this is a mail folder and are at the 1429 * If we are confident that this is a mail folder and are at the
1441 */ 1441 */
1442 1442
1443 while (mssdepth) { 1443 while (mssdepth) {
1444 mssdepth--; 1444 mssdepth--;
1445 UUkillheaders (&(multistack[mssdepth].envelope)); 1445 UUkillheaders (&(multistack[mssdepth].envelope));
1446 FP_free (multistack[mssdepth].source); 1446 _FP_free (multistack[mssdepth].source);
1447 } 1447 }
1448 1448
1449 if (FP_fgets (line, 255, datei) == NULL) { 1449 if (_FP_fgets (line, 255, datei) == NULL) {
1450 FP_free (result); 1450 _FP_free (result);
1451 return NULL; 1451 return NULL;
1452 } 1452 }
1453 line[255] = '\0'; 1453 line[255] = '\0';
1454 1454
1455 /* 1455 /*
1465 line[strlen(line)-1] == '\015') { 1465 line[strlen(line)-1] == '\015') {
1466 line[strlen(line)-1] = '\0'; 1466 line[strlen(line)-1] = '\0';
1467 } 1467 }
1468 1468
1469 sstate.ismime = 1; 1469 sstate.ismime = 1;
1470 sstate.envelope.mimevers = FP_strdup ("1.0"); 1470 sstate.envelope.mimevers = _FP_strdup ("1.0");
1471 sstate.envelope.boundary = FP_strdup (line+2); 1471 sstate.envelope.boundary = _FP_strdup (line+2);
1472 sstate.envelope.ctype = FP_strdup ("multipart/mixed"); 1472 sstate.envelope.ctype = _FP_strdup ("multipart/mixed");
1473 sstate.mimestate = MS_SUBPART; 1473 sstate.mimestate = MS_SUBPART;
1474 1474
1475 *errcode = UURET_CONT; 1475 *errcode = UURET_CONT;
1476 FP_free (result); 1476 _FP_free (result);
1477 return NULL; 1477 return NULL;
1478 } 1478 }
1479 1479
1480 /* 1480 /*
1481 * Normal behavior: look for a RFC 822 header 1481 * Normal behavior: look for a RFC 822 header
1486 hcount++; 1486 hcount++;
1487 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 1487 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
1488 ptr1 = ScanHeaderLine (datei, line); 1488 ptr1 = ScanHeaderLine (datei, line);
1489 if (ParseHeader (&sstate.envelope, ptr1) == NULL) { 1489 if (ParseHeader (&sstate.envelope, ptr1) == NULL) {
1490 *errcode = UURET_NOMEM; 1490 *errcode = UURET_NOMEM;
1491 FP_free (result); 1491 _FP_free (result);
1492 return NULL; 1492 return NULL;
1493 } 1493 }
1494 /* 1494 /*
1495 * if we've read too many lines without finding headers, then 1495 * if we've read too many lines without finding headers, then
1496 * this probably isn't a mail folder after all 1496 * this probably isn't a mail folder after all
1497 */ 1497 */
1498 lcount++; 1498 lcount++;
1499 if (lcount > WAITHEADER && hcount < hlcount.afternl) 1499 if (lcount > WAITHEADER && hcount < hlcount.afternl)
1500 break; 1500 break;
1501 1501
1502 if (FP_fgets (line, 255, datei) == NULL) 1502 if (_FP_fgets (line, 255, datei) == NULL)
1503 break; 1503 break;
1504 line[255] = '\0'; 1504 line[255] = '\0';
1505 } 1505 }
1506 /* skip empty lines */ 1506 /* skip empty lines */
1507 prevpos = ftell (datei); 1507 prevpos = ftell (datei);
1508 while (!feof (datei)) { 1508 while (!feof (datei)) {
1509 if (FP_fgets (line, 255, datei) == NULL) 1509 if (_FP_fgets (line, 255, datei) == NULL)
1510 break; 1510 break;
1511 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 1511 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
1512 if (!IsLineEmpty (line)) { 1512 if (!IsLineEmpty (line)) {
1513 fseek (datei, prevpos, SEEK_SET); 1513 fseek (datei, prevpos, SEEK_SET);
1514 line[255] = '\0'; 1514 line[255] = '\0';
1527 sstate.envelope.ctenc == NULL && 1527 sstate.envelope.ctenc == NULL &&
1528 IsKnownHeader (line)) { 1528 IsKnownHeader (line)) {
1529 /* 1529 /*
1530 * see above 1530 * see above
1531 */ 1531 */
1532 if (FP_fgets (line, 255, datei) == NULL) { 1532 if (_FP_fgets (line, 255, datei) == NULL) {
1533 line[0] = '\012'; 1533 line[0] = '\012';
1534 line[1] = '\0'; 1534 line[1] = '\0';
1535 } 1535 }
1536 line[255] = '\0'; 1536 line[255] = '\0';
1537 1537
1540 hcount++; 1540 hcount++;
1541 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 1541 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
1542 ptr1 = ScanHeaderLine (datei, line); 1542 ptr1 = ScanHeaderLine (datei, line);
1543 if (ParseHeader (&sstate.envelope, ptr1) == NULL) { 1543 if (ParseHeader (&sstate.envelope, ptr1) == NULL) {
1544 *errcode = UURET_NOMEM; 1544 *errcode = UURET_NOMEM;
1545 FP_free (result); 1545 _FP_free (result);
1546 return NULL; 1546 return NULL;
1547 } 1547 }
1548 1548
1549 if (FP_fgets (line, 255, datei) == NULL) 1549 if (_FP_fgets (line, 255, datei) == NULL)
1550 break; 1550 break;
1551 line[255] = '\0'; 1551 line[255] = '\0';
1552 } 1552 }
1553 /* skip empty lines */ 1553 /* skip empty lines */
1554 prevpos = ftell (datei); 1554 prevpos = ftell (datei);
1555 while (!feof (datei)) { 1555 while (!feof (datei)) {
1556 if (FP_fgets (line, 255, datei) == NULL) 1556 if (_FP_fgets (line, 255, datei) == NULL)
1557 break; 1557 break;
1558 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 1558 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
1559 if (!IsLineEmpty (line)) { 1559 if (!IsLineEmpty (line)) {
1560 fseek (datei, prevpos, SEEK_SET); 1560 fseek (datei, prevpos, SEEK_SET);
1561 line[255] = '\0'; 1561 line[255] = '\0';
1571 * MIME message 1571 * MIME message
1572 * if mimevers is not set but there are other well-known MIME 1572 * if mimevers is not set but there are other well-known MIME
1573 * headers, don't be too picky about it. 1573 * headers, don't be too picky about it.
1574 */ 1574 */
1575 if (sstate.envelope.ctype && sstate.envelope.mimevers==NULL && 1575 if (sstate.envelope.ctype && sstate.envelope.mimevers==NULL &&
1576 FP_stristr (sstate.envelope.ctype, "multipart") != NULL && 1576 _FP_stristr (sstate.envelope.ctype, "multipart") != NULL &&
1577 sstate.envelope.boundary != NULL) { 1577 sstate.envelope.boundary != NULL) {
1578 sstate.envelope.mimevers = FP_strdup ("1.0"); 1578 sstate.envelope.mimevers = _FP_strdup ("1.0");
1579 hcount = hlcount.afternl; 1579 hcount = hlcount.afternl;
1580 } 1580 }
1581 else if (sstate.envelope.mimevers==NULL && sstate.envelope.ctype && 1581 else if (sstate.envelope.mimevers==NULL && sstate.envelope.ctype &&
1582 sstate.envelope.fname && sstate.envelope.ctenc) { 1582 sstate.envelope.fname && sstate.envelope.ctenc) {
1583 sstate.envelope.mimevers = FP_strdup ("1.0"); 1583 sstate.envelope.mimevers = _FP_strdup ("1.0");
1584 hcount = hlcount.afternl; 1584 hcount = hlcount.afternl;
1585 } 1585 }
1586 1586
1587 if (hcount < hlcount.afternl) { 1587 if (hcount < hlcount.afternl) {
1588 /* not a folder after all */ 1588 /* not a folder after all */
1591 sstate.ismime = 0; 1591 sstate.ismime = 0;
1592 } 1592 }
1593 else if (sstate.envelope.mimevers != NULL) { 1593 else if (sstate.envelope.mimevers != NULL) {
1594 /* this is a MIME file. check the Content-Type */ 1594 /* this is a MIME file. check the Content-Type */
1595 sstate.ismime = 1; 1595 sstate.ismime = 1;
1596 if (FP_stristr (sstate.envelope.ctype, "multipart") != NULL) { 1596 if (_FP_stristr (sstate.envelope.ctype, "multipart") != NULL) {
1597 if (sstate.envelope.boundary == NULL) { 1597 if (sstate.envelope.boundary == NULL) {
1598 UUMessage (uuscan_id, __LINE__, UUMSG_WARNING, 1598 UUMessage (uuscan_id, __LINE__, UUMSG_WARNING,
1599 uustring (S_MIME_NO_BOUNDARY)); 1599 uustring (S_MIME_NO_BOUNDARY));
1600 sstate.mimestate = MS_BODY; 1600 sstate.mimestate = MS_BODY;
1601 FP_free (sstate.envelope.ctype); 1601 _FP_free (sstate.envelope.ctype);
1602 sstate.envelope.ctype = FP_strdup ("text/plain"); 1602 sstate.envelope.ctype = _FP_strdup ("text/plain");
1603 } 1603 }
1604 else { 1604 else {
1605 sstate.mimestate = MS_PREAMBLE; 1605 sstate.mimestate = MS_PREAMBLE;
1606 } 1606 }
1607 } 1607 }
1610 } 1610 }
1611 } 1611 }
1612 } 1612 }
1613 1613
1614 if (feof (datei) || ferror (datei)) { /* oops */ 1614 if (feof (datei) || ferror (datei)) { /* oops */
1615 FP_free (result); 1615 _FP_free (result);
1616 return NULL; 1616 return NULL;
1617 } 1617 }
1618 1618
1619 /* 1619 /*
1620 * Handle MIME stuff 1620 * Handle MIME stuff
1632 1632
1633 blen = strlen (sstate.envelope.boundary); 1633 blen = strlen (sstate.envelope.boundary);
1634 lcount = 0; 1634 lcount = 0;
1635 1635
1636 while (!feof (datei)) { 1636 while (!feof (datei)) {
1637 if (FP_fgets (line, 255, datei) == NULL) { 1637 if (_FP_fgets (line, 255, datei) == NULL) {
1638 line[0] = '\0'; 1638 line[0] = '\0';
1639 break; 1639 break;
1640 } 1640 }
1641 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 1641 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
1642 if (line[0] == '-' && line[1] == '-' && 1642 if (line[0] == '-' && line[1] == '-' &&
1659 1659
1660 if (!uu_fast_scanning) { 1660 if (!uu_fast_scanning) {
1661 *errcode = UURET_CONT; 1661 *errcode = UURET_CONT;
1662 fseek (datei, preheaders, SEEK_SET); 1662 fseek (datei, preheaders, SEEK_SET);
1663 } 1663 }
1664 FP_free (result); 1664 _FP_free (result);
1665 return NULL; 1665 return NULL;
1666 } 1666 }
1667 if (line[0] == '-' && line[1] == '-' && 1667 if (line[0] == '-' && line[1] == '-' &&
1668 strncmp (line+2, sstate.envelope.boundary, blen) == 0) { 1668 strncmp (line+2, sstate.envelope.boundary, blen) == 0) {
1669 ptr1 = line + 2 + blen; 1669 ptr1 = line + 2 + blen;
1687 1687
1688 if (!uu_fast_scanning) { 1688 if (!uu_fast_scanning) {
1689 *errcode = UURET_CONT; 1689 *errcode = UURET_CONT;
1690 fseek (datei, preheaders, SEEK_SET); 1690 fseek (datei, preheaders, SEEK_SET);
1691 } 1691 }
1692 FP_free (result); 1692 _FP_free (result);
1693 return NULL; 1693 return NULL;
1694 } 1694 }
1695 /* produce result if uu_usepreamble is set */ 1695 /* produce result if uu_usepreamble is set */
1696 if (uu_usepreamble && lcount) { 1696 if (uu_usepreamble && lcount) {
1697 sprintf (line, "%04d.txt", ++mimseqno); 1697 sprintf (line, "%04d.txt", ++mimseqno);
1698 result->subject = FP_strdup (sstate.envelope.subject); 1698 result->subject = _FP_strdup (sstate.envelope.subject);
1699 result->filename = FP_strdup (line); 1699 result->filename = _FP_strdup (line);
1700 result->origin = FP_strdup (sstate.envelope.from); 1700 result->origin = _FP_strdup (sstate.envelope.from);
1701 result->mimeid = FP_strdup (sstate.envelope.mimeid); 1701 result->mimeid = _FP_strdup (sstate.envelope.mimeid);
1702 result->mimetype = FP_strdup ("text/plain"); 1702 result->mimetype = _FP_strdup ("text/plain");
1703 result->mode = 0644; 1703 result->mode = 0644;
1704 result->uudet = PT_ENCODED; /* plain text */ 1704 result->uudet = PT_ENCODED; /* plain text */
1705 result->sfname = FP_strdup (fname); 1705 result->sfname = _FP_strdup (fname);
1706 result->flags = FL_SINGLE | FL_PROPER; 1706 result->flags = FL_SINGLE | FL_PROPER;
1707 /* result->startpos set from above */ 1707 /* result->startpos set from above */
1708 result->length = prevpos - result->startpos; 1708 result->length = prevpos - result->startpos;
1709 result->partno = 1; 1709 result->partno = 1;
1710 1710
1721 /* MIME message, let's continue */ 1721 /* MIME message, let's continue */
1722 if (*errcode == UURET_OK) 1722 if (*errcode == UURET_OK)
1723 *errcode = UURET_CONT; 1723 *errcode = UURET_CONT;
1724 1724
1725 /* otherwise, just return NULL */ 1725 /* otherwise, just return NULL */
1726 FP_free (result); 1726 _FP_free (result);
1727 return NULL; 1727 return NULL;
1728 } 1728 }
1729 1729
1730 /* 1730 /*
1731 * Read Epilogue, the plain text after the last boundary. 1731 * Read Epilogue, the plain text after the last boundary.
1758 if (uu_fast_scanning && mssdepth == 0) { 1758 if (uu_fast_scanning && mssdepth == 0) {
1759 /* 1759 /*
1760 * check if the epilogue is empty 1760 * check if the epilogue is empty
1761 */ 1761 */
1762 while (!feof (datei) && !ferror (datei) && lcount<10 && res==0) { 1762 while (!feof (datei) && !ferror (datei) && lcount<10 && res==0) {
1763 if (FP_fgets (line, 255, datei) == NULL) 1763 if (_FP_fgets (line, 255, datei) == NULL)
1764 break; 1764 break;
1765 if (!IsLineEmpty (line)) 1765 if (!IsLineEmpty (line))
1766 res++; 1766 res++;
1767 lcount++; 1767 lcount++;
1768 } 1768 }
1769 if (uu_usepreamble && res) { 1769 if (uu_usepreamble && res) {
1770 sprintf (line, "%04d.txt", ++mimseqno); 1770 sprintf (line, "%04d.txt", ++mimseqno);
1771 result->subject = FP_strdup (sstate.envelope.subject); 1771 result->subject = _FP_strdup (sstate.envelope.subject);
1772 result->filename = FP_strdup (line); 1772 result->filename = _FP_strdup (line);
1773 result->origin = FP_strdup (sstate.envelope.from); 1773 result->origin = _FP_strdup (sstate.envelope.from);
1774 result->mimeid = FP_strdup (sstate.envelope.mimeid); 1774 result->mimeid = _FP_strdup (sstate.envelope.mimeid);
1775 result->mimetype = FP_strdup ("text/plain"); 1775 result->mimetype = _FP_strdup ("text/plain");
1776 result->mode = 0644; 1776 result->mode = 0644;
1777 result->uudet = PT_ENCODED; /* plain text */ 1777 result->uudet = PT_ENCODED; /* plain text */
1778 result->sfname = FP_strdup (fname); 1778 result->sfname = _FP_strdup (fname);
1779 result->flags = FL_SINGLE | FL_PROPER | FL_TOEND; 1779 result->flags = FL_SINGLE | FL_PROPER | FL_TOEND;
1780 result->partno = 1; 1780 result->partno = 1;
1781 /* result->startpos set from above */ 1781 /* result->startpos set from above */
1782 result->length = progress.fsize - result->startpos; 1782 result->length = progress.fsize - result->startpos;
1783 1783
1786 *errcode = UURET_NOMEM; 1786 *errcode = UURET_NOMEM;
1787 } 1787 }
1788 1788
1789 return result; 1789 return result;
1790 } 1790 }
1791 FP_free (result); 1791 _FP_free (result);
1792 return NULL; 1792 return NULL;
1793 } 1793 }
1794 1794
1795 if (mssdepth > 0) 1795 if (mssdepth > 0)
1796 blen = strlen (multistack[mssdepth-1].envelope.boundary); 1796 blen = strlen (multistack[mssdepth-1].envelope.boundary);
1797 1797
1798 while (!feof (datei)) { 1798 while (!feof (datei)) {
1799 if (FP_fgets (line, 255, datei) == NULL) { 1799 if (_FP_fgets (line, 255, datei) == NULL) {
1800 line[0] = '\0'; 1800 line[0] = '\0';
1801 break; 1801 break;
1802 } 1802 }
1803 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 1803 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
1804 line[255] = '\0'; 1804 line[255] = '\0';
1835 } 1835 }
1836 1836
1837 /* check for begin and encoded data only at outermost level */ 1837 /* check for begin and encoded data only at outermost level */
1838 if (mssdepth == 0 && !uu_more_mime) { 1838 if (mssdepth == 0 && !uu_more_mime) {
1839 if (strncmp (line, "begin ", 6) == 0 || 1839 if (strncmp (line, "begin ", 6) == 0 ||
1840 FP_strnicmp (line, "<pre>begin ", 11) == 0) { 1840 _FP_strnicmp (line, "<pre>begin ", 11) == 0) {
1841 preenc = prevpos; 1841 preenc = prevpos;
1842 begflag = 1; 1842 begflag = 1;
1843 } 1843 }
1844 else if (strncmp (line, "end", 3) == 0 && begflag) { 1844 else if (strncmp (line, "end", 3) == 0 && begflag) {
1845 ecount = ELC_COUNT; 1845 ecount = ELC_COUNT;
1878 strncmp (line+2, 1878 strncmp (line+2,
1879 multistack[mssdepth-1].envelope.boundary, blen) == 0) { 1879 multistack[mssdepth-1].envelope.boundary, blen) == 0) {
1880 /* restore previous state */ 1880 /* restore previous state */
1881 mssdepth--; 1881 mssdepth--;
1882 UUkillheaders (&sstate.envelope); 1882 UUkillheaders (&sstate.envelope);
1883 FP_free (sstate.source); 1883 _FP_free (sstate.source);
1884 memcpy (&sstate, &(multistack[mssdepth]), sizeof (scanstate)); 1884 memcpy (&sstate, &(multistack[mssdepth]), sizeof (scanstate));
1885 1885
1886 ptr1 = line + 2 + strlen (sstate.envelope.boundary); 1886 ptr1 = line + 2 + strlen (sstate.envelope.boundary);
1887 1887
1888 if (*ptr1 == '-' && *(ptr1+1) == '-') { 1888 if (*ptr1 == '-' && *(ptr1+1) == '-') {
1905 sstate.mimestate = MS_BODY; 1905 sstate.mimestate = MS_BODY;
1906 1906
1907 while (mssdepth) { 1907 while (mssdepth) {
1908 mssdepth--; 1908 mssdepth--;
1909 UUkillheaders (&(multistack[mssdepth].envelope)); 1909 UUkillheaders (&(multistack[mssdepth].envelope));
1910 FP_free (multistack[mssdepth].source); 1910 _FP_free (multistack[mssdepth].source);
1911 } 1911 }
1912 1912
1913 if (!uu_fast_scanning) { 1913 if (!uu_fast_scanning) {
1914 *errcode = UURET_CONT; 1914 *errcode = UURET_CONT;
1915 fseek (datei, preheaders, SEEK_SET); 1915 fseek (datei, preheaders, SEEK_SET);
1916 } 1916 }
1917 FP_free (result); 1917 _FP_free (result);
1918 return NULL; 1918 return NULL;
1919 } 1919 }
1920 else if (IsKnownHeader (line)) { 1920 else if (IsKnownHeader (line)) {
1921 /* new message follows */ 1921 /* new message follows */
1922 sstate.isfolder = 1; 1922 sstate.isfolder = 1;
1935 } 1935 }
1936 1936
1937 /* produce result if uu_usepreamble is set */ 1937 /* produce result if uu_usepreamble is set */
1938 if (uu_usepreamble && res) { 1938 if (uu_usepreamble && res) {
1939 sprintf (line, "%04d.txt", ++mimseqno); 1939 sprintf (line, "%04d.txt", ++mimseqno);
1940 result->subject = FP_strdup (sstate.envelope.subject); 1940 result->subject = _FP_strdup (sstate.envelope.subject);
1941 result->filename = FP_strdup (line); 1941 result->filename = _FP_strdup (line);
1942 result->origin = FP_strdup (sstate.envelope.from); 1942 result->origin = _FP_strdup (sstate.envelope.from);
1943 result->mimeid = FP_strdup (sstate.envelope.mimeid); 1943 result->mimeid = _FP_strdup (sstate.envelope.mimeid);
1944 result->mimetype = FP_strdup ("text/plain"); 1944 result->mimetype = _FP_strdup ("text/plain");
1945 result->mode = 0644; 1945 result->mode = 0644;
1946 result->uudet = PT_ENCODED; /* plain text */ 1946 result->uudet = PT_ENCODED; /* plain text */
1947 result->sfname = FP_strdup (fname); 1947 result->sfname = _FP_strdup (fname);
1948 result->flags = FL_SINGLE | FL_PROPER; 1948 result->flags = FL_SINGLE | FL_PROPER;
1949 result->partno = 1; 1949 result->partno = 1;
1950 /* result->startpos set from above */ 1950 /* result->startpos set from above */
1951 /* result->length set from above */ 1951 /* result->length set from above */
1952 1952
1956 } 1956 }
1957 1957
1958 return result; 1958 return result;
1959 } 1959 }
1960 /* otherwise, just return NULL */ 1960 /* otherwise, just return NULL */
1961 FP_free (result); 1961 _FP_free (result);
1962 return NULL; 1962 return NULL;
1963 } 1963 }
1964 1964
1965 /* 1965 /*
1966 * Scan a new part from a Multipart message. Check for a new local 1966 * Scan a new part from a Multipart message. Check for a new local
1980 1980
1981 /* 1981 /*
1982 * Duplicate some data from outer envelope 1982 * Duplicate some data from outer envelope
1983 */ 1983 */
1984 1984
1985 localenv.mimevers = FP_strdup (sstate.envelope.mimevers); 1985 localenv.mimevers = _FP_strdup (sstate.envelope.mimevers);
1986 localenv.from = FP_strdup (sstate.envelope.from); 1986 localenv.from = _FP_strdup (sstate.envelope.from);
1987 localenv.subject = FP_strdup (sstate.envelope.subject); 1987 localenv.subject = _FP_strdup (sstate.envelope.subject);
1988 localenv.rcpt = FP_strdup (sstate.envelope.rcpt); 1988 localenv.rcpt = _FP_strdup (sstate.envelope.rcpt);
1989 localenv.date = FP_strdup (sstate.envelope.date); 1989 localenv.date = _FP_strdup (sstate.envelope.date);
1990 1990
1991 if ((sstate.envelope.mimevers != NULL && localenv.mimevers == NULL) || 1991 if ((sstate.envelope.mimevers != NULL && localenv.mimevers == NULL) ||
1992 (sstate.envelope.from != NULL && localenv.from == NULL) || 1992 (sstate.envelope.from != NULL && localenv.from == NULL) ||
1993 (sstate.envelope.subject != NULL && localenv.subject == NULL) || 1993 (sstate.envelope.subject != NULL && localenv.subject == NULL) ||
1994 (sstate.envelope.rcpt != NULL && localenv.rcpt == NULL) || 1994 (sstate.envelope.rcpt != NULL && localenv.rcpt == NULL) ||
1995 (sstate.envelope.date != NULL && localenv.date == NULL)) { 1995 (sstate.envelope.date != NULL && localenv.date == NULL)) {
1996 1996
1997 while (mssdepth) { 1997 while (mssdepth) {
1998 mssdepth--; 1998 mssdepth--;
1999 UUkillheaders (&(multistack[mssdepth].envelope)); 1999 UUkillheaders (&(multistack[mssdepth].envelope));
2000 FP_free (multistack[mssdepth].source); 2000 _FP_free (multistack[mssdepth].source);
2001 } 2001 }
2002 sstate.isfolder = 0; 2002 sstate.isfolder = 0;
2003 sstate.ismime = 0; 2003 sstate.ismime = 0;
2004 2004
2005 UUkillheaders (&localenv); 2005 UUkillheaders (&localenv);
2006 *errcode = UURET_NOMEM; 2006 *errcode = UURET_NOMEM;
2007 FP_free (result); 2007 _FP_free (result);
2008 return NULL; 2008 return NULL;
2009 } 2009 }
2010 2010
2011 /* Scan subheader. But what if there is no subheader? */ 2011 /* Scan subheader. But what if there is no subheader? */
2012 hcount = 0; 2012 hcount = 0;
2013 lcount = 0; 2013 lcount = 0;
2014 preheaders = prevpos; 2014 preheaders = prevpos;
2015 2015
2016 if (FP_fgets (line, 255, datei) == NULL) { 2016 if (_FP_fgets (line, 255, datei) == NULL) {
2017 sstate.isfolder = 0; 2017 sstate.isfolder = 0;
2018 sstate.ismime = 0; 2018 sstate.ismime = 0;
2019 while (mssdepth) { 2019 while (mssdepth) {
2020 mssdepth--; 2020 mssdepth--;
2021 UUkillheaders (&(multistack[mssdepth].envelope)); 2021 UUkillheaders (&(multistack[mssdepth].envelope));
2022 FP_free (multistack[mssdepth].source); 2022 _FP_free (multistack[mssdepth].source);
2023 } 2023 }
2024 UUkillheaders (&localenv); 2024 UUkillheaders (&localenv);
2025 FP_free (result); 2025 _FP_free (result);
2026 return NULL; 2026 return NULL;
2027 } 2027 }
2028 line[255] = '\0'; 2028 line[255] = '\0';
2029 2029
2030 while (!feof (datei) && !IsLineEmpty (line)) { 2030 while (!feof (datei) && !IsLineEmpty (line)) {
2043 if (line[0] == '-' && line[1] == '-') 2043 if (line[0] == '-' && line[1] == '-')
2044 break; 2044 break;
2045 2045
2046 prevpos = ftell (datei); 2046 prevpos = ftell (datei);
2047 2047
2048 if (FP_fgets (line, 255, datei) == NULL) 2048 if (_FP_fgets (line, 255, datei) == NULL)
2049 break; 2049 break;
2050 line[255] = '\0'; 2050 line[255] = '\0';
2051 lcount++; 2051 lcount++;
2052 } 2052 }
2053 if (line[0] == '-' && line[1] == '-') { 2053 if (line[0] == '-' && line[1] == '-') {
2057 * boundary, so that it gets handled below 2057 * boundary, so that it gets handled below
2058 */ 2058 */
2059 fseek (datei, prevpos, SEEK_SET); 2059 fseek (datei, prevpos, SEEK_SET);
2060 } 2060 }
2061 2061
2062 if (FP_stristr (localenv.ctype, "multipart") != NULL) { 2062 if (_FP_stristr (localenv.ctype, "multipart") != NULL) {
2063 /* oh no, not again */ 2063 /* oh no, not again */
2064 if (mssdepth >= MSMAXDEPTH) { 2064 if (mssdepth >= MSMAXDEPTH) {
2065 /* Argh, what an isane message. Treat as plain text */ 2065 /* Argh, what an isane message. Treat as plain text */
2066 UUMessage (uuscan_id, __LINE__, UUMSG_WARNING, 2066 UUMessage (uuscan_id, __LINE__, UUMSG_WARNING,
2067 uustring (S_MIME_MULTI_DEPTH)); 2067 uustring (S_MIME_MULTI_DEPTH));
2073 else { 2073 else {
2074 memcpy (&multistack[mssdepth], &sstate, sizeof (scanstate)); 2074 memcpy (&multistack[mssdepth], &sstate, sizeof (scanstate));
2075 memcpy (&sstate.envelope, &localenv, sizeof (headers)); 2075 memcpy (&sstate.envelope, &localenv, sizeof (headers));
2076 memset (&localenv, 0, sizeof (headers)); 2076 memset (&localenv, 0, sizeof (headers));
2077 sstate.mimestate = MS_PREAMBLE; 2077 sstate.mimestate = MS_PREAMBLE;
2078 if ((sstate.source = FP_strdup (sstate.source)) == NULL) 2078 if ((sstate.source = _FP_strdup (sstate.source)) == NULL)
2079 *errcode = UURET_NOMEM; 2079 *errcode = UURET_NOMEM;
2080 2080
2081 if (*errcode == UURET_OK) 2081 if (*errcode == UURET_OK)
2082 *errcode = UURET_CONT; 2082 *errcode = UURET_CONT;
2083 2083
2084 mssdepth++; 2084 mssdepth++;
2085 /* need a restart */ 2085 /* need a restart */
2086 FP_free (result); 2086 _FP_free (result);
2087 return NULL; 2087 return NULL;
2088 } 2088 }
2089 } 2089 }
2090 2090
2091 /* 2091 /*
2099 * text. 2099 * text.
2100 * This is done because users might `attach' a uuencoded file, which 2100 * This is done because users might `attach' a uuencoded file, which
2101 * would then be correctly typed as `text/plain'. 2101 * would then be correctly typed as `text/plain'.
2102 */ 2102 */
2103 2103
2104 if (FP_stristr (localenv.ctenc, "base64") != NULL) 2104 if (_FP_stristr (localenv.ctenc, "base64") != NULL)
2105 result->uudet = B64ENCODED; 2105 result->uudet = B64ENCODED;
2106 else if (FP_stristr (localenv.ctenc, "x-uue") != NULL) { 2106 else if (_FP_stristr (localenv.ctenc, "x-uue") != NULL) {
2107 result->uudet = UU_ENCODED; 2107 result->uudet = UU_ENCODED;
2108 result->begin = result->end = 1; 2108 result->begin = result->end = 1;
2109 } 2109 }
2110 else if (FP_stristr (localenv.ctenc, "x-yenc") != NULL) { 2110 else if (_FP_stristr (localenv.ctenc, "x-yenc") != NULL) {
2111 result->uudet = YENC_ENCODED; 2111 result->uudet = YENC_ENCODED;
2112 result->begin = result->end = 1; 2112 result->begin = result->end = 1;
2113 } 2113 }
2114 else if (FP_stristr (localenv.ctenc, "quoted-printable") != NULL) 2114 else if (_FP_stristr (localenv.ctenc, "quoted-printable") != NULL)
2115 result->uudet = QP_ENCODED; 2115 result->uudet = QP_ENCODED;
2116 else if (FP_stristr (localenv.ctenc, "7bit") != NULL || 2116 else if (_FP_stristr (localenv.ctenc, "7bit") != NULL ||
2117 FP_stristr (localenv.ctenc, "8bit") != NULL) 2117 _FP_stristr (localenv.ctenc, "8bit") != NULL)
2118 result->uudet = PT_ENCODED; 2118 result->uudet = PT_ENCODED;
2119 else if (FP_stristr (localenv.ctype, "multipart") != NULL || 2119 else if (_FP_stristr (localenv.ctype, "multipart") != NULL ||
2120 FP_stristr (localenv.ctype, "message") != NULL) 2120 _FP_stristr (localenv.ctype, "message") != NULL)
2121 result->uudet = PT_ENCODED; 2121 result->uudet = PT_ENCODED;
2122 2122
2123 /* 2123 /*
2124 * If we're switched to MIME-only mode, handle as text 2124 * If we're switched to MIME-only mode, handle as text
2125 */ 2125 */
2136 prevpos = ftell (datei); 2136 prevpos = ftell (datei);
2137 blen = strlen (sstate.envelope.boundary); 2137 blen = strlen (sstate.envelope.boundary);
2138 lcount = 0; 2138 lcount = 0;
2139 2139
2140 while (!feof (datei)) { 2140 while (!feof (datei)) {
2141 if (FP_fgets (line, 255, datei) == NULL) { 2141 if (_FP_fgets (line, 255, datei) == NULL) {
2142 line[0] = '\0'; 2142 line[0] = '\0';
2143 break; 2143 break;
2144 } 2144 }
2145 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 2145 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
2146 line[255] = '\0'; 2146 line[255] = '\0';
2155 * This check here doesn't cover folded header lines, but we don't 2155 * This check here doesn't cover folded header lines, but we don't
2156 * want to slow down scanning too much. We just check for 2156 * want to slow down scanning too much. We just check for
2157 * Content-Type: multipart/... boundary="same-boundary" 2157 * Content-Type: multipart/... boundary="same-boundary"
2158 */ 2158 */
2159 if (line[0] == 'C' && line[1] == 'o' && 2159 if (line[0] == 'C' && line[1] == 'o' &&
2160 FP_strnicmp (line, "Content-Type:", 13) == 0) { 2160 _FP_strnicmp (line, "Content-Type:", 13) == 0) {
2161 ptr1 = ScanHeaderLine (datei, line); 2161 ptr1 = ScanHeaderLine (datei, line);
2162 ptr2 = (ptr1)?FP_stristr(ptr1,"boundary"):NULL; 2162 ptr2 = (ptr1)?_FP_stristr(ptr1,"boundary"):NULL;
2163 ptr1 = (ptr2)?ParseValue(ptr2):NULL; 2163 ptr1 = (ptr2)?ParseValue(ptr2):NULL;
2164 if (ptr1 && strcmp (ptr1, sstate.envelope.boundary) == 0) 2164 if (ptr1 && strcmp (ptr1, sstate.envelope.boundary) == 0)
2165 break; 2165 break;
2166 for (res=0; ptr1 && res<mssdepth; res++) 2166 for (res=0; ptr1 && res<mssdepth; res++)
2167 if (strcmp (ptr1, multistack[res].envelope.boundary) == 0) 2167 if (strcmp (ptr1, multistack[res].envelope.boundary) == 0)
2186 uustring (S_MIME_B_NOT_FOUND)); 2186 uustring (S_MIME_B_NOT_FOUND));
2187 2187
2188 while (mssdepth) { 2188 while (mssdepth) {
2189 mssdepth--; 2189 mssdepth--;
2190 UUkillheaders (&(multistack[mssdepth].envelope)); 2190 UUkillheaders (&(multistack[mssdepth].envelope));
2191 FP_free (multistack[mssdepth].source); 2191 _FP_free (multistack[mssdepth].source);
2192 } 2192 }
2193 /* 2193 /*
2194 * Don't retry if uu_fast_scanning 2194 * Don't retry if uu_fast_scanning
2195 */ 2195 */
2196 2196
2197 if (uu_fast_scanning) { 2197 if (uu_fast_scanning) {
2198 UUkillheaders (&localenv); 2198 UUkillheaders (&localenv);
2199 sstate.isfolder = 0; 2199 sstate.isfolder = 0;
2200 sstate.ismime = 0; 2200 sstate.ismime = 0;
2201 sstate.mimestate = MS_BODY; 2201 sstate.mimestate = MS_BODY;
2202 FP_free (result); 2202 _FP_free (result);
2203 return NULL; 2203 return NULL;
2204 } 2204 }
2205 2205
2206 /* 2206 /*
2207 * Retry, but listening to headers this time 2207 * Retry, but listening to headers this time
2241 } 2241 }
2242 /* produce result if uu_handletext is set */ 2242 /* produce result if uu_handletext is set */
2243 /* or if the file is explicitely named */ 2243 /* or if the file is explicitely named */
2244 if (result->uudet == B64ENCODED || lcount) { 2244 if (result->uudet == B64ENCODED || lcount) {
2245 if (localenv.fname) { 2245 if (localenv.fname) {
2246 FP_free (result->filename); 2246 _FP_free (result->filename);
2247 if ((result->filename = FP_strdup (localenv.fname)) == NULL) 2247 if ((result->filename = _FP_strdup (localenv.fname)) == NULL)
2248 *errcode = UURET_NOMEM; 2248 *errcode = UURET_NOMEM;
2249 } 2249 }
2250 else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) && 2250 else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) &&
2251 result->filename == NULL && uu_handletext) { 2251 result->filename == NULL && uu_handletext) {
2252 sprintf (line, "%04d.txt", ++mimseqno); 2252 sprintf (line, "%04d.txt", ++mimseqno);
2253 if ((result->filename = FP_strdup (line)) == NULL) 2253 if ((result->filename = _FP_strdup (line)) == NULL)
2254 *errcode = UURET_NOMEM; 2254 *errcode = UURET_NOMEM;
2255 } 2255 }
2256 result->subject = FP_strdup (localenv.subject); 2256 result->subject = _FP_strdup (localenv.subject);
2257 result->origin = FP_strdup (localenv.from); 2257 result->origin = _FP_strdup (localenv.from);
2258 result->mimeid = FP_strdup (localenv.mimeid); 2258 result->mimeid = _FP_strdup (localenv.mimeid);
2259 result->mimetype = FP_strdup (localenv.ctype); 2259 result->mimetype = _FP_strdup (localenv.ctype);
2260 result->mode = 0644; 2260 result->mode = 0644;
2261 result->sfname = FP_strdup (fname); 2261 result->sfname = _FP_strdup (fname);
2262 result->flags = FL_SINGLE | FL_PROPER; 2262 result->flags = FL_SINGLE | FL_PROPER;
2263 result->partno = 1; 2263 result->partno = 1;
2264 /* result->uudet determined above */ 2264 /* result->uudet determined above */
2265 /* result->startpos set from above */ 2265 /* result->startpos set from above */
2266 result->length = prevpos - result->startpos; 2266 result->length = prevpos - result->startpos;
2270 *errcode = UURET_NOMEM; 2270 *errcode = UURET_NOMEM;
2271 } 2271 }
2272 } 2272 }
2273 else { 2273 else {
2274 /* don't produce a result */ 2274 /* don't produce a result */
2275 FP_free (result); 2275 _FP_free (result);
2276 result = NULL; 2276 result = NULL;
2277 } 2277 }
2278 if (*errcode == UURET_OK) 2278 if (*errcode == UURET_OK)
2279 *errcode = UURET_CONT; 2279 *errcode = UURET_CONT;
2280 /* 2280 /*
2305 */ 2305 */
2306 blen = strlen (sstate.envelope.boundary); 2306 blen = strlen (sstate.envelope.boundary);
2307 prevpos = ftell (datei); 2307 prevpos = ftell (datei);
2308 2308
2309 while (!feof (datei)) { 2309 while (!feof (datei)) {
2310 if (FP_fgets (line, 255, datei) == NULL) { 2310 if (_FP_fgets (line, 255, datei) == NULL) {
2311 line[0] = '\0'; 2311 line[0] = '\0';
2312 break; 2312 break;
2313 } 2313 }
2314 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 2314 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
2315 line[255] = '\0'; 2315 line[255] = '\0';
2316 if (line[0] == '-' && line[1] == '-' && 2316 if (line[0] == '-' && line[1] == '-' &&
2317 strncmp (line+2, sstate.envelope.boundary, blen) == 0) 2317 strncmp (line+2, sstate.envelope.boundary, blen) == 0)
2318 break; 2318 break;
2319 if (line[0] == 'C' && line[1] == 'o' && 2319 if (line[0] == 'C' && line[1] == 'o' &&
2320 FP_strnicmp (line, "Content-Type:", 13) == 0) { 2320 _FP_strnicmp (line, "Content-Type:", 13) == 0) {
2321 ptr1 = ScanHeaderLine (datei, line); 2321 ptr1 = ScanHeaderLine (datei, line);
2322 ptr2 = (ptr1)?FP_stristr(ptr1,"boundary"):NULL; 2322 ptr2 = (ptr1)?_FP_stristr(ptr1,"boundary"):NULL;
2323 ptr1 = (ptr2)?ParseValue(ptr2):NULL; 2323 ptr1 = (ptr2)?ParseValue(ptr2):NULL;
2324 if (ptr1 && strcmp (ptr1, sstate.envelope.boundary) == 0) 2324 if (ptr1 && strcmp (ptr1, sstate.envelope.boundary) == 0)
2325 break; 2325 break;
2326 } 2326 }
2327 prevpos = ftell (datei); 2327 prevpos = ftell (datei);
2342 uustring (S_MIME_B_NOT_FOUND)); 2342 uustring (S_MIME_B_NOT_FOUND));
2343 2343
2344 while (mssdepth) { 2344 while (mssdepth) {
2345 mssdepth--; 2345 mssdepth--;
2346 UUkillheaders (&(multistack[mssdepth].envelope)); 2346 UUkillheaders (&(multistack[mssdepth].envelope));
2347 FP_free (multistack[mssdepth].source); 2347 _FP_free (multistack[mssdepth].source);
2348 } 2348 }
2349 2349
2350 if (uu_fast_scanning) { 2350 if (uu_fast_scanning) {
2351 UUkillheaders (&localenv); 2351 UUkillheaders (&localenv);
2352 sstate.isfolder = 0; 2352 sstate.isfolder = 0;
2353 sstate.ismime = 0; 2353 sstate.ismime = 0;
2354 sstate.mimestate = MS_BODY; 2354 sstate.mimestate = MS_BODY;
2355 FP_free (result); 2355 _FP_free (result);
2356 return NULL; 2356 return NULL;
2357 } 2357 }
2358 2358
2359 /* 2359 /*
2360 * Retry, listening to headers this time 2360 * Retry, listening to headers this time
2399 * it doesn't hold up, handle as plain text instead. 2399 * it doesn't hold up, handle as plain text instead.
2400 */ 2400 */
2401 2401
2402 if (sstate.ismime && sstate.mimestate == MS_SUBPART && 2402 if (sstate.ismime && sstate.mimestate == MS_SUBPART &&
2403 strcmp (localenv.mimevers, "1.0") == 0 && 2403 strcmp (localenv.mimevers, "1.0") == 0 &&
2404 FP_stristr (localenv.ctype, "text") != NULL && 2404 _FP_stristr (localenv.ctype, "text") != NULL &&
2405 !uu_desperate) { 2405 !uu_desperate) {
2406 if (result->uudet == UU_ENCODED && !(result->begin || result->end)) { 2406 if (result->uudet == UU_ENCODED && !(result->begin || result->end)) {
2407 result->uudet = 0; 2407 result->uudet = 0;
2408 } 2408 }
2409 } 2409 }
2415 if (result->uudet == 0) { 2415 if (result->uudet == 0) {
2416 result->uudet = PT_ENCODED; /* plain text */ 2416 result->uudet = PT_ENCODED; /* plain text */
2417 } 2417 }
2418 2418
2419 if (localenv.fname) { 2419 if (localenv.fname) {
2420 FP_free (result->filename); 2420 _FP_free (result->filename);
2421 if ((result->filename = FP_strdup (localenv.fname)) == NULL) 2421 if ((result->filename = _FP_strdup (localenv.fname)) == NULL)
2422 *errcode = UURET_NOMEM; 2422 *errcode = UURET_NOMEM;
2423 } 2423 }
2424 else if ((result->uudet==QP_ENCODED || result->uudet==PT_ENCODED) && 2424 else if ((result->uudet==QP_ENCODED || result->uudet==PT_ENCODED) &&
2425 result->filename==NULL && uu_handletext) { 2425 result->filename==NULL && uu_handletext) {
2426 sprintf (line, "%04d.txt", ++mimseqno); 2426 sprintf (line, "%04d.txt", ++mimseqno);
2427 if ((result->filename = FP_strdup (line)) == NULL) 2427 if ((result->filename = _FP_strdup (line)) == NULL)
2428 *errcode = UURET_NOMEM; 2428 *errcode = UURET_NOMEM;
2429 } 2429 }
2430 else { 2430 else {
2431 /* assign a filename lateron */ 2431 /* assign a filename lateron */
2432 } 2432 }
2433 if (result->mimetype) FP_free (result->mimetype); 2433 if (result->mimetype) _FP_free (result->mimetype);
2434 if (result->uudet) { 2434 if (result->uudet) {
2435 if (FP_stristr (localenv.ctype, "text") != NULL && 2435 if (_FP_stristr (localenv.ctype, "text") != NULL &&
2436 result->uudet != QP_ENCODED && result->uudet != PT_ENCODED) 2436 result->uudet != QP_ENCODED && result->uudet != PT_ENCODED)
2437 result->mimetype = NULL; /* better don't set it */ 2437 result->mimetype = NULL; /* better don't set it */
2438 else 2438 else
2439 result->mimetype = FP_strdup (localenv.ctype); 2439 result->mimetype = _FP_strdup (localenv.ctype);
2440 } 2440 }
2441 if (result->origin) FP_free (result->origin); 2441 if (result->origin) _FP_free (result->origin);
2442 result->origin = FP_strdup (localenv.from); 2442 result->origin = _FP_strdup (localenv.from);
2443 2443
2444 if (result->subject) FP_free (result->subject); 2444 if (result->subject) _FP_free (result->subject);
2445 result->subject = FP_strdup (localenv.subject); 2445 result->subject = _FP_strdup (localenv.subject);
2446 2446
2447 if (result->sfname == NULL) 2447 if (result->sfname == NULL)
2448 if ((result->sfname = FP_strdup (fname)) == NULL) 2448 if ((result->sfname = _FP_strdup (fname)) == NULL)
2449 *errcode = UURET_NOMEM; 2449 *errcode = UURET_NOMEM;
2450 2450
2451 result->length = prevpos - result->startpos; 2451 result->length = prevpos - result->startpos;
2452 result->flags = FL_SINGLE | FL_PROPER; 2452 result->flags = FL_SINGLE | FL_PROPER;
2453 result->partno = 1; 2453 result->partno = 1;
2475 * long to figure this out. But this might still be a MIME message 2475 * long to figure this out. But this might still be a MIME message
2476 * body. And if it's a message/partial, we need more special handling 2476 * body. And if it's a message/partial, we need more special handling
2477 */ 2477 */
2478 2478
2479 if (sstate.isfolder && sstate.ismime && sstate.mimestate == MS_BODY && 2479 if (sstate.isfolder && sstate.ismime && sstate.mimestate == MS_BODY &&
2480 FP_stristr (sstate.envelope.ctype, "message") != NULL && 2480 _FP_stristr (sstate.envelope.ctype, "message") != NULL &&
2481 FP_stristr (sstate.envelope.ctype, "partial") != NULL) { 2481 _FP_stristr (sstate.envelope.ctype, "partial") != NULL) {
2482 2482
2483 result->startpos = ftell (datei); 2483 result->startpos = ftell (datei);
2484 2484
2485 if (sstate.envelope.partno == 1) { 2485 if (sstate.envelope.partno == 1) {
2486 /* read local envelope */ 2486 /* read local envelope */
2488 memset (&localenv, 0, sizeof (headers)); 2488 memset (&localenv, 0, sizeof (headers));
2489 2489
2490 /* skip over blank lines first */ 2490 /* skip over blank lines first */
2491 prevpos = ftell (datei); 2491 prevpos = ftell (datei);
2492 while (!feof (datei)) { 2492 while (!feof (datei)) {
2493 if (FP_fgets (line, 255, datei) == NULL) 2493 if (_FP_fgets (line, 255, datei) == NULL)
2494 break; 2494 break;
2495 line[255] = '\0'; 2495 line[255] = '\0';
2496 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 2496 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
2497 if (!IsLineEmpty (line)) 2497 if (!IsLineEmpty (line))
2498 break; 2498 break;
2513 } 2513 }
2514 ptr1 = ScanHeaderLine (datei, line); 2514 ptr1 = ScanHeaderLine (datei, line);
2515 if (ParseHeader (&localenv, ptr1) == NULL) 2515 if (ParseHeader (&localenv, ptr1) == NULL)
2516 *errcode = UURET_NOMEM; 2516 *errcode = UURET_NOMEM;
2517 2517
2518 if (FP_fgets (line, 255, datei) == NULL) 2518 if (_FP_fgets (line, 255, datei) == NULL)
2519 break; 2519 break;
2520 line[255] = '\0'; 2520 line[255] = '\0';
2521 lcount++; 2521 lcount++;
2522 } 2522 }
2523 prevpos = ftell (datei); 2523 prevpos = ftell (datei);
2524 /* 2524 /*
2525 * Examine local header. We're mostly interested in the Content-Type 2525 * Examine local header. We're mostly interested in the Content-Type
2526 * and the Content-Transfer-Encoding. 2526 * and the Content-Transfer-Encoding.
2527 */ 2527 */
2528 if (FP_stristr (localenv.ctype, "multipart") != NULL) { 2528 if (_FP_stristr (localenv.ctype, "multipart") != NULL) {
2529 UUMessage (uuscan_id, __LINE__, UUMSG_WARNING, 2529 UUMessage (uuscan_id, __LINE__, UUMSG_WARNING,
2530 uustring (S_MIME_PART_MULTI)); 2530 uustring (S_MIME_PART_MULTI));
2531 } 2531 }
2532 if (localenv.subject) 2532 if (localenv.subject)
2533 result->subject = FP_strdup (localenv.subject); 2533 result->subject = _FP_strdup (localenv.subject);
2534 else 2534 else
2535 result->subject = FP_strdup (sstate.envelope.subject); 2535 result->subject = _FP_strdup (sstate.envelope.subject);
2536 2536
2537 if (localenv.from) 2537 if (localenv.from)
2538 result->origin = FP_strdup (localenv.from); 2538 result->origin = _FP_strdup (localenv.from);
2539 else 2539 else
2540 result->origin = FP_strdup (sstate.envelope.from); 2540 result->origin = _FP_strdup (sstate.envelope.from);
2541 2541
2542 if (localenv.ctype) 2542 if (localenv.ctype)
2543 result->mimetype = FP_strdup (localenv.ctype); 2543 result->mimetype = _FP_strdup (localenv.ctype);
2544 else 2544 else
2545 result->mimetype = FP_strdup ("text/plain"); 2545 result->mimetype = _FP_strdup ("text/plain");
2546 2546
2547 if (FP_stristr (localenv.ctenc, "quoted-printable") != NULL) 2547 if (_FP_stristr (localenv.ctenc, "quoted-printable") != NULL)
2548 result->uudet = QP_ENCODED; 2548 result->uudet = QP_ENCODED;
2549 else if (FP_stristr (localenv.ctenc, "base64") != NULL) 2549 else if (_FP_stristr (localenv.ctenc, "base64") != NULL)
2550 result->uudet = B64ENCODED; 2550 result->uudet = B64ENCODED;
2551 else if (FP_stristr (localenv.ctenc, "x-uue") != NULL) { 2551 else if (_FP_stristr (localenv.ctenc, "x-uue") != NULL) {
2552 result->uudet = UU_ENCODED; 2552 result->uudet = UU_ENCODED;
2553 result->begin = result->end = 1; 2553 result->begin = result->end = 1;
2554 } 2554 }
2555 else if (FP_stristr (localenv.ctenc, "x-yenc") != NULL) { 2555 else if (_FP_stristr (localenv.ctenc, "x-yenc") != NULL) {
2556 result->uudet = YENC_ENCODED; 2556 result->uudet = YENC_ENCODED;
2557 result->begin = result->end = 1; 2557 result->begin = result->end = 1;
2558 } 2558 }
2559 else if (FP_stristr (localenv.ctenc, "7bit") != NULL || 2559 else if (_FP_stristr (localenv.ctenc, "7bit") != NULL ||
2560 FP_stristr (localenv.ctenc, "8bit") != NULL) 2560 _FP_stristr (localenv.ctenc, "8bit") != NULL)
2561 result->uudet = PT_ENCODED; 2561 result->uudet = PT_ENCODED;
2562 else if (FP_stristr (localenv.ctype, "multipart") != NULL || 2562 else if (_FP_stristr (localenv.ctype, "multipart") != NULL ||
2563 FP_stristr (localenv.ctype, "message") != NULL) 2563 _FP_stristr (localenv.ctype, "message") != NULL)
2564 result->uudet = PT_ENCODED; 2564 result->uudet = PT_ENCODED;
2565 2565
2566 /* 2566 /*
2567 * If we're switched to MIME-only mode, handle as text 2567 * If we're switched to MIME-only mode, handle as text
2568 */ 2568 */
2595 } 2595 }
2596 else if (result->uudet != 0) { 2596 else if (result->uudet != 0) {
2597 hcount = lcount = 0; 2597 hcount = lcount = 0;
2598 prevpos = ftell (datei); 2598 prevpos = ftell (datei);
2599 2599
2600 if (FP_stristr (localenv.ctype, "message") != NULL && 2600 if (_FP_stristr (localenv.ctype, "message") != NULL &&
2601 FP_stristr (localenv.ctype, "rfc822") != NULL) { 2601 _FP_stristr (localenv.ctype, "rfc822") != NULL) {
2602 /* 2602 /*
2603 * skip over empty lines and local header 2603 * skip over empty lines and local header
2604 */ 2604 */
2605 preheaders = ftell (datei); 2605 preheaders = ftell (datei);
2606 while (!feof (datei)) { 2606 while (!feof (datei)) {
2607 if (FP_fgets (line, 255, datei) == NULL) 2607 if (_FP_fgets (line, 255, datei) == NULL)
2608 break; 2608 break;
2609 line[255] = '\0'; 2609 line[255] = '\0';
2610 if (!IsLineEmpty (line)) { 2610 if (!IsLineEmpty (line)) {
2611 break; 2611 break;
2612 } 2612 }
2617 hcount++; 2617 hcount++;
2618 lcount++; 2618 lcount++;
2619 if (lcount > WAITHEADER && hcount < hlcount.afternl) 2619 if (lcount > WAITHEADER && hcount < hlcount.afternl)
2620 break; 2620 break;
2621 2621
2622 if (FP_fgets (line, 255, datei) == NULL) 2622 if (_FP_fgets (line, 255, datei) == NULL)
2623 break; 2623 break;
2624 line[255] = '\0'; 2624 line[255] = '\0';
2625 } 2625 }
2626 if (hcount < hlcount.afternl) 2626 if (hcount < hlcount.afternl)
2627 fseek (datei, preheaders, SEEK_SET); 2627 fseek (datei, preheaders, SEEK_SET);
2631 /* 2631 /*
2632 * look for next header 2632 * look for next header
2633 */ 2633 */
2634 2634
2635 while (!feof (datei)) { 2635 while (!feof (datei)) {
2636 if (FP_fgets (line, 255, datei) == NULL) 2636 if (_FP_fgets (line, 255, datei) == NULL)
2637 break; 2637 break;
2638 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 2638 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
2639 if (ferror (datei)) 2639 if (ferror (datei))
2640 break; 2640 break;
2641 line[255] = '\0'; 2641 line[255] = '\0';
2689 } 2689 }
2690 /* 2690 /*
2691 * produce result 2691 * produce result
2692 */ 2692 */
2693 if (localenv.fname) { 2693 if (localenv.fname) {
2694 FP_free (result->filename); 2694 _FP_free (result->filename);
2695 if ((result->filename = FP_strdup (localenv.fname)) == NULL) 2695 if ((result->filename = _FP_strdup (localenv.fname)) == NULL)
2696 *errcode = UURET_NOMEM; 2696 *errcode = UURET_NOMEM;
2697 } 2697 }
2698 else if (sstate.envelope.fname) { 2698 else if (sstate.envelope.fname) {
2699 FP_free (result->filename); 2699 _FP_free (result->filename);
2700 if ((result->filename = FP_strdup (sstate.envelope.fname)) == NULL) 2700 if ((result->filename = _FP_strdup (sstate.envelope.fname)) == NULL)
2701 *errcode = UURET_NOMEM; 2701 *errcode = UURET_NOMEM;
2702 } 2702 }
2703 else if ((result->uudet==QP_ENCODED || result->uudet==PT_ENCODED) && 2703 else if ((result->uudet==QP_ENCODED || result->uudet==PT_ENCODED) &&
2704 result->filename == NULL) { 2704 result->filename == NULL) {
2705 sprintf (line, "%04d.txt", ++mimseqno); 2705 sprintf (line, "%04d.txt", ++mimseqno);
2706 if ((result->filename = FP_strdup (line)) == NULL) 2706 if ((result->filename = _FP_strdup (line)) == NULL)
2707 *errcode = UURET_NOMEM; 2707 *errcode = UURET_NOMEM;
2708 } 2708 }
2709 else { 2709 else {
2710 /* assign a filename lateron */ 2710 /* assign a filename lateron */
2711 } 2711 }
2712 if (result->subject == NULL) { 2712 if (result->subject == NULL) {
2713 if (sstate.envelope.subject) 2713 if (sstate.envelope.subject)
2714 result->subject = FP_strdup (sstate.envelope.subject); 2714 result->subject = _FP_strdup (sstate.envelope.subject);
2715 } 2715 }
2716 result->partno = sstate.envelope.partno; 2716 result->partno = sstate.envelope.partno;
2717 result->maxpno = sstate.envelope.numparts; 2717 result->maxpno = sstate.envelope.numparts;
2718 result->flags = FL_PARTIAL | 2718 result->flags = FL_PARTIAL |
2719 ((res==1 || uu_fast_scanning) ? FL_PROPER : 0) | 2719 ((res==1 || uu_fast_scanning) ? FL_PROPER : 0) |
2720 ((uu_fast_scanning) ? FL_TOEND : 0); 2720 ((uu_fast_scanning) ? FL_TOEND : 0);
2721 result->mimeid = FP_strdup (sstate.envelope.mimeid); 2721 result->mimeid = _FP_strdup (sstate.envelope.mimeid);
2722 if (result->partno == 1) 2722 if (result->partno == 1)
2723 result->begin = 1; 2723 result->begin = 1;
2724 2724
2725 if (uu_fast_scanning) 2725 if (uu_fast_scanning)
2726 result->length = progress.fsize - result->startpos; 2726 result->length = progress.fsize - result->startpos;
2727 else 2727 else
2728 result->length = prevpos - result->startpos; 2728 result->length = prevpos - result->startpos;
2729 2729
2730 if (result->sfname == NULL) 2730 if (result->sfname == NULL)
2731 result->sfname = FP_strdup (fname); 2731 result->sfname = _FP_strdup (fname);
2732 2732
2733 if (result->mode == 0) 2733 if (result->mode == 0)
2734 result->mode = 0644; 2734 result->mode = 0644;
2735 2735
2736 /* 2736 /*
2770 * decode a plain-text segment with a filename. 2770 * decode a plain-text segment with a filename.
2771 */ 2771 */
2772 2772
2773 if (sstate.isfolder && sstate.ismime && 2773 if (sstate.isfolder && sstate.ismime &&
2774 sstate.mimestate == MS_BODY && 2774 sstate.mimestate == MS_BODY &&
2775 (FP_stristr (sstate.envelope.ctenc, "quoted-printable") != NULL || 2775 (_FP_stristr (sstate.envelope.ctenc, "quoted-printable") != NULL ||
2776 FP_stristr (sstate.envelope.ctenc, "base64") != NULL || 2776 _FP_stristr (sstate.envelope.ctenc, "base64") != NULL ||
2777 FP_stristr (sstate.envelope.ctenc, "x-uue") != NULL || 2777 _FP_stristr (sstate.envelope.ctenc, "x-uue") != NULL ||
2778 FP_stristr (sstate.envelope.ctenc, "x-yenc") != NULL || 2778 _FP_stristr (sstate.envelope.ctenc, "x-yenc") != NULL ||
2779 FP_stristr (sstate.envelope.ctype, "message") != NULL || 2779 _FP_stristr (sstate.envelope.ctype, "message") != NULL ||
2780 sstate.envelope.fname != NULL)) { 2780 sstate.envelope.fname != NULL)) {
2781 2781
2782 if (sstate.envelope.subject) 2782 if (sstate.envelope.subject)
2783 result->subject = FP_strdup (sstate.envelope.subject); 2783 result->subject = _FP_strdup (sstate.envelope.subject);
2784 if (sstate.envelope.from) 2784 if (sstate.envelope.from)
2785 result->origin = FP_strdup (sstate.envelope.from); 2785 result->origin = _FP_strdup (sstate.envelope.from);
2786 2786
2787 if (sstate.envelope.ctype) 2787 if (sstate.envelope.ctype)
2788 result->mimetype = FP_strdup (sstate.envelope.ctype); 2788 result->mimetype = _FP_strdup (sstate.envelope.ctype);
2789 else 2789 else
2790 result->mimetype = FP_strdup ("text/plain"); 2790 result->mimetype = _FP_strdup ("text/plain");
2791 2791
2792 if (FP_stristr (sstate.envelope.ctenc, "quoted-printable") != NULL) 2792 if (_FP_stristr (sstate.envelope.ctenc, "quoted-printable") != NULL)
2793 result->uudet = QP_ENCODED; 2793 result->uudet = QP_ENCODED;
2794 else if (FP_stristr (sstate.envelope.ctenc, "base64") != NULL) 2794 else if (_FP_stristr (sstate.envelope.ctenc, "base64") != NULL)
2795 result->uudet = B64ENCODED; 2795 result->uudet = B64ENCODED;
2796 else if (FP_stristr (sstate.envelope.ctenc, "x-uue") != NULL) { 2796 else if (_FP_stristr (sstate.envelope.ctenc, "x-uue") != NULL) {
2797 result->uudet = UU_ENCODED; 2797 result->uudet = UU_ENCODED;
2798 result->begin = result->end = 1; 2798 result->begin = result->end = 1;
2799 } 2799 }
2800 else if (FP_stristr (sstate.envelope.ctenc, "x-yenc") != NULL) { 2800 else if (_FP_stristr (sstate.envelope.ctenc, "x-yenc") != NULL) {
2801 result->uudet = YENC_ENCODED; 2801 result->uudet = YENC_ENCODED;
2802 } 2802 }
2803 else if (FP_stristr (sstate.envelope.ctenc, "7bit") != NULL || 2803 else if (_FP_stristr (sstate.envelope.ctenc, "7bit") != NULL ||
2804 FP_stristr (sstate.envelope.ctenc, "8bit") != NULL) 2804 _FP_stristr (sstate.envelope.ctenc, "8bit") != NULL)
2805 result->uudet = PT_ENCODED; 2805 result->uudet = PT_ENCODED;
2806 else if (FP_stristr (sstate.envelope.ctype, "multipart") != NULL || 2806 else if (_FP_stristr (sstate.envelope.ctype, "multipart") != NULL ||
2807 FP_stristr (sstate.envelope.ctype, "message") != NULL || 2807 _FP_stristr (sstate.envelope.ctype, "message") != NULL ||
2808 sstate.envelope.fname != NULL) 2808 sstate.envelope.fname != NULL)
2809 result->uudet = PT_ENCODED; 2809 result->uudet = PT_ENCODED;
2810 2810
2811 /* 2811 /*
2812 * If we're switched to MIME-only mode, handle as text 2812 * If we're switched to MIME-only mode, handle as text
2831 } 2831 }
2832 else if (result->uudet != 0) { 2832 else if (result->uudet != 0) {
2833 hcount = lcount = 0; 2833 hcount = lcount = 0;
2834 prevpos = ftell (datei); 2834 prevpos = ftell (datei);
2835 2835
2836 if (FP_stristr (sstate.envelope.ctype, "message") != NULL && 2836 if (_FP_stristr (sstate.envelope.ctype, "message") != NULL &&
2837 FP_stristr (sstate.envelope.ctype, "rfc822") != NULL) { 2837 _FP_stristr (sstate.envelope.ctype, "rfc822") != NULL) {
2838 /* 2838 /*
2839 * skip over empty lines and local header 2839 * skip over empty lines and local header
2840 */ 2840 */
2841 preheaders = ftell (datei); 2841 preheaders = ftell (datei);
2842 while (!feof (datei)) { 2842 while (!feof (datei)) {
2843 if (FP_fgets (line, 255, datei) == NULL) 2843 if (_FP_fgets (line, 255, datei) == NULL)
2844 break; 2844 break;
2845 line[255] = '\0'; 2845 line[255] = '\0';
2846 if (!IsLineEmpty (line)) { 2846 if (!IsLineEmpty (line)) {
2847 break; 2847 break;
2848 } 2848 }
2853 hcount++; 2853 hcount++;
2854 lcount++; 2854 lcount++;
2855 if (lcount > WAITHEADER && hcount < hlcount.afternl) 2855 if (lcount > WAITHEADER && hcount < hlcount.afternl)
2856 break; 2856 break;
2857 2857
2858 if (FP_fgets (line, 255, datei) == NULL) 2858 if (_FP_fgets (line, 255, datei) == NULL)
2859 break; 2859 break;
2860 line[255] = '\0'; 2860 line[255] = '\0';
2861 } 2861 }
2862 if (hcount < hlcount.afternl) 2862 if (hcount < hlcount.afternl)
2863 fseek (datei, preheaders, SEEK_SET); 2863 fseek (datei, preheaders, SEEK_SET);
2867 /* 2867 /*
2868 * look for next header 2868 * look for next header
2869 */ 2869 */
2870 2870
2871 while (!feof (datei)) { 2871 while (!feof (datei)) {
2872 if (FP_fgets (line, 255, datei) == NULL) 2872 if (_FP_fgets (line, 255, datei) == NULL)
2873 break; 2873 break;
2874 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 2874 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
2875 if (ferror (datei)) 2875 if (ferror (datei))
2876 break; 2876 break;
2877 line[255] = '\0'; 2877 line[255] = '\0';
2923 } 2923 }
2924 /* 2924 /*
2925 * produce result 2925 * produce result
2926 */ 2926 */
2927 if (sstate.envelope.fname) { 2927 if (sstate.envelope.fname) {
2928 FP_free (result->filename); 2928 _FP_free (result->filename);
2929 if ((result->filename = FP_strdup (sstate.envelope.fname)) == NULL) 2929 if ((result->filename = _FP_strdup (sstate.envelope.fname)) == NULL)
2930 *errcode = UURET_NOMEM; 2930 *errcode = UURET_NOMEM;
2931 } 2931 }
2932 else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) && 2932 else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) &&
2933 result->filename == NULL) { 2933 result->filename == NULL) {
2934 sprintf (line, "%04d.txt", ++mimseqno); 2934 sprintf (line, "%04d.txt", ++mimseqno);
2935 if ((result->filename = FP_strdup (line)) == NULL) 2935 if ((result->filename = _FP_strdup (line)) == NULL)
2936 *errcode = UURET_NOMEM; 2936 *errcode = UURET_NOMEM;
2937 } 2937 }
2938 else { 2938 else {
2939 /* assign a filename lateron */ 2939 /* assign a filename lateron */
2940 } 2940 }
2941 if (result->subject == NULL) { 2941 if (result->subject == NULL) {
2942 if (sstate.envelope.subject) 2942 if (sstate.envelope.subject)
2943 result->subject = FP_strdup (sstate.envelope.subject); 2943 result->subject = _FP_strdup (sstate.envelope.subject);
2944 } 2944 }
2945 result->flags = ((res==1||uu_fast_scanning)?FL_PROPER:0) | 2945 result->flags = ((res==1||uu_fast_scanning)?FL_PROPER:0) |
2946 ((uu_fast_scanning) ? FL_TOEND : 0); 2946 ((uu_fast_scanning) ? FL_TOEND : 0);
2947 result->mimeid = FP_strdup (sstate.envelope.mimeid); 2947 result->mimeid = _FP_strdup (sstate.envelope.mimeid);
2948 2948
2949 if (uu_fast_scanning) 2949 if (uu_fast_scanning)
2950 result->length = progress.fsize - result->startpos; 2950 result->length = progress.fsize - result->startpos;
2951 else 2951 else
2952 result->length = prevpos - result->startpos; 2952 result->length = prevpos - result->startpos;
2953 2953
2954 if (result->sfname == NULL) 2954 if (result->sfname == NULL)
2955 result->sfname = FP_strdup (fname); 2955 result->sfname = _FP_strdup (fname);
2956 2956
2957 if (result->mode == 0) 2957 if (result->mode == 0)
2958 result->mode = 0644; 2958 result->mode = 0644;
2959 2959
2960 /* 2960 /*
2994 * we know that sstate.envelope.boundary is NULL, or we wouldn't 2994 * we know that sstate.envelope.boundary is NULL, or we wouldn't
2995 * be here! 2995 * be here!
2996 */ 2996 */
2997 2997
2998 if ((sstate.envelope.ctype == NULL || 2998 if ((sstate.envelope.ctype == NULL ||
2999 FP_stristr (sstate.envelope.ctype, "multipart") != NULL) && 2999 _FP_stristr (sstate.envelope.ctype, "multipart") != NULL) &&
3000 !uu_more_mime) { 3000 !uu_more_mime) {
3001 prevpos = ftell (datei); 3001 prevpos = ftell (datei);
3002 while (!feof (datei)) { 3002 while (!feof (datei)) {
3003 if (FP_fgets (line, 255, datei) == NULL) { 3003 if (_FP_fgets (line, 255, datei) == NULL) {
3004 line[0] = '\0'; 3004 line[0] = '\0';
3005 break; 3005 break;
3006 } 3006 }
3007 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 3007 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
3008 if (!IsLineEmpty (line)) 3008 if (!IsLineEmpty (line))
3009 break; 3009 break;
3010 } 3010 }
3011 if (line[0] == '-' && line[1] == '-' && 3011 if (line[0] == '-' && line[1] == '-' &&
3012 !IsLineEmpty (line+2) && !feof (datei)) { 3012 !IsLineEmpty (line+2) && !feof (datei)) {
3013 ptr1 = FP_strrstr (line+2, "--"); 3013 ptr1 = _FP_strrstr (line+2, "--");
3014 ptr2 = ScanHeaderLine (datei, NULL); 3014 ptr2 = ScanHeaderLine (datei, NULL);
3015 if ((ptr1 == NULL || (*(ptr1+2) != '\012' && *(ptr1+2) != '\015')) && 3015 if ((ptr1 == NULL || (*(ptr1+2) != '\012' && *(ptr1+2) != '\015')) &&
3016 ptr2 && FP_strnicmp (ptr2, "Content-", 8) == 0) { 3016 ptr2 && _FP_strnicmp (ptr2, "Content-", 8) == 0) {
3017 /* 3017 /*
3018 * hmm, okay, let's do it! 3018 * hmm, okay, let's do it!
3019 */ 3019 */
3020 sstate.isfolder = 1; 3020 sstate.isfolder = 1;
3021 sstate.ismime = 1; 3021 sstate.ismime = 1;
3026 ptr1 = line+2; 3026 ptr1 = line+2;
3027 while (*ptr1 && !isspace(*ptr1)) 3027 while (*ptr1 && !isspace(*ptr1))
3028 ptr1++; 3028 ptr1++;
3029 *ptr1 = '\0'; 3029 *ptr1 = '\0';
3030 3030
3031 sstate.envelope.mimevers = FP_strdup ("1.0"); 3031 sstate.envelope.mimevers = _FP_strdup ("1.0");
3032 sstate.envelope.boundary = FP_strdup (line+2); 3032 sstate.envelope.boundary = _FP_strdup (line+2);
3033 3033
3034 /* 3034 /*
3035 * need restart 3035 * need restart
3036 */ 3036 */
3037 3037
3038 fseek (datei, prevpos, SEEK_SET); 3038 fseek (datei, prevpos, SEEK_SET);
3039 3039
3040 FP_free (result); 3040 _FP_free (result);
3041 return NULL; 3041 return NULL;
3042 } 3042 }
3043 } 3043 }
3044 fseek (datei, prevpos, SEEK_SET); 3044 fseek (datei, prevpos, SEEK_SET);
3045 } 3045 }
3049 * Freestyle time. Anyway, if this seems to be a Mime message, 3049 * Freestyle time. Anyway, if this seems to be a Mime message,
3050 * don't allow the minimal Base64 handling. 3050 * don't allow the minimal Base64 handling.
3051 */ 3051 */
3052 3052
3053 if (sstate.envelope.subject) 3053 if (sstate.envelope.subject)
3054 result->subject = FP_strdup (sstate.envelope.subject); 3054 result->subject = _FP_strdup (sstate.envelope.subject);
3055 if (sstate.envelope.from) 3055 if (sstate.envelope.from)
3056 result->origin = FP_strdup (sstate.envelope.from); 3056 result->origin = _FP_strdup (sstate.envelope.from);
3057 3057
3058 if (sstate.envelope.ctype) 3058 if (sstate.envelope.ctype)
3059 result->mimetype = FP_strdup (sstate.envelope.ctype); 3059 result->mimetype = _FP_strdup (sstate.envelope.ctype);
3060 3060
3061 if ((res=ScanData (datei, fname, errcode, NULL, 3061 if ((res=ScanData (datei, fname, errcode, NULL,
3062 sstate.ismime, 1, result))==-1) { 3062 sstate.ismime, 1, result))==-1) {
3063 /* oops, something went wrong */ 3063 /* oops, something went wrong */
3064 sstate.isfolder = 0; 3064 sstate.isfolder = 0;
3081 /* 3081 /*
3082 * prevent replacing the filename found on the =ybegin line 3082 * prevent replacing the filename found on the =ybegin line
3083 */ 3083 */
3084 } 3084 }
3085 else if (sstate.envelope.fname) { 3085 else if (sstate.envelope.fname) {
3086 FP_free (result->filename); 3086 _FP_free (result->filename);
3087 if ((result->filename = FP_strdup (sstate.envelope.fname)) == NULL) 3087 if ((result->filename = _FP_strdup (sstate.envelope.fname)) == NULL)
3088 *errcode = UURET_NOMEM; 3088 *errcode = UURET_NOMEM;
3089 } 3089 }
3090 else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) && 3090 else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) &&
3091 result->filename == NULL) { 3091 result->filename == NULL) {
3092 sprintf (line, "%04d.txt", ++mimseqno); 3092 sprintf (line, "%04d.txt", ++mimseqno);
3093 if ((result->filename = FP_strdup (line)) == NULL) 3093 if ((result->filename = _FP_strdup (line)) == NULL)
3094 *errcode = UURET_NOMEM; 3094 *errcode = UURET_NOMEM;
3095 } 3095 }
3096 else { 3096 else {
3097 /* assign a filename lateron */ 3097 /* assign a filename lateron */
3098 } 3098 }
3099 3099
3100 if (result->subject == NULL) { 3100 if (result->subject == NULL) {
3101 if (sstate.envelope.subject) 3101 if (sstate.envelope.subject)
3102 result->subject = FP_strdup (sstate.envelope.subject); 3102 result->subject = _FP_strdup (sstate.envelope.subject);
3103 } 3103 }
3104 3104
3105 result->flags = (result->uudet==PT_ENCODED)?FL_SINGLE:0; 3105 result->flags = (result->uudet==PT_ENCODED)?FL_SINGLE:0;
3106 result->mimeid = FP_strdup (sstate.envelope.mimeid); 3106 result->mimeid = _FP_strdup (sstate.envelope.mimeid);
3107 result->length = ftell (datei) - result->startpos; 3107 result->length = ftell (datei) - result->startpos;
3108 3108
3109 if (result->mode == 0) 3109 if (result->mode == 0)
3110 result->mode = 0644; 3110 result->mode = 0644;
3111 3111
3112 if (result->sfname == NULL) 3112 if (result->sfname == NULL)
3113 result->sfname = FP_strdup (fname); 3113 result->sfname = _FP_strdup (fname);
3114 3114
3115 if (res == 1) { 3115 if (res == 1) {
3116 /* 3116 /*
3117 * new headers found 3117 * new headers found
3118 */ 3118 */
3141 UUkillheaders (&localenv); 3141 UUkillheaders (&localenv);
3142 3142
3143 while (mssdepth) { 3143 while (mssdepth) {
3144 mssdepth--; 3144 mssdepth--;
3145 UUkillheaders (&(multistack[mssdepth].envelope)); 3145 UUkillheaders (&(multistack[mssdepth].envelope));
3146 FP_free (multistack[mssdepth].source); 3146 _FP_free (multistack[mssdepth].source);
3147 } 3147 }
3148 3148
3149 return NULL; 3149 return NULL;
3150} 3150}
3151 3151

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines