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
|
|
168 /* */
|
|
169
|
|
170 /* ARGSUSED */
|
|
171
|
|
172 main (argc, argv)
|
|
173 int argc;
|
|
174 char *argv[];
|
|
175 {
|
|
176 int msgp = 0,
|
|
177 distsw = 0,
|
|
178 vecp = 1,
|
|
179 isdf = 0,
|
|
180 msgnum,
|
|
181 status;
|
|
182 char *cp,
|
|
183 *dfolder = NULL,
|
|
184 *maildir = NULL,
|
|
185 buf[100],
|
|
186 **ap,
|
|
187 **argp,
|
|
188 *arguments[MAXARGS],
|
|
189 *msgs[MAXARGS],
|
|
190 *vec[MAXARGS];
|
|
191 struct msgs *mp;
|
|
192 struct stat st;
|
|
193 #ifdef UCI
|
|
194 FILE *fp;
|
|
195 #endif /* UCI */
|
|
196
|
|
197 #ifdef LOCALE
|
|
198 setlocale(LC_ALL, "");
|
|
199 #endif
|
|
200 #ifdef JAPAN
|
|
201 ml_init();
|
|
202 #endif /* JAPAN */
|
|
203 invo_name = r1bindex (argv[0], '/');
|
|
204 if ((cp = m_find (invo_name)) != NULL) {
|
|
205 ap = brkstring (cp = getcpy (cp), " ", "\n");
|
|
206 ap = copyip (ap, arguments);
|
|
207 }
|
|
208 else
|
|
209 ap = arguments;
|
|
210 (void) copyip (argv + 1, ap);
|
|
211 argp = arguments;
|
|
212
|
|
213 vec[vecp++] = "-library";
|
|
214 vec[vecp++] = getcpy (m_maildir (""));
|
|
215
|
|
216 /* */
|
|
217
|
|
218 while (cp = *argp++) {
|
|
219 if (*cp == '-')
|
|
220 switch (smatch (++cp, switches)) {
|
|
221 case AMBIGSW:
|
|
222 ambigsw (cp, switches);
|
|
223 done (1);
|
|
224 case UNKWNSW:
|
|
225 adios (NULLCP, "-%s unknown\n", cp);
|
|
226 case HELPSW:
|
|
227 (void) sprintf (buf, "%s [file] [switches]", invo_name);
|
|
228 help (buf, switches);
|
|
229 done (1); /* thanks, phyl */
|
|
230
|
|
231 case DRAFTSW:
|
|
232 msgs[msgp++] = draft;
|
|
233 continue;
|
|
234
|
|
235 case DFOLDSW:
|
|
236 if (dfolder)
|
|
237 adios (NULLCP, "only one draft folder at a time!");
|
|
238 if (!(cp = *argp++) || *cp == '-')
|
|
239 adios (NULLCP, "missing argument to %s", argp[-2]);
|
|
240 dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp,
|
|
241 *cp != '@' ? TFOLDER : TSUBCWF);
|
|
242 continue;
|
|
243 case DMSGSW:
|
|
244 if (!(cp = *argp++) || *cp == '-')
|
|
245 adios (NULLCP, "missing argument to %s", argp[-2]);
|
|
246 msgs[msgp++] = cp;
|
|
247 continue;
|
|
248 case NDFLDSW:
|
|
249 dfolder = NULL;
|
|
250 isdf = NOTOK;
|
|
251 continue;
|
|
252
|
|
253 case PUSHSW:
|
|
254 pushsw++;
|
|
255 continue;
|
|
256 case NPUSHSW:
|
|
257 pushsw = 0;
|
|
258 continue;
|
|
259
|
|
260 case SPLITSW:
|
|
261 if (!(cp = *argp++) || sscanf (cp, "%d", &splitsw) != 1)
|
|
262 adios (NULLCP, "missing argument to %s", argp[-2]);
|
|
263 continue;
|
|
264
|
|
265 case UNIQSW:
|
|
266 unique++;
|
|
267 continue;
|
|
268 case NUNIQSW:
|
|
269 unique = 0;
|
|
270 continue;
|
|
271
|
|
272 case FORWSW:
|
|
273 forwsw++;
|
|
274 continue;
|
|
275 case NFORWSW:
|
|
276 forwsw = 0;
|
|
277 continue;
|
|
278
|
|
279 case VERBSW:
|
|
280 verbsw++;
|
|
281 vec[vecp++] = --cp;
|
|
282 continue;
|
|
283 case NVERBSW:
|
|
284 verbsw = 0;
|
|
285 vec[vecp++] = --cp;
|
|
286 continue;
|
|
287
|
|
288 case MIMESW:
|
|
289 #ifdef MIME
|
|
290 mime++;
|
|
291 vec[vecp++] = --cp;
|
|
292 #endif
|
|
293 continue;
|
|
294 case NMIMESW:
|
|
295 #ifdef MIME
|
|
296 mime = 0;
|
|
297 vec[vecp++] = --cp;
|
|
298 #endif
|
|
299 continue;
|
|
300
|
|
301 case DEBUGSW:
|
|
302 debugsw++; /* fall */
|
|
303 case NFILTSW:
|
|
304 case FRMTSW:
|
|
305 case NFRMTSW:
|
|
306 case MSGDSW:
|
|
307 case NMSGDSW:
|
|
308 case WATCSW:
|
|
309 case NWATCSW:
|
|
310 case MAILSW:
|
|
311 case SAMLSW:
|
|
312 case SENDSW:
|
|
313 case SOMLSW:
|
|
314 case ENCRSW:
|
|
315 case NENCRSW:
|
|
316 case SNOOPSW:
|
|
317 case QUEUESW:
|
|
318 case NRECOSW:
|
|
319 #ifdef MIME_HEADERS
|
|
320 case HENCDSW:
|
|
321 case NHENCDSW:
|
|
322 #endif /* MIME_HEADERS */
|
|
323 vec[vecp++] = --cp;
|
|
324 continue;
|
|
325
|
|
326 case ALIASW:
|
|
327 case FILTSW:
|
|
328 case WIDTHSW:
|
|
329 case CLIESW:
|
|
330 case SERVSW:
|
|
331 case RECORSW:
|
|
332 vec[vecp++] = --cp;
|
|
333 if (!(cp = *argp++) || *cp == '-')
|
|
334 adios (NULLCP, "missing argument to %s", argp[-2]);
|
|
335 vec[vecp++] = cp;
|
|
336 continue;
|
|
337 }
|
|
338 else
|
|
339 msgs[msgp++] = cp;
|
|
340 }
|
|
341 if (cp = m_find ("Aliasfile")) { /* allow Aliasfile: profile entry */
|
|
342 char *dp = NULL;
|
|
343
|
|
344 for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap; ap++) {
|
|
345 vec[vecp++] = "-alias";
|
|
346 vec[vecp++] = *ap;
|
|
347 }
|
|
348 }
|
|
349
|
|
350 /* */
|
|
351
|
|
352 if (dfolder == NULL) {
|
|
353 if (msgp == 0) {
|
|
354 #ifdef WHATNOW
|
|
355 if ((cp = getenv ("mhdraft")) && *cp) {
|
|
356 msgs[msgp++] = cp;
|
|
357 goto go_to_it;
|
|
358 }
|
|
359 #endif /* WHATNOW */
|
|
360 msgs[msgp++] = getcpy (m_draft (NULLCP, NULLCP, 1, &isdf));
|
|
361 if (stat (msgs[0], &st) == NOTOK)
|
|
362 adios (msgs[0], "unable to stat draft file");
|
|
363 cp = concat ("Use \"", msgs[0], "\"? ", NULLCP);
|
|
364 for (status = LISTDSW; status != YESW;) {
|
|
365 if (!(argp = getans (cp, anyl)))
|
|
366 done (1);
|
|
367 switch (status = smatch (*argp, anyl)) {
|
|
368 case NOSW:
|
|
369 done (0);
|
|
370 case YESW:
|
|
371 break;
|
|
372 case LISTDSW:
|
|
373 (void) showfile (++argp, msgs[0]);
|
|
374 break;
|
|
375 default:
|
|
376 advise (NULLCP, "say what?");
|
|
377 break;
|
|
378 }
|
|
379 }
|
|
380 }
|
|
381 else
|
|
382 for (msgnum = 0; msgnum < msgp; msgnum++)
|
|
383 msgs[msgnum] = getcpy (m_maildir (msgs[msgnum]));
|
|
384 }
|
|
385 else {
|
|
386 if (!m_find ("path"))
|
|
387 free (path ("./", TFOLDER));
|
|
388
|
|
389 if (!msgp)
|
|
390 msgs[msgp++] = "cur";
|
|
391 maildir = m_maildir (dfolder);
|
|
392
|
|
393 if (chdir (maildir) == NOTOK)
|
|
394 adios (maildir, "unable to change directory to");
|
|
395 if (!(mp = m_gmsg (dfolder)))
|
|
396 adios (NULLCP, "unable to read folder %s", dfolder);
|
|
397 if (mp -> hghmsg == 0)
|
|
398 adios (NULLCP, "no messages in %s", dfolder);
|
|
399
|
|
400 for (msgnum = 0; msgnum < msgp; msgnum++)
|
|
401 if (!m_convert (mp, msgs[msgnum]))
|
|
402 done (1);
|
|
403 m_setseq (mp);
|
|
404
|
|
405 for (msgp = 0, msgnum = mp -> lowsel; msgnum <= mp -> hghsel; msgnum++)
|
|
406 if (mp -> msgstats[msgnum] & SELECTED) {
|
|
407 msgs[msgp++] = getcpy (m_name (msgnum));
|
|
408 #ifdef notdef
|
|
409 mp -> msgstats[msgnum] |= DELETED;
|
|
410 #endif /* notdef */
|
|
411 mp -> msgstats[msgnum] &= ~EXISTS;
|
|
412 }
|
|
413 mp -> msgflags |= SEQMOD;
|
|
414
|
|
415 m_sync (mp);
|
|
416 }
|
|
417 #ifdef WHATNOW
|
|
418 go_to_it: ;
|
|
419 #endif /* WHATNOW */
|
|
420
|
|
421 /* */
|
|
422
|
|
423 #ifdef TMA
|
|
424 if ((cp = getenv ("KDS")) == NULL || *cp == 0)
|
|
425 if ((cp = m_find ("kdsproc")) && *cp)
|
|
426 (void) m_putenv ("KDS", cp);
|
|
427 if ((cp = getenv ("TMADB")) == NULL || *cp == 0)
|
|
428 if ((cp = m_find ("tmadb")) && *cp)
|
|
429 (void) m_putenv ("TMADB", m_maildir (cp));
|
|
430 #endif /* TMA */
|
|
431
|
|
432 if ((cp = getenv ("SIGNATURE")) == NULL || *cp == 0)
|
|
433 if ((cp = m_find ("signature")) && *cp)
|
|
434 (void) m_putenv ("SIGNATURE", cp);
|
|
435 #ifdef UCI
|
|
436 else {
|
|
437 (void) sprintf (buf, "%s/.signature", mypath);
|
|
438 if ((fp = fopen (buf, "r")) != NULL
|
|
439 && fgets (buf, sizeof buf, fp) != NULL) {
|
|
440 (void) fclose (fp);
|
|
441 if (cp = index (buf, '\n'))
|
|
442 *cp = 0;
|
|
443 (void) m_putenv ("SIGNATURE", buf);
|
|
444 }
|
|
445 }
|
|
446 #endif /* UCI */
|
|
447
|
|
448 for (msgnum = 0; msgnum < msgp; msgnum++)
|
|
449 if (stat (msgs[msgnum], &st) == NOTOK)
|
|
450 adios (msgs[msgnum], "unable to stat draft file");
|
|
451
|
|
452 if ((annotext = getenv ("mhannotate")) == NULL || *annotext == 0)
|
|
453 annotext = NULL;
|
|
454 if (annotext && ((cp = getenv ("mhinplace")) != NULL && *cp != 0))
|
|
455 inplace = atoi (cp);
|
|
456 if ((altmsg = getenv ("mhaltmsg")) == NULL || *altmsg == 0)
|
|
457 altmsg = NULL; /* used by dist interface - see below */
|
|
458
|
|
459 if ((cp = getenv ("mhdist"))
|
|
460 && *cp
|
|
461 && (distsw = atoi (cp))
|
|
462 && altmsg) {
|
|
463 vec[vecp++] = "-dist";
|
|
464 distfile = getcpy (m_scratch (altmsg, invo_name));
|
|
465 if (link (altmsg, distfile) == NOTOK) {
|
|
466 if (errno != EXDEV
|
|
467 #ifdef EISREMOTE
|
|
468 && errno != EISREMOTE
|
|
469 #endif /* EISREMOTE */
|
|
470 )
|
|
471 adios (distfile, "unable to link %s to", altmsg);
|
|
472 free (distfile);
|
|
473 distfile = getcpy (m_tmpfil (invo_name));
|
|
474 {
|
|
475 int in, out;
|
|
476 struct stat st;
|
|
477
|
|
478 if ((in = open (altmsg, 0)) == NOTOK)
|
|
479 adios (altmsg, "unable to open");
|
|
480 (void) fstat(in, &st);
|
|
481 if ((out = creat (distfile, (int) st.st_mode & 0777)) == NOTOK)
|
|
482 adios (distfile, "unable to write");
|
|
483 cpydata (in, out, altmsg, distfile);
|
|
484 (void) close (in);
|
|
485 (void) close (out);
|
|
486 }
|
|
487 }
|
|
488 }
|
|
489 else
|
|
490 distfile = NULL;
|
|
491
|
|
492 if (altmsg == NULL || stat (altmsg, &st) == NOTOK)
|
|
493 st.st_mtime = 0, st.st_dev = 0, st.st_ino = 0;
|
|
494 if (pushsw)
|
|
495 push ();
|
|
496
|
|
497 status = 0;
|
|
498 vec[0] = r1bindex (postproc, '/');
|
|
499 closefds (3);
|
|
500
|
|
501 for (msgnum = 0; msgnum < msgp; msgnum++)
|
|
502 switch (sendsbr (vec, vecp, msgs[msgnum], &st)) {
|
|
503 case DONE:
|
|
504 done (++status);
|
|
505
|
|
506 case NOTOK:
|
|
507 status++; /* fall */
|
|
508 case OK:
|
|
509 break;
|
|
510 }
|
|
511
|
|
512 m_update ();
|
|
513
|
|
514 done (status);
|
|
515 }
|