-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailcmd.c
858 lines (729 loc) · 25.6 KB
/
mailcmd.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
/* mailcmd.c - Mail commands */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <syslog.h>
#include "mailcmd.h"
#include "defines.h"
#include "config.h"
#include "mbox.h"
#include "utils.h"
/* List messages */
void printhead(int i, struct message *m) {
char ch = ' ';
if ((m->m_flag & (MREAD|MNEW)) == MNEW)
ch = 'N';
if ((m->m_flag & (MREAD|MNEW)) == 0)
ch = 'U';
if ((m->m_flag & (MDELETED)) == MDELETED)
ch = 'K';
printf("%c%c%4i %25.25s %-24.24s %5.16s%6li\n",
(current == i+1) ? '>' : ' ',
ch, i+1, m->from, m->subj, m->date ,m->m_size);
}
int do_list(int argc, char **argv)
{
int i;
if (!(messages)) {
printf("No messages.\n");
return 0;
}
printf("St Num From Subject Date Size\n");
for (i = 0; i < messages; i++) {
printhead(i, &message[i]);
}
return 0;
}
/* Read a message (xNOS-stylish parameters) */
int do_read(int argc, char **argv)
{
char *myargv[64];
int myargc, argsmine;
char *tmpbuf;
int i, j, k;
struct message *m;
int msg, maxmsg;
char line[2000];
// Automatic Receipt generator
FILE *f;
char str [LINESIZE + 1];
if (!(messages)) {
printf("You have no messages.\n");
return 0;
}
if (argc > 1) {
argsmine = 0;
for (i = 1; i < argc; i++)
myargv[i] = argv[i];
myargc = argc;
} else {
argsmine = 1;
if (current >= messages) {
printf("No more messages.\n");
return 0;
}
current++;
myargc = 2;
myargv[1] = malloc(17);
sprintf(myargv[1], "echo");
sprintf(myargv[1], "%i", current);
}
for (i = 1; i < myargc; i++) {
tmpbuf = strchr(myargv[i], '-');
msg = atoi(myargv[i]);
if (tmpbuf == NULL)
maxmsg = msg;
else
maxmsg = atoi(++tmpbuf);
if (maxmsg < msg) {
printf("Bad message number %i.\n", maxmsg);
continue;
}
for (; msg <= maxmsg; msg++) {
if (msg < 1 || msg > messages) {
printf("There's no message number %i.\n", msg);
continue;
}
readmesg(msg, (!strncmp(argv[0], "v", 1)));
printf("--- end of message #%i --- \n", msg);
if (dot->receipt != NULL) {
getstr(str, LINESIZE, "\aA receipt was asked for, do we send one? (y/N): ");
if (!strcasecmp(str, "Y") || !strcasecmp (str, "YES") || !strcasecmp (str, "YE")) {
/* Let's try to automate the receipt generator more */
f = fopen(tempMesg, "w");
fprintf(f, "From: %s <%s@%s>\n", fullname, username, hostname);
strncpy (str, dot->from, LINESIZE);
printf("Receipt going to: %s\n", str);
fprintf(f,"To: %s\n", str);
fprintf(f,"X-Mailer: %s\n",VERSION);
fprintf(f,"X-Origin: Amateur Radio Services\n");
fprintf(f,"Subject: axMail-FAX read receipt for \"%s\"\n", dot->subj);
strncpy (str, dot->subj, LINESIZE);
fprintf(f, "Your mail to %s <%s@%s> about \"%s\"\n", fullname, username, hostname, dot->subj);
fprintf(f,"written on %s has been read.\n\n", dot->date);
fprintf(f, "\n-----\nThis receipt is sent via axMail-FAX: Not your Elmer\'s Wlink!\n");
fclose(f);
sprintf(str, "%s -oem -t < %s", BIN_AXMAIL_SENDMAIL, tempMesg);
system(str);
printf("Read receipt sent.\n");
}
}
}
}
if (argsmine)
for (i = 1; i < myargc; i++)
free(myargv[i]);
return 0;
}
/* Send a message (perhaps a reply) */
int do_send(int argc, char **argv)
{
FILE *f;
FILE *g;
char str[LINESIZE + 1];
char cc[LINESIZE + 1];
char bcc[LINESIZE + 1];
int i;
int reply = 0;
if (!strncmp(argv[0], "sr", 2)) {
reply = 1;
if (argc == 1) {
if (current == 0) {
printf("No current message to reply to.\n");
return 0;
}
i = current;
} else
i = atoi(argv[0]);
i--;
if ((i < 0) || (i >= messages)) {
printf("Just enter SR without a parameter or number.\n");
return 0;
}
dot = &message[i];
}
if ((f = fopen(tempMesg, "w")) == NULL) {
printf("Could not create temporary file.\n");
syslog(LOG_NOTICE, "do_send: Could not create temporary file.\n");
return 0;
}
fprintf(f, "From: %s <%s@%s>\n", fullname, username, hostname);
str[0] = '\0';
if (argc != 1) /* Recipient on command line */
for (i = 1; i < argc; i++) {
if (i > 1)
strcat(str, " ");
strncat(str, argv[i], LINESIZE - strlen(str));
}
else {
if (reply) {
strncpy(str, dot->from, LINESIZE);
printf("To: %s\n", str);
} else {
mymain:
getstr(str, LINESIZE, "(? = help)\nTo: ");
if (!strcmp(str, "?")) {
printf("Enter the email address or addresses separated by commas on this line\n");
printf("You'll be asked if you want copies to others.\n");
printf("Ex: [email protected], [email protected] - all on one line.\n");
goto mymain;
}
if (str[0] == '\0') {
printf("No recipients, message cancelled.\n");
fclose(f);
remove(tempMesg);
return 0;
}
}
}
fprintf( f, "To: %s\n", str);
/* adding a carbon copy feature */
copies:
getstr(str, LINESIZE, "Send a copy or copies of this mail to others? (y/N/?): ");
if (!strcmp(str, "?")) {
printf("Answering \"Y\" or \"yes\" here will prompt you to enter cc or bcc mail\n");
printf("addreses. Separate them using commas. Ex: [email protected], [email protected]\n");
goto copies;
} else {
if (!strcasecmp(str, "Y") || !strcasecmp (str, "YES") || !strcasecmp (str, "YE")) {
goto carbon;
} else {
goto prio;
}
}
carbon:
getstr(cc, LINESIZE, "(? = help)\ncc: ");
if (!strcmp(cc, "?")) {
printf("Enter your carbon copied address(es) below. You will be prompted for\n");
printf("bcc addresses after carbon copied addresses. Enter multiple emails on\n");
goto carbon;
}
if (cc[0] == '\0') {
goto goblind;
}
fprintf( f, "cc: %s\n", cc);
goblind:
/* adding a blind carbon copy feature */
getstr(bcc, LINESIZE, "Send a copy to a hidden user? (hit enter if there's no one.)\n(? = help)\nbcc: ");
if (!strcmp(bcc, "?")) {
printf("Enter your blinded copied address(es) below. These won't show in the mail sent\n");
printf("list. Enter multiple emails the same line. Ex: [email protected], [email protected]\n");
goto goblind;
}
if (bcc[0] == '\0') {
goto header;
}
fprintf( f, "bcc: %s\n", bcc);
header:
fprintf( f, "X-Mailer: %s\n", VERSION );
fprintf( f, "X-Origin: Amateur Radio Services\n" );
goto prio;;
/* adding priority receive rule */
prio:
getstr(str, LINESIZE, "Is this message emergency or urgent? (y/N/?): ");
/* try to bullet-proof end-user responces a bit... */
if (!strcmp(str, "?")) {
printf("\nAnswering \"Y\" or \"yes\" here will flag the message as of being highest\n");
printf("priority in nature and with most mail client software will present\n");
printf("your message as an urgent read communication. By entering \"N\" or \"no\" or\n");
printf("by hitting the enter key will send your mail message via normal delivery.\n\n");
goto prio;
}
if (!strcasecmp(str, "Y") || !strcasecmp (str, "YES") || !strcasecmp (str, "YE")) {
fprintf( f, "X-Priority: 1 (Highest)\n" );
}
else
{ fprintf( f,"X-Priority: 3 (Normal)\n" );
}
receipt:
getstr(str, LINESIZE, "Read receipt requested? (y/N/?): ");
if (!strcmp(str, "?")) {
printf("\nAnswering \"Y\" or \"yes\" here will request a confirmation of \n");
printf("your message being opened by the remote user. By entering \"N\" or \"no\" or\n");
printf("by hitting the enter key will not request a confirmation receipt.\n\n");
goto receipt;
}
if (!strcasecmp(str, "Y") || !strcasecmp (str, "YES") || !strcasecmp (str, "YE")) {
fprintf( f, "Disposition-Notification-To: %s <%s@%s>\n", fullname, username, hostname);
}
else
{ fprintf( f,"" );
}
if (reply) {
if (strncasecmp(dot->subj, "Re: ", 3))
snprintf(str, LINESIZE, "Re: %s", dot->subj);
else
snprintf(str, LINESIZE, "%s", dot->subj);
printf("Subject: %s\n", str);
} else
getstr(str, LINESIZE, "Subject: ");
fprintf(f, "Subject: %s\n", str);
if (reply)
fprintf(f, "In-Reply-To: %s\n", dot->id);
printf("Enter message text (end with \"/ex\" or \".\" on a line by itself):\n");
fflush(stdout);
cont:
do {
fgets(str, LINESIZE, stdin);
if ( strcmp( str, ".\n") && strcmp( str, "/ex\n")) fputs(str, f);
} while (strcmp(str, ".\n") && strcmp(str, "/ex\n"));
retry:
getstr(str, LINESIZE, "Deliver (Y/n/c/?): ");
if (!strcmp(str, "?")) {
printf("Answering \"N\" here will cancel the message. Answering \"C\" will\n");
printf("let you continue writing the message. Answering anything else will\n");
printf("proceed with delivering the message to the recipient.\n");
goto retry;
}
if (!strcasecmp(str, "c")) {
printf("Continue entering message text\n(end with \"/ex\" or \".\" on a line by itself):\n");
fflush(stdout);
goto cont;
}
/* append a signature file signature to the mail message */
FILE *stream;
FILE *streamm;
FILE *streammm;
char *line = NULL;
char *sig = NULL;
char buffer[79 + 1];
char bufferr[50 + 1];
char bufferrr[50 + 1];
size_t len = 0;
ssize_t read;
sprintf(buffer,"%s/.signature", homedir);
sprintf(bufferr,"/etc/clamsmtpd.conf");
sprintf(bufferrr,"/etc/clamav/clamav-milter.conf");
stream = fopen(buffer, "r");
streamm = fopen(bufferr, "r");
streammm = fopen(bufferrr, "r");
if (stream == NULL) {
printf("No signature file found, use the SIG command to make one.\n");
fprintf(f, "\n---\nsent via axMail-FAX by N1URO.");
if (streamm == NULL) {
}
else if (streammm == NULL) {
} else {
fprintf(f, "\n---\nMail scanned for viri by ClamAV.");
fclose(streamm);
fclose(streammm);
}
goto mailmsg;
} else {
while ((read = getline(&line, &len, stream)) != -1) {
fprintf(f, "\n---\n%s\nsent via axMail-FAX by N1URO.", line);
if (streamm == NULL) {
} else if (streammm == NULL) {
} else {
fprintf(f, "\n---\nMail scanned for viri by ClamAV.");
fclose(streamm);
}
}
free(line);
fclose(stream);
}
mailmsg:
if (fclose(f)) {
printf("Ouch, could not close temporary file.\n");
syslog(LOG_NOTICE, "do_send: Could not close temporary file.\n");
return 0;
}
delrcpt:
if (strcasecmp(str, "n")) {
getstr(str, LINESIZE, "Request a delivery receipt? (y/N/?): ");
if (!strcasecmp(str, "?")) {
printf("Requesting a delivery receipt sends the remote mail server a command that tells\n");
printf("it that you desire notification that your mail message not only was received but\n");
printf("also that it was actually delivered to the user's mailbox. This comes in very handy\n");
printf("if you need to log the fact that you sent a communication to a specific person\n");
printf("especially for emergency communication purposes and they do NOT send you a read\n");
printf("receipt even though you asked for one, this covers you and is your log of proof that\n");
printf("you infact did send a communication and the remote person did in fact received it.\n");
printf("This feature can ONLY be found in axMail-FAX.\n");
goto delrcpt;
}
if (!strcasecmp(str, "y")) {
sprintf(str, "%s -N success,delay,failure -oem -t < %s", BIN_AXMAIL_SENDMAIL, tempMesg);
system(str);
printf("Message sent, delivery notification activated.\n");
} else {
sprintf(str, "%s -oem -t < %s", BIN_AXMAIL_SENDMAIL, tempMesg);
system(str);
printf("Message sent.\n");
}
} else
printf("Message canceled.\n");
if (remove(tempMesg)) {
printf("Ouch, could not remove temporary file.\n");
syslog(LOG_NOTICE, "do_send: Could not remove temporary file.\n");
return 0;
}
return 0;
}
/* Send a personal message with no flags or copy prompts */
int do_psend(int argc, char **argv)
{
FILE *f;
FILE *g;
char str[LINESIZE + 1];
int i;
int reply = 0;
if (!strncmp(argv[0], "sr", 2)) {
reply = 1;
if (argc == 1) {
if (current == 0) {
printf("No current message to reply to.\n");
return 0;
}
i = current;
} else
i = atoi(argv[0]);
i--;
if ((i < 0) || (i >= messages)) {
printf("Just enter SR without a parameter or number.\n");
return 0;
}
dot = &message[i];
}
if ((f = fopen(tempMesg, "w")) == NULL) {
printf("Could not create temporary file.\n");
syslog(LOG_NOTICE, "do_send: Could not create temporary file.\n");
return 0;
}
fprintf(f, "From: %s <%s@%s>\n", fullname, username, hostname);
str[0] = '\0';
if (argc != 1) /* Recipient on command line */
for (i = 1; i < argc; i++) {
if (i > 1)
strcat(str, " ");
strncat(str, argv[i], LINESIZE - strlen(str));
}
else {
if (reply) {
strncpy(str, dot->from, LINESIZE);
printf("To: %s\n", str);
} else {
mypmain:
getstr(str, LINESIZE, "(? = help)\nTo: ");
if (!strcmp(str, "?")) {
printf("Enter the email address or addresses separated by commas on this line\n");
printf("Ex: [email protected], [email protected] - all on one line.\n");
goto mypmain;
}
if (str[0] == '\0') {
printf("No recipients, message cancelled.\n");
fclose(f);
remove(tempMesg);
return 0;
}
}
}
fprintf( f, "To: %s\n", str);
fprintf( f, "X-Mailer: %s\n", VERSION );
fprintf( f, "X-Origin: Amateur Radio Services\n" );
fprintf( f, "X-Priority: 1 (Highest)\n" );
if (reply) {
if (strncasecmp(dot->subj, "Re: ", 3))
snprintf(str, LINESIZE, "Re: %s", dot->subj);
else
snprintf(str, LINESIZE, "%s", dot->subj);
printf("Subject: %s\n", str);
} else
getstr(str, LINESIZE, "Subject: ");
fprintf(f, "Subject: %s\n", str);
printf("Enter message text (end with \"/ex\" or \".\" on a line by itself):\n");
fflush(stdout);
pcont:
do {
fgets(str, LINESIZE, stdin);
if ( strcmp( str, ".\n") && strcmp( str, "/ex\n")) fputs(str, f);
} while (strcmp(str, ".\n") && strcmp(str, "/ex\n"));
pretry:
getstr(str, LINESIZE, "Deliver (Y/n/c/?): ");
if (!strcmp(str, "?")) {
printf("Answering \"N\" here will cancel the message. Answering \"C\" will\n");
printf("let you continue writing the message. Answering anything else will\n");
printf("proceed with delivering the message to the recipient.\n");
goto pretry;
}
if (!strcasecmp(str, "c")) {
printf("Continue entering message text\n(end with \"/ex\" or \".\" on a line by itself):\n");
fflush(stdout);
goto pcont;
}
/* append a signature file signature to the mail message */
FILE *stream;
FILE *streamm;
FILE *streammm;
char *line = NULL;
char *sig = NULL;
char buffer[79 + 1];
char bufferr[50 + 1];
char bufferrr[50 + 1];
size_t len = 0;
ssize_t read;
sprintf(buffer,"%s/.signature", homedir);
sprintf(bufferr,"/etc/clamsmtpd.conf");
sprintf(bufferrr,"/etc/clamav/clamav-milter.conf");
stream = fopen(buffer, "r");
streamm = fopen(bufferr, "r");
streammm= fopen(bufferrr, "r");
if (stream == NULL) {
printf("No signature file found, use the SIG command to make one.\n");
fprintf(f, "\n---\nsent via axMail-FAX by N1URO.");
} else if (streamm == NULL) {
}
else if (streammm == NULL) {
} else {
fprintf(f, "\n---\nMail scanned for viri by ClamAV.");
fclose(streamm);
}
goto pmailmsg;
if (stream) {
while ((read = getline(&line, &len, stream)) != -1) {
fprintf(f, "\n---\n%s\nsent via axMail-FAX by N1URO.", line);
if (streamm == NULL) {
}
if (streammm == NULL) {
} else {
fprintf(f, "\n---\nMail scanned for viri by ClamAV.");
fclose(streamm);
fclose(streammm);
}
}
free(line);
fclose(stream);
}
pmailmsg:
if (fclose(f)) {
printf("Ouch, could not close temporary file.\n");
syslog(LOG_NOTICE, "do_send: Could not close temporary file.\n");
return 0;
}
if (strcasecmp(str, "n")) {
pdelrcpt:
getstr(str, LINESIZE, "Request a delivery receipt? (y/N/?): ");
if (!strcasecmp(str, "?")) {
printf("Requesting a delivery receipt sends the remote mail server a command that tells\n");
printf("it that you desire notification that your mail message not only was received but\n");
printf("also that it was actually delivered to the user's mailbox. This comes in very handy\n");
printf("if you need to log the fact that you sent a communication to a specific person\n");
printf("especially for emergency communication purposes and they do NOT send you a read\n");
printf("receipt even though you asked for one, this covers you and is your log of proof that\n");
printf("you infact did send a communication and the remote person did in fact received it.\n");
printf("This feature can ONLY be found in axMail-FAX.\n");
goto pdelrcpt;
}
if (!strcasecmp(str, "y")) {
sprintf(str, "%s -N success,delay,failure -oem -t < %s", BIN_AXMAIL_SENDMAIL, tempMesg);
system(str);
printf("Message sent, delivery notification activated.\n");
} else {
sprintf(str, "%s -oem -t < %s", BIN_AXMAIL_SENDMAIL, tempMesg);
system(str);
printf("Message sent.\n");
}
} else
printf("Message canceled.\n");
if (remove(tempMesg)) {
printf("Ouch, could not remove temporary file.\n");
syslog(LOG_NOTICE, "do_send: Could not remove temporary file.\n");
return 0;
}
return 0;
}
/* Kill a message */
int do_kill(int argc, char **argv)
{
int i, msg = 0, cnt = 0;
char *myargv[64];
int myargc, argsmine;
if (!(messages)) {
printf("You have no messages.\n");
return 0;
}
if (argc > 1) {
argsmine = 0;
for (i = 1; i < argc; i++)
myargv[i] = argv[i];
myargc = argc;
} else {
if (current == 0) {
printf("No current message to kill.\n");
return 0;
}
argsmine = 1;
myargc = 2;
myargv[1] = malloc(17);
sprintf(myargv[1], "%i", current);
}
for (i = 1; i < myargc; i++) {
msg = atoi(myargv[i]) - 1;
if ((msg < 0) || (msg >= messages)) {
printf("There's no message %s.\n", myargv[i]);
continue;
}
dot = &message[msg];
if ((dot->m_flag & MDELETED) == MDELETED) {
printf("Message %i is already dead.\n", msg + 1);
continue;
}
dot->m_flag |= MDELETED;
cnt++;
}
if (cnt == 1) /* GCC warns here, but what the heck! 8-) */
printf("Message %i killed.\n", msg + 1);
else if (cnt > 1)
printf("%i messages killed.\n", cnt);
if (argsmine)
for (i = 1; i < myargc; i++)
free(myargv[i]);
return 0;
}
/* Unkill a message */
int do_unkill(int argc, char **argv)
{
int i, msg = 0, cnt = 0;
char *myargv[64];
int myargc, argsmine;
if (!(messages)) {
printf("You have no messages.\n");
return 0;
}
if (argc > 1) {
argsmine = 0;
for (i = 1; i < argc; i++)
myargv[i] = argv[i];
myargc = argc;
} else {
if (current == 0) {
printf("No current message to unkill.\n");
return 0;
}
argsmine = 1;
myargc = 2;
myargv[1] = malloc(17);
sprintf(myargv[1], "%i", current);
}
for (i = 1; i < myargc; i++) {
msg = atoi(myargv[i]) - 1;
if ((msg < 0) || (msg >= messages)) {
printf("There's no message %s.\n", myargv[i]);
continue;
}
dot = &message[msg];
if ((dot->m_flag & MDELETED) != MDELETED) {
printf("Message %i is not dead.\n", msg + 1);
continue;
}
dot->m_flag ^= (dot->m_flag & MDELETED);
cnt++;
}
if (cnt == 1) /* GCC warns here, but what the heck! 8-) */
printf("Message %i unkilled.\n", msg + 1);
else if (cnt > 1)
printf("%i messages unkilled.\n", cnt);
if (argsmine)
for (i = 1; i < myargc; i++)
free(myargv[i]);
return 0;
}
/* Send a Fax */
int do_fax(int argc, char **argv)
{
FILE *f;
char str[LINESIZE + 1];
int i;
int reply = 0;
if (!strncmp(argv[0], "sr", 2)) {
reply = 1;
if (argc == 1) {
if (current == 0) {
printf("No current message to reply to.\n");
return 0;
}
i = current;
} else
i = atoi(argv[1]);
i--;
if ((i < 0) || (i >= messages)) {
printf("There's no message %s.\n", argv[1]);
return 0;
}
dot = &message[i];
}
if ((f = fopen(tempMesg, "w")) == NULL) {
printf("Could not create temporary file.\n");
syslog(LOG_NOTICE, "do_send: Could not create temporary file.\n");
return 0;
}
fprintf(f, "From: %s <%s@%s>\n", fullname, username, hostname);
str[0] = '\0';
if (argc != 1) /* Recipient on command line */
for (i = 1; i < argc; i++) {
if (i > 1)
strcat(str, " ");
strncat(str, argv[i], LINESIZE - strlen(str));
}
else {
}
printf("To: Fax Gateway\n");
fprintf( f, "To: %s\n", faxgate );
fprintf( f, "X-Mailer: %s\n", VERSION );
fprintf( f, "X-Origin: Amateur Radio Services\n" );
goto prio;;
/* adding priority receive rule */
prio:
/* if (reply) {
if (strncasecmp(dot->subj, "Re: ", 3))
snprintf(str, LINESIZE, "Re: %s", dot->subj);
else
snprintf(str, LINESIZE, "%s", dot->subj);
printf("Subject: %s\n", str);
} else */
getstr(str, LINESIZE, "Enter a header <firstname@fullphone Brief note here>\nEx: john@16195551212 Hi From Packet\nHeader: ");
fprintf(f, "Subject: %s\n", str);
if (reply)
fprintf(f, "In-Reply-To: %s\n", dot->id);
printf("Enter fax message (end with \"/ex\" or \".\" on a line by itself):\n");
fflush(stdout);
cont:
do {
/* fprintf( f, "X-Mailer: %s\n", VERSION );
fprintf( f, "X-Origin: Amateur Radio Services\n" ); */
fgets(str, LINESIZE, stdin);
if ( strcmp( str, ".\n") && strcmp( str, "/ex\n")) fputs(str, f);
} while (strcmp(str, ".\n") && strcmp(str, "/ex\n"));
retry:
getstr(str, LINESIZE, "Deliver (Y/n/c/?): ");
if (!strcmp(str, "?")) {
printf("Answering \"N\" here will cancel the message. Answering \"C\" will\n");
printf("let you continue writing the facsimile. Answering anything else will\n");
printf("proceed with delivering the facsimile to the recipient.\n");
goto retry;
}
if (!strcasecmp(str, "c")) {
printf("Continue entering facsimile text\n(end with \"/ex\" or \".\" on a line by itself):\n");
fflush(stdout);
goto cont;
}
if (fclose(f)) {
printf("Ouch, could not close temporary file.\n");
syslog(LOG_NOTICE, "do_send: Could not close temporary file.\n");
return 0;
}
if (strcasecmp(str, "n")) {
sprintf(str, "%s -oem -t < %s", BIN_AXMAIL_SENDMAIL, tempMesg);
system(str);
printf("Facsimile sent.\n");
} else
printf("Facsimile canceled.\n");
if (remove(tempMesg)) {
printf("Ouch, could not remove temporary file.\n");
syslog(LOG_NOTICE, "do_send: Could not remove temporary file.\n");
return 0;
}
return 0;
}