… | |
… | |
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.3 2001/08/07 13:38:38 root Exp $"; |
60 | char * uuscan_id = "$Id: uuscan.c,v 1.3.2.2 2002/03/31 19:52:08 root Exp $"; |
61 | |
61 | |
62 | /* |
62 | /* |
63 | * Header fields we recognize as such. See RFC822. We add "From ", |
63 | * Header fields we recognize as such. See RFC822. We add "From ", |
64 | * the usual marker for a beginning of a new message, and a couple |
64 | * the usual marker for a beginning of a new message, and a couple |
65 | * of usual MDA, News and MIME headers. |
65 | * of usual MDA, News and MIME headers. |
… | |
… | |
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); |
… | |
… | |
288 | |
288 | |
289 | if (*attribute == '"') { |
289 | if (*attribute == '"') { |
290 | /* quoted-string */ |
290 | /* quoted-string */ |
291 | attribute++; |
291 | attribute++; |
292 | while (*attribute && *attribute != '"' && length < 255) { |
292 | while (*attribute && *attribute != '"' && length < 255) { |
293 | if (*attribute == '\\' |
293 | if (*attribute == '\\') |
294 | && (attribute[1] == '"' |
|
|
295 | || attribute[1] == '\015' |
|
|
296 | || attribute[1] == '\\')) |
|
|
297 | /* we dequote only the three characters that MUST be quoted, since |
|
|
298 | * microsoft is obviously unable to correctly implement even mime headers: |
|
|
299 | * filename="c:\xxx". *sigh* |
|
|
300 | */ |
|
|
301 | *ptr++ = *++attribute; |
294 | *ptr++ = *++attribute; |
302 | else |
295 | else |
303 | *ptr++ = *attribute; |
296 | *ptr++ = *attribute; |
304 | attribute++; |
297 | attribute++; |
305 | length++; |
298 | length++; |
… | |
… | |
334 | { |
327 | { |
335 | char **variable=NULL; |
328 | char **variable=NULL; |
336 | char *value, *ptr, *thenew; |
329 | char *value, *ptr, *thenew; |
337 | int delimit, length; |
330 | int delimit, length; |
338 | |
331 | |
339 | value = 0; delimit = 0; /* calm down gcc */ |
|
|
340 | |
|
|
341 | if (line == NULL) |
332 | if (line == NULL) |
342 | return theheaders; |
333 | return theheaders; |
343 | |
334 | |
344 | if (FP_strnicmp (line, "From:", 5) == 0) { |
335 | if (_FP_strnicmp (line, "From:", 5) == 0) { |
345 | if (theheaders->from) return theheaders; |
336 | if (theheaders->from) return theheaders; |
346 | variable = &theheaders->from; |
337 | variable = &theheaders->from; |
347 | value = line+5; |
338 | value = line+5; |
348 | delimit = 0; |
339 | delimit = 0; |
349 | } |
340 | } |
350 | else if (FP_strnicmp (line, "Subject:", 8) == 0) { |
341 | else if (_FP_strnicmp (line, "Subject:", 8) == 0) { |
351 | if (theheaders->subject) return theheaders; |
342 | if (theheaders->subject) return theheaders; |
352 | variable = &theheaders->subject; |
343 | variable = &theheaders->subject; |
353 | value = line+8; |
344 | value = line+8; |
354 | delimit = 0; |
345 | delimit = 0; |
355 | } |
346 | } |
356 | else if (FP_strnicmp (line, "To:", 3) == 0) { |
347 | else if (_FP_strnicmp (line, "To:", 3) == 0) { |
357 | if (theheaders->rcpt) return theheaders; |
348 | if (theheaders->rcpt) return theheaders; |
358 | variable = &theheaders->rcpt; |
349 | variable = &theheaders->rcpt; |
359 | value = line+3; |
350 | value = line+3; |
360 | delimit = 0; |
351 | delimit = 0; |
361 | } |
352 | } |
362 | else if (FP_strnicmp (line, "Date:", 5) == 0) { |
353 | else if (_FP_strnicmp (line, "Date:", 5) == 0) { |
363 | if (theheaders->date) return theheaders; |
354 | if (theheaders->date) return theheaders; |
364 | variable = &theheaders->date; |
355 | variable = &theheaders->date; |
365 | value = line+5; |
356 | value = line+5; |
366 | delimit = 0; |
357 | delimit = 0; |
367 | } |
358 | } |
368 | else if (FP_strnicmp (line, "Mime-Version:", 13) == 0) { |
359 | else if (_FP_strnicmp (line, "Mime-Version:", 13) == 0) { |
369 | if (theheaders->mimevers) return theheaders; |
360 | if (theheaders->mimevers) return theheaders; |
370 | variable = &theheaders->mimevers; |
361 | variable = &theheaders->mimevers; |
371 | value = line+13; |
362 | value = line+13; |
372 | delimit = 0; |
363 | delimit = 0; |
373 | } |
364 | } |
374 | else if (FP_strnicmp (line, "Content-Type:", 13) == 0) { |
365 | else if (_FP_strnicmp (line, "Content-Type:", 13) == 0) { |
375 | if (theheaders->ctype) return theheaders; |
366 | if (theheaders->ctype) return theheaders; |
376 | variable = &theheaders->ctype; |
367 | variable = &theheaders->ctype; |
377 | value = line+13; |
368 | value = line+13; |
378 | delimit = ';'; |
369 | delimit = ';'; |
379 | |
370 | |
380 | /* we can probably extract more information */ |
371 | /* we can probably extract more information */ |
381 | if ((ptr = FP_stristr (line, "boundary")) != NULL) { |
372 | if ((ptr = _FP_stristr (line, "boundary")) != NULL) { |
382 | if ((thenew = ParseValue (ptr))) { |
373 | if ((thenew = ParseValue (ptr))) { |
383 | if (theheaders->boundary) free (theheaders->boundary); |
374 | if (theheaders->boundary) free (theheaders->boundary); |
384 | theheaders->boundary = FP_strdup (thenew); |
375 | theheaders->boundary = _FP_strdup (thenew); |
385 | } |
|
|
386 | } |
376 | } |
|
|
377 | } |
387 | if ((ptr = FP_stristr (line, "name")) != NULL) { |
378 | if ((ptr = _FP_stristr (line, "name")) != NULL) { |
388 | if ((thenew = ParseValue (ptr))) { |
379 | if ((thenew = ParseValue (ptr))) { |
389 | if (theheaders->fname) free (theheaders->fname); |
380 | if (theheaders->fname) free (theheaders->fname); |
390 | theheaders->fname = FP_strdup (thenew); |
381 | theheaders->fname = _FP_strdup (thenew); |
391 | } |
|
|
392 | } |
382 | } |
|
|
383 | } |
393 | if ((ptr = FP_stristr (line, "id")) != NULL) { |
384 | if ((ptr = _FP_stristr (line, "id")) != NULL) { |
394 | if ((thenew = ParseValue (ptr))) { |
385 | if ((thenew = ParseValue (ptr))) { |
395 | if (theheaders->mimeid) free (theheaders->mimeid); |
386 | if (theheaders->mimeid) free (theheaders->mimeid); |
396 | theheaders->mimeid = FP_strdup (thenew); |
387 | theheaders->mimeid = _FP_strdup (thenew); |
397 | } |
|
|
398 | } |
388 | } |
|
|
389 | } |
399 | if ((ptr = FP_stristr (line, "number")) != NULL) { |
390 | if ((ptr = _FP_stristr (line, "number")) != NULL) { |
400 | if ((thenew = ParseValue (ptr))) { |
391 | if ((thenew = ParseValue (ptr))) { |
401 | theheaders->partno = atoi (thenew); |
392 | theheaders->partno = atoi (thenew); |
402 | } |
393 | } |
403 | } |
394 | } |
404 | if ((ptr = FP_stristr (line, "total")) != NULL) { |
395 | if ((ptr = _FP_stristr (line, "total")) != NULL) { |
405 | if ((thenew = ParseValue (ptr))) { |
396 | if ((thenew = ParseValue (ptr))) { |
406 | theheaders->numparts = atoi (thenew); |
397 | theheaders->numparts = atoi (thenew); |
407 | } |
398 | } |
408 | } |
399 | } |
409 | } |
400 | } |
410 | else if (FP_strnicmp (line, "Content-Transfer-Encoding:", 26) == 0) { |
401 | else if (_FP_strnicmp (line, "Content-Transfer-Encoding:", 26) == 0) { |
411 | if (theheaders->ctenc) return theheaders; |
402 | if (theheaders->ctenc) return theheaders; |
412 | variable = &theheaders->ctenc; |
403 | variable = &theheaders->ctenc; |
413 | value = line+26; |
404 | value = line+26; |
414 | delimit = ';'; |
405 | delimit = ';'; |
415 | } |
406 | } |
416 | else if (FP_strnicmp (line, "Content-Disposition:", 20) == 0) { |
407 | else if (_FP_strnicmp (line, "Content-Disposition:", 20) == 0) { |
417 | /* |
408 | /* |
418 | * Some encoders mention the original filename as parameter to |
409 | * Some encoders mention the original filename as parameter to |
419 | * Content-Type, others as parameter to Content-Disposition. We |
410 | * Content-Type, others as parameter to Content-Disposition. We |
420 | * do prefer the first solution, but accept this situation, too. |
411 | * do prefer the first solution, but accept this situation, too. |
421 | * TODO: Read RFC1806 |
412 | * TODO: Read RFC1806 |
422 | */ |
413 | */ |
423 | if ((ptr = FP_stristr (line, "name")) != NULL) { |
414 | if ((ptr = _FP_stristr (line, "name")) != NULL) { |
424 | if (theheaders->fname == NULL && (thenew=ParseValue(ptr)) != NULL) { |
415 | if (theheaders->fname == NULL && (thenew=ParseValue(ptr)) != NULL) { |
425 | theheaders->fname = FP_strdup (thenew); |
416 | theheaders->fname = _FP_strdup (thenew); |
426 | } |
417 | } |
427 | } |
418 | } |
428 | variable = NULL; |
419 | variable = NULL; |
429 | } |
420 | } |
430 | else { |
421 | else { |
431 | /* |
422 | /* |
432 | * nothing interesting |
423 | * nothing interesting |
433 | */ |
424 | */ |
434 | variable = NULL; |
425 | return theheaders; |
435 | } |
426 | } |
436 | |
427 | |
437 | /* |
428 | /* |
438 | * okay, so extract the actual data |
429 | * okay, so extract the actual data |
439 | */ |
430 | */ |
… | |
… | |
451 | while (length && isspace(*(ptr-1))) { |
442 | while (length && isspace(*(ptr-1))) { |
452 | ptr--; length--; |
443 | ptr--; length--; |
453 | } |
444 | } |
454 | *ptr = '\0'; |
445 | *ptr = '\0'; |
455 | |
446 | |
456 | if ((*variable = FP_strdup (uuscan_phtext)) == NULL) |
447 | if ((*variable = _FP_strdup (uuscan_phtext)) == NULL) |
457 | return NULL; |
448 | return NULL; |
458 | } |
449 | } |
459 | |
450 | |
460 | return theheaders; |
451 | return theheaders; |
461 | } |
452 | } |
… | |
… | |
468 | IsKnownHeader (char *line) |
459 | IsKnownHeader (char *line) |
469 | { |
460 | { |
470 | char **iter = knownmsgheaders; |
461 | char **iter = knownmsgheaders; |
471 | |
462 | |
472 | while (iter && *iter) { |
463 | while (iter && *iter) { |
473 | if (FP_strnicmp (line, *iter, strlen (*iter)) == 0) |
464 | if (_FP_strnicmp (line, *iter, strlen (*iter)) == 0) |
474 | return 1; |
465 | return 1; |
475 | iter++; |
466 | iter++; |
476 | } |
467 | } |
477 | |
468 | |
478 | iter = knownmimeheaders; |
469 | iter = knownmimeheaders; |
479 | |
470 | |
480 | while (iter && *iter) { |
471 | while (iter && *iter) { |
481 | if (FP_strnicmp (line, *iter, strlen (*iter)) == 0) |
472 | if (_FP_strnicmp (line, *iter, strlen (*iter)) == 0) |
482 | return 2; |
473 | return 2; |
483 | iter++; |
474 | iter++; |
484 | } |
475 | } |
485 | |
476 | |
486 | return 0; |
477 | return 0; |
… | |
… | |
526 | char *line=uuscan_sdline, *bhds1=uuscan_sdbhds1, *bhds2=uuscan_sdbhds2; |
517 | char *line=uuscan_sdline, *bhds1=uuscan_sdbhds1, *bhds2=uuscan_sdbhds2; |
527 | static char *ptr, *p2, *p3=NULL, *bhdsp, bhl; |
518 | static char *ptr, *p2, *p3=NULL, *bhdsp, bhl; |
528 | int isb64[10], isuue[10], isxxe[10], isbhx[10], iscnt; |
519 | int isb64[10], isuue[10], isxxe[10], isbhx[10], iscnt; |
529 | int cbb64, cbuue, cbxxe, cbbhx; |
520 | int cbb64, cbuue, cbxxe, cbbhx; |
530 | int bhflag=0, vflag, haddh=0, hadct=0; |
521 | int bhflag=0, vflag, haddh=0, hadct=0; |
531 | int bhrpc=0, bhnf=0, c, hcount, lcount, blen; |
522 | int bhrpc=0, bhnf=0, c, hcount, lcount, blen=0; |
532 | int encoding=0, dflag=0, ctline=42; |
523 | int encoding=0, dflag=0, ctline=42; |
533 | int dontcare=0, hadnl=0; |
524 | int dontcare=0, hadnl=0; |
534 | long preheaders, oldposition; |
525 | long preheaders=0, oldposition; |
|
|
526 | long yefilesize=0, yepartends=0; |
535 | size_t dcc, bhopc; |
527 | size_t dcc, bhopc; |
536 | |
|
|
537 | blen = 0; preheaders = 0; /* calm down gcc */ |
|
|
538 | |
528 | |
539 | *errcode = UURET_OK; |
529 | *errcode = UURET_OK; |
540 | (void) UUDecodeLine (NULL, NULL, 0); /* init */ |
530 | (void) UUDecodeLine (NULL, NULL, 0); /* init */ |
541 | bhdsp = bhds2; |
531 | bhdsp = bhds2; |
542 | |
532 | |
… | |
… | |
555 | if (boundary) |
545 | if (boundary) |
556 | blen = strlen (boundary); |
546 | blen = strlen (boundary); |
557 | |
547 | |
558 | while (!feof (datei)) { |
548 | while (!feof (datei)) { |
559 | oldposition = ftell (datei); |
549 | oldposition = ftell (datei); |
560 | if (FP_fgets (line, 255, datei) == NULL) |
550 | if (_FP_fgets (line, 299, datei) == NULL) |
561 | break; |
551 | break; |
562 | if (ferror (datei)) |
552 | if (ferror (datei)) |
563 | break; |
553 | break; |
564 | |
554 | |
565 | line[255] = '\0'; /* For Safety of string functions */ |
555 | line[299] = '\0'; /* For Safety of string functions */ |
566 | |
556 | |
567 | /* |
557 | /* |
568 | * Make Busy Polls |
558 | * Make Busy Polls |
569 | */ |
559 | */ |
570 | |
560 | |
… | |
… | |
630 | strncmp (line+2, boundary, blen) == 0) { |
620 | strncmp (line+2, boundary, blen) == 0) { |
631 | fseek (datei, oldposition, SEEK_SET); |
621 | fseek (datei, oldposition, SEEK_SET); |
632 | break; |
622 | break; |
633 | } |
623 | } |
634 | if (boundary != NULL && line[0] == 'C' && line[1] == 'o' && |
624 | if (boundary != NULL && line[0] == 'C' && line[1] == 'o' && |
635 | FP_strnicmp (line, "Content-Type:", 13) == 0) { |
625 | _FP_strnicmp (line, "Content-Type:", 13) == 0) { |
636 | ptr = ScanHeaderLine (datei, line); |
626 | ptr = ScanHeaderLine (datei, line); |
637 | p2 = (ptr)?FP_stristr(ptr,"boundary"):NULL; |
627 | p2 = (ptr)?_FP_stristr(ptr,"boundary"):NULL; |
638 | p3 = (p2)?ParseValue(p2):NULL; |
628 | p3 = (p2)?ParseValue(p2):NULL; |
639 | |
629 | |
640 | if (p3 && strcmp (p3, boundary) == 0) { |
630 | if (p3 && strcmp (p3, boundary) == 0) { |
641 | fseek (datei, oldposition, SEEK_SET); |
631 | fseek (datei, oldposition, SEEK_SET); |
642 | break; |
632 | break; |
… | |
… | |
645 | p3 = NULL; |
635 | p3 = NULL; |
646 | } |
636 | } |
647 | } |
637 | } |
648 | |
638 | |
649 | if (strncmp (line, "begin ", 6) == 0 || |
639 | if (strncmp (line, "begin ", 6) == 0 || |
650 | FP_strnicmp (line, "<pre>begin ", 11) == 0) { |
640 | _FP_strnicmp (line, "<pre>begin ", 11) == 0) { |
651 | if ((result->begin || result->end || |
641 | if ((result->begin || result->end || |
652 | result->uudet == B64ENCODED || |
642 | result->uudet == B64ENCODED || |
653 | result->uudet == BH_ENCODED) && !uu_more_mime) { |
643 | result->uudet == BH_ENCODED) && !uu_more_mime) { |
654 | fseek (datei, oldposition, SEEK_SET); |
644 | fseek (datei, oldposition, SEEK_SET); |
655 | break; |
645 | break; |
… | |
… | |
666 | while (*ptr == ' ') ptr++; |
656 | while (*ptr == ' ') ptr++; |
667 | |
657 | |
668 | /* |
658 | /* |
669 | * We may have picked up a filename from a uuenview-style header |
659 | * We may have picked up a filename from a uuenview-style header |
670 | */ |
660 | */ |
671 | FP_free (result->filename); |
661 | _FP_free (result->filename); |
672 | result->filename = FP_strdup (ptr); |
662 | result->filename = _FP_strdup (ptr); |
673 | result->begin = 1; |
663 | result->begin = 1; |
674 | |
664 | |
675 | while (isspace (result->filename[strlen(result->filename)-1])) |
665 | while (isspace (result->filename[strlen(result->filename)-1])) |
676 | result->filename[strlen(result->filename)-1] = '\0'; |
666 | result->filename[strlen(result->filename)-1] = '\0'; |
677 | |
667 | |
678 | continue; |
668 | continue; |
679 | } |
669 | } |
680 | |
670 | |
681 | if ((strncmp (line, "end", 3) == 0) && result->uudet != BH_ENCODED) { |
671 | if ((strncmp (line, "end", 3) == 0) && |
|
|
672 | result->uudet != BH_ENCODED && |
|
|
673 | result->uudet != YENC_ENCODED) { |
682 | if (result->uudet == B64ENCODED && result->begin) |
674 | if (result->uudet == B64ENCODED && result->begin) |
683 | result->uudet = XX_ENCODED; |
675 | result->uudet = XX_ENCODED; |
684 | |
676 | |
685 | if (result->uudet != B64ENCODED) { |
677 | if (result->uudet != B64ENCODED) { |
686 | result->end = 1; |
678 | result->end = 1; |
… | |
… | |
694 | |
686 | |
695 | /* |
687 | /* |
696 | * Detect a UUDeview-Style header |
688 | * Detect a UUDeview-Style header |
697 | */ |
689 | */ |
698 | |
690 | |
699 | if (FP_strnicmp (line, "_=_ Part ", 9) == 0) { |
691 | if (_FP_strnicmp (line, "_=_ Part ", 9) == 0 && |
|
|
692 | result->uudet != YENC_ENCODED) { |
700 | if (result->uudet) { |
693 | if (result->uudet) { |
701 | fseek (datei, oldposition, SEEK_SET); |
694 | fseek (datei, oldposition, SEEK_SET); |
702 | break; |
695 | break; |
703 | } |
696 | } |
704 | result->partno = atoi (line + 8); |
697 | result->partno = atoi (line + 8); |
705 | if ((ptr = FP_stristr (line, "of file ")) != NULL) { |
698 | if ((ptr = _FP_stristr (line, "of file ")) != NULL) { |
706 | ptr += 8; |
699 | ptr += 8; |
707 | while (isspace (*ptr)) ptr++; |
700 | while (isspace (*ptr)) ptr++; |
708 | p2 = ptr; |
701 | p2 = ptr; |
709 | while (isalnum(*p2) || |
702 | while (isalnum(*p2) || |
710 | *p2 == '.' || *p2=='_' || *p2 == '-' || |
703 | *p2 == '.' || *p2=='_' || *p2 == '-' || |
711 | *p2 == '!' || *p2=='@' || *p2 == '$') |
704 | *p2 == '!' || *p2=='@' || *p2 == '$') |
712 | p2++; |
705 | p2++; |
713 | c = *p2; *p2 = '\0'; |
706 | c = *p2; *p2 = '\0'; |
714 | if (p2 != ptr && result->filename == NULL) |
707 | if (p2 != ptr && result->filename == NULL) |
715 | result->filename = FP_strdup (ptr); |
708 | result->filename = _FP_strdup (ptr); |
716 | else if (p2 - ptr > 5 && strchr (ptr, '.') != NULL) { |
709 | else if (p2 - ptr > 5 && strchr (ptr, '.') != NULL) { |
717 | /* |
710 | /* |
718 | * This file name looks good, too. Let's use it |
711 | * This file name looks good, too. Let's use it |
719 | */ |
712 | */ |
720 | FP_free (result->filename); |
713 | _FP_free (result->filename); |
721 | result->filename = FP_strdup (ptr); |
714 | result->filename = _FP_strdup (ptr); |
722 | } |
715 | } |
723 | *p2 = c; |
716 | *p2 = c; |
724 | } |
717 | } |
725 | } |
718 | } |
726 | |
719 | |
727 | /* |
720 | /* |
728 | * Some reduced MIME handling. Only use if boundary == NULL. Also |
721 | * Some reduced MIME handling. Only use if boundary == NULL. Also |
729 | * accept the "X-Orcl-Content-Type" used by some braindead program. |
722 | * accept the "X-Orcl-Content-Type" used by some braindead program. |
730 | */ |
723 | */ |
731 | if (boundary == NULL && !ismime && !uu_more_mime) { |
724 | if (boundary == NULL && !ismime && !uu_more_mime && |
|
|
725 | result->uudet != YENC_ENCODED) { |
732 | if (FP_strnicmp (line, "Content-Type", 12) == 0 || |
726 | if (_FP_strnicmp (line, "Content-Type", 12) == 0 || |
733 | FP_strnicmp (line, "X-Orcl-Content-Type", 19) == 0) { |
727 | _FP_strnicmp (line, "X-Orcl-Content-Type", 19) == 0) { |
734 | /* |
728 | /* |
735 | * We use Content-Type to mark a new attachment and split the file. |
729 | * We use Content-Type to mark a new attachment and split the file. |
736 | * However, we do not split if we haven't found anything encoded yet. |
730 | * However, we do not split if we haven't found anything encoded yet. |
737 | */ |
731 | */ |
738 | if (result->uudet) { |
732 | if (result->uudet) { |
… | |
… | |
743 | ptr++; |
737 | ptr++; |
744 | while (isspace (*ptr)) ptr++; p2 = ptr; |
738 | while (isspace (*ptr)) ptr++; p2 = ptr; |
745 | while (!isspace (*p2) && *p2 != ';') p2++; |
739 | while (!isspace (*p2) && *p2 != ';') p2++; |
746 | c = *p2; *p2 = '\0'; |
740 | c = *p2; *p2 = '\0'; |
747 | if (p2 != ptr) { |
741 | if (p2 != ptr) { |
748 | FP_free (result->mimetype); |
742 | _FP_free (result->mimetype); |
749 | result->mimetype = FP_strdup (ptr); |
743 | result->mimetype = _FP_strdup (ptr); |
750 | } |
744 | } |
751 | *p2 = c; |
745 | *p2 = c; |
752 | } |
746 | } |
753 | ctline=0; |
747 | ctline=0; |
754 | hadct=1; |
748 | hadct=1; |
755 | } |
749 | } |
756 | if ((ptr = FP_stristr (line, "number=")) && ctline<4) { |
750 | if ((ptr = _FP_stristr (line, "number=")) && ctline<4) { |
757 | ptr += 7; if (*ptr == '"') ptr++; |
751 | ptr += 7; if (*ptr == '"') ptr++; |
758 | result->partno = atoi (ptr); |
752 | result->partno = atoi (ptr); |
759 | } |
753 | } |
760 | if ((ptr = FP_stristr (line, "total=")) && ctline<4) { |
754 | if ((ptr = _FP_stristr (line, "total=")) && ctline<4) { |
761 | ptr += 6; if (*ptr == '"') ptr++; |
755 | ptr += 6; if (*ptr == '"') ptr++; |
762 | result->maxpno = atoi (ptr); |
756 | result->maxpno = atoi (ptr); |
763 | } |
757 | } |
764 | if ((ptr = FP_stristr (line, "name=")) && ctline<4) { |
758 | if ((ptr = _FP_stristr (line, "name=")) && ctline<4) { |
765 | ptr += 5; |
759 | ptr += 5; |
766 | while (isspace (*ptr)) ptr++; |
760 | while (isspace (*ptr)) ptr++; |
767 | if (*ptr == '"' && *(ptr+1) && (p2 = strchr (ptr+2, '"')) != NULL) { |
761 | if (*ptr == '"' && *(ptr+1) && (p2 = strchr (ptr+2, '"')) != NULL) { |
768 | c = *p2; *p2 = '\0'; |
762 | c = *p2; *p2 = '\0'; |
769 | FP_free (result->filename); |
763 | _FP_free (result->filename); |
770 | result->filename = FP_strdup (ptr+1); |
764 | result->filename = _FP_strdup (ptr+1); |
771 | *p2 = c; |
765 | *p2 = c; |
772 | } |
766 | } |
773 | else if (*ptr=='\''&&*(ptr+1)&&(p2 = strchr(ptr+2, '\'')) != NULL) { |
767 | else if (*ptr=='\''&&*(ptr+1)&&(p2 = strchr(ptr+2, '\'')) != NULL) { |
774 | c = *p2; *p2 = '\0'; |
768 | c = *p2; *p2 = '\0'; |
775 | FP_free (result->filename); |
769 | _FP_free (result->filename); |
776 | result->filename = FP_strdup (ptr+1); |
770 | result->filename = _FP_strdup (ptr+1); |
777 | *p2 = c; |
771 | *p2 = c; |
778 | } |
772 | } |
779 | else { |
773 | else { |
780 | p2 = ptr; |
774 | p2 = ptr; |
781 | while (isalnum(*p2) || |
775 | while (isalnum(*p2) || |
782 | *p2 == '.' || *p2=='_' || *p2 == '-' || |
776 | *p2 == '.' || *p2=='_' || *p2 == '-' || |
783 | *p2 == '!' || *p2=='@' || *p2 == '$') |
777 | *p2 == '!' || *p2=='@' || *p2 == '$') |
784 | p2++; |
778 | p2++; |
785 | c = *p2; *p2 = '\0'; |
779 | c = *p2; *p2 = '\0'; |
786 | if (p2 != ptr && result->filename == NULL) |
780 | if (p2 != ptr && result->filename == NULL) |
787 | result->filename = FP_strdup (ptr); |
781 | result->filename = _FP_strdup (ptr); |
788 | else if (p2 - ptr > 5 && strchr (ptr, '.') != NULL) { |
782 | else if (p2 - ptr > 5 && strchr (ptr, '.') != NULL) { |
789 | /* |
783 | /* |
790 | * This file name looks good, too. Let's use it |
784 | * This file name looks good, too. Let's use it |
791 | */ |
785 | */ |
792 | FP_free (result->filename); |
786 | _FP_free (result->filename); |
793 | result->filename = FP_strdup (ptr); |
787 | result->filename = _FP_strdup (ptr); |
794 | } |
788 | } |
795 | *p2 = c; |
789 | *p2 = c; |
796 | } |
790 | } |
797 | } |
791 | } |
798 | if ((ptr = FP_stristr (line, "id=")) && ctline<4) { |
792 | if ((ptr = _FP_stristr (line, "id=")) && ctline<4) { |
799 | p2 = ptr += 3; |
793 | p2 = ptr += 3; |
800 | if (*p2 == '"') { |
794 | if (*p2 == '"') { |
801 | p2 = strchr (++ptr, '"'); |
795 | p2 = strchr (++ptr, '"'); |
802 | } |
796 | } |
803 | else { |
797 | else { |
… | |
… | |
805 | p2++; |
799 | p2++; |
806 | } |
800 | } |
807 | if (p2 && *p2 && p2!=ptr) { |
801 | if (p2 && *p2 && p2!=ptr) { |
808 | c = *p2; *p2 = '\0'; |
802 | c = *p2; *p2 = '\0'; |
809 | if (result->mimeid) |
803 | if (result->mimeid) |
810 | FP_free (result->mimeid); |
804 | _FP_free (result->mimeid); |
811 | result->mimeid = FP_strdup (ptr); |
805 | result->mimeid = _FP_strdup (ptr); |
812 | *p2 = c; |
806 | *p2 = c; |
813 | } |
807 | } |
814 | } |
808 | } |
815 | |
809 | |
816 | /* |
810 | /* |
… | |
… | |
837 | * a boundary, followed by a Content-* line, try to use it. |
831 | * a boundary, followed by a Content-* line, try to use it. |
838 | */ |
832 | */ |
839 | |
833 | |
840 | if (boundary == NULL && !ismime && !uu_more_mime && dflag <= 1 && |
834 | if (boundary == NULL && !ismime && !uu_more_mime && dflag <= 1 && |
841 | line[0] == '-' && line[1] == '-' && strlen(line+2)>10 && |
835 | line[0] == '-' && line[1] == '-' && strlen(line+2)>10 && |
842 | (((ptr = FP_strrstr (line+2, "--")) == NULL) || |
836 | (((ptr = _FP_strrstr (line+2, "--")) == NULL) || |
843 | *(ptr+2) != '\012' && *(ptr+2) != '\015') && |
837 | (*(ptr+2) != '\012' && *(ptr+2) != '\015')) && |
844 | FP_strstr (line+2, "_=_") != NULL) { |
838 | _FP_strstr (line+2, "_=_") != NULL) { |
845 | if (FP_fgets (line, 255, datei) == NULL) { |
839 | if (_FP_fgets (line, 255, datei) == NULL) { |
846 | break; |
840 | break; |
847 | } |
841 | } |
848 | if (FP_strnicmp (line, "Content-", 8) == 0) { |
842 | if (_FP_strnicmp (line, "Content-", 8) == 0) { |
849 | /* |
843 | /* |
850 | * Okay, let's do it. This breaks out of ScanData. ScanPart will |
844 | * Okay, let's do it. This breaks out of ScanData. ScanPart will |
851 | * recognize the boundary on the next call and use it. |
845 | * recognize the boundary on the next call and use it. |
852 | */ |
846 | */ |
853 | fseek (datei, oldposition, SEEK_SET); |
847 | fseek (datei, oldposition, SEEK_SET); |
854 | break; |
848 | break; |
855 | } |
849 | } |
|
|
850 | } |
|
|
851 | |
|
|
852 | /* |
|
|
853 | * Detection for yEnc encoding |
|
|
854 | */ |
|
|
855 | |
|
|
856 | if (strncmp (line, "=ybegin ", 8) == 0 && |
|
|
857 | _FP_strstr (line, " size=") != NULL && |
|
|
858 | _FP_strstr (line, " name=") != NULL) { |
|
|
859 | if ((result->begin || result->end) && !uu_more_mime) { |
|
|
860 | fseek (datei, oldposition, SEEK_SET); |
|
|
861 | break; |
|
|
862 | } |
|
|
863 | |
|
|
864 | /* |
|
|
865 | * name continues to the end of the line |
|
|
866 | */ |
|
|
867 | |
|
|
868 | _FP_free (result->filename); |
|
|
869 | ptr = _FP_strstr (line, " name=") + 6; |
|
|
870 | result->filename = _FP_strdup (ptr); |
|
|
871 | |
|
|
872 | while (isspace (result->filename[strlen(result->filename)-1])) |
|
|
873 | result->filename[strlen(result->filename)-1] = '\0'; |
|
|
874 | |
|
|
875 | /* |
|
|
876 | * Determine size |
|
|
877 | */ |
|
|
878 | |
|
|
879 | ptr = _FP_strstr (line, " size=") + 6; |
|
|
880 | yefilesize = atoi (ptr); |
|
|
881 | |
|
|
882 | /* |
|
|
883 | * check for multipart file and read =ypart line |
|
|
884 | */ |
|
|
885 | |
|
|
886 | if ((ptr = _FP_strstr (line, " part=")) != NULL) { |
|
|
887 | result->partno = atoi (ptr + 6); |
|
|
888 | |
|
|
889 | if (result->partno == 1) { |
|
|
890 | result->begin = 1; |
|
|
891 | } |
|
|
892 | |
|
|
893 | if (_FP_fgets (line, 255, datei) == NULL) { |
|
|
894 | break; |
|
|
895 | } |
|
|
896 | |
|
|
897 | line[255] = '\0'; |
|
|
898 | |
|
|
899 | if (strncmp (line, "=ypart ", 7) != 0) { |
|
|
900 | break; |
|
|
901 | } |
|
|
902 | |
|
|
903 | if ((ptr = _FP_strstr (line, " end=")) == NULL) { |
|
|
904 | break; |
|
|
905 | } |
|
|
906 | |
|
|
907 | yepartends = atoi (ptr + 5); |
|
|
908 | } |
|
|
909 | else { |
|
|
910 | result->partno = 1; |
|
|
911 | result->begin = 1; |
|
|
912 | } |
|
|
913 | |
|
|
914 | /* |
|
|
915 | * Don't want auto-detection |
|
|
916 | */ |
|
|
917 | |
|
|
918 | result->uudet = YENC_ENCODED; |
|
|
919 | continue; |
|
|
920 | } |
|
|
921 | |
|
|
922 | if (strncmp (line, "=yend ", 6) == 0 && |
|
|
923 | result->uudet == YENC_ENCODED) { |
|
|
924 | if (yepartends == 0 || yepartends >= yefilesize) { |
|
|
925 | result->end = 1; |
|
|
926 | } |
|
|
927 | if (!uu_more_mime) |
|
|
928 | break; |
856 | } |
929 | } |
857 | |
930 | |
858 | /* |
931 | /* |
859 | * if we haven't yet found anything encoded, try to find something |
932 | * if we haven't yet found anything encoded, try to find something |
860 | */ |
933 | */ |
… | |
… | |
934 | } |
1007 | } |
935 | if ((bhdsp-bhds2) > (int) bhds2[0] && bhds2[0]>0 && |
1008 | if ((bhdsp-bhds2) > (int) bhds2[0] && bhds2[0]>0 && |
936 | result->filename==NULL) { |
1009 | result->filename==NULL) { |
937 | memcpy (bhds1, bhds2+1, (int) bhds2[0]); |
1010 | memcpy (bhds1, bhds2+1, (int) bhds2[0]); |
938 | bhds1[(int)bhds2[0]]='\0'; |
1011 | bhds1[(int)bhds2[0]]='\0'; |
939 | result->filename = FP_strdup (bhds1); |
1012 | result->filename = _FP_strdup (bhds1); |
940 | bhnf = 1; |
1013 | bhnf = 1; |
941 | } |
1014 | } |
942 | else if (bhdsp-bhds2 >= 256 && bhds2[0]>0) { |
1015 | else if (bhdsp-bhds2 >= 256 && bhds2[0]>0) { |
943 | memcpy (bhds1, bhds2+1, 255); |
1016 | memcpy (bhds1, bhds2+1, 255); |
944 | bhds1[255] = '\0'; |
1017 | bhds1[255] = '\0'; |
945 | result->filename = FP_strdup (bhds1); |
1018 | result->filename = _FP_strdup (bhds1); |
946 | bhnf = 1; |
1019 | bhnf = 1; |
947 | } |
1020 | } |
948 | else if (bhds2[0] <= 0) |
1021 | else if (bhds2[0] <= 0) |
949 | bhnf = 1; |
1022 | bhnf = 1; |
950 | } |
1023 | } |
… | |
… | |
1015 | *errcode = UURET_CANCEL; |
1088 | *errcode = UURET_CANCEL; |
1016 | break; |
1089 | break; |
1017 | } |
1090 | } |
1018 | |
1091 | |
1019 | oldposition = ftell (datei); |
1092 | oldposition = ftell (datei); |
1020 | if (FP_fgets (line, 255, datei) == NULL) |
1093 | if (_FP_fgets (line, 255, datei) == NULL) |
1021 | break; |
1094 | break; |
1022 | if (ferror (datei)) |
1095 | if (ferror (datei)) |
1023 | break; |
1096 | break; |
1024 | |
1097 | |
1025 | line[255] = '\0'; |
1098 | line[255] = '\0'; |
… | |
… | |
1202 | /* Base64 doesn't have begin or end */ |
1275 | /* Base64 doesn't have begin or end */ |
1203 | if (result->uudet == B64ENCODED) |
1276 | if (result->uudet == B64ENCODED) |
1204 | result->begin = result->end = 0; |
1277 | result->begin = result->end = 0; |
1205 | |
1278 | |
1206 | /* Base64 and BinHex don't have a file mode */ |
1279 | /* Base64 and BinHex don't have a file mode */ |
1207 | if (result->uudet == B64ENCODED || result->uudet == BH_ENCODED) |
1280 | if (result->uudet == B64ENCODED || result->uudet == BH_ENCODED || |
|
|
1281 | result->uudet == YENC_ENCODED) |
1208 | result->mode = 6*64+4*8+4; |
1282 | result->mode = 6*64+4*8+4; |
1209 | |
1283 | |
1210 | /* |
1284 | /* |
1211 | * When strict MIME adherance is set, throw out suspicious attachments |
1285 | * When strict MIME adherance is set, throw out suspicious attachments |
1212 | */ |
1286 | */ |
… | |
… | |
1253 | if (boundary && line[0] == '-' && line[1] == '-' && |
1327 | if (boundary && line[0] == '-' && line[1] == '-' && |
1254 | strncmp (line+2, boundary, blen) == 0) |
1328 | strncmp (line+2, boundary, blen) == 0) |
1255 | return 2; |
1329 | return 2; |
1256 | else if (boundary && p3 && |
1330 | else if (boundary && p3 && |
1257 | line[0] == 'C' && line[1] == 'o' && |
1331 | line[0] == 'C' && line[1] == 'o' && |
1258 | FP_strnicmp (line, "Content-Type:", 13) == 0 && |
1332 | _FP_strnicmp (line, "Content-Type:", 13) == 0 && |
1259 | strcmp (p3, boundary) == 0) |
1333 | strcmp (p3, boundary) == 0) |
1260 | return 2; |
1334 | return 2; |
1261 | else if (IsKnownHeader (line)) |
1335 | else if (IsKnownHeader (line)) |
1262 | return 1; |
1336 | return 1; |
1263 | |
1337 | |
… | |
… | |
1270 | |
1344 | |
1271 | fileread * |
1345 | fileread * |
1272 | ScanPart (FILE *datei, char *fname, int *errcode) |
1346 | ScanPart (FILE *datei, char *fname, int *errcode) |
1273 | { |
1347 | { |
1274 | int ecount, hcount, lcount; |
1348 | int ecount, hcount, lcount; |
1275 | int bhflag, begflag, vflag, blen, res; |
1349 | int bhflag, begflag, vflag, blen=0, res; |
1276 | long preheaders, prevpos, preenc, before; |
1350 | long preheaders, prevpos=0, preenc, before; |
1277 | char *line=uuscan_spline; |
1351 | char *line=uuscan_spline; |
1278 | fileread *result; |
1352 | fileread *result; |
1279 | char *ptr1, *ptr2; |
1353 | char *ptr1, *ptr2; |
1280 | |
|
|
1281 | blen = 0; prevpos = 0; /* calm down gcc */ |
|
|
1282 | |
1354 | |
1283 | (void) UUDecodeLine (NULL, NULL, 0); /* init */ |
1355 | (void) UUDecodeLine (NULL, NULL, 0); /* init */ |
1284 | if (datei == NULL || feof (datei)) { |
1356 | if (datei == NULL || feof (datei)) { |
1285 | *errcode = UURET_OK; |
1357 | *errcode = UURET_OK; |
1286 | return NULL; |
1358 | return NULL; |
… | |
… | |
1305 | /* mimseqno = 1; */ |
1377 | /* mimseqno = 1; */ |
1306 | |
1378 | |
1307 | while (mssdepth) { |
1379 | while (mssdepth) { |
1308 | mssdepth--; |
1380 | mssdepth--; |
1309 | UUkillheaders (&(multistack[mssdepth].envelope)); |
1381 | UUkillheaders (&(multistack[mssdepth].envelope)); |
1310 | FP_free (multistack[mssdepth].source); |
1382 | _FP_free (multistack[mssdepth].source); |
1311 | } |
1383 | } |
1312 | |
1384 | |
1313 | UUkillheaders (&sstate.envelope); |
1385 | UUkillheaders (&sstate.envelope); |
1314 | memset (&sstate.envelope, 0, sizeof (headers)); |
1386 | memset (&sstate.envelope, 0, sizeof (headers)); |
1315 | |
1387 | |
1316 | FP_free (sstate.source); |
1388 | _FP_free (sstate.source); |
1317 | if ((sstate.source = FP_strdup (fname)) == NULL) { |
1389 | if ((sstate.source = _FP_strdup (fname)) == NULL) { |
1318 | *errcode = UURET_NOMEM; |
1390 | *errcode = UURET_NOMEM; |
1319 | FP_free (result); |
1391 | _FP_free (result); |
1320 | return NULL; |
1392 | return NULL; |
1321 | } |
1393 | } |
1322 | |
1394 | |
1323 | /* ignore empty lines at the beginning of a file */ |
1395 | /* ignore empty lines at the beginning of a file */ |
1324 | preheaders = ftell (datei); |
1396 | preheaders = ftell (datei); |
1325 | while (!feof (datei)) { |
1397 | while (!feof (datei)) { |
1326 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
1398 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
1327 | if (FP_fgets (line, 255, datei) == NULL) |
1399 | if (_FP_fgets (line, 255, datei) == NULL) |
1328 | break; |
1400 | break; |
1329 | if (!IsLineEmpty (line)) { |
1401 | if (!IsLineEmpty (line)) { |
1330 | fseek (datei, preheaders, SEEK_SET); |
1402 | fseek (datei, preheaders, SEEK_SET); |
1331 | line[255] = '\0'; |
1403 | line[255] = '\0'; |
1332 | break; |
1404 | break; |
… | |
… | |
1334 | preheaders = ftell (datei); |
1406 | preheaders = ftell (datei); |
1335 | } |
1407 | } |
1336 | } |
1408 | } |
1337 | |
1409 | |
1338 | if (ferror(datei) || feof(datei)) { |
1410 | if (ferror(datei) || feof(datei)) { |
1339 | FP_free (result); |
1411 | _FP_free (result); |
1340 | return NULL; |
1412 | return NULL; |
1341 | } |
1413 | } |
1342 | |
1414 | |
1343 | /* |
1415 | /* |
1344 | * If we are confident that this is a mail folder and are at the |
1416 | * If we are confident that this is a mail folder and are at the |
… | |
… | |
1356 | */ |
1428 | */ |
1357 | |
1429 | |
1358 | while (mssdepth) { |
1430 | while (mssdepth) { |
1359 | mssdepth--; |
1431 | mssdepth--; |
1360 | UUkillheaders (&(multistack[mssdepth].envelope)); |
1432 | UUkillheaders (&(multistack[mssdepth].envelope)); |
1361 | FP_free (multistack[mssdepth].source); |
1433 | _FP_free (multistack[mssdepth].source); |
1362 | } |
1434 | } |
1363 | |
1435 | |
1364 | if (FP_fgets (line, 255, datei) == NULL) { |
1436 | if (_FP_fgets (line, 255, datei) == NULL) { |
1365 | FP_free (result); |
1437 | _FP_free (result); |
1366 | return NULL; |
1438 | return NULL; |
1367 | } |
1439 | } |
1368 | line[255] = '\0'; |
1440 | line[255] = '\0'; |
1369 | |
1441 | |
1370 | /* |
1442 | /* |
… | |
… | |
1380 | line[strlen(line)-1] == '\015') { |
1452 | line[strlen(line)-1] == '\015') { |
1381 | line[strlen(line)-1] = '\0'; |
1453 | line[strlen(line)-1] = '\0'; |
1382 | } |
1454 | } |
1383 | |
1455 | |
1384 | sstate.ismime = 1; |
1456 | sstate.ismime = 1; |
1385 | sstate.envelope.mimevers = FP_strdup ("1.0"); |
1457 | sstate.envelope.mimevers = _FP_strdup ("1.0"); |
1386 | sstate.envelope.boundary = FP_strdup (line+2); |
1458 | sstate.envelope.boundary = _FP_strdup (line+2); |
1387 | sstate.envelope.ctype = FP_strdup ("multipart/mixed"); |
1459 | sstate.envelope.ctype = _FP_strdup ("multipart/mixed"); |
1388 | sstate.mimestate = MS_SUBPART; |
1460 | sstate.mimestate = MS_SUBPART; |
1389 | |
1461 | |
1390 | *errcode = UURET_CONT; |
1462 | *errcode = UURET_CONT; |
1391 | FP_free (result); |
1463 | _FP_free (result); |
1392 | return NULL; |
1464 | return NULL; |
1393 | } |
1465 | } |
1394 | |
1466 | |
1395 | /* |
1467 | /* |
1396 | * Normal behavior: look for a RFC 822 header |
1468 | * Normal behavior: look for a RFC 822 header |
… | |
… | |
1401 | hcount++; |
1473 | hcount++; |
1402 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
1474 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
1403 | ptr1 = ScanHeaderLine (datei, line); |
1475 | ptr1 = ScanHeaderLine (datei, line); |
1404 | if (ParseHeader (&sstate.envelope, ptr1) == NULL) { |
1476 | if (ParseHeader (&sstate.envelope, ptr1) == NULL) { |
1405 | *errcode = UURET_NOMEM; |
1477 | *errcode = UURET_NOMEM; |
1406 | FP_free (result); |
1478 | _FP_free (result); |
1407 | return NULL; |
1479 | return NULL; |
1408 | } |
1480 | } |
1409 | /* |
1481 | /* |
1410 | * if we've read too many lines without finding headers, then |
1482 | * if we've read too many lines without finding headers, then |
1411 | * this probably isn't a mail folder after all |
1483 | * this probably isn't a mail folder after all |
1412 | */ |
1484 | */ |
1413 | lcount++; |
1485 | lcount++; |
1414 | if (lcount > WAITHEADER && hcount < hlcount.afternl) |
1486 | if (lcount > WAITHEADER && hcount < hlcount.afternl) |
1415 | break; |
1487 | break; |
1416 | |
1488 | |
1417 | if (FP_fgets (line, 255, datei) == NULL) |
1489 | if (_FP_fgets (line, 255, datei) == NULL) |
1418 | break; |
1490 | break; |
1419 | line[255] = '\0'; |
1491 | line[255] = '\0'; |
1420 | } |
1492 | } |
1421 | /* skip empty lines */ |
1493 | /* skip empty lines */ |
1422 | prevpos = ftell (datei); |
1494 | prevpos = ftell (datei); |
1423 | while (!feof (datei)) { |
1495 | while (!feof (datei)) { |
1424 | if (FP_fgets (line, 255, datei) == NULL) |
1496 | if (_FP_fgets (line, 255, datei) == NULL) |
1425 | break; |
1497 | break; |
1426 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
1498 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
1427 | if (!IsLineEmpty (line)) { |
1499 | if (!IsLineEmpty (line)) { |
1428 | fseek (datei, prevpos, SEEK_SET); |
1500 | fseek (datei, prevpos, SEEK_SET); |
1429 | line[255] = '\0'; |
1501 | line[255] = '\0'; |
… | |
… | |
1442 | sstate.envelope.ctenc == NULL && |
1514 | sstate.envelope.ctenc == NULL && |
1443 | IsKnownHeader (line)) { |
1515 | IsKnownHeader (line)) { |
1444 | /* |
1516 | /* |
1445 | * see above |
1517 | * see above |
1446 | */ |
1518 | */ |
1447 | if (FP_fgets (line, 255, datei) == NULL) { |
1519 | if (_FP_fgets (line, 255, datei) == NULL) { |
1448 | line[0] = '\012'; |
1520 | line[0] = '\012'; |
1449 | line[1] = '\0'; |
1521 | line[1] = '\0'; |
1450 | } |
1522 | } |
1451 | line[255] = '\0'; |
1523 | line[255] = '\0'; |
1452 | |
1524 | |
… | |
… | |
1455 | hcount++; |
1527 | hcount++; |
1456 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
1528 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
1457 | ptr1 = ScanHeaderLine (datei, line); |
1529 | ptr1 = ScanHeaderLine (datei, line); |
1458 | if (ParseHeader (&sstate.envelope, ptr1) == NULL) { |
1530 | if (ParseHeader (&sstate.envelope, ptr1) == NULL) { |
1459 | *errcode = UURET_NOMEM; |
1531 | *errcode = UURET_NOMEM; |
1460 | FP_free (result); |
1532 | _FP_free (result); |
1461 | return NULL; |
1533 | return NULL; |
1462 | } |
1534 | } |
1463 | |
|
|
1464 | if (FP_fgets (line, 255, datei) == NULL) |
1535 | if (_FP_fgets (line, 255, datei) == NULL) |
1465 | break; |
1536 | break; |
1466 | line[255] = '\0'; |
1537 | line[255] = '\0'; |
1467 | } |
1538 | } |
1468 | /* skip empty lines */ |
1539 | /* skip empty lines */ |
1469 | prevpos = ftell (datei); |
1540 | prevpos = ftell (datei); |
1470 | while (!feof (datei)) { |
1541 | while (!feof (datei)) { |
1471 | if (FP_fgets (line, 255, datei) == NULL) |
1542 | if (_FP_fgets (line, 255, datei) == NULL) |
1472 | break; |
1543 | break; |
1473 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
1544 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
1474 | if (!IsLineEmpty (line)) { |
1545 | if (!IsLineEmpty (line)) { |
1475 | fseek (datei, prevpos, SEEK_SET); |
1546 | fseek (datei, prevpos, SEEK_SET); |
1476 | line[255] = '\0'; |
1547 | line[255] = '\0'; |
… | |
… | |
1486 | * MIME message |
1557 | * MIME message |
1487 | * if mimevers is not set but there are other well-known MIME |
1558 | * if mimevers is not set but there are other well-known MIME |
1488 | * headers, don't be too picky about it. |
1559 | * headers, don't be too picky about it. |
1489 | */ |
1560 | */ |
1490 | if (sstate.envelope.ctype && sstate.envelope.mimevers==NULL && |
1561 | if (sstate.envelope.ctype && sstate.envelope.mimevers==NULL && |
1491 | FP_stristr (sstate.envelope.ctype, "multipart") != NULL && |
1562 | _FP_stristr (sstate.envelope.ctype, "multipart") != NULL && |
1492 | sstate.envelope.boundary != NULL) { |
1563 | sstate.envelope.boundary != NULL) { |
1493 | sstate.envelope.mimevers = FP_strdup ("1.0"); |
1564 | sstate.envelope.mimevers = _FP_strdup ("1.0"); |
1494 | hcount = hlcount.afternl; |
1565 | hcount = hlcount.afternl; |
1495 | } |
1566 | } |
1496 | else if (sstate.envelope.mimevers==NULL && sstate.envelope.ctype && |
1567 | else if (sstate.envelope.mimevers==NULL && sstate.envelope.ctype && |
1497 | sstate.envelope.fname && sstate.envelope.ctenc) { |
1568 | sstate.envelope.fname && sstate.envelope.ctenc) { |
1498 | sstate.envelope.mimevers = FP_strdup ("1.0"); |
1569 | sstate.envelope.mimevers = _FP_strdup ("1.0"); |
1499 | hcount = hlcount.afternl; |
1570 | hcount = hlcount.afternl; |
1500 | } |
1571 | } |
1501 | |
1572 | |
1502 | if (hcount < hlcount.afternl) { |
1573 | if (hcount < hlcount.afternl) { |
1503 | /* not a folder after all */ |
1574 | /* not a folder after all */ |
… | |
… | |
1506 | sstate.ismime = 0; |
1577 | sstate.ismime = 0; |
1507 | } |
1578 | } |
1508 | else if (sstate.envelope.mimevers != NULL) { |
1579 | else if (sstate.envelope.mimevers != NULL) { |
1509 | /* this is a MIME file. check the Content-Type */ |
1580 | /* this is a MIME file. check the Content-Type */ |
1510 | sstate.ismime = 1; |
1581 | sstate.ismime = 1; |
1511 | if (FP_stristr (sstate.envelope.ctype, "multipart") != NULL) { |
1582 | if (_FP_stristr (sstate.envelope.ctype, "multipart") != NULL) { |
1512 | if (sstate.envelope.boundary == NULL) { |
1583 | if (sstate.envelope.boundary == NULL) { |
1513 | UUMessage (uuscan_id, __LINE__, UUMSG_WARNING, |
1584 | UUMessage (uuscan_id, __LINE__, UUMSG_WARNING, |
1514 | uustring (S_MIME_NO_BOUNDARY)); |
1585 | uustring (S_MIME_NO_BOUNDARY)); |
1515 | sstate.mimestate = MS_BODY; |
1586 | sstate.mimestate = MS_BODY; |
1516 | FP_free (sstate.envelope.ctype); |
1587 | _FP_free (sstate.envelope.ctype); |
1517 | sstate.envelope.ctype = FP_strdup ("text/plain"); |
1588 | sstate.envelope.ctype = _FP_strdup ("text/plain"); |
1518 | } |
1589 | } |
1519 | else { |
1590 | else { |
1520 | sstate.mimestate = MS_PREAMBLE; |
1591 | sstate.mimestate = MS_PREAMBLE; |
1521 | } |
1592 | } |
1522 | } |
1593 | } |
… | |
… | |
1525 | } |
1596 | } |
1526 | } |
1597 | } |
1527 | } |
1598 | } |
1528 | |
1599 | |
1529 | if (feof (datei) || ferror (datei)) { /* oops */ |
1600 | if (feof (datei) || ferror (datei)) { /* oops */ |
1530 | FP_free (result); |
1601 | _FP_free (result); |
1531 | return NULL; |
1602 | return NULL; |
1532 | } |
1603 | } |
1533 | |
1604 | |
1534 | /* |
1605 | /* |
1535 | * Handle MIME stuff |
1606 | * Handle MIME stuff |
… | |
… | |
1547 | |
1618 | |
1548 | blen = strlen (sstate.envelope.boundary); |
1619 | blen = strlen (sstate.envelope.boundary); |
1549 | lcount = 0; |
1620 | lcount = 0; |
1550 | |
1621 | |
1551 | while (!feof (datei)) { |
1622 | while (!feof (datei)) { |
1552 | if (FP_fgets (line, 255, datei) == NULL) { |
1623 | if (_FP_fgets (line, 255, datei) == NULL) { |
1553 | line[0] = '\0'; |
1624 | line[0] = '\0'; |
1554 | break; |
1625 | break; |
1555 | } |
1626 | } |
1556 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
1627 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
1557 | if (line[0] == '-' && line[1] == '-' && |
1628 | if (line[0] == '-' && line[1] == '-' && |
… | |
… | |
1574 | |
1645 | |
1575 | if (!uu_fast_scanning) { |
1646 | if (!uu_fast_scanning) { |
1576 | *errcode = UURET_CONT; |
1647 | *errcode = UURET_CONT; |
1577 | fseek (datei, preheaders, SEEK_SET); |
1648 | fseek (datei, preheaders, SEEK_SET); |
1578 | } |
1649 | } |
1579 | FP_free (result); |
1650 | _FP_free (result); |
1580 | return NULL; |
1651 | return NULL; |
1581 | } |
1652 | } |
1582 | if (line[0] == '-' && line[1] == '-' && |
1653 | if (line[0] == '-' && line[1] == '-' && |
1583 | strncmp (line+2, sstate.envelope.boundary, blen) == 0) { |
1654 | strncmp (line+2, sstate.envelope.boundary, blen) == 0) { |
1584 | ptr1 = line + 2 + blen; |
1655 | ptr1 = line + 2 + blen; |
… | |
… | |
1602 | |
1673 | |
1603 | if (!uu_fast_scanning) { |
1674 | if (!uu_fast_scanning) { |
1604 | *errcode = UURET_CONT; |
1675 | *errcode = UURET_CONT; |
1605 | fseek (datei, preheaders, SEEK_SET); |
1676 | fseek (datei, preheaders, SEEK_SET); |
1606 | } |
1677 | } |
1607 | FP_free (result); |
1678 | _FP_free (result); |
1608 | return NULL; |
1679 | return NULL; |
1609 | } |
1680 | } |
1610 | /* produce result if uu_usepreamble is set */ |
1681 | /* produce result if uu_usepreamble is set */ |
1611 | if (uu_usepreamble && lcount) { |
1682 | if (uu_usepreamble && lcount) { |
1612 | sprintf (line, "%04d.txt", ++mimseqno); |
1683 | sprintf (line, "%04d.txt", ++mimseqno); |
1613 | result->subject = FP_strdup (sstate.envelope.subject); |
1684 | result->subject = _FP_strdup (sstate.envelope.subject); |
1614 | result->filename = FP_strdup (line); |
1685 | result->filename = _FP_strdup (line); |
1615 | result->origin = FP_strdup (sstate.envelope.from); |
1686 | result->origin = _FP_strdup (sstate.envelope.from); |
1616 | result->mimeid = FP_strdup (sstate.envelope.mimeid); |
1687 | result->mimeid = _FP_strdup (sstate.envelope.mimeid); |
1617 | result->mimetype = FP_strdup ("text/plain"); |
1688 | result->mimetype = _FP_strdup ("text/plain"); |
1618 | result->mode = 0644; |
1689 | result->mode = 0644; |
1619 | result->uudet = PT_ENCODED; /* plain text */ |
1690 | result->uudet = PT_ENCODED; /* plain text */ |
1620 | result->sfname = FP_strdup (fname); |
1691 | result->sfname = _FP_strdup (fname); |
1621 | result->flags = FL_SINGLE | FL_PROPER; |
1692 | result->flags = FL_SINGLE | FL_PROPER; |
1622 | /* result->startpos set from above */ |
1693 | /* result->startpos set from above */ |
1623 | result->length = prevpos - result->startpos; |
1694 | result->length = prevpos - result->startpos; |
1624 | result->partno = 1; |
1695 | result->partno = 1; |
1625 | |
1696 | |
… | |
… | |
1636 | /* MIME message, let's continue */ |
1707 | /* MIME message, let's continue */ |
1637 | if (*errcode == UURET_OK) |
1708 | if (*errcode == UURET_OK) |
1638 | *errcode = UURET_CONT; |
1709 | *errcode = UURET_CONT; |
1639 | |
1710 | |
1640 | /* otherwise, just return NULL */ |
1711 | /* otherwise, just return NULL */ |
1641 | FP_free (result); |
1712 | _FP_free (result); |
1642 | return NULL; |
1713 | return NULL; |
1643 | } |
1714 | } |
1644 | |
1715 | |
1645 | /* |
1716 | /* |
1646 | * Read Epilogue, the plain text after the last boundary. |
1717 | * Read Epilogue, the plain text after the last boundary. |
… | |
… | |
1673 | if (uu_fast_scanning && mssdepth == 0) { |
1744 | if (uu_fast_scanning && mssdepth == 0) { |
1674 | /* |
1745 | /* |
1675 | * check if the epilogue is empty |
1746 | * check if the epilogue is empty |
1676 | */ |
1747 | */ |
1677 | while (!feof (datei) && !ferror (datei) && lcount<10 && res==0) { |
1748 | while (!feof (datei) && !ferror (datei) && lcount<10 && res==0) { |
1678 | if (FP_fgets (line, 255, datei) == NULL) |
1749 | if (_FP_fgets (line, 255, datei) == NULL) |
1679 | break; |
1750 | break; |
1680 | if (!IsLineEmpty (line)) |
1751 | if (!IsLineEmpty (line)) |
1681 | res++; |
1752 | res++; |
1682 | lcount++; |
1753 | lcount++; |
1683 | } |
1754 | } |
1684 | if (uu_usepreamble && res) { |
1755 | if (uu_usepreamble && res) { |
1685 | sprintf (line, "%04d.txt", ++mimseqno); |
1756 | sprintf (line, "%04d.txt", ++mimseqno); |
1686 | result->subject = FP_strdup (sstate.envelope.subject); |
1757 | result->subject = _FP_strdup (sstate.envelope.subject); |
1687 | result->filename = FP_strdup (line); |
1758 | result->filename = _FP_strdup (line); |
1688 | result->origin = FP_strdup (sstate.envelope.from); |
1759 | result->origin = _FP_strdup (sstate.envelope.from); |
1689 | result->mimeid = FP_strdup (sstate.envelope.mimeid); |
1760 | result->mimeid = _FP_strdup (sstate.envelope.mimeid); |
1690 | result->mimetype = FP_strdup ("text/plain"); |
1761 | result->mimetype = _FP_strdup ("text/plain"); |
1691 | result->mode = 0644; |
1762 | result->mode = 0644; |
1692 | result->uudet = PT_ENCODED; /* plain text */ |
1763 | result->uudet = PT_ENCODED; /* plain text */ |
1693 | result->sfname = FP_strdup (fname); |
1764 | result->sfname = _FP_strdup (fname); |
1694 | result->flags = FL_SINGLE | FL_PROPER | FL_TOEND; |
1765 | result->flags = FL_SINGLE | FL_PROPER | FL_TOEND; |
1695 | result->partno = 1; |
1766 | result->partno = 1; |
1696 | /* result->startpos set from above */ |
1767 | /* result->startpos set from above */ |
1697 | result->length = progress.fsize - result->startpos; |
1768 | result->length = progress.fsize - result->startpos; |
1698 | |
1769 | |
… | |
… | |
1701 | *errcode = UURET_NOMEM; |
1772 | *errcode = UURET_NOMEM; |
1702 | } |
1773 | } |
1703 | |
1774 | |
1704 | return result; |
1775 | return result; |
1705 | } |
1776 | } |
1706 | FP_free (result); |
1777 | _FP_free (result); |
1707 | return NULL; |
1778 | return NULL; |
1708 | } |
1779 | } |
1709 | |
1780 | |
1710 | if (mssdepth > 0) |
1781 | if (mssdepth > 0) |
1711 | blen = strlen (multistack[mssdepth-1].envelope.boundary); |
1782 | blen = strlen (multistack[mssdepth-1].envelope.boundary); |
1712 | |
1783 | |
1713 | while (!feof (datei)) { |
1784 | while (!feof (datei)) { |
1714 | if (FP_fgets (line, 255, datei) == NULL) { |
1785 | if (_FP_fgets (line, 255, datei) == NULL) { |
1715 | line[0] = '\0'; |
1786 | line[0] = '\0'; |
1716 | break; |
1787 | break; |
1717 | } |
1788 | } |
1718 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
1789 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
1719 | line[255] = '\0'; |
1790 | line[255] = '\0'; |
… | |
… | |
1750 | } |
1821 | } |
1751 | |
1822 | |
1752 | /* check for begin and encoded data only at outermost level */ |
1823 | /* check for begin and encoded data only at outermost level */ |
1753 | if (mssdepth == 0 && !uu_more_mime) { |
1824 | if (mssdepth == 0 && !uu_more_mime) { |
1754 | if (strncmp (line, "begin ", 6) == 0 || |
1825 | if (strncmp (line, "begin ", 6) == 0 || |
1755 | FP_strnicmp (line, "<pre>begin ", 11) == 0) { |
1826 | _FP_strnicmp (line, "<pre>begin ", 11) == 0) { |
1756 | preenc = prevpos; |
1827 | preenc = prevpos; |
1757 | begflag = 1; |
1828 | begflag = 1; |
1758 | } |
1829 | } |
1759 | else if (strncmp (line, "end", 3) == 0 && begflag) { |
1830 | else if (strncmp (line, "end", 3) == 0 && begflag) { |
1760 | ecount = ELC_COUNT; |
1831 | ecount = ELC_COUNT; |
… | |
… | |
1793 | strncmp (line+2, |
1864 | strncmp (line+2, |
1794 | multistack[mssdepth-1].envelope.boundary, blen) == 0) { |
1865 | multistack[mssdepth-1].envelope.boundary, blen) == 0) { |
1795 | /* restore previous state */ |
1866 | /* restore previous state */ |
1796 | mssdepth--; |
1867 | mssdepth--; |
1797 | UUkillheaders (&sstate.envelope); |
1868 | UUkillheaders (&sstate.envelope); |
1798 | FP_free (sstate.source); |
1869 | _FP_free (sstate.source); |
1799 | memcpy (&sstate, &(multistack[mssdepth]), sizeof (scanstate)); |
1870 | memcpy (&sstate, &(multistack[mssdepth]), sizeof (scanstate)); |
1800 | |
1871 | |
1801 | ptr1 = line + 2 + strlen (sstate.envelope.boundary); |
1872 | ptr1 = line + 2 + strlen (sstate.envelope.boundary); |
1802 | |
1873 | |
1803 | if (*ptr1 == '-' && *(ptr1+1) == '-') { |
1874 | if (*ptr1 == '-' && *(ptr1+1) == '-') { |
… | |
… | |
1820 | sstate.mimestate = MS_BODY; |
1891 | sstate.mimestate = MS_BODY; |
1821 | |
1892 | |
1822 | while (mssdepth) { |
1893 | while (mssdepth) { |
1823 | mssdepth--; |
1894 | mssdepth--; |
1824 | UUkillheaders (&(multistack[mssdepth].envelope)); |
1895 | UUkillheaders (&(multistack[mssdepth].envelope)); |
1825 | FP_free (multistack[mssdepth].source); |
1896 | _FP_free (multistack[mssdepth].source); |
1826 | } |
1897 | } |
1827 | |
1898 | |
1828 | if (!uu_fast_scanning) { |
1899 | if (!uu_fast_scanning) { |
1829 | *errcode = UURET_CONT; |
1900 | *errcode = UURET_CONT; |
1830 | fseek (datei, preheaders, SEEK_SET); |
1901 | fseek (datei, preheaders, SEEK_SET); |
1831 | } |
1902 | } |
1832 | FP_free (result); |
1903 | _FP_free (result); |
1833 | return NULL; |
1904 | return NULL; |
1834 | } |
1905 | } |
1835 | else if (IsKnownHeader (line)) { |
1906 | else if (IsKnownHeader (line)) { |
1836 | /* new message follows */ |
1907 | /* new message follows */ |
1837 | sstate.isfolder = 1; |
1908 | sstate.isfolder = 1; |
… | |
… | |
1850 | } |
1921 | } |
1851 | |
1922 | |
1852 | /* produce result if uu_usepreamble is set */ |
1923 | /* produce result if uu_usepreamble is set */ |
1853 | if (uu_usepreamble && res) { |
1924 | if (uu_usepreamble && res) { |
1854 | sprintf (line, "%04d.txt", ++mimseqno); |
1925 | sprintf (line, "%04d.txt", ++mimseqno); |
1855 | result->subject = FP_strdup (sstate.envelope.subject); |
1926 | result->subject = _FP_strdup (sstate.envelope.subject); |
1856 | result->filename = FP_strdup (line); |
1927 | result->filename = _FP_strdup (line); |
1857 | result->origin = FP_strdup (sstate.envelope.from); |
1928 | result->origin = _FP_strdup (sstate.envelope.from); |
1858 | result->mimeid = FP_strdup (sstate.envelope.mimeid); |
1929 | result->mimeid = _FP_strdup (sstate.envelope.mimeid); |
1859 | result->mimetype = FP_strdup ("text/plain"); |
1930 | result->mimetype = _FP_strdup ("text/plain"); |
1860 | result->mode = 0644; |
1931 | result->mode = 0644; |
1861 | result->uudet = PT_ENCODED; /* plain text */ |
1932 | result->uudet = PT_ENCODED; /* plain text */ |
1862 | result->sfname = FP_strdup (fname); |
1933 | result->sfname = _FP_strdup (fname); |
1863 | result->flags = FL_SINGLE | FL_PROPER; |
1934 | result->flags = FL_SINGLE | FL_PROPER; |
1864 | result->partno = 1; |
1935 | result->partno = 1; |
1865 | /* result->startpos set from above */ |
1936 | /* result->startpos set from above */ |
1866 | /* result->length set from above */ |
1937 | /* result->length set from above */ |
1867 | |
1938 | |
… | |
… | |
1871 | } |
1942 | } |
1872 | |
1943 | |
1873 | return result; |
1944 | return result; |
1874 | } |
1945 | } |
1875 | /* otherwise, just return NULL */ |
1946 | /* otherwise, just return NULL */ |
1876 | FP_free (result); |
1947 | _FP_free (result); |
1877 | return NULL; |
1948 | return NULL; |
1878 | } |
1949 | } |
1879 | |
1950 | |
1880 | /* |
1951 | /* |
1881 | * Scan a new part from a Multipart message. Check for a new local |
1952 | * Scan a new part from a Multipart message. Check for a new local |
… | |
… | |
1895 | |
1966 | |
1896 | /* |
1967 | /* |
1897 | * Duplicate some data from outer envelope |
1968 | * Duplicate some data from outer envelope |
1898 | */ |
1969 | */ |
1899 | |
1970 | |
1900 | localenv.mimevers = FP_strdup (sstate.envelope.mimevers); |
1971 | localenv.mimevers = _FP_strdup (sstate.envelope.mimevers); |
1901 | localenv.from = FP_strdup (sstate.envelope.from); |
1972 | localenv.from = _FP_strdup (sstate.envelope.from); |
1902 | localenv.subject = FP_strdup (sstate.envelope.subject); |
1973 | localenv.subject = _FP_strdup (sstate.envelope.subject); |
1903 | localenv.rcpt = FP_strdup (sstate.envelope.rcpt); |
1974 | localenv.rcpt = _FP_strdup (sstate.envelope.rcpt); |
1904 | localenv.date = FP_strdup (sstate.envelope.date); |
1975 | localenv.date = _FP_strdup (sstate.envelope.date); |
1905 | |
1976 | |
1906 | if ((sstate.envelope.mimevers != NULL && localenv.mimevers == NULL) || |
1977 | if ((sstate.envelope.mimevers != NULL && localenv.mimevers == NULL) || |
1907 | (sstate.envelope.from != NULL && localenv.from == NULL) || |
1978 | (sstate.envelope.from != NULL && localenv.from == NULL) || |
1908 | (sstate.envelope.subject != NULL && localenv.subject == NULL) || |
1979 | (sstate.envelope.subject != NULL && localenv.subject == NULL) || |
1909 | (sstate.envelope.rcpt != NULL && localenv.rcpt == NULL) || |
1980 | (sstate.envelope.rcpt != NULL && localenv.rcpt == NULL) || |
1910 | (sstate.envelope.date != NULL && localenv.date == NULL)) { |
1981 | (sstate.envelope.date != NULL && localenv.date == NULL)) { |
1911 | |
1982 | |
1912 | while (mssdepth) { |
1983 | while (mssdepth) { |
1913 | mssdepth--; |
1984 | mssdepth--; |
1914 | UUkillheaders (&(multistack[mssdepth].envelope)); |
1985 | UUkillheaders (&(multistack[mssdepth].envelope)); |
1915 | FP_free (multistack[mssdepth].source); |
1986 | _FP_free (multistack[mssdepth].source); |
1916 | } |
1987 | } |
1917 | sstate.isfolder = 0; |
1988 | sstate.isfolder = 0; |
1918 | sstate.ismime = 0; |
1989 | sstate.ismime = 0; |
1919 | |
1990 | |
1920 | UUkillheaders (&localenv); |
1991 | UUkillheaders (&localenv); |
1921 | *errcode = UURET_NOMEM; |
1992 | *errcode = UURET_NOMEM; |
1922 | FP_free (result); |
1993 | _FP_free (result); |
1923 | return NULL; |
1994 | return NULL; |
1924 | } |
1995 | } |
1925 | |
1996 | |
1926 | /* Scan subheader. But what if there is no subheader? */ |
1997 | /* Scan subheader. But what if there is no subheader? */ |
1927 | hcount = 0; |
1998 | hcount = 0; |
1928 | lcount = 0; |
1999 | lcount = 0; |
1929 | preheaders = prevpos; |
2000 | preheaders = prevpos; |
1930 | |
2001 | |
1931 | if (FP_fgets (line, 255, datei) == NULL) { |
2002 | if (_FP_fgets (line, 255, datei) == NULL) { |
1932 | sstate.isfolder = 0; |
2003 | sstate.isfolder = 0; |
1933 | sstate.ismime = 0; |
2004 | sstate.ismime = 0; |
1934 | while (mssdepth) { |
2005 | while (mssdepth) { |
1935 | mssdepth--; |
2006 | mssdepth--; |
1936 | UUkillheaders (&(multistack[mssdepth].envelope)); |
2007 | UUkillheaders (&(multistack[mssdepth].envelope)); |
1937 | FP_free (multistack[mssdepth].source); |
2008 | _FP_free (multistack[mssdepth].source); |
1938 | } |
2009 | } |
1939 | UUkillheaders (&localenv); |
2010 | UUkillheaders (&localenv); |
1940 | FP_free (result); |
2011 | _FP_free (result); |
1941 | return NULL; |
2012 | return NULL; |
1942 | } |
2013 | } |
1943 | line[255] = '\0'; |
2014 | line[255] = '\0'; |
1944 | |
2015 | |
1945 | while (!feof (datei) && !IsLineEmpty (line)) { |
2016 | while (!feof (datei) && !IsLineEmpty (line)) { |
… | |
… | |
1958 | if (line[0] == '-' && line[1] == '-') |
2029 | if (line[0] == '-' && line[1] == '-') |
1959 | break; |
2030 | break; |
1960 | |
2031 | |
1961 | prevpos = ftell (datei); |
2032 | prevpos = ftell (datei); |
1962 | |
2033 | |
1963 | if (FP_fgets (line, 255, datei) == NULL) |
2034 | if (_FP_fgets (line, 255, datei) == NULL) |
1964 | break; |
2035 | break; |
1965 | line[255] = '\0'; |
2036 | line[255] = '\0'; |
1966 | lcount++; |
2037 | lcount++; |
1967 | } |
2038 | } |
1968 | if (line[0] == '-' && line[1] == '-') { |
2039 | if (line[0] == '-' && line[1] == '-') { |
… | |
… | |
1972 | * boundary, so that it gets handled below |
2043 | * boundary, so that it gets handled below |
1973 | */ |
2044 | */ |
1974 | fseek (datei, prevpos, SEEK_SET); |
2045 | fseek (datei, prevpos, SEEK_SET); |
1975 | } |
2046 | } |
1976 | |
2047 | |
1977 | if (FP_stristr (localenv.ctype, "multipart") != NULL) { |
2048 | if (_FP_stristr (localenv.ctype, "multipart") != NULL) { |
1978 | /* oh no, not again */ |
2049 | /* oh no, not again */ |
1979 | if (mssdepth >= MSMAXDEPTH) { |
2050 | if (mssdepth >= MSMAXDEPTH) { |
1980 | /* Argh, what an isane message. Treat as plain text */ |
2051 | /* Argh, what an isane message. Treat as plain text */ |
1981 | UUMessage (uuscan_id, __LINE__, UUMSG_WARNING, |
2052 | UUMessage (uuscan_id, __LINE__, UUMSG_WARNING, |
1982 | uustring (S_MIME_MULTI_DEPTH)); |
2053 | uustring (S_MIME_MULTI_DEPTH)); |
… | |
… | |
1988 | else { |
2059 | else { |
1989 | memcpy (&multistack[mssdepth], &sstate, sizeof (scanstate)); |
2060 | memcpy (&multistack[mssdepth], &sstate, sizeof (scanstate)); |
1990 | memcpy (&sstate.envelope, &localenv, sizeof (headers)); |
2061 | memcpy (&sstate.envelope, &localenv, sizeof (headers)); |
1991 | memset (&localenv, 0, sizeof (headers)); |
2062 | memset (&localenv, 0, sizeof (headers)); |
1992 | sstate.mimestate = MS_PREAMBLE; |
2063 | sstate.mimestate = MS_PREAMBLE; |
1993 | if ((sstate.source = FP_strdup (sstate.source)) == NULL) |
2064 | if ((sstate.source = _FP_strdup (sstate.source)) == NULL) |
1994 | *errcode = UURET_NOMEM; |
2065 | *errcode = UURET_NOMEM; |
1995 | |
2066 | |
1996 | if (*errcode == UURET_OK) |
2067 | if (*errcode == UURET_OK) |
1997 | *errcode = UURET_CONT; |
2068 | *errcode = UURET_CONT; |
1998 | |
2069 | |
1999 | mssdepth++; |
2070 | mssdepth++; |
2000 | /* need a restart */ |
2071 | /* need a restart */ |
2001 | FP_free (result); |
2072 | _FP_free (result); |
2002 | return NULL; |
2073 | return NULL; |
2003 | } |
2074 | } |
2004 | } |
2075 | } |
|
|
2076 | |
2005 | /* |
2077 | /* |
2006 | * So this subpart is either plain text or something else. Check |
2078 | * So this subpart is either plain text or something else. Check |
2007 | * the Content-Type and Content-Transfer-Encoding. If the latter |
2079 | * the Content-Type and Content-Transfer-Encoding. If the latter |
2008 | * is a defined value, we know what to do and just copy everything |
2080 | * is a defined value, we know what to do and just copy everything |
2009 | * up to the boundary. |
2081 | * up to the boundary. |
… | |
… | |
2012 | * message to our encoding detection. Otherwise, treat as plain |
2084 | * message to our encoding detection. Otherwise, treat as plain |
2013 | * text. |
2085 | * text. |
2014 | * This is done because users might `attach' a uuencoded file, which |
2086 | * This is done because users might `attach' a uuencoded file, which |
2015 | * would then be correctly typed as `text/plain'. |
2087 | * would then be correctly typed as `text/plain'. |
2016 | */ |
2088 | */ |
|
|
2089 | |
2017 | if (FP_stristr (localenv.ctenc, "base64") != NULL) |
2090 | if (_FP_stristr (localenv.ctenc, "base64") != NULL) |
2018 | result->uudet = B64ENCODED; |
2091 | result->uudet = B64ENCODED; |
2019 | else if (FP_stristr (localenv.ctenc, "x-uue") != NULL) |
2092 | else if (_FP_stristr (localenv.ctenc, "x-uue") != NULL) { |
2020 | result->uudet = UU_ENCODED; |
2093 | result->uudet = UU_ENCODED; |
|
|
2094 | result->begin = result->end = 1; |
|
|
2095 | } |
|
|
2096 | else if (_FP_stristr (localenv.ctenc, "x-yenc") != NULL) { |
|
|
2097 | result->uudet = YENC_ENCODED; |
|
|
2098 | result->begin = result->end = 1; |
|
|
2099 | } |
2021 | else if (FP_stristr (localenv.ctenc, "quoted-printable") != NULL) |
2100 | else if (_FP_stristr (localenv.ctenc, "quoted-printable") != NULL) |
2022 | result->uudet = QP_ENCODED; |
2101 | result->uudet = QP_ENCODED; |
2023 | else if (FP_stristr (localenv.ctenc, "7bit") != NULL || |
2102 | else if (_FP_stristr (localenv.ctenc, "7bit") != NULL || |
2024 | FP_stristr (localenv.ctenc, "8bit") != NULL) |
2103 | _FP_stristr (localenv.ctenc, "8bit") != NULL) |
2025 | result->uudet = PT_ENCODED; |
2104 | result->uudet = PT_ENCODED; |
2026 | else if (FP_stristr (localenv.ctype, "multipart") != NULL || |
2105 | else if (_FP_stristr (localenv.ctype, "multipart") != NULL || |
2027 | FP_stristr (localenv.ctype, "message") != NULL) |
2106 | _FP_stristr (localenv.ctype, "message") != NULL) |
2028 | result->uudet = PT_ENCODED; |
2107 | result->uudet = PT_ENCODED; |
2029 | |
2108 | |
2030 | /* |
2109 | /* |
2031 | * If we're switched to MIME-only mode, handle as text |
2110 | * If we're switched to MIME-only mode, handle as text |
2032 | */ |
2111 | */ |
… | |
… | |
2043 | prevpos = ftell (datei); |
2122 | prevpos = ftell (datei); |
2044 | blen = strlen (sstate.envelope.boundary); |
2123 | blen = strlen (sstate.envelope.boundary); |
2045 | lcount = 0; |
2124 | lcount = 0; |
2046 | |
2125 | |
2047 | while (!feof (datei)) { |
2126 | while (!feof (datei)) { |
2048 | if (FP_fgets (line, 255, datei) == NULL) { |
2127 | if (_FP_fgets (line, 255, datei) == NULL) { |
2049 | line[0] = '\0'; |
2128 | line[0] = '\0'; |
2050 | break; |
2129 | break; |
2051 | } |
2130 | } |
2052 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
2131 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
2053 | line[255] = '\0'; |
2132 | line[255] = '\0'; |
… | |
… | |
2062 | * This check here doesn't cover folded header lines, but we don't |
2141 | * This check here doesn't cover folded header lines, but we don't |
2063 | * want to slow down scanning too much. We just check for |
2142 | * want to slow down scanning too much. We just check for |
2064 | * Content-Type: multipart/... boundary="same-boundary" |
2143 | * Content-Type: multipart/... boundary="same-boundary" |
2065 | */ |
2144 | */ |
2066 | if (line[0] == 'C' && line[1] == 'o' && |
2145 | if (line[0] == 'C' && line[1] == 'o' && |
2067 | FP_strnicmp (line, "Content-Type:", 13) == 0) { |
2146 | _FP_strnicmp (line, "Content-Type:", 13) == 0) { |
2068 | ptr1 = ScanHeaderLine (datei, line); |
2147 | ptr1 = ScanHeaderLine (datei, line); |
2069 | ptr2 = (ptr1)?FP_stristr(ptr1,"boundary"):NULL; |
2148 | ptr2 = (ptr1)?_FP_stristr(ptr1,"boundary"):NULL; |
2070 | ptr1 = (ptr2)?ParseValue(ptr2):NULL; |
2149 | ptr1 = (ptr2)?ParseValue(ptr2):NULL; |
2071 | if (ptr1 && strcmp (ptr1, sstate.envelope.boundary) == 0) |
2150 | if (ptr1 && strcmp (ptr1, sstate.envelope.boundary) == 0) |
2072 | break; |
2151 | break; |
2073 | for (res=0; ptr1 && res<mssdepth; res++) |
2152 | for (res=0; ptr1 && res<mssdepth; res++) |
2074 | if (strcmp (ptr1, multistack[res].envelope.boundary) == 0) |
2153 | if (strcmp (ptr1, multistack[res].envelope.boundary) == 0) |
… | |
… | |
2093 | uustring (S_MIME_B_NOT_FOUND)); |
2172 | uustring (S_MIME_B_NOT_FOUND)); |
2094 | |
2173 | |
2095 | while (mssdepth) { |
2174 | while (mssdepth) { |
2096 | mssdepth--; |
2175 | mssdepth--; |
2097 | UUkillheaders (&(multistack[mssdepth].envelope)); |
2176 | UUkillheaders (&(multistack[mssdepth].envelope)); |
2098 | FP_free (multistack[mssdepth].source); |
2177 | _FP_free (multistack[mssdepth].source); |
2099 | } |
2178 | } |
2100 | /* |
2179 | /* |
2101 | * Don't retry if uu_fast_scanning |
2180 | * Don't retry if uu_fast_scanning |
2102 | */ |
2181 | */ |
2103 | |
2182 | |
2104 | if (uu_fast_scanning) { |
2183 | if (uu_fast_scanning) { |
2105 | UUkillheaders (&localenv); |
2184 | UUkillheaders (&localenv); |
2106 | sstate.isfolder = 0; |
2185 | sstate.isfolder = 0; |
2107 | sstate.ismime = 0; |
2186 | sstate.ismime = 0; |
2108 | sstate.mimestate = MS_BODY; |
2187 | sstate.mimestate = MS_BODY; |
2109 | FP_free (result); |
2188 | _FP_free (result); |
2110 | return NULL; |
2189 | return NULL; |
2111 | } |
2190 | } |
2112 | |
2191 | |
2113 | /* |
2192 | /* |
2114 | * Retry, but listening to headers this time |
2193 | * Retry, but listening to headers this time |
… | |
… | |
2148 | } |
2227 | } |
2149 | /* produce result if uu_handletext is set */ |
2228 | /* produce result if uu_handletext is set */ |
2150 | /* or if the file is explicitely named */ |
2229 | /* or if the file is explicitely named */ |
2151 | if (result->uudet == B64ENCODED || lcount) { |
2230 | if (result->uudet == B64ENCODED || lcount) { |
2152 | if (localenv.fname) { |
2231 | if (localenv.fname) { |
2153 | FP_free (result->filename); |
2232 | _FP_free (result->filename); |
2154 | if ((result->filename = FP_strdup (localenv.fname)) == NULL) |
2233 | if ((result->filename = _FP_strdup (localenv.fname)) == NULL) |
2155 | *errcode = UURET_NOMEM; |
2234 | *errcode = UURET_NOMEM; |
2156 | } |
2235 | } |
2157 | else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) && |
2236 | else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) && |
2158 | result->filename == NULL && uu_handletext) { |
2237 | result->filename == NULL && uu_handletext) { |
2159 | sprintf (line, "%04d.txt", ++mimseqno); |
2238 | sprintf (line, "%04d.txt", ++mimseqno); |
2160 | if ((result->filename = FP_strdup (line)) == NULL) |
2239 | if ((result->filename = _FP_strdup (line)) == NULL) |
2161 | *errcode = UURET_NOMEM; |
2240 | *errcode = UURET_NOMEM; |
2162 | } |
2241 | } |
2163 | result->subject = FP_strdup (localenv.subject); |
2242 | result->subject = _FP_strdup (localenv.subject); |
2164 | result->origin = FP_strdup (localenv.from); |
2243 | result->origin = _FP_strdup (localenv.from); |
2165 | result->mimeid = FP_strdup (localenv.mimeid); |
2244 | result->mimeid = _FP_strdup (localenv.mimeid); |
2166 | result->mimetype = FP_strdup (localenv.ctype); |
2245 | result->mimetype = _FP_strdup (localenv.ctype); |
2167 | result->mode = 0644; |
2246 | result->mode = 0644; |
2168 | result->sfname = FP_strdup (fname); |
2247 | result->sfname = _FP_strdup (fname); |
2169 | result->flags = FL_SINGLE | FL_PROPER; |
2248 | result->flags = FL_SINGLE | FL_PROPER; |
2170 | result->partno = 1; |
2249 | result->partno = 1; |
2171 | /* result->uudet determined above */ |
2250 | /* result->uudet determined above */ |
2172 | /* result->startpos set from above */ |
2251 | /* result->startpos set from above */ |
2173 | result->length = prevpos - result->startpos; |
2252 | result->length = prevpos - result->startpos; |
… | |
… | |
2177 | *errcode = UURET_NOMEM; |
2256 | *errcode = UURET_NOMEM; |
2178 | } |
2257 | } |
2179 | } |
2258 | } |
2180 | else { |
2259 | else { |
2181 | /* don't produce a result */ |
2260 | /* don't produce a result */ |
2182 | FP_free (result); |
2261 | _FP_free (result); |
2183 | result = NULL; |
2262 | result = NULL; |
2184 | } |
2263 | } |
2185 | if (*errcode == UURET_OK) |
2264 | if (*errcode == UURET_OK) |
2186 | *errcode = UURET_CONT; |
2265 | *errcode = UURET_CONT; |
2187 | /* |
2266 | /* |
… | |
… | |
2212 | */ |
2291 | */ |
2213 | blen = strlen (sstate.envelope.boundary); |
2292 | blen = strlen (sstate.envelope.boundary); |
2214 | prevpos = ftell (datei); |
2293 | prevpos = ftell (datei); |
2215 | |
2294 | |
2216 | while (!feof (datei)) { |
2295 | while (!feof (datei)) { |
2217 | if (FP_fgets (line, 255, datei) == NULL) { |
2296 | if (_FP_fgets (line, 255, datei) == NULL) { |
2218 | line[0] = '\0'; |
2297 | line[0] = '\0'; |
2219 | break; |
2298 | break; |
2220 | } |
2299 | } |
2221 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
2300 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
2222 | line[255] = '\0'; |
2301 | line[255] = '\0'; |
2223 | if (line[0] == '-' && line[1] == '-' && |
2302 | if (line[0] == '-' && line[1] == '-' && |
2224 | strncmp (line+2, sstate.envelope.boundary, blen) == 0) |
2303 | strncmp (line+2, sstate.envelope.boundary, blen) == 0) |
2225 | break; |
2304 | break; |
2226 | if (line[0] == 'C' && line[1] == 'o' && |
2305 | if (line[0] == 'C' && line[1] == 'o' && |
2227 | FP_strnicmp (line, "Content-Type:", 13) == 0) { |
2306 | _FP_strnicmp (line, "Content-Type:", 13) == 0) { |
2228 | ptr1 = ScanHeaderLine (datei, line); |
2307 | ptr1 = ScanHeaderLine (datei, line); |
2229 | ptr2 = (ptr1)?FP_stristr(ptr1,"boundary"):NULL; |
2308 | ptr2 = (ptr1)?_FP_stristr(ptr1,"boundary"):NULL; |
2230 | ptr1 = (ptr2)?ParseValue(ptr2):NULL; |
2309 | ptr1 = (ptr2)?ParseValue(ptr2):NULL; |
2231 | if (ptr1 && strcmp (ptr1, sstate.envelope.boundary) == 0) |
2310 | if (ptr1 && strcmp (ptr1, sstate.envelope.boundary) == 0) |
2232 | break; |
2311 | break; |
2233 | } |
2312 | } |
2234 | prevpos = ftell (datei); |
2313 | prevpos = ftell (datei); |
… | |
… | |
2249 | uustring (S_MIME_B_NOT_FOUND)); |
2328 | uustring (S_MIME_B_NOT_FOUND)); |
2250 | |
2329 | |
2251 | while (mssdepth) { |
2330 | while (mssdepth) { |
2252 | mssdepth--; |
2331 | mssdepth--; |
2253 | UUkillheaders (&(multistack[mssdepth].envelope)); |
2332 | UUkillheaders (&(multistack[mssdepth].envelope)); |
2254 | FP_free (multistack[mssdepth].source); |
2333 | _FP_free (multistack[mssdepth].source); |
2255 | } |
2334 | } |
2256 | |
2335 | |
2257 | if (uu_fast_scanning) { |
2336 | if (uu_fast_scanning) { |
2258 | UUkillheaders (&localenv); |
2337 | UUkillheaders (&localenv); |
2259 | sstate.isfolder = 0; |
2338 | sstate.isfolder = 0; |
2260 | sstate.ismime = 0; |
2339 | sstate.ismime = 0; |
2261 | sstate.mimestate = MS_BODY; |
2340 | sstate.mimestate = MS_BODY; |
2262 | FP_free (result); |
2341 | _FP_free (result); |
2263 | return NULL; |
2342 | return NULL; |
2264 | } |
2343 | } |
2265 | |
2344 | |
2266 | /* |
2345 | /* |
2267 | * Retry, listening to headers this time |
2346 | * Retry, listening to headers this time |
… | |
… | |
2304 | * If this file has been nicely MIME so far, then be very suspicious |
2383 | * If this file has been nicely MIME so far, then be very suspicious |
2305 | * if ScanData reports anything else. So do a double check, and if |
2384 | * if ScanData reports anything else. So do a double check, and if |
2306 | * it doesn't hold up, handle as plain text instead. |
2385 | * it doesn't hold up, handle as plain text instead. |
2307 | */ |
2386 | */ |
2308 | |
2387 | |
2309 | if (sstate.ismime && sstate.mimestate == MS_SUBPART && |
|
|
2310 | strcmp (localenv.mimevers, "1.0") == 0 && |
2388 | if (strcmp (localenv.mimevers, "1.0") == 0 && |
2311 | FP_stristr (localenv.ctype, "text") != NULL && |
2389 | _FP_stristr (localenv.ctype, "text") != NULL && |
|
|
2390 | sstate.ismime && sstate.mimestate == MS_SUBPART && |
2312 | !uu_desperate) { |
2391 | !uu_desperate) { |
2313 | if (result->uudet == UU_ENCODED && !(result->begin || result->end)) { |
2392 | if (result->uudet == UU_ENCODED && !(result->begin || result->end)) { |
2314 | result->uudet = 0; |
2393 | result->uudet = 0; |
2315 | } |
2394 | } |
2316 | } |
2395 | } |
… | |
… | |
2322 | if (result->uudet == 0) { |
2401 | if (result->uudet == 0) { |
2323 | result->uudet = PT_ENCODED; /* plain text */ |
2402 | result->uudet = PT_ENCODED; /* plain text */ |
2324 | } |
2403 | } |
2325 | |
2404 | |
2326 | if (localenv.fname) { |
2405 | if (localenv.fname) { |
2327 | FP_free (result->filename); |
2406 | _FP_free (result->filename); |
2328 | if ((result->filename = FP_strdup (localenv.fname)) == NULL) |
2407 | if ((result->filename = _FP_strdup (localenv.fname)) == NULL) |
2329 | *errcode = UURET_NOMEM; |
2408 | *errcode = UURET_NOMEM; |
2330 | } |
2409 | } |
2331 | else if ((result->uudet==QP_ENCODED || result->uudet==PT_ENCODED) && |
2410 | else if ((result->uudet==QP_ENCODED || result->uudet==PT_ENCODED) && |
2332 | result->filename==NULL && uu_handletext) { |
2411 | result->filename==NULL && uu_handletext) { |
2333 | sprintf (line, "%04d.txt", ++mimseqno); |
2412 | sprintf (line, "%04d.txt", ++mimseqno); |
2334 | if ((result->filename = FP_strdup (line)) == NULL) |
2413 | if ((result->filename = _FP_strdup (line)) == NULL) |
2335 | *errcode = UURET_NOMEM; |
2414 | *errcode = UURET_NOMEM; |
2336 | } |
2415 | } |
2337 | else { |
2416 | else { |
2338 | /* assign a filename lateron */ |
2417 | /* assign a filename lateron */ |
2339 | } |
2418 | } |
2340 | if (result->mimetype) FP_free (result->mimetype); |
2419 | if (result->mimetype) _FP_free (result->mimetype); |
2341 | if (result->uudet) { |
2420 | if (result->uudet) { |
2342 | if (FP_stristr (localenv.ctype, "text") != NULL && |
2421 | if (_FP_stristr (localenv.ctype, "text") != NULL && |
2343 | result->uudet != QP_ENCODED && result->uudet != PT_ENCODED) |
2422 | result->uudet != QP_ENCODED && result->uudet != PT_ENCODED) |
2344 | result->mimetype = NULL; /* better don't set it */ |
2423 | result->mimetype = NULL; /* better don't set it */ |
2345 | else |
2424 | else |
2346 | result->mimetype = FP_strdup (localenv.ctype); |
2425 | result->mimetype = _FP_strdup (localenv.ctype); |
2347 | } |
2426 | } |
2348 | if (result->origin) FP_free (result->origin); |
2427 | if (result->origin) _FP_free (result->origin); |
2349 | result->origin = FP_strdup (localenv.from); |
2428 | result->origin = _FP_strdup (localenv.from); |
2350 | |
2429 | |
2351 | if (result->subject) FP_free (result->subject); |
2430 | if (result->subject) _FP_free (result->subject); |
2352 | result->subject = FP_strdup (localenv.subject); |
2431 | result->subject = _FP_strdup (localenv.subject); |
2353 | |
2432 | |
2354 | if (result->sfname == NULL) |
2433 | if (result->sfname == NULL) |
2355 | if ((result->sfname = FP_strdup (fname)) == NULL) |
2434 | if ((result->sfname = _FP_strdup (fname)) == NULL) |
2356 | *errcode = UURET_NOMEM; |
2435 | *errcode = UURET_NOMEM; |
2357 | |
2436 | |
2358 | result->length = prevpos - result->startpos; |
2437 | result->length = prevpos - result->startpos; |
2359 | result->flags = FL_SINGLE | FL_PROPER; |
2438 | result->flags = FL_SINGLE | FL_PROPER; |
2360 | result->partno = 1; |
2439 | result->partno = 1; |
… | |
… | |
2382 | * long to figure this out. But this might still be a MIME message |
2461 | * long to figure this out. But this might still be a MIME message |
2383 | * body. And if it's a message/partial, we need more special handling |
2462 | * body. And if it's a message/partial, we need more special handling |
2384 | */ |
2463 | */ |
2385 | |
2464 | |
2386 | if (sstate.isfolder && sstate.ismime && sstate.mimestate == MS_BODY && |
2465 | if (sstate.isfolder && sstate.ismime && sstate.mimestate == MS_BODY && |
2387 | FP_stristr (sstate.envelope.ctype, "message") != NULL && |
2466 | _FP_stristr (sstate.envelope.ctype, "message") != NULL && |
2388 | FP_stristr (sstate.envelope.ctype, "partial") != NULL) { |
2467 | _FP_stristr (sstate.envelope.ctype, "partial") != NULL) { |
2389 | |
2468 | |
2390 | result->startpos = ftell (datei); |
2469 | result->startpos = ftell (datei); |
2391 | |
2470 | |
2392 | if (sstate.envelope.partno == 1) { |
2471 | if (sstate.envelope.partno == 1) { |
2393 | /* read local envelope */ |
2472 | /* read local envelope */ |
… | |
… | |
2395 | memset (&localenv, 0, sizeof (headers)); |
2474 | memset (&localenv, 0, sizeof (headers)); |
2396 | |
2475 | |
2397 | /* skip over blank lines first */ |
2476 | /* skip over blank lines first */ |
2398 | prevpos = ftell (datei); |
2477 | prevpos = ftell (datei); |
2399 | while (!feof (datei)) { |
2478 | while (!feof (datei)) { |
2400 | if (FP_fgets (line, 255, datei) == NULL) |
2479 | if (_FP_fgets (line, 255, datei) == NULL) |
2401 | break; |
2480 | break; |
2402 | line[255] = '\0'; |
2481 | line[255] = '\0'; |
2403 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
2482 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
2404 | if (!IsLineEmpty (line)) |
2483 | if (!IsLineEmpty (line)) |
2405 | break; |
2484 | break; |
… | |
… | |
2420 | } |
2499 | } |
2421 | ptr1 = ScanHeaderLine (datei, line); |
2500 | ptr1 = ScanHeaderLine (datei, line); |
2422 | if (ParseHeader (&localenv, ptr1) == NULL) |
2501 | if (ParseHeader (&localenv, ptr1) == NULL) |
2423 | *errcode = UURET_NOMEM; |
2502 | *errcode = UURET_NOMEM; |
2424 | |
2503 | |
2425 | if (FP_fgets (line, 255, datei) == NULL) |
2504 | if (_FP_fgets (line, 255, datei) == NULL) |
2426 | break; |
2505 | break; |
2427 | line[255] = '\0'; |
2506 | line[255] = '\0'; |
2428 | lcount++; |
2507 | lcount++; |
2429 | } |
2508 | } |
2430 | prevpos = ftell (datei); |
2509 | prevpos = ftell (datei); |
2431 | /* |
2510 | /* |
2432 | * Examine local header. We're mostly interested in the Content-Type |
2511 | * Examine local header. We're mostly interested in the Content-Type |
2433 | * and the Content-Transfer-Encoding. |
2512 | * and the Content-Transfer-Encoding. |
2434 | */ |
2513 | */ |
2435 | if (FP_stristr (localenv.ctype, "multipart") != NULL) { |
2514 | if (_FP_stristr (localenv.ctype, "multipart") != NULL) { |
2436 | UUMessage (uuscan_id, __LINE__, UUMSG_WARNING, |
2515 | UUMessage (uuscan_id, __LINE__, UUMSG_WARNING, |
2437 | uustring (S_MIME_PART_MULTI)); |
2516 | uustring (S_MIME_PART_MULTI)); |
2438 | } |
2517 | } |
2439 | if (localenv.subject) |
2518 | if (localenv.subject) |
2440 | result->subject = FP_strdup (localenv.subject); |
2519 | result->subject = _FP_strdup (localenv.subject); |
2441 | else |
2520 | else |
2442 | result->subject = FP_strdup (sstate.envelope.subject); |
2521 | result->subject = _FP_strdup (sstate.envelope.subject); |
2443 | |
2522 | |
2444 | if (localenv.from) |
2523 | if (localenv.from) |
2445 | result->origin = FP_strdup (localenv.from); |
2524 | result->origin = _FP_strdup (localenv.from); |
2446 | else |
2525 | else |
2447 | result->origin = FP_strdup (sstate.envelope.from); |
2526 | result->origin = _FP_strdup (sstate.envelope.from); |
2448 | |
2527 | |
2449 | if (localenv.ctype) |
2528 | if (localenv.ctype) |
2450 | result->mimetype = FP_strdup (localenv.ctype); |
2529 | result->mimetype = _FP_strdup (localenv.ctype); |
2451 | else |
2530 | else |
2452 | result->mimetype = FP_strdup ("text/plain"); |
2531 | result->mimetype = _FP_strdup ("text/plain"); |
2453 | |
2532 | |
2454 | if (FP_stristr (localenv.ctenc, "quoted-printable") != NULL) |
2533 | if (_FP_stristr (localenv.ctenc, "quoted-printable") != NULL) |
2455 | result->uudet = QP_ENCODED; |
2534 | result->uudet = QP_ENCODED; |
2456 | else if (FP_stristr (localenv.ctenc, "base64") != NULL) |
2535 | else if (_FP_stristr (localenv.ctenc, "base64") != NULL) |
2457 | result->uudet = B64ENCODED; |
2536 | result->uudet = B64ENCODED; |
2458 | else if (FP_stristr (localenv.ctenc, "x-uue") != NULL) |
2537 | else if (_FP_stristr (localenv.ctenc, "x-uue") != NULL) { |
2459 | result->uudet = UU_ENCODED; |
2538 | result->uudet = UU_ENCODED; |
|
|
2539 | result->begin = result->end = 1; |
|
|
2540 | } |
|
|
2541 | else if (_FP_stristr (localenv.ctenc, "x-yenc") != NULL) { |
|
|
2542 | result->uudet = YENC_ENCODED; |
|
|
2543 | result->begin = result->end = 1; |
|
|
2544 | } |
2460 | else if (FP_stristr (localenv.ctenc, "7bit") != NULL || |
2545 | else if (_FP_stristr (localenv.ctenc, "7bit") != NULL || |
2461 | FP_stristr (localenv.ctenc, "8bit") != NULL) |
2546 | _FP_stristr (localenv.ctenc, "8bit") != NULL) |
2462 | result->uudet = PT_ENCODED; |
2547 | result->uudet = PT_ENCODED; |
2463 | else if (FP_stristr (localenv.ctype, "multipart") != NULL || |
2548 | else if (_FP_stristr (localenv.ctype, "multipart") != NULL || |
2464 | FP_stristr (localenv.ctype, "message") != NULL) |
2549 | _FP_stristr (localenv.ctype, "message") != NULL) |
2465 | result->uudet = PT_ENCODED; |
2550 | result->uudet = PT_ENCODED; |
2466 | |
2551 | |
2467 | /* |
2552 | /* |
2468 | * If we're switched to MIME-only mode, handle as text |
2553 | * If we're switched to MIME-only mode, handle as text |
2469 | */ |
2554 | */ |
… | |
… | |
2496 | } |
2581 | } |
2497 | else if (result->uudet != 0) { |
2582 | else if (result->uudet != 0) { |
2498 | hcount = lcount = 0; |
2583 | hcount = lcount = 0; |
2499 | prevpos = ftell (datei); |
2584 | prevpos = ftell (datei); |
2500 | |
2585 | |
2501 | if (FP_stristr (localenv.ctype, "message") != NULL && |
2586 | if (_FP_stristr (localenv.ctype, "message") != NULL && |
2502 | FP_stristr (localenv.ctype, "rfc822") != NULL) { |
2587 | _FP_stristr (localenv.ctype, "rfc822") != NULL) { |
2503 | /* |
2588 | /* |
2504 | * skip over empty lines and local header |
2589 | * skip over empty lines and local header |
2505 | */ |
2590 | */ |
2506 | preheaders = ftell (datei); |
2591 | preheaders = ftell (datei); |
2507 | while (!feof (datei)) { |
2592 | while (!feof (datei)) { |
2508 | if (FP_fgets (line, 255, datei) == NULL) |
2593 | if (_FP_fgets (line, 255, datei) == NULL) |
2509 | break; |
2594 | break; |
2510 | line[255] = '\0'; |
2595 | line[255] = '\0'; |
2511 | if (!IsLineEmpty (line)) { |
2596 | if (!IsLineEmpty (line)) { |
2512 | break; |
2597 | break; |
2513 | } |
2598 | } |
… | |
… | |
2518 | hcount++; |
2603 | hcount++; |
2519 | lcount++; |
2604 | lcount++; |
2520 | if (lcount > WAITHEADER && hcount < hlcount.afternl) |
2605 | if (lcount > WAITHEADER && hcount < hlcount.afternl) |
2521 | break; |
2606 | break; |
2522 | |
2607 | |
2523 | if (FP_fgets (line, 255, datei) == NULL) |
2608 | if (_FP_fgets (line, 255, datei) == NULL) |
2524 | break; |
2609 | break; |
2525 | line[255] = '\0'; |
2610 | line[255] = '\0'; |
2526 | } |
2611 | } |
2527 | if (hcount < hlcount.afternl) |
2612 | if (hcount < hlcount.afternl) |
2528 | fseek (datei, preheaders, SEEK_SET); |
2613 | fseek (datei, preheaders, SEEK_SET); |
… | |
… | |
2532 | /* |
2617 | /* |
2533 | * look for next header |
2618 | * look for next header |
2534 | */ |
2619 | */ |
2535 | |
2620 | |
2536 | while (!feof (datei)) { |
2621 | while (!feof (datei)) { |
2537 | if (FP_fgets (line, 255, datei) == NULL) |
2622 | if (_FP_fgets (line, 255, datei) == NULL) |
2538 | break; |
2623 | break; |
2539 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
2624 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
2540 | if (ferror (datei)) |
2625 | if (ferror (datei)) |
2541 | break; |
2626 | break; |
2542 | line[255] = '\0'; |
2627 | line[255] = '\0'; |
… | |
… | |
2590 | } |
2675 | } |
2591 | /* |
2676 | /* |
2592 | * produce result |
2677 | * produce result |
2593 | */ |
2678 | */ |
2594 | if (localenv.fname) { |
2679 | if (localenv.fname) { |
2595 | FP_free (result->filename); |
2680 | _FP_free (result->filename); |
2596 | if ((result->filename = FP_strdup (localenv.fname)) == NULL) |
2681 | if ((result->filename = _FP_strdup (localenv.fname)) == NULL) |
2597 | *errcode = UURET_NOMEM; |
2682 | *errcode = UURET_NOMEM; |
2598 | } |
2683 | } |
2599 | else if (sstate.envelope.fname) { |
2684 | else if (sstate.envelope.fname) { |
2600 | FP_free (result->filename); |
2685 | _FP_free (result->filename); |
2601 | if ((result->filename = FP_strdup (sstate.envelope.fname)) == NULL) |
2686 | if ((result->filename = _FP_strdup (sstate.envelope.fname)) == NULL) |
2602 | *errcode = UURET_NOMEM; |
2687 | *errcode = UURET_NOMEM; |
2603 | } |
2688 | } |
2604 | else if ((result->uudet==QP_ENCODED || result->uudet==PT_ENCODED) && |
2689 | else if ((result->uudet==QP_ENCODED || result->uudet==PT_ENCODED) && |
2605 | result->filename == NULL) { |
2690 | result->filename == NULL) { |
2606 | sprintf (line, "%04d.txt", ++mimseqno); |
2691 | sprintf (line, "%04d.txt", ++mimseqno); |
2607 | if ((result->filename = FP_strdup (line)) == NULL) |
2692 | if ((result->filename = _FP_strdup (line)) == NULL) |
2608 | *errcode = UURET_NOMEM; |
2693 | *errcode = UURET_NOMEM; |
2609 | } |
2694 | } |
2610 | else { |
2695 | else { |
2611 | /* assign a filename lateron */ |
2696 | /* assign a filename lateron */ |
2612 | } |
2697 | } |
2613 | if (result->subject == NULL) { |
2698 | if (result->subject == NULL) { |
2614 | if (sstate.envelope.subject) |
2699 | if (sstate.envelope.subject) |
2615 | result->subject = FP_strdup (sstate.envelope.subject); |
2700 | result->subject = _FP_strdup (sstate.envelope.subject); |
2616 | } |
2701 | } |
2617 | result->partno = sstate.envelope.partno; |
2702 | result->partno = sstate.envelope.partno; |
2618 | result->maxpno = sstate.envelope.numparts; |
2703 | result->maxpno = sstate.envelope.numparts; |
2619 | result->flags = FL_PARTIAL | |
2704 | result->flags = FL_PARTIAL | |
2620 | ((res==1 || uu_fast_scanning) ? FL_PROPER : 0) | |
2705 | ((res==1 || uu_fast_scanning) ? FL_PROPER : 0) | |
2621 | ((uu_fast_scanning) ? FL_TOEND : 0); |
2706 | ((uu_fast_scanning) ? FL_TOEND : 0); |
2622 | result->mimeid = FP_strdup (sstate.envelope.mimeid); |
2707 | result->mimeid = _FP_strdup (sstate.envelope.mimeid); |
|
|
2708 | if (result->partno == 1) |
|
|
2709 | result->begin = 1; |
2623 | |
2710 | |
2624 | if (uu_fast_scanning) |
2711 | if (uu_fast_scanning) |
2625 | result->length = progress.fsize - result->startpos; |
2712 | result->length = progress.fsize - result->startpos; |
2626 | else |
2713 | else |
2627 | result->length = prevpos - result->startpos; |
2714 | result->length = prevpos - result->startpos; |
2628 | |
2715 | |
2629 | if (result->sfname == NULL) |
2716 | if (result->sfname == NULL) |
2630 | result->sfname = FP_strdup (fname); |
2717 | result->sfname = _FP_strdup (fname); |
2631 | |
2718 | |
2632 | if (result->mode == 0) |
2719 | if (result->mode == 0) |
2633 | result->mode = 0644; |
2720 | result->mode = 0644; |
2634 | |
2721 | |
2635 | /* |
2722 | /* |
… | |
… | |
2666 | * text/plain or a proper Content-Transfer-Encoding. |
2753 | * text/plain or a proper Content-Transfer-Encoding. |
2667 | * We also go in here if we have an assigned filename - this means |
2754 | * We also go in here if we have an assigned filename - this means |
2668 | * that we've had a Content-Disposition field, and we should probably |
2755 | * that we've had a Content-Disposition field, and we should probably |
2669 | * decode a plain-text segment with a filename. |
2756 | * decode a plain-text segment with a filename. |
2670 | */ |
2757 | */ |
|
|
2758 | |
2671 | if (sstate.isfolder && sstate.ismime && |
2759 | if (sstate.isfolder && sstate.ismime && |
2672 | sstate.mimestate == MS_BODY && |
2760 | sstate.mimestate == MS_BODY && |
2673 | (FP_stristr (sstate.envelope.ctenc, "quoted-printable") != NULL || |
2761 | (_FP_stristr (sstate.envelope.ctenc, "quoted-printable") != NULL || |
2674 | FP_stristr (sstate.envelope.ctenc, "base64") != NULL || |
2762 | _FP_stristr (sstate.envelope.ctenc, "base64") != NULL || |
2675 | FP_stristr (sstate.envelope.ctenc, "x-uue") != NULL || |
2763 | _FP_stristr (sstate.envelope.ctenc, "x-uue") != NULL || |
|
|
2764 | _FP_stristr (sstate.envelope.ctenc, "x-yenc") != NULL || |
2676 | FP_stristr (sstate.envelope.ctype, "message") != NULL || |
2765 | _FP_stristr (sstate.envelope.ctype, "message") != NULL || |
2677 | sstate.envelope.fname != NULL)) { |
2766 | sstate.envelope.fname != NULL)) { |
2678 | |
2767 | |
2679 | if (sstate.envelope.subject) |
2768 | if (sstate.envelope.subject) |
2680 | result->subject = FP_strdup (sstate.envelope.subject); |
2769 | result->subject = _FP_strdup (sstate.envelope.subject); |
2681 | if (sstate.envelope.from) |
2770 | if (sstate.envelope.from) |
2682 | result->origin = FP_strdup (sstate.envelope.from); |
2771 | result->origin = _FP_strdup (sstate.envelope.from); |
2683 | |
2772 | |
2684 | if (sstate.envelope.ctype) |
2773 | if (sstate.envelope.ctype) |
2685 | result->mimetype = FP_strdup (sstate.envelope.ctype); |
2774 | result->mimetype = _FP_strdup (sstate.envelope.ctype); |
2686 | else |
2775 | else |
2687 | result->mimetype = FP_strdup ("text/plain"); |
2776 | result->mimetype = _FP_strdup ("text/plain"); |
2688 | |
2777 | |
2689 | if (FP_stristr (sstate.envelope.ctenc, "quoted-printable") != NULL) |
2778 | if (_FP_stristr (sstate.envelope.ctenc, "quoted-printable") != NULL) |
2690 | result->uudet = QP_ENCODED; |
2779 | result->uudet = QP_ENCODED; |
2691 | else if (FP_stristr (sstate.envelope.ctenc, "base64") != NULL) |
2780 | else if (_FP_stristr (sstate.envelope.ctenc, "base64") != NULL) |
2692 | result->uudet = B64ENCODED; |
2781 | result->uudet = B64ENCODED; |
2693 | else if (FP_stristr (sstate.envelope.ctenc, "x-uue") != NULL) |
2782 | else if (_FP_stristr (sstate.envelope.ctenc, "x-uue") != NULL) { |
2694 | result->uudet = UU_ENCODED; |
2783 | result->uudet = UU_ENCODED; |
|
|
2784 | result->begin = result->end = 1; |
|
|
2785 | } |
|
|
2786 | else if (_FP_stristr (sstate.envelope.ctenc, "x-yenc") != NULL) { |
|
|
2787 | result->uudet = YENC_ENCODED; |
|
|
2788 | } |
2695 | else if (FP_stristr (sstate.envelope.ctenc, "7bit") != NULL || |
2789 | else if (_FP_stristr (sstate.envelope.ctenc, "7bit") != NULL || |
2696 | FP_stristr (sstate.envelope.ctenc, "8bit") != NULL) |
2790 | _FP_stristr (sstate.envelope.ctenc, "8bit") != NULL) |
2697 | result->uudet = PT_ENCODED; |
2791 | result->uudet = PT_ENCODED; |
2698 | else if (FP_stristr (sstate.envelope.ctype, "multipart") != NULL || |
2792 | else if (_FP_stristr (sstate.envelope.ctype, "multipart") != NULL || |
2699 | FP_stristr (sstate.envelope.ctype, "message") != NULL || |
2793 | _FP_stristr (sstate.envelope.ctype, "message") != NULL || |
2700 | sstate.envelope.fname != NULL) |
2794 | sstate.envelope.fname != NULL) |
2701 | result->uudet = PT_ENCODED; |
2795 | result->uudet = PT_ENCODED; |
2702 | |
2796 | |
2703 | /* |
2797 | /* |
2704 | * If we're switched to MIME-only mode, handle as text |
2798 | * If we're switched to MIME-only mode, handle as text |
… | |
… | |
2707 | if (uu_more_mime >= 2 && !result->uudet) { |
2801 | if (uu_more_mime >= 2 && !result->uudet) { |
2708 | result->uudet = PT_ENCODED; |
2802 | result->uudet = PT_ENCODED; |
2709 | } |
2803 | } |
2710 | |
2804 | |
2711 | result->startpos = prevpos = ftell (datei); |
2805 | result->startpos = prevpos = ftell (datei); |
2712 | |
2806 | |
2713 | /* |
2807 | /* |
2714 | * If this is Quoted-Printable or Plain Text, just try looking |
2808 | * If this is Quoted-Printable or Plain Text, just try looking |
2715 | * for the next message header. If uu_fast_scanning, we know |
2809 | * for the next message header. If uu_fast_scanning, we know |
2716 | * there won't be more headers. |
2810 | * there won't be more headers. |
2717 | * If it is a "trivial" (non-embedded) message/rfc822, skip over |
2811 | * If it is a "trivial" (non-embedded) message/rfc822, skip over |
… | |
… | |
2723 | } |
2817 | } |
2724 | else if (result->uudet != 0) { |
2818 | else if (result->uudet != 0) { |
2725 | hcount = lcount = 0; |
2819 | hcount = lcount = 0; |
2726 | prevpos = ftell (datei); |
2820 | prevpos = ftell (datei); |
2727 | |
2821 | |
2728 | if (FP_stristr (sstate.envelope.ctype, "message") != NULL && |
2822 | if (_FP_stristr (sstate.envelope.ctype, "message") != NULL && |
2729 | FP_stristr (sstate.envelope.ctype, "rfc822") != NULL) { |
2823 | _FP_stristr (sstate.envelope.ctype, "rfc822") != NULL) { |
2730 | /* |
2824 | /* |
2731 | * skip over empty lines and local header |
2825 | * skip over empty lines and local header |
2732 | */ |
2826 | */ |
2733 | preheaders = ftell (datei); |
2827 | preheaders = ftell (datei); |
2734 | while (!feof (datei)) { |
2828 | while (!feof (datei)) { |
2735 | if (FP_fgets (line, 255, datei) == NULL) |
2829 | if (_FP_fgets (line, 255, datei) == NULL) |
2736 | break; |
2830 | break; |
2737 | line[255] = '\0'; |
2831 | line[255] = '\0'; |
2738 | if (!IsLineEmpty (line)) { |
2832 | if (!IsLineEmpty (line)) { |
2739 | break; |
2833 | break; |
2740 | } |
2834 | } |
… | |
… | |
2745 | hcount++; |
2839 | hcount++; |
2746 | lcount++; |
2840 | lcount++; |
2747 | if (lcount > WAITHEADER && hcount < hlcount.afternl) |
2841 | if (lcount > WAITHEADER && hcount < hlcount.afternl) |
2748 | break; |
2842 | break; |
2749 | |
2843 | |
2750 | if (FP_fgets (line, 255, datei) == NULL) |
2844 | if (_FP_fgets (line, 255, datei) == NULL) |
2751 | break; |
2845 | break; |
2752 | line[255] = '\0'; |
2846 | line[255] = '\0'; |
2753 | } |
2847 | } |
2754 | if (hcount < hlcount.afternl) |
2848 | if (hcount < hlcount.afternl) |
2755 | fseek (datei, preheaders, SEEK_SET); |
2849 | fseek (datei, preheaders, SEEK_SET); |
… | |
… | |
2759 | /* |
2853 | /* |
2760 | * look for next header |
2854 | * look for next header |
2761 | */ |
2855 | */ |
2762 | |
2856 | |
2763 | while (!feof (datei)) { |
2857 | while (!feof (datei)) { |
2764 | if (FP_fgets (line, 255, datei) == NULL) |
2858 | if (_FP_fgets (line, 255, datei) == NULL) |
2765 | break; |
2859 | break; |
2766 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
2860 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
2767 | if (ferror (datei)) |
2861 | if (ferror (datei)) |
2768 | break; |
2862 | break; |
2769 | line[255] = '\0'; |
2863 | line[255] = '\0'; |
… | |
… | |
2815 | } |
2909 | } |
2816 | /* |
2910 | /* |
2817 | * produce result |
2911 | * produce result |
2818 | */ |
2912 | */ |
2819 | if (sstate.envelope.fname) { |
2913 | if (sstate.envelope.fname) { |
2820 | FP_free (result->filename); |
2914 | _FP_free (result->filename); |
2821 | if ((result->filename = FP_strdup (sstate.envelope.fname)) == NULL) |
2915 | if ((result->filename = _FP_strdup (sstate.envelope.fname)) == NULL) |
2822 | *errcode = UURET_NOMEM; |
2916 | *errcode = UURET_NOMEM; |
2823 | } |
2917 | } |
2824 | else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) && |
2918 | else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) && |
2825 | result->filename == NULL) { |
2919 | result->filename == NULL) { |
2826 | sprintf (line, "%04d.txt", ++mimseqno); |
2920 | sprintf (line, "%04d.txt", ++mimseqno); |
2827 | if ((result->filename = FP_strdup (line)) == NULL) |
2921 | if ((result->filename = _FP_strdup (line)) == NULL) |
2828 | *errcode = UURET_NOMEM; |
2922 | *errcode = UURET_NOMEM; |
2829 | } |
2923 | } |
2830 | else { |
2924 | else { |
2831 | /* assign a filename lateron */ |
2925 | /* assign a filename lateron */ |
2832 | } |
2926 | } |
2833 | if (result->subject == NULL) { |
2927 | if (result->subject == NULL) { |
2834 | if (sstate.envelope.subject) |
2928 | if (sstate.envelope.subject) |
2835 | result->subject = FP_strdup (sstate.envelope.subject); |
2929 | result->subject = _FP_strdup (sstate.envelope.subject); |
2836 | } |
2930 | } |
2837 | result->flags = ((res==1||uu_fast_scanning)?FL_PROPER:0) | |
2931 | result->flags = ((res==1||uu_fast_scanning)?FL_PROPER:0) | |
2838 | ((uu_fast_scanning) ? FL_TOEND : 0); |
2932 | ((uu_fast_scanning) ? FL_TOEND : 0); |
2839 | result->mimeid = FP_strdup (sstate.envelope.mimeid); |
2933 | result->mimeid = _FP_strdup (sstate.envelope.mimeid); |
2840 | |
2934 | |
2841 | if (uu_fast_scanning) |
2935 | if (uu_fast_scanning) |
2842 | result->length = progress.fsize - result->startpos; |
2936 | result->length = progress.fsize - result->startpos; |
2843 | else |
2937 | else |
2844 | result->length = prevpos - result->startpos; |
2938 | result->length = prevpos - result->startpos; |
2845 | |
2939 | |
2846 | if (result->sfname == NULL) |
2940 | if (result->sfname == NULL) |
2847 | result->sfname = FP_strdup (fname); |
2941 | result->sfname = _FP_strdup (fname); |
2848 | |
2942 | |
2849 | if (result->mode == 0) |
2943 | if (result->mode == 0) |
2850 | result->mode = 0644; |
2944 | result->mode = 0644; |
2851 | |
2945 | |
2852 | /* |
2946 | /* |
… | |
… | |
2886 | * we know that sstate.envelope.boundary is NULL, or we wouldn't |
2980 | * we know that sstate.envelope.boundary is NULL, or we wouldn't |
2887 | * be here! |
2981 | * be here! |
2888 | */ |
2982 | */ |
2889 | |
2983 | |
2890 | if ((sstate.envelope.ctype == NULL || |
2984 | if ((sstate.envelope.ctype == NULL || |
2891 | FP_stristr (sstate.envelope.ctype, "multipart") != NULL) && |
2985 | _FP_stristr (sstate.envelope.ctype, "multipart") != NULL) && |
2892 | !uu_more_mime) { |
2986 | !uu_more_mime) { |
2893 | prevpos = ftell (datei); |
2987 | prevpos = ftell (datei); |
2894 | while (!feof (datei)) { |
2988 | while (!feof (datei)) { |
2895 | if (FP_fgets (line, 255, datei) == NULL) { |
2989 | if (_FP_fgets (line, 255, datei) == NULL) { |
2896 | line[0] = '\0'; |
2990 | line[0] = '\0'; |
2897 | break; |
2991 | break; |
2898 | } |
2992 | } |
2899 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
2993 | if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); |
2900 | if (!IsLineEmpty (line)) |
2994 | if (!IsLineEmpty (line)) |
2901 | break; |
2995 | break; |
2902 | } |
2996 | } |
2903 | if (line[0] == '-' && line[1] == '-' && |
2997 | if (line[0] == '-' && line[1] == '-' && |
2904 | !IsLineEmpty (line+2) && !feof (datei)) { |
2998 | !IsLineEmpty (line+2) && !feof (datei)) { |
2905 | ptr1 = FP_strrstr (line+2, "--"); |
2999 | ptr1 = _FP_strrstr (line+2, "--"); |
2906 | ptr2 = ScanHeaderLine (datei, NULL); |
3000 | ptr2 = ScanHeaderLine (datei, NULL); |
2907 | if ((ptr1 == NULL || (*(ptr1+2) != '\012' && *(ptr1+2) != '\015')) && |
3001 | if ((ptr1 == NULL || (*(ptr1+2) != '\012' && *(ptr1+2) != '\015')) && |
2908 | ptr2 && FP_strnicmp (ptr2, "Content-", 8) == 0) { |
3002 | ptr2 && _FP_strnicmp (ptr2, "Content-", 8) == 0) { |
2909 | /* |
3003 | /* |
2910 | * hmm, okay, let's do it! |
3004 | * hmm, okay, let's do it! |
2911 | */ |
3005 | */ |
2912 | sstate.isfolder = 1; |
3006 | sstate.isfolder = 1; |
2913 | sstate.ismime = 1; |
3007 | sstate.ismime = 1; |
… | |
… | |
2917 | */ |
3011 | */ |
2918 | ptr1 = line+2; |
3012 | ptr1 = line+2; |
2919 | while (*ptr1 && !isspace(*ptr1)) |
3013 | while (*ptr1 && !isspace(*ptr1)) |
2920 | ptr1++; |
3014 | ptr1++; |
2921 | *ptr1 = '\0'; |
3015 | *ptr1 = '\0'; |
2922 | |
3016 | |
2923 | sstate.envelope.mimevers = FP_strdup ("1.0"); |
3017 | sstate.envelope.mimevers = _FP_strdup ("1.0"); |
2924 | sstate.envelope.boundary = FP_strdup (line+2); |
3018 | sstate.envelope.boundary = _FP_strdup (line+2); |
2925 | |
3019 | |
2926 | /* |
3020 | /* |
2927 | * need restart |
3021 | * need restart |
2928 | */ |
3022 | */ |
2929 | |
3023 | |
2930 | fseek (datei, prevpos, SEEK_SET); |
3024 | fseek (datei, prevpos, SEEK_SET); |
2931 | |
3025 | |
2932 | FP_free (result); |
3026 | _FP_free (result); |
2933 | return NULL; |
3027 | return NULL; |
2934 | } |
3028 | } |
2935 | } |
3029 | } |
2936 | fseek (datei, prevpos, SEEK_SET); |
3030 | fseek (datei, prevpos, SEEK_SET); |
2937 | } |
3031 | } |
… | |
… | |
2941 | * Freestyle time. Anyway, if this seems to be a Mime message, |
3035 | * Freestyle time. Anyway, if this seems to be a Mime message, |
2942 | * don't allow the minimal Base64 handling. |
3036 | * don't allow the minimal Base64 handling. |
2943 | */ |
3037 | */ |
2944 | |
3038 | |
2945 | if (sstate.envelope.subject) |
3039 | if (sstate.envelope.subject) |
2946 | result->subject = FP_strdup (sstate.envelope.subject); |
3040 | result->subject = _FP_strdup (sstate.envelope.subject); |
2947 | if (sstate.envelope.from) |
3041 | if (sstate.envelope.from) |
2948 | result->origin = FP_strdup (sstate.envelope.from); |
3042 | result->origin = _FP_strdup (sstate.envelope.from); |
2949 | |
3043 | |
2950 | if (sstate.envelope.ctype) |
3044 | if (sstate.envelope.ctype) |
2951 | result->mimetype = FP_strdup (sstate.envelope.ctype); |
3045 | result->mimetype = _FP_strdup (sstate.envelope.ctype); |
2952 | |
3046 | |
2953 | if ((res=ScanData (datei, fname, errcode, NULL, |
3047 | if ((res=ScanData (datei, fname, errcode, NULL, |
2954 | sstate.ismime, 1, result))==-1) { |
3048 | sstate.ismime, 1, result))==-1) { |
2955 | /* oops, something went wrong */ |
3049 | /* oops, something went wrong */ |
2956 | sstate.isfolder = 0; |
3050 | sstate.isfolder = 0; |
2957 | sstate.ismime = 0; |
3051 | sstate.ismime = 0; |
2958 | UUkillfread (result); |
3052 | UUkillfread (result); |
2959 | return NULL; |
3053 | return NULL; |
2960 | } |
3054 | } |
|
|
3055 | |
2961 | /* |
3056 | /* |
2962 | * produce result |
3057 | * produce result |
2963 | */ |
3058 | */ |
|
|
3059 | |
2964 | if (result->uudet == 0 && uu_handletext) { |
3060 | if (result->uudet == 0 && uu_handletext) { |
2965 | result->startpos = before; /* display headers */ |
3061 | result->startpos = before; /* display headers */ |
2966 | result->uudet = PT_ENCODED; |
3062 | result->uudet = PT_ENCODED; |
2967 | result->partno = 1; |
3063 | result->partno = 1; |
2968 | } |
3064 | } |
2969 | |
3065 | |
|
|
3066 | if (result->uudet == YENC_ENCODED && result->filename != NULL) { |
|
|
3067 | /* |
|
|
3068 | * prevent replacing the filename found on the =ybegin line |
|
|
3069 | */ |
|
|
3070 | } |
2970 | if (sstate.envelope.fname) { |
3071 | else if (sstate.envelope.fname) { |
2971 | FP_free (result->filename); |
3072 | _FP_free (result->filename); |
2972 | if ((result->filename = FP_strdup (sstate.envelope.fname)) == NULL) |
3073 | if ((result->filename = _FP_strdup (sstate.envelope.fname)) == NULL) |
2973 | *errcode = UURET_NOMEM; |
3074 | *errcode = UURET_NOMEM; |
2974 | } |
3075 | } |
2975 | else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) && |
3076 | else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) && |
2976 | result->filename == NULL) { |
3077 | result->filename == NULL) { |
2977 | sprintf (line, "%04d.txt", ++mimseqno); |
3078 | sprintf (line, "%04d.txt", ++mimseqno); |
2978 | if ((result->filename = FP_strdup (line)) == NULL) |
3079 | if ((result->filename = _FP_strdup (line)) == NULL) |
2979 | *errcode = UURET_NOMEM; |
3080 | *errcode = UURET_NOMEM; |
2980 | } |
3081 | } |
2981 | else { |
3082 | else { |
2982 | /* assign a filename lateron */ |
3083 | /* assign a filename lateron */ |
2983 | } |
3084 | } |
|
|
3085 | |
2984 | if (result->subject == NULL) { |
3086 | if (result->subject == NULL) { |
2985 | if (sstate.envelope.subject) |
3087 | if (sstate.envelope.subject) |
2986 | result->subject = FP_strdup (sstate.envelope.subject); |
3088 | result->subject = _FP_strdup (sstate.envelope.subject); |
2987 | } |
3089 | } |
2988 | |
3090 | |
2989 | result->flags = (result->uudet==PT_ENCODED)?FL_SINGLE:0; |
3091 | result->flags = (result->uudet==PT_ENCODED)?FL_SINGLE:0; |
2990 | result->mimeid = FP_strdup (sstate.envelope.mimeid); |
3092 | result->mimeid = _FP_strdup (sstate.envelope.mimeid); |
2991 | result->length = ftell (datei) - result->startpos; |
3093 | result->length = ftell (datei) - result->startpos; |
2992 | |
3094 | |
2993 | if (result->mode == 0) |
3095 | if (result->mode == 0) |
2994 | result->mode = 0644; |
3096 | result->mode = 0644; |
2995 | |
3097 | |
2996 | if (result->sfname == NULL) |
3098 | if (result->sfname == NULL) |
2997 | result->sfname = FP_strdup (fname); |
3099 | result->sfname = _FP_strdup (fname); |
2998 | |
3100 | |
2999 | if (res == 1) { |
3101 | if (res == 1) { |
3000 | /* |
3102 | /* |
3001 | * new headers found |
3103 | * new headers found |
3002 | */ |
3104 | */ |
… | |
… | |
3025 | UUkillheaders (&localenv); |
3127 | UUkillheaders (&localenv); |
3026 | |
3128 | |
3027 | while (mssdepth) { |
3129 | while (mssdepth) { |
3028 | mssdepth--; |
3130 | mssdepth--; |
3029 | UUkillheaders (&(multistack[mssdepth].envelope)); |
3131 | UUkillheaders (&(multistack[mssdepth].envelope)); |
3030 | FP_free (multistack[mssdepth].source); |
3132 | _FP_free (multistack[mssdepth].source); |
3031 | } |
3133 | } |
3032 | |
3134 | |
3033 | return NULL; |
3135 | return NULL; |
3034 | } |
3136 | } |
3035 | |
3137 | |