3 * whatnowsbr.c -- the WhatNow shell
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
9 * Several options have been added to ease the inclusion of attachments
10 * using the header field name mechanism added to anno and send. The
11 * -attach option is used to specify the header field name for attachments.
13 * Several commands have been added at the whatnow prompt:
15 * cd [ directory ] This option works just like the shell's
16 * cd command and lets the user change the
17 * directory from which attachments are
18 * taken so that long path names are not
19 * needed with every file.
21 * ls [ ls-options ] This option works just like the normal
22 * ls command and exists to allow the user
23 * to verify file names in the directory.
25 * pwd This option works just like the normal
26 * pwd command and exists to allow the user
27 * to verify the directory.
29 * attach files This option attaches the named files to
32 * alist [-ln] This option lists the attachments on the
33 * draft. -l gets long listings, -n gets
36 * detach files This option removes attachments from the
37 * detach -n numbers draft. This can be done by file name or
38 * by attachment number.
47 static struct swit whatnowswitches[] = {
49 { "draftfolder +folder", 0 },
51 { "draftmessage msg", 0 },
53 { "nodraftfolder", 0 },
55 { "editor editor", 0 },
59 { "prompt string", 4 },
65 { "attach header-field-name", 0 },
72 * Options at the "whatnow" prompt
74 static struct swit aleqs[] = {
76 { "edit [<editor> <switches>]", 0 },
78 { "refile [<switches>] +folder", 0 },
80 { "mime [<switches>]", 0 },
82 { "display [<switches>]", 0 },
84 { "list [<switches>]", 0 },
86 { "send [<switches>]", 0 },
88 { "push [<switches>]", 0 },
90 { "whom [<switches>]", 0 },
92 { "quit [-delete]", 0 },
96 { "cd [directory]", 0 },
101 #define ATTACHCMDSW 13
103 #define DETACHCMDSW 14
104 { "detach [-n]", 2 },
105 #define ALISTCMDSW 15
106 { "alist [-ln] ", 2 },
110 static char *myprompt = "\nWhat now? ";
115 static int editfile (char **, char **, char *, int, struct msgs *,
116 char *, char *, int);
117 static int sendfile (char **, char *, int);
118 static void sendit (char *, char **, char *, int);
119 static int buildfile (char **, char *);
120 static int check_draft (char *);
121 static int whomfile (char **, char *);
122 static int removefile (char *);
123 static void writelscmd(char *, int, char **);
124 static void writesomecmd(char *buf, int bufsz, char *cmd, char *trailcmd, char **argp);
125 static FILE* popen_in_dir(const char *dir, const char *cmd, const char *type);
126 static int system_in_dir(const char *dir, const char *cmd);
130 static int copyf (char *, char *);
135 WhatNow (int argc, char **argv)
137 int isdf = 0, nedit = 0, use = 0;
138 char *cp, *dfolder = NULL, *dmsg = NULL;
139 char *ed = NULL, *drft = NULL, *msgnam = NULL;
140 char buf[BUFSIZ], prompt[BUFSIZ];
141 char **argp, **arguments;
143 char *attach = NMH_ATTACH_HEADER;/* attachment header field name */
144 char cwd[MAXPATHLEN + 1]; /* current working directory */
145 char file[MAXPATHLEN + 1]; /* file name buffer */
146 char shell[MAXPATHLEN + 1]; /* shell response buffer */
147 FILE *f; /* read pointer for bgnd proc */
148 char *l; /* set on -l to alist command */
149 int n; /* set on -n to alist command */
151 invo_name = r1bindex (argv[0], '/');
153 /* read user profile/context */
156 arguments = getarguments (invo_name, argc, argv, 1);
160 * Get the initial current working directory.
163 if (getcwd(cwd, sizeof (cwd)) == (char *)0) {
164 adios("getcwd", "could not get working directory");
167 while ((cp = *argp++)) {
169 switch (smatch (++cp, whatnowswitches)) {
171 ambigsw (cp, whatnowswitches);
174 adios (NULL, "-%s unknown", cp);
177 snprintf (buf, sizeof(buf), "%s [switches] [file]", invo_name);
178 print_help (buf, whatnowswitches, 1);
181 print_version(invo_name);
186 adios (NULL, "only one draft folder at a time!");
187 if (!(cp = *argp++) || *cp == '-')
188 adios (NULL, "missing argument to %s", argp[-2]);
189 dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp,
190 *cp != '@' ? TFOLDER : TSUBCWF);
194 adios (NULL, "only one draft message at a time!");
195 if (!(dmsg = *argp++) || *dmsg == '-')
196 adios (NULL, "missing argument to %s", argp[-2]);
204 if (!(ed = *argp++) || *ed == '-')
205 adios (NULL, "missing argument to %s", argp[-2]);
213 if (!(myprompt = *argp++) || *myprompt == '-')
214 adios (NULL, "missing argument to %s", argp[-2]);
218 if (!(attach = *argp++) || *attach == '-')
219 adios (NULL, "missing argument to %s", argp[-2]);
228 adios (NULL, "only one draft at a time!");
233 if ((drft == NULL && (drft = getenv ("mhdraft")) == NULL) || *drft == 0)
234 drft = getcpy (m_draft (dfolder, dmsg, 1, &isdf));
236 msgnam = (cp = getenv ("mhaltmsg")) && *cp ? getcpy (cp) : NULL;
238 if ((cp = getenv ("mhuse")) && *cp)
241 if (ed == NULL && ((ed = getenv ("mheditor")) == NULL || *ed == 0)) {
246 /* start editing the draft, unless -noedit was given */
247 if (!nedit && editfile (&ed, NULL, drft, use, NULL, msgnam, NULL, 1) < 0)
250 snprintf (prompt, sizeof(prompt), myprompt, invo_name);
252 #ifdef READLINE_SUPPORT
253 if (!(argp = getans_via_readline (prompt, aleqs))) {
254 #else /* ! READLINE_SUPPORT */
255 if (!(argp = getans (prompt, aleqs))) {
256 #endif /* READLINE_SUPPORT */
260 switch (smatch (*argp, aleqs)) {
262 /* display the message being replied to, or distributed */
264 showfile (++argp, msgnam);
266 advise (NULL, "no alternate message to display");
270 /* Translate MIME composition file */
271 buildfile (++argp, drft);
275 /* Call an editor on the draft file */
278 if (editfile (&ed, argp, drft, NOUSE, NULL, msgnam, NULL, 1) == NOTOK)
283 /* display the draft file */
284 showfile (++argp, drft);
288 /* Check to whom the draft would be sent */
289 whomfile (++argp, drft);
293 /* Quit, and possibly delete the draft */
294 if (*++argp && (*argp[0] == 'd' ||
295 ((*argp)[0] == '-' && (*argp)[1] == 'd'))) {
298 if (stat (drft, &st) != NOTOK)
299 advise (NULL, "draft left on %s", drft);
304 /* Delete draft and exit */
309 /* Send draft in background */
310 if (sendfile (++argp, drft, 1))
316 sendfile (++argp, drft, 0);
320 /* Refile the draft */
321 if (refile (++argp, drft) == 0)
326 /* Change the working directory for attachments
328 * Run the directory through the user's shell so that
329 * we can take advantage of any syntax that the user
330 * is accustomed to. Read back the absolute path.
333 if (*(argp+1) == (char *)0) {
334 (void)sprintf(buf, "$SHELL -c \"cd;pwd\"");
337 writesomecmd(buf, BUFSIZ, "cd", "pwd", argp);
339 if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
340 fgets(cwd, sizeof (cwd), f);
342 if (strchr(cwd, '\n') != (char *)0)
343 *strchr(cwd, '\n') = '\0';
348 advise("popen", "could not get directory");
354 /* Print the working directory for attachments */
359 /* List files in the current attachment working directory
361 * Use the user's shell so that we can take advantage of any
362 * syntax that the user is accustomed to.
364 writelscmd(buf, sizeof(buf), argp);
365 (void)system_in_dir(cwd, buf);
370 * List attachments on current draft. Options are:
372 * -l long listing (full path names)
376 if (attach == (char *)0) {
377 advise((char *)0, "can't list because no header field name was given.");
384 while (*++argp != (char *)0) {
385 if (strcmp(*argp, "-l") == 0)
388 else if (strcmp(*argp, "-n") == 0)
391 else if (strcmp(*argp, "-ln") == 0 || strcmp(*argp, "-nl") == 0) {
403 advise((char *)0, "usage is alist [-ln].");
406 annolist(drft, attach, l, n);
412 * Attach files to current draft.
415 if (attach == (char *)0) {
416 advise((char *)0, "can't attach because no header field name was given.");
420 if (*(argp+1) == (char *)0) {
421 advise((char *)0, "attach command requires file argument(s).");
426 * Build a command line that causes the user's shell to list the file name
427 * arguments. This handles and wildcard expansion, tilde expansion, etc.
429 writelscmd(buf, sizeof(buf), argp);
432 * Read back the response from the shell, which contains a number of lines
433 * with one file name per line. Remove off the newline. Determine whether
434 * we have an absolute or relative path name. Prepend the current working
435 * directory to relative path names. Add the attachment annotation to the
439 if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
440 while (fgets(shell, sizeof (shell), f) != (char *)0) {
441 *(strchr(shell, '\n')) = '\0';
444 (void)annotate(drft, attach, shell, 1, 0, -2, 1);
446 (void)sprintf(file, "%s/%s", cwd, shell);
447 (void)annotate(drft, attach, file, 1, 0, -2, 1);
454 advise("popen", "could not get file from shell");
461 * Detach files from current draft.
464 if (attach == (char *)0) {
465 advise((char *)0, "can't detach because no header field name was given.");
470 * Scan the arguments for a -n. Mixed file names and numbers aren't allowed,
471 * so this catches a -n anywhere in the argument list.
474 for (n = 0, arguments = argp + 1; *arguments != (char *)0; arguments++) {
475 if (strcmp(*arguments, "-n") == 0) {
482 * A -n was found so interpret the arguments as attachment numbers.
483 * Decrement any remaining argument number that is greater than the one
484 * just processed after processing each one so that the numbering stays
489 for (arguments = argp + 1; *arguments != (char *)0; arguments++) {
490 if (strcmp(*arguments, "-n") == 0)
493 if (**arguments != '\0') {
494 n = atoi(*arguments);
495 (void)annotate(drft, attach, (char *)0, 1, 0, n, 1);
497 for (argp = arguments + 1; *argp != (char *)0; argp++) {
498 if (atoi(*argp) > n) {
499 if (atoi(*argp) == 1)
502 (void)sprintf(*argp, "%d", atoi(*argp) - 1);
510 * The arguments are interpreted as file names. Run them through the
511 * user's shell for wildcard expansion and other goodies. Do this from
512 * the current working directory if the argument is not an absolute path
513 * name (does not begin with a /).
515 * We feed all the file names to the shell at once, otherwise you can't
516 * provide a file name with a space in it.
518 writelscmd(buf, sizeof(buf), argp);
519 if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
520 while (fgets(shell, sizeof (shell), f) != (char *)0) {
521 *(strchr(shell, '\n')) = '\0';
522 (void)annotate(drft, attach, shell, 1, 0, 0, 1);
526 advise("popen", "could not get file from shell");
532 /* Unknown command */
533 advise (NULL, "say what?");
542 /* Build a command line of the form $SHELL -c "cd 'cwd'; cmd argp ... ; trailcmd". */
544 writesomecmd(char *buf, int bufsz, char *cmd, char *trailcmd, char **argp)
547 /* Note that we do not quote -- the argp from the user
548 * is assumed to be quoted as they desire. (We can't treat
549 * it as pure literal as that would prevent them using ~,
550 * wildcards, etc.) The buffer produced by this function
551 * should be given to popen_in_dir() or system_in_dir() so
552 * that the current working directory is set correctly.
554 int ln = snprintf(buf, bufsz, "$SHELL -c \"%s", cmd);
555 /* NB that some snprintf() return -1 on overflow rather than the
556 * new C99 mandated 'number of chars that would have been written'
558 /* length checks here and inside the loop allow for the
559 * trailing ';', trailcmd, '"' and NUL
561 int trailln = strlen(trailcmd) + 3;
562 if (ln < 0 || ln + trailln > bufsz)
563 adios((char *)0, "arguments too long");
567 while (*++argp != (char *)0) {
569 /* +1 for leading space */
570 if (ln + trailln + 1 > bufsz - (cp-buf))
571 adios((char *)0, "arguments too long");
573 memcpy(cp, *argp, ln+1);
578 strcpy(cp, trailcmd);
586 * Build a command line that causes the user's shell to list the file name
587 * arguments. This handles and wildcard expansion, tilde expansion, etc.
590 writelscmd(char *buf, int bufsz, char **argp)
592 writesomecmd(buf, bufsz, "ls", "", argp);
595 /* Like system(), but run the command in directory dir.
596 * This assumes the program is single-threaded!
599 system_in_dir(const char *dir, const char *cmd)
603 if (getcwd(olddir, sizeof(olddir)) == 0)
604 adios("getcwd", "could not get working directory");
606 adios("chdir", "could not change working directory");
608 if (chdir(olddir) != 0)
609 adios("chdir", "could not change working directory");
613 /* ditto for popen() */
615 popen_in_dir(const char *dir, const char *cmd, const char *type)
619 if (getcwd(olddir, sizeof(olddir)) == 0)
620 adios("getcwd", "could not get working directory");
622 adios("chdir", "could not change working directory");
623 f = popen(cmd, type);
624 if (chdir(olddir) != 0)
625 adios("chdir", "could not change working directory");
634 static int reedit = 0; /* have we been here before? */
635 static char *edsave = NULL; /* the editor we used previously */
639 editfile (char **ed, char **arg, char *file, int use, struct msgs *mp,
640 char *altmsg, char *cwd, int save_editor)
642 int pid, status, vecp;
643 char altpath[BUFSIZ], linkpath[BUFSIZ];
644 char *cp, *vec[MAXARGS];
649 #endif /* HAVE_LSTAT */
651 /* Was there a previous edit session? */
653 if (!*ed) { /* no explicit editor */
654 *ed = edsave; /* so use the previous one */
655 if ((cp = r1bindex (*ed, '/')) == NULL)
658 /* unless we've specified it via "editor-next" */
659 cp = concat (cp, "-next", NULL);
660 if ((cp = context_find (cp)) != NULL)
664 /* set initial editor */
665 if (*ed == NULL && (*ed = context_find ("editor")) == NULL)
670 if (mp == NULL || *altmsg == '/' || cwd == NULL)
671 strncpy (altpath, altmsg, sizeof(altpath));
673 snprintf (altpath, sizeof(altpath), "%s/%s", mp->foldpath, altmsg);
675 strncpy (linkpath, LINK, sizeof(linkpath));
677 snprintf (linkpath, sizeof(linkpath), "%s/%s", cwd, LINK);
681 if (link (altpath, linkpath) == NOTOK) {
682 symlink (altpath, linkpath);
687 #else /* not HAVE_LSTAT */
688 link (altpath, linkpath);
689 #endif /* not HAVE_LSTAT */
692 context_save (); /* save the context file */
695 switch (pid = vfork()) {
697 advise ("fork", "unable to");
706 m_putenv ("mhfolder", mp->foldpath);
707 m_putenv ("editalt", altpath);
711 vec[vecp++] = r1bindex (*ed, '/');
714 vec[vecp++] = *arg++;
719 fprintf (stderr, "unable to exec ");
724 if ((status = pidwait (pid, NOTOK))) {
725 if (((status & 0xff00) != 0xff00)
726 && (!reedit || (status & 0x00ff))) {
727 if (!use && (status & 0xff00) &&
728 (rename (file, cp = m_backup (file)) != NOTOK)) {
729 advise (NULL, "problems with edit--draft left in %s", cp);
731 advise (NULL, "problems with edit--%s preserved", file);
734 status = -2; /* maybe "reedit ? -2 : -1"? */
744 ? lstat (linkpath, &st) != NOTOK
745 && S_ISREG(st.st_mode)
746 && copyf (linkpath, altpath) == NOTOK
747 : stat (linkpath, &st) != NOTOK
749 && (unlink (altpath) == NOTOK
750 || link (linkpath, altpath) == NOTOK)))
751 advise (linkpath, "unable to update %s from", altmsg);
752 #else /* HAVE_LSTAT */
756 && stat (linkpath, &st) != NOTOK
758 && (unlink (altpath) == NOTOK
759 || link (linkpath, altpath) == NOTOK))
760 advise (linkpath, "unable to update %s from", altmsg);
761 #endif /* HAVE_LSTAT */
764 /* normally, we remember which editor we used */
766 edsave = getcpy (*ed);
778 copyf (char *ifile, char *ofile)
783 if ((in = open (ifile, O_RDONLY)) == NOTOK)
785 if ((out = open (ofile, O_WRONLY | O_TRUNC)) == NOTOK) {
786 admonish (ofile, "unable to open and truncate");
791 while ((i = read (in, buffer, sizeof(buffer))) > OK)
792 if (write (out, buffer, i) != i) {
793 advise (ofile, "may have damaged");
802 #endif /* HAVE_LSTAT */
810 sendfile (char **arg, char *file, int pushsw)
814 char *cp, *sp, *vec[MAXARGS];
816 /* Translate MIME composition file, if necessary */
817 if ((cp = context_find ("automimeproc"))
818 && (!strcmp (cp, "1"))
819 && !getenv ("NOMHNPROC")
820 && check_draft (file)
821 && (buildfile (NULL, file) == NOTOK))
824 /* For backwards compatibility */
825 if ((cp = context_find ("automhnproc"))
826 && !getenv ("NOMHNPROC")
827 && check_draft (file)
828 && (i = editfile (&cp, NULL, file, NOUSE, NULL, NULL, NULL, 0)))
832 * If the sendproc is the nmh command `send', then we call
833 * those routines directly rather than exec'ing the command.
835 if (strcmp (sp = r1bindex (sendproc, '/'), "send") == 0) {
837 sendit (invo_name = sp, arg, file, pushsw);
842 context_save (); /* save the context file */
845 for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++)
849 advise (NULL, "unable to fork, so sending directly...");
852 vec[vecp++] = invo_name;
854 vec[vecp++] = "-push";
857 vec[vecp++] = *arg++;
861 execvp (sendproc, vec);
862 fprintf (stderr, "unable to exec ");
867 if (pidwait(child_id, OK) == 0)
875 * Translate MIME composition file (call buildmimeproc)
879 buildfile (char **argp, char *file)
886 /* allocate space for arguments */
892 args = (char **) mh_xmalloc((i + 2) * sizeof(char *));
895 * For backward compatibility, we need to add -build
896 * if we are using mhn as buildmimeproc
899 if (strcmp (r1bindex (ed, '/'), "mhn") == 0)
900 args[i++] = "-build";
902 /* copy any other arguments */
903 while (argp && *argp)
907 i = editfile (&ed, args, file, NOUSE, NULL, NULL, NULL, 0);
910 return (i ? NOTOK : OK);
915 * Check if draft is a mhbuild composition file
919 check_draft (char *msgnam)
922 char buf[BUFSIZ], name[NAMESZ];
925 if ((fp = fopen (msgnam, "r")) == NULL)
928 switch (state = m_getfld (state, name, buf, sizeof(buf), fp)) {
933 * If draft already contains any of the
934 * Content-XXX fields, then assume it already
937 if (uprf (name, XXX_FIELD_PRF)) {
941 while (state == FLDPLUS)
942 state = m_getfld (state, name, buf, sizeof(buf), fp);
949 for (bp = buf; *bp; bp++)
950 if (*bp != ' ' && *bp != '\t' && *bp != '\n') {
955 state = m_getfld (state, name, buf, sizeof(buf), fp);
956 } while (state == BODY);
967 # define SASLminc(a) (a)
968 #else /* CYRUS_SASL */
969 # define SASLminc(a) 0
970 #endif /* CYRUS_SASL */
973 # define TLSminc(a) (a)
974 #else /* TLS_SUPPORT */
975 # define TLSminc(a) 0
976 #endif /* TLS_SUPPORT */
978 static struct swit sendswitches[] = {
980 { "alias aliasfile", 0 },
984 { "filter filterfile", 0 },
1008 { "split seconds", 0 },
1022 { "width columns", 0 },
1023 #define SVERSIONSW 22
1027 #define BITSTUFFSW 24
1028 { "dashstuffing", -12 },
1029 #define NBITSTUFFSW 25
1030 { "nodashstuffing", -14 },
1040 { "client host", -6 },
1042 { "server host", 6 },
1046 { "draftfolder +folder", -6 },
1048 { "draftmessage msg", -6 },
1050 { "nodraftfolder", -3 },
1052 { "sasl", SASLminc(-4) },
1054 { "nosasl", SASLminc(-6) },
1055 #define SASLMXSSFSW 38
1056 { "saslmaxssf", SASLminc(-10) },
1057 #define SASLMECHSW 39
1058 { "saslmech", SASLminc(-5) },
1060 { "user", SASLminc(-4) },
1061 #define SNDATTACHSW 41
1062 { "attach file", 6 },
1063 #define SNDNOATTACHSW 42
1065 #define SNDATTACHFORMAT 43
1066 { "attachformat", 7 },
1068 { "port server-port-name/number", 4 },
1070 { "tls", TLSminc(-3) },
1072 { "notls", TLSminc(-5) },
1077 extern int debugsw; /* from sendsbr.c */
1085 extern char *altmsg; /* .. */
1086 extern char *annotext;
1087 extern char *distfile;
1091 sendit (char *sp, char **arg, char *file, int pushed)
1094 char *cp, buf[BUFSIZ], **argp;
1095 char **arguments, *vec[MAXARGS];
1097 char *attach = NMH_ATTACH_HEADER;/* attachment header field name */
1098 int attachformat = 1; /* mhbuild format specifier for
1106 * Make sure these are defined. In particular, we need
1107 * vec[1] to be NULL, in case "arg" is NULL below. It
1108 * doesn't matter what is the value of vec[0], but we
1109 * set it to NULL, to help catch "off-by-one" errors.
1115 * Temporarily copy arg to vec, since the brkstring() call in
1116 * getarguments() will wipe it out before it is merged in.
1117 * Also, we skip the first element of vec, since getarguments()
1118 * skips it. Then we count the number of arguments
1119 * copied. The value of "n" will be one greater than
1120 * this in order to simulate the standard argc/argv.
1125 copyip (arg, vec+1, MAXARGS-1);
1132 * Merge any arguments from command line (now in vec)
1133 * and arguments from profile.
1135 arguments = getarguments (sp, n, vec, 1);
1147 vecp = 1; /* we'll get the zero'th element later */
1148 vec[vecp++] = "-library";
1149 vec[vecp++] = getcpy (m_maildir (""));
1151 if ((cp = context_find ("fileproc"))) {
1152 vec[vecp++] = "-fileproc";
1156 if ((cp = context_find ("mhlproc"))) {
1157 vec[vecp++] = "-mhlproc";
1161 while ((cp = *argp++)) {
1163 switch (smatch (++cp, sendswitches)) {
1165 ambigsw (cp, sendswitches);
1168 advise (NULL, "-%s unknown\n", cp);
1172 snprintf (buf, sizeof(buf), "%s [switches]", sp);
1173 print_help (buf, sendswitches, 1);
1176 print_version (invo_name);
1187 if (!(cp = *argp++) || sscanf (cp, "%d", &splitsw) != 1) {
1188 advise (NULL, "missing argument to %s", argp[-2]);
1216 debugsw++; /* fall */
1250 if (!(cp = *argp++) || *cp == '-') {
1251 advise (NULL, "missing argument to %s", argp[-2]);
1259 if (!(cp = *argp++) || *cp == '-') {
1260 advise (NULL, "missing argument to %s", argp[-2]);
1267 if (!(attach = *argp++) || *attach == '-') {
1268 advise (NULL, "missing argument to %s", argp[-2]);
1276 case SNDATTACHFORMAT:
1277 if (! *argp || **argp == '-')
1278 adios (NULL, "missing argument to %s", argp[-1]);
1280 attachformat = atoi (*argp);
1281 if (attachformat < 0 ||
1282 attachformat > ATTACHFORMATS - 1) {
1283 advise (NULL, "unsupported attachformat %d",
1292 advise (NULL, "usage: %s [switches]", sp);
1296 /* allow Aliasfile: profile entry */
1297 if ((cp = context_find ("Aliasfile"))) {
1301 for (ap = brkstring (dp, " ", "\n"); ap && *ap; ap++) {
1302 vec[vecp++] = "-alias";
1307 if ((cp = getenv ("SIGNATURE")) == NULL || *cp == 0)
1308 if ((cp = context_find ("signature")) && *cp)
1309 m_putenv ("SIGNATURE", cp);
1311 if ((annotext = getenv ("mhannotate")) == NULL || *annotext == 0)
1313 if ((altmsg = getenv ("mhaltmsg")) == NULL || *altmsg == 0)
1315 if (annotext && ((cp = getenv ("mhinplace")) != NULL && *cp != 0))
1316 inplace = atoi (cp);
1318 if ((cp = getenv ("mhdist"))
1321 && (distsw = atoi (cp))
1322 #endif /* not lint */
1324 vec[vecp++] = "-dist";
1325 distfile = getcpy (m_mktemp2(altmsg, invo_name, NULL, NULL));
1327 if (link (altmsg, distfile) == NOTOK)
1328 adios (distfile, "unable to link %s to", altmsg);
1333 if (altmsg == NULL || stat (altmsg, &st) == NOTOK) {
1338 if ((pushsw = pushed))
1341 vec[0] = r1bindex (postproc, '/');
1344 if (sendsbr (vec, vecp, file, &st, 1, attach, attachformat) == OK)
1353 whomfile (char **arg, char *file)
1359 context_save (); /* save the context file */
1362 switch (pid = vfork()) {
1364 advise ("fork", "unable to");
1369 vec[vecp++] = r1bindex (whomproc, '/');
1373 vec[vecp++] = *arg++;
1376 execvp (whomproc, vec);
1377 fprintf (stderr, "unable to exec ");
1379 _exit (-1); /* NOTREACHED */
1382 return (pidwait (pid, NOTOK) & 0377 ? 1 : 0);
1388 * Remove the draft file
1392 removefile (char *drft)
1394 if (unlink (drft) == NOTOK)
1395 adios (drft, "unable to unlink");