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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines