0
|
1 /* whatnowsbr.c - the WhatNow shell */
|
|
2 #ifndef lint
|
12
|
3 static char ident[] = "@(#)$Id: whatnowsbr.c,v 1.1.1.1 2005/04/18 14:46:07 kono Exp $";
|
0
|
4 #endif /* lint */
|
|
5
|
|
6 #include "../h/mh.h"
|
|
7 #include <stdio.h>
|
|
8 #include <signal.h>
|
|
9 #include <sys/types.h>
|
|
10 #include <sys/stat.h>
|
|
11 #ifdef UNISTD
|
|
12 #include <unistd.h>
|
|
13 #endif
|
|
14
|
|
15 #ifndef MIME
|
|
16 #define MIMEminc(a) (a)
|
|
17 #else
|
|
18 #define MIMEminc(a) 0
|
|
19 #endif
|
|
20
|
16
|
21 static int editfile(), copyf(), sendfile(), whomfile();
|
|
22 static void sendit();
|
0
|
23 #ifdef MIME
|
|
24 static int mhnfile();
|
|
25 #endif
|
|
26 /* */
|
|
27
|
|
28 static struct swit whatnowswitches[] = {
|
|
29 #define DFOLDSW 0
|
|
30 "draftfolder +folder", 0,
|
|
31 #define DMSGSW 1
|
|
32 "draftmessage msg", 0,
|
|
33 #define NDFLDSW 2
|
|
34 "nodraftfolder", 0,
|
|
35
|
|
36 #define EDITRSW 3
|
|
37 "editor editor", 0,
|
|
38 #define NEDITSW 4
|
|
39 "noedit", 0,
|
|
40
|
|
41 #define PRMPTSW 5
|
|
42 "prompt string", 4,
|
|
43
|
|
44 #define HELPSW 6
|
|
45 "help", 4,
|
|
46
|
|
47 NULL, 0
|
|
48 };
|
|
49
|
|
50 /* */
|
|
51
|
|
52 static struct swit aleqs[] = {
|
|
53 #define DISPSW 0
|
|
54 "display [<switches>]", 0,
|
|
55 #define EDITSW 1
|
|
56 "edit [<editor> <switches>]", 0,
|
|
57 #define LISTSW 2
|
|
58 "list [<switches>]", 0,
|
|
59 #define PUSHSW 3
|
|
60 "push [<switches>]", 0,
|
|
61 #define QUITSW 4
|
|
62 "quit [-delete]", 0,
|
|
63 #define REFILEOPT 5
|
|
64 "refile [<switches>] +folder", 0,
|
|
65 #define SENDSW 6
|
|
66 "send [<switches>]", 0,
|
|
67 #define WHOMSW 7
|
|
68 "whom [<switches>]", 0,
|
|
69
|
|
70 NULL, 0
|
|
71 };
|
|
72
|
|
73 /* */
|
|
74
|
|
75 static char *myprompt = "\nWhat now? ";
|
|
76
|
|
77 /* */
|
|
78
|
|
79 /* ARGSUSED */
|
|
80
|
|
81 int WhatNow (argc, argv)
|
|
82 int argc;
|
|
83 char **argv;
|
|
84 {
|
|
85 int isdf = 0,
|
|
86 nedit = 0,
|
|
87 use = 0;
|
|
88 char *cp,
|
|
89 *dfolder = NULL,
|
|
90 *dmsg = NULL,
|
|
91 *ed = NULL,
|
|
92 *drft = NULL,
|
|
93 *msgnam = NULL,
|
|
94 buf[100],
|
|
95 prompt[BUFSIZ],
|
|
96 **ap,
|
|
97 **argp,
|
|
98 *arguments[MAXARGS];
|
|
99 struct stat st;
|
|
100
|
|
101 invo_name = r1bindex (argv[0], '/');
|
|
102 if ((cp = m_find (invo_name)) != NULL) {
|
|
103 ap = brkstring (cp = getcpy (cp), " ", "\n");
|
|
104 ap = copyip (ap, arguments);
|
|
105 }
|
|
106 else
|
|
107 ap = arguments;
|
|
108 (void) copyip (argv + 1, ap);
|
|
109 argp = arguments;
|
|
110
|
|
111 /* */
|
|
112
|
|
113 while (cp = *argp++) {
|
|
114 if (*cp == '-')
|
|
115 switch (smatch (++cp, whatnowswitches)) {
|
|
116 case AMBIGSW:
|
|
117 ambigsw (cp, whatnowswitches);
|
|
118 done (1);
|
|
119 case UNKWNSW:
|
|
120 adios (NULLCP, "-%s unknown", cp);
|
|
121 case HELPSW:
|
|
122 (void) sprintf (buf, "%s [switches] [file]", invo_name);
|
|
123 help (buf, whatnowswitches);
|
|
124 done (1);
|
|
125
|
|
126 case DFOLDSW:
|
|
127 if (dfolder)
|
|
128 adios (NULLCP, "only one draft folder at a time!");
|
|
129 if (!(cp = *argp++) || *cp == '-')
|
|
130 adios (NULLCP, "missing argument to %s", argp[-2]);
|
|
131 dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp,
|
|
132 *cp != '@' ? TFOLDER : TSUBCWF);
|
|
133 continue;
|
|
134 case DMSGSW:
|
|
135 if (dmsg)
|
|
136 adios (NULLCP, "only one draft message at a time!");
|
|
137 if (!(dmsg = *argp++) || *dmsg == '-')
|
|
138 adios (NULLCP, "missing argument to %s", argp[-2]);
|
|
139 continue;
|
|
140 case NDFLDSW:
|
|
141 dfolder = NULL;
|
|
142 isdf = NOTOK;
|
|
143 continue;
|
|
144
|
|
145 case EDITRSW:
|
|
146 if (!(ed = *argp++) || *ed == '-')
|
|
147 adios (NULLCP, "missing argument to %s", argp[-2]);
|
|
148 nedit = 0;
|
|
149 continue;
|
|
150 case NEDITSW:
|
|
151 nedit++;
|
|
152 continue;
|
|
153
|
|
154 case PRMPTSW:
|
|
155 if (!(myprompt = *argp++) || *myprompt == '-')
|
|
156 adios (NULLCP, "missing argument to %s", argp[-2]);
|
|
157 continue;
|
|
158 }
|
|
159 if (drft)
|
|
160 adios (NULLCP, "only one draft at a time!");
|
|
161 else
|
|
162 drft = cp;
|
|
163 }
|
|
164
|
|
165 /* */
|
|
166
|
|
167 if (drft == NULL && (drft = getenv ("mhdraft")) == NULL || *drft == 0)
|
|
168 drft = getcpy (m_draft (dfolder, dmsg, 1, &isdf));
|
|
169 msgnam = (cp = getenv ("mhaltmsg")) && *cp ? getcpy (cp) : NULLCP;
|
|
170 if (ed == NULL && ((ed = getenv ("mheditor")) == NULL || *ed == 0))
|
|
171 ed = NULL, nedit++;
|
|
172 if ((cp = getenv ("mhuse")) && *cp)
|
|
173 use = atoi (cp);
|
|
174 if (!nedit
|
|
175 && editfile (&ed, NULLVP, drft, use, NULLMP, msgnam, NULLCP) < 0)
|
|
176 done (1);
|
|
177
|
|
178 /* */
|
|
179
|
|
180 (void) sprintf (prompt, myprompt, invo_name);
|
|
181 for (;;) {
|
|
182 if (!(argp = getans (prompt, aleqs))) {
|
|
183 (void) unlink (LINK);
|
|
184 done (1);
|
|
185 }
|
|
186 switch (smatch (*argp, aleqs)) {
|
|
187 case DISPSW:
|
|
188 if (msgnam)
|
|
189 (void) showfile (++argp, msgnam);
|
|
190 else
|
|
191 advise (NULLCP, "no alternate message to display");
|
|
192 break;
|
|
193
|
|
194 case EDITSW:
|
|
195 if (*++argp)
|
|
196 ed = *argp++;
|
|
197 if (editfile (&ed, argp, drft, NOUSE, NULLMP, msgnam, NULLCP)
|
|
198 == NOTOK)
|
|
199 done (1);
|
|
200 break;
|
|
201
|
|
202 case LISTSW:
|
|
203 (void) showfile (++argp, drft);
|
|
204 break;
|
|
205
|
|
206 case WHOMSW:
|
|
207 (void) whomfile (++argp, drft);
|
|
208 break;
|
|
209
|
|
210 case QUITSW:
|
|
211 if (*++argp && (*argp[0] == 'd' ||
|
|
212 ((*argp)[0] == '-' && (*argp)[1] == 'd'))) {
|
|
213 if (unlink (drft) == NOTOK)
|
|
214 adios (drft, "unable to unlink");
|
|
215 }
|
|
216 else
|
|
217 if (stat (drft, &st) != NOTOK)
|
|
218 advise (NULLCP, "draft left on %s", drft);
|
|
219 done (1);
|
|
220
|
|
221 case PUSHSW:
|
|
222 if (sendfile (++argp, drft, 1))
|
|
223 done (1);
|
|
224 break;
|
|
225
|
|
226 case SENDSW:
|
|
227 (void) sendfile (++argp, drft, 0);
|
|
228 break;
|
|
229
|
|
230 case REFILEOPT:
|
|
231 if (refile (++argp, drft) == 0)
|
|
232 done (0);
|
|
233 break;
|
|
234
|
|
235 default:
|
|
236 advise (NULLCP, "say what?");
|
|
237 break;
|
|
238 }
|
|
239 }
|
|
240 /*NOTREACHED*/
|
|
241 }
|
|
242
|
|
243 /* EDIT */
|
|
244
|
|
245 static int reedit = 0;
|
|
246 static char *edsave = NULL;
|
|
247
|
|
248
|
|
249 /* ARGSUSED */
|
|
250
|
|
251 static int editfile (ed, arg, file, use, mp, altmsg, cwd)
|
|
252 register struct msgs *mp;
|
|
253 register char **ed,
|
|
254 **arg,
|
|
255 *file,
|
|
256 *altmsg,
|
|
257 *cwd;
|
|
258 register int use;
|
|
259 {
|
|
260 int pid,
|
|
261 status;
|
|
262 register int vecp;
|
|
263 register char *cp;
|
|
264 char altpath[BUFSIZ],
|
|
265 linkpath[BUFSIZ],
|
|
266 *vec[MAXARGS];
|
|
267 struct stat st;
|
|
268 #if defined(BSD42) || defined(SVR4)
|
|
269 #ifdef notdef
|
|
270 int oumask; /* PJS: for setting permissions on symlinks. */
|
|
271 #endif
|
|
272 int slinked;
|
|
273 #endif /* BSD42 || SVR4 */
|
|
274
|
|
275 if (!reedit) { /* set initial editor */
|
|
276 if (*ed == NULL && (*ed = m_find ("editor")) == NULL)
|
|
277 *ed = sysed;
|
|
278 }
|
|
279 else
|
|
280 if (!*ed) { /* no explicit editor */
|
|
281 *ed = edsave;
|
|
282 if ((cp = r1bindex (*ed, '/')) == NULL)
|
|
283 cp = *ed;
|
|
284 cp = concat (cp, "-next", NULLCP);
|
|
285 if ((cp = m_find (cp)) != NULL)
|
|
286 *ed = cp;
|
|
287 }
|
|
288
|
|
289 if (altmsg) {
|
|
290 if (mp == NULL || *altmsg == '/' || cwd == NULL)
|
|
291 (void) strcpy (altpath, altmsg);
|
|
292 else
|
|
293 (void) sprintf (altpath, "%s/%s", mp -> foldpath, altmsg);
|
|
294 if (cwd == NULL)
|
|
295 (void) strcpy (linkpath, LINK);
|
|
296 else
|
|
297 (void) sprintf (linkpath, "%s/%s", cwd, LINK);
|
|
298 }
|
|
299
|
|
300 if (altmsg) {
|
|
301 (void) unlink (linkpath);
|
|
302 #if defined(BSD42) || defined(SVR4)
|
|
303 if (link (altpath, linkpath) == NOTOK) {
|
|
304 #ifdef notdef /* I don't think permission on symlinks matters /JLR */
|
|
305 oumask = umask(0044); /* PJS: else symlinks are world 'r' */
|
|
306 #endif
|
|
307 (void) symlink (altpath, linkpath);
|
|
308 #ifdef notdef
|
|
309 umask(oumask); /* PJS: else symlinks are world 'r' */
|
|
310 #endif
|
|
311 slinked = 1;
|
|
312 }
|
|
313 else
|
|
314 slinked = 0;
|
|
315 #else /* not BSD42 && not SVR4 */
|
|
316 (void) link (altpath, linkpath);
|
|
317 #endif /* not BSD42 && not SVR4 */
|
|
318 }
|
|
319
|
|
320 m_update ();
|
|
321 (void) fflush (stdout);
|
|
322
|
|
323 switch (pid = vfork ()) {
|
|
324 case NOTOK:
|
|
325 advise ("fork", "unable to");
|
|
326 status = NOTOK;
|
|
327 break;
|
|
328
|
|
329 case OK:
|
|
330 if (cwd)
|
|
331 (void) chdir (cwd);
|
|
332 if (altmsg) {
|
|
333 if (mp)
|
|
334 (void) m_putenv ("mhfolder", mp -> foldpath);
|
|
335 (void) m_putenv ("editalt", altpath);
|
|
336 }
|
|
337
|
|
338 vecp = 0;
|
|
339 vec[vecp++] = r1bindex (*ed, '/');
|
|
340 if (arg)
|
|
341 while (*arg)
|
|
342 vec[vecp++] = *arg++;
|
|
343 vec[vecp++] = file;
|
|
344 vec[vecp] = NULL;
|
|
345
|
|
346 execvp (*ed, vec);
|
|
347 fprintf (stderr, "unable to exec ");
|
|
348 perror (*ed);
|
|
349 _exit (-1);
|
|
350
|
|
351 default:
|
|
352 if (status = pidwait (pid, NOTOK)) {
|
12
|
353 #if 0
|
0
|
354 #ifdef ATTVIBUG
|
|
355 if ((cp = r1bindex (*ed, '/'))
|
|
356 && strcmp (cp, "vi") == 0
|
|
357 && (status & 0x00ff) == 0)
|
|
358 status = 0;
|
|
359 else {
|
|
360 #endif
|
|
361 if (((status & 0xff00) != 0xff00)
|
|
362 && (!reedit || (status & 0x00ff)))
|
|
363 if (!use && (status & 0xff00) &&
|
|
364 (rename (file, cp = m_backup (file)) != NOTOK)) {
|
|
365 advise (NULLCP, "problems with edit--draft left in %s",
|
|
366 cp);
|
|
367 }
|
|
368 else
|
|
369 advise (NULLCP, "problems with edit--%s preserved",
|
|
370 file);
|
|
371 status = -2; /* maybe "reedit ? -2 : -1"? */
|
|
372 break;
|
|
373 #ifdef ATTVIBUG
|
|
374 }
|
|
375 #endif
|
12
|
376 #else
|
|
377 /* do nothing ... */
|
|
378 #endif
|
0
|
379 }
|
|
380
|
|
381 reedit++;
|
|
382 #if defined(BSD42) || defined(SVR4)
|
|
383 if (altmsg
|
|
384 && mp
|
|
385 && (!mp -> msgflags & READONLY)
|
|
386 && (slinked
|
|
387 ? lstat (linkpath, &st) != NOTOK
|
|
388 && (st.st_mode & S_IFMT) == S_IFREG
|
|
389 && copyf (linkpath, altpath) == NOTOK
|
|
390 : stat (linkpath, &st) != NOTOK
|
|
391 && st.st_nlink == 1
|
|
392 && (unlink (altpath) == NOTOK
|
|
393 || link (linkpath, altpath) == NOTOK)))
|
|
394 advise (linkpath, "unable to update %s from", altmsg);
|
|
395 #else /* not BSD42 && not SVR4 */
|
|
396 if (altmsg
|
|
397 && mp
|
|
398 && (!mp -> msgflags & READONLY)
|
|
399 && stat (linkpath, &st) != NOTOK
|
|
400 && st.st_nlink == 1
|
|
401 && (unlink (altpath) == NOTOK
|
|
402 || link (linkpath, altpath) == NOTOK))
|
|
403 advise (linkpath, "unable to update %s from", altmsg);
|
|
404 #endif /* not BSD42 && not SVR4 */
|
|
405 }
|
|
406
|
|
407 edsave = getcpy (*ed);
|
|
408 *ed = NULL;
|
|
409 if (altmsg)
|
|
410 (void) unlink (linkpath);
|
|
411
|
|
412 return status;
|
|
413 }
|
|
414
|
|
415 /* */
|
|
416
|
|
417 #if defined(BSD42) || defined(SVR4)
|
|
418 static int copyf (ifile, ofile)
|
|
419 register char *ifile,
|
|
420 *ofile;
|
|
421 {
|
|
422 register int i;
|
|
423 int in,
|
|
424 out;
|
|
425 char buffer[BUFSIZ];
|
|
426
|
|
427 if ((in = open (ifile, 0)) == NOTOK)
|
|
428 return NOTOK;
|
|
429 if ((out = open (ofile, 1)) == NOTOK || ftruncate (out, (off_t)0) == NOTOK) {
|
|
430 if (out != NOTOK) {
|
|
431 admonish (ofile, "unable to truncate");
|
|
432 (void) close (out);
|
|
433 }
|
|
434 (void) close (in);
|
|
435 return NOTOK;
|
|
436 }
|
|
437
|
|
438 while ((i = read (in, buffer, sizeof buffer)) > OK)
|
|
439 if (write (out, buffer, i) != i) {
|
|
440 advise (ofile, "may have damaged");
|
|
441 i = NOTOK;
|
|
442 break;
|
|
443 }
|
|
444
|
|
445 (void) close (in);
|
|
446 (void) close (out);
|
|
447
|
|
448 return i;
|
|
449 }
|
|
450 #endif /* BSD42 || SVR4 */
|
|
451
|
|
452 /* SEND */
|
|
453
|
|
454 static sendfile (arg, file, pushsw)
|
|
455 register char **arg,
|
|
456 *file;
|
|
457 int pushsw;
|
|
458 {
|
|
459 register int child_id,
|
|
460 i,
|
|
461 vecp;
|
|
462 char *cp,
|
|
463 *sp,
|
|
464 *vec[MAXARGS];
|
|
465
|
|
466 #ifdef MIME
|
|
467 if ((cp = m_find ("automhnproc"))
|
|
468 /* && !getenv ("NOMHNPROC") */
|
|
469 && mhnfile (file)
|
|
470 && (i = editfile (&cp, NULLVP, file, NOUSE, NULLMP, NULLCP,
|
|
471 NULLCP)))
|
|
472 return 0;
|
|
473 #endif
|
|
474
|
|
475 if (strcmp (sp = r1bindex (sendproc, '/'), "send") == 0) {
|
|
476 cp = invo_name;
|
|
477 sendit (invo_name = sp, arg, file, pushsw);
|
|
478 invo_name = cp;
|
|
479 return 1;
|
|
480 }
|
|
481
|
|
482 m_update ();
|
|
483 (void) fflush (stdout);
|
|
484
|
|
485 for (i = 0; (child_id = vfork ()) == NOTOK && i < 5; i++)
|
|
486 sleep (5);
|
|
487 switch (child_id) {
|
|
488 case NOTOK:
|
|
489 advise (NULLCP, "unable to fork, so sending directly...");
|
|
490 case OK:
|
|
491 vecp = 0;
|
|
492 vec[vecp++] = invo_name;
|
|
493 if (pushsw)
|
|
494 vec[vecp++] = "-push";
|
|
495 if (arg)
|
|
496 while (*arg)
|
|
497 vec[vecp++] = *arg++;
|
|
498 vec[vecp++] = file;
|
|
499 vec[vecp] = NULL;
|
|
500
|
|
501 execvp (sendproc, vec);
|
|
502 fprintf (stderr, "unable to exec ");
|
|
503 perror (sendproc);
|
|
504 _exit (-1);
|
|
505
|
|
506 default:
|
|
507 if (pidwait (child_id, OK) == 0)
|
|
508 done (0);
|
|
509 return 1;
|
|
510 }
|
|
511 }
|
|
512
|
|
513 /* */
|
|
514
|
|
515 #ifdef MIME
|
|
516 #include "../h/mhn.h"
|
|
517
|
|
518
|
|
519 static int mhnfile (msgnam)
|
|
520 char *msgnam;
|
|
521 {
|
|
522 int state;
|
|
523 char buf[BUFSIZ],
|
|
524 name[NAMESZ];
|
|
525 FILE *fp;
|
|
526
|
|
527 if ((fp = fopen (msgnam, "r")) == NULL)
|
|
528 return 0;
|
|
529 for (state = FLD;;)
|
|
530 switch (state = m_getfld (state, name, buf, sizeof buf, fp)) {
|
|
531 case FLD:
|
|
532 case FLDPLUS:
|
|
533 case FLDEOF:
|
|
534 if (uleq (name, VRSN_FIELD) || uprf (name, XXX_FIELD_PRF)) {
|
|
535 (void) fclose (fp);
|
|
536 return 0;
|
|
537 }
|
|
538 while (state == FLDPLUS)
|
|
539 state = m_getfld (state, name, buf, sizeof buf, fp);
|
|
540 break;
|
|
541
|
|
542 case BODY:
|
|
543 do {
|
|
544 register char *bp;
|
|
545
|
|
546 for (bp = buf; *bp; bp++)
|
|
547 if (*bp != ' ' && *bp != '\t' && *bp != '\n') {
|
|
548 (void) fclose (fp);
|
|
549 return 1;
|
|
550 }
|
|
551
|
|
552 state = m_getfld (state, name, buf, sizeof buf, fp);
|
|
553 } while (state == BODY);
|
|
554 /* and fall... */
|
|
555
|
|
556 default:
|
|
557 (void) fclose (fp);
|
|
558 return 0;
|
|
559 }
|
|
560 }
|
|
561 #endif /* MIME */
|
|
562
|
|
563 /* */
|
|
564
|
|
565 static struct swit sendswitches[] = {
|
|
566 #define ALIASW 0
|
|
567 "alias aliasfile", 0,
|
|
568
|
|
569 #define DEBUGSW 1
|
|
570 "debug", -5,
|
|
571
|
|
572 #define ENCRSW 2
|
|
573 "encrypt",
|
|
574 #ifndef TMA
|
|
575 -7,
|
|
576 #else /* TMA */
|
|
577 0,
|
|
578 #endif /* TMA */
|
|
579 #define NENCRSW 3
|
|
580 "noencrypt",
|
|
581 #ifndef TMA
|
|
582 -9,
|
|
583 #else /* TMA */
|
|
584 0,
|
|
585 #endif /* TMA */
|
|
586
|
|
587 #define FILTSW 4
|
|
588 "filter filterfile", 0,
|
|
589 #define NFILTSW 5
|
|
590 "nofilter", 0,
|
|
591
|
|
592 #define FRMTSW 6
|
|
593 "format", 0,
|
|
594 #define NFRMTSW 7
|
|
595 "noformat", 0,
|
|
596
|
|
597 #define FORWSW 8
|
|
598 "forward", 0,
|
|
599 #define NFORWSW 9
|
|
600 "noforward", 0,
|
|
601
|
|
602 #define MIMESW 10
|
|
603 "mime", MIMEminc(-4),
|
|
604 #define NMIMESW 11
|
|
605 "nomime", MIMEminc(-6),
|
|
606
|
|
607 #define MSGDSW 12
|
|
608 "msgid", 0,
|
|
609 #define NMSGDSW 13
|
|
610 "nomsgid", 0,
|
|
611
|
|
612 #define SPSHSW 14
|
|
613 "push", 0,
|
|
614 #define NSPSHSW 15
|
|
615 "nopush", 0,
|
|
616
|
|
617 #define SPLITSW 16
|
|
618 "split seconds", MIMEminc(-5),
|
|
619
|
|
620 #define UNIQSW 17
|
|
621 "unique", -6,
|
|
622 #define NUNIQSW 18
|
|
623 "nounique", -8,
|
|
624
|
|
625 #define VERBSW 19
|
|
626 "verbose", 0,
|
|
627 #define NVERBSW 20
|
|
628 "noverbose", 0,
|
|
629
|
|
630 #define WATCSW 21
|
|
631 "watch", 0,
|
|
632 #define NWATCSW 22
|
|
633 "nowatch", 0,
|
|
634
|
|
635 #define WIDTHSW 23
|
|
636 "width columns", 0,
|
|
637
|
|
638 #define SHELPSW 24
|
|
639 "help", 4,
|
|
640
|
|
641 #define MAILSW 25
|
|
642 "mail", -4,
|
|
643 #define SAMLSW 26
|
|
644 "saml", -4,
|
|
645 #define SSNDSW 27
|
|
646 "send", -4,
|
|
647 #define SOMLSW 28
|
|
648 "soml", -4,
|
|
649
|
|
650 #define CLIESW 29
|
|
651 "client host", -6,
|
|
652 #define SERVSW 30
|
|
653 "server host", -6,
|
|
654 #define SNOOPSW 31
|
|
655 "snoop", -5,
|
|
656
|
|
657 #define SDRFSW 32
|
|
658 "draftfolder +folder", -6,
|
|
659 #define SDRMSW 33
|
|
660 "draftmessage msg", -6,
|
|
661 #define SNDRFSW 34
|
|
662 "nodraftfolder", -3,
|
|
663
|
|
664 #define QUEUESW 35
|
|
665 "queued", -6,
|
|
666
|
|
667 #define RECORSW 36
|
|
668 "record program", -6,
|
|
669 #define NRECOSW 37
|
|
670 "norecord", -8,
|
|
671
|
|
672 #ifdef MIME_HEADERS
|
|
673 #define HENCDSW 38
|
|
674 "hencode", 0,
|
|
675 #define NHENCDSW 39
|
|
676 "nohencode", 0,
|
|
677 #endif /* MIME_HEADERS */
|
|
678
|
|
679 NULL, 0
|
|
680 };
|
|
681
|
|
682 /* */
|
|
683
|
|
684 extern int debugsw; /* from sendsbr.c */
|
|
685 extern int forwsw;
|
|
686 extern int inplace;
|
|
687 extern int pushsw;
|
|
688 extern int splitsw;
|
|
689 extern int unique;
|
|
690 extern int verbsw;
|
|
691
|
|
692 extern char *altmsg; /* .. */
|
|
693 extern char *annotext;
|
|
694 extern char *distfile;
|
|
695
|
|
696 /* */
|
|
697
|
16
|
698 static void sendit (sp, arg, file, pushed)
|
0
|
699 register char *sp,
|
|
700 **arg,
|
|
701 *file;
|
|
702 int pushed;
|
|
703 {
|
|
704 #ifndef lint
|
|
705 int distsw = 0;
|
|
706 #endif /* not lint */
|
|
707 int vecp = 1;
|
|
708 char *cp,
|
|
709 buf[100],
|
|
710 **ap,
|
|
711 **argp,
|
|
712 *arguments[MAXARGS],
|
|
713 *vec[MAXARGS];
|
|
714 struct stat st;
|
|
715 #ifdef UCI
|
|
716 FILE *fp;
|
|
717 #endif /* UCI */
|
|
718
|
|
719 if (arg)
|
|
720 (void) copyip (arg, vec);
|
|
721 if ((cp = m_find (sp)) != NULL) {
|
|
722 ap = brkstring (cp = getcpy (cp), " ", "\n");
|
|
723 ap = copyip (ap, arguments);
|
|
724 }
|
|
725 else
|
|
726 ap = arguments;
|
|
727 if (arg)
|
|
728 (void) copyip (vec, ap);
|
|
729 argp = arguments;
|
|
730
|
|
731 debugsw = 0, forwsw = 1, inplace = 0, unique = 0;
|
|
732 altmsg = annotext = distfile = NULL;
|
|
733 vec[vecp++] = "-library";
|
|
734 vec[vecp++] = getcpy (m_maildir (""));
|
|
735
|
|
736 /* */
|
|
737
|
|
738 while (cp = *argp++) {
|
|
739 if (*cp == '-')
|
|
740 switch (smatch (++cp, sendswitches)) {
|
|
741 case AMBIGSW:
|
|
742 ambigsw (cp, sendswitches);
|
|
743 return;
|
|
744 case UNKWNSW:
|
|
745 advise (NULLCP, "-%s unknown\n", cp);
|
|
746 return;
|
|
747 case SHELPSW:
|
|
748 (void) sprintf (buf, "%s [switches]", sp);
|
|
749 help (buf, sendswitches);
|
|
750 return;
|
|
751
|
|
752 case SPSHSW:
|
|
753 pushed++;
|
|
754 continue;
|
|
755 case NSPSHSW:
|
|
756 pushed = 0;
|
|
757 continue;
|
|
758
|
|
759 case SPLITSW:
|
|
760 if (!(cp = *argp++) || sscanf (cp, "%d", &splitsw) != 1) {
|
|
761 advise (NULLCP, "missing argument to %s", argp[-2]);
|
|
762 return;
|
|
763 }
|
|
764 continue;
|
|
765
|
|
766 case UNIQSW:
|
|
767 unique++;
|
|
768 continue;
|
|
769 case NUNIQSW:
|
|
770 unique = 0;
|
|
771 continue;
|
|
772 case FORWSW:
|
|
773 forwsw++;
|
|
774 continue;
|
|
775 case NFORWSW:
|
|
776 forwsw = 0;
|
|
777 continue;
|
|
778
|
|
779 case VERBSW:
|
|
780 verbsw++;
|
|
781 vec[vecp++] = --cp;
|
|
782 continue;
|
|
783 case NVERBSW:
|
|
784 verbsw = 0;
|
|
785 vec[vecp++] = --cp;
|
|
786 continue;
|
|
787
|
|
788 case DEBUGSW:
|
|
789 debugsw++; /* fall */
|
|
790 case NFILTSW:
|
|
791 case FRMTSW:
|
|
792 case NFRMTSW:
|
|
793 case MIMESW:
|
|
794 case NMIMESW:
|
|
795 case MSGDSW:
|
|
796 case NMSGDSW:
|
|
797 case WATCSW:
|
|
798 case NWATCSW:
|
|
799 case MAILSW:
|
|
800 case SAMLSW:
|
|
801 case SSNDSW:
|
|
802 case SOMLSW:
|
|
803 case ENCRSW:
|
|
804 case NENCRSW:
|
|
805 case SNOOPSW:
|
|
806 case QUEUESW:
|
|
807 case NRECOSW:
|
|
808 #ifdef MIME_HEADERS
|
|
809 case HENCDSW:
|
|
810 case NHENCDSW:
|
|
811 #endif /* MIME_HEADERS */
|
|
812 vec[vecp++] = --cp;
|
|
813 continue;
|
|
814
|
|
815 case ALIASW:
|
|
816 case FILTSW:
|
|
817 case WIDTHSW:
|
|
818 case CLIESW:
|
|
819 case SERVSW:
|
|
820 case RECORSW:
|
|
821 vec[vecp++] = --cp;
|
|
822 if (!(cp = *argp++) || *cp == '-') {
|
|
823 advise (NULLCP, "missing argument to %s", argp[-2]);
|
|
824 return;
|
|
825 }
|
|
826 vec[vecp++] = cp;
|
|
827 continue;
|
|
828
|
|
829 case SDRFSW:
|
|
830 case SDRMSW:
|
|
831 if (!(cp = *argp++) || *cp == '-') {
|
|
832 advise (NULLCP, "missing argument to %s", argp[-2]);
|
|
833 return;
|
|
834 }
|
|
835 case SNDRFSW:
|
|
836 continue;
|
|
837 }
|
|
838 advise (NULLCP, "usage: %s [switches]", sp);
|
|
839 return;
|
|
840 }
|
|
841 if (cp = m_find ("Aliasfile")) { /* allow Aliasfile: profile entry */
|
|
842 char *dp = NULL;
|
|
843
|
|
844 for (ap = brkstring(dp = getcpy(cp), " ", "\n"); ap && *ap; ap++) {
|
|
845 vec[vecp++] = "-alias";
|
|
846 vec[vecp++] = *ap;
|
|
847 }
|
|
848 }
|
|
849
|
|
850 /* */
|
|
851
|
|
852 #ifdef TMA
|
|
853 if ((cp = getenv ("KDS")) == NULL || *cp == NULL)
|
|
854 if ((cp = m_find ("kdsproc")) && *cp)
|
|
855 (void) m_putenv ("KDS", cp);
|
|
856 if ((cp = getenv ("TMADB")) == NULL || *cp == NULL)
|
|
857 if ((cp = m_find ("tmadb")) && *cp)
|
|
858 (void) m_putenv ("TMADB", m_maildir (cp));
|
|
859 #endif /* TMA */
|
|
860
|
|
861 if ((cp = getenv ("SIGNATURE")) == NULL || *cp == 0)
|
|
862 if ((cp = m_find ("signature")) && *cp)
|
|
863 (void) m_putenv ("SIGNATURE", cp);
|
|
864 #ifdef UCI
|
|
865 else {
|
|
866 (void) sprintf (buf, "%s/.signature", mypath);
|
|
867 if ((fp = fopen (buf, "r")) != NULL
|
|
868 && fgets (buf, sizeof buf, fp) != NULL) {
|
|
869 (void) fclose (fp);
|
|
870 if (cp = index (buf, '\n'))
|
|
871 *cp = 0;
|
|
872 (void) m_putenv ("SIGNATURE", buf);
|
|
873 }
|
|
874 }
|
|
875 #endif /* UCI */
|
|
876
|
|
877 if ((annotext = getenv ("mhannotate")) == NULL || *annotext == 0)
|
|
878 annotext = NULL;
|
|
879 if ((altmsg = getenv ("mhaltmsg")) == NULL || *altmsg == 0)
|
|
880 altmsg = NULL;
|
|
881 if (annotext && ((cp = getenv ("mhinplace")) != NULL && *cp != 0))
|
|
882 inplace = atoi (cp);
|
|
883
|
|
884 if ((cp = getenv ("mhdist"))
|
|
885 && *cp
|
|
886 #ifndef lint
|
|
887 && (distsw = atoi (cp))
|
|
888 #endif /* not lint */
|
|
889 && altmsg) {
|
|
890 vec[vecp++] = "-dist";
|
|
891 distfile = getcpy (m_scratch (altmsg, invo_name));
|
|
892 if (link (altmsg, distfile) == NOTOK)
|
|
893 adios (distfile, "unable to link %s to", altmsg);
|
|
894 }
|
|
895 else
|
|
896 distfile = NULL;
|
|
897
|
|
898 if (altmsg == NULL || stat (altmsg, &st) == NOTOK)
|
|
899 st.st_mtime = 0, st.st_dev = 0, st.st_ino = 0;
|
|
900 if (pushsw = pushed)
|
|
901 push ();
|
|
902
|
|
903 vec[0] = r1bindex (postproc, '/');
|
|
904 closefds (3);
|
|
905
|
|
906 if (sendsbr (vec, vecp, file, &st) == OK)
|
|
907 done (0);
|
|
908 }
|
|
909
|
|
910 /* WHOM */
|
|
911
|
|
912 static int whomfile (arg, file)
|
|
913 register char **arg,
|
|
914 *file;
|
|
915 {
|
|
916 int pid;
|
|
917 register int vecp;
|
|
918 char *vec[MAXARGS];
|
|
919
|
|
920 m_update ();
|
|
921 (void) fflush (stdout);
|
|
922
|
|
923 switch (pid = vfork ()) {
|
|
924 case NOTOK:
|
|
925 advise ("fork", "unable to");
|
|
926 return 1;
|
|
927
|
|
928 case OK:
|
|
929 vecp = 0;
|
|
930 vec[vecp++] = r1bindex (whomproc, '/');
|
|
931 vec[vecp++] = file;
|
|
932 if (arg)
|
|
933 while (*arg)
|
|
934 vec[vecp++] = *arg++;
|
|
935 vec[vecp] = NULL;
|
|
936
|
|
937 execvp (whomproc, vec);
|
|
938 fprintf (stderr, "unable to exec ");
|
|
939 perror (whomproc);
|
|
940 _exit (-1); /* NOTREACHED */
|
|
941
|
|
942 default:
|
|
943 return (pidwait (pid, NOTOK) & 0377 ? 1 : 0);
|
|
944 }
|
|
945 }
|