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, 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, atfile = 1;
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[PATH_MAX + 1]; /* current working directory */
145 char file[PATH_MAX + 1]; /* file name buffer */
146 char shell[PATH_MAX + 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 ("mhatfile")) && *cp)
241 if ((cp = getenv ("mhuse")) && *cp)
244 if (ed == NULL && ((ed = getenv ("mheditor")) == NULL || *ed == 0)) {
249 /* start editing the draft, unless -noedit was given */
250 if (!nedit && editfile (&ed, NULL, drft, use, NULL, msgnam,
251 NULL, 1, atfile) < 0)
254 snprintf (prompt, sizeof(prompt), myprompt, invo_name);
256 #ifdef READLINE_SUPPORT
257 if (!(argp = getans_via_readline (prompt, aleqs))) {
258 #else /* ! READLINE_SUPPORT */
259 if (!(argp = getans (prompt, aleqs))) {
260 #endif /* READLINE_SUPPORT */
264 switch (smatch (*argp, aleqs)) {
266 /* display the message being replied to, or distributed */
268 showfile (++argp, msgnam);
270 advise (NULL, "no alternate message to display");
274 /* Translate MIME composition file */
275 buildfile (++argp, drft);
279 /* Call an editor on the draft file */
282 if (editfile (&ed, argp, drft, NOUSE, NULL, msgnam,
283 NULL, 1, atfile) == NOTOK)
288 /* display the draft file */
289 showfile (++argp, drft);
293 /* Check to whom the draft would be sent */
294 whomfile (++argp, drft);
298 /* Quit, and possibly delete the draft */
299 if (*++argp && (*argp[0] == 'd' ||
300 ((*argp)[0] == '-' && (*argp)[1] == 'd'))) {
303 if (stat (drft, &st) != NOTOK)
304 advise (NULL, "draft left on %s", drft);
309 /* Delete draft and exit */
314 /* Send draft in background */
315 if (sendfile (++argp, drft, 1))
321 sendfile (++argp, drft, 0);
325 /* Refile the draft */
326 if (refile (++argp, drft) == 0)
331 /* Change the working directory for attachments
333 * Run the directory through the user's shell so that
334 * we can take advantage of any syntax that the user
335 * is accustomed to. Read back the absolute path.
338 if (*(argp+1) == (char *)0) {
339 (void)sprintf(buf, "$SHELL -c \"cd;pwd\"");
342 writesomecmd(buf, BUFSIZ, "cd", "pwd", argp);
344 if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
345 fgets(cwd, sizeof (cwd), f);
347 if (strchr(cwd, '\n') != (char *)0)
348 *strchr(cwd, '\n') = '\0';
353 advise("popen", "could not get directory");
359 /* Print the working directory for attachments */
364 /* List files in the current attachment working directory
366 * Use the user's shell so that we can take advantage of any
367 * syntax that the user is accustomed to.
369 writelscmd(buf, sizeof(buf), argp);
370 (void)system_in_dir(cwd, buf);
375 * List attachments on current draft. Options are:
377 * -l long listing (full path names)
381 if (attach == (char *)0) {
382 advise((char *)0, "can't list because no header field name was given.");
389 while (*++argp != (char *)0) {
390 if (strcmp(*argp, "-l") == 0)
393 else if (strcmp(*argp, "-n") == 0)
396 else if (strcmp(*argp, "-ln") == 0 || strcmp(*argp, "-nl") == 0) {
408 advise((char *)0, "usage is alist [-ln].");
411 annolist(drft, attach, l, n);
417 * Attach files to current draft.
420 if (attach == (char *)0) {
421 advise((char *)0, "can't attach because no header field name was given.");
425 if (*(argp+1) == (char *)0) {
426 advise((char *)0, "attach command requires file argument(s).");
431 * Build a command line that causes the user's shell to list the file name
432 * arguments. This handles and wildcard expansion, tilde expansion, etc.
434 writelscmd(buf, sizeof(buf), argp);
437 * Read back the response from the shell, which contains a number of lines
438 * with one file name per line. Remove off the newline. Determine whether
439 * we have an absolute or relative path name. Prepend the current working
440 * directory to relative path names. Add the attachment annotation to the
444 if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
445 while (fgets(shell, sizeof (shell), f) != (char *)0) {
446 *(strchr(shell, '\n')) = '\0';
449 (void)annotate(drft, attach, shell, 1, 0, -2, 1);
451 (void)sprintf(file, "%s/%s", cwd, shell);
452 (void)annotate(drft, attach, file, 1, 0, -2, 1);
459 advise("popen", "could not get file from shell");
466 * Detach files from current draft.
469 if (attach == (char *)0) {
470 advise((char *)0, "can't detach because no header field name was given.");
475 * Scan the arguments for a -n. Mixed file names and numbers aren't allowed,
476 * so this catches a -n anywhere in the argument list.
479 for (n = 0, arguments = argp + 1; *arguments != (char *)0; arguments++) {
480 if (strcmp(*arguments, "-n") == 0) {
487 * A -n was found so interpret the arguments as attachment numbers.
488 * Decrement any remaining argument number that is greater than the one
489 * just processed after processing each one so that the numbering stays
494 for (arguments = argp + 1; *arguments != (char *)0; arguments++) {
495 if (strcmp(*arguments, "-n") == 0)
498 if (**arguments != '\0') {
499 n = atoi(*arguments);
500 (void)annotate(drft, attach, (char *)0, 1, 0, n, 1);
502 for (argp = arguments + 1; *argp != (char *)0; argp++) {
503 if (atoi(*argp) > n) {
504 if (atoi(*argp) == 1)
507 (void)sprintf(*argp, "%d", atoi(*argp) - 1);
515 * The arguments are interpreted as file names. Run them through the
516 * user's shell for wildcard expansion and other goodies. Do this from
517 * the current working directory if the argument is not an absolute path
518 * name (does not begin with a /).
520 * We feed all the file names to the shell at once, otherwise you can't
521 * provide a file name with a space in it.
523 writelscmd(buf, sizeof(buf), argp);
524 if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
525 while (fgets(shell, sizeof (shell), f) != (char *)0) {
526 *(strchr(shell, '\n')) = '\0';
527 (void)annotate(drft, attach, shell, 1, 0, 0, 1);
531 advise("popen", "could not get file from shell");
537 /* Unknown command */
538 advise (NULL, "say what?");
547 /* Build a command line of the form $SHELL -c "cd 'cwd'; cmd argp ... ; trailcmd". */
549 writesomecmd(char *buf, int bufsz, char *cmd, char *trailcmd, char **argp)
552 /* Note that we do not quote -- the argp from the user
553 * is assumed to be quoted as they desire. (We can't treat
554 * it as pure literal as that would prevent them using ~,
555 * wildcards, etc.) The buffer produced by this function
556 * should be given to popen_in_dir() or system_in_dir() so
557 * that the current working directory is set correctly.
559 int ln = snprintf(buf, bufsz, "$SHELL -c \"%s", cmd);
560 /* NB that some snprintf() return -1 on overflow rather than the
561 * new C99 mandated 'number of chars that would have been written'
563 /* length checks here and inside the loop allow for the
564 * trailing ';', trailcmd, '"' and NUL
566 int trailln = strlen(trailcmd) + 3;
567 if (ln < 0 || ln + trailln > bufsz)
568 adios((char *)0, "arguments too long");
572 while (*++argp != (char *)0) {
574 /* +1 for leading space */
575 if (ln + trailln + 1 > bufsz - (cp-buf))
576 adios((char *)0, "arguments too long");
578 memcpy(cp, *argp, ln+1);
583 strcpy(cp, trailcmd);
591 * Build a command line that causes the user's shell to list the file name
592 * arguments. This handles and wildcard expansion, tilde expansion, etc.
595 writelscmd(char *buf, int bufsz, char **argp)
597 writesomecmd(buf, bufsz, "ls", "", argp);
600 /* Like system(), but run the command in directory dir.
601 * This assumes the program is single-threaded!
604 system_in_dir(const char *dir, const char *cmd)
608 if (getcwd(olddir, sizeof(olddir)) == 0)
609 adios("getcwd", "could not get working directory");
611 adios("chdir", "could not change working directory");
613 if (chdir(olddir) != 0)
614 adios("chdir", "could not change working directory");
618 /* ditto for popen() */
620 popen_in_dir(const char *dir, const char *cmd, const char *type)
624 if (getcwd(olddir, sizeof(olddir)) == 0)
625 adios("getcwd", "could not get working directory");
627 adios("chdir", "could not change working directory");
628 f = popen(cmd, type);
629 if (chdir(olddir) != 0)
630 adios("chdir", "could not change working directory");
639 static int reedit = 0; /* have we been here before? */
640 static char *edsave = NULL; /* the editor we used previously */
644 editfile (char **ed, char **arg, char *file, int use, struct msgs *mp,
645 char *altmsg, char *cwd, int save_editor, int atfile)
647 int pid, status, vecp;
648 char altpath[BUFSIZ], linkpath[BUFSIZ];
649 char *cp, *vec[MAXARGS];
654 #endif /* HAVE_LSTAT */
656 /* Was there a previous edit session? */
658 if (!*ed) { /* no explicit editor */
659 *ed = edsave; /* so use the previous one */
660 if ((cp = r1bindex (*ed, '/')) == NULL)
663 /* unless we've specified it via "editor-next" */
664 cp = concat (cp, "-next", NULL);
665 if ((cp = context_find (cp)) != NULL)
669 /* set initial editor */
670 if (*ed == NULL && (*ed = context_find ("editor")) == NULL)
674 if (altmsg && atfile) {
675 if (mp == NULL || *altmsg == '/' || cwd == NULL)
676 strncpy (altpath, altmsg, sizeof(altpath));
678 snprintf (altpath, sizeof(altpath), "%s/%s", mp->foldpath, altmsg);
680 strncpy (linkpath, LINK, sizeof(linkpath));
682 snprintf (linkpath, sizeof(linkpath), "%s/%s", cwd, LINK);
686 if (link (altpath, linkpath) == NOTOK) {
687 symlink (altpath, linkpath);
692 #else /* not HAVE_LSTAT */
693 link (altpath, linkpath);
694 #endif /* not HAVE_LSTAT */
697 context_save (); /* save the context file */
700 switch (pid = vfork()) {
702 advise ("fork", "unable to");
711 m_putenv ("mhfolder", mp->foldpath);
712 m_putenv ("editalt", altpath);
716 vec[vecp++] = r1bindex (*ed, '/');
719 vec[vecp++] = *arg++;
724 fprintf (stderr, "unable to exec ");
729 if ((status = pidwait (pid, NOTOK))) {
730 if (((status & 0xff00) != 0xff00)
731 && (!reedit || (status & 0x00ff))) {
732 if (!use && (status & 0xff00) &&
733 (rename (file, cp = m_backup (file)) != NOTOK)) {
734 advise (NULL, "problems with edit--draft left in %s", cp);
736 advise (NULL, "problems with edit--%s preserved", file);
739 status = -2; /* maybe "reedit ? -2 : -1"? */
749 ? lstat (linkpath, &st) != NOTOK
750 && S_ISREG(st.st_mode)
751 && copyf (linkpath, altpath) == NOTOK
752 : stat (linkpath, &st) != NOTOK
754 && (unlink (altpath) == NOTOK
755 || link (linkpath, altpath) == NOTOK)))
756 advise (linkpath, "unable to update %s from", altmsg);
757 #else /* HAVE_LSTAT */
761 && stat (linkpath, &st) != NOTOK
763 && (unlink (altpath) == NOTOK
764 || link (linkpath, altpath) == NOTOK))
765 advise (linkpath, "unable to update %s from", altmsg);
766 #endif /* HAVE_LSTAT */
769 /* normally, we remember which editor we used */
771 edsave = getcpy (*ed);
774 if (altmsg && atfile)
783 copyf (char *ifile, char *ofile)
788 if ((in = open (ifile, O_RDONLY)) == NOTOK)
790 if ((out = open (ofile, O_WRONLY | O_TRUNC)) == NOTOK) {
791 admonish (ofile, "unable to open and truncate");
796 while ((i = read (in, buffer, sizeof(buffer))) > OK)
797 if (write (out, buffer, i) != i) {
798 advise (ofile, "may have damaged");
807 #endif /* HAVE_LSTAT */
815 sendfile (char **arg, char *file, int pushsw)
819 char *cp, *sp, *vec[MAXARGS];
821 /* Translate MIME composition file, if necessary */
822 if ((cp = context_find ("automimeproc"))
823 && (!strcmp (cp, "1"))
824 && check_draft (file)
825 && (buildfile (NULL, file) == NOTOK))
828 /* For backwards compatibility */
829 if ((cp = context_find ("automhnproc"))
830 && check_draft (file)
831 && (i = editfile (&cp, NULL, file, NOUSE, NULL, NULL, NULL, 0, 0)))
835 * If the sendproc is the nmh command `send', then we call
836 * those routines directly rather than exec'ing the command.
838 if (strcmp (sp = r1bindex (sendproc, '/'), "send") == 0) {
840 sendit (invo_name = sp, arg, file, pushsw);
845 context_save (); /* save the context file */
848 for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++)
852 advise (NULL, "unable to fork, so sending directly...");
855 vec[vecp++] = invo_name;
857 vec[vecp++] = "-push";
860 vec[vecp++] = *arg++;
864 execvp (sendproc, vec);
865 fprintf (stderr, "unable to exec ");
870 if (pidwait(child_id, OK) == 0)
878 * Translate MIME composition file (call buildmimeproc)
882 buildfile (char **argp, char *file)
889 /* allocate space for arguments */
895 args = (char **) mh_xmalloc((i + 2) * sizeof(char *));
898 * For backward compatibility, we need to add -build
899 * if we are using mhn as buildmimeproc
902 if (strcmp (r1bindex (ed, '/'), "mhn") == 0)
903 args[i++] = "-build";
905 /* copy any other arguments */
906 while (argp && *argp)
910 i = editfile (&ed, args, file, NOUSE, NULL, NULL, NULL, 0, 0);
913 return (i ? NOTOK : OK);
918 * Check if draft is a mhbuild composition file
922 check_draft (char *msgnam)
925 char buf[BUFSIZ], name[NAMESZ];
928 if ((fp = fopen (msgnam, "r")) == NULL)
931 switch (state = m_getfld (state, name, buf, sizeof(buf), fp)) {
936 * If draft already contains any of the
937 * Content-XXX fields, then assume it already
940 if (uprf (name, XXX_FIELD_PRF)) {
944 while (state == FLDPLUS)
945 state = m_getfld (state, name, buf, sizeof(buf), fp);
952 for (bp = buf; *bp; bp++)
953 if (*bp != ' ' && *bp != '\t' && *bp != '\n') {
958 state = m_getfld (state, name, buf, sizeof(buf), fp);
959 } while (state == BODY);
970 # define SASLminc(a) (a)
971 #else /* CYRUS_SASL */
972 # define SASLminc(a) 0
973 #endif /* CYRUS_SASL */
976 # define TLSminc(a) (a)
977 #else /* TLS_SUPPORT */
978 # define TLSminc(a) 0
979 #endif /* TLS_SUPPORT */
981 static struct swit sendswitches[] = {
983 { "alias aliasfile", 0 },
987 { "filter filterfile", 0 },
1011 { "split seconds", 0 },
1025 { "width columns", 0 },
1026 #define SVERSIONSW 22
1030 #define BITSTUFFSW 24
1031 { "dashstuffing", -12 },
1032 #define NBITSTUFFSW 25
1033 { "nodashstuffing", -14 },
1043 { "client host", -6 },
1045 { "server host", 6 },
1049 { "draftfolder +folder", -6 },
1051 { "draftmessage msg", -6 },
1053 { "nodraftfolder", -3 },
1055 { "sasl", SASLminc(-4) },
1057 { "nosasl", SASLminc(-6) },
1058 #define SASLMXSSFSW 38
1059 { "saslmaxssf", SASLminc(-10) },
1060 #define SASLMECHSW 39
1061 { "saslmech", SASLminc(-5) },
1063 { "user", SASLminc(-4) },
1064 #define SNDATTACHSW 41
1065 { "attach file", 6 },
1066 #define SNDNOATTACHSW 42
1068 #define SNDATTACHFORMAT 43
1069 { "attachformat", 7 },
1071 { "port server-port-name/number", 4 },
1073 { "tls", TLSminc(-3) },
1075 { "notls", TLSminc(-5) },
1080 extern int debugsw; /* from sendsbr.c */
1088 extern char *altmsg; /* .. */
1089 extern char *annotext;
1090 extern char *distfile;
1094 sendit (char *sp, char **arg, char *file, int pushed)
1097 char *cp, buf[BUFSIZ], **argp;
1098 char **arguments, *vec[MAXARGS];
1100 char *attach = NMH_ATTACH_HEADER;/* attachment header field name */
1101 int attachformat = 1; /* mhbuild format specifier for
1109 * Make sure these are defined. In particular, we need
1110 * vec[1] to be NULL, in case "arg" is NULL below. It
1111 * doesn't matter what is the value of vec[0], but we
1112 * set it to NULL, to help catch "off-by-one" errors.
1118 * Temporarily copy arg to vec, since the brkstring() call in
1119 * getarguments() will wipe it out before it is merged in.
1120 * Also, we skip the first element of vec, since getarguments()
1121 * skips it. Then we count the number of arguments
1122 * copied. The value of "n" will be one greater than
1123 * this in order to simulate the standard argc/argv.
1128 copyip (arg, vec+1, MAXARGS-1);
1135 * Merge any arguments from command line (now in vec)
1136 * and arguments from profile.
1138 arguments = getarguments (sp, n, vec, 1);
1150 vecp = 1; /* we'll get the zero'th element later */
1151 vec[vecp++] = "-library";
1152 vec[vecp++] = getcpy (m_maildir (""));
1154 if ((cp = context_find ("fileproc"))) {
1155 vec[vecp++] = "-fileproc";
1159 if ((cp = context_find ("mhlproc"))) {
1160 vec[vecp++] = "-mhlproc";
1164 while ((cp = *argp++)) {
1166 switch (smatch (++cp, sendswitches)) {
1168 ambigsw (cp, sendswitches);
1171 advise (NULL, "-%s unknown\n", cp);
1175 snprintf (buf, sizeof(buf), "%s [switches]", sp);
1176 print_help (buf, sendswitches, 1);
1179 print_version (invo_name);
1190 if (!(cp = *argp++) || sscanf (cp, "%d", &splitsw) != 1) {
1191 advise (NULL, "missing argument to %s", argp[-2]);
1219 debugsw++; /* fall */
1253 if (!(cp = *argp++) || *cp == '-') {
1254 advise (NULL, "missing argument to %s", argp[-2]);
1262 if (!(cp = *argp++) || *cp == '-') {
1263 advise (NULL, "missing argument to %s", argp[-2]);
1270 if (!(attach = *argp++) || *attach == '-') {
1271 advise (NULL, "missing argument to %s", argp[-2]);
1279 case SNDATTACHFORMAT:
1280 if (! *argp || **argp == '-')
1281 adios (NULL, "missing argument to %s", argp[-1]);
1283 attachformat = atoi (*argp);
1284 if (attachformat < 0 ||
1285 attachformat > ATTACHFORMATS - 1) {
1286 advise (NULL, "unsupported attachformat %d",
1295 advise (NULL, "usage: %s [switches]", sp);
1299 /* allow Aliasfile: profile entry */
1300 if ((cp = context_find ("Aliasfile"))) {
1304 for (ap = brkstring (dp, " ", "\n"); ap && *ap; ap++) {
1305 vec[vecp++] = "-alias";
1310 if ((cp = getenv ("SIGNATURE")) == NULL || *cp == 0)
1311 if ((cp = context_find ("signature")) && *cp)
1312 m_putenv ("SIGNATURE", cp);
1314 if ((annotext = getenv ("mhannotate")) == NULL || *annotext == 0)
1316 if ((altmsg = getenv ("mhaltmsg")) == NULL || *altmsg == 0)
1318 if (annotext && ((cp = getenv ("mhinplace")) != NULL && *cp != 0))
1319 inplace = atoi (cp);
1321 if ((cp = getenv ("mhdist"))
1324 && (distsw = atoi (cp))
1325 #endif /* not lint */
1327 vec[vecp++] = "-dist";
1328 distfile = getcpy (m_mktemp2(altmsg, invo_name, NULL, NULL));
1330 if (link (altmsg, distfile) == NOTOK)
1331 adios (distfile, "unable to link %s to", altmsg);
1336 if (altmsg == NULL || stat (altmsg, &st) == NOTOK) {
1341 if ((pushsw = pushed))
1344 vec[0] = r1bindex (postproc, '/');
1347 if (sendsbr (vec, vecp, file, &st, 1, attach, attachformat) == OK)
1356 whomfile (char **arg, char *file)
1362 context_save (); /* save the context file */
1365 switch (pid = vfork()) {
1367 advise ("fork", "unable to");
1372 vec[vecp++] = r1bindex (whomproc, '/');
1376 vec[vecp++] = *arg++;
1379 execvp (whomproc, vec);
1380 fprintf (stderr, "unable to exec ");
1382 _exit (-1); /* NOTREACHED */
1385 return (pidwait (pid, NOTOK) & 0377 ? 1 : 0);
1391 * Remove the draft file
1395 removefile (char *drft)
1397 if (unlink (drft) == NOTOK)
1398 adios (drft, "unable to unlink");