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

Comparing Convert-UUlib/uulib/uuscan.c (file contents):
Revision 1.3 by root, Tue Aug 7 13:38:38 2001 UTC vs.
Revision 1.3.2.4 by root, Thu Nov 6 13:08:24 2003 UTC

55#include <uudeview.h> 55#include <uudeview.h>
56#include <uuint.h> 56#include <uuint.h>
57#include <fptools.h> 57#include <fptools.h>
58#include <uustring.h> 58#include <uustring.h>
59 59
60char * uuscan_id = "$Id: uuscan.c,v 1.3 2001/08/07 13:38:38 root Exp $"; 60char * uuscan_id = "$Id: uuscan.c,v 1.3.2.4 2003/11/06 13:08:24 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.
117/* 117/*
118 * mallocable areas 118 * mallocable areas
119 */ 119 */
120 120
121char *uuscan_shlline; 121char *uuscan_shlline;
122char *uuscan_shlline2;
122char *uuscan_pvvalue; 123char *uuscan_pvvalue;
123char *uuscan_phtext; 124char *uuscan_phtext;
124char *uuscan_sdline; 125char *uuscan_sdline;
125char *uuscan_sdbhds1; 126char *uuscan_sdbhds1;
126char *uuscan_sdbhds2; 127char *uuscan_sdbhds2;
140IsLineEmpty (char *data) 141IsLineEmpty (char *data)
141{ 142{
142 if (data == NULL) return 0; 143 if (data == NULL) return 0;
143 while (*data && isspace (*data)) data++; 144 while (*data && isspace (*data)) data++;
144 return ((*data)?0:1); 145 return ((*data)?0:1);
146}
147
148/*
149 * Is this a header line? A header line has alphanumeric characters
150 * followed by a colon.
151 */
152
153static int
154IsHeaderLine (char *data)
155{
156 if (data == NULL) return 0;
157 if (*data == ':') return 0;
158 while (*data && isalnum (*data)) data++;
159 return (*data == ':') ? 1 : 0;
145} 160}
146 161
147/* 162/*
148 * Scans a potentially folded header line from the input file. If 163 * Scans a potentially folded header line from the input file. If
149 * initial is non-NULL, it is the first line of the header, useful 164 * initial is non-NULL, it is the first line of the header, useful
155 170
156static char * 171static char *
157ScanHeaderLine (FILE *datei, char *initial) 172ScanHeaderLine (FILE *datei, char *initial)
158{ 173{
159 char *ptr=uuscan_shlline; 174 char *ptr=uuscan_shlline;
175 char *ptr2, *p1, *p2, *p3;
160 int llength, c; 176 int llength, c;
161 long curpos; 177 long curpos;
162 int hadcr; 178 int hadcr;
163 179
164 if (initial) { 180 if (initial) {
165 FP_strncpy (uuscan_shlline, initial, 1024); 181 _FP_strncpy (uuscan_shlline, initial, 1024);
166 } 182 }
167 else { 183 else {
168 /* read first line */ 184 /* read first line */
169 if (feof (datei) || ferror (datei)) 185 if (feof (datei) || ferror (datei))
170 return NULL; 186 return NULL;
171 if (FP_fgets (uuscan_shlline, 1023, datei) == NULL) 187 if (_FP_fgets (uuscan_shlline, 1023, datei) == NULL)
172 return NULL; 188 return NULL;
173 uuscan_shlline[1023] = '\0'; 189 uuscan_shlline[1023] = '\0';
174 } 190 }
175 191
176 llength = strlen (uuscan_shlline); 192 llength = strlen (uuscan_shlline);
219 if (feof (datei)) 235 if (feof (datei))
220 break; 236 break;
221 237
222 /* read next line */ 238 /* read next line */
223 curpos = ftell (datei); 239 curpos = ftell (datei);
224 if (FP_fgets (uugen_inbuffer, 255, datei) == NULL) 240 if (_FP_fgets (uugen_inbuffer, 255, datei) == NULL)
225 break; 241 break;
226 uugen_inbuffer[255] = '\0'; 242 uugen_inbuffer[255] = '\0';
227 243
228 if (IsLineEmpty (uugen_inbuffer)) { /* oops */ 244 if (IsLineEmpty (uugen_inbuffer)) { /* oops */
229 fseek (datei, curpos, SEEK_SET); 245 fseek (datei, curpos, SEEK_SET);
230 break; 246 break;
231 } 247 }
232 248
233 FP_strncpy (ptr, uugen_inbuffer, 1024-llength); 249 _FP_strncpy (ptr, uugen_inbuffer, 1024-llength);
234 250
235 /* 251 /*
236 * see if line was terminated with CR. Otherwise, it continues ... 252 * see if line was terminated with CR. Otherwise, it continues ...
237 */ 253 */
238 c = strlen (ptr); 254 c = strlen (ptr);
249 llength += c; 265 llength += c;
250 while (llength && isspace(*(ptr-1))) { 266 while (llength && isspace(*(ptr-1))) {
251 ptr--; llength--; 267 ptr--; llength--;
252 } 268 }
253 } 269 }
270
254 *ptr = '\0'; 271 *ptr = '\0';
255 272
256 if (llength == 0) 273 if (llength == 0)
257 return NULL; 274 return NULL;
258 275
276 /*
277 * Now that we've read the header line, we can RFC 1522-decode it
278 */
279
280 ptr = uuscan_shlline;
281 ptr2 = uuscan_shlline2;
282
283 while (*ptr) {
284 /*
285 * Look for =? magic
286 */
287
288 if (*ptr == '=' && *(ptr+1) == '?') {
289 /*
290 * Let p1 point to the charset, look for next question mark
291 */
292
293 p1 = p2 = ptr+2;
294
295 while (*p2 && *p2 != '?') {
296 p2++;
297 }
298
299 if (*p2 == '?' &&
300 (*(p2+1) == 'q' || *(p2+1) == 'Q' ||
301 *(p2+1) == 'b' || *(p2+1) == 'B') &&
302 *(p2+2) == '?') {
303 /*
304 * Let p2 point to the encoding, look for ?= magic
305 */
306
307 p2++;
308 p3=p2+2;
309
310 while (*p3 && (*p3 != '?' || *(p3+1) != '=')) {
311 p3++;
312 }
313
314 if (*p3 == '?' && *(p3+1) == '=') {
315 /*
316 * Alright, we've found an RFC 1522 header field
317 */
318 if (*p2 == 'q' || *p2 == 'Q') {
319 c = UUDecodeField (p2+2, ptr2, QP_ENCODED);
320 }
321 else if (*p2 == 'b' || *p2 == 'B') {
322 c = UUDecodeField (p2+2, ptr2, B64ENCODED);
323 }
324 if (c >= 0) {
325 ptr2 += c;
326 ptr = p3+2;
327 continue;
328 }
329 }
330 }
331 }
332
333 *ptr2++ = *ptr++;
334 }
335
336 *ptr2 = 0;
337
259 return uuscan_shlline; 338 return uuscan_shlline2;
260} 339}
261 340
262/* 341/*
263 * Extract the value from a MIME attribute=value pair. This function 342 * Extract the value from a MIME attribute=value pair. This function
264 * receives a pointer to the attribute. 343 * receives a pointer to the attribute.
288 367
289 if (*attribute == '"') { 368 if (*attribute == '"') {
290 /* quoted-string */ 369 /* quoted-string */
291 attribute++; 370 attribute++;
292 while (*attribute && *attribute != '"' && length < 255) { 371 while (*attribute && *attribute != '"' && length < 255) {
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;
302 else
303 *ptr++ = *attribute; 372 *ptr++ = *attribute++;
304 attribute++;
305 length++; 373 length++;
306 } 374 }
307 *ptr = '\0'; 375 *ptr = '\0';
308 } 376 }
309 else { 377 else {
310 /* tspecials from RFC1521 */ 378 /* tspecials from RFC1521 */
379 /*
380 * Note - exclude '[', ']' and ';' on popular request; these are
381 * used in some Content-Type fields by the Klez virus, and people
382 * who feed their virus scanners with the output of UUDeview would
383 * like to catch it!
384 */
311 385
312 while (*attribute && !isspace (*attribute) && 386 while (*attribute && !isspace (*attribute) &&
313 *attribute != '(' && *attribute != ')' && 387 *attribute != '(' && *attribute != ')' &&
314 *attribute != '<' && *attribute != '>' && 388 *attribute != '<' && *attribute != '>' &&
315 *attribute != '@' && *attribute != ',' && 389 *attribute != '@' && *attribute != ',' &&
316 *attribute != ';' && *attribute != ':' && 390 /* *attribute != ';' && */ *attribute != ':' &&
317 *attribute != '\\' &&*attribute != '"' && 391 *attribute != '\\' &&*attribute != '"' &&
318 *attribute != '/' && *attribute != '[' && 392 *attribute != '/' && /* *attribute != '[' &&
319 *attribute != ']' && *attribute != '?' && 393 *attribute != ']' && */ *attribute != '?' &&
320 *attribute != '=' && length < 255) 394 *attribute != '=' && length < 255)
321 *ptr++ = *attribute++; 395 *ptr++ = *attribute++;
322 396
323 *ptr = '\0'; 397 *ptr = '\0';
324 } 398 }
334{ 408{
335 char **variable=NULL; 409 char **variable=NULL;
336 char *value, *ptr, *thenew; 410 char *value, *ptr, *thenew;
337 int delimit, length; 411 int delimit, length;
338 412
339 value = 0; delimit = 0; /* calm down gcc */
340
341 if (line == NULL) 413 if (line == NULL)
342 return theheaders; 414 return theheaders;
343 415
344 if (FP_strnicmp (line, "From:", 5) == 0) { 416 if (_FP_strnicmp (line, "From:", 5) == 0) {
345 if (theheaders->from) return theheaders; 417 if (theheaders->from) return theheaders;
346 variable = &theheaders->from; 418 variable = &theheaders->from;
347 value = line+5; 419 value = line+5;
348 delimit = 0; 420 delimit = 0;
349 } 421 }
350 else if (FP_strnicmp (line, "Subject:", 8) == 0) { 422 else if (_FP_strnicmp (line, "Subject:", 8) == 0) {
351 if (theheaders->subject) return theheaders; 423 if (theheaders->subject) return theheaders;
352 variable = &theheaders->subject; 424 variable = &theheaders->subject;
353 value = line+8; 425 value = line+8;
354 delimit = 0; 426 delimit = 0;
355 } 427 }
356 else if (FP_strnicmp (line, "To:", 3) == 0) { 428 else if (_FP_strnicmp (line, "To:", 3) == 0) {
357 if (theheaders->rcpt) return theheaders; 429 if (theheaders->rcpt) return theheaders;
358 variable = &theheaders->rcpt; 430 variable = &theheaders->rcpt;
359 value = line+3; 431 value = line+3;
360 delimit = 0; 432 delimit = 0;
361 } 433 }
362 else if (FP_strnicmp (line, "Date:", 5) == 0) { 434 else if (_FP_strnicmp (line, "Date:", 5) == 0) {
363 if (theheaders->date) return theheaders; 435 if (theheaders->date) return theheaders;
364 variable = &theheaders->date; 436 variable = &theheaders->date;
365 value = line+5; 437 value = line+5;
366 delimit = 0; 438 delimit = 0;
367 } 439 }
368 else if (FP_strnicmp (line, "Mime-Version:", 13) == 0) { 440 else if (_FP_strnicmp (line, "Mime-Version:", 13) == 0) {
369 if (theheaders->mimevers) return theheaders; 441 if (theheaders->mimevers) return theheaders;
370 variable = &theheaders->mimevers; 442 variable = &theheaders->mimevers;
371 value = line+13; 443 value = line+13;
372 delimit = 0; 444 delimit = 0;
373 } 445 }
374 else if (FP_strnicmp (line, "Content-Type:", 13) == 0) { 446 else if (_FP_strnicmp (line, "Content-Type:", 13) == 0) {
375 if (theheaders->ctype) return theheaders; 447 if (theheaders->ctype) return theheaders;
376 variable = &theheaders->ctype; 448 variable = &theheaders->ctype;
377 value = line+13; 449 value = line+13;
378 delimit = ';'; 450 delimit = ';';
379 451
380 /* we can probably extract more information */ 452 /* we can probably extract more information */
381 if ((ptr = FP_stristr (line, "boundary")) != NULL) { 453 if ((ptr = _FP_stristr (line, "boundary")) != NULL) {
382 if ((thenew = ParseValue (ptr))) { 454 if ((thenew = ParseValue (ptr))) {
383 if (theheaders->boundary) free (theheaders->boundary); 455 if (theheaders->boundary) free (theheaders->boundary);
384 theheaders->boundary = FP_strdup (thenew); 456 theheaders->boundary = _FP_strdup (thenew);
385 }
386 } 457 }
458 }
387 if ((ptr = FP_stristr (line, "name")) != NULL) { 459 if ((ptr = _FP_stristr (line, "name")) != NULL) {
388 if ((thenew = ParseValue (ptr))) { 460 if ((thenew = ParseValue (ptr))) {
389 if (theheaders->fname) free (theheaders->fname); 461 if (theheaders->fname) free (theheaders->fname);
390 theheaders->fname = FP_strdup (thenew); 462 theheaders->fname = _FP_strdup (thenew);
391 }
392 } 463 }
464 }
393 if ((ptr = FP_stristr (line, "id")) != NULL) { 465 if ((ptr = _FP_stristr (line, "id")) != NULL) {
394 if ((thenew = ParseValue (ptr))) { 466 if ((thenew = ParseValue (ptr))) {
395 if (theheaders->mimeid) free (theheaders->mimeid); 467 if (theheaders->mimeid) free (theheaders->mimeid);
396 theheaders->mimeid = FP_strdup (thenew); 468 theheaders->mimeid = _FP_strdup (thenew);
397 }
398 } 469 }
470 }
399 if ((ptr = FP_stristr (line, "number")) != NULL) { 471 if ((ptr = _FP_stristr (line, "number")) != NULL) {
400 if ((thenew = ParseValue (ptr))) { 472 if ((thenew = ParseValue (ptr))) {
401 theheaders->partno = atoi (thenew); 473 theheaders->partno = atoi (thenew);
402 } 474 }
403 } 475 }
404 if ((ptr = FP_stristr (line, "total")) != NULL) { 476 if ((ptr = _FP_stristr (line, "total")) != NULL) {
405 if ((thenew = ParseValue (ptr))) { 477 if ((thenew = ParseValue (ptr))) {
406 theheaders->numparts = atoi (thenew); 478 theheaders->numparts = atoi (thenew);
407 } 479 }
408 } 480 }
409 } 481 }
410 else if (FP_strnicmp (line, "Content-Transfer-Encoding:", 26) == 0) { 482 else if (_FP_strnicmp (line, "Content-Transfer-Encoding:", 26) == 0) {
411 if (theheaders->ctenc) return theheaders; 483 if (theheaders->ctenc) return theheaders;
412 variable = &theheaders->ctenc; 484 variable = &theheaders->ctenc;
413 value = line+26; 485 value = line+26;
414 delimit = ';'; 486 delimit = ';';
415 } 487 }
416 else if (FP_strnicmp (line, "Content-Disposition:", 20) == 0) { 488 else if (_FP_strnicmp (line, "Content-Disposition:", 20) == 0) {
417 /* 489 /*
418 * Some encoders mention the original filename as parameter to 490 * Some encoders mention the original filename as parameter to
419 * Content-Type, others as parameter to Content-Disposition. We 491 * Content-Type, others as parameter to Content-Disposition. We
420 * do prefer the first solution, but accept this situation, too. 492 * do prefer the first solution, but accept this situation, too.
421 * TODO: Read RFC1806 493 * TODO: Read RFC1806
422 */ 494 */
423 if ((ptr = FP_stristr (line, "name")) != NULL) { 495 if ((ptr = _FP_stristr (line, "name")) != NULL) {
424 if (theheaders->fname == NULL && (thenew=ParseValue(ptr)) != NULL) { 496 if (theheaders->fname == NULL && (thenew=ParseValue(ptr)) != NULL) {
425 theheaders->fname = FP_strdup (thenew); 497 theheaders->fname = _FP_strdup (thenew);
426 } 498 }
427 } 499 }
428 variable = NULL; 500 variable = NULL;
429 } 501 }
430 else { 502 else {
431 /* 503 /*
432 * nothing interesting 504 * nothing interesting
433 */ 505 */
434 variable = NULL; 506 return theheaders;
435 } 507 }
436 508
437 /* 509 /*
438 * okay, so extract the actual data 510 * okay, so extract the actual data
439 */ 511 */
451 while (length && isspace(*(ptr-1))) { 523 while (length && isspace(*(ptr-1))) {
452 ptr--; length--; 524 ptr--; length--;
453 } 525 }
454 *ptr = '\0'; 526 *ptr = '\0';
455 527
456 if ((*variable = FP_strdup (uuscan_phtext)) == NULL) 528 if ((*variable = _FP_strdup (uuscan_phtext)) == NULL)
457 return NULL; 529 return NULL;
458 } 530 }
459 531
460 return theheaders; 532 return theheaders;
461} 533}
468IsKnownHeader (char *line) 540IsKnownHeader (char *line)
469{ 541{
470 char **iter = knownmsgheaders; 542 char **iter = knownmsgheaders;
471 543
472 while (iter && *iter) { 544 while (iter && *iter) {
473 if (FP_strnicmp (line, *iter, strlen (*iter)) == 0) 545 if (_FP_strnicmp (line, *iter, strlen (*iter)) == 0)
474 return 1; 546 return 1;
475 iter++; 547 iter++;
476 } 548 }
477 549
478 iter = knownmimeheaders; 550 iter = knownmimeheaders;
479 551
480 while (iter && *iter) { 552 while (iter && *iter) {
481 if (FP_strnicmp (line, *iter, strlen (*iter)) == 0) 553 if (_FP_strnicmp (line, *iter, strlen (*iter)) == 0)
482 return 2; 554 return 2;
483 iter++; 555 iter++;
484 } 556 }
485 557
486 return 0; 558 return 0;
523 char *boundary, int ismime, int checkheaders, 595 char *boundary, int ismime, int checkheaders,
524 fileread *result) 596 fileread *result)
525{ 597{
526 char *line=uuscan_sdline, *bhds1=uuscan_sdbhds1, *bhds2=uuscan_sdbhds2; 598 char *line=uuscan_sdline, *bhds1=uuscan_sdbhds1, *bhds2=uuscan_sdbhds2;
527 static char *ptr, *p2, *p3=NULL, *bhdsp, bhl; 599 static char *ptr, *p2, *p3=NULL, *bhdsp, bhl;
528 int isb64[10], isuue[10], isxxe[10], isbhx[10], iscnt; 600 int islen[10], isb64[10], isuue[10], isxxe[10], isbhx[10], iscnt;
529 int cbb64, cbuue, cbxxe, cbbhx; 601 int cbb64, cbuue, cbxxe, cbbhx;
530 int bhflag=0, vflag, haddh=0, hadct=0; 602 int bhflag=0, vflag, haddh=0, hadct=0;
531 int bhrpc=0, bhnf=0, c, hcount, lcount, blen; 603 int bhrpc=0, bhnf=0, c, hcount, lcount, blen=0;
532 int encoding=0, dflag=0, ctline=42; 604 int encoding=0, dflag=0, ctline=42;
533 int dontcare=0, hadnl=0; 605 int dontcare=0, hadnl=0;
534 long preheaders, oldposition; 606 long preheaders=0, oldposition;
607 long yefilesize=0, yepartends=0;
535 size_t dcc, bhopc; 608 size_t dcc, bhopc;
536
537 blen = 0; preheaders = 0; /* calm down gcc */
538 609
539 *errcode = UURET_OK; 610 *errcode = UURET_OK;
540 (void) UUDecodeLine (NULL, NULL, 0); /* init */ 611 (void) UUDecodeLine (NULL, NULL, 0); /* init */
541 bhdsp = bhds2; 612 bhdsp = bhds2;
542 613
546 result->startpos = ftell (datei); 617 result->startpos = ftell (datei);
547 hcount = lcount = 0; 618 hcount = lcount = 0;
548 619
549 for (iscnt=0; iscnt<10; iscnt++) { 620 for (iscnt=0; iscnt<10; iscnt++) {
550 isb64[iscnt] = isuue[iscnt] = isxxe[iscnt] = isbhx[iscnt] = 0; 621 isb64[iscnt] = isuue[iscnt] = isxxe[iscnt] = isbhx[iscnt] = 0;
622 islen[iscnt] = -1;
551 } 623 }
552 624
553 iscnt = 0; 625 iscnt = 0;
554 626
555 if (boundary) 627 if (boundary)
556 blen = strlen (boundary); 628 blen = strlen (boundary);
557 629
558 while (!feof (datei)) { 630 while (!feof (datei)) {
559 oldposition = ftell (datei); 631 oldposition = ftell (datei);
560 if (FP_fgets (line, 255, datei) == NULL) 632 if (_FP_fgets (line, 299, datei) == NULL)
561 break; 633 break;
562 if (ferror (datei)) 634 if (ferror (datei))
563 break; 635 break;
564 636
565 line[255] = '\0'; /* For Safety of string functions */ 637 line[299] = '\0'; /* For Safety of string functions */
566 638
567 /* 639 /*
568 * Make Busy Polls 640 * Make Busy Polls
569 */ 641 */
570 642
630 strncmp (line+2, boundary, blen) == 0) { 702 strncmp (line+2, boundary, blen) == 0) {
631 fseek (datei, oldposition, SEEK_SET); 703 fseek (datei, oldposition, SEEK_SET);
632 break; 704 break;
633 } 705 }
634 if (boundary != NULL && line[0] == 'C' && line[1] == 'o' && 706 if (boundary != NULL && line[0] == 'C' && line[1] == 'o' &&
635 FP_strnicmp (line, "Content-Type:", 13) == 0) { 707 _FP_strnicmp (line, "Content-Type:", 13) == 0) {
636 ptr = ScanHeaderLine (datei, line); 708 ptr = ScanHeaderLine (datei, line);
637 p2 = (ptr)?FP_stristr(ptr,"boundary"):NULL; 709 p2 = (ptr)?_FP_stristr(ptr,"boundary"):NULL;
638 p3 = (p2)?ParseValue(p2):NULL; 710 p3 = (p2)?ParseValue(p2):NULL;
639 711
640 if (p3 && strcmp (p3, boundary) == 0) { 712 if (p3 && strcmp (p3, boundary) == 0) {
641 fseek (datei, oldposition, SEEK_SET); 713 fseek (datei, oldposition, SEEK_SET);
642 break; 714 break;
645 p3 = NULL; 717 p3 = NULL;
646 } 718 }
647 } 719 }
648 720
649 if (strncmp (line, "begin ", 6) == 0 || 721 if (strncmp (line, "begin ", 6) == 0 ||
650 FP_strnicmp (line, "<pre>begin ", 11) == 0) { 722 _FP_strnicmp (line, "<pre>begin ", 11) == 0) {
651 if ((result->begin || result->end || 723 if ((result->begin || result->end ||
652 result->uudet == B64ENCODED || 724 result->uudet == B64ENCODED ||
653 result->uudet == BH_ENCODED) && !uu_more_mime) { 725 result->uudet == BH_ENCODED) && !uu_more_mime) {
654 fseek (datei, oldposition, SEEK_SET); 726 fseek (datei, oldposition, SEEK_SET);
655 break; 727 break;
666 while (*ptr == ' ') ptr++; 738 while (*ptr == ' ') ptr++;
667 739
668 /* 740 /*
669 * We may have picked up a filename from a uuenview-style header 741 * We may have picked up a filename from a uuenview-style header
670 */ 742 */
671 FP_free (result->filename); 743 _FP_free (result->filename);
672 result->filename = FP_strdup (ptr); 744 result->filename = _FP_strdup (ptr);
673 result->begin = 1; 745 result->begin = 1;
674 746
675 while (isspace (result->filename[strlen(result->filename)-1])) 747 while (isspace (result->filename[strlen(result->filename)-1]))
676 result->filename[strlen(result->filename)-1] = '\0'; 748 result->filename[strlen(result->filename)-1] = '\0';
677 749
678 continue; 750 continue;
679 } 751 }
680 752
681 if ((strncmp (line, "end", 3) == 0) && result->uudet != BH_ENCODED) { 753 if ((strncmp (line, "end", 3) == 0) &&
754 result->uudet != BH_ENCODED &&
755 result->uudet != YENC_ENCODED) {
682 if (result->uudet == B64ENCODED && result->begin) 756 if (result->uudet == B64ENCODED && result->begin)
683 result->uudet = XX_ENCODED; 757 result->uudet = XX_ENCODED;
684 758
685 if (result->uudet != B64ENCODED) { 759 if (result->uudet != B64ENCODED) {
686 result->end = 1; 760 result->end = 1;
694 768
695 /* 769 /*
696 * Detect a UUDeview-Style header 770 * Detect a UUDeview-Style header
697 */ 771 */
698 772
699 if (FP_strnicmp (line, "_=_ Part ", 9) == 0) { 773 if (_FP_strnicmp (line, "_=_ Part ", 9) == 0 &&
774 result->uudet != YENC_ENCODED) {
700 if (result->uudet) { 775 if (result->uudet) {
701 fseek (datei, oldposition, SEEK_SET); 776 fseek (datei, oldposition, SEEK_SET);
702 break; 777 break;
703 } 778 }
704 result->partno = atoi (line + 8); 779 result->partno = atoi (line + 8);
705 if ((ptr = FP_stristr (line, "of file ")) != NULL) { 780 if ((ptr = _FP_stristr (line, "of file ")) != NULL) {
706 ptr += 8; 781 ptr += 8;
707 while (isspace (*ptr)) ptr++; 782 while (isspace (*ptr)) ptr++;
708 p2 = ptr; 783 p2 = ptr;
709 while (isalnum(*p2) || 784 while (isalnum(*p2) ||
710 *p2 == '.' || *p2=='_' || *p2 == '-' || 785 *p2 == '.' || *p2=='_' || *p2 == '-' ||
711 *p2 == '!' || *p2=='@' || *p2 == '$') 786 *p2 == '!' || *p2=='@' || *p2 == '$')
712 p2++; 787 p2++;
713 c = *p2; *p2 = '\0'; 788 c = *p2; *p2 = '\0';
714 if (p2 != ptr && result->filename == NULL) 789 if (p2 != ptr && result->filename == NULL)
715 result->filename = FP_strdup (ptr); 790 result->filename = _FP_strdup (ptr);
716 else if (p2 - ptr > 5 && strchr (ptr, '.') != NULL) { 791 else if (p2 - ptr > 5 && strchr (ptr, '.') != NULL) {
717 /* 792 /*
718 * This file name looks good, too. Let's use it 793 * This file name looks good, too. Let's use it
719 */ 794 */
720 FP_free (result->filename); 795 _FP_free (result->filename);
721 result->filename = FP_strdup (ptr); 796 result->filename = _FP_strdup (ptr);
722 } 797 }
723 *p2 = c; 798 *p2 = c;
724 } 799 }
725 } 800 }
726 801
727 /* 802 /*
728 * Some reduced MIME handling. Only use if boundary == NULL. Also 803 * Some reduced MIME handling. Only use if boundary == NULL. Also
729 * accept the "X-Orcl-Content-Type" used by some braindead program. 804 * accept the "X-Orcl-Content-Type" used by some braindead program.
730 */ 805 */
731 if (boundary == NULL && !ismime && !uu_more_mime) { 806 if (boundary == NULL && !ismime && !uu_more_mime &&
807 result->uudet != YENC_ENCODED) {
732 if (FP_strnicmp (line, "Content-Type", 12) == 0 || 808 if (_FP_strnicmp (line, "Content-Type", 12) == 0 ||
733 FP_strnicmp (line, "X-Orcl-Content-Type", 19) == 0) { 809 _FP_strnicmp (line, "X-Orcl-Content-Type", 19) == 0) {
734 /* 810 /*
735 * We use Content-Type to mark a new attachment and split the file. 811 * We use Content-Type to mark a new attachment and split the file.
736 * However, we do not split if we haven't found anything encoded yet. 812 * However, we do not split if we haven't found anything encoded yet.
737 */ 813 */
738 if (result->uudet) { 814 if (result->uudet) {
743 ptr++; 819 ptr++;
744 while (isspace (*ptr)) ptr++; p2 = ptr; 820 while (isspace (*ptr)) ptr++; p2 = ptr;
745 while (!isspace (*p2) && *p2 != ';') p2++; 821 while (!isspace (*p2) && *p2 != ';') p2++;
746 c = *p2; *p2 = '\0'; 822 c = *p2; *p2 = '\0';
747 if (p2 != ptr) { 823 if (p2 != ptr) {
748 FP_free (result->mimetype); 824 _FP_free (result->mimetype);
749 result->mimetype = FP_strdup (ptr); 825 result->mimetype = _FP_strdup (ptr);
750 } 826 }
751 *p2 = c; 827 *p2 = c;
752 } 828 }
753 ctline=0; 829 ctline=0;
754 hadct=1; 830 hadct=1;
755 } 831 }
756 if ((ptr = FP_stristr (line, "number=")) && ctline<4) { 832 if ((ptr = _FP_stristr (line, "number=")) && ctline<4) {
757 ptr += 7; if (*ptr == '"') ptr++; 833 ptr += 7; if (*ptr == '"') ptr++;
758 result->partno = atoi (ptr); 834 result->partno = atoi (ptr);
759 } 835 }
760 if ((ptr = FP_stristr (line, "total=")) && ctline<4) { 836 if ((ptr = _FP_stristr (line, "total=")) && ctline<4) {
761 ptr += 6; if (*ptr == '"') ptr++; 837 ptr += 6; if (*ptr == '"') ptr++;
762 result->maxpno = atoi (ptr); 838 result->maxpno = atoi (ptr);
763 } 839 }
764 if ((ptr = FP_stristr (line, "name=")) && ctline<4) { 840 if ((ptr = _FP_stristr (line, "name=")) && ctline<4) {
765 ptr += 5; 841 ptr += 5;
766 while (isspace (*ptr)) ptr++; 842 while (isspace (*ptr)) ptr++;
767 if (*ptr == '"' && *(ptr+1) && (p2 = strchr (ptr+2, '"')) != NULL) { 843 if (*ptr == '"' && *(ptr+1) && (p2 = strchr (ptr+2, '"')) != NULL) {
768 c = *p2; *p2 = '\0'; 844 c = *p2; *p2 = '\0';
769 FP_free (result->filename); 845 _FP_free (result->filename);
770 result->filename = FP_strdup (ptr+1); 846 result->filename = _FP_strdup (ptr+1);
771 *p2 = c; 847 *p2 = c;
772 } 848 }
773 else if (*ptr=='\''&&*(ptr+1)&&(p2 = strchr(ptr+2, '\'')) != NULL) { 849 else if (*ptr=='\''&&*(ptr+1)&&(p2 = strchr(ptr+2, '\'')) != NULL) {
774 c = *p2; *p2 = '\0'; 850 c = *p2; *p2 = '\0';
775 FP_free (result->filename); 851 _FP_free (result->filename);
776 result->filename = FP_strdup (ptr+1); 852 result->filename = _FP_strdup (ptr+1);
777 *p2 = c; 853 *p2 = c;
778 } 854 }
779 else { 855 else {
780 p2 = ptr; 856 p2 = ptr;
781 while (isalnum(*p2) || 857 while (isalnum(*p2) ||
782 *p2 == '.' || *p2=='_' || *p2 == '-' || 858 *p2 == '.' || *p2=='_' || *p2 == '-' ||
783 *p2 == '!' || *p2=='@' || *p2 == '$') 859 *p2 == '!' || *p2=='@' || *p2 == '$')
784 p2++; 860 p2++;
785 c = *p2; *p2 = '\0'; 861 c = *p2; *p2 = '\0';
786 if (p2 != ptr && result->filename == NULL) 862 if (p2 != ptr && result->filename == NULL)
787 result->filename = FP_strdup (ptr); 863 result->filename = _FP_strdup (ptr);
788 else if (p2 - ptr > 5 && strchr (ptr, '.') != NULL) { 864 else if (p2 - ptr > 5 && strchr (ptr, '.') != NULL) {
789 /* 865 /*
790 * This file name looks good, too. Let's use it 866 * This file name looks good, too. Let's use it
791 */ 867 */
792 FP_free (result->filename); 868 _FP_free (result->filename);
793 result->filename = FP_strdup (ptr); 869 result->filename = _FP_strdup (ptr);
794 } 870 }
795 *p2 = c; 871 *p2 = c;
796 } 872 }
797 } 873 }
798 if ((ptr = FP_stristr (line, "id=")) && ctline<4) { 874 if ((ptr = _FP_stristr (line, "id=")) && ctline<4) {
799 p2 = ptr += 3; 875 p2 = ptr += 3;
800 if (*p2 == '"') { 876 if (*p2 == '"') {
801 p2 = strchr (++ptr, '"'); 877 p2 = strchr (++ptr, '"');
802 } 878 }
803 else { 879 else {
805 p2++; 881 p2++;
806 } 882 }
807 if (p2 && *p2 && p2!=ptr) { 883 if (p2 && *p2 && p2!=ptr) {
808 c = *p2; *p2 = '\0'; 884 c = *p2; *p2 = '\0';
809 if (result->mimeid) 885 if (result->mimeid)
810 FP_free (result->mimeid); 886 _FP_free (result->mimeid);
811 result->mimeid = FP_strdup (ptr); 887 result->mimeid = _FP_strdup (ptr);
812 *p2 = c; 888 *p2 = c;
813 } 889 }
814 } 890 }
815 891
816 /* 892 /*
837 * a boundary, followed by a Content-* line, try to use it. 913 * a boundary, followed by a Content-* line, try to use it.
838 */ 914 */
839 915
840 if (boundary == NULL && !ismime && !uu_more_mime && dflag <= 1 && 916 if (boundary == NULL && !ismime && !uu_more_mime && dflag <= 1 &&
841 line[0] == '-' && line[1] == '-' && strlen(line+2)>10 && 917 line[0] == '-' && line[1] == '-' && strlen(line+2)>10 &&
842 (((ptr = FP_strrstr (line+2, "--")) == NULL) || 918 (((ptr = _FP_strrstr (line+2, "--")) == NULL) ||
843 *(ptr+2) != '\012' && *(ptr+2) != '\015') && 919 (*(ptr+2) != '\012' && *(ptr+2) != '\015')) &&
844 FP_strstr (line+2, "_=_") != NULL) { 920 _FP_strstr (line+2, "_=_") != NULL) {
845 if (FP_fgets (line, 255, datei) == NULL) { 921 if (_FP_fgets (line, 255, datei) == NULL) {
846 break; 922 break;
847 } 923 }
848 if (FP_strnicmp (line, "Content-", 8) == 0) { 924 if (_FP_strnicmp (line, "Content-", 8) == 0) {
849 /* 925 /*
850 * Okay, let's do it. This breaks out of ScanData. ScanPart will 926 * Okay, let's do it. This breaks out of ScanData. ScanPart will
851 * recognize the boundary on the next call and use it. 927 * recognize the boundary on the next call and use it.
852 */ 928 */
853 fseek (datei, oldposition, SEEK_SET); 929 fseek (datei, oldposition, SEEK_SET);
854 break; 930 break;
855 } 931 }
856 } 932 }
857 933
858 /* 934 /*
935 * Detection for yEnc encoding
936 */
937
938 if (strncmp (line, "=ybegin ", 8) == 0 &&
939 _FP_strstr (line, " name=") != NULL) {
940 if ((result->begin || result->end || result->uudet) && !uu_more_mime) {
941 fseek (datei, oldposition, SEEK_SET);
942 break;
943 }
944
945 /*
946 * name continues to the end of the line
947 */
948
949 _FP_free (result->filename);
950 ptr = _FP_strstr (line, " name=") + 6;
951 result->filename = _FP_strdup (ptr);
952
953 while (isspace (result->filename[strlen(result->filename)-1]))
954 result->filename[strlen(result->filename)-1] = '\0';
955
956 /*
957 * Determine size
958 */
959
960 if ((ptr = _FP_strstr (line, " size=")) != NULL) {
961 ptr += 6;
962 yefilesize = atoi (ptr);
963 }
964 else {
965 yefilesize = -1;
966 }
967
968 /*
969 * check for multipart file and read =ypart line
970 */
971
972 if ((ptr = _FP_strstr (line, " part=")) != NULL) {
973 result->partno = atoi (ptr + 6);
974
975 if (result->partno == 1) {
976 result->begin = 1;
977 }
978
979 if (_FP_fgets (line, 255, datei) == NULL) {
980 break;
981 }
982
983 line[255] = '\0';
984
985 if (strncmp (line, "=ypart ", 7) != 0) {
986 break;
987 }
988
989 if ((ptr = _FP_strstr (line, " end=")) == NULL) {
990 break;
991 }
992
993 yepartends = atoi (ptr + 5);
994 }
995 else {
996 result->partno = 1;
997 result->begin = 1;
998 }
999
1000 /*
1001 * Don't want auto-detection
1002 */
1003
1004 result->uudet = YENC_ENCODED;
1005 continue;
1006 }
1007
1008 if (strncmp (line, "=yend ", 6) == 0 &&
1009 result->uudet == YENC_ENCODED) {
1010 if (yepartends == 0 || yepartends >= yefilesize) {
1011 result->end = 1;
1012 }
1013#if 0
1014 if (!uu_more_mime)
1015 break;
1016#endif
1017 continue;
1018 }
1019
1020 /*
859 * if we haven't yet found anything encoded, try to find something 1021 * if we haven't yet found anything encoded, try to find something
860 */ 1022 */
861 1023
862 if (!(result->uudet)) { 1024 if (!(result->uudet)) {
863 /* 1025 /*
869 1031
870 /* 1032 /*
871 * Check data against all possible encodings 1033 * Check data against all possible encodings
872 */ 1034 */
873 1035
1036 islen[iscnt%10] = strlen(line);
874 isb64[iscnt%10] = (UUValidData (line, B64ENCODED, &bhflag)==B64ENCODED); 1037 isb64[iscnt%10] = (UUValidData (line, B64ENCODED, &bhflag)==B64ENCODED);
875 isuue[iscnt%10] = (UUValidData (line, UU_ENCODED, &bhflag)==UU_ENCODED); 1038 isuue[iscnt%10] = (UUValidData (line, UU_ENCODED, &bhflag)==UU_ENCODED);
876 isxxe[iscnt%10] = (UUValidData (line, XX_ENCODED, &bhflag)==XX_ENCODED); 1039 isxxe[iscnt%10] = (UUValidData (line, XX_ENCODED, &bhflag)==XX_ENCODED);
877 isbhx[iscnt%10] = (UUValidData (line, BH_ENCODED, &bhflag)==BH_ENCODED); 1040 isbhx[iscnt%10] = (UUValidData (line, BH_ENCODED, &bhflag)==BH_ENCODED);
878 1041
934 } 1097 }
935 if ((bhdsp-bhds2) > (int) bhds2[0] && bhds2[0]>0 && 1098 if ((bhdsp-bhds2) > (int) bhds2[0] && bhds2[0]>0 &&
936 result->filename==NULL) { 1099 result->filename==NULL) {
937 memcpy (bhds1, bhds2+1, (int) bhds2[0]); 1100 memcpy (bhds1, bhds2+1, (int) bhds2[0]);
938 bhds1[(int)bhds2[0]]='\0'; 1101 bhds1[(int)bhds2[0]]='\0';
939 result->filename = FP_strdup (bhds1); 1102 result->filename = _FP_strdup (bhds1);
940 bhnf = 1; 1103 bhnf = 1;
941 } 1104 }
942 else if (bhdsp-bhds2 >= 256 && bhds2[0]>0) { 1105 else if (bhdsp-bhds2 >= 256 && bhds2[0]>0) {
943 memcpy (bhds1, bhds2+1, 255); 1106 memcpy (bhds1, bhds2+1, 255);
944 bhds1[255] = '\0'; 1107 bhds1[255] = '\0';
945 result->filename = FP_strdup (bhds1); 1108 result->filename = _FP_strdup (bhds1);
946 bhnf = 1; 1109 bhnf = 1;
947 } 1110 }
948 else if (bhds2[0] <= 0) 1111 else if (bhds2[0] <= 0)
949 bhnf = 1; 1112 bhnf = 1;
950 } 1113 }
953 * We accept an encoding if it has been true for four consecutive 1116 * We accept an encoding if it has been true for four consecutive
954 * lines. Check the is<enc> arrays to avoid mistaking one encoding 1117 * lines. Check the is<enc> arrays to avoid mistaking one encoding
955 * for the other. Uuencoded data is rather easily mistaken for 1118 * for the other. Uuencoded data is rather easily mistaken for
956 * Base 64. If the data matches more than one encoding, we need to 1119 * Base 64. If the data matches more than one encoding, we need to
957 * scan further. 1120 * scan further.
1121 *
1122 * Since text can also rather easily be mistaken for UUencoded
1123 * data if it just happens to have 4 lines in a row that have the
1124 * correct first character for the length of the line, we also add
1125 * a check that the first 3 lines must be the same length, and the
1126 * 4th line must be less than or equal to that length. (since
1127 * uuencoders use the same length for all lines except the last,
1128 * this shouldn't increase the minimum size of UUdata we can
1129 * detect, as it would if we tested all 4 lines for being the same
1130 * length.) - Matthew Mueller, 20030109
958 */ 1131 */
959 1132
960 if (iscnt > 3) { 1133 if (iscnt > 3) {
961 cbb64 = (isb64[(iscnt-1)%10] && isb64[(iscnt-2)%10] && 1134 cbb64 = (isb64[(iscnt-1)%10] && isb64[(iscnt-2)%10] &&
962 isb64[(iscnt-3)%10] && isb64[(iscnt-4)%10]); 1135 isb64[(iscnt-3)%10] && isb64[(iscnt-4)%10]);
963 cbuue = (isuue[(iscnt-1)%10] && isuue[(iscnt-2)%10] && 1136 cbuue = (isuue[(iscnt-1)%10] && isuue[(iscnt-2)%10] &&
964 isuue[(iscnt-3)%10] && isuue[(iscnt-4)%10]); 1137 isuue[(iscnt-3)%10] && isuue[(iscnt-4)%10] &&
1138 islen[(iscnt-1)%10] <= islen[(iscnt-2)%10] &&
1139 islen[(iscnt-2)%10] == islen[(iscnt-3)%10] &&
1140 islen[(iscnt-3)%10] == islen[(iscnt-4)%10]);
965 cbxxe = (isxxe[(iscnt-1)%10] && isxxe[(iscnt-2)%10] && 1141 cbxxe = (isxxe[(iscnt-1)%10] && isxxe[(iscnt-2)%10] &&
966 isxxe[(iscnt-3)%10] && isxxe[(iscnt-4)%10]); 1142 isxxe[(iscnt-3)%10] && isxxe[(iscnt-4)%10] &&
1143 islen[(iscnt-1)%10] <= islen[(iscnt-2)%10] &&
1144 islen[(iscnt-2)%10] == islen[(iscnt-3)%10] &&
1145 islen[(iscnt-3)%10] == islen[(iscnt-4)%10]);
967 cbbhx = (isbhx[(iscnt-1)%10] && isbhx[(iscnt-2)%10] && 1146 cbbhx = (isbhx[(iscnt-1)%10] && isbhx[(iscnt-2)%10] &&
968 isbhx[(iscnt-3)%10] && isbhx[(iscnt-4)%10]); 1147 isbhx[(iscnt-3)%10] && isbhx[(iscnt-4)%10]);
969 } 1148 }
970 else { 1149 else {
971 cbb64 = cbuue = cbxxe = cbbhx = 0; 1150 cbb64 = cbuue = cbxxe = cbbhx = 0;
1015 *errcode = UURET_CANCEL; 1194 *errcode = UURET_CANCEL;
1016 break; 1195 break;
1017 } 1196 }
1018 1197
1019 oldposition = ftell (datei); 1198 oldposition = ftell (datei);
1020 if (FP_fgets (line, 255, datei) == NULL) 1199 if (_FP_fgets (line, 255, datei) == NULL)
1021 break; 1200 break;
1022 if (ferror (datei)) 1201 if (ferror (datei))
1023 break; 1202 break;
1024 1203
1025 line[255] = '\0'; 1204 line[255] = '\0';
1202 /* Base64 doesn't have begin or end */ 1381 /* Base64 doesn't have begin or end */
1203 if (result->uudet == B64ENCODED) 1382 if (result->uudet == B64ENCODED)
1204 result->begin = result->end = 0; 1383 result->begin = result->end = 0;
1205 1384
1206 /* Base64 and BinHex don't have a file mode */ 1385 /* Base64 and BinHex don't have a file mode */
1207 if (result->uudet == B64ENCODED || result->uudet == BH_ENCODED) 1386 if (result->uudet == B64ENCODED || result->uudet == BH_ENCODED ||
1387 result->uudet == YENC_ENCODED)
1208 result->mode = 6*64+4*8+4; 1388 result->mode = 6*64+4*8+4;
1209 1389
1210 /* 1390 /*
1211 * When strict MIME adherance is set, throw out suspicious attachments 1391 * When strict MIME adherance is set, throw out suspicious attachments
1212 */ 1392 */
1253 if (boundary && line[0] == '-' && line[1] == '-' && 1433 if (boundary && line[0] == '-' && line[1] == '-' &&
1254 strncmp (line+2, boundary, blen) == 0) 1434 strncmp (line+2, boundary, blen) == 0)
1255 return 2; 1435 return 2;
1256 else if (boundary && p3 && 1436 else if (boundary && p3 &&
1257 line[0] == 'C' && line[1] == 'o' && 1437 line[0] == 'C' && line[1] == 'o' &&
1258 FP_strnicmp (line, "Content-Type:", 13) == 0 && 1438 _FP_strnicmp (line, "Content-Type:", 13) == 0 &&
1259 strcmp (p3, boundary) == 0) 1439 strcmp (p3, boundary) == 0)
1260 return 2; 1440 return 2;
1261 else if (IsKnownHeader (line)) 1441 else if (IsKnownHeader (line))
1262 return 1; 1442 return 1;
1263 1443
1270 1450
1271fileread * 1451fileread *
1272ScanPart (FILE *datei, char *fname, int *errcode) 1452ScanPart (FILE *datei, char *fname, int *errcode)
1273{ 1453{
1274 int ecount, hcount, lcount; 1454 int ecount, hcount, lcount;
1275 int bhflag, begflag, vflag, blen, res; 1455 int bhflag, begflag, vflag, blen=0, res;
1276 long preheaders, prevpos, preenc, before; 1456 long preheaders, prevpos=0, preenc, before;
1277 char *line=uuscan_spline; 1457 char *line=uuscan_spline;
1278 fileread *result; 1458 fileread *result;
1279 char *ptr1, *ptr2; 1459 char *ptr1, *ptr2;
1280
1281 blen = 0; prevpos = 0; /* calm down gcc */
1282 1460
1283 (void) UUDecodeLine (NULL, NULL, 0); /* init */ 1461 (void) UUDecodeLine (NULL, NULL, 0); /* init */
1284 if (datei == NULL || feof (datei)) { 1462 if (datei == NULL || feof (datei)) {
1285 *errcode = UURET_OK; 1463 *errcode = UURET_OK;
1286 return NULL; 1464 return NULL;
1305 /* mimseqno = 1; */ 1483 /* mimseqno = 1; */
1306 1484
1307 while (mssdepth) { 1485 while (mssdepth) {
1308 mssdepth--; 1486 mssdepth--;
1309 UUkillheaders (&(multistack[mssdepth].envelope)); 1487 UUkillheaders (&(multistack[mssdepth].envelope));
1310 FP_free (multistack[mssdepth].source); 1488 _FP_free (multistack[mssdepth].source);
1311 } 1489 }
1312 1490
1313 UUkillheaders (&sstate.envelope); 1491 UUkillheaders (&sstate.envelope);
1314 memset (&sstate.envelope, 0, sizeof (headers)); 1492 memset (&sstate.envelope, 0, sizeof (headers));
1315 1493
1316 FP_free (sstate.source); 1494 _FP_free (sstate.source);
1317 if ((sstate.source = FP_strdup (fname)) == NULL) { 1495 if ((sstate.source = _FP_strdup (fname)) == NULL) {
1318 *errcode = UURET_NOMEM; 1496 *errcode = UURET_NOMEM;
1319 FP_free (result); 1497 _FP_free (result);
1320 return NULL; 1498 return NULL;
1321 } 1499 }
1322 1500
1323 /* ignore empty lines at the beginning of a file */ 1501 /* ignore empty lines at the beginning of a file */
1324 preheaders = ftell (datei); 1502 preheaders = ftell (datei);
1325 while (!feof (datei)) { 1503 while (!feof (datei)) {
1326 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 1504 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
1327 if (FP_fgets (line, 255, datei) == NULL) 1505 if (_FP_fgets (line, 255, datei) == NULL)
1328 break; 1506 break;
1507 line[255] = '\0';
1329 if (!IsLineEmpty (line)) { 1508 if (!IsLineEmpty (line)) {
1330 fseek (datei, preheaders, SEEK_SET); 1509 fseek (datei, preheaders, SEEK_SET);
1331 line[255] = '\0';
1332 break; 1510 break;
1333 } 1511 }
1334 preheaders = ftell (datei); 1512 preheaders = ftell (datei);
1335 } 1513 }
1336 } 1514 }
1337 1515
1338 if (ferror(datei) || feof(datei)) { 1516 if (ferror(datei) || feof(datei)) {
1339 FP_free (result); 1517 _FP_free (result);
1340 return NULL; 1518 return NULL;
1341 } 1519 }
1342 1520
1343 /* 1521 /*
1344 * If we are confident that this is a mail folder and are at the 1522 * If we are confident that this is a mail folder and are at the
1356 */ 1534 */
1357 1535
1358 while (mssdepth) { 1536 while (mssdepth) {
1359 mssdepth--; 1537 mssdepth--;
1360 UUkillheaders (&(multistack[mssdepth].envelope)); 1538 UUkillheaders (&(multistack[mssdepth].envelope));
1361 FP_free (multistack[mssdepth].source); 1539 _FP_free (multistack[mssdepth].source);
1362 } 1540 }
1363 1541
1542 prevpos = ftell (datei);
1364 if (FP_fgets (line, 255, datei) == NULL) { 1543 if (_FP_fgets (line, 255, datei) == NULL) {
1365 FP_free (result); 1544 _FP_free (result);
1366 return NULL; 1545 return NULL;
1367 } 1546 }
1368 line[255] = '\0'; 1547 line[255] = '\0';
1369 1548
1370 /* 1549 /*
1380 line[strlen(line)-1] == '\015') { 1559 line[strlen(line)-1] == '\015') {
1381 line[strlen(line)-1] = '\0'; 1560 line[strlen(line)-1] = '\0';
1382 } 1561 }
1383 1562
1384 sstate.ismime = 1; 1563 sstate.ismime = 1;
1385 sstate.envelope.mimevers = FP_strdup ("1.0"); 1564 sstate.envelope.mimevers = _FP_strdup ("1.0");
1386 sstate.envelope.boundary = FP_strdup (line+2); 1565 sstate.envelope.boundary = _FP_strdup (line+2);
1387 sstate.envelope.ctype = FP_strdup ("multipart/mixed"); 1566 sstate.envelope.ctype = _FP_strdup ("multipart/mixed");
1388 sstate.mimestate = MS_SUBPART; 1567 sstate.mimestate = MS_SUBPART;
1389 1568
1390 *errcode = UURET_CONT; 1569 *errcode = UURET_CONT;
1391 FP_free (result); 1570 _FP_free (result);
1392 return NULL; 1571 return NULL;
1393 } 1572 }
1394 1573
1395 /* 1574 /*
1396 * Normal behavior: look for a RFC 822 header 1575 * Normal behavior: look for a RFC 822 header
1398 1577
1399 while (!feof (datei) && !IsLineEmpty (line)) { 1578 while (!feof (datei) && !IsLineEmpty (line)) {
1400 if (IsKnownHeader (line)) 1579 if (IsKnownHeader (line))
1401 hcount++; 1580 hcount++;
1402 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 1581 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
1582 if (IsHeaderLine (line)) {
1403 ptr1 = ScanHeaderLine (datei, line); 1583 ptr1 = ScanHeaderLine (datei, line);
1404 if (ParseHeader (&sstate.envelope, ptr1) == NULL) { 1584 if (ParseHeader (&sstate.envelope, ptr1) == NULL) {
1405 *errcode = UURET_NOMEM; 1585 *errcode = UURET_NOMEM;
1406 FP_free (result); 1586 _FP_free (result);
1407 return NULL; 1587 return NULL;
1588 }
1408 } 1589 }
1409 /* 1590 /*
1410 * if we've read too many lines without finding headers, then 1591 * if we've read too many lines without finding headers, then
1411 * this probably isn't a mail folder after all 1592 * this probably isn't a mail folder after all
1412 */ 1593 */
1413 lcount++; 1594 lcount++;
1414 if (lcount > WAITHEADER && hcount < hlcount.afternl) 1595 if (lcount > WAITHEADER && hcount < hlcount.afternl) {
1596 fseek (datei, prevpos, SEEK_SET);
1597 line[0] = '\0';
1415 break; 1598 break;
1599 }
1416 1600
1417 if (FP_fgets (line, 255, datei) == NULL) 1601 if (_FP_fgets (line, 255, datei) == NULL)
1418 break; 1602 break;
1419 line[255] = '\0'; 1603 line[255] = '\0';
1420 } 1604 }
1605
1421 /* skip empty lines */ 1606 /* skip empty lines */
1422 prevpos = ftell (datei); 1607 prevpos = ftell (datei);
1608 if (IsLineEmpty (line)) {
1423 while (!feof (datei)) { 1609 while (!feof (datei)) {
1424 if (FP_fgets (line, 255, datei) == NULL) 1610 if (_FP_fgets (line, 255, datei) == NULL)
1425 break; 1611 break;
1426 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 1612 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
1427 if (!IsLineEmpty (line)) { 1613 if (!IsLineEmpty (line)) {
1428 fseek (datei, prevpos, SEEK_SET); 1614 fseek (datei, prevpos, SEEK_SET);
1429 line[255] = '\0'; 1615 line[255] = '\0';
1430 break; 1616 break;
1431 } 1617 }
1432 prevpos = ftell (datei); 1618 prevpos = ftell (datei);
1433 } 1619 }
1620 }
1621
1434 /* 1622 /*
1435 * If we don't have all valid MIME headers yet, but the following 1623 * If we don't have all valid MIME headers yet, but the following
1436 * line is a MIME header, accept it anyway. 1624 * line is a MIME header, accept it anyway.
1437 */ 1625 */
1438 1626
1442 sstate.envelope.ctenc == NULL && 1630 sstate.envelope.ctenc == NULL &&
1443 IsKnownHeader (line)) { 1631 IsKnownHeader (line)) {
1444 /* 1632 /*
1445 * see above 1633 * see above
1446 */ 1634 */
1447 if (FP_fgets (line, 255, datei) == NULL) { 1635 if (_FP_fgets (line, 255, datei) == NULL) {
1448 line[0] = '\012'; 1636 line[0] = '\012';
1449 line[1] = '\0'; 1637 line[1] = '\0';
1450 } 1638 }
1451 line[255] = '\0'; 1639 line[255] = '\0';
1452 1640
1455 hcount++; 1643 hcount++;
1456 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 1644 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
1457 ptr1 = ScanHeaderLine (datei, line); 1645 ptr1 = ScanHeaderLine (datei, line);
1458 if (ParseHeader (&sstate.envelope, ptr1) == NULL) { 1646 if (ParseHeader (&sstate.envelope, ptr1) == NULL) {
1459 *errcode = UURET_NOMEM; 1647 *errcode = UURET_NOMEM;
1460 FP_free (result); 1648 _FP_free (result);
1461 return NULL; 1649 return NULL;
1462 } 1650 }
1463
1464 if (FP_fgets (line, 255, datei) == NULL) 1651 if (_FP_fgets (line, 255, datei) == NULL)
1465 break; 1652 break;
1466 line[255] = '\0'; 1653 line[255] = '\0';
1467 } 1654 }
1468 /* skip empty lines */ 1655 /* skip empty lines */
1469 prevpos = ftell (datei); 1656 prevpos = ftell (datei);
1470 while (!feof (datei)) { 1657 while (!feof (datei)) {
1471 if (FP_fgets (line, 255, datei) == NULL) 1658 if (_FP_fgets (line, 255, datei) == NULL)
1472 break; 1659 break;
1473 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 1660 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
1474 if (!IsLineEmpty (line)) { 1661 if (!IsLineEmpty (line)) {
1475 fseek (datei, prevpos, SEEK_SET); 1662 fseek (datei, prevpos, SEEK_SET);
1476 line[255] = '\0'; 1663 line[255] = '\0';
1486 * MIME message 1673 * MIME message
1487 * if mimevers is not set but there are other well-known MIME 1674 * if mimevers is not set but there are other well-known MIME
1488 * headers, don't be too picky about it. 1675 * headers, don't be too picky about it.
1489 */ 1676 */
1490 if (sstate.envelope.ctype && sstate.envelope.mimevers==NULL && 1677 if (sstate.envelope.ctype && sstate.envelope.mimevers==NULL &&
1491 FP_stristr (sstate.envelope.ctype, "multipart") != NULL && 1678 _FP_stristr (sstate.envelope.ctype, "multipart") != NULL &&
1492 sstate.envelope.boundary != NULL) { 1679 sstate.envelope.boundary != NULL) {
1493 sstate.envelope.mimevers = FP_strdup ("1.0"); 1680 sstate.envelope.mimevers = _FP_strdup ("1.0");
1494 hcount = hlcount.afternl; 1681 hcount = hlcount.afternl;
1495 } 1682 }
1496 else if (sstate.envelope.mimevers==NULL && sstate.envelope.ctype && 1683 else if (sstate.envelope.mimevers==NULL && sstate.envelope.ctype &&
1497 sstate.envelope.fname && sstate.envelope.ctenc) { 1684 sstate.envelope.fname && sstate.envelope.ctenc) {
1498 sstate.envelope.mimevers = FP_strdup ("1.0"); 1685 sstate.envelope.mimevers = _FP_strdup ("1.0");
1499 hcount = hlcount.afternl; 1686 hcount = hlcount.afternl;
1500 } 1687 }
1501 1688
1502 if (hcount < hlcount.afternl) {
1503 /* not a folder after all */
1504 fseek (datei, preheaders, SEEK_SET);
1505 sstate.isfolder = 0;
1506 sstate.ismime = 0;
1507 }
1508 else if (sstate.envelope.mimevers != NULL) { 1689 if (sstate.envelope.mimevers != NULL) {
1509 /* this is a MIME file. check the Content-Type */ 1690 /* this is a MIME file. check the Content-Type */
1510 sstate.ismime = 1; 1691 sstate.ismime = 1;
1511 if (FP_stristr (sstate.envelope.ctype, "multipart") != NULL) { 1692 if (_FP_stristr (sstate.envelope.ctype, "multipart") != NULL) {
1512 if (sstate.envelope.boundary == NULL) { 1693 if (sstate.envelope.boundary == NULL) {
1513 UUMessage (uuscan_id, __LINE__, UUMSG_WARNING, 1694 UUMessage (uuscan_id, __LINE__, UUMSG_WARNING,
1514 uustring (S_MIME_NO_BOUNDARY)); 1695 uustring (S_MIME_NO_BOUNDARY));
1515 sstate.mimestate = MS_BODY; 1696 sstate.mimestate = MS_BODY;
1516 FP_free (sstate.envelope.ctype); 1697 _FP_free (sstate.envelope.ctype);
1517 sstate.envelope.ctype = FP_strdup ("text/plain"); 1698 sstate.envelope.ctype = _FP_strdup ("text/plain");
1518 } 1699 }
1519 else { 1700 else {
1520 sstate.mimestate = MS_PREAMBLE; 1701 sstate.mimestate = MS_PREAMBLE;
1521 } 1702 }
1522 } 1703 }
1523 else { 1704 else {
1524 sstate.mimestate = MS_BODY; /* just a `simple' message */ 1705 sstate.mimestate = MS_BODY; /* just a `simple' message */
1525 } 1706 }
1526 } 1707 }
1708 else {
1709 /* not a folder after all */
1710 fseek (datei, prevpos, SEEK_SET);
1711 sstate.isfolder = 0;
1712 sstate.ismime = 0;
1713 }
1527 } 1714 }
1528 1715
1529 if (feof (datei) || ferror (datei)) { /* oops */ 1716 if (feof (datei) || ferror (datei)) { /* oops */
1530 FP_free (result); 1717 _FP_free (result);
1531 return NULL; 1718 return NULL;
1532 } 1719 }
1533 1720
1534 /* 1721 /*
1535 * Handle MIME stuff 1722 * Handle MIME stuff
1547 1734
1548 blen = strlen (sstate.envelope.boundary); 1735 blen = strlen (sstate.envelope.boundary);
1549 lcount = 0; 1736 lcount = 0;
1550 1737
1551 while (!feof (datei)) { 1738 while (!feof (datei)) {
1552 if (FP_fgets (line, 255, datei) == NULL) { 1739 if (_FP_fgets (line, 255, datei) == NULL) {
1553 line[0] = '\0'; 1740 line[0] = '\0';
1554 break; 1741 break;
1555 } 1742 }
1556 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 1743 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
1557 if (line[0] == '-' && line[1] == '-' && 1744 if (line[0] == '-' && line[1] == '-' &&
1574 1761
1575 if (!uu_fast_scanning) { 1762 if (!uu_fast_scanning) {
1576 *errcode = UURET_CONT; 1763 *errcode = UURET_CONT;
1577 fseek (datei, preheaders, SEEK_SET); 1764 fseek (datei, preheaders, SEEK_SET);
1578 } 1765 }
1579 FP_free (result); 1766 _FP_free (result);
1580 return NULL; 1767 return NULL;
1581 } 1768 }
1582 if (line[0] == '-' && line[1] == '-' && 1769 if (line[0] == '-' && line[1] == '-' &&
1583 strncmp (line+2, sstate.envelope.boundary, blen) == 0) { 1770 strncmp (line+2, sstate.envelope.boundary, blen) == 0) {
1584 ptr1 = line + 2 + blen; 1771 ptr1 = line + 2 + blen;
1602 1789
1603 if (!uu_fast_scanning) { 1790 if (!uu_fast_scanning) {
1604 *errcode = UURET_CONT; 1791 *errcode = UURET_CONT;
1605 fseek (datei, preheaders, SEEK_SET); 1792 fseek (datei, preheaders, SEEK_SET);
1606 } 1793 }
1607 FP_free (result); 1794 _FP_free (result);
1608 return NULL; 1795 return NULL;
1609 } 1796 }
1610 /* produce result if uu_usepreamble is set */ 1797 /* produce result if uu_usepreamble is set */
1611 if (uu_usepreamble && lcount) { 1798 if (uu_usepreamble && lcount) {
1612 sprintf (line, "%04d.txt", ++mimseqno); 1799 sprintf (line, "%04d.txt", ++mimseqno);
1613 result->subject = FP_strdup (sstate.envelope.subject); 1800 result->subject = _FP_strdup (sstate.envelope.subject);
1614 result->filename = FP_strdup (line); 1801 result->filename = _FP_strdup (line);
1615 result->origin = FP_strdup (sstate.envelope.from); 1802 result->origin = _FP_strdup (sstate.envelope.from);
1616 result->mimeid = FP_strdup (sstate.envelope.mimeid); 1803 result->mimeid = _FP_strdup (sstate.envelope.mimeid);
1617 result->mimetype = FP_strdup ("text/plain"); 1804 result->mimetype = _FP_strdup ("text/plain");
1618 result->mode = 0644; 1805 result->mode = 0644;
1619 result->uudet = PT_ENCODED; /* plain text */ 1806 result->uudet = PT_ENCODED; /* plain text */
1620 result->sfname = FP_strdup (fname); 1807 result->sfname = _FP_strdup (fname);
1621 result->flags = FL_SINGLE | FL_PROPER; 1808 result->flags = FL_SINGLE | FL_PROPER;
1622 /* result->startpos set from above */ 1809 /* result->startpos set from above */
1623 result->length = prevpos - result->startpos; 1810 result->length = prevpos - result->startpos;
1624 result->partno = 1; 1811 result->partno = 1;
1625 1812
1636 /* MIME message, let's continue */ 1823 /* MIME message, let's continue */
1637 if (*errcode == UURET_OK) 1824 if (*errcode == UURET_OK)
1638 *errcode = UURET_CONT; 1825 *errcode = UURET_CONT;
1639 1826
1640 /* otherwise, just return NULL */ 1827 /* otherwise, just return NULL */
1641 FP_free (result); 1828 _FP_free (result);
1642 return NULL; 1829 return NULL;
1643 } 1830 }
1644 1831
1645 /* 1832 /*
1646 * Read Epilogue, the plain text after the last boundary. 1833 * Read Epilogue, the plain text after the last boundary.
1673 if (uu_fast_scanning && mssdepth == 0) { 1860 if (uu_fast_scanning && mssdepth == 0) {
1674 /* 1861 /*
1675 * check if the epilogue is empty 1862 * check if the epilogue is empty
1676 */ 1863 */
1677 while (!feof (datei) && !ferror (datei) && lcount<10 && res==0) { 1864 while (!feof (datei) && !ferror (datei) && lcount<10 && res==0) {
1678 if (FP_fgets (line, 255, datei) == NULL) 1865 if (_FP_fgets (line, 255, datei) == NULL)
1679 break; 1866 break;
1680 if (!IsLineEmpty (line)) 1867 if (!IsLineEmpty (line))
1681 res++; 1868 res++;
1682 lcount++; 1869 lcount++;
1683 } 1870 }
1684 if (uu_usepreamble && res) { 1871 if (uu_usepreamble && res) {
1685 sprintf (line, "%04d.txt", ++mimseqno); 1872 sprintf (line, "%04d.txt", ++mimseqno);
1686 result->subject = FP_strdup (sstate.envelope.subject); 1873 result->subject = _FP_strdup (sstate.envelope.subject);
1687 result->filename = FP_strdup (line); 1874 result->filename = _FP_strdup (line);
1688 result->origin = FP_strdup (sstate.envelope.from); 1875 result->origin = _FP_strdup (sstate.envelope.from);
1689 result->mimeid = FP_strdup (sstate.envelope.mimeid); 1876 result->mimeid = _FP_strdup (sstate.envelope.mimeid);
1690 result->mimetype = FP_strdup ("text/plain"); 1877 result->mimetype = _FP_strdup ("text/plain");
1691 result->mode = 0644; 1878 result->mode = 0644;
1692 result->uudet = PT_ENCODED; /* plain text */ 1879 result->uudet = PT_ENCODED; /* plain text */
1693 result->sfname = FP_strdup (fname); 1880 result->sfname = _FP_strdup (fname);
1694 result->flags = FL_SINGLE | FL_PROPER | FL_TOEND; 1881 result->flags = FL_SINGLE | FL_PROPER | FL_TOEND;
1695 result->partno = 1; 1882 result->partno = 1;
1696 /* result->startpos set from above */ 1883 /* result->startpos set from above */
1697 result->length = progress.fsize - result->startpos; 1884 result->length = progress.fsize - result->startpos;
1698 1885
1701 *errcode = UURET_NOMEM; 1888 *errcode = UURET_NOMEM;
1702 } 1889 }
1703 1890
1704 return result; 1891 return result;
1705 } 1892 }
1706 FP_free (result); 1893 _FP_free (result);
1707 return NULL; 1894 return NULL;
1708 } 1895 }
1709 1896
1710 if (mssdepth > 0) 1897 if (mssdepth > 0)
1711 blen = strlen (multistack[mssdepth-1].envelope.boundary); 1898 blen = strlen (multistack[mssdepth-1].envelope.boundary);
1712 1899
1713 while (!feof (datei)) { 1900 while (!feof (datei)) {
1714 if (FP_fgets (line, 255, datei) == NULL) { 1901 if (_FP_fgets (line, 255, datei) == NULL) {
1715 line[0] = '\0'; 1902 line[0] = '\0';
1716 break; 1903 break;
1717 } 1904 }
1718 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 1905 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
1719 line[255] = '\0'; 1906 line[255] = '\0';
1750 } 1937 }
1751 1938
1752 /* check for begin and encoded data only at outermost level */ 1939 /* check for begin and encoded data only at outermost level */
1753 if (mssdepth == 0 && !uu_more_mime) { 1940 if (mssdepth == 0 && !uu_more_mime) {
1754 if (strncmp (line, "begin ", 6) == 0 || 1941 if (strncmp (line, "begin ", 6) == 0 ||
1755 FP_strnicmp (line, "<pre>begin ", 11) == 0) { 1942 _FP_strnicmp (line, "<pre>begin ", 11) == 0) {
1756 preenc = prevpos; 1943 preenc = prevpos;
1757 begflag = 1; 1944 begflag = 1;
1758 } 1945 }
1759 else if (strncmp (line, "end", 3) == 0 && begflag) { 1946 else if (strncmp (line, "end", 3) == 0 && begflag) {
1760 ecount = ELC_COUNT; 1947 ecount = ELC_COUNT;
1793 strncmp (line+2, 1980 strncmp (line+2,
1794 multistack[mssdepth-1].envelope.boundary, blen) == 0) { 1981 multistack[mssdepth-1].envelope.boundary, blen) == 0) {
1795 /* restore previous state */ 1982 /* restore previous state */
1796 mssdepth--; 1983 mssdepth--;
1797 UUkillheaders (&sstate.envelope); 1984 UUkillheaders (&sstate.envelope);
1798 FP_free (sstate.source); 1985 _FP_free (sstate.source);
1799 memcpy (&sstate, &(multistack[mssdepth]), sizeof (scanstate)); 1986 memcpy (&sstate, &(multistack[mssdepth]), sizeof (scanstate));
1800 1987
1801 ptr1 = line + 2 + strlen (sstate.envelope.boundary); 1988 ptr1 = line + 2 + strlen (sstate.envelope.boundary);
1802 1989
1803 if (*ptr1 == '-' && *(ptr1+1) == '-') { 1990 if (*ptr1 == '-' && *(ptr1+1) == '-') {
1820 sstate.mimestate = MS_BODY; 2007 sstate.mimestate = MS_BODY;
1821 2008
1822 while (mssdepth) { 2009 while (mssdepth) {
1823 mssdepth--; 2010 mssdepth--;
1824 UUkillheaders (&(multistack[mssdepth].envelope)); 2011 UUkillheaders (&(multistack[mssdepth].envelope));
1825 FP_free (multistack[mssdepth].source); 2012 _FP_free (multistack[mssdepth].source);
1826 } 2013 }
1827 2014
1828 if (!uu_fast_scanning) { 2015 if (!uu_fast_scanning) {
1829 *errcode = UURET_CONT; 2016 *errcode = UURET_CONT;
1830 fseek (datei, preheaders, SEEK_SET); 2017 fseek (datei, preheaders, SEEK_SET);
1831 } 2018 }
1832 FP_free (result); 2019 _FP_free (result);
1833 return NULL; 2020 return NULL;
1834 } 2021 }
1835 else if (IsKnownHeader (line)) { 2022 else if (IsKnownHeader (line)) {
1836 /* new message follows */ 2023 /* new message follows */
1837 sstate.isfolder = 1; 2024 sstate.isfolder = 1;
1850 } 2037 }
1851 2038
1852 /* produce result if uu_usepreamble is set */ 2039 /* produce result if uu_usepreamble is set */
1853 if (uu_usepreamble && res) { 2040 if (uu_usepreamble && res) {
1854 sprintf (line, "%04d.txt", ++mimseqno); 2041 sprintf (line, "%04d.txt", ++mimseqno);
1855 result->subject = FP_strdup (sstate.envelope.subject); 2042 result->subject = _FP_strdup (sstate.envelope.subject);
1856 result->filename = FP_strdup (line); 2043 result->filename = _FP_strdup (line);
1857 result->origin = FP_strdup (sstate.envelope.from); 2044 result->origin = _FP_strdup (sstate.envelope.from);
1858 result->mimeid = FP_strdup (sstate.envelope.mimeid); 2045 result->mimeid = _FP_strdup (sstate.envelope.mimeid);
1859 result->mimetype = FP_strdup ("text/plain"); 2046 result->mimetype = _FP_strdup ("text/plain");
1860 result->mode = 0644; 2047 result->mode = 0644;
1861 result->uudet = PT_ENCODED; /* plain text */ 2048 result->uudet = PT_ENCODED; /* plain text */
1862 result->sfname = FP_strdup (fname); 2049 result->sfname = _FP_strdup (fname);
1863 result->flags = FL_SINGLE | FL_PROPER; 2050 result->flags = FL_SINGLE | FL_PROPER;
1864 result->partno = 1; 2051 result->partno = 1;
1865 /* result->startpos set from above */ 2052 /* result->startpos set from above */
1866 /* result->length set from above */ 2053 /* result->length set from above */
1867 2054
1871 } 2058 }
1872 2059
1873 return result; 2060 return result;
1874 } 2061 }
1875 /* otherwise, just return NULL */ 2062 /* otherwise, just return NULL */
1876 FP_free (result); 2063 _FP_free (result);
1877 return NULL; 2064 return NULL;
1878 } 2065 }
1879 2066
1880 /* 2067 /*
1881 * Scan a new part from a Multipart message. Check for a new local 2068 * Scan a new part from a Multipart message. Check for a new local
1895 2082
1896 /* 2083 /*
1897 * Duplicate some data from outer envelope 2084 * Duplicate some data from outer envelope
1898 */ 2085 */
1899 2086
1900 localenv.mimevers = FP_strdup (sstate.envelope.mimevers); 2087 localenv.mimevers = _FP_strdup (sstate.envelope.mimevers);
1901 localenv.from = FP_strdup (sstate.envelope.from); 2088 localenv.from = _FP_strdup (sstate.envelope.from);
1902 localenv.subject = FP_strdup (sstate.envelope.subject); 2089 localenv.subject = _FP_strdup (sstate.envelope.subject);
1903 localenv.rcpt = FP_strdup (sstate.envelope.rcpt); 2090 localenv.rcpt = _FP_strdup (sstate.envelope.rcpt);
1904 localenv.date = FP_strdup (sstate.envelope.date); 2091 localenv.date = _FP_strdup (sstate.envelope.date);
1905 2092
1906 if ((sstate.envelope.mimevers != NULL && localenv.mimevers == NULL) || 2093 if ((sstate.envelope.mimevers != NULL && localenv.mimevers == NULL) ||
1907 (sstate.envelope.from != NULL && localenv.from == NULL) || 2094 (sstate.envelope.from != NULL && localenv.from == NULL) ||
1908 (sstate.envelope.subject != NULL && localenv.subject == NULL) || 2095 (sstate.envelope.subject != NULL && localenv.subject == NULL) ||
1909 (sstate.envelope.rcpt != NULL && localenv.rcpt == NULL) || 2096 (sstate.envelope.rcpt != NULL && localenv.rcpt == NULL) ||
1910 (sstate.envelope.date != NULL && localenv.date == NULL)) { 2097 (sstate.envelope.date != NULL && localenv.date == NULL)) {
1911 2098
1912 while (mssdepth) { 2099 while (mssdepth) {
1913 mssdepth--; 2100 mssdepth--;
1914 UUkillheaders (&(multistack[mssdepth].envelope)); 2101 UUkillheaders (&(multistack[mssdepth].envelope));
1915 FP_free (multistack[mssdepth].source); 2102 _FP_free (multistack[mssdepth].source);
1916 } 2103 }
1917 sstate.isfolder = 0; 2104 sstate.isfolder = 0;
1918 sstate.ismime = 0; 2105 sstate.ismime = 0;
1919 2106
1920 UUkillheaders (&localenv); 2107 UUkillheaders (&localenv);
1921 *errcode = UURET_NOMEM; 2108 *errcode = UURET_NOMEM;
1922 FP_free (result); 2109 _FP_free (result);
1923 return NULL; 2110 return NULL;
1924 } 2111 }
1925 2112
1926 /* Scan subheader. But what if there is no subheader? */ 2113 /* Scan subheader. But what if there is no subheader? */
1927 hcount = 0; 2114 hcount = 0;
1928 lcount = 0; 2115 lcount = 0;
1929 preheaders = prevpos; 2116 preheaders = prevpos;
1930 2117
1931 if (FP_fgets (line, 255, datei) == NULL) { 2118 if (_FP_fgets (line, 255, datei) == NULL) {
1932 sstate.isfolder = 0; 2119 sstate.isfolder = 0;
1933 sstate.ismime = 0; 2120 sstate.ismime = 0;
1934 while (mssdepth) { 2121 while (mssdepth) {
1935 mssdepth--; 2122 mssdepth--;
1936 UUkillheaders (&(multistack[mssdepth].envelope)); 2123 UUkillheaders (&(multistack[mssdepth].envelope));
1937 FP_free (multistack[mssdepth].source); 2124 _FP_free (multistack[mssdepth].source);
1938 } 2125 }
1939 UUkillheaders (&localenv); 2126 UUkillheaders (&localenv);
1940 FP_free (result); 2127 _FP_free (result);
1941 return NULL; 2128 return NULL;
1942 } 2129 }
1943 line[255] = '\0'; 2130 line[255] = '\0';
1944 2131
1945 while (!feof (datei) && !IsLineEmpty (line)) { 2132 while (!feof (datei) && !IsLineEmpty (line)) {
1958 if (line[0] == '-' && line[1] == '-') 2145 if (line[0] == '-' && line[1] == '-')
1959 break; 2146 break;
1960 2147
1961 prevpos = ftell (datei); 2148 prevpos = ftell (datei);
1962 2149
1963 if (FP_fgets (line, 255, datei) == NULL) 2150 if (_FP_fgets (line, 255, datei) == NULL)
1964 break; 2151 break;
1965 line[255] = '\0'; 2152 line[255] = '\0';
1966 lcount++; 2153 lcount++;
1967 } 2154 }
1968 if (line[0] == '-' && line[1] == '-') { 2155 if (line[0] == '-' && line[1] == '-') {
1972 * boundary, so that it gets handled below 2159 * boundary, so that it gets handled below
1973 */ 2160 */
1974 fseek (datei, prevpos, SEEK_SET); 2161 fseek (datei, prevpos, SEEK_SET);
1975 } 2162 }
1976 2163
1977 if (FP_stristr (localenv.ctype, "multipart") != NULL) { 2164 if (_FP_stristr (localenv.ctype, "multipart") != NULL) {
1978 /* oh no, not again */ 2165 /* oh no, not again */
1979 if (mssdepth >= MSMAXDEPTH) { 2166 if (mssdepth >= MSMAXDEPTH) {
1980 /* Argh, what an isane message. Treat as plain text */ 2167 /* Argh, what an isane message. Treat as plain text */
1981 UUMessage (uuscan_id, __LINE__, UUMSG_WARNING, 2168 UUMessage (uuscan_id, __LINE__, UUMSG_WARNING,
1982 uustring (S_MIME_MULTI_DEPTH)); 2169 uustring (S_MIME_MULTI_DEPTH));
1988 else { 2175 else {
1989 memcpy (&multistack[mssdepth], &sstate, sizeof (scanstate)); 2176 memcpy (&multistack[mssdepth], &sstate, sizeof (scanstate));
1990 memcpy (&sstate.envelope, &localenv, sizeof (headers)); 2177 memcpy (&sstate.envelope, &localenv, sizeof (headers));
1991 memset (&localenv, 0, sizeof (headers)); 2178 memset (&localenv, 0, sizeof (headers));
1992 sstate.mimestate = MS_PREAMBLE; 2179 sstate.mimestate = MS_PREAMBLE;
1993 if ((sstate.source = FP_strdup (sstate.source)) == NULL) 2180 if ((sstate.source = _FP_strdup (sstate.source)) == NULL)
1994 *errcode = UURET_NOMEM; 2181 *errcode = UURET_NOMEM;
1995 2182
1996 if (*errcode == UURET_OK) 2183 if (*errcode == UURET_OK)
1997 *errcode = UURET_CONT; 2184 *errcode = UURET_CONT;
1998 2185
1999 mssdepth++; 2186 mssdepth++;
2000 /* need a restart */ 2187 /* need a restart */
2001 FP_free (result); 2188 _FP_free (result);
2002 return NULL; 2189 return NULL;
2003 } 2190 }
2004 } 2191 }
2192
2005 /* 2193 /*
2006 * So this subpart is either plain text or something else. Check 2194 * So this subpart is either plain text or something else. Check
2007 * the Content-Type and Content-Transfer-Encoding. If the latter 2195 * the Content-Type and Content-Transfer-Encoding. If the latter
2008 * is a defined value, we know what to do and just copy everything 2196 * is a defined value, we know what to do and just copy everything
2009 * up to the boundary. 2197 * up to the boundary.
2012 * message to our encoding detection. Otherwise, treat as plain 2200 * message to our encoding detection. Otherwise, treat as plain
2013 * text. 2201 * text.
2014 * This is done because users might `attach' a uuencoded file, which 2202 * This is done because users might `attach' a uuencoded file, which
2015 * would then be correctly typed as `text/plain'. 2203 * would then be correctly typed as `text/plain'.
2016 */ 2204 */
2205
2017 if (FP_stristr (localenv.ctenc, "base64") != NULL) 2206 if (_FP_stristr (localenv.ctenc, "base64") != NULL)
2018 result->uudet = B64ENCODED; 2207 result->uudet = B64ENCODED;
2019 else if (FP_stristr (localenv.ctenc, "x-uue") != NULL) 2208 else if (_FP_stristr (localenv.ctenc, "x-uue") != NULL) {
2020 result->uudet = UU_ENCODED; 2209 result->uudet = UU_ENCODED;
2210 result->begin = result->end = 1;
2211 }
2212 else if (_FP_stristr (localenv.ctenc, "x-yenc") != NULL) {
2213 result->uudet = YENC_ENCODED;
2214 result->begin = result->end = 1;
2215 }
2021 else if (FP_stristr (localenv.ctenc, "quoted-printable") != NULL) 2216 else if (_FP_stristr (localenv.ctenc, "quoted-printable") != NULL)
2022 result->uudet = QP_ENCODED; 2217 result->uudet = QP_ENCODED;
2023 else if (FP_stristr (localenv.ctenc, "7bit") != NULL || 2218 else if (_FP_stristr (localenv.ctenc, "7bit") != NULL ||
2024 FP_stristr (localenv.ctenc, "8bit") != NULL) 2219 _FP_stristr (localenv.ctenc, "8bit") != NULL)
2025 result->uudet = PT_ENCODED; 2220 result->uudet = PT_ENCODED;
2026 else if (FP_stristr (localenv.ctype, "multipart") != NULL || 2221 else if (_FP_stristr (localenv.ctype, "multipart") != NULL ||
2027 FP_stristr (localenv.ctype, "message") != NULL) 2222 _FP_stristr (localenv.ctype, "message") != NULL)
2028 result->uudet = PT_ENCODED; 2223 result->uudet = PT_ENCODED;
2029 2224
2030 /* 2225 /*
2031 * If we're switched to MIME-only mode, handle as text 2226 * If we're switched to MIME-only mode, handle as text
2032 */ 2227 */
2043 prevpos = ftell (datei); 2238 prevpos = ftell (datei);
2044 blen = strlen (sstate.envelope.boundary); 2239 blen = strlen (sstate.envelope.boundary);
2045 lcount = 0; 2240 lcount = 0;
2046 2241
2047 while (!feof (datei)) { 2242 while (!feof (datei)) {
2048 if (FP_fgets (line, 255, datei) == NULL) { 2243 if (_FP_fgets (line, 255, datei) == NULL) {
2049 line[0] = '\0'; 2244 line[0] = '\0';
2050 break; 2245 break;
2051 } 2246 }
2052 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 2247 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
2053 line[255] = '\0'; 2248 line[255] = '\0';
2062 * This check here doesn't cover folded header lines, but we don't 2257 * 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 2258 * want to slow down scanning too much. We just check for
2064 * Content-Type: multipart/... boundary="same-boundary" 2259 * Content-Type: multipart/... boundary="same-boundary"
2065 */ 2260 */
2066 if (line[0] == 'C' && line[1] == 'o' && 2261 if (line[0] == 'C' && line[1] == 'o' &&
2067 FP_strnicmp (line, "Content-Type:", 13) == 0) { 2262 _FP_strnicmp (line, "Content-Type:", 13) == 0) {
2068 ptr1 = ScanHeaderLine (datei, line); 2263 ptr1 = ScanHeaderLine (datei, line);
2069 ptr2 = (ptr1)?FP_stristr(ptr1,"boundary"):NULL; 2264 ptr2 = (ptr1)?_FP_stristr(ptr1,"boundary"):NULL;
2070 ptr1 = (ptr2)?ParseValue(ptr2):NULL; 2265 ptr1 = (ptr2)?ParseValue(ptr2):NULL;
2071 if (ptr1 && strcmp (ptr1, sstate.envelope.boundary) == 0) 2266 if (ptr1 && strcmp (ptr1, sstate.envelope.boundary) == 0)
2072 break; 2267 break;
2073 for (res=0; ptr1 && res<mssdepth; res++) 2268 for (res=0; ptr1 && res<mssdepth; res++)
2074 if (strcmp (ptr1, multistack[res].envelope.boundary) == 0) 2269 if (strcmp (ptr1, multistack[res].envelope.boundary) == 0)
2093 uustring (S_MIME_B_NOT_FOUND)); 2288 uustring (S_MIME_B_NOT_FOUND));
2094 2289
2095 while (mssdepth) { 2290 while (mssdepth) {
2096 mssdepth--; 2291 mssdepth--;
2097 UUkillheaders (&(multistack[mssdepth].envelope)); 2292 UUkillheaders (&(multistack[mssdepth].envelope));
2098 FP_free (multistack[mssdepth].source); 2293 _FP_free (multistack[mssdepth].source);
2099 } 2294 }
2100 /* 2295 /*
2101 * Don't retry if uu_fast_scanning 2296 * Don't retry if uu_fast_scanning
2102 */ 2297 */
2103 2298
2104 if (uu_fast_scanning) { 2299 if (uu_fast_scanning) {
2105 UUkillheaders (&localenv); 2300 UUkillheaders (&localenv);
2106 sstate.isfolder = 0; 2301 sstate.isfolder = 0;
2107 sstate.ismime = 0; 2302 sstate.ismime = 0;
2108 sstate.mimestate = MS_BODY; 2303 sstate.mimestate = MS_BODY;
2109 FP_free (result); 2304 _FP_free (result);
2110 return NULL; 2305 return NULL;
2111 } 2306 }
2112 2307
2113 /* 2308 /*
2114 * Retry, but listening to headers this time 2309 * Retry, but listening to headers this time
2148 } 2343 }
2149 /* produce result if uu_handletext is set */ 2344 /* produce result if uu_handletext is set */
2150 /* or if the file is explicitely named */ 2345 /* or if the file is explicitely named */
2151 if (result->uudet == B64ENCODED || lcount) { 2346 if (result->uudet == B64ENCODED || lcount) {
2152 if (localenv.fname) { 2347 if (localenv.fname) {
2153 FP_free (result->filename); 2348 _FP_free (result->filename);
2154 if ((result->filename = FP_strdup (localenv.fname)) == NULL) 2349 if ((result->filename = _FP_strdup (localenv.fname)) == NULL)
2155 *errcode = UURET_NOMEM; 2350 *errcode = UURET_NOMEM;
2156 } 2351 }
2157 else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) && 2352 else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) &&
2158 result->filename == NULL && uu_handletext) { 2353 result->filename == NULL && uu_handletext) {
2159 sprintf (line, "%04d.txt", ++mimseqno); 2354 sprintf (line, "%04d.txt", ++mimseqno);
2160 if ((result->filename = FP_strdup (line)) == NULL) 2355 if ((result->filename = _FP_strdup (line)) == NULL)
2161 *errcode = UURET_NOMEM; 2356 *errcode = UURET_NOMEM;
2162 } 2357 }
2163 result->subject = FP_strdup (localenv.subject); 2358 result->subject = _FP_strdup (localenv.subject);
2164 result->origin = FP_strdup (localenv.from); 2359 result->origin = _FP_strdup (localenv.from);
2165 result->mimeid = FP_strdup (localenv.mimeid); 2360 result->mimeid = _FP_strdup (localenv.mimeid);
2166 result->mimetype = FP_strdup (localenv.ctype); 2361 result->mimetype = _FP_strdup (localenv.ctype);
2167 result->mode = 0644; 2362 result->mode = 0644;
2168 result->sfname = FP_strdup (fname); 2363 result->sfname = _FP_strdup (fname);
2169 result->flags = FL_SINGLE | FL_PROPER; 2364 result->flags = FL_SINGLE | FL_PROPER;
2170 result->partno = 1; 2365 result->partno = 1;
2171 /* result->uudet determined above */ 2366 /* result->uudet determined above */
2172 /* result->startpos set from above */ 2367 /* result->startpos set from above */
2173 result->length = prevpos - result->startpos; 2368 result->length = prevpos - result->startpos;
2177 *errcode = UURET_NOMEM; 2372 *errcode = UURET_NOMEM;
2178 } 2373 }
2179 } 2374 }
2180 else { 2375 else {
2181 /* don't produce a result */ 2376 /* don't produce a result */
2182 FP_free (result); 2377 _FP_free (result);
2183 result = NULL; 2378 result = NULL;
2184 } 2379 }
2185 if (*errcode == UURET_OK) 2380 if (*errcode == UURET_OK)
2186 *errcode = UURET_CONT; 2381 *errcode = UURET_CONT;
2187 /* 2382 /*
2212 */ 2407 */
2213 blen = strlen (sstate.envelope.boundary); 2408 blen = strlen (sstate.envelope.boundary);
2214 prevpos = ftell (datei); 2409 prevpos = ftell (datei);
2215 2410
2216 while (!feof (datei)) { 2411 while (!feof (datei)) {
2217 if (FP_fgets (line, 255, datei) == NULL) { 2412 if (_FP_fgets (line, 255, datei) == NULL) {
2218 line[0] = '\0'; 2413 line[0] = '\0';
2219 break; 2414 break;
2220 } 2415 }
2221 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 2416 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
2222 line[255] = '\0'; 2417 line[255] = '\0';
2223 if (line[0] == '-' && line[1] == '-' && 2418 if (line[0] == '-' && line[1] == '-' &&
2224 strncmp (line+2, sstate.envelope.boundary, blen) == 0) 2419 strncmp (line+2, sstate.envelope.boundary, blen) == 0)
2225 break; 2420 break;
2226 if (line[0] == 'C' && line[1] == 'o' && 2421 if (line[0] == 'C' && line[1] == 'o' &&
2227 FP_strnicmp (line, "Content-Type:", 13) == 0) { 2422 _FP_strnicmp (line, "Content-Type:", 13) == 0) {
2228 ptr1 = ScanHeaderLine (datei, line); 2423 ptr1 = ScanHeaderLine (datei, line);
2229 ptr2 = (ptr1)?FP_stristr(ptr1,"boundary"):NULL; 2424 ptr2 = (ptr1)?_FP_stristr(ptr1,"boundary"):NULL;
2230 ptr1 = (ptr2)?ParseValue(ptr2):NULL; 2425 ptr1 = (ptr2)?ParseValue(ptr2):NULL;
2231 if (ptr1 && strcmp (ptr1, sstate.envelope.boundary) == 0) 2426 if (ptr1 && strcmp (ptr1, sstate.envelope.boundary) == 0)
2232 break; 2427 break;
2233 } 2428 }
2234 prevpos = ftell (datei); 2429 prevpos = ftell (datei);
2249 uustring (S_MIME_B_NOT_FOUND)); 2444 uustring (S_MIME_B_NOT_FOUND));
2250 2445
2251 while (mssdepth) { 2446 while (mssdepth) {
2252 mssdepth--; 2447 mssdepth--;
2253 UUkillheaders (&(multistack[mssdepth].envelope)); 2448 UUkillheaders (&(multistack[mssdepth].envelope));
2254 FP_free (multistack[mssdepth].source); 2449 _FP_free (multistack[mssdepth].source);
2255 } 2450 }
2256 2451
2257 if (uu_fast_scanning) { 2452 if (uu_fast_scanning) {
2258 UUkillheaders (&localenv); 2453 UUkillheaders (&localenv);
2259 sstate.isfolder = 0; 2454 sstate.isfolder = 0;
2260 sstate.ismime = 0; 2455 sstate.ismime = 0;
2261 sstate.mimestate = MS_BODY; 2456 sstate.mimestate = MS_BODY;
2262 FP_free (result); 2457 _FP_free (result);
2263 return NULL; 2458 return NULL;
2264 } 2459 }
2265 2460
2266 /* 2461 /*
2267 * Retry, listening to headers this time 2462 * Retry, listening to headers this time
2304 * If this file has been nicely MIME so far, then be very suspicious 2499 * 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 2500 * if ScanData reports anything else. So do a double check, and if
2306 * it doesn't hold up, handle as plain text instead. 2501 * it doesn't hold up, handle as plain text instead.
2307 */ 2502 */
2308 2503
2309 if (sstate.ismime && sstate.mimestate == MS_SUBPART &&
2310 strcmp (localenv.mimevers, "1.0") == 0 && 2504 if (strcmp (localenv.mimevers, "1.0") == 0 &&
2311 FP_stristr (localenv.ctype, "text") != NULL && 2505 _FP_stristr (localenv.ctype, "text") != NULL &&
2506 sstate.ismime && sstate.mimestate == MS_SUBPART &&
2312 !uu_desperate) { 2507 !uu_desperate) {
2313 if (result->uudet == UU_ENCODED && !(result->begin || result->end)) { 2508 if (result->uudet == UU_ENCODED && !(result->begin || result->end)) {
2314 result->uudet = 0; 2509 result->uudet = 0;
2315 } 2510 }
2316 } 2511 }
2322 if (result->uudet == 0) { 2517 if (result->uudet == 0) {
2323 result->uudet = PT_ENCODED; /* plain text */ 2518 result->uudet = PT_ENCODED; /* plain text */
2324 } 2519 }
2325 2520
2326 if (localenv.fname) { 2521 if (localenv.fname) {
2327 FP_free (result->filename); 2522 _FP_free (result->filename);
2328 if ((result->filename = FP_strdup (localenv.fname)) == NULL) 2523 if ((result->filename = _FP_strdup (localenv.fname)) == NULL)
2329 *errcode = UURET_NOMEM; 2524 *errcode = UURET_NOMEM;
2330 } 2525 }
2331 else if ((result->uudet==QP_ENCODED || result->uudet==PT_ENCODED) && 2526 else if ((result->uudet==QP_ENCODED || result->uudet==PT_ENCODED) &&
2332 result->filename==NULL && uu_handletext) { 2527 result->filename==NULL && uu_handletext) {
2333 sprintf (line, "%04d.txt", ++mimseqno); 2528 sprintf (line, "%04d.txt", ++mimseqno);
2334 if ((result->filename = FP_strdup (line)) == NULL) 2529 if ((result->filename = _FP_strdup (line)) == NULL)
2335 *errcode = UURET_NOMEM; 2530 *errcode = UURET_NOMEM;
2336 } 2531 }
2337 else { 2532 else {
2338 /* assign a filename lateron */ 2533 /* assign a filename lateron */
2339 } 2534 }
2340 if (result->mimetype) FP_free (result->mimetype); 2535 if (result->mimetype) _FP_free (result->mimetype);
2341 if (result->uudet) { 2536 if (result->uudet) {
2342 if (FP_stristr (localenv.ctype, "text") != NULL && 2537 if (_FP_stristr (localenv.ctype, "text") != NULL &&
2343 result->uudet != QP_ENCODED && result->uudet != PT_ENCODED) 2538 result->uudet != QP_ENCODED && result->uudet != PT_ENCODED)
2344 result->mimetype = NULL; /* better don't set it */ 2539 result->mimetype = NULL; /* better don't set it */
2345 else 2540 else
2346 result->mimetype = FP_strdup (localenv.ctype); 2541 result->mimetype = _FP_strdup (localenv.ctype);
2347 } 2542 }
2348 if (result->origin) FP_free (result->origin); 2543 if (result->origin) _FP_free (result->origin);
2349 result->origin = FP_strdup (localenv.from); 2544 result->origin = _FP_strdup (localenv.from);
2350 2545
2351 if (result->subject) FP_free (result->subject); 2546 if (result->subject) _FP_free (result->subject);
2352 result->subject = FP_strdup (localenv.subject); 2547 result->subject = _FP_strdup (localenv.subject);
2353 2548
2354 if (result->sfname == NULL) 2549 if (result->sfname == NULL)
2355 if ((result->sfname = FP_strdup (fname)) == NULL) 2550 if ((result->sfname = _FP_strdup (fname)) == NULL)
2356 *errcode = UURET_NOMEM; 2551 *errcode = UURET_NOMEM;
2357 2552
2358 result->length = prevpos - result->startpos; 2553 result->length = prevpos - result->startpos;
2359 result->flags = FL_SINGLE | FL_PROPER; 2554 result->flags = FL_SINGLE | FL_PROPER;
2360 result->partno = 1; 2555 result->partno = 1;
2382 * long to figure this out. But this might still be a MIME message 2577 * 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 2578 * body. And if it's a message/partial, we need more special handling
2384 */ 2579 */
2385 2580
2386 if (sstate.isfolder && sstate.ismime && sstate.mimestate == MS_BODY && 2581 if (sstate.isfolder && sstate.ismime && sstate.mimestate == MS_BODY &&
2387 FP_stristr (sstate.envelope.ctype, "message") != NULL && 2582 _FP_stristr (sstate.envelope.ctype, "message") != NULL &&
2388 FP_stristr (sstate.envelope.ctype, "partial") != NULL) { 2583 _FP_stristr (sstate.envelope.ctype, "partial") != NULL) {
2389 2584
2390 result->startpos = ftell (datei); 2585 result->startpos = ftell (datei);
2391 2586
2392 if (sstate.envelope.partno == 1) { 2587 if (sstate.envelope.partno == 1) {
2393 /* read local envelope */ 2588 /* read local envelope */
2395 memset (&localenv, 0, sizeof (headers)); 2590 memset (&localenv, 0, sizeof (headers));
2396 2591
2397 /* skip over blank lines first */ 2592 /* skip over blank lines first */
2398 prevpos = ftell (datei); 2593 prevpos = ftell (datei);
2399 while (!feof (datei)) { 2594 while (!feof (datei)) {
2400 if (FP_fgets (line, 255, datei) == NULL) 2595 if (_FP_fgets (line, 255, datei) == NULL)
2401 break; 2596 break;
2402 line[255] = '\0'; 2597 line[255] = '\0';
2403 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 2598 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
2404 if (!IsLineEmpty (line)) 2599 if (!IsLineEmpty (line))
2405 break; 2600 break;
2420 } 2615 }
2421 ptr1 = ScanHeaderLine (datei, line); 2616 ptr1 = ScanHeaderLine (datei, line);
2422 if (ParseHeader (&localenv, ptr1) == NULL) 2617 if (ParseHeader (&localenv, ptr1) == NULL)
2423 *errcode = UURET_NOMEM; 2618 *errcode = UURET_NOMEM;
2424 2619
2425 if (FP_fgets (line, 255, datei) == NULL) 2620 if (_FP_fgets (line, 255, datei) == NULL)
2426 break; 2621 break;
2427 line[255] = '\0'; 2622 line[255] = '\0';
2428 lcount++; 2623 lcount++;
2429 } 2624 }
2430 prevpos = ftell (datei); 2625 prevpos = ftell (datei);
2431 /* 2626 /*
2432 * Examine local header. We're mostly interested in the Content-Type 2627 * Examine local header. We're mostly interested in the Content-Type
2433 * and the Content-Transfer-Encoding. 2628 * and the Content-Transfer-Encoding.
2434 */ 2629 */
2435 if (FP_stristr (localenv.ctype, "multipart") != NULL) { 2630 if (_FP_stristr (localenv.ctype, "multipart") != NULL) {
2436 UUMessage (uuscan_id, __LINE__, UUMSG_WARNING, 2631 UUMessage (uuscan_id, __LINE__, UUMSG_WARNING,
2437 uustring (S_MIME_PART_MULTI)); 2632 uustring (S_MIME_PART_MULTI));
2438 } 2633 }
2439 if (localenv.subject) 2634 if (localenv.subject)
2440 result->subject = FP_strdup (localenv.subject); 2635 result->subject = _FP_strdup (localenv.subject);
2441 else 2636 else
2442 result->subject = FP_strdup (sstate.envelope.subject); 2637 result->subject = _FP_strdup (sstate.envelope.subject);
2443 2638
2444 if (localenv.from) 2639 if (localenv.from)
2445 result->origin = FP_strdup (localenv.from); 2640 result->origin = _FP_strdup (localenv.from);
2446 else 2641 else
2447 result->origin = FP_strdup (sstate.envelope.from); 2642 result->origin = _FP_strdup (sstate.envelope.from);
2448 2643
2449 if (localenv.ctype) 2644 if (localenv.ctype)
2450 result->mimetype = FP_strdup (localenv.ctype); 2645 result->mimetype = _FP_strdup (localenv.ctype);
2451 else 2646 else
2452 result->mimetype = FP_strdup ("text/plain"); 2647 result->mimetype = _FP_strdup ("text/plain");
2453 2648
2454 if (FP_stristr (localenv.ctenc, "quoted-printable") != NULL) 2649 if (_FP_stristr (localenv.ctenc, "quoted-printable") != NULL)
2455 result->uudet = QP_ENCODED; 2650 result->uudet = QP_ENCODED;
2456 else if (FP_stristr (localenv.ctenc, "base64") != NULL) 2651 else if (_FP_stristr (localenv.ctenc, "base64") != NULL)
2457 result->uudet = B64ENCODED; 2652 result->uudet = B64ENCODED;
2458 else if (FP_stristr (localenv.ctenc, "x-uue") != NULL) 2653 else if (_FP_stristr (localenv.ctenc, "x-uue") != NULL) {
2459 result->uudet = UU_ENCODED; 2654 result->uudet = UU_ENCODED;
2655 result->begin = result->end = 1;
2656 }
2657 else if (_FP_stristr (localenv.ctenc, "x-yenc") != NULL) {
2658 result->uudet = YENC_ENCODED;
2659 result->begin = result->end = 1;
2660 }
2460 else if (FP_stristr (localenv.ctenc, "7bit") != NULL || 2661 else if (_FP_stristr (localenv.ctenc, "7bit") != NULL ||
2461 FP_stristr (localenv.ctenc, "8bit") != NULL) 2662 _FP_stristr (localenv.ctenc, "8bit") != NULL)
2462 result->uudet = PT_ENCODED; 2663 result->uudet = PT_ENCODED;
2463 else if (FP_stristr (localenv.ctype, "multipart") != NULL || 2664 else if (_FP_stristr (localenv.ctype, "multipart") != NULL ||
2464 FP_stristr (localenv.ctype, "message") != NULL) 2665 _FP_stristr (localenv.ctype, "message") != NULL)
2465 result->uudet = PT_ENCODED; 2666 result->uudet = PT_ENCODED;
2466 2667
2467 /* 2668 /*
2468 * If we're switched to MIME-only mode, handle as text 2669 * If we're switched to MIME-only mode, handle as text
2469 */ 2670 */
2496 } 2697 }
2497 else if (result->uudet != 0) { 2698 else if (result->uudet != 0) {
2498 hcount = lcount = 0; 2699 hcount = lcount = 0;
2499 prevpos = ftell (datei); 2700 prevpos = ftell (datei);
2500 2701
2501 if (FP_stristr (localenv.ctype, "message") != NULL && 2702 if (_FP_stristr (localenv.ctype, "message") != NULL &&
2502 FP_stristr (localenv.ctype, "rfc822") != NULL) { 2703 _FP_stristr (localenv.ctype, "rfc822") != NULL) {
2503 /* 2704 /*
2504 * skip over empty lines and local header 2705 * skip over empty lines and local header
2505 */ 2706 */
2506 preheaders = ftell (datei); 2707 preheaders = ftell (datei);
2507 while (!feof (datei)) { 2708 while (!feof (datei)) {
2508 if (FP_fgets (line, 255, datei) == NULL) 2709 if (_FP_fgets (line, 255, datei) == NULL)
2509 break; 2710 break;
2510 line[255] = '\0'; 2711 line[255] = '\0';
2511 if (!IsLineEmpty (line)) { 2712 if (!IsLineEmpty (line)) {
2512 break; 2713 break;
2513 } 2714 }
2518 hcount++; 2719 hcount++;
2519 lcount++; 2720 lcount++;
2520 if (lcount > WAITHEADER && hcount < hlcount.afternl) 2721 if (lcount > WAITHEADER && hcount < hlcount.afternl)
2521 break; 2722 break;
2522 2723
2523 if (FP_fgets (line, 255, datei) == NULL) 2724 if (_FP_fgets (line, 255, datei) == NULL)
2524 break; 2725 break;
2525 line[255] = '\0'; 2726 line[255] = '\0';
2526 } 2727 }
2527 if (hcount < hlcount.afternl) 2728 if (hcount < hlcount.afternl)
2528 fseek (datei, preheaders, SEEK_SET); 2729 fseek (datei, preheaders, SEEK_SET);
2532 /* 2733 /*
2533 * look for next header 2734 * look for next header
2534 */ 2735 */
2535 2736
2536 while (!feof (datei)) { 2737 while (!feof (datei)) {
2537 if (FP_fgets (line, 255, datei) == NULL) 2738 if (_FP_fgets (line, 255, datei) == NULL)
2538 break; 2739 break;
2539 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 2740 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
2540 if (ferror (datei)) 2741 if (ferror (datei))
2541 break; 2742 break;
2542 line[255] = '\0'; 2743 line[255] = '\0';
2590 } 2791 }
2591 /* 2792 /*
2592 * produce result 2793 * produce result
2593 */ 2794 */
2594 if (localenv.fname) { 2795 if (localenv.fname) {
2595 FP_free (result->filename); 2796 _FP_free (result->filename);
2596 if ((result->filename = FP_strdup (localenv.fname)) == NULL) 2797 if ((result->filename = _FP_strdup (localenv.fname)) == NULL)
2597 *errcode = UURET_NOMEM; 2798 *errcode = UURET_NOMEM;
2598 } 2799 }
2599 else if (sstate.envelope.fname) { 2800 else if (sstate.envelope.fname) {
2600 FP_free (result->filename); 2801 _FP_free (result->filename);
2601 if ((result->filename = FP_strdup (sstate.envelope.fname)) == NULL) 2802 if ((result->filename = _FP_strdup (sstate.envelope.fname)) == NULL)
2602 *errcode = UURET_NOMEM; 2803 *errcode = UURET_NOMEM;
2603 } 2804 }
2604 else if ((result->uudet==QP_ENCODED || result->uudet==PT_ENCODED) && 2805 else if ((result->uudet==QP_ENCODED || result->uudet==PT_ENCODED) &&
2605 result->filename == NULL) { 2806 result->filename == NULL) {
2606 sprintf (line, "%04d.txt", ++mimseqno); 2807 sprintf (line, "%04d.txt", ++mimseqno);
2607 if ((result->filename = FP_strdup (line)) == NULL) 2808 if ((result->filename = _FP_strdup (line)) == NULL)
2608 *errcode = UURET_NOMEM; 2809 *errcode = UURET_NOMEM;
2609 } 2810 }
2610 else { 2811 else {
2611 /* assign a filename lateron */ 2812 /* assign a filename lateron */
2612 } 2813 }
2613 if (result->subject == NULL) { 2814 if (result->subject == NULL) {
2614 if (sstate.envelope.subject) 2815 if (sstate.envelope.subject)
2615 result->subject = FP_strdup (sstate.envelope.subject); 2816 result->subject = _FP_strdup (sstate.envelope.subject);
2616 } 2817 }
2617 result->partno = sstate.envelope.partno; 2818 result->partno = sstate.envelope.partno;
2618 result->maxpno = sstate.envelope.numparts; 2819 result->maxpno = sstate.envelope.numparts;
2619 result->flags = FL_PARTIAL | 2820 result->flags = FL_PARTIAL |
2620 ((res==1 || uu_fast_scanning) ? FL_PROPER : 0) | 2821 ((res==1 || uu_fast_scanning) ? FL_PROPER : 0) |
2621 ((uu_fast_scanning) ? FL_TOEND : 0); 2822 ((uu_fast_scanning) ? FL_TOEND : 0);
2622 result->mimeid = FP_strdup (sstate.envelope.mimeid); 2823 result->mimeid = _FP_strdup (sstate.envelope.mimeid);
2824 if (result->partno == 1)
2825 result->begin = 1;
2623 2826
2624 if (uu_fast_scanning) 2827 if (uu_fast_scanning)
2625 result->length = progress.fsize - result->startpos; 2828 result->length = progress.fsize - result->startpos;
2626 else 2829 else
2627 result->length = prevpos - result->startpos; 2830 result->length = prevpos - result->startpos;
2628 2831
2629 if (result->sfname == NULL) 2832 if (result->sfname == NULL)
2630 result->sfname = FP_strdup (fname); 2833 result->sfname = _FP_strdup (fname);
2631 2834
2632 if (result->mode == 0) 2835 if (result->mode == 0)
2633 result->mode = 0644; 2836 result->mode = 0644;
2634 2837
2635 /* 2838 /*
2666 * text/plain or a proper Content-Transfer-Encoding. 2869 * text/plain or a proper Content-Transfer-Encoding.
2667 * We also go in here if we have an assigned filename - this means 2870 * 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 2871 * that we've had a Content-Disposition field, and we should probably
2669 * decode a plain-text segment with a filename. 2872 * decode a plain-text segment with a filename.
2670 */ 2873 */
2874
2671 if (sstate.isfolder && sstate.ismime && 2875 if (sstate.isfolder && sstate.ismime &&
2672 sstate.mimestate == MS_BODY && 2876 sstate.mimestate == MS_BODY &&
2673 (FP_stristr (sstate.envelope.ctenc, "quoted-printable") != NULL || 2877 (_FP_stristr (sstate.envelope.ctenc, "quoted-printable") != NULL ||
2674 FP_stristr (sstate.envelope.ctenc, "base64") != NULL || 2878 _FP_stristr (sstate.envelope.ctenc, "base64") != NULL ||
2675 FP_stristr (sstate.envelope.ctenc, "x-uue") != NULL || 2879 _FP_stristr (sstate.envelope.ctenc, "x-uue") != NULL ||
2880 _FP_stristr (sstate.envelope.ctenc, "x-yenc") != NULL ||
2676 FP_stristr (sstate.envelope.ctype, "message") != NULL || 2881 _FP_stristr (sstate.envelope.ctype, "message") != NULL ||
2677 sstate.envelope.fname != NULL)) { 2882 sstate.envelope.fname != NULL)) {
2678 2883
2679 if (sstate.envelope.subject) 2884 if (sstate.envelope.subject)
2680 result->subject = FP_strdup (sstate.envelope.subject); 2885 result->subject = _FP_strdup (sstate.envelope.subject);
2681 if (sstate.envelope.from) 2886 if (sstate.envelope.from)
2682 result->origin = FP_strdup (sstate.envelope.from); 2887 result->origin = _FP_strdup (sstate.envelope.from);
2683 2888
2684 if (sstate.envelope.ctype) 2889 if (sstate.envelope.ctype)
2685 result->mimetype = FP_strdup (sstate.envelope.ctype); 2890 result->mimetype = _FP_strdup (sstate.envelope.ctype);
2686 else 2891 else
2687 result->mimetype = FP_strdup ("text/plain"); 2892 result->mimetype = _FP_strdup ("text/plain");
2688 2893
2689 if (FP_stristr (sstate.envelope.ctenc, "quoted-printable") != NULL) 2894 if (_FP_stristr (sstate.envelope.ctenc, "quoted-printable") != NULL)
2690 result->uudet = QP_ENCODED; 2895 result->uudet = QP_ENCODED;
2691 else if (FP_stristr (sstate.envelope.ctenc, "base64") != NULL) 2896 else if (_FP_stristr (sstate.envelope.ctenc, "base64") != NULL)
2692 result->uudet = B64ENCODED; 2897 result->uudet = B64ENCODED;
2693 else if (FP_stristr (sstate.envelope.ctenc, "x-uue") != NULL) 2898 else if (_FP_stristr (sstate.envelope.ctenc, "x-uue") != NULL) {
2694 result->uudet = UU_ENCODED; 2899 result->uudet = UU_ENCODED;
2900 result->begin = result->end = 1;
2901 }
2902 else if (_FP_stristr (sstate.envelope.ctenc, "x-yenc") != NULL) {
2903 result->uudet = YENC_ENCODED;
2904 }
2695 else if (FP_stristr (sstate.envelope.ctenc, "7bit") != NULL || 2905 else if (_FP_stristr (sstate.envelope.ctenc, "7bit") != NULL ||
2696 FP_stristr (sstate.envelope.ctenc, "8bit") != NULL) 2906 _FP_stristr (sstate.envelope.ctenc, "8bit") != NULL)
2697 result->uudet = PT_ENCODED; 2907 result->uudet = PT_ENCODED;
2698 else if (FP_stristr (sstate.envelope.ctype, "multipart") != NULL || 2908 else if (_FP_stristr (sstate.envelope.ctype, "multipart") != NULL ||
2699 FP_stristr (sstate.envelope.ctype, "message") != NULL || 2909 _FP_stristr (sstate.envelope.ctype, "message") != NULL ||
2700 sstate.envelope.fname != NULL) 2910 sstate.envelope.fname != NULL)
2701 result->uudet = PT_ENCODED; 2911 result->uudet = PT_ENCODED;
2702 2912
2703 /* 2913 /*
2704 * If we're switched to MIME-only mode, handle as text 2914 * If we're switched to MIME-only mode, handle as text
2707 if (uu_more_mime >= 2 && !result->uudet) { 2917 if (uu_more_mime >= 2 && !result->uudet) {
2708 result->uudet = PT_ENCODED; 2918 result->uudet = PT_ENCODED;
2709 } 2919 }
2710 2920
2711 result->startpos = prevpos = ftell (datei); 2921 result->startpos = prevpos = ftell (datei);
2712 2922
2713 /* 2923 /*
2714 * If this is Quoted-Printable or Plain Text, just try looking 2924 * If this is Quoted-Printable or Plain Text, just try looking
2715 * for the next message header. If uu_fast_scanning, we know 2925 * for the next message header. If uu_fast_scanning, we know
2716 * there won't be more headers. 2926 * there won't be more headers.
2717 * If it is a "trivial" (non-embedded) message/rfc822, skip over 2927 * If it is a "trivial" (non-embedded) message/rfc822, skip over
2723 } 2933 }
2724 else if (result->uudet != 0) { 2934 else if (result->uudet != 0) {
2725 hcount = lcount = 0; 2935 hcount = lcount = 0;
2726 prevpos = ftell (datei); 2936 prevpos = ftell (datei);
2727 2937
2728 if (FP_stristr (sstate.envelope.ctype, "message") != NULL && 2938 if (_FP_stristr (sstate.envelope.ctype, "message") != NULL &&
2729 FP_stristr (sstate.envelope.ctype, "rfc822") != NULL) { 2939 _FP_stristr (sstate.envelope.ctype, "rfc822") != NULL) {
2730 /* 2940 /*
2731 * skip over empty lines and local header 2941 * skip over empty lines and local header
2732 */ 2942 */
2733 preheaders = ftell (datei); 2943 preheaders = ftell (datei);
2734 while (!feof (datei)) { 2944 while (!feof (datei)) {
2735 if (FP_fgets (line, 255, datei) == NULL) 2945 if (_FP_fgets (line, 255, datei) == NULL)
2736 break; 2946 break;
2737 line[255] = '\0'; 2947 line[255] = '\0';
2738 if (!IsLineEmpty (line)) { 2948 if (!IsLineEmpty (line)) {
2739 break; 2949 break;
2740 } 2950 }
2745 hcount++; 2955 hcount++;
2746 lcount++; 2956 lcount++;
2747 if (lcount > WAITHEADER && hcount < hlcount.afternl) 2957 if (lcount > WAITHEADER && hcount < hlcount.afternl)
2748 break; 2958 break;
2749 2959
2750 if (FP_fgets (line, 255, datei) == NULL) 2960 if (_FP_fgets (line, 255, datei) == NULL)
2751 break; 2961 break;
2752 line[255] = '\0'; 2962 line[255] = '\0';
2753 } 2963 }
2754 if (hcount < hlcount.afternl) 2964 if (hcount < hlcount.afternl)
2755 fseek (datei, preheaders, SEEK_SET); 2965 fseek (datei, preheaders, SEEK_SET);
2759 /* 2969 /*
2760 * look for next header 2970 * look for next header
2761 */ 2971 */
2762 2972
2763 while (!feof (datei)) { 2973 while (!feof (datei)) {
2764 if (FP_fgets (line, 255, datei) == NULL) 2974 if (_FP_fgets (line, 255, datei) == NULL)
2765 break; 2975 break;
2766 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 2976 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
2767 if (ferror (datei)) 2977 if (ferror (datei))
2768 break; 2978 break;
2769 line[255] = '\0'; 2979 line[255] = '\0';
2815 } 3025 }
2816 /* 3026 /*
2817 * produce result 3027 * produce result
2818 */ 3028 */
2819 if (sstate.envelope.fname) { 3029 if (sstate.envelope.fname) {
2820 FP_free (result->filename); 3030 _FP_free (result->filename);
2821 if ((result->filename = FP_strdup (sstate.envelope.fname)) == NULL) 3031 if ((result->filename = _FP_strdup (sstate.envelope.fname)) == NULL)
2822 *errcode = UURET_NOMEM; 3032 *errcode = UURET_NOMEM;
2823 } 3033 }
2824 else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) && 3034 else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) &&
2825 result->filename == NULL) { 3035 result->filename == NULL) {
2826 sprintf (line, "%04d.txt", ++mimseqno); 3036 sprintf (line, "%04d.txt", ++mimseqno);
2827 if ((result->filename = FP_strdup (line)) == NULL) 3037 if ((result->filename = _FP_strdup (line)) == NULL)
2828 *errcode = UURET_NOMEM; 3038 *errcode = UURET_NOMEM;
2829 } 3039 }
2830 else { 3040 else {
2831 /* assign a filename lateron */ 3041 /* assign a filename lateron */
2832 } 3042 }
2833 if (result->subject == NULL) { 3043 if (result->subject == NULL) {
2834 if (sstate.envelope.subject) 3044 if (sstate.envelope.subject)
2835 result->subject = FP_strdup (sstate.envelope.subject); 3045 result->subject = _FP_strdup (sstate.envelope.subject);
2836 } 3046 }
2837 result->flags = ((res==1||uu_fast_scanning)?FL_PROPER:0) | 3047 result->flags = ((res==1||uu_fast_scanning)?FL_PROPER:0) |
2838 ((uu_fast_scanning) ? FL_TOEND : 0); 3048 ((uu_fast_scanning) ? FL_TOEND : 0);
2839 result->mimeid = FP_strdup (sstate.envelope.mimeid); 3049 result->mimeid = _FP_strdup (sstate.envelope.mimeid);
2840 3050
2841 if (uu_fast_scanning) 3051 if (uu_fast_scanning)
2842 result->length = progress.fsize - result->startpos; 3052 result->length = progress.fsize - result->startpos;
2843 else 3053 else
2844 result->length = prevpos - result->startpos; 3054 result->length = prevpos - result->startpos;
2845 3055
2846 if (result->sfname == NULL) 3056 if (result->sfname == NULL)
2847 result->sfname = FP_strdup (fname); 3057 result->sfname = _FP_strdup (fname);
2848 3058
2849 if (result->mode == 0) 3059 if (result->mode == 0)
2850 result->mode = 0644; 3060 result->mode = 0644;
2851 3061
2852 /* 3062 /*
2886 * we know that sstate.envelope.boundary is NULL, or we wouldn't 3096 * we know that sstate.envelope.boundary is NULL, or we wouldn't
2887 * be here! 3097 * be here!
2888 */ 3098 */
2889 3099
2890 if ((sstate.envelope.ctype == NULL || 3100 if ((sstate.envelope.ctype == NULL ||
2891 FP_stristr (sstate.envelope.ctype, "multipart") != NULL) && 3101 _FP_stristr (sstate.envelope.ctype, "multipart") != NULL) &&
2892 !uu_more_mime) { 3102 !uu_more_mime) {
2893 prevpos = ftell (datei); 3103 prevpos = ftell (datei);
2894 while (!feof (datei)) { 3104 while (!feof (datei)) {
2895 if (FP_fgets (line, 255, datei) == NULL) { 3105 if (_FP_fgets (line, 255, datei) == NULL) {
2896 line[0] = '\0'; 3106 line[0] = '\0';
2897 break; 3107 break;
2898 } 3108 }
2899 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL(); 3109 if (UUBUSYPOLL(ftell(datei),progress.fsize)) SPCANCEL();
2900 if (!IsLineEmpty (line)) 3110 if (!IsLineEmpty (line))
2901 break; 3111 break;
2902 } 3112 }
2903 if (line[0] == '-' && line[1] == '-' && 3113 if (line[0] == '-' && line[1] == '-' &&
2904 !IsLineEmpty (line+2) && !feof (datei)) { 3114 !IsLineEmpty (line+2) && !feof (datei)) {
2905 ptr1 = FP_strrstr (line+2, "--"); 3115 ptr1 = _FP_strrstr (line+2, "--");
2906 ptr2 = ScanHeaderLine (datei, NULL); 3116 ptr2 = ScanHeaderLine (datei, NULL);
2907 if ((ptr1 == NULL || (*(ptr1+2) != '\012' && *(ptr1+2) != '\015')) && 3117 if ((ptr1 == NULL || (*(ptr1+2) != '\012' && *(ptr1+2) != '\015')) &&
2908 ptr2 && FP_strnicmp (ptr2, "Content-", 8) == 0) { 3118 ptr2 && _FP_strnicmp (ptr2, "Content-", 8) == 0) {
2909 /* 3119 /*
2910 * hmm, okay, let's do it! 3120 * hmm, okay, let's do it!
2911 */ 3121 */
2912 sstate.isfolder = 1; 3122 sstate.isfolder = 1;
2913 sstate.ismime = 1; 3123 sstate.ismime = 1;
2917 */ 3127 */
2918 ptr1 = line+2; 3128 ptr1 = line+2;
2919 while (*ptr1 && !isspace(*ptr1)) 3129 while (*ptr1 && !isspace(*ptr1))
2920 ptr1++; 3130 ptr1++;
2921 *ptr1 = '\0'; 3131 *ptr1 = '\0';
2922 3132
2923 sstate.envelope.mimevers = FP_strdup ("1.0"); 3133 sstate.envelope.mimevers = _FP_strdup ("1.0");
2924 sstate.envelope.boundary = FP_strdup (line+2); 3134 sstate.envelope.boundary = _FP_strdup (line+2);
2925 3135
2926 /* 3136 /*
2927 * need restart 3137 * need restart
2928 */ 3138 */
2929 3139
2930 fseek (datei, prevpos, SEEK_SET); 3140 fseek (datei, prevpos, SEEK_SET);
2931 3141
2932 FP_free (result); 3142 _FP_free (result);
2933 return NULL; 3143 return NULL;
2934 } 3144 }
2935 } 3145 }
2936 fseek (datei, prevpos, SEEK_SET); 3146 fseek (datei, prevpos, SEEK_SET);
2937 } 3147 }
2941 * Freestyle time. Anyway, if this seems to be a Mime message, 3151 * Freestyle time. Anyway, if this seems to be a Mime message,
2942 * don't allow the minimal Base64 handling. 3152 * don't allow the minimal Base64 handling.
2943 */ 3153 */
2944 3154
2945 if (sstate.envelope.subject) 3155 if (sstate.envelope.subject)
2946 result->subject = FP_strdup (sstate.envelope.subject); 3156 result->subject = _FP_strdup (sstate.envelope.subject);
2947 if (sstate.envelope.from) 3157 if (sstate.envelope.from)
2948 result->origin = FP_strdup (sstate.envelope.from); 3158 result->origin = _FP_strdup (sstate.envelope.from);
2949 3159
2950 if (sstate.envelope.ctype) 3160 if (sstate.envelope.ctype)
2951 result->mimetype = FP_strdup (sstate.envelope.ctype); 3161 result->mimetype = _FP_strdup (sstate.envelope.ctype);
2952 3162
2953 if ((res=ScanData (datei, fname, errcode, NULL, 3163 if ((res=ScanData (datei, fname, errcode, NULL,
2954 sstate.ismime, 1, result))==-1) { 3164 sstate.ismime, 1, result))==-1) {
2955 /* oops, something went wrong */ 3165 /* oops, something went wrong */
2956 sstate.isfolder = 0; 3166 sstate.isfolder = 0;
2957 sstate.ismime = 0; 3167 sstate.ismime = 0;
2958 UUkillfread (result); 3168 UUkillfread (result);
2959 return NULL; 3169 return NULL;
2960 } 3170 }
3171
2961 /* 3172 /*
2962 * produce result 3173 * produce result
2963 */ 3174 */
3175
2964 if (result->uudet == 0 && uu_handletext) { 3176 if (result->uudet == 0 && uu_handletext) {
2965 result->startpos = before; /* display headers */ 3177 result->startpos = before; /* display headers */
2966 result->uudet = PT_ENCODED; 3178 result->uudet = PT_ENCODED;
2967 result->partno = 1; 3179 result->partno = 1;
2968 } 3180 }
2969 3181
3182 if (result->uudet == YENC_ENCODED && result->filename != NULL) {
3183 /*
3184 * prevent replacing the filename found on the =ybegin line
3185 */
3186 }
2970 if (sstate.envelope.fname) { 3187 else if (sstate.envelope.fname) {
2971 FP_free (result->filename); 3188 _FP_free (result->filename);
2972 if ((result->filename = FP_strdup (sstate.envelope.fname)) == NULL) 3189 if ((result->filename = _FP_strdup (sstate.envelope.fname)) == NULL)
2973 *errcode = UURET_NOMEM; 3190 *errcode = UURET_NOMEM;
2974 } 3191 }
2975 else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) && 3192 else if ((result->uudet==QP_ENCODED||result->uudet==PT_ENCODED) &&
2976 result->filename == NULL) { 3193 result->filename == NULL) {
2977 sprintf (line, "%04d.txt", ++mimseqno); 3194 sprintf (line, "%04d.txt", ++mimseqno);
2978 if ((result->filename = FP_strdup (line)) == NULL) 3195 if ((result->filename = _FP_strdup (line)) == NULL)
2979 *errcode = UURET_NOMEM; 3196 *errcode = UURET_NOMEM;
2980 } 3197 }
2981 else { 3198 else {
2982 /* assign a filename lateron */ 3199 /* assign a filename lateron */
2983 } 3200 }
3201
2984 if (result->subject == NULL) { 3202 if (result->subject == NULL) {
2985 if (sstate.envelope.subject) 3203 if (sstate.envelope.subject)
2986 result->subject = FP_strdup (sstate.envelope.subject); 3204 result->subject = _FP_strdup (sstate.envelope.subject);
2987 } 3205 }
2988 3206
2989 result->flags = (result->uudet==PT_ENCODED)?FL_SINGLE:0; 3207 result->flags = (result->uudet==PT_ENCODED)?FL_SINGLE:0;
2990 result->mimeid = FP_strdup (sstate.envelope.mimeid); 3208 result->mimeid = _FP_strdup (sstate.envelope.mimeid);
2991 result->length = ftell (datei) - result->startpos; 3209 result->length = ftell (datei) - result->startpos;
2992 3210
2993 if (result->mode == 0) 3211 if (result->mode == 0)
2994 result->mode = 0644; 3212 result->mode = 0644;
2995 3213
2996 if (result->sfname == NULL) 3214 if (result->sfname == NULL)
2997 result->sfname = FP_strdup (fname); 3215 result->sfname = _FP_strdup (fname);
2998 3216
2999 if (res == 1) { 3217 if (res == 1) {
3000 /* 3218 /*
3001 * new headers found 3219 * new headers found
3002 */ 3220 */
3025 UUkillheaders (&localenv); 3243 UUkillheaders (&localenv);
3026 3244
3027 while (mssdepth) { 3245 while (mssdepth) {
3028 mssdepth--; 3246 mssdepth--;
3029 UUkillheaders (&(multistack[mssdepth].envelope)); 3247 UUkillheaders (&(multistack[mssdepth].envelope));
3030 FP_free (multistack[mssdepth].source); 3248 _FP_free (multistack[mssdepth].source);
3031 } 3249 }
3032 3250
3033 return NULL; 3251 return NULL;
3034} 3252}
3035 3253

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines