3 * whatnowsbr.c -- the WhatNow shell
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
11 * Several options have been added to ease the inclusion of attachments
12 * using the header field name mechanism added to anno and send. The
13 * -attach option is used to specify the header field name for attachments.
15 * Several commands have been added at the whatnow prompt:
17 * cd [ directory ] This option works just like the shell's
18 * cd command and lets the user change the
19 * directory from which attachments are
20 * taken so that long path names are not
21 * needed with every file.
23 * ls [ ls-options ] This option works just like the normal
24 * ls command and exists to allow the user
25 * to verify file names in the directory.
27 * pwd This option works just like the normal
28 * pwd command and exists to allow the user
29 * to verify the directory.
31 * attach files This option attaches the named files to
34 * alist [-ln] This option lists the attachments on the
35 * draft. -l gets long listings, -n gets
38 * detach files This option removes attachments from the
39 * detach -n numbers draft. This can be done by file name or
40 * by attachment number.
49 static struct swit whatnowswitches[] = {
51 { "draftfolder +folder", 0 },
53 { "draftmessage msg", 0 },
55 { "nodraftfolder", 0 },
57 { "editor editor", 0 },
61 { "prompt string", 4 },
67 { "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 = (char *)0; /* 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 != (char *)0)
219 adios(NULL, "only one attachment header field name at a time!");
220 if (!(attach = *argp++) || *attach == '-')
221 adios (NULL, "missing argument to %s", argp[-2]);
226 adios (NULL, "only one draft at a time!");
231 if ((drft == NULL && (drft = getenv ("mhdraft")) == NULL) || *drft == 0)
232 drft = getcpy (m_draft (dfolder, dmsg, 1, &isdf));
234 msgnam = (cp = getenv ("mhaltmsg")) && *cp ? getcpy (cp) : NULL;
236 if ((cp = getenv ("mhuse")) && *cp)
239 if (ed == NULL && ((ed = getenv ("mheditor")) == NULL || *ed == 0)) {
244 /* start editing the draft, unless -noedit was given */
245 if (!nedit && editfile (&ed, NULL, drft, use, NULL, msgnam, NULL, 1) < 0)
248 snprintf (prompt, sizeof(prompt), myprompt, invo_name);
250 if (!(argp = getans (prompt, aleqs))) {
254 switch (smatch (*argp, aleqs)) {
256 /* display the message being replied to, or distributed */
258 showfile (++argp, msgnam);
260 advise (NULL, "no alternate message to display");
264 /* Translate MIME composition file */
265 buildfile (++argp, drft);
269 /* Call an editor on the draft file */
272 if (editfile (&ed, argp, drft, NOUSE, NULL, msgnam, NULL, 1) == NOTOK)
277 /* display the draft file */
278 showfile (++argp, drft);
282 /* Check to whom the draft would be sent */
283 whomfile (++argp, drft);
287 /* Quit, and possibly delete the draft */
288 if (*++argp && (*argp[0] == 'd' ||
289 ((*argp)[0] == '-' && (*argp)[1] == 'd'))) {
292 if (stat (drft, &st) != NOTOK)
293 advise (NULL, "draft left on %s", drft);
298 /* Delete draft and exit */
303 /* Send draft in background */
304 if (sendfile (++argp, drft, 1))
310 sendfile (++argp, drft, 0);
314 /* Refile the draft */
315 if (refile (++argp, drft) == 0)
320 /* Change the working directory for attachments
322 * Run the directory through the user's shell so that
323 * we can take advantage of any syntax that the user
324 * is accustomed to. Read back the absolute path.
327 if (*(argp+1) == (char *)0) {
328 (void)sprintf(buf, "$SHELL -c \"cd;pwd\"");
331 writesomecmd(buf, BUFSIZ, "cd", "pwd", argp);
333 if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
334 fgets(cwd, sizeof (cwd), f);
336 if (strchr(cwd, '\n') != (char *)0)
337 *strchr(cwd, '\n') = '\0';
342 advise("popen", "could not get directory");
348 /* Print the working directory for attachments */
353 /* List files in the current attachment working directory
355 * Use the user's shell so that we can take advantage of any
356 * syntax that the user is accustomed to.
358 writelscmd(buf, sizeof(buf), argp);
359 (void)system_in_dir(cwd, buf);
364 * List attachments on current draft. Options are:
366 * -l long listing (full path names)
370 if (attach == (char *)0) {
371 advise((char *)0, "can't list because no header field name was given.");
378 while (*++argp != (char *)0) {
379 if (strcmp(*argp, "-l") == 0)
382 else if (strcmp(*argp, "-n") == 0)
385 else if (strcmp(*argp, "-ln") == 0 || strcmp(*argp, "-nl") == 0) {
397 advise((char *)0, "usage is alist [-ln].");
400 annolist(drft, attach, l, n);
406 * Attach files to current draft.
409 if (attach == (char *)0) {
410 advise((char *)0, "can't attach because no header field name was given.");
415 * Build a command line that causes the user's shell to list the file name
416 * arguments. This handles and wildcard expansion, tilde expansion, etc.
418 writelscmd(buf, sizeof(buf), argp);
421 * Read back the response from the shell, which contains a number of lines
422 * with one file name per line. Remove off the newline. Determine whether
423 * we have an absolute or relative path name. Prepend the current working
424 * directory to relative path names. Add the attachment annotation to the
428 if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
429 while (fgets(shell, sizeof (shell), f) != (char *)0) {
430 *(strchr(shell, '\n')) = '\0';
433 (void)annotate(drft, attach, shell, 1, 0, -2, 1);
435 (void)sprintf(file, "%s/%s", cwd, shell);
436 (void)annotate(drft, attach, file, 1, 0, -2, 1);
443 advise("popen", "could not get file from shell");
450 * Detach files from current draft.
453 if (attach == (char *)0) {
454 advise((char *)0, "can't detach because no header field name was given.");
459 * Scan the arguments for a -n. Mixed file names and numbers aren't allowed,
460 * so this catches a -n anywhere in the argument list.
463 for (n = 0, arguments = argp + 1; *arguments != (char *)0; arguments++) {
464 if (strcmp(*arguments, "-n") == 0) {
471 * A -n was found so interpret the arguments as attachment numbers.
472 * Decrement any remaining argument number that is greater than the one
473 * just processed after processing each one so that the numbering stays
478 for (arguments = argp + 1; *arguments != (char *)0; arguments++) {
479 if (strcmp(*arguments, "-n") == 0)
482 if (**arguments != '\0') {
483 n = atoi(*arguments);
484 (void)annotate(drft, attach, (char *)0, 1, 0, n, 1);
486 for (argp = arguments + 1; *argp != (char *)0; argp++) {
487 if (atoi(*argp) > n) {
488 if (atoi(*argp) == 1)
491 (void)sprintf(*argp, "%d", atoi(*argp) - 1);
499 * The arguments are interpreted as file names. Run them through the
500 * user's shell for wildcard expansion and other goodies. Do this from
501 * the current working directory if the argument is not an absolute path
502 * name (does not begin with a /).
504 * We feed all the file names to the shell at once, otherwise you can't
505 * provide a file name with a space in it.
507 writelscmd(buf, sizeof(buf), argp);
508 if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
509 while (fgets(shell, sizeof (shell), f) != (char *)0) {
510 *(strchr(shell, '\n')) = '\0';
511 (void)annotate(drft, attach, shell, 1, 0, 0, 1);
515 advise("popen", "could not get file from shell");
521 /* Unknown command */
522 advise (NULL, "say what?");
531 /* Build a command line of the form $SHELL -c "cd 'cwd'; cmd argp ... ; trailcmd". */
533 writesomecmd(char *buf, int bufsz, char *cmd, char *trailcmd, char **argp)
536 /* Note that we do not quote -- the argp from the user
537 * is assumed to be quoted as they desire. (We can't treat
538 * it as pure literal as that would prevent them using ~,
539 * wildcards, etc.) The buffer produced by this function
540 * should be given to popen_in_dir() or system_in_dir() so
541 * that the current working directory is set correctly.
543 int ln = snprintf(buf, bufsz, "$SHELL -c \"%s", cmd);
544 /* NB that some snprintf() return -1 on overflow rather than the
545 * new C99 mandated 'number of chars that would have been written'
547 /* length checks here and inside the loop allow for the
548 * trailing ';', trailcmd, '"' and NUL
550 int trailln = strlen(trailcmd) + 3;
551 if (ln < 0 || ln + trailln > bufsz)
552 adios((char *)0, "arguments too long");
556 while (*++argp != (char *)0) {
558 /* +1 for leading space */
559 if (ln + trailln + 1 > bufsz - (cp-buf))
560 adios((char *)0, "arguments too long");
562 memcpy(cp, *argp, ln+1);
567 strcpy(cp, trailcmd);
575 * Build a command line that causes the user's shell to list the file name
576 * arguments. This handles and wildcard expansion, tilde expansion, etc.
579 writelscmd(char *buf, int bufsz, char **argp)
581 writesomecmd(buf, bufsz, "ls", "", argp);
584 /* Like system(), but run the command in directory dir.
585 * This assumes the program is single-threaded!
588 system_in_dir(const char *dir, const char *cmd)
592 if (getcwd(olddir, sizeof(olddir)) == 0)
593 adios("getcwd", "could not get working directory");
595 adios("chdir", "could not change working directory");
597 if (chdir(olddir) != 0)
598 adios("chdir", "could not change working directory");
602 /* ditto for popen() */
604 popen_in_dir(const char *dir, const char *cmd, const char *type)
608 if (getcwd(olddir, sizeof(olddir)) == 0)
609 adios("getcwd", "could not get working directory");
611 adios("chdir", "could not change working directory");
612 f = popen(cmd, type);
613 if (chdir(olddir) != 0)
614 adios("chdir", "could not change working directory");
623 static int reedit = 0; /* have we been here before? */
624 static char *edsave = NULL; /* the editor we used previously */
628 editfile (char **ed, char **arg, char *file, int use, struct msgs *mp,
629 char *altmsg, char *cwd, int save_editor)
631 int pid, status, vecp;
632 char altpath[BUFSIZ], linkpath[BUFSIZ];
633 char *cp, *vec[MAXARGS];
639 int oumask; /* PJS: for setting permissions on symlinks. */
641 #endif /* HAVE_LSTAT */
643 /* Was there a previous edit session? */
645 if (!*ed) { /* no explicit editor */
646 *ed = edsave; /* so use the previous one */
647 if ((cp = r1bindex (*ed, '/')) == NULL)
650 /* unless we've specified it via "editor-next" */
651 cp = concat (cp, "-next", NULL);
652 if ((cp = context_find (cp)) != NULL)
656 /* set initial editor */
657 if (*ed == NULL && (*ed = context_find ("editor")) == NULL)
662 if (mp == NULL || *altmsg == '/' || cwd == NULL)
663 strncpy (altpath, altmsg, sizeof(altpath));
665 snprintf (altpath, sizeof(altpath), "%s/%s", mp->foldpath, altmsg);
667 strncpy (linkpath, LINK, sizeof(linkpath));
669 snprintf (linkpath, sizeof(linkpath), "%s/%s", cwd, LINK);
675 if (link (altpath, linkpath) == NOTOK) {
677 /* I don't think permission on symlinks matters /JLR */
678 oumask = umask(0044); /* PJS: else symlinks are world 'r' */
680 symlink (altpath, linkpath);
682 umask(oumask); /* PJS: else symlinks are world 'r' */
688 #else /* not HAVE_LSTAT */
689 link (altpath, linkpath);
690 #endif /* not HAVE_LSTAT */
693 context_save (); /* save the context file */
696 switch (pid = vfork ()) {
698 advise ("fork", "unable to");
707 m_putenv ("mhfolder", mp->foldpath);
708 m_putenv ("editalt", altpath);
712 vec[vecp++] = r1bindex (*ed, '/');
715 vec[vecp++] = *arg++;
720 fprintf (stderr, "unable to exec ");
725 if ((status = pidwait (pid, NOTOK))) {
727 if ((cp = r1bindex (*ed, '/'))
728 && strcmp (cp, "vi") == 0
729 && (status & 0x00ff) == 0)
733 if (((status & 0xff00) != 0xff00)
734 && (!reedit || (status & 0x00ff))) {
735 if (!use && (status & 0xff00) &&
736 (rename (file, cp = m_backup (file)) != NOTOK)) {
737 advise (NULL, "problems with edit--draft left in %s", cp);
739 advise (NULL, "problems with edit--%s preserved", file);
742 status = -2; /* maybe "reedit ? -2 : -1"? */
755 ? lstat (linkpath, &st) != NOTOK
756 && S_ISREG(st.st_mode)
757 && copyf (linkpath, altpath) == NOTOK
758 : stat (linkpath, &st) != NOTOK
760 && (unlink (altpath) == NOTOK
761 || link (linkpath, altpath) == NOTOK)))
762 advise (linkpath, "unable to update %s from", altmsg);
763 #else /* HAVE_LSTAT */
767 && stat (linkpath, &st) != NOTOK
769 && (unlink (altpath) == NOTOK
770 || link (linkpath, altpath) == NOTOK))
771 advise (linkpath, "unable to update %s from", altmsg);
772 #endif /* HAVE_LSTAT */
775 /* normally, we remember which editor we used */
777 edsave = getcpy (*ed);
789 copyf (char *ifile, char *ofile)
794 if ((in = open (ifile, O_RDONLY)) == NOTOK)
796 if ((out = open (ofile, O_WRONLY | O_TRUNC)) == NOTOK) {
797 admonish (ofile, "unable to open and truncate");
802 while ((i = read (in, buffer, sizeof(buffer))) > OK)
803 if (write (out, buffer, i) != i) {
804 advise (ofile, "may have damaged");
813 #endif /* HAVE_LSTAT */
821 sendfile (char **arg, char *file, int pushsw)
825 char *cp, *sp, *vec[MAXARGS];
827 /* Translate MIME composition file, if necessary */
828 if ((cp = context_find ("automimeproc"))
829 && (!strcmp (cp, "1"))
830 && !getenv ("NOMHNPROC")
831 && check_draft (file)
832 && (buildfile (NULL, file) == NOTOK))
835 /* For backwards compatibility */
836 if ((cp = context_find ("automhnproc"))
837 && !getenv ("NOMHNPROC")
838 && check_draft (file)
839 && (i = editfile (&cp, NULL, file, NOUSE, NULL, NULL, NULL, 0)))
843 * If the sendproc is the nmh command `send', then we call
844 * those routines directly rather than exec'ing the command.
846 if (strcmp (sp = r1bindex (sendproc, '/'), "send") == 0) {
848 sendit (invo_name = sp, arg, file, pushsw);
853 context_save (); /* save the context file */
856 for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++)
860 advise (NULL, "unable to fork, so sending directly...");
863 vec[vecp++] = invo_name;
865 vec[vecp++] = "-push";
868 vec[vecp++] = *arg++;
872 execvp (sendproc, vec);
873 fprintf (stderr, "unable to exec ");
878 if (pidwait(child_id, OK) == 0)
886 * Translate MIME composition file (call buildmimeproc)
890 buildfile (char **argp, char *file)
897 /* allocate space for arguments */
903 args = (char **) mh_xmalloc((i + 2) * sizeof(char *));
906 * For backward compatibility, we need to add -build
907 * if we are using mhn as buildmimeproc
910 if (strcmp (r1bindex (ed, '/'), "mhn") == 0)
911 args[i++] = "-build";
913 /* copy any other arguments */
914 while (argp && *argp)
918 i = editfile (&ed, args, file, NOUSE, NULL, NULL, NULL, 0);
921 return (i ? NOTOK : OK);
926 * Check if draft is a mhbuild composition file
930 check_draft (char *msgnam)
933 char buf[BUFSIZ], name[NAMESZ];
936 if ((fp = fopen (msgnam, "r")) == NULL)
939 switch (state = m_getfld (state, name, buf, sizeof(buf), fp)) {
944 * If draft already contains any of the
945 * Content-XXX fields, then assume it already
948 if (uprf (name, XXX_FIELD_PRF)) {
952 while (state == FLDPLUS)
953 state = m_getfld (state, name, buf, sizeof(buf), fp);
960 for (bp = buf; *bp; bp++)
961 if (*bp != ' ' && *bp != '\t' && *bp != '\n') {
966 state = m_getfld (state, name, buf, sizeof(buf), fp);
967 } while (state == BODY);
978 # define SASLminc(a) (a)
979 #else /* CYRUS_SASL */
980 # define SASLminc(a) 0
981 #endif /* CYRUS_SASL */
983 static struct swit sendswitches[] = {
985 { "alias aliasfile", 0 },
989 { "filter filterfile", 0 },
1013 { "split seconds", 0 },
1027 { "width columns", 0 },
1028 #define SVERSIONSW 22
1032 #define BITSTUFFSW 24
1033 { "dashstuffing", -12 },
1034 #define NBITSTUFFSW 25
1035 { "nodashstuffing", -14 },
1045 { "client host", -6 },
1047 { "server host", -6 },
1051 { "draftfolder +folder", -6 },
1053 { "draftmessage msg", -6 },
1055 { "nodraftfolder", -3 },
1057 { "sasl", SASLminc(-4) },
1058 #define SASLMECHSW 37
1059 { "saslmech", SASLminc(-5) },
1061 { "user", SASLminc(-4) },
1062 #define SNDATTACHSW 39
1063 { "attach file", 6 },
1064 #define SNDATTACHFORMAT 40
1065 { "attachformat", 7 },
1070 extern int debugsw; /* from sendsbr.c */
1078 extern char *altmsg; /* .. */
1079 extern char *annotext;
1080 extern char *distfile;
1084 sendit (char *sp, char **arg, char *file, int pushed)
1087 char *cp, buf[BUFSIZ], **argp;
1088 char **arguments, *vec[MAXARGS];
1090 char *attach = (char *)0; /* attachment header field name */
1091 int attachformat = 0; /* mhbuild format specifier for
1102 * Make sure these are defined. In particular, we need
1103 * vec[1] to be NULL, in case "arg" is NULL below. It
1104 * doesn't matter what is the value of vec[0], but we
1105 * set it to NULL, to help catch "off-by-one" errors.
1111 * Temporarily copy arg to vec, since the brkstring() call in
1112 * getarguments() will wipe it out before it is merged in.
1113 * Also, we skip the first element of vec, since getarguments()
1114 * skips it. Then we count the number of arguments
1115 * copied. The value of "n" will be one greater than
1116 * this in order to simulate the standard argc/argv.
1121 copyip (arg, vec+1, MAXARGS-1);
1128 * Merge any arguments from command line (now in vec)
1129 * and arguments from profile.
1131 arguments = getarguments (sp, n, vec, 1);
1143 vecp = 1; /* we'll get the zero'th element later */
1144 vec[vecp++] = "-library";
1145 vec[vecp++] = getcpy (m_maildir (""));
1147 while ((cp = *argp++)) {
1149 switch (smatch (++cp, sendswitches)) {
1151 ambigsw (cp, sendswitches);
1154 advise (NULL, "-%s unknown\n", cp);
1158 snprintf (buf, sizeof(buf), "%s [switches]", sp);
1159 print_help (buf, sendswitches, 1);
1162 print_version (invo_name);
1173 if (!(cp = *argp++) || sscanf (cp, "%d", &splitsw) != 1) {
1174 advise (NULL, "missing argument to %s", argp[-2]);
1202 debugsw++; /* fall */
1231 if (!(cp = *argp++) || *cp == '-') {
1232 advise (NULL, "missing argument to %s", argp[-2]);
1240 if (!(cp = *argp++) || *cp == '-') {
1241 advise (NULL, "missing argument to %s", argp[-2]);
1248 if (!(attach = *argp++) || *attach == '-') {
1249 advise (NULL, "missing argument to %s", argp[-2]);
1254 case SNDATTACHFORMAT:
1255 if (! *argp || **argp == '-')
1256 adios (NULL, "missing argument to %s", argp[-1]);
1258 attachformat = atoi (*argp);
1259 if (attachformat < 0 ||
1260 attachformat > ATTACHFORMATS - 1) {
1261 advise (NULL, "unsupported attachformat %d",
1270 advise (NULL, "usage: %s [switches]", sp);
1274 /* allow Aliasfile: profile entry */
1275 if ((cp = context_find ("Aliasfile"))) {
1279 for (ap = brkstring (dp, " ", "\n"); ap && *ap; ap++) {
1280 vec[vecp++] = "-alias";
1285 if ((cp = getenv ("SIGNATURE")) == NULL || *cp == 0)
1286 if ((cp = context_find ("signature")) && *cp)
1287 m_putenv ("SIGNATURE", cp);
1290 snprintf (buf, sizeof(buf), "%s/.signature", mypath);
1291 if ((fp = fopen (buf, "r")) != NULL
1292 && fgets (buf, sizeof(buf), fp) != NULL) {
1294 if (cp = strchr (buf, '\n'))
1296 m_putenv ("SIGNATURE", buf);
1301 if ((annotext = getenv ("mhannotate")) == NULL || *annotext == 0)
1303 if ((altmsg = getenv ("mhaltmsg")) == NULL || *altmsg == 0)
1305 if (annotext && ((cp = getenv ("mhinplace")) != NULL && *cp != 0))
1306 inplace = atoi (cp);
1308 if ((cp = getenv ("mhdist"))
1311 && (distsw = atoi (cp))
1312 #endif /* not lint */
1314 vec[vecp++] = "-dist";
1315 distfile = getcpy (m_scratch (altmsg, invo_name));
1316 if (link (altmsg, distfile) == NOTOK)
1317 adios (distfile, "unable to link %s to", altmsg);
1322 if (altmsg == NULL || stat (altmsg, &st) == NOTOK) {
1327 if ((pushsw = pushed))
1330 vec[0] = r1bindex (postproc, '/');
1333 if (sendsbr (vec, vecp, file, &st, 1, attach, attachformat) == OK)
1342 whomfile (char **arg, char *file)
1348 context_save (); /* save the context file */
1351 switch (pid = vfork ()) {
1353 advise ("fork", "unable to");
1358 vec[vecp++] = r1bindex (whomproc, '/');
1362 vec[vecp++] = *arg++;
1365 execvp (whomproc, vec);
1366 fprintf (stderr, "unable to exec ");
1368 _exit (-1); /* NOTREACHED */
1371 return (pidwait (pid, NOTOK) & 0377 ? 1 : 0);
1377 * Remove the draft file
1381 removefile (char *drft)
1383 if (unlink (drft) == NOTOK)
1384 adios (drft, "unable to unlink");