2 * whatnowsbr.c -- the WhatNow shell
4 * This code is Copyright (c) 2002, by the authors of nmh. See the
5 * COPYRIGHT file in the root directory of the nmh distribution for
6 * complete copyright information.
8 * Several options have been added to ease the inclusion of attachments
9 * using the header field name mechanism added to anno and send. The
10 * -attach option is used to specify the header field name for attachments.
12 * Several commands have been added at the whatnow prompt:
14 * cd [ directory ] This option works just like the shell's
15 * cd command and lets the user change the
16 * directory from which attachments are
17 * taken so that long path names are not
18 * needed with every file.
20 * ls [ ls-options ] This option works just like the normal
21 * ls command and exists to allow the user
22 * to verify file names in the directory.
24 * pwd This option works just like the normal
25 * pwd command and exists to allow the user
26 * to verify the directory.
28 * attach files This option attaches the named files to
31 * alist [-ln] This option lists the attachments on the
32 * draft. -l gets long listings, -n gets
35 * detach files This option removes attachments from the
36 * detach -n numbers draft. This can be done by file name or
37 * by attachment number.
46 static struct swit whatnowswitches[] = {
48 { "draftfolder +folder", 0 },
50 { "draftmessage msg", 0 },
52 { "nodraftfolder", 0 },
54 { "editor editor", 0 },
58 { "prompt string", 4 },
64 { "attach header-field-name", 0 },
69 * Options at the "whatnow" prompt
71 static struct swit aleqs[] = {
73 { "edit [<editor> <switches>]", 0 },
75 { "refile [<switches>] +folder", 0 },
77 { "mime [<switches>]", 0 },
79 { "display [<switches>]", 0 },
81 { "list [<switches>]", 0 },
83 { "send [<switches>]", 0 },
85 { "push [<switches>]", 0 },
87 { "whom [<switches>]", 0 },
89 { "quit [-delete]", 0 },
93 { "cd [directory]", 0 },
98 #define ATTACHCMDSW 13
100 #define DETACHCMDSW 14
101 { "detach [-n]", 2 },
102 #define ALISTCMDSW 15
103 { "alist [-ln] ", 2 },
107 static char *myprompt = "\nWhat now? ";
112 static int editfile (char **, char **, char *, int, struct msgs *,
113 char *, char *, int);
114 static int sendfile (char **, char *, int);
115 static void sendit (char *, char **, char *, int);
116 static int buildfile (char **, char *);
117 static int check_draft (char *);
118 static int whomfile (char **, char *);
119 static int removefile (char *);
120 static void writelscmd(char *, int, char **);
121 static void writesomecmd(char *buf, int bufsz, char *cmd, char *trailcmd, char **argp);
122 static FILE* popen_in_dir(const char *dir, const char *cmd, const char *type);
123 static int system_in_dir(const char *dir, const char *cmd);
127 static int copyf (char *, char *);
132 WhatNow (int argc, char **argv)
134 int isdf = 0, nedit = 0, use = 0;
135 char *cp, *dfolder = NULL, *dmsg = NULL;
136 char *ed = NULL, *drft = NULL, *msgnam = NULL;
137 char buf[BUFSIZ], prompt[BUFSIZ];
138 char **argp, **arguments;
140 char *attach = (char *)0; /* attachment header field name */
141 char cwd[MAXPATHLEN + 1]; /* current working directory */
142 char file[MAXPATHLEN + 1]; /* file name buffer */
143 char shell[MAXPATHLEN + 1]; /* shell response buffer */
144 FILE *f; /* read pointer for bgnd proc */
145 char *l; /* set on -l to alist command */
146 int n; /* set on -n to alist command */
148 invo_name = r1bindex (argv[0], '/');
150 /* read user profile/context */
153 arguments = getarguments (invo_name, argc, argv, 1);
157 * Get the initial current working directory.
160 if (getcwd(cwd, sizeof (cwd)) == (char *)0) {
161 adios("getcwd", "could not get working directory");
164 while ((cp = *argp++)) {
166 switch (smatch (++cp, whatnowswitches)) {
168 ambigsw (cp, whatnowswitches);
171 adios (NULL, "-%s unknown", cp);
174 snprintf (buf, sizeof(buf), "%s [switches] [file]", invo_name);
175 print_help (buf, whatnowswitches, 1);
178 print_version(invo_name);
183 adios (NULL, "only one draft folder at a time!");
184 if (!(cp = *argp++) || *cp == '-')
185 adios (NULL, "missing argument to %s", argp[-2]);
186 dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp,
187 *cp != '@' ? TFOLDER : TSUBCWF);
191 adios (NULL, "only one draft message at a time!");
192 if (!(dmsg = *argp++) || *dmsg == '-')
193 adios (NULL, "missing argument to %s", argp[-2]);
201 if (!(ed = *argp++) || *ed == '-')
202 adios (NULL, "missing argument to %s", argp[-2]);
210 if (!(myprompt = *argp++) || *myprompt == '-')
211 adios (NULL, "missing argument to %s", argp[-2]);
215 if (attach != (char *)0)
216 adios(NULL, "only one attachment header field name at a time!");
217 if (!(attach = *argp++) || *attach == '-')
218 adios (NULL, "missing argument to %s", argp[-2]);
223 adios (NULL, "only one draft at a time!");
228 if ((drft == NULL && (drft = getenv ("mhdraft")) == NULL) || *drft == 0)
229 drft = getcpy (m_draft (dfolder, dmsg, 1, &isdf));
231 msgnam = (cp = getenv ("mhaltmsg")) && *cp ? getcpy (cp) : NULL;
233 if ((cp = getenv ("mhuse")) && *cp)
236 if (ed == NULL && ((ed = getenv ("mheditor")) == NULL || *ed == 0)) {
241 /* start editing the draft, unless -noedit was given */
242 if (!nedit && editfile (&ed, NULL, drft, use, NULL, msgnam, NULL, 1) < 0)
245 snprintf (prompt, sizeof(prompt), myprompt, invo_name);
247 if (!(argp = getans (prompt, aleqs))) {
251 switch (smatch (*argp, aleqs)) {
253 /* display the message being replied to, or distributed */
255 showfile (++argp, msgnam);
257 advise (NULL, "no alternate message to display");
261 /* Translate MIME composition file */
262 buildfile (++argp, drft);
266 /* Call an editor on the draft file */
269 if (editfile (&ed, argp, drft, NOUSE, NULL, msgnam, NULL, 1) == NOTOK)
274 /* display the draft file */
275 showfile (++argp, drft);
279 /* Check to whom the draft would be sent */
280 whomfile (++argp, drft);
284 /* Quit, and possibly delete the draft */
285 if (*++argp && (*argp[0] == 'd' ||
286 ((*argp)[0] == '-' && (*argp)[1] == 'd'))) {
289 if (stat (drft, &st) != NOTOK)
290 advise (NULL, "draft left on %s", drft);
295 /* Delete draft and exit */
300 /* Send draft in background */
301 if (sendfile (++argp, drft, 1))
307 sendfile (++argp, drft, 0);
311 /* Refile the draft */
312 if (refile (++argp, drft) == 0)
318 * Change the working directory for attachments
320 * Run the directory through the user's shell
321 * so that we can take advantage of any syntax
322 * that the user is accustomed to. Read back
326 if (*(argp+1) == (char *)0) {
327 (void)sprintf(buf, "$SHELL -c \"cd;pwd\"");
329 writesomecmd(buf, BUFSIZ, "cd", "pwd", argp);
331 if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
332 fgets(cwd, sizeof (cwd), f);
334 if (strchr(cwd, '\n') != (char *)0)
335 *strchr(cwd, '\n') = '\0';
339 advise("popen", "could not get directory");
345 /* Print the working directory for attachments */
351 * List files in the current attachment working
354 * Use the user's shell so that we can take
355 * advantage of any syntax that the user is
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) {
395 advise((char *)0, "usage is alist [-ln].");
398 annolist(drft, attach, l, n);
404 * Attach files to current draft.
407 if (attach == (char *)0) {
408 advise((char *)0, "can't attach because no header field name was given.");
412 if (*(argp+1) == (char *)0) {
413 advise((char *)0, "attach command requires file argument(s).");
418 * Build a command line that causes the user's
419 * shell to list the file name arguments.
420 * This handles and wildcard expansion, tilde
423 writelscmd(buf, sizeof(buf), argp);
426 * Read back the response from the shell,
427 * which contains a number of lines with one
428 * file name per line. Remove off the newline.
429 * Determine whether we have an absolute or
430 * relative path name. Prepend the current
431 * working directory to relative path names.
432 * Add the attachment annotation to the draft.
435 if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
436 while (fgets(shell, sizeof (shell), f) != (char *)0) {
437 *(strchr(shell, '\n')) = '\0';
440 (void)annotate(drft, attach, shell, 1, 0, -2, 1);
442 (void)sprintf(file, "%s/%s", cwd, shell);
443 (void)annotate(drft, attach, file, 1, 0, -2, 1);
449 advise("popen", "could not get file from shell");
456 * Detach files from current draft.
459 if (attach == (char *)0) {
460 advise((char *)0, "can't detach because no header field name was given.");
465 * Scan the arguments for a -n. Mixed file
466 * names and numbers aren't allowed, so this
467 * catches a -n anywhere in the argument list.
470 for (n = 0, arguments = argp + 1; *arguments != (char *)0; arguments++) {
471 if (strcmp(*arguments, "-n") == 0) {
478 * A -n was found so interpret the arguments as
479 * attachment numbers. Decrement any remaining
480 * argument number that is greater than the one
481 * just processed after processing each one so
482 * that the numbering stays correct.
486 for (arguments = argp + 1; *arguments != (char *)0; arguments++) {
487 if (strcmp(*arguments, "-n") == 0)
490 if (**arguments != '\0') {
491 n = atoi(*arguments);
492 (void)annotate(drft, attach, (char *)0, 1, 0, n, 1);
494 for (argp = arguments + 1; *argp != (char *)0; argp++) {
495 if (atoi(*argp) > n) {
496 if (atoi(*argp) == 1)
499 (void)sprintf(*argp, "%d", atoi(*argp) - 1);
507 * The arguments are interpreted as file names.
508 * Run them through the user's shell for wildcard
509 * expansion and other goodies. Do this from
510 * the current working directory if the argument
511 * is not an absolute path name (does not begin
514 * We feed all the file names to the shell at
515 * once, otherwise you can't provide a file name
516 * 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?");
543 * Build a command line of the form $SHELL -c "cd 'cwd'; cmd argp ... ;
547 writesomecmd(char *buf, int bufsz, char *cmd, char *trailcmd, char **argp)
550 /* Note that we do not quote -- the argp from the user
551 * is assumed to be quoted as they desire. (We can't treat
552 * it as pure literal as that would prevent them using ~,
553 * wildcards, etc.) The buffer produced by this function
554 * should be given to popen_in_dir() or system_in_dir() so
555 * that the current working directory is set correctly.
557 int ln = snprintf(buf, bufsz, "$SHELL -c \"%s", cmd);
558 /* NB that some snprintf() return -1 on overflow rather than the
559 * new C99 mandated 'number of chars that would have been written'
561 /* length checks here and inside the loop allow for the
562 * trailing ';', trailcmd, '"' and NUL
564 int trailln = strlen(trailcmd) + 3;
565 if (ln < 0 || ln + trailln > bufsz)
566 adios((char *)0, "arguments too long");
570 while (*++argp != (char *)0) {
572 /* +1 for leading space */
573 if (ln + trailln + 1 > bufsz - (cp-buf))
574 adios((char *)0, "arguments too long");
576 memcpy(cp, *argp, ln+1);
581 strcpy(cp, trailcmd);
589 * Build a command line that causes the user's shell to list the file name
590 * arguments. This handles and wildcard expansion, tilde expansion, etc.
593 writelscmd(char *buf, int bufsz, char **argp)
595 writesomecmd(buf, bufsz, "ls", "", argp);
598 /* Like system(), but run the command in directory dir.
599 * This assumes the program is single-threaded!
602 system_in_dir(const char *dir, const char *cmd)
606 if (getcwd(olddir, sizeof(olddir)) == 0)
607 adios("getcwd", "could not get working directory");
609 adios("chdir", "could not change working directory");
611 if (chdir(olddir) != 0)
612 adios("chdir", "could not change working directory");
616 /* ditto for popen() */
618 popen_in_dir(const char *dir, const char *cmd, const char *type)
622 if (getcwd(olddir, sizeof(olddir)) == 0)
623 adios("getcwd", "could not get working directory");
625 adios("chdir", "could not change working directory");
626 f = popen(cmd, type);
627 if (chdir(olddir) != 0)
628 adios("chdir", "could not change working directory");
637 static int reedit = 0; /* have we been here before? */
638 static char *edsave = NULL; /* the editor we used previously */
642 editfile (char **ed, char **arg, char *file, int use, struct msgs *mp,
643 char *altmsg, char *cwd, int save_editor)
645 int pid, status, vecp;
646 char altpath[BUFSIZ], linkpath[BUFSIZ];
647 char *cp, *vec[MAXARGS];
653 int oumask; /* PJS: for setting permissions on symlinks. */
655 #endif /* HAVE_LSTAT */
657 /* Was there a previous edit session? */
659 if (!*ed) { /* no explicit editor */
660 *ed = edsave; /* so use the previous one */
661 if ((cp = r1bindex (*ed, '/')) == NULL)
664 /* unless we've specified it via "editor-next" */
665 cp = concat (cp, "-next", NULL);
666 if ((cp = context_find (cp)) != NULL)
670 /* set initial editor */
671 if (*ed == NULL && (*ed = context_find ("editor")) == NULL)
676 if (mp == NULL || *altmsg == '/' || cwd == NULL)
677 strncpy (altpath, altmsg, sizeof(altpath));
679 snprintf (altpath, sizeof(altpath), "%s/%s", mp->foldpath, altmsg);
681 strncpy (linkpath, altmsglink, sizeof(linkpath));
683 snprintf (linkpath, sizeof(linkpath), "%s/%s", cwd, altmsglink);
689 if (link (altpath, linkpath) == NOTOK) {
691 /* I don't think permission on symlinks matters /JLR */
692 oumask = umask(0044); /* PJS: else symlinks are world 'r' */
694 symlink (altpath, linkpath);
696 umask(oumask); /* PJS: else symlinks are world 'r' */
702 #else /* not HAVE_LSTAT */
703 link (altpath, linkpath);
704 #endif /* not HAVE_LSTAT */
707 context_save (); /* save the context file */
710 switch (pid = vfork ()) {
712 advise ("fork", "unable to");
721 m_putenv ("mhfolder", mp->foldpath);
722 m_putenv ("editalt", altpath);
726 vec[vecp++] = r1bindex (*ed, '/');
729 vec[vecp++] = *arg++;
734 fprintf (stderr, "unable to exec ");
739 if ((status = pidwait (pid, NOTOK))) {
741 if ((cp = r1bindex (*ed, '/'))
742 && strcmp (cp, "vi") == 0
743 && (status & 0x00ff) == 0)
747 if (((status & 0xff00) != 0xff00)
748 && (!reedit || (status & 0x00ff))) {
749 if (!use && (status & 0xff00) &&
750 (rename (file, cp = m_backup (file)) != NOTOK)) {
751 advise (NULL, "problems with edit--draft left in %s", cp);
753 advise (NULL, "problems with edit--%s preserved", file);
756 status = -2; /* maybe "reedit ? -2 : -1"? */
769 ? lstat (linkpath, &st) != NOTOK
770 && S_ISREG(st.st_mode)
771 && copyf (linkpath, altpath) == NOTOK
772 : stat (linkpath, &st) != NOTOK
774 && (unlink (altpath) == NOTOK
775 || link (linkpath, altpath) == NOTOK)))
776 advise (linkpath, "unable to update %s from", altmsg);
777 #else /* HAVE_LSTAT */
781 && stat (linkpath, &st) != NOTOK
783 && (unlink (altpath) == NOTOK
784 || link (linkpath, altpath) == NOTOK))
785 advise (linkpath, "unable to update %s from", altmsg);
786 #endif /* HAVE_LSTAT */
789 /* normally, we remember which editor we used */
791 edsave = getcpy (*ed);
803 copyf (char *ifile, char *ofile)
808 if ((in = open (ifile, O_RDONLY)) == NOTOK)
810 if ((out = open (ofile, O_WRONLY | O_TRUNC)) == NOTOK) {
811 admonish (ofile, "unable to open and truncate");
816 while ((i = read (in, buffer, sizeof(buffer))) > OK)
817 if (write (out, buffer, i) != i) {
818 advise (ofile, "may have damaged");
827 #endif /* HAVE_LSTAT */
835 sendfile (char **arg, char *file, int pushsw)
839 char *cp, *sp, *vec[MAXARGS];
841 /* Translate MIME composition file, if necessary */
842 if ((cp = context_find ("automimeproc"))
843 && (!strcmp (cp, "1"))
844 && !getenv ("NOMHNPROC")
845 && check_draft (file)
846 && (buildfile (NULL, file) == NOTOK))
849 /* For backwards compatibility */
850 if ((cp = context_find ("automhnproc"))
851 && !getenv ("NOMHNPROC")
852 && check_draft (file)
853 && (i = editfile (&cp, NULL, file, NOUSE, NULL, NULL, NULL, 0)))
857 * If the sendproc is the nmh command `send', then we call
858 * those routines directly rather than exec'ing the command.
860 if (strcmp (sp = r1bindex (sendproc, '/'), "send") == 0) {
862 sendit (invo_name = sp, arg, file, pushsw);
867 context_save (); /* save the context file */
870 for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++)
874 advise (NULL, "unable to fork, so sending directly...");
877 vec[vecp++] = invo_name;
879 vec[vecp++] = "-push";
882 vec[vecp++] = *arg++;
886 execvp (sendproc, vec);
887 fprintf (stderr, "unable to exec ");
892 if (pidwait(child_id, OK) == 0)
900 * Translate MIME composition file (call buildmimeproc)
904 buildfile (char **argp, char *file)
911 /* allocate space for arguments */
917 args = (char **) mh_xmalloc((i + 2) * sizeof(char *));
920 * For backward compatibility, we need to add -build
921 * if we are using mhn as buildmimeproc
924 if (strcmp (r1bindex (ed, '/'), "mhn") == 0)
925 args[i++] = "-build";
927 /* copy any other arguments */
928 while (argp && *argp)
932 i = editfile (&ed, args, file, NOUSE, NULL, NULL, NULL, 0);
935 return (i ? NOTOK : OK);
940 * Check if draft is a mhbuild composition file
944 check_draft (char *msgnam)
947 char buf[BUFSIZ], name[NAMESZ];
950 if ((fp = fopen (msgnam, "r")) == NULL)
953 switch (state = m_getfld (state, name, buf, sizeof(buf), fp)) {
958 * If draft already contains any of the
959 * Content-XXX fields, then assume it already
962 if (uprf (name, XXX_FIELD_PRF)) {
966 while (state == FLDPLUS)
967 state = m_getfld (state, name, buf, sizeof(buf), fp);
974 for (bp = buf; *bp; bp++)
975 if (*bp != ' ' && *bp != '\t' && *bp != '\n') {
980 state = m_getfld (state, name, buf, sizeof(buf), fp);
981 } while (state == BODY);
991 static struct swit sendswitches[] = {
993 { "alias aliasfile", 0 },
997 { "filter filterfile", 0 },
1021 { "split seconds", 0 },
1035 { "width columns", 0 },
1036 #define SVERSIONSW 22
1040 #define BITSTUFFSW 24
1041 { "dashstuffing", -12 },
1042 #define NBITSTUFFSW 25
1043 { "nodashstuffing", -14 },
1053 { "client host", -6 },
1055 { "server host", 6 },
1059 { "draftfolder +folder", -6 },
1061 { "draftmessage msg", -6 },
1063 { "nodraftfolder", -3 },
1064 #define SNDATTACHSW 39
1065 { "attach file", 6 },
1066 #define SNDATTACHFORMAT 40
1067 { "attachformat", 7 },
1069 { "port server-port-name/number", 4 },
1074 extern int debugsw; /* from sendsbr.c */
1082 extern char *altmsg; /* .. */
1083 extern char *annotext;
1084 extern char *distfile;
1088 sendit (char *sp, char **arg, char *file, int pushed)
1091 char *cp, buf[BUFSIZ], **argp;
1092 char **arguments, *vec[MAXARGS];
1094 char *attach = (char *)0; /* attachment header field name */
1095 int attachformat = 0; /* 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 while ((cp = *argp++)) {
1153 switch (smatch (++cp, sendswitches)) {
1155 ambigsw (cp, sendswitches);
1158 advise (NULL, "-%s unknown\n", cp);
1162 snprintf (buf, sizeof(buf), "%s [switches]", sp);
1163 print_help (buf, sendswitches, 1);
1166 print_version (invo_name);
1177 if (!(cp = *argp++) || sscanf (cp, "%d", &splitsw) != 1) {
1178 advise (NULL, "missing argument to %s", argp[-2]);
1206 debugsw++; /* fall */
1233 if (!(cp = *argp++) || *cp == '-') {
1234 advise (NULL, "missing argument to %s", argp[-2]);
1242 if (!(cp = *argp++) || *cp == '-') {
1243 advise (NULL, "missing argument to %s", argp[-2]);
1250 if (!(attach = *argp++) || *attach == '-') {
1251 advise (NULL, "missing argument to %s", argp[-2]);
1256 case SNDATTACHFORMAT:
1257 if (! *argp || **argp == '-')
1258 adios (NULL, "missing argument to %s", argp[-1]);
1260 attachformat = atoi (*argp);
1261 if (attachformat < 0 ||
1262 attachformat > ATTACHFORMATS - 1) {
1263 advise (NULL, "unsupported attachformat %d",
1272 advise (NULL, "usage: %s [switches]", sp);
1276 /* allow Aliasfile: profile entry */
1277 if ((cp = context_find ("Aliasfile"))) {
1281 for (ap = brkstring (dp, " ", "\n"); ap && *ap; ap++) {
1282 vec[vecp++] = "-alias";
1287 if ((cp = getenv ("SIGNATURE")) == NULL || *cp == 0)
1288 if ((cp = context_find ("signature")) && *cp)
1289 m_putenv ("SIGNATURE", cp);
1292 snprintf (buf, sizeof(buf), "%s/.signature", mypath);
1293 if ((fp = fopen (buf, "r")) != NULL
1294 && fgets (buf, sizeof(buf), fp) != NULL) {
1296 if (cp = strchr (buf, '\n'))
1298 m_putenv ("SIGNATURE", buf);
1303 if ((annotext = getenv ("mhannotate")) == NULL || *annotext == 0)
1305 if ((altmsg = getenv ("mhaltmsg")) == NULL || *altmsg == 0)
1307 if (annotext && ((cp = getenv ("mhinplace")) != NULL && *cp != 0))
1308 inplace = atoi (cp);
1310 if ((cp = getenv ("mhdist"))
1313 && (distsw = atoi (cp))
1314 #endif /* not lint */
1316 vec[vecp++] = "-dist";
1317 distfile = getcpy (m_mktemp2(altmsg, invo_name, NULL, NULL));
1318 if (link (altmsg, distfile) == NOTOK)
1319 adios (distfile, "unable to link %s to", altmsg);
1324 if (altmsg == NULL || stat (altmsg, &st) == NOTOK) {
1329 if ((pushsw = pushed))
1332 vec[0] = r1bindex (postproc, '/');
1335 if (sendsbr (vec, vecp, file, &st, 1, attach, attachformat) == OK)
1344 whomfile (char **arg, char *file)
1350 context_save (); /* save the context file */
1353 switch (pid = vfork ()) {
1355 advise ("fork", "unable to");
1360 vec[vecp++] = r1bindex (whomproc, '/');
1364 vec[vecp++] = *arg++;
1367 execvp (whomproc, vec);
1368 fprintf (stderr, "unable to exec ");
1370 _exit (-1); /* NOTREACHED */
1373 return (pidwait (pid, NOTOK) & 0377 ? 1 : 0);
1379 * Remove the draft file
1383 removefile (char *drft)
1385 if (unlink (drft) == NOTOK)
1386 adios (drft, "unable to unlink");