-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdoc_msgs.c
948 lines (852 loc) · 26.6 KB
/
doc_msgs.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
/*
* doc_msgs.c - Basic handling of messages: read, post, delete.
*/
#include "defs.h"
#include "ext.h"
/****************************************************************************
* deletemessage Updated 10/27/91 -dll
* Deletes message from current room, delnum is the universal message nbr of
* the notes to be nuked.
* The fullroom and quickroom structures are local because this routine
* reads the files and updates them itself.
* Adjusted for FRchron on 4-23-91 -dn
****************************************************************************/
void deletemessage(int32_t delnum, int32_t pos, bool quiet) {
locks(SEM_MSG);
fr_delete(delnum, pos);
msg->room[curr].highest = msg->room[curr].num[MSGSPERRM - 1];
unlocks(SEM_MSG);
if (!quiet) {
colorize(BOLD_RED "Message deleted.\n" BOLD_GREEN);
}
}
/*******************************************************************
* enter message
* This does what the code labelled ENTMSG:, SKFALL:, ENTFIN: in Cit did,
* (and more!).
*
* Terminology:
* 'Post' refers to a public room message.
* 'Letter' refers to a private mail message.
* Letters to Sysop are actually treated as posts to aideroom.
* Twit posts are diverted to the twitroom which is usually aideroom.
* When message forwarding is implemented, this will have to be redone.
*
* This uses an alternate method of keeping mail.
*
**********************************************************************/
int entermessage(int32_t troom, const char *recipient, int8_t upload) {
int32_t curr_rm = troom;
int8_t err;
uint8_t mtype = MES_NORMAL; /* message type; i.e., anon, etc. */
int32_t mmpos;
int32_t mmhi;
struct user *tmpuser = NULL;
bool tosysop = NO; /* message to sysop flag */
int32_t len;
struct mheader *mh;
int32_t i;
if (curr_rm == LOBBY_RM_NBR && !ouruser->f_admin) {
colorize(BOLD_RED "You can't post messages here!\n" BOLD_GREEN);
return (FALSE);
} else if (curr_rm == LOBBY_RM_NBR) {
my_printf("Are you sure you want to post to the Lobby? (Y/N) -> ");
if (!yesno(-1)) {
return (FALSE);
}
my_putchar('\n');
}
if (ouruser->f_twit && troom >= 0) {
my_printf(
"Sorry, you may not post messages while your BBS privileges are "
"suspended.\nPlease Yell to the sysops for more information.\n");
return (FALSE);
}
if (upload == 1) {
my_printf("You are uploading this message! (Use ctrl-D to end)\n\n");
} else if (upload == 2) {
if (troom < 0) {
my_printf(
"\nHit Y to upload a Yell or N to enter a Yell normally (Y/N) -> ");
} else {
my_printf(
"Hit Y to upload a message or N to enter a message normally (Y/N) "
"-> ");
}
if (yesno(-1) == YES) {
my_printf("\n(Use control-D to end!)\n\n");
upload = 1;
} else {
my_printf("\n(Enter %s normally)\n\n", troom < 0 ? "Yell" : "message");
upload = 0;
}
} else if (troom < 0) {
my_putchar('\n');
}
/* If this is email (in Mail>) we need a recipient */
/* If <R>eply was called, recipient should already be set */
if (((curr_rm == MAIL_RM_NBR || curr_rm == YELLS_RM_NBR) &&
(*recipient || curr_rm == MAIL_RM_NBR)) ||
upload < 0) {
if (upload < 0) {
recipient = get_name(
"This command is intended to send harassing X messages you have "
"received to the\nSysops, please hit return if you do not wish to do "
"this. Otherwise, enter the\nname of the user whose X's you want to "
"send: ",
2);
} else if (!*recipient) {
recipient = get_name("Enter recipient: ", 2);
} else if (sysopflags & SYSOP_FROM_USER) {
mtype = MES_SYSOP;
}
if (!*recipient) {
return (FALSE);
}
if (!strcmp(recipient, "Guest")) {
my_printf("\nThat user cannot receive mail.\n");
return (FALSE);
}
if (!strcmp(recipient, "Sysop") && upload >= 0) {
my_printf("\nUse the <Y>ell command to contact the sysops.\n");
return (FALSE);
}
if (curr_rm == YELLS_RM_NBR) {
curr_rm = MAIL_RM_NBR;
}
} /* end if mailroom (recipient analysis) */
if (*recipient) {
if (!(tmpuser = getuser(recipient)) || tmpuser->f_invisible) {
if (tmpuser) {
freeuser(tmpuser);
}
my_printf("\nThere is no user %s on this BBS.\n", recipient);
flush_input(1);
return (FALSE);
} else if (tmpuser->f_twit && !ouruser->f_admin && upload >= 0) {
freeuser(tmpuser);
my_printf("\nThat user has been twitted and cannot receive mail!\n");
flush_input(1);
return (FALSE);
} else {
for (i = 0;
i < NXCONF && (tmpuser->xconf[i].usernum != ouruser->usernum ||
tmpuser->xconf[i].which);
i++)
;
if (i < NXCONF && upload >= 0) {
my_printf("\nSorry, %s has you on his/her disable list.\n",
tmpuser->name);
freeuser(tmpuser);
flush_input(1);
return (FALSE);
}
for (i = 0;
i < NXCONF && (ouruser->xconf[i].usernum != tmpuser->usernum ||
ouruser->xconf[i].which);
i++)
;
if (i < NXCONF && upload >= 0) {
my_printf("\nSorry, you have %s on your disable list.\n",
tmpuser->name);
freeuser(tmpuser);
flush_input(1);
return (FALSE);
}
curr_rm = MAIL_RM_NBR;
}
}
if (sysopflags & SYSOP_FROM_SYSOP) {
mtype = MES_SYSOP;
}
if (sysopflags & SYSOP_FROM_FM) {
mtype = MES_FM;
}
if (curr_rm < 0 || upload < 0) {
tosysop = TRUE;
curr_rm = YELLS_RM_NBR;
}
if (upload < 0) {
mtype = MES_XYELL;
}
/* Set the room type */
if (!*recipient && !tosysop && mtype != MES_SYSOP && mtype != MES_FM &&
(msg->room[curr_rm].flags & QR_ANONONLY)) {
mtype = MES_ANON;
}
if (!*recipient && !tosysop && (msg->room[curr_rm].flags & QR_ANON2) &&
!ouruser->f_noanon && mtype != MES_SYSOP && mtype != MES_FM) {
my_printf("Anonymous? (Y/N) -> ");
if (yesno(-1) == YES) {
mtype = MES_AN2;
my_printf(
"\nIt might be helpful if you included an alias for yourself in your "
"anonymous\npost somewhere, to allow those who respond to you to "
"identify you in some\nfashion. It is not required, but it is "
"encouraged to reduce confusion.\n\n");
} else {
my_putchar('\n');
}
}
if ((msg->room[curr_rm].flags & QR_ANONONLY) && ouruser->f_noanon) {
colorize(
BOLD_RED
"You are not permitted to post in an anon-only forum.\n" BOLD_GREEN);
if (tmpuser) {
freeuser(tmpuser);
}
return (FALSE);
}
/*
* Now go and enter the message. The message is created in a temp file and
* will be integrated into the message database later
*/
err = makemessage(tmpuser, mtype, upload);
if (err == ABORT) {
munmap((void *)tmpstart, 53248);
if (mtype == MES_XYELL) {
colorize(BOLD_RED "No X's to you from that user.\n" BOLD_GREEN);
} else {
colorize(BOLD_RED "Message not entered\n" BOLD_GREEN);
}
if (tmpuser) {
freeuser(tmpuser);
}
return (FALSE);
} else if (err != SAVE) {
if (err != MMAP_ERR) {
munmap((void *)tmpstart, 53248);
}
my_printf("entermessage: mystical error can't make message\n");
if (tmpuser) {
freeuser(tmpuser);
}
return (FALSE);
}
mh = (struct mheader *)(void *)tmpstart;
// align this to a 32b boundary
len = (mh->hlen + mh->len + 4) & ~0x03;
/* Touch to insure memory we'll need is paged in */
mmpos = msg->curpos;
#if 1
mmpos = mmpos + len >= MM_FILELEN ? 0L : mmpos;
#else
/* Msgsize should be a constant in msg-> rather than a global? */
mmpos = mmpos + len >= msgsize ? 0L : mmpos;
#endif
for (i = 0; i < len; i += 1024) {
foo = *((char *)msgstart + mmpos + i) + *((char *)tmpstart + i);
}
foo = ouruser->usernum;
if (tmpuser) {
foo = tmpuser->usernum;
}
locks(SEM_MSG);
/* Store the message in the main message file */
mh->msgid = mmhi = ++msg->highest;
#if 1
msg->curpos =
(mmpos = msg->curpos + len >= mm_filelen ? 0L : msg->curpos) + len;
#else
msg->curpos = (mmpos = msg->curpos + len >= msgsize ? 0L : msg->curpos) + len;
#endif
memcpy((char *)msgstart + mmpos, (const char *)tmpstart, len);
/* Now add a pointer to this message in the fullrm file for this room */
msg->room[curr_rm].posted++;
fr_post(curr_rm, msg->room[curr_rm].posted, mmpos, mmhi, tmpuser);
/* Re-post a copy if to/from Sysop or is a Yell */
if (tosysop && mtype != MES_XYELL) {
fr_post(MAIL_RM_NBR, ++msg->room[MAIL_RM_NBR].posted, mmpos, mmhi, NULL);
} else if (mtype == MES_SYSOP || mtype == MES_FM) {
fr_post(SYSOP_RM_NBR, ++msg->room[SYSOP_RM_NBR].posted, mmpos, mmhi,
tmpuser);
if (curr == YELLS_RM_NBR) {
ouruser->yells++;
}
}
unlocks(SEM_MSG);
munmap((void *)tmpstart, 53248);
if (tmpuser) {
freeuser(tmpuser);
}
ouruser->posted++;
if (room->num[MSGSPERRM - 1] != savedhighest) {
long sh = savedhighest;
loadroom();
if (ouruser->lastseen[curr] == sh && !ouruser->f_ownnew &&
room->num[MSGSPERRM - 2] == sh)
ouruser->lastseen[curr] = savedhighest;
}
if (mtype == MES_XYELL) {
my_printf(
"\nX messages saved in a Yell to Sysop. Please allow up to 24 hours "
"for the\nsysops to have time to respond.\n");
} else if (tosysop) {
my_printf(
"\nYour Yell has been saved. Please allow up to 24 hours for the "
"sysops to have\ntime to respond.\n");
}
return (TRUE);
}
/*
* Messages now have a struct containing some binary data as their header, to
* making parsing messages much quicker and easier. Messages are headed by a
* special magic byte on a word (4 byte) boundary that is unique (M_MAGIC).
*/
/*
* Copy the POST_E POST_S stuff from readmessage()'s wrapper
*/
static int32_t newreadmessage(
unsigned char *p, bool *auth, /* set this parameter to YES if author */
char *aname, bool new, /* TRUE to skip new message author just wrote */
uint32_t msgid) /* message id (validity check -- if 0 ignore it) */
{
bool show = TRUE;
char *title = NULL;
struct user *user;
bool old_ansi = false;
struct mheader *mh = (struct mheader *)(void *)p;
if (!mh) {
my_printf("readmessage: no mh!\n");
return (MNFERR);
}
if ((intptr_t)p & 3) // This is appears to be testing for an address not
// aligned to 32-bit boundary. But why?
{
printf("wtf?\r\n");
return (MNFERR);
}
if (mh->magic != M_MAGIC) {
printf("no magic\r\n");
return (MNFERR);
}
if (mh->mtype < MES_NORMAL || mh->mtype > MES_FM) {
my_printf("\nReadmessage: error in message type\n");
return (FMTERR);
}
if (msgid > 0 && mh->msgid != msgid) {
return (MNFERR);
}
if (msgid) {
sysopflags &= ~SYSOP_MSG;
}
if (mh->mtype == MES_ANON) {
title = my_sprintf(title, "%s", BOLD_YELLOW " *********** ");
} else if (mh->mtype == MES_AN2) {
title = my_sprintf(title, "%s", BOLD_YELLOW " -anonymous- ");
} else {
title = my_sprintf(NULL, "%s", "");
}
char *authfield = strdup(title);
title = my_sprintf(title, "" BOLD_MAGENTA "%s", formtime(2, mh->ptime));
// sprintf(work, ""BOLD_MAGENTA"%s %d, %d %02d:%02d", months[mh->month],
// mh->day, 1900 + mh->year, mh->hour, mh->minute);
char *name = getusername(mh->poster, 1);
/* This shows the room description */
if (mh->mtype == MES_DESC) {
title = my_sprintf(title, BOLD_GREEN " by " BOLD_CYAN "%s", name);
if (msg->room[curr].roomaide) {
name = getusername(msg->room[curr].roomaide, 0);
if (!name) {
name = "Sysop";
}
} else {
name = "(Sysop)";
}
strcpy(aname, name);
colorize(BOLD_GREEN "\nForum moderator is " BOLD_CYAN "%s" BOLD_GREEN
". Total messages:" BOLD_RED " %i\n" BOLD_GREEN
"Forum info "
"last updated ",
name, msg->room[curr].posted);
title = my_sprintf(title, "\n");
/* now on to regular posts */
} else {
if (ouruser->usernum == mh->poster) {
if (new && !ouruser->f_ownnew) {
return (REPERR);
} else {
*auth = TRUE;
}
} else {
*auth = FALSE;
}
if (msgid > 0) {
strcpy(aname, name);
} /* send name back to caller */
if (ouruser->usernum != mh->poster && *name != '<') {
strcpy(profile_default, name);
}
if ((mh->mtype != MES_ANON && mh->mtype != MES_AN2) ||
curr == YELLS_RM_NBR) {
if (mh->mtype == MES_SYSOP) {
sysopflags |= SYSOP_MSG;
}
/* create a completely different string for deleted messages */
if (mh->deleted) {
char poster_color[4];
char delby_color[4];
char poster_name[MAXALIAS + 5];
user = finduser(0, mh->poster, 0);
if (user) {
strcpy(poster_color, BOLD_CYAN);
strcpy(poster_name, user->name);
} else {
strcpy(poster_color, BOLD_RED);
if (mh->poster_name[0] != 0) {
strcpy(poster_name, mh->poster_name);
} else {
strcpy(poster_name, "<Deleted User>");
}
}
user = finduser(0, mh->deleted_by_num, 0);
if (user) {
strcpy(delby_color, BOLD_CYAN);
} else {
strcpy(delby_color, BOLD_RED);
}
title = my_sprintf(title,
BOLD_GREEN " from %s%s " BOLD_GREEN
"deleted by %s%s " BOLD_GREEN
"on " BOLD_MAGENTA "%s\n",
poster_color, poster_name, delby_color,
mh->deleted_by_name, formtime(2, mh->dtime));
title = my_sprintf(title,
BOLD_GREEN "Msg #: " BOLD_YELLOW "%i, " BOLD_GREEN
"Room: " BOLD_YELLOW "%s>" BOLD_GREEN,
mh->old_msgid, msg->room[mh->del_room_num].name);
/* room name changed - make note of it */
if (strcmp(msg->room[mh->del_room_num].name, mh->del_room_name)) {
title =
my_sprintf(title, " Original: " BOLD_YELLOW "%s>" BOLD_GREEN "\n",
mh->del_room_name);
}
} else {
char poster_color[4] = BOLD_CYAN;
if (*name == '<' && mh->poster_name[0] != 0) {
name = mh->poster_name;
strcpy(poster_color, BOLD_WHITE);
}
title = my_sprintf(
title, BOLD_GREEN " from %s%s%s%s", poster_color, name,
mh->mtype == MES_FM ? " (Forum Moderator)" : "",
(mh->mtype == MES_SYSOP &&
(!mh->mail ||
((*auth && ouruser->f_aide) || (!*auth && !ouruser->f_aide))))
? " (Sysop)"
: "");
}
} else if (!*auth && !ouruser->f_prog &&
ouruser->usernum != msg->room[curr].roomaide) {
show = FALSE;
*profile_default = '\0';
} else if (*auth) {
title = my_sprintf(title, BOLD_GREEN " from " BOLD_CYAN "%s", name);
}
}
if (mh->mail) {
if (mh->mtype == MES_NORMAL && ouruser->usernum != mh->ext.mail.recipient &&
curr == MAIL_RM_NBR && !*auth) {
return (MNFERR);
}
name = getusername(mh->ext.mail.recipient, 1);
title =
my_sprintf(title, BOLD_GREEN " to " BOLD_CYAN "%s%s", name,
(mh->mtype == MES_SYSOP && ((*auth && !ouruser->f_aide) ||
(!*auth && ouruser->f_aide)))
? " (Sysop)"
: "");
} else if (mh->quotedx) {
title = my_sprintf(title, " " BOLD_CYAN "(Quoted X's)");
}
if (curr != MAIL_RM_NBR && mh->mtype != MES_DESC && curr != mh->forum &&
curr != YELLS_RM_NBR && curr != DELMSG_RM_NBR) {
title = my_sprintf(title, BOLD_GREEN " in " BOLD_YELLOW "%s>",
msg->room[mh->forum].name);
}
if (new) {
my_putchar('\n');
}
if (show || mh->mtype == MES_DESC) {
colorize("%s", title);
} else {
colorize("%s", authfield);
}
colorize(BOLD_GREEN "\n");
p += mh->hlen;
// int16_t msgsize = mh->len;
// int16_t msgpos = 0;
int16_t linenbr = mh->mtype == MES_DESC ? 3 : 1;
/*
for (int i;;) {
if (!(i = *p++) ||
((++msgpos, my_putchar(i)) == '\n' && ++linenbr >= rows - 1 &&
line_more(&linenbr, (msgpos * 100) / msgsize) < 0)) {
break;
}
}*/
old_ansi = ansi;
ansi = false;
display_with_pagination((const char *)p, rows - 1, linenbr);
ansi = old_ansi;
free(authfield);
free(title);
return (0);
}
int readmessage(
unsigned char *p, bool *auth, /* set this parameter to YES if author */
char *aname, bool new, /* TRUE to skip new message author just wrote */
uint32_t msgid) /* message id (validity check -- if 0 ignore it) */
{
int ret;
if (client) {
my_putchar(IAC);
my_putchar(POST_S);
}
ret = newreadmessage(p, auth, aname, new, msgid);
if (client) {
my_putchar(IAC);
my_putchar(POST_E);
if (numposts++ < 0) {
numposts = -numposts + 2;
}
}
return (ret);
}
int8_t makemessage(
struct user *recipient, /* on entry, NULL if its not mail */
uint8_t mtype, /* MES_NORMAL, MES_ANON, MES_AN2, MES_DESC */
int8_t upload) /* TRUE if user wants to end a message via ctrl-D */
{
bool auth;
char chr = CTRL_D;
char cmd;
int32_t i;
uint8_t lnlngth; /* line length */
uint8_t lastspace; /* char position of last space encountered on line */
uint8_t cancelspace; /* true when last character on line is a space */
char thisline[MARGIN + 1]; /* array to save current line */
time_t now;
char dummy[MAXALIAS + 1];
uint8_t invalid = 0;
struct mheader *mh;
unsigned char *tmpp;
unsigned char *tmpsave;
{
size_t size = 53248;
if (!(tmpstart = mmap_anonymous(size))) {
return (MMAP_ERR);
}
}
mh = (struct mheader *)(void *)tmpstart;
mh->magic = M_MAGIC;
mh->mtype = mtype;
mh->poster = ouruser->usernum;
time(&now);
mh->ptime = now;
/* Mail posts and room descriptions use this field */
if (recipient && mtype != MES_XYELL) {
mh->mail = 1;
mh->ext.mail.recipient = recipient->usernum;
mh->hlen = sizeof *mh - sizeof mh->ext + sizeof mh->ext.mail;
} else {
mh->hlen = sizeof *mh - sizeof mh->ext;
}
mh->forum = curr;
tmpp = tmpsave = tmpstart + mh->hlen;
if (mtype == MES_XYELL) {
if ((i = xyell(recipient, tmpp)) <= 0) {
my_putchar('\n');
return (ABORT);
}
tmpp[i] = 0;
mh->quotedx = 1;
mh->len = i;
return (SAVE);
}
*tmpp = 0; /* Marks end of message for pre-entering header */
if (recipient) {
my_putchar('\n');
}
readmessage(tmpstart, &auth, dummy, FALSE, 0);
if (client) {
my_putchar(IAC);
my_putchar(G_POST);
my_putchar(upload);
my_putc((byte >> 16) & 255, stdout);
my_putc((byte >> 8) & 255, stdout);
my_putc(byte & 255, stdout);
block = 1;
upload = 1;
}
lnlngth = 0;
lastspace = 0;
cancelspace = FALSE;
for (;;) {
if (tmpp - tmpstart > 50000) {
if (!client) {
my_printf("\nMessage too long, must Abort or Save\n\n");
flush_input(1);
}
while ((chr = inkey()) != CTRL_D)
;
} else {
chr = inkey();
}
if (client) {
if (lnlngth < MARGIN - 1 && chr >= SP && chr < DEL) {
*tmpp++ = chr;
lnlngth++;
continue;
} else if (chr == LF || chr == CTRL_D ||
(chr == TAB && lnlngth >= MARGIN - 8)) {
for (; lnlngth && tmpp[-1] == SP; tmpp--, lnlngth--)
;
if (lnlngth || chr != CTRL_D) {
*tmpp++ = LF;
}
lnlngth = 0;
if (chr != CTRL_D) {
continue;
}
} else if (chr == TAB) {
do {
*tmpp++ = SP;
lnlngth++;
} while (lnlngth & 7);
continue;
} else {
my_printf(
"\n\nClient error while posting, message not saved! Please see "
"Client> forum\n\n");
while (inkey() != CTRL_D)
;
return (ABORT);
}
} else {
if (chr < ' ' && (chr != CTRL_D || !upload) && chr != BS && chr != TAB &&
chr != LF && chr != CTRL_X && chr != CTRL_W && chr != CTRL_R) {
if (invalid++) {
flush_input(invalid < 6 ? (invalid / 2) : 3);
}
continue;
}
invalid = 0;
if (chr == BS) {
if (lnlngth) {
my_putchar(BS);
my_putchar(SP);
my_putchar(BS);
if (lnlngth-- == lastspace) {
for (; --lastspace && thisline[lastspace] != SP;)
;
}
}
continue;
} else if (chr == CTRL_X) {
for (; lnlngth; lnlngth--) {
my_putchar(BS);
my_putchar(SP);
my_putchar(BS);
}
lastspace = 0;
continue;
} else if (chr == CTRL_W) {
for (; lnlngth && thisline[lnlngth] == SP; lnlngth--) {
my_putchar(BS);
my_putchar(SP);
my_putchar(BS);
}
for (; lnlngth && thisline[lnlngth] != SP; lnlngth--) {
my_putchar(BS);
my_putchar(SP);
my_putchar(BS);
}
lastspace = lnlngth;
continue;
} else if (chr == CTRL_R) {
thisline[lnlngth + 1] = 0;
my_printf("\n%s", thisline + 1);
continue;
} else if (chr == TAB)
if (lnlngth >= MARGIN - 8) {
chr = LF;
} else {
for (thisline[++lnlngth] = my_putchar(SP); lnlngth & 7;) {
thisline[++lnlngth] = my_putchar(SP);
}
continue;
}
else if (chr == SP && cancelspace) {
cancelspace = 0;
continue;
} else {
cancelspace = FALSE;
}
if (chr != LF && chr != CTRL_D) {
lnlngth++;
}
if (chr == SP && ((lastspace = lnlngth) == MARGIN)) {
cancelspace = TRUE;
chr = LF;
lnlngth--;
} else if (lnlngth == MARGIN) {
if (lastspace > MARGIN / 2) {
for (lnlngth--; lnlngth > lastspace; lnlngth--) {
my_putchar(BS);
my_putchar(SP);
my_putchar(BS);
}
for (i = 1; i < lnlngth; i++) {
*tmpp++ = thisline[i];
}
*tmpp++ = my_putchar(LF);
for (lnlngth = 1; lnlngth + lastspace < MARGIN; lnlngth++) {
i = thisline[lnlngth + lastspace];
thisline[lnlngth] = my_putchar(i);
}
lastspace = 0;
} else {
for (i = 1; i < MARGIN; i++) {
*tmpp++ = thisline[i];
}
*tmpp++ = my_putchar(LF);
lastspace = 0;
lnlngth = 1;
}
}
if (chr != CTRL_D && chr != LF) {
thisline[lnlngth] = my_putchar(chr);
continue;
} else if (lnlngth || (chr == LF && upload)) {
int save = lnlngth;
for (; lnlngth && thisline[lnlngth] == ' '; lnlngth--)
;
for (i = 1; i <= lnlngth; i++) {
*tmpp++ = thisline[i];
}
*tmpp++ = my_putchar(LF);
lastspace = lnlngth = 0;
if (chr == LF && (save || upload)) {
continue;
}
}
}
/* Two LFs or ctrl-D when uploading reach here */
mh->len = tmpp - tmpsave;
*tmpp = 0;
for (i = 0, cmd = ' '; cmd != 'C' && cmd != 'P';) {
checkx(1);
if (!client && cmd != 'q' && i != 1) {
colorize(BOLD_YELLOW "<A>" BOLD_CYAN "bort " BOLD_YELLOW "<C>" BOLD_CYAN
"ontinue " BOLD_YELLOW "<P>" BOLD_CYAN
"rint " BOLD_YELLOW "<S>" BOLD_CYAN
"ave " BOLD_YELLOW "<X>" BOLD_CYAN
"press "
"-> " BOLD_GREEN);
}
cmd = get_single_quiet(" \nACPSqQx?/");
if (strchr("qQx?/", cmd)) {
i = 0;
}
if (guest && (cmd == 'Q' || cmd == 'x')) {
my_printf("\n\nThe Guest user cannot do that.\n\n");
continue;
}
switch (cmd) {
case '\n':
case ' ':
if (!i++) {
continue;
}
flush_input(i < 6 ? (i / 2) : 3);
my_putchar('\n');
break;
case 'A':
if (!client) {
colorize(BOLD_RED "Abort:" BOLD_GREEN " are you sure? ");
if (yesno(-1) == NO) {
break;
}
}
my_putchar('\n');
return (ABORT);
case 'C':
if (client) {
break;
}
my_printf("Continue...\n");
continue;
case 'P':
my_printf("Print formatted\n\n");
readmessage(tmpstart, &auth, dummy, FALSE, 0);
continue;
case 'S':
if (!client) {
my_printf("Save message\n");
}
if (tmpp < tmpsave + 3) {
my_printf("\nEmpty message -- ");
return (ABORT);
}
i = (++postcount - 10) * 30;
time(&now);
if (now - ouruser->time < i) {
flush_input(i - now + ouruser->time);
}
return (SAVE);
case 'Q':
get_syself_help(cmd);
my_putchar('\n');
break;
case 'x':
express(10);
my_putchar('\n');
break;
case '?':
case '/':
my_printf("\n\nThe help for this section is not yet available.\n");
my_putchar('\n');
break;
} /* switch (cmd) */
i = 0;
if (client) {
my_putchar(IAC);
my_putchar(G_POST);
my_putchar(upload);
my_putc((byte >> 16) & 255, stdout);
my_putc((byte >> 8) & 255, stdout);
my_putc(byte & 255, stdout);
block = 1;
}
}
}
}
// Function to display the string with pagination support.
void display_with_pagination(const char *message, uint8_t rows,
int16_t linenbr) {
int16_t msgpos = 0;
const int msgsize = strlen(message); // Get the size of the message.
char line[200];
uint8_t index = 0;
// Loop through the message and display it.
for (const char *p = message; *p; ++p, ++msgpos) {
line[index++] = *p;
// my_putchar(*p); // Display the current character.
// Check for newline character.
if (*p == '\n') {
line[index] = 0;
cleanup_strings(line);
colorize((const char *)line);
index = 0;
linenbr++; // Increment the line number counter.
// Check if we have reached the end of page.
if (linenbr >= rows) {
// Handle pagination, break if the user decides to quit.
if (line_more(&linenbr, (msgpos * 100) / msgsize) < 0) {
break;
}
}
}
}
}