0
|
1 /* send.c - send a composed message */
|
|
2 #ifndef lint
|
|
3 static char ident[] = "@(#)$Id$";
|
|
4 #endif /* lint */
|
|
5
|
|
6 #include "../h/mh.h"
|
|
7 #include <errno.h>
|
|
8 #include <stdio.h>
|
|
9 #include <signal.h>
|
|
10 #include <sys/types.h>
|
|
11 #include <sys/stat.h>
|
|
12 #ifdef LOCALE
|
|
13 #include <locale.h>
|
|
14 #endif
|
|
15
|
|
16 /* */
|
|
17
|
|
18 #ifndef TMA
|
|
19 #define TMAminc(a) (a)
|
|
20 #else /* TMA */
|
|
21 #define TMAminc(a) 0
|
|
22 #endif /* TMA */
|
|
23
|
|
24 #ifndef MIME
|
|
25 #define MIMEminc(a) (a)
|
|
26 #else
|
|
27 #define MIMEminc(a) 0
|
|
28 #endif
|
|
29
|
|
30 static struct swit switches[] = {
|
|
31 #define ALIASW 0
|
|
32 "alias aliasfile", 0,
|
|
33
|
|
34 #define DEBUGSW 1
|
|
35 "debug", -5,
|
|
36
|
|
37 #define DRAFTSW 2
|
|
38 "draft", 0,
|
|
39
|
|
40 #define DFOLDSW 3
|
|
41 "draftfolder +folder", 6,
|
|
42 #define DMSGSW 4
|
|
43 "draftmessage msg", 6,
|
|
44 #define NDFLDSW 5
|
|
45 "nodraftfolder", 0,
|
|
46
|
|
47 #define ENCRSW 6
|
|
48 "encrypt", TMAminc (-7),
|
|
49 #define NENCRSW 7
|
|
50 "noencrypt", TMAminc (-9),
|
|
51
|
|
52 #define FILTSW 8
|
|
53 "filter filterfile", 0,
|
|
54 #define NFILTSW 9
|
|
55 "nofilter", 0,
|
|
56
|
|
57 #define FRMTSW 10
|
|
58 "format", 0,
|
|
59 #define NFRMTSW 11
|
|
60 "noformat", 0,
|
|
61
|
|
62 #define FORWSW 12
|
|
63 "forward", 0,
|
|
64 #define NFORWSW 13
|
|
65 "noforward", 0,
|
|
66
|
|
67 #define MIMESW 14
|
|
68 "mime", MIMEminc(-4),
|
|
69 #define NMIMESW 15
|
|
70 "nomime", MIMEminc(-6),
|
|
71
|
|
72 #define MSGDSW 16
|
|
73 "msgid", 0,
|
|
74 #define NMSGDSW 17
|
|
75 "nomsgid", 0,
|
|
76
|
|
77 #define PUSHSW 18
|
|
78 "push", 0,
|
|
79 #define NPUSHSW 19
|
|
80 "nopush", 0,
|
|
81
|
|
82 #define SPLITSW 20
|
|
83 "split seconds", MIMEminc(-5),
|
|
84
|
|
85 #define UNIQSW 21
|
|
86 "unique", -6,
|
|
87 #define NUNIQSW 22
|
|
88 "nounique", -8,
|
|
89
|
|
90 #define VERBSW 23
|
|
91 "verbose", 0,
|
|
92 #define NVERBSW 24
|
|
93 "noverbose", 0,
|
|
94
|
|
95 #define WATCSW 25
|
|
96 "watch", 0,
|
|
97 #define NWATCSW 26
|
|
98 "nowatch", 0,
|
|
99
|
|
100 #define WIDTHSW 27
|
|
101 "width columns", 0,
|
|
102
|
|
103 #define HELPSW 28
|
|
104 "help", 4,
|
|
105
|
|
106 #define MAILSW 29
|
|
107 "mail", -4,
|
|
108 #define SAMLSW 30
|
|
109 "saml", -4,
|
|
110 #define SENDSW 31
|
|
111 "send", -4,
|
|
112 #define SOMLSW 32
|
|
113 "soml", -4,
|
|
114
|
|
115 #define CLIESW 33
|
|
116 "client host", -6,
|
|
117 #define SERVSW 34
|
|
118 "server host", -6,
|
|
119 #define SNOOPSW 35
|
|
120 "snoop", -5,
|
|
121
|
|
122 #define QUEUESW 36
|
|
123 "queued", -6,
|
|
124
|
|
125 #define RECORSW 37
|
|
126 "record program", -6,
|
|
127 #define NRECOSW 38
|
|
128 "norecord", -8,
|
|
129
|
|
130 #ifdef MIME_HEADERS
|
|
131 #define HENCDSW 39
|
|
132 "hencode", 0,
|
|
133 #define NHENCDSW 40
|
|
134 "nohencode", 0,
|
|
135 #endif /* MIME_HEADERS */
|
|
136
|
|
137 NULL, 0
|
|
138 };
|
|
139
|
|
140 static struct swit anyl[] = {
|
|
141 #define NOSW 0
|
|
142 "no", 0,
|
|
143 #define YESW 1
|
|
144 "yes", 0,
|
|
145 #define LISTDSW 2
|
|
146 "list", 0,
|
|
147
|
|
148 NULL, 0
|
|
149 };
|
|
150
|
|
151 /* */
|
|
152
|
|
153 extern int debugsw; /* from sendsbr.c */
|
|
154 extern int forwsw;
|
|
155 extern int inplace;
|
|
156 extern int mime;
|
|
157 extern int pushsw;
|
|
158 extern int splitsw;
|
|
159 extern int unique;
|
|
160 extern int verbsw;
|
|
161
|
|
162 extern char *altmsg; /* .. */
|
|
163 extern char *annotext;
|
|
164 extern char *distfile;
|
|
165
|
|
166
|
|
167 extern int errno;
|
|
168
|
|
169 /* */
|
|
170
|
|
171 /* ARGSUSED */
|
|
172
|
|
173 main (argc, argv)
|
|
174 int argc;
|
|
175 char *argv[];
|
|
176 {
|
|
177 int msgp = 0,
|
|
178 distsw = 0,
|
|
179 vecp = 1,
|
|
180 isdf = 0,
|
|
181 msgnum,
|
|
182 status;
|
|
183 char *cp,
|
|
184 *dfolder = NULL,
|
|
185 *maildir = NULL,
|
|
186 buf[100],
|
|
187 **ap,
|
|
188 **argp,
|
|
189 *arguments[MAXARGS],
|
|
190 *msgs[MAXARGS],
|
|
191 *vec[MAXARGS];
|
|
192 struct msgs *mp;
|
|
193 struct stat st;
|
|
194 #ifdef UCI
|
|
195 FILE *fp;
|
|
196 #endif /* UCI */
|
|
197
|
|
198 #ifdef LOCALE
|
|
199 setlocale(LC_ALL, "");
|
|
200 #endif
|
|
201 #ifdef JAPAN
|
|
202 ml_init();
|
|
203 #endif /* JAPAN */
|
|
204 invo_name = r1bindex (argv[0], '/');
|
|
205 if ((cp = m_find (invo_name)) != NULL) {
|
|
206 ap = brkstring (cp = getcpy (cp), " ", "\n");
|
|
207 ap = copyip (ap, arguments);
|
|
208 }
|
|
209 else
|
|
210 ap = arguments;
|
|
211 (void) copyip (argv + 1, ap);
|
|
212 argp = arguments;
|
|
213
|
|
214 vec[vecp++] = "-library";
|
|
215 vec[vecp++] = getcpy (m_maildir (""));
|
|
216
|
|
217 /* */
|
|
218
|
|
219 while (cp = *argp++) {
|
|
220 if (*cp == '-')
|
|
221 switch (smatch (++cp, switches)) {
|
|
222 case AMBIGSW:
|
|
223 ambigsw (cp, switches);
|
|
224 done (1);
|
|
225 case UNKWNSW:
|
|
226 adios (NULLCP, "-%s unknown\n", cp);
|
|
227 case HELPSW:
|
|
228 (void) sprintf (buf, "%s [file] [switches]", invo_name);
|
|
229 help (buf, switches);
|
|
230 done (1); /* thanks, phyl */
|
|
231
|
|
232 case DRAFTSW:
|
|
233 msgs[msgp++] = draft;
|
|
234 continue;
|
|
235
|
|
236 case DFOLDSW:
|
|
237 if (dfolder)
|
|
238 adios (NULLCP, "only one draft folder at a time!");
|
|
239 if (!(cp = *argp++) || *cp == '-')
|
|
240 adios (NULLCP, "missing argument to %s", argp[-2]);
|
|
241 dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp,
|
|
242 *cp != '@' ? TFOLDER : TSUBCWF);
|
|
243 continue;
|
|
244 case DMSGSW:
|
|
245 if (!(cp = *argp++) || *cp == '-')
|
|
246 adios (NULLCP, "missing argument to %s", argp[-2]);
|
|
247 msgs[msgp++] = cp;
|
|
248 continue;
|
|
249 case NDFLDSW:
|
|
250 dfolder = NULL;
|
|
251 isdf = NOTOK;
|
|
252 continue;
|
|
253
|
|
254 case PUSHSW:
|
|
255 pushsw++;
|
|
256 continue;
|
|
257 case NPUSHSW:
|
|
258 pushsw = 0;
|
|
259 continue;
|
|
260
|
|
261 case SPLITSW:
|
|
262 if (!(cp = *argp++) || sscanf (cp, "%d", &splitsw) != 1)
|
|
263 adios (NULLCP, "missing argument to %s", argp[-2]);
|
|
264 continue;
|
|
265
|
|
266 case UNIQSW:
|
|
267 unique++;
|
|
268 continue;
|
|
269 case NUNIQSW:
|
|
270 unique = 0;
|
|
271 continue;
|
|
272
|
|
273 case FORWSW:
|
|
274 forwsw++;
|
|
275 continue;
|
|
276 case NFORWSW:
|
|
277 forwsw = 0;
|
|
278 continue;
|
|
279
|
|
280 case VERBSW:
|
|
281 verbsw++;
|
|
282 vec[vecp++] = --cp;
|
|
283 continue;
|
|
284 case NVERBSW:
|
|
285 verbsw = 0;
|
|
286 vec[vecp++] = --cp;
|
|
287 continue;
|
|
288
|
|
289 case MIMESW:
|
|
290 #ifdef MIME
|
|
291 mime++;
|
|
292 vec[vecp++] = --cp;
|
|
293 #endif
|
|
294 continue;
|
|
295 case NMIMESW:
|
|
296 #ifdef MIME
|
|
297 mime = 0;
|
|
298 vec[vecp++] = --cp;
|
|
299 #endif
|
|
300 continue;
|
|
301
|
|
302 case DEBUGSW:
|
|
303 debugsw++; /* fall */
|
|
304 case NFILTSW:
|
|
305 case FRMTSW:
|
|
306 case NFRMTSW:
|
|
307 case MSGDSW:
|
|
308 case NMSGDSW:
|
|
309 case WATCSW:
|
|
310 case NWATCSW:
|
|
311 case MAILSW:
|
|
312 case SAMLSW:
|
|
313 case SENDSW:
|
|
314 case SOMLSW:
|
|
315 case ENCRSW:
|
|
316 case NENCRSW:
|
|
317 case SNOOPSW:
|
|
318 case QUEUESW:
|
|
319 case NRECOSW:
|
|
320 #ifdef MIME_HEADERS
|
|
321 case HENCDSW:
|
|
322 case NHENCDSW:
|
|
323 #endif /* MIME_HEADERS */
|
|
324 vec[vecp++] = --cp;
|
|
325 continue;
|
|
326
|
|
327 case ALIASW:
|
|
328 case FILTSW:
|
|
329 case WIDTHSW:
|
|
330 case CLIESW:
|
|
331 case SERVSW:
|
|
332 case RECORSW:
|
|
333 vec[vecp++] = --cp;
|
|
334 if (!(cp = *argp++) || *cp == '-')
|
|
335 adios (NULLCP, "missing argument to %s", argp[-2]);
|
|
336 vec[vecp++] = cp;
|
|
337 continue;
|
|
338 }
|
|
339 else
|
|
340 msgs[msgp++] = cp;
|
|
341 }
|
|
342 if (cp = m_find ("Aliasfile")) { /* allow Aliasfile: profile entry */
|
|
343 char *dp = NULL;
|
|
344
|
|
345 for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap; ap++) {
|
|
346 vec[vecp++] = "-alias";
|
|
347 vec[vecp++] = *ap;
|
|
348 }
|
|
349 }
|
|
350
|
|
351 /* */
|
|
352
|
|
353 if (dfolder == NULL) {
|
|
354 if (msgp == 0) {
|
|
355 #ifdef WHATNOW
|
|
356 if ((cp = getenv ("mhdraft")) && *cp) {
|
|
357 msgs[msgp++] = cp;
|
|
358 goto go_to_it;
|
|
359 }
|
|
360 #endif /* WHATNOW */
|
|
361 msgs[msgp++] = getcpy (m_draft (NULLCP, NULLCP, 1, &isdf));
|
|
362 if (stat (msgs[0], &st) == NOTOK)
|
|
363 adios (msgs[0], "unable to stat draft file");
|
|
364 cp = concat ("Use \"", msgs[0], "\"? ", NULLCP);
|
|
365 for (status = LISTDSW; status != YESW;) {
|
|
366 if (!(argp = getans (cp, anyl)))
|
|
367 done (1);
|
|
368 switch (status = smatch (*argp, anyl)) {
|
|
369 case NOSW:
|
|
370 done (0);
|
|
371 case YESW:
|
|
372 break;
|
|
373 case LISTDSW:
|
|
374 (void) showfile (++argp, msgs[0]);
|
|
375 break;
|
|
376 default:
|
|
377 advise (NULLCP, "say what?");
|
|
378 break;
|
|
379 }
|
|
380 }
|
|
381 }
|
|
382 else
|
|
383 for (msgnum = 0; msgnum < msgp; msgnum++)
|
|
384 msgs[msgnum] = getcpy (m_maildir (msgs[msgnum]));
|
|
385 }
|
|
386 else {
|
|
387 if (!m_find ("path"))
|
|
388 free (path ("./", TFOLDER));
|
|
389
|
|
390 if (!msgp)
|
|
391 msgs[msgp++] = "cur";
|
|
392 maildir = m_maildir (dfolder);
|
|
393
|
|
394 if (chdir (maildir) == NOTOK)
|
|
395 adios (maildir, "unable to change directory to");
|
|
396 if (!(mp = m_gmsg (dfolder)))
|
|
397 adios (NULLCP, "unable to read folder %s", dfolder);
|
|
398 if (mp -> hghmsg == 0)
|
|
399 adios (NULLCP, "no messages in %s", dfolder);
|
|
400
|
|
401 for (msgnum = 0; msgnum < msgp; msgnum++)
|
|
402 if (!m_convert (mp, msgs[msgnum]))
|
|
403 done (1);
|
|
404 m_setseq (mp);
|
|
405
|
|
406 for (msgp = 0, msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
|
|
407 if (mp -> msgstats[msgnum] & SELECTED) {
|
|
408 msgs[msgp++] = getcpy (m_name (msgnum));
|
|
409 #ifdef notdef
|
|
410 mp -> msgstats[msgnum] |= DELETED;
|
|
411 #endif /* notdef */
|
|
412 mp -> msgstats[msgnum] &= ~EXISTS;
|
|
413 }
|
|
414 mp -> msgflags |= SEQMOD;
|
|
415
|
|
416 m_sync (mp);
|
|
417 }
|
|
418 #ifdef WHATNOW
|
|
419 go_to_it: ;
|
|
420 #endif /* WHATNOW */
|
|
421
|
|
422 /* */
|
|
423
|
|
424 #ifdef TMA
|
|
425 if ((cp = getenv ("KDS")) == NULL || *cp == 0)
|
|
426 if ((cp = m_find ("kdsproc")) && *cp)
|
|
427 (void) m_putenv ("KDS", cp);
|
|
428 if ((cp = getenv ("TMADB")) == NULL || *cp == 0)
|
|
429 if ((cp = m_find ("tmadb")) && *cp)
|
|
430 (void) m_putenv ("TMADB", m_maildir (cp));
|
|
431 #endif /* TMA */
|
|
432
|
|
433 if ((cp = getenv ("SIGNATURE")) == NULL || *cp == 0)
|
|
434 if ((cp = m_find ("signature")) && *cp)
|
|
435 (void) m_putenv ("SIGNATURE", cp);
|
|
436 #ifdef UCI
|
|
437 else {
|
|
438 (void) sprintf (buf, "%s/.signature", mypath);
|
|
439 if ((fp = fopen (buf, "r")) != NULL
|
|
440 && fgets (buf, sizeof buf, fp) != NULL) {
|
|
441 (void) fclose (fp);
|
|
442 if (cp = index (buf, '\n'))
|
|
443 *cp = 0;
|
|
444 (void) m_putenv ("SIGNATURE", buf);
|
|
445 }
|
|
446 }
|
|
447 #endif /* UCI */
|
|
448
|
|
449 for (msgnum = 0; msgnum < msgp; msgnum++)
|
|
450 if (stat (msgs[msgnum], &st) == NOTOK)
|
|
451 adios (msgs[msgnum], "unable to stat draft file");
|
|
452
|
|
453 if ((annotext = getenv ("mhannotate")) == NULL || *annotext == 0)
|
|
454 annotext = NULL;
|
|
455 if (annotext && ((cp = getenv ("mhinplace")) != NULL && *cp != 0))
|
|
456 inplace = atoi (cp);
|
|
457 if ((altmsg = getenv ("mhaltmsg")) == NULL || *altmsg == 0)
|
|
458 altmsg = NULL; /* used by dist interface - see below */
|
|
459
|
|
460 if ((cp = getenv ("mhdist"))
|
|
461 && *cp
|
|
462 && (distsw = atoi (cp))
|
|
463 && altmsg) {
|
|
464 vec[vecp++] = "-dist";
|
|
465 distfile = getcpy (m_scratch (altmsg, invo_name));
|
|
466 if (link (altmsg, distfile) == NOTOK) {
|
|
467 if (errno != EXDEV
|
|
468 #ifdef EISREMOTE
|
|
469 && errno != EISREMOTE
|
|
470 #endif /* EISREMOTE */
|
|
471 )
|
|
472 adios (distfile, "unable to link %s to", altmsg);
|
|
473 free (distfile);
|
|
474 distfile = getcpy (m_tmpfil (invo_name));
|
|
475 {
|
|
476 int in, out;
|
|
477 struct stat st;
|
|
478
|
|
479 if ((in = open (altmsg, 0)) == NOTOK)
|
|
480 adios (altmsg, "unable to open");
|
|
481 (void) fstat(in, &st);
|
|
482 if ((out = creat (distfile, (int) st.st_mode & 0777)) == NOTOK)
|
|
483 adios (distfile, "unable to write");
|
|
484 cpydata (in, out, altmsg, distfile);
|
|
485 (void) close (in);
|
|
486 (void) close (out);
|
|
487 }
|
|
488 }
|
|
489 }
|
|
490 else
|
|
491 distfile = NULL;
|
|
492
|
|
493 if (altmsg == NULL || stat (altmsg, &st) == NOTOK)
|
|
494 st.st_mtime = 0, st.st_dev = 0, st.st_ino = 0;
|
|
495 if (pushsw)
|
|
496 push ();
|
|
497
|
|
498 status = 0;
|
|
499 vec[0] = r1bindex (postproc, '/');
|
|
500 closefds (3);
|
|
501
|
|
502 for (msgnum = 0; msgnum < msgp; msgnum++)
|
|
503 switch (sendsbr (vec, vecp, msgs[msgnum], &st)) {
|
|
504 case DONE:
|
|
505 done (++status);
|
|
506
|
|
507 case NOTOK:
|
|
508 status++; /* fall */
|
|
509 case OK:
|
|
510 break;
|
|
511 }
|
|
512
|
|
513 m_update ();
|
|
514
|
|
515 done (status);
|
|
516 }
|