fix suppression of from address in mailing lists.
[unix-history] / usr / src / usr.bin / mail / main.c
CommitLineData
83f7d6ec
KS
1#
2
3#include "rcv.h"
4#include <sys/stat.h>
5
6/*
7 * Mail -- a mail program
8 *
9 * Startup -- interface with user.
10 */
11
12a8dbc7 12static char *SccsId = "@(#)main.c 2.2 %G%";
83f7d6ec
KS
13
14/*
15 * Find out who the user is, copy his mail file (if exists) into
16 * /tmp/Rxxxxx and set up the message pointers. Then, print out the
17 * message headers and read user commands.
18 *
19 * Command line syntax:
20 * Mail [ -i ] [ -r address ] [ -h number ] [ -f [ name ] ]
21 * or:
22 * Mail [ -i ] [ -r address ] [ -h number ] people ...
23 */
24
25main(argc, argv)
26 char **argv;
27{
28 register char *ef;
29 register int i, argp;
30 int mustsend, uflag;
31 FILE *ibuf, *ftat;
0b3c8268 32 extern char _sobuf[];
83f7d6ec
KS
33
34#ifdef signal
35 Siginit();
36#endif
37
38 /*
39 * Set up a reasonable environment. We clobber the last
40 * element of argument list for compatibility with version 6,
41 * figure out whether we are being run interactively, set up
42 * all the temporary files, buffer standard output, and so forth.
43 */
44
45 uflag = 0;
46 argv[argc] = (char *) -1;
47 mypid = getpid();
48 intty = isatty(0);
49 outtty = isatty(1);
50 image = -1;
51 setbuf(stdout, _sobuf);
52
53 /*
54 * Now, determine how we are being used.
55 * We successively pick off instances of -r, -h, -f, and -i.
56 * If called as "rmail" we note this fact for letter sending.
57 * If there is anything left, it is the base of the list
58 * of users to mail to. Argp will be set to point to the
59 * first of these users.
60 */
61
62 ef = NOSTR;
63 argp = -1;
64 mustsend = 0;
65 if (argc > 0 && **argv == 'r')
66 rmail++;
67 for (i = 1; i < argc; i++) {
68
69 /*
70 * If current argument is not a flag, then the
71 * rest of the arguments must be recipients.
72 */
73
74 if (*argv[i] != '-') {
75 argp = i;
76 break;
77 }
78 switch (argv[i][1]) {
79 case 'r':
80 /*
81 * Next argument is address to be sent along
82 * to the mailer.
83 */
84 if (i >= argc - 1) {
85 fprintf(stderr, "Address required after -r\n");
86 exit(1);
87 }
88 mustsend++;
89 rflag = argv[i+1];
90 i++;
91 break;
92
12a8dbc7
KS
93 case 'T':
94 /*
95 * Next argument is temp file to write which
96 * articles have been read/deleted for netnews.
97 */
98 if (i >= argc - 1) {
99 fprintf(stderr, "Name required after -T\n");
100 exit(1);
101 }
102 Tflag = argv[i+1];
103 i++;
104 break;
105
83f7d6ec
KS
106 case 'u':
107 /*
108 * Next argument is person to pretend to be.
109 */
110 uflag++;
111 if (i >= argc - 1) {
112 fprintf(stderr, "You obviously dont know what you're doing\n");
113 exit(1);
114 }
115 strcpy(myname, argv[i+1]);
116 i++;
117 break;
118
119 case 'i':
120 /*
121 * User wants to ignore interrupts.
122 * Set the variable "ignore"
123 */
124 assign("ignore", "");
125 break;
126
127 case 'd':
128 debug++;
129 break;
130
131 case 'h':
132 /*
133 * Specified sequence number for network.
134 * This is the number of "hops" made so
135 * far (count of times message has been
136 * forwarded) to help avoid infinite mail loops.
137 */
138 if (i >= argc - 1) {
139 fprintf(stderr, "Number required for -h\n");
140 exit(1);
141 }
142 mustsend++;
143 hflag = atoi(argv[i+1]);
144 if (hflag == 0) {
145 fprintf(stderr, "-h needs non-zero number\n");
146 exit(1);
147 }
148 i++;
149 break;
150
151 case 's':
152 /*
153 * Give a subject field for sending from
154 * non terminal
155 */
156 if (i >= argc - 1) {
157 fprintf(stderr, "Subject req'd for -s\n");
158 exit(1);
159 }
160 mustsend++;
161 sflag = argv[i+1];
162 i++;
163 break;
164
165 case 'f':
166 /*
167 * User is specifying file to "edit" with Mail,
168 * as opposed to reading system mailbox.
169 * If no argument is given after -f, we read his
170 * mbox file in his home directory.
171 */
172 if (i >= argc - 1)
173 ef = mbox;
174 else
175 ef = argv[i + 1];
176 i++;
177 break;
178
179 case 'n':
180 /*
181 * User doesn't want to source /usr/lib/Mail.rc
182 */
183 nosrc++;
184 break;
185
da8590df
KS
186 case 'N':
187 /*
188 * Avoid initial header printing.
189 */
190 noheader++;
191 break;
192
83f7d6ec
KS
193 default:
194 fprintf(stderr, "Unknown flag: %s\n", argv[i]);
195 exit(1);
196 }
197 }
198
199 /*
200 * Check for inconsistent arguments.
201 */
202
203 if (rflag != NOSTR && strcmp(rflag, "daemon") == 0) {
204 ftat = fopen("/crp/kas/gotcha", "a");
205 if (ftat != NULL) {
206 fprintf(ftat, "user daemon, real uid %d\n", getuid());
207 fclose(ftat);
208 }
209 }
210 if (ef != NOSTR && argp != -1) {
211 fprintf(stderr, "Cannot give -f and people to send to.\n");
212 exit(1);
213 }
214 if (mustsend && argp == -1) {
215 fprintf(stderr, "The flags you gave make no sense since you're not sending mail.\n");
216 exit(1);
217 }
218 tinit();
219 if (argp != -1) {
220 commands();
221 mail(&argv[argp]);
222
223 /*
224 * why wait?
225 */
226
227 exit(senderr);
228 }
229
230 /*
231 * Ok, we are reading mail.
232 * Decide whether we are editing a mailbox or reading
233 * the system mailbox, and open up the right stuff.
234 */
235
236 rcvmode++;
237 if (ef != NOSTR) {
238 edit++;
239 editfile = mailname = ef;
83f7d6ec 240 }
0b3c8268 241 if (setfile(mailname, edit) < 0)
83f7d6ec 242 exit(1);
83f7d6ec 243 commands();
714288d2
KS
244 if (!edit) {
245 sigset(SIGHUP, SIG_IGN);
246 sigset(SIGINT, SIG_IGN);
247 sigset(SIGQUIT, SIG_IGN);
83f7d6ec 248 quit();
714288d2 249 }
83f7d6ec
KS
250 exit(0);
251}