-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathKLUDGE_CH_mboxmail.c
2371 lines (2115 loc) · 71.9 KB
/
KLUDGE_CH_mboxmail.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
/*
* JNOS 2.0
*
* $Id: mboxmail.c,v 1.1 2015/04/22 01:51:45 root Exp root $
*
* These are the MAILCMDS
*
* Mods by VE4KLM
*/
#include <time.h>
#include <ctype.h>
#ifdef MSDOS
#include <alloc.h>
#endif
#ifdef UNIX
#include <sys/types.h>
#include <sys/stat.h>
#endif
#include "global.h"
#ifdef MAILCMDS
#include "timer.h"
#include "proc.h"
#include "socket.h"
#include "usock.h"
#include "session.h"
#include "smtp.h"
#include "dirutil.h"
#include "telnet.h"
#include "ftp.h"
#include "ftpserv.h"
#include "commands.h"
#include "netuser.h"
#include "files.h"
#include "bm.h"
#include "pktdrvr.h"
#include "ax25.h"
#include "mailbox.h"
#include "mailutil.h"
#include "ax25mail.h"
#include "nr4mail.h"
#include "cmdparse.h"
#include "mailfor.h"
#ifdef B2F
/* 02Feb2012, Maiko, To resolve j2noB2F() prototype */
#include "b2f.h"
#endif
#include "domain.h"
#include "activeBID.h" /* added 23Oct2020 */
#define CC_HIER
/* By setting the fp to NULL, we can check in exitbbs()
* wether a tempfile has been closed or not - WG7J
*/
#define MYFCLOSE(x) { fclose(x); x = (FILE *) 0; }
char CcLine[] = "Cc: ";
char Mbwarning[] = "Third Party mail is not permitted.\n";
char InvalidNameChars[] = "?*<>[],;:+=\"";
int MbSent;
int MbRead;
int MbRecvd;
#ifdef MBFWD
int MbForwarded;
extern char *Mbhaddress;
#else
#define Mbhaddress NULL
#endif
#ifdef DEBUG_SID
int debug_sid_user = -1; /* 31Aug2013, Maiko (VE4KLM) */
#endif
extern int MbrewriteToHdr; /* 29Dec2013, Maiko, Hdr[TO] rewrite option */
/* 14Apr2016, Maiko, prototype (should use string.h with GNU_SOURCE, but */
extern char *strcasestr (const char*, const char*);
/* 14Apr2016, Maiko, prototype, see ufgets.c source file */
extern char* ufgets (int);
#ifdef J2_SID_CAPTURE
/*
* 12May2016, Maiko (VE4KLM), a prototype 'SID from where' database, for now
* just start with the mailbox callsign and the heard SID - add to it later !
* 13May2016, Maiko (VE4KLM), change SID primary, MBOX secondary - a new LL
*/
typedef struct xbmdis2j { /* 13May2016, decided make mbox secondary */
char *mbox; /* 06Nov2020, Maiko, Leave this as connecting call sign !!! */
/*
* 06Nov2020, Maiko, I got this all wrong, the mbox field was originally
* intended for the connecting callsign, not this new feature I had added
* after the fact, giving extra information about the host involved.
*
* In using mbox to now hold this extra info, I inadvertantly removed the
* ability for the SYSOP to see the connecting call, which frankly is more
* important. That was what the first prototype was doing - so we now put
* this extra information (if there is any) in this new 'resolution' var.
*/
char *resolution;
time_t when; /* 13Jun2016, Maiko, add last time seen */
struct xbmdis2j *next;
} J2SIDMBX;
static J2SIDMBX *mclptr; /* 13May2016 */
typedef struct pacdis2j {
//char *mbox; /* 13May2016, decided to make mbox secondary */
J2SIDMBX *mbox;
char *sid;
struct pacdis2j *next;
} J2SIDCAP;
static J2SIDCAP *sclptr, *j2sidcaplist = (J2SIDCAP*)0;
static void capture_sid (struct mbx *m, char *argv)
{
/* 19Nov2019, Maiko, more important to know system name, not user name
struct sockaddr fsocket;
*/
char fsocket[MAXSOCKSIZE]; /* 06Nov2020, Maiko, do it this way instead, don't ask */
char *psock, *tptr;
int i = MAXSOCKSIZE; /* 06Nov2020, Someone (myself, Maiko), forgot to initialize !!! */
/* 13Jun2016, Maiko, TYPO +2 should be outside strlen, not on argv :( */
char *sidcopy = malloc (strlen (argv) + 2);
*sidcopy = m->stype; strcpy (sidcopy + 1, argv);
strupr (sidcopy); /* 14May2015, Maiko */
/* 19Nov2019, Maiko, for netrom connects, we want system name, not user */
if (j2getpeername (m->user, fsocket, &i) != -1)
{
psock = psocket (fsocket); /* keep in mind, psock is just the extra information */
// log (m->user, "SID DB - psock [%s] user [%s]", psock, m->name);
#ifdef DONT_COMPILE
// netrom
if ((tptr = strchr (psock, '@')))
psock = tptr; // include the @ to denote the node
else
#endif
/*
* 06Nov2020, Maiko, We just have to worry about telnet, netrom
* and port can stay the way it is, so just use entire peername
* for those. Worry about other possible weird stuff later.
*/
if ((tptr = strchr (psock, ':')))
{
*tptr = 0; /* just give dotted string representation */
// try and get a hostname
if ((tptr = resolve_a (aton (psock), 0)))
{
psock = tptr;
#ifdef DONT_COMPILE /* 06Nov2020, Maiko, No need to trim, we have room now */
// see if we can trim down some variations for display
if ((tptr = strstr (tptr, ".ampr")))
*tptr = 0; // just show prefix of ampr.org portion
else psock = m->name;
#endif
}
/* 06Nov2020, Maiko, If hostname resolution fails, then just
* leave the original dotted string representation alone !
*
* else psock = m->name;
*/
}
#ifdef DONT_COMPILE
// 06Nov2020, Maiko, Check for ports as well
else if ((tptr = strstr (psock, "port")))
{
psock = tptr;
}
else psock = m->name; /* if no extra info, just put in the callsign */
#endif
}
else psock = m->name; /* if not able to get extra info, stick with the call */
/* see if we're on the list already, if not, add, if so, leave */
for (sclptr = j2sidcaplist ; sclptr; sclptr = sclptr->next)
if (!strcmp (sidcopy, sclptr->sid))
break;
if (!sclptr)
{
/*
* 30Oct2020, Maiko, log calls smack in the middle of a link
* list processing can cause problems, since log() can give a
* thread the chance to hand the CPU off to someone else, so
* when it comes back, pointers may have changed. Pretty sure
* this can happen, so the logs are strictly for debugging !
log (m->user, "SID DB - adding [%s mbox [%s]", sidcopy, m->name);
*/
/* put it at the top of the list */
sclptr = malloc (sizeof(J2SIDCAP));
sclptr->sid = sidcopy;
sclptr->mbox = (J2SIDMBX*)0;
sclptr->next = j2sidcaplist;
j2sidcaplist = sclptr;
}
else free (sidcopy); /* only free if not adding to the list */
/* 13May2016, see if MBOX is on the list for this SID, if not then add */
for (mclptr = sclptr->mbox; mclptr; mclptr = mclptr->next)
if (!strcmp (m->name /* should never have been psock */ , mclptr->mbox))
break;
/* 13May2016, see if MBOX is on the list for this SID, if not then add */
if (!mclptr)
{
/*
* 30Oct2020, Maiko, See above comment about using log() inside of link lists
log (m->user, "SID DB - adding mbox [%s] [%s] to [%s", m->name, psock, sclptr->sid);
*/
/* put it at the top of the list */
mclptr = malloc (sizeof(J2SIDMBX));
/* 06Nov2020, Maiko, Do this properly now !!! */
mclptr->mbox = j2strdup (m->name);
#ifdef MOVED_OUT_UPDATE_EACH_TIME
/* only fill in resolution if psock is different then mbox name */
if (strcmp (m->name, psock))
mclptr->resolution = j2strdup (psock);
else
mclptr->resolution = (char*)0;
#endif
mclptr->next = sclptr->mbox;
sclptr->mbox = mclptr;
}
/*
* Only fill in resolution if psock is different then mbox name,
* and if you think about it, not a bad idea to keep it updated,
* since the connecting station may change the way they connect.
*/
if (strcmp (m->name, psock))
mclptr->resolution = j2strdup (psock);
else
mclptr->resolution = (char*)0;
time (&(mclptr->when)); /* 13Jun2016, Maiko, update each time seen */
}
/* 13May2016, Maiko (VE4KLM), display in a tree what we've captured */
int dosidmbxpast (int argc, char **argv, void *p)
{
int days;
time_t now = time (NULL); /* 03Jul2016, Maiko, get days since */
for (sclptr = j2sidcaplist ; sclptr; sclptr = sclptr->next)
{
tprintf ("[%s\n", sclptr->sid);
for (mclptr = sclptr->mbox; mclptr; mclptr = mclptr->next)
{
tprintf (" %-6.6s %-9.9s", mclptr->mbox, ctime (&(mclptr->when)) + 11);
/* 03Jul2016, Maiko, get days since */
if ((days = (now - mclptr->when) / 86400) > 0)
tprintf (" %dd", days);
/* 06Nov2020, Maiko, New field for extra information */
if (mclptr->resolution)
tprintf (" %s", mclptr->resolution);
tprintf ("\n");
}
// tprintf ("\n");
}
return 0;
}
#endif
int dosid (int argc, char **argv, void *p)
{
struct mbx *m;
char *cp;
char *whichargv;
m = (struct mbx *)p;
/*
* debugging
*
log (m->user, "argc [%d] sid [%s] [%s]", argc, argv[1], argv[2]);
log (m->user, "name [%s] privs [%lx]", m->name, m->privs);
*
*/
#ifdef J2_SID_CAPTURE
/* 12May2016, Maiko (VE4KLM), let's start a 'SID from where' database */
capture_sid (m, argv[1]);
#endif
#ifndef J2_DONT_ENFORCE_BBS_USER /* 24Dec2020, Maiko, for Red (PE1RRR) */
/*
* 27Oct2020, Maiko (VE4KLM), After seeing some mods from Brian (N1URO), I
* think the better approach is that if we see an incoming SID AND the user
* hasn't been configured as a BBS in our ftpusers, then we should just do
* the disconnect 'now' ...
*
* There really is no security to prevent a rogue connect from manually
* entering a SID when they connect and forward malicious content ! Even
* an ignorant user attempting to do a forward because they may not know
* any better, is something we should protect against.
*
* Anyone you forward with 'should' be configured.
*
* We don't care if we initiate the forward, privs will always be 0 then.
*
*/
if (m->privs && !(m->privs & IS_BBS))
{
tprintf ("*** User NOT configured for BBS operation\n");
logmbox (m->user, m->name, "SID from non BBS user, discouraged");
return 1;
}
#endif /* J2_DONT_ENFORCE_BBS_USER */
/* kludge to help handle the space in the author_id part of sid
* 13Apr2010, Maiko, trying to forward with RMS Express
*/
if (argc == 3)
whichargv = argv[2];
else
whichargv = argv[1];
if ((argc == 1) || (whichargv[strlen(whichargv)-1] != ']')) /* must be a SID */
return 1;
/* Other bbs's */
m->sid |= MBX_SID;
#ifdef B2F
/* 25Mar2008, Maiko (VE4KLM), New flag field (for WinLink B2F) */
m->sid2 = 0;
#endif
/* Now check to see if this is an RLI board.
* As usual, Hank does it a bit differently from
* the rest of the world.
*/
if(m->stype == 'R' && strncmp(whichargv,"li",2) == 0)/* [RLI] at a minimum */
m->sid |= MBX_RLI_SID;
/* Or maybe it is F6FBB ? */
else if(m->stype == 'F')
m->sid |= MBX_FBB;
#ifdef DEBUG_SID
log (debug_sid_user, "SID in [%s", whichargv);
#endif
/* Check to see if the BBS supports a kludge called "hierarchical
* routing designators."
*
* No need to check for ']' -- it must be there or this is not
* a valid mbox id -- it is checked earlier (fix de OH3LKU)
*
* Sid format is [BBSTYPE-VERSION-OPTIONS]
* check for LAST -, to allow for version portion. - WG7J
*/
if((cp = strrchr(whichargv,'-')) != NULLCHAR)
{
cp++;
if((strchr(cp,'h') != NULLCHAR) && (strchr(cp,'$') != NULLCHAR))
m->sid |= MBX_HIER_SID;
if(strchr(cp,'m') != NULLCHAR)
m->sid |= MBX_MID;
/* 27Mar2008, Maiko (VE4KLM), Reorganize this code for B2F (WinLink) */
#if defined (MBFWD) && defined(FBBFWD)
if (Mfbb)
if (strchr (cp, 'f') != NULLCHAR)
m->sid |= MBX_FBBFWD;
#endif
#if defined (MBFWD) && defined(FBBCMP)
if (Mfbb > 1 && !(m->sid & MBX_FOREGO_FBBCMP))
{
if (strchr (cp, 'b') != NULLCHAR)
{
m->sid |= MBX_FBBCMP;
/* 27Aug2013, Maiko (VE4KLM), Flag this as being B1F */
if (strchr (cp, '1') != NULLCHAR)
m->sid |= MBX_FBBCMP1;
}
#ifdef B2F
/* 10Jun2016, Maiko (VE4KLM), no more of this 'mbox fbb 3' crap */
if (strchr (cp, '2') != NULLCHAR)
{
/*
* 14May2021, Maiko (VE4KLM), Gus says some of the BPQ systems
* are now presenting B2F in their SID, but I only wrote this
* for Winlink initially, so best to downgrade to B1F if any
* system besides Winlink CMS comes at us with a B2F prompt.
* (for now anyways, till I am able to test with BPQ)
*
* For general forwarding I don't see the benefit of using B2F,
* since it's just B1F with an extra checksum value, but entire
* message content is now encapsulated in the payload, so in a
* way the proposals really contain nothing terribly useful.
*
* 22May2021, Maiko (VE4KLM), Need to allow RMS clients B2F
* (testing vara access mode with Winlink Express client)
*/
if (m->stype == 'W' && strstr (whichargv, "in") == 0) /* [WIN] at a minimum */
m->sid2 |= MBX_B2F;
else if (m->stype == 'R' && strstr (whichargv, "ms") == 0) /* [RMS] at a minimum */
m->sid2 |= MBX_B2F;
else
{
log (m->user, "downgrading B2F offer (for now), sorry");
m->sid |= MBX_FBBCMP1;
}
}
#endif
}
#endif
#ifdef NO_MORE_MBOX_FBB_3_JUST_A_STUPID_IDEA
/* 10Jun2016, Maiko (VE4KLM), B2F is only for Winklink use, let's face it,
* having a Mbox fbb 3 makes no sense, so just check for the '2' in the SID
* regardless of Mfbb level, we only call out to Winlink never the other way.
*/
#if defined (MBFWD) && defined(FBBCMP) && defined(B2F)
/* 25Mar2008, Maiko (VE4KLM), New WinLink options, new flag added */
if (Mfbb > 2 && !(m->sid & MBX_FOREGO_FBBCMP))
{
if (strchr (cp, '2') != NULLCHAR)
m->sid2 |= MBX_B2F;
#ifdef DONT_COMPILE
/* 29Aug2013, Maiko (VE4KLM), I can confirm JNOS now supports B1F !!! */
/*
* 20Jan2011, Maiko (VE4KLM), It would appear that JNOS has always
* ignored the '1', treating B1F as BF - they are NOT the same ! This
* is only a problem IF we are running B2F and the following happens :
*
* A B1F capable station (winfbb) connects to our system, we send the
* station a SID with B2F, they reply with a SID of B1F, since that is
* the highest they can go. Since B1F is 'ignored' by JNOS, it proceeds
* to forward using the BF format. This can crash JNOS, but more likely
* drives up hard disk and CPU usage, generating HUGE temporary files,
* and leaving users with HUGE messages containing garbled text.
*
* Until I get this fixed properly, the only thing I can do about
* this is WARN the sysop, and force a disconnection !
*/
if (strchr (cp, '1') != NULLCHAR)
{
if (!j2noB2F (m->name))
{
log (-1, "Station [%s] is B1F capable, which is not supported yet", m->name);
log (-1, "Add 'mbox nob2f %s' to autoexec.nos for a workaround", m->name);
close_s (m->user);
}
}
#endif /* DONT_COMPILE */
}
#endif /* end of B2F */
#endif /* end of NO_MORE_MBOX_FBB_3_JUST_A_STUPID_IDEA */
}
return 0;
}
int
doarea(argc,argv,p)
int argc;
char *argv[];
void *p;
{
struct mbx *m;
FILE *fp;
int cnt;
char buf[MBXLINE];
m = (struct mbx *) p;
if(argc < 2){
#ifdef USERLOG
if(m->stype == 'N') {
listnewmail(m,0);
return 0;
}
#endif
tprintf("Current message area is: %s\n\n",m->area);
tprintf("Available areas are:\n\n%-10s",m->name);
if(m->stype == 'F')
j2tputs(" Your private mail area\n");
else
tputc('\n');
if((fp = fopen(Arealist,READ_TEXT)) == NULLFILE)
return 0;
if(m->stype == 'F')
sendfile(fp,m->user,ASCII_TYPE,0,m);
else {
/* send only the area names, not the description. Multi-columns by WA7TAS */
cnt=0;
while(fgets(buf,MBXLINE,fp) != NULLCHAR) {
if(buf[0] != '#') { /* skip comments */
firsttoken(buf);
tprintf("%-10s",buf);
if(++cnt > 5 ) {
cnt=0;
tprintf("\n");
}
}
}
if(cnt) tprintf("\n");
j2tputs("\nType AF to get description of areas.\nAF <name> tells more about that area.\n\n");
}
fclose(fp);
return 0;
} else {
dotformat(argv[1]);
//#ifdef AREADOCS
if(m->stype == 'F' && isarea(argv[1])) { /* AF areaname => display areaname.doc */
dirformat(argv[1]);
sprintf(buf, "%s/%s.doc", Mailspool, argv[1]);
if ((fp = fopen(buf, READ_TEXT)) != NULLFILE) {
sendfile(fp,m->user,ASCII_TYPE,0,m);
fclose(fp);
}
else j2tputs("No additional info found.\n");
} else
//#endif /* AREADOCS */
if(!strcmp(m->name,argv[1]) || isarea(argv[1]) ||
((m->privs&SYSOP_CMD) && strpbrk(argv[1],InvalidNameChars)==NULLCHAR
&& *(argv[1]+strlen(argv[1])-1)!='.' )){
changearea(m,argv[1]);
if(m->areatype == PRIVATE)
j2tputs("You have ");
else
tprintf("%s: ",m->area);
if(m->nmsgs){
#ifdef USERLOG
tprintf("%d message%s - %d new.\n",m->nmsgs,
m->nmsgs == 1 ? " " : "s ", m->newmsgs);
#else
if(m->areatype == PRIVATE)
tprintf("%d message%s - %d new.\n", m->nmsgs,
m->nmsgs == 1 ? " " : "s ", m->newmsgs);
else
tprintf("%d message%s.\n", m->nmsgs,
m->nmsgs == 1 ? "" : "s");
#endif
} else
j2tputs("0 messages.\n");
} else
tprintf("No such message area: %s\n",argv[1]);
}
return 0;
}
/* subroutine to do the actual switch from one area to another */
/* USERLOGGING added by WG7J */
void
changearea(m,area)
struct mbx *m;
char *area;
{
if (m->area[0]) { /* current area non-null? */
#ifdef USERLOG
setlastread(m);
#endif
closenotes(m);
}
dotformat(area);
strcpy(m->area,area);
/* Check areas first, so regular users loging in with areaname
* cannot gain permission to kill messages in areas
* (if univperm in ftpusers doesn't allow that)
*/
m->areatype = USER;
if (m->area[0]) { /* non-null area name */
if(isarea(area))
m->areatype = AREA;
else if(!strcmp(m->name,area))
m->areatype = PRIVATE;
/* else was Sysop checking someone else's area; leave areatype==USER */
#ifdef USERLOG
/* only read last read message-id if this IS a bbs, or
* current area is a public area and not 'help'
* or area starts with 'sys' or we have (sysop or no_lastread) privs.
*/
if((m->sid & MBX_SID) ||
#ifdef FWDFILE
m->family == AF_FILE ||
#endif
(strcmp(area,"help") && m->areatype == AREA) ||
!strncmp(m->area,"sys",3) ||
(m->privs & (SYSOP_CMD|NO_LASTREAD)) )
getlastread(m);
#endif
scanmail(m);
}
}
/* States for send line parser state machine */
#define LOOK_FOR_USER 2
#define IN_USER 3
#define AFTER_USER 4
#define LOOK_FOR_HOST 5
#define IN_HOST 6
#define AFTER_HOST 7
#define LOOK_FOR_FROM 8
#define IN_FROM 9
#define AFTER_FROM 10
#define LOOK_FOR_MSGID 11
#define IN_MSGID 12
#define FINAL_STATE 13
#define ERROR_STATE 14
/* Prepare the addressee. If the address is bad, return -1, otherwise
* return 0
*/
int
mbx_to(argc,argv,p)
int argc;
char *argv[];
void *p;
{
char *cp;
int state, i;
char *user, *host, *from, *msgid;
int userlen = 0, hostlen = 0, fromlen = 0, msgidlen = 0;
struct mbx *m;
m = (struct mbx *)p;
/* Free anything that might be allocated
* since the last call to mbx_to() or mbx_reply()
*/
free(m->to);
m->to = NULLCHAR;
free(m->tofrom);
m->tofrom = NULLCHAR;
free(m->tomsgid);
m->tomsgid = NULLCHAR;
free(m->origto);
m->origto = NULLCHAR;
free(m->origbbs);
m->origbbs = NULLCHAR;
free(m->subject);
m->subject = NULLCHAR;
free(m->date);
m->date = NULLCHAR;
if(argc == 1)
return -1;
i = 1;
cp = argv[i];
state = LOOK_FOR_USER;
while(state < FINAL_STATE){
#ifdef MBDEBUG
tprintf("State is %d, char is %c\n", state, *cp);
#endif
switch(state){
case LOOK_FOR_USER:
if(*cp == '@' || *cp == '<' || *cp == '$'){
state = ERROR_STATE; /* no user */
} else {
user = cp; /* point at start */
userlen++; /* start counting */
state = IN_USER;
}
break;
case IN_USER:
switch(*cp){
case '\0':
state = AFTER_USER; /* done with username */
break;
case '@':
state = LOOK_FOR_HOST; /* hostname should follow */
break;
case '<':
state = LOOK_FOR_FROM; /* from name should follow */
break;
case '$':
state = LOOK_FOR_MSGID; /* message id should follow */
break;
default:
userlen++; /* part of username */
}
break;
case AFTER_USER:
switch(*cp){
case '@':
state = LOOK_FOR_HOST; /* hostname follows */
break;
case '<':
state = LOOK_FOR_FROM; /* fromname follows */
break;
case '$':
state = LOOK_FOR_MSGID; /* message id follows */
break;
default:
state = ERROR_STATE;
}
break;
case LOOK_FOR_HOST:
if(*cp == '@' || *cp == '<' || *cp == '$'){
state = ERROR_STATE;
break;
}
if(*cp == '\0')
break;
host = cp;
hostlen++;
state = IN_HOST;
break;
case IN_HOST:
switch(*cp){
case '\0':
state = AFTER_HOST; /* found user@host */
break;
case '@':
state = ERROR_STATE; /* user@host@? */
break;
case '<':
state = LOOK_FOR_FROM; /* fromname follows */
break;
case '$':
state = LOOK_FOR_MSGID; /* message id follows */
break;
default:
hostlen++;
}
break;
case AFTER_HOST:
switch(*cp){
case '@':
state = ERROR_STATE; /* user@host @ */
break;
case '<':
state = LOOK_FOR_FROM; /* user@host < */
break;
case '$':
state = LOOK_FOR_MSGID; /* user@host $ */
break;
default:
state = ERROR_STATE; /* user@host foo */
}
break;
case LOOK_FOR_FROM:
if(*cp == '@' || *cp == '<' || *cp == '$'){
state = ERROR_STATE;
break;
}
if(*cp == '\0')
break;
from = cp;
fromlen++;
state = IN_FROM;
break;
case IN_FROM:
switch(*cp){
case '\0':
state = AFTER_FROM; /* user@host <foo */
break;
case '<':
state = ERROR_STATE; /* user@host <foo< */
break;
case '$':
state = LOOK_FOR_MSGID; /* message id follows */
break;
default:
fromlen++;
}
break;
case AFTER_FROM:
switch(*cp){
case '@': /* user@host <foo @ */
case '<': /* user@host <foo < */
state = ERROR_STATE;
break;
case '$':
state = LOOK_FOR_MSGID; /* user@host <foo $ */
break;
default:
state = ERROR_STATE; /* user@host foo */
}
break;
case LOOK_FOR_MSGID:
if(*cp == '\0')
break;
msgid = cp;
msgidlen++;
state = IN_MSGID;
break;
case IN_MSGID:
if(*cp == '\0')
state = FINAL_STATE;
else
msgidlen++;
break;
default:
/* what are we doing in this state? */
state = ERROR_STATE;
}
if(*(cp) == '\0'){
++i;
if(i < argc)
cp = argv[i];
else break;
} else
++cp;
}
if(state == ERROR_STATE || state == LOOK_FOR_HOST
|| state == LOOK_FOR_FROM || state == LOOK_FOR_MSGID)
return -1; /* syntax error */
m->to = mallocw((unsigned)userlen + hostlen + 2);
strncpy(m->to, user, (unsigned)userlen);
m->to[userlen] = '\0';
if(hostlen){
m->to[userlen] = '@';
strncpy(m->to + userlen + 1, host, (unsigned)hostlen);
m->to[userlen + hostlen + 1] = '\0';
}
if(fromlen){
m->tofrom = mallocw((unsigned)fromlen + 1);
strncpy(m->tofrom, from, (unsigned)fromlen);
m->tofrom[fromlen] = '\0';
}
if(msgidlen){
m->tomsgid = mallocw((unsigned)msgidlen + 1);
strncpy(m->tomsgid, msgid, (unsigned)msgidlen);
m->tomsgid[msgidlen] = '\0';
#ifdef FBBFWD
if(strncmp(m->tomsgid, "fbbbid",6) == 0) {
m->origto = mallocw((unsigned)msgidlen + 1 - 7);
strcpy(m->origto, &msgid[7]);
cp = strstr(m->origto,"->");
*cp = '\0';
}
#endif
}
return 0;
}
#ifdef WPAGES
extern void wpageAdd (char *entry, int bbs, int updateit, char which);
#endif
#ifdef MAILCMDS
#ifdef DEBUG_MBX_HDRS
/* 11Dec2013, Function to dump MBX information to help me debug !!! */
void mbx_dump (char *where, struct mbx *m)
{
char *nstr = "null";
log (m->user, "mbx_dump [%s]", where);
log (-1, " to [%s]", m->to ? m->to : nstr);
log (-1, " origto [%s]", m->origto ? m->origto : nstr);
log (-1, " tofrom [%s]", m->tofrom ? m->tofrom : nstr);
log (-1, " origbbs [%s]", m->origbbs ? m->origbbs : nstr);
}
#endif
#endif
/* This opens the data file and writes the mail header into it.
* Returns 0 if OK, and -1 if not.
*/
int
mbx_data(m,cclist,extra)
struct mbx *m;
struct list *cclist; /* list of carbon copy recipients */
char *extra; /* optional extra header lines */
{
time_t t;
struct list *ap;
int cccnt = 0;
char buf[100]; /* 02Feb2012, Maiko, For WPAGES code from TNOS 240 */
int wl2k_smtp = 0;
char *tfile_to_hdr, *newmto; /* 29Dec2013, dealing with Hdrs[TO] field */
char *new1cc; /* 25Jul2014, rewriting of CCLIST local addresses if necessary */
#ifdef DEBUG_MBX_HDRS
mbx_dump ("mbx_data", m);
#endif
/* If m->date is set, use this one (comes from bbs-forwarded mail) */
time(&t);
if(m->date != NULLCHAR) {
fprintf(m->tfile,"%s%s",Hdrs[DATE],m->date);
#ifdef RLINE
if(Rholdold && m->stype=='B' &&
(t - mydate(m->date)) > 86400L*Rholdold) /* too old? */
fprintf(m->tfile, "%sAge\n", Hdrs[XBBSHOLD]);
#endif
}
else {
fprintf(m->tfile,"%s%s",Hdrs[DATE],ptime(&t));
}
/* 16Jul2013, Maiko, Support for 3rd party emails via Winlink */
if (m->origto)
{
// log (-1, "TO [%s]", m->origto);
if (strcasestr (m->origto, "smtp:"))
wl2k_smtp = 1;
}
/* Bulletin ID, if any */
fprintf(m->tfile, "%s", Hdrs[MSGID]); /* 05Jul2016, Maiko, compiler */
/*
* 17Jul2013, Actually, lets set MSGID to '[email protected]', that way the
* code in forward.c generates a more useful MID in the FC proposal when
* the B2F forwarding comes into play. GOOD - just tested this, I did get
* the email to my '[email protected]' account, and this time the Message-ID
* in the email header includes the full JNOS call (it's not cutoff, due to
* the '_' character one sees if MSGID contains the JNOS hostname instead).
*/
if (wl2k_smtp)
fprintf(m->tfile,"<%ld@%s>\n",get_msgid(), "winlink.org");
else if(m->tomsgid)
fprintf(m->tfile,"<%s@%s.bbs>\n", m->tomsgid, m->name);
else
fprintf(m->tfile,"<%ld@%s>\n",get_msgid(), Hostname);
/* From : , could use 'real bbs address', if origbbs is set */
fprintf(m->tfile, "%s", Hdrs[FROM]); /* 05Jul2016, Maiko, compiler */
/* 27Jul2013, Use the BBS user name */
if (wl2k_smtp)
sprintf (buf, "%[email protected]\n", m->name);
else
/* 02Feb2012, Maiko, In order to incorporate the WPAGES code from
* the Lantz TNOS 240 project, I need to use sprintf (buf) instead
* of fprintf (m->tfile), then just do one fprintf later on ...
*/
if(m->tofrom) { /* BBS style '< call' */
if(m->origbbs != NULLCHAR)
sprintf(buf,"%s@%s\n",m->tofrom,m->origbbs);
else
sprintf(buf,"%s%%%s.bbs@%s\n",m->tofrom, m->name, Hostname);