-
Notifications
You must be signed in to change notification settings - Fork 1
/
import.c
2702 lines (2612 loc) · 82.1 KB
/
import.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
SoupGate Open-Source License
Copyright (c) 1999-2000 by Tom Torfs
The SoupGate software and its documentation may freely be distributed
and used for all purposes, provided no fee is charged other than to
cover administration and distribution costs, in other words it may
not be sold for profit.
The SoupGate software may freely be modified. Source code need
not be made available for modified versions or derived programs,
but if it is not, at least a copy of this license must be included
in the program or its documentation.
Modified source code may be made available, provided this license
remains included, intact and unmodified, and the fact that changes
were made must clearly be identified in both the source code and
documentation, and a reference must be provided as to where the
original, unmodified version can be obtained.
DISCLAIMER: THE AUTHOR EXCLUDES ANY AND ALL IMPLIED
WARRANTIES, INCLUDING WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE. THE AUTHOR
MAKES NO WARRANTY OR REPRESENTATION, EITHER EXPRESS
OR IMPLIED, WITH RESPECT TO THIS SOFTWARE, ITS
QUALITY, PERFORMANCE, MERCHANTABILITY, OR FITNESS
FOR A PARTICULAR PURPOSE. THE AUTHOR SHALL HAVE NO
LIABILITY FOR SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
DAMAGES ARISING OUT OF OR RESULTING FROM THE USE OR
MODIFICATION OF THIS SOFTWARE.
End of License
*/
/* SoupGate import functions */
#include "soupgate.h"
/*...sisseparator:0:*/
static int isseparator(int c)
{
return (c==',' || c==';' || c=='=');
}
/*...e*/
/*...sisrightsep:0:*/
static int isrightsep(int c)
{
return (c=='>' || c==')');
}
/*...e*/
/*...sisdelimiter:0:*/
static int isdelimiter(int c)
{
return (c=='\0' || c==' ' || c=='\t'
|| c=='<' || c=='>' || c=='(' || c==')');
}
/*...e*/
/*...sunescape:0:*/
static void unescape(char *s)
{
for (;*s!='\0'; s++)
{
if (*s=='\\')
{
memmove(s,s+1,strlen(s+1)+1);
if (*s==' ')
*s = (char)255;
}
}
}
/*...e*/
/*...sunfixed:0:*/
static void unfixed(char *s)
{
for (;*s!='\0'; s++)
{
if (*s==(char)255)
*s = ' ';
}
}
/*...e*/
/*...sunquote:0:*/
static void unquote(char *s)
{
int len = strlen(s);
/* remove quotes that are both left and right */
while (len>=2
&& s[0]==s[len-1]
&& (s[0]=='\"' || s[0]=='\''))
{
if (len<2)
break;
memmove(s,s+1,len);
len-=2;
s[len] = '\0';
}
}
/*...e*/
/*...sprocessemail:0:*/
static void processemail(char *s, char *addr, char *name, int type)
{
char *cp,*cp2,*ep,*np;
int len;
int inlevel,qlevel;
static char tempbuf[EMAILBUFSIZE];
int storename, first;
/* remove escaped characters */
unescape(s);
cp = s;
first = 1;
do
{
/* delimit current address */
inlevel = 0;
qlevel = 0;
for (cp2=cp; *cp2!=',' || inlevel!=0 || qlevel!=0; cp2++)
{
if (*cp2=='\0')
{
cp2 = NULL;
break;
}
if (*cp2=='\"' || *cp2=='\'')
qlevel = !qlevel;
else if (*cp2=='(' || *cp2=='<')
inlevel++;
else if (*cp2==')' || *cp2=='>')
inlevel--;
}
if (cp2!=NULL)
*(cp2++) = '\0';
storename = -1;
/* find at-sign of e-mail address */
ep = strchr(cp,'@');
if (ep!=NULL)
{
/* scan till left delimiter */
while (ep>cp)
{
if (isdelimiter(ep[-1]))
break;
ep--;
}
/* blank out left delimiter */
if (ep>cp)
ep[-1] = ' ';
/* copy until right delimiter & blank out */
len = 0;
while (!isdelimiter(*ep) && len<EMAILBUFSIZE-1)
{
tempbuf[len++] = *ep;
*(ep++) = ' ';
}
tempbuf[len] = '\0';
unquote(tempbuf);
unfixed(tempbuf);
/* primary address */
if (first && addr!=NULL)
{
strncpy(addr,tempbuf,EMAILBUFSIZE);
}
/* additional To & CC addresses */
else if ((type==EMAIL_TO || type==EMAIL_CC || type==EMAIL_BCC)
&& emaillistcount<MAXEMAIL)
{
emaillist[emaillistcount].type = type;
emaillist[emaillistcount].addr = malloc(strlen(tempbuf)+1);
if (emaillist[emaillistcount].addr!=NULL)
strcpy(emaillist[emaillistcount].addr,tempbuf);
emaillist[emaillistcount].name = NULL;
storename = emaillistcount;
emaillistcount++;
}
/* blank out right delimiter */
if (*ep!='\0')
*ep = ' ';
}
/* what's left must be the name */
np = NULL;
if (ep!=NULL)
{
/* find first non-blank character right of e-mail */
np = ep;
while (isspace(*np))
np++;
if (*np=='\0')
np = NULL;
}
if (np==NULL)
{
/* find first non-blank character from beginning */
np = cp;
while (isspace(*np))
np++;
if (*np=='\0')
np = NULL;
}
if (np!=NULL)
{
if (ep==NULL)
ep = cp + strlen(cp) - 1;
else if (np>ep)
{
/* name after email-address */
np = ep;
ep = cp + strlen(cp) - 1;
}
/* skip left whitespace & delimiter */
while (np<=ep && (isspace(*np) || isdelimiter(*np)))
np++;
/* skip right whitespace & delimiter */
while (ep>=np && (isspace(*ep) || isdelimiter(*ep)))
ep--;
if (np<=ep)
{
/* copy name */
len = ep - np + 1;
if (len >= EMAILBUFSIZE)
len = EMAILBUFSIZE - 1;
memcpy(tempbuf,np,len);
tempbuf[len] = '\0';
unquote(tempbuf);
unfixed(tempbuf);
if (first && name!=NULL)
strncpy(name,tempbuf,TEXTBUFSIZE);
if (storename!=-1)
{
emaillist[storename].name = malloc(strlen(tempbuf)+1);
if (emaillist[storename].name!=NULL)
strcpy(emaillist[storename].name,tempbuf);
}
}
}
cp = cp2;
first = 0;
}
while (cp!=NULL);
}
/*...e*/
/*...sprocessmsgid:0:*/
static void processmsgid(char *s, char *msgid, int rightmost)
{
char *cp;
int len;
/* remove escaped characters */
unescape(s);
/* find at-sign of last msgid address */
if (rightmost)
cp = strrchr(s,'@');
else
cp = strchr(s,'@');
if (cp!=NULL)
{
/* scan till left delimiter: white space, <, (, \" */
while (cp>s && cp[-1]!=' ' && cp[-1]!='\t' && cp[-1]!='<' && cp[-1]!='(' && cp[-1]!='\"')
cp--;
/* copy until right delimiter */
len = 0;
while (*cp!='\0' && *cp!=' ' && *cp!='\t' && *cp!='>' && *cp!=')' && *cp!='\"')
{
msgid[len++] = *cp;
cp++;
}
msgid[len] = '\0';
unfixed(msgid);
}
}
/*...e*/
/*...sprocesstext:0:*/
static void processtext(char *s, char *text)
{
char *ep;
int len;
/* skip left whitespace */
while (*s==' ' || *s=='\t')
s++;
/* skip right whitespace */
ep = s + strlen(s) - 1;
while (ep>=s && (*ep==' ' || *ep=='\t'))
ep--;
if (s<=ep)
{
/* copy text */
len = ep - s + 1;
if (len>=TEXTBUFSIZE)
len = TEXTBUFSIZE-1;
memcpy(text,s,len);
text[len] = '\0';
unfixed(text);
}
}
/*...e*/
/*...sprocessnewsgroups:0:*/
static void processnewsgroups(char *s, char *ngname)
{
static char name[TEXTBUFSIZE];
char *cp,*cp2;
cp = s;
for (;;)
{
cp2 = strchr(cp,',');
if (cp2!=NULL)
*cp2 = '\0';
processtext(cp,name);
if (stricmp(name,ngname)!=0 && xpostcount<MAXXPOST)
{
xpost[xpostcount] = malloc(strlen(name)+1);
if (xpost[xpostcount]!=NULL)
{
strcpy(xpost[xpostcount],name);
trim(xpost[xpostcount]);
xpostcount++;
}
}
if (cp2==NULL)
break;
*cp2 = ',';
cp = cp2+1;
}
}
/*...e*/
/*...sprocessdate:0:*/
static void processdate(char *s, TIMESTRUC *msgt, char *tzone)
{
char *cp,*cp2;
int i;
/* remove escaped characters */
unescape(s);
msgt->day = 1;
msgt->month = 0;
msgt->year = 1970;
msgt->hour = 0;
msgt->min = 0;
msgt->sec = 0;
/* skip day if present */
cp = strchr(s,',');
if (cp==NULL || cp<s+3 || cp>s+12)
cp = s;
else
cp++;
/* skip left whitespace */
while (*cp==' ' || *cp=='\t')
cp++;
/* scan day */
cp2 = cp;
while (*cp2!=' ' && *cp2!='\t' && *cp2!='\0')
cp2++;
if (*cp2=='\0')
return;
*(cp2++) = '\0';
while (*cp2==' ' || *cp2=='\t')
cp2++;
msgt->day = atoi(cp);
/* scan month */
cp = cp2;
while (*cp2!=' ' && *cp2!='\t' && *cp2!='\0')
cp2++;
if (*cp2=='\0')
return;
*(cp2++) = '\0';
while (*cp2==' ' || *cp2=='\t')
cp2++;
for (i=0; i<12; i++)
{
if (memicmp(cp,month[i],3)==0)
{
msgt->month = i;
break;
}
}
/* scan year */
cp = cp2;
while (*cp2!=' ' && *cp2!='\t' && *cp2!='\0')
cp2++;
if (*cp2=='\0')
return;
*(cp2++) = '\0';
while (*cp2==' ' || *cp2=='\t')
cp2++;
msgt->year = atoi(cp);
if (msgt->year>=70 && msgt->year<=99)
msgt->year += 1900;
else if (msgt->year<70)
msgt->year += 2000;
/* scan time */
cp = cp2;
while (*cp2!=' ' && *cp2!='\t' && *cp2!='\0')
cp2++;
if (*cp2!='\0')
{
*(cp2++) = '\0';
while (*cp2==' ' || *cp2=='\t')
cp2++;
}
sscanf(cp,"%hu:%hu:%hu",&msgt->hour,&msgt->min,&msgt->sec);
/* scan timezone */
if (tzone!=NULL)
strncpy(tzone, cp2, TEXTBUFSIZE);
}
/*...e*/
/*...sismapdomain:0:*/
static int ismapdomain(char *cp)
{
int i,len,clen;
len = strlen(cp);
if (len>=12
&& stricmp(cp+len-12, ".fidonet.org")==0)
return 1;
for (i=0; i<fidodomains; i++)
{
if (fidodomain[i].domain[0]!='#')
continue;
clen = strlen(fidodomain[i].domain);
if (clen<=len
&& cp[len-clen]=='.'
&& stricmp(cp+(len-clen+1), fidodomain[i].domain+1)==0)
return 1;
}
return 0;
}
/*...e*/
/*...sprocessimport:0:*/
/* isjunk may be set to JUNK_STR if it is initially NO_JUNK
in non-copy mode */
static void processimport(int copy, int filesonly, int msgcategory,
int isownorg, int *isjunk,
char *truncate, char *truncend,
FILE *fp, FILE *fpkt,
long msgpos, long endpos, long *bodypos,
char *linebuf, char *filebuf)
{
/*...svariables:0:*/
static char fname[FILENAME_MAX]; /* must keep filename(s) */
char decfpath[FILENAME_MAX], *decfname;
int frenamed;
char boundary[TEXTBUFSIZE];
char buffer[BUFSIZE];
FILE *fdec;
char *cp,*cp2;
int buflen,maxlen;
unsigned attr;
int i,j,cc,bcc,len,numid;
int emptylines,notallempty;
int pasttrunc;
int inbody;
int qptrans;
int nextmimedata,nextmimename;
int decodefile,dofile;
int linebytes;
int b1,b2,b3,b4;
int filebuflen,writelen;
long fpos;
unsigned long decodebytes;
int ch;
int insertline;
int pastqchars, inquote;
int pastat;
int dowhite;
int strip;
static int alreadyfromto, pastfirstline;
/*...e*/
/*...sinitialize:0:*/
/* seek to start of message */
fseek(fp,msgpos,SEEK_SET);
if (copy)
{
partno = 1;
/* write message header */
if (!filesonly)
writepktmsgheader(msgcategory, fpkt, fname, *isjunk, isownorg);
}
else
{
parts = 1;
msgfromemail[0] = '\0';
msgfromname[0] = '\0';
msgtoemail[0] = '\0';
msgtoname[0] = '\0';
msgreplyemail[0] = '\0';
msgreplyname[0] = '\0';
xfrom[0] = '\0';
sender[0] = '\0';
quotename[0] = '\0';
quoteemail[0] = '\0';
msgsubj[0] = '\0';
msgorganization[0] = '\0';
msgid[0] = '\0';
replyid[0] = '\0';
routemailpwd[0] = '\0';
routemailsubj[0] = '\0';
rfccharset[0] = '\0';
mimetype[0] = '\0';
mimecte[0] = '\0';
tzinfo[0] = '\0';
emaillistcount = 0;
pastqchars = 0;
inquote = 0;
*bodypos = msgpos;
xpostcount = 0;
alreadyfromto = 0;
}
partbytes = 0;
isfattach = 0;
qptrans = 0;
nextmimedata = 0;
nextmimename = 0;
decodefile = ENCODE_NONE;
fdec = NULL;
decfpath[0] = '\0';
decfname = decfpath;
frenamed = 0;
fname[0] = '\0';
boundary[0] = '\0';
filebuflen = 0;
emptylines = 0;
inbody = 0;
insertline = 0;
pasttrunc = 0;
pastfirstline = 0;
/*...e*/
for (;;)
{
/*...sinsert line:0:*/
fpos = ftell(fp);
if (fpos>=endpos)
{
if (*bodypos==msgpos)
*bodypos = endpos;
break;
}
if (copy && !filesonly && (insertline==1))
{
insertline++; /* avoids duplicates */
dowhite = 0;
if (xpostcount>0)
{
for (i=0; i<xpostcount; i++)
{
if (i%3==0)
{
if (i>0)
fprintf(fpkt,"\r");
fprintf(fpkt,"XPost: ");
}
else
fprintf(fpkt,", ");
fprintf(fpkt,"%s",xpost[i]);
free(xpost[i]);
}
fprintf(fpkt,"\r");
dowhite = 1;
}
if (!alreadyfromto)
{
switch(infoinsert)
{
case INFO_EMAIL:
if (msgfromemail[0]!='\0' && stricmp(msgfromemail,msgfromname)!=0)
{
fprintf(fpkt,"From: %s\r", msgfromemail);
dowhite = 1;
}
if (msgtype==EMAIL
&& msgtoemail[0]!='\0' && stricmp(msgtoemail,msgtoname)!=0)
{
fprintf(fpkt,"To: %s\r", msgtoemail);
dowhite = 1;
}
break;
case INFO_NAME:
if (msgfromname[0]!='\0' && stricmp(msgfromname,msgfromemail)!=0)
{
fprintf(fpkt,"From: %s\r", msgfromname);
dowhite = 1;
}
if (msgtype==EMAIL
&& msgtoname[0]!='\0' && stricmp(msgtoname,msgtoemail)!=0)
{
fprintf(fpkt,"To: %s\r", msgtoname);
dowhite = 1;
}
break;
}
}
cc = 0;
bcc = 0;
for (i=0; i<emaillistcount; i++)
{
if (emaillist[i].type!=EMAIL_TO)
{
if (emaillist[i].type==EMAIL_BCC)
bcc = 1;
else
cc = 1;
continue;
}
if (emaillist[i].addr!=NULL)
{
fprintf(fpkt,"To: %s",emaillist[i].addr);
free(emaillist[i].addr);
}
if (emaillist[i].name!=NULL)
{
fprintf(fpkt," (%s)",emaillist[i].name);
free(emaillist[i].name);
}
fprintf(fpkt,"\r");
}
if (cc)
{
for (i=0; i<emaillistcount; i++)
{
if (emaillist[i].type!=EMAIL_CC)
continue;
if (emaillist[i].addr!=NULL)
{
fprintf(fpkt,"Copy: %s",emaillist[i].addr);
free(emaillist[i].addr);
}
if (emaillist[i].name!=NULL)
{
fprintf(fpkt," (%s)",emaillist[i].name);
free(emaillist[i].name);
}
fprintf(fpkt,"\r");
}
}
if (bcc)
{
for (i=0; i<emaillistcount; i++)
{
if (emaillist[i].type!=EMAIL_BCC)
continue;
if (emaillist[i].addr!=NULL)
{
fprintf(fpkt,"BCopy: %s",emaillist[i].addr);
free(emaillist[i].addr);
}
if (emaillist[i].name!=NULL)
{
fprintf(fpkt," (%s)",emaillist[i].name);
free(emaillist[i].name);
}
fprintf(fpkt,"\r");
}
}
if (emaillistcount>0)
dowhite = 1;
if (routepwdfailed)
{
fprintf(fpkt,"*** Incorrect SoupGate Route-password ");
fprintf(fpkt,"for node %u:%u/%u",
route[routeno]->fido.zone,
route[routeno]->fido.net,
route[routeno]->fido.node);
if (route[routeno]->fido.point>0)
fprintf(fpkt,".%u",route[routeno]->fido.point);
fprintf(fpkt," ***\r");
dowhite = 1;
}
if (msgtype==EMAIL && isfattach && fncmp(msgsubj,fname)!=0)
{
fprintf(fpkt,"Subject: %s\r",msgsubj);
dowhite = 1;
}
if (dowhite)
fprintf(fpkt,"\r");
}
/*...e*/
/*...sread line:0:*/
if (inbody)
{
buflen = 0;
for (;;)
{
fgets(linebuf+buflen,LINEBUFSIZE-buflen,fp);
if (feof(fp))
break;
buflen += strlen(linebuf+buflen);
if (decodefile==ENCODE_UU)
{
if (linebuf[buflen-1]=='\n')
buflen--;
}
else
{
while (buflen>0
&& (linebuf[buflen-1]=='\n' || linebuf[buflen-1]==' '))
buflen--;
}
if (qptrans && buflen>0 && linebuf[buflen-1]=='=')
buflen--;
else
break;
}
linebuf[buflen] = '\0';
if (feof(fp) && buflen==0)
break;
}
else
{
buflen = 0;
do
{
fgets(linebuf+buflen,LINEBUFSIZE-buflen,fp);
if (feof(fp))
break;
buflen += strlen(linebuf+buflen);
if (linebuf[buflen-1]=='\n')
buflen--;
if (buflen==0)
break;
ch = fgetc(fp);
ungetc(ch,fp);
}
while (ch!=EOF && ch!='\r' && ch!='\n' && isspace(ch));
/* strip excess whitespace */
for (i=0; i<buflen;)
{
if (isspace(linebuf[i]))
{
if (isspace(linebuf[i-1]) || i==0)
{
memmove(linebuf+i, linebuf+i+1, buflen-i);
buflen--;
}
else
{
linebuf[i] = ' ';
i++;
}
}
else
i++;
}
while (buflen>0 && isspace(linebuf[buflen-1]))
buflen--;
linebuf[buflen] = '\0';
}
/*...e*/
/*...spassword\47\boundary\47\quoted\45\printable:0:*/
if (pasttrunc)
{
if (truncend!=NULL && strstr(linebuf, truncend) != NULL)
pasttrunc = 0;
continue;
}
if (copy
&& !inbody
&& memicmp(linebuf,"X-MailPassword:",15)==0)
continue;
if (inbody
&& boundary[0]!='\0'
&& memcmp(linebuf,"--",2)==0
&& memcmp(linebuf+2,boundary,strlen(boundary))==0)
{
if (decodefile!=ENCODE_NONE && copy)
{
writefileinfo(decfpath,decfname,frenamed,
decodefile,dofile,decodebytes,
filesonly,fpkt);
if (fdec!=NULL)
{
if (filebuflen>0)
fwrite(filebuf,1,filebuflen,fdec);
fclose(fdec);
fdec = NULL;
}
}
decodefile = ENCODE_NONE;
inbody = 0;
qptrans = 0;
nextmimedata = 0;
nextmimename = 0;
if (memcmp(linebuf+2+strlen(boundary),"--",2)==0)
break;
else
continue;
}
if (qptrans && inbody)
{
for (cp=linebuf; *cp!='\0'; cp++)
{
if (cp[0]=='=' && isxdigit(cp[1]) && isxdigit(cp[2]))
{
cp[0] = hexbyte(cp+1);
if (cp[0]=='\0')
cp[0] = ' ';
memmove(cp+1,cp+3,strlen(cp+3)+1);
buflen -= 2;
}
}
}
/*...e*/
/*...sdecode MIME:0:*/
if (decodefile==ENCODE_MIME && dofile!=ATTACH_IGNORE)
{
if (mimevalue(linebuf[0])!=-1)
{
if (copy)
{
linebytes = 0;
for (i=0; linebuf[i]!='\0'; i++)
{
if (mimevalue(linebuf[i])!=-1)
linebytes++;
}
linebytes = (linebytes*3)/4;
decodebytes += linebytes;
if (fdec!=NULL)
{
cp = linebuf;
while (linebytes>0)
{
if (filebuflen>=512-3)
{
fwrite(filebuf,1,filebuflen,fdec);
filebuflen = 0;
}
b1 = mimevalue(*(cp++));
b2 = mimevalue(*(cp++));
b3 = mimevalue(*(cp++));
b4 = mimevalue(*(cp++));
if (linebytes-->0 && b1!=-1 && b2!=-1)
filebuf[filebuflen++] = (b1<<2)|(b2>>4);
if (linebytes-->0 && b2!=-1 && b3!=-1)
filebuf[filebuflen++] = (b2<<4)|(b3>>2);
if (linebytes-->0 && b3!=-1 && b4!=-1)
filebuf[filebuflen++] = (b3<<6)|(b4);
}
}
}
if (memcmp(linebuf+buflen-2,"==",2)==0)
{
if (copy)
{
writefileinfo(decfpath,decfname,frenamed,
decodefile,dofile,decodebytes,
filesonly,fpkt);
if (fdec!=NULL)
{
if (filebuflen>0)
fwrite(filebuf,1,filebuflen,fdec);
fclose(fdec);
fdec = NULL;
decfpath[0] = '\0';
}
}
decodefile = ENCODE_NONE;
}
continue;
}
else
{
if (copy)
{
writefileinfo(decfpath,decfname,frenamed,
decodefile,dofile,decodebytes,
filesonly,fpkt);
if (fdec!=NULL)
{
if (filebuflen>0)
fwrite(filebuf,1,filebuflen,fdec);
fclose(fdec);
fdec = NULL;
decfpath[0] = '\0';
}
}
decodefile = ENCODE_NONE;
}
}
/*...e*/
/*...sdecode UU:0:*/
else if (decodefile==ENCODE_UU && dofile!=ATTACH_IGNORE)
{
if (linebuf[0]>=33 && linebuf[0]<=96
&& (linebytes = (linebuf[0]-32)&077)
<= (strlen(linebuf)-1) * 3 / 4)
{
if (copy)
{
decodebytes += linebytes;
if (fdec!=NULL)
{
cp = linebuf + 1;
while (linebytes>0)
{
if (filebuflen>=512-3)
{
fwrite(filebuf,1,filebuflen,fdec);
filebuflen = 0;
}
b1 = (*(cp++)-32)&077;
b2 = (*(cp++)-32)&077;
b3 = (*(cp++)-32)&077;
b4 = (*(cp++)-32)&077;
if (linebytes-->0)
filebuf[filebuflen++] = (b1<<2)|(b2>>4);
if (linebytes-->0)
filebuf[filebuflen++] = (b2<<4)|(b3>>2);
if (linebytes-->0)
filebuf[filebuflen++] = (b3<<6)|(b4);
}
}
}
continue;
}
else
{
if (copy)
{
writefileinfo(decfpath,decfname,frenamed,
decodefile,dofile,decodebytes,
filesonly,fpkt);
if (fdec!=NULL)
{
if (filebuflen>0)
fwrite(filebuf,1,filebuflen,fdec);
fclose(fdec);
fdec = NULL;
decfpath[0] = '\0';
}
}
decodefile = ENCODE_NONE;
}
if (stricmp(linebuf,"end")==0)
continue;
}
/*...e*/
/*...sempty line:0:*/
if (buflen==0)
{
if (inbody && notallempty)
emptylines++;
else
{
if (*bodypos==msgpos)
*bodypos = ftell(fp);
inbody = 1;
insertline++;
notallempty = 0;
}
if (nextmimedata)
{
nextmimedata = 0;
nextmimename = 0;
frenamed = 0;
if (decfpath[0]=='\0')
{