-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommand.c
More file actions
178 lines (156 loc) · 3.6 KB
/
command.c
File metadata and controls
178 lines (156 loc) · 3.6 KB
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
/* command.c - Commands which have nothing to do with mail... */
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <unistd.h>
#include <time.h>
#include "defines.h"
#include "command.h"
#include "config.h"
#include "mailcmd.h"
#include "mbox.h"
#include "utils.h"
#include "quit.h"
void getsig(char *signature);
void getaddy(char *forward);
struct cmd Mailcmds[] = {
{ "?", do_help },
{ "Autofwd", do_forward },
{ "Bye", do_exit },
{ "Cancel", do_quit },
{ "Delete", do_kill },
{ "Exit", do_exit },
{ "Help", do_help },
{ "Info", do_help },
{ "Kill", do_kill },
{ "List", do_list },
{ "Name", do_name },
{ "Quit", do_exit },
{ "Read", do_read },
{ "Send", do_send },
{ "SFax", do_fax },
{ "SIg", do_signature },
{ "SPers", do_psend },
{ "SReply", do_send },
{ "STatus", do_status },
{ "Unkill", do_unkill },
{ "Verbose", do_read },
{ NULL, NULL }
};
int do_status(int argc, char **argv)
{
printf("Messages: %i\n", messages);
return 0;
}
int do_name(int argc, char **argv)
{
char name[32];
getname(name);
if (strlen(name) == 0)
printf("Name not changed. ");
else { /* Okay, save it */
strcpy(fullname, name);
}
printf("You're now known as %s.\n", fullname);
return 0;
}
/* int do_forward(int argc, char **argv) */
int do_forward(int argc, char **argv)
{
char *email;
char *fwdfile;
char fwd[79];
char forward[79];
getaddy(fwd);
FILE *fptr;
sprintf(forward, "%s/.forward", homedir);
fwdfile = strdup(forward);
fptr = fopen(fwdfile, "w+");
fprintf(fptr, "%s", fwd);
while (! *fwd) {
fclose(fptr);
remove(fwdfile);
printf("Forwarding halted, forward file removed.\n");
return 0;
}
printf("You're mail will be sent to:\n%s\nThank you.\n", fwd);
fclose(fptr);
return 0;
}
/* int do_signature(int argc, char **argv) */
int do_signature(int argc, char **argv)
{
char *sigfile;
char sig[79];
char signature[79];
getsig(sig);
FILE *fptr;
sprintf(signature, "%s/.signature", homedir);
sigfile = strdup(signature);
fptr = fopen(sigfile, "w+");
fprintf(fptr, "%s\n", sig);
while (! *sig) {
fclose(fptr);
remove(sigfile);
printf("Signature file deleted.\n");
return 0;
}
printf("You're signature is set to:\n%s\nThank you.\n", sig);
fclose(fptr);
return 0;
}
int do_help(int argc, char **argv)
{
FILE *fp;
char fname[80], line[256];
struct cmd *cmdp;
int i = 0;
if (*argv[0] == '?') { /* "?" */
printf("Commands:\n");
for (cmdp = Mailcmds; cmdp->name != NULL; cmdp++) {
printf("%s%s", i ? ", " : "", cmdp->name);
if (++i == 10) {
printf("\n");
i = 0;
}
}
if (i) printf("\n");
return 0;
}
strcpy(fname, DATA_AXMAIL_HELP_DIR);
if (*argv[0] == 'i') { /* "info" */
strcat(fname, "info.hlp");
printf("%s - %s\n", VERSION, COPYRIGHT);
printf("%s", LICENSE);
} else if (argc == 1) { /* "help" */
strcat(fname, "help.hlp");
} else { /* "help <cmd>" */
if (strchr(argv[1], '/') == NULL) {
strlwr(argv[1]);
strcat(fname, argv[1]);
strcat(fname, ".hlp");
}
}
if ((fp = fopen(fname, "r")) == NULL) {
if (*argv[0] != 'i')
printf("No help for command %s.\n", argv[1] ? argv[1] : "help");
return 0;
}
if (*argv[0] != 'i')
printf("Help for command %s:\n", argv[1] ? argv[1] : "help");
while (fgets(line, 256, fp) != NULL) {
printf("%s", line);
}
fclose(fp);
return 0;
}
int do_quit(int argc, char **argv)
{
quit(0, 0);
return 0;
}
int do_exit(int argc, char **argv)
{
quit(1, 0);
return 0;
}