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 if (!(argp = getans (prompt, aleqs))) {
256 switch (smatch (*argp, aleqs)) {
258 /* display the message being replied to, or distributed */
260 showfile (++argp, msgnam);
262 advise (NULL, "no alternate message to display");
266 /* Translate MIME composition file */
267 buildfile (++argp, drft);
271 /* Call an editor on the draft file */
274 if (editfile (&ed, argp, drft, NOUSE, NULL, msgnam, NULL, 1) == NOTOK)
279 /* display the draft file */
280 showfile (++argp, drft);
284 /* Check to whom the draft would be sent */
285 whomfile (++argp, drft);
289 /* Quit, and possibly delete the draft */
290 if (*++argp && (*argp[0] == 'd' ||
291 ((*argp)[0] == '-' && (*argp)[1] == 'd'))) {
294 if (stat (drft, &st) != NOTOK)
295 advise (NULL, "draft left on %s", drft);
300 /* Delete draft and exit */
305 /* Send draft in background */
306 if (sendfile (++argp, drft, 1))
312 sendfile (++argp, drft, 0);
316 /* Refile the draft */
317 if (refile (++argp, drft) == 0)
322 /* Change the working directory for attachments
324 * Run the directory through the user's shell so that
325 * we can take advantage of any syntax that the user
326 * is accustomed to. Read back the absolute path.
329 if (*(argp+1) == (char *)0) {
330 (void)sprintf(buf, "$SHELL -c \"cd;pwd\"");
333 writesomecmd(buf, BUFSIZ, "cd", "pwd", argp);
335 if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
336 fgets(cwd, sizeof (cwd), f);
338 if (strchr(cwd, '\n') != (char *)0)
339 *strchr(cwd, '\n') = '\0';
344 advise("popen", "could not get directory");
350 /* Print the working directory for attachments */
355 /* List files in the current attachment working directory
357 * Use the user's shell so that we can take advantage of any
358 * syntax that the user is accustomed to.
360 writelscmd(buf, sizeof(buf), argp);
361 (void)system_in_dir(cwd, buf);
366 * List attachments on current draft. Options are:
368 * -l long listing (full path names)
372 if (attach == (char *)0) {
373 advise((char *)0, "can't list because no header field name was given.");
380 while (*++argp != (char *)0) {
381 if (strcmp(*argp, "-l") == 0)
384 else if (strcmp(*argp, "-n") == 0)
387 else if (strcmp(*argp, "-ln") == 0 || strcmp(*argp, "-nl") == 0) {
399 advise((char *)0, "usage is alist [-ln].");
402 annolist(drft, attach, l, n);
408 * Attach files to current draft.
411 if (attach == (char *)0) {
412 advise((char *)0, "can't attach because no header field name was given.");
416 if (*(argp+1) == (char *)0) {
417 advise((char *)0, "attach command requires file argument(s).");
422 * Build a command line that causes the user's shell to list the file name
423 * arguments. This handles and wildcard expansion, tilde expansion, etc.
425 writelscmd(buf, sizeof(buf), argp);
428 * Read back the response from the shell, which contains a number of lines
429 * with one file name per line. Remove off the newline. Determine whether
430 * we have an absolute or relative path name. Prepend the current working
431 * directory to relative path names. Add the attachment annotation to the
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);
450 advise("popen", "could not get file from shell");
457 * Detach files from current draft.
460 if (attach == (char *)0) {
461 advise((char *)0, "can't detach because no header field name was given.");
466 * Scan the arguments for a -n. Mixed file names and numbers aren't allowed,
467 * so this 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 attachment numbers.
479 * Decrement any remaining argument number that is greater than the one
480 * just processed after processing each one so that the numbering stays
485 for (arguments = argp + 1; *arguments != (char *)0; arguments++) {
486 if (strcmp(*arguments, "-n") == 0)
489 if (**arguments != '\0') {
490 n = atoi(*arguments);
491 (void)annotate(drft, attach, (char *)0, 1, 0, n, 1);
493 for (argp = arguments + 1; *argp != (char *)0; argp++) {
494 if (atoi(*argp) > n) {
495 if (atoi(*argp) == 1)
498 (void)sprintf(*argp, "%d", atoi(*argp) - 1);
506 * The arguments are interpreted as file names. Run them through the
507 * user's shell for wildcard expansion and other goodies. Do this from
508 * the current working directory if the argument is not an absolute path
509 * name (does not begin with a /).
511 * We feed all the file names to the shell at once, otherwise you can't
512 * provide a file name with a space in it.
514 writelscmd(buf, sizeof(buf), argp);
515 if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
516 while (fgets(shell, sizeof (shell), f) != (char *)0) {
517 *(strchr(shell, '\n')) = '\0';
518 (void)annotate(drft, attach, shell, 1, 0, 0, 1);
522 advise("popen", "could not get file from shell");
528 /* Unknown command */
529 advise (NULL, "say what?");
538 /* Build a command line of the form $SHELL -c "cd 'cwd'; cmd argp ... ; trailcmd". */
540 writesomecmd(char *buf, int bufsz, char *cmd, char *trailcmd, char **argp)
543 /* Note that we do not quote -- the argp from the user
544 * is assumed to be quoted as they desire. (We can't treat
545 * it as pure literal as that would prevent them using ~,
546 * wildcards, etc.) The buffer produced by this function
547 * should be given to popen_in_dir() or system_in_dir() so
548 * that the current working directory is set correctly.
550 int ln = snprintf(buf, bufsz, "$SHELL -c \"%s", cmd);
551 /* NB that some snprintf() return -1 on overflow rather than the
552 * new C99 mandated 'number of chars that would have been written'
554 /* length checks here and inside the loop allow for the
555 * trailing ';', trailcmd, '"' and NUL
557 int trailln = strlen(trailcmd) + 3;
558 if (ln < 0 || ln + trailln > bufsz)
559 adios((char *)0, "arguments too long");
563 while (*++argp != (char *)0) {
565 /* +1 for leading space */
566 if (ln + trailln + 1 > bufsz - (cp-buf))
567 adios((char *)0, "arguments too long");
569 memcpy(cp, *argp, ln+1);
574 strcpy(cp, trailcmd);
582 * Build a command line that causes the user's shell to list the file name
583 * arguments. This handles and wildcard expansion, tilde expansion, etc.
586 writelscmd(char *buf, int bufsz, char **argp)
588 writesomecmd(buf, bufsz, "ls", "", argp);
591 /* Like system(), but run the command in directory dir.
592 * This assumes the program is single-threaded!
595 system_in_dir(const char *dir, const char *cmd)
599 if (getcwd(olddir, sizeof(olddir)) == 0)
600 adios("getcwd", "could not get working directory");
602 adios("chdir", "could not change working directory");
604 if (chdir(olddir) != 0)
605 adios("chdir", "could not change working directory");
609 /* ditto for popen() */
611 popen_in_dir(const char *dir, const char *cmd, const char *type)
615 if (getcwd(olddir, sizeof(olddir)) == 0)
616 adios("getcwd", "could not get working directory");
618 adios("chdir", "could not change working directory");
619 f = popen(cmd, type);
620 if (chdir(olddir) != 0)
621 adios("chdir", "could not change working directory");
630 static int reedit = 0; /* have we been here before? */
631 static char *edsave = NULL; /* the editor we used previously */
635 editfile (char **ed, char **arg, char *file, int use, struct msgs *mp,
636 char *altmsg, char *cwd, int save_editor)
638 int pid, status, vecp;
639 char altpath[BUFSIZ], linkpath[BUFSIZ];
640 char *cp, *vec[MAXARGS];
645 #endif /* HAVE_LSTAT */
647 /* Was there a previous edit session? */
649 if (!*ed) { /* no explicit editor */
650 *ed = edsave; /* so use the previous one */
651 if ((cp = r1bindex (*ed, '/')) == NULL)
654 /* unless we've specified it via "editor-next" */
655 cp = concat (cp, "-next", NULL);
656 if ((cp = context_find (cp)) != NULL)
660 /* set initial editor */
661 if (*ed == NULL && (*ed = context_find ("editor")) == NULL)
666 if (mp == NULL || *altmsg == '/' || cwd == NULL)
667 strncpy (altpath, altmsg, sizeof(altpath));
669 snprintf (altpath, sizeof(altpath), "%s/%s", mp->foldpath, altmsg);
671 strncpy (linkpath, LINK, sizeof(linkpath));
673 snprintf (linkpath, sizeof(linkpath), "%s/%s", cwd, LINK);
677 if (link (altpath, linkpath) == NOTOK) {
678 symlink (altpath, linkpath);
683 #else /* not HAVE_LSTAT */
684 link (altpath, linkpath);
685 #endif /* not HAVE_LSTAT */
688 context_save (); /* save the context file */
691 switch (pid = vfork()) {
693 advise ("fork", "unable to");
702 m_putenv ("mhfolder", mp->foldpath);
703 m_putenv ("editalt", altpath);
707 vec[vecp++] = r1bindex (*ed, '/');
710 vec[vecp++] = *arg++;
715 fprintf (stderr, "unable to exec ");
720 if ((status = pidwait (pid, NOTOK))) {
721 if (((status & 0xff00) != 0xff00)
722 && (!reedit || (status & 0x00ff))) {
723 if (!use && (status & 0xff00) &&
724 (rename (file, cp = m_backup (file)) != NOTOK)) {
725 advise (NULL, "problems with edit--draft left in %s", cp);
727 advise (NULL, "problems with edit--%s preserved", file);
730 status = -2; /* maybe "reedit ? -2 : -1"? */
740 ? lstat (linkpath, &st) != NOTOK
741 && S_ISREG(st.st_mode)
742 && copyf (linkpath, altpath) == NOTOK
743 : stat (linkpath, &st) != NOTOK
745 && (unlink (altpath) == NOTOK
746 || link (linkpath, altpath) == NOTOK)))
747 advise (linkpath, "unable to update %s from", altmsg);
748 #else /* HAVE_LSTAT */
752 && stat (linkpath, &st) != NOTOK
754 && (unlink (altpath) == NOTOK
755 || link (linkpath, altpath) == NOTOK))
756 advise (linkpath, "unable to update %s from", altmsg);
757 #endif /* HAVE_LSTAT */
760 /* normally, we remember which editor we used */
762 edsave = getcpy (*ed);
774 copyf (char *ifile, char *ofile)
779 if ((in = open (ifile, O_RDONLY)) == NOTOK)
781 if ((out = open (ofile, O_WRONLY | O_TRUNC)) == NOTOK) {
782 admonish (ofile, "unable to open and truncate");
787 while ((i = read (in, buffer, sizeof(buffer))) > OK)
788 if (write (out, buffer, i) != i) {
789 advise (ofile, "may have damaged");
798 #endif /* HAVE_LSTAT */
806 sendfile (char **arg, char *file, int pushsw)
810 char *cp, *sp, *vec[MAXARGS];
812 /* Translate MIME composition file, if necessary */
813 if ((cp = context_find ("automimeproc"))
814 && (!strcmp (cp, "1"))
815 && !getenv ("NOMHNPROC")
816 && check_draft (file)
817 && (buildfile (NULL, file) == NOTOK))
820 /* For backwards compatibility */
821 if ((cp = context_find ("automhnproc"))
822 && !getenv ("NOMHNPROC")
823 && check_draft (file)
824 && (i = editfile (&cp, NULL, file, NOUSE, NULL, NULL, NULL, 0)))
828 * If the sendproc is the nmh command `send', then we call
829 * those routines directly rather than exec'ing the command.
831 if (strcmp (sp = r1bindex (sendproc, '/'), "send") == 0) {
833 sendit (invo_name = sp, arg, file, pushsw);
838 context_save (); /* save the context file */
841 for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++)
845 advise (NULL, "unable to fork, so sending directly...");
848 vec[vecp++] = invo_name;
850 vec[vecp++] = "-push";
853 vec[vecp++] = *arg++;
857 execvp (sendproc, vec);
858 fprintf (stderr, "unable to exec ");
863 if (pidwait(child_id, OK) == 0)
871 * Translate MIME composition file (call buildmimeproc)
875 buildfile (char **argp, char *file)
882 /* allocate space for arguments */
888 args = (char **) mh_xmalloc((i + 2) * sizeof(char *));
891 * For backward compatibility, we need to add -build
892 * if we are using mhn as buildmimeproc
895 if (strcmp (r1bindex (ed, '/'), "mhn") == 0)
896 args[i++] = "-build";
898 /* copy any other arguments */
899 while (argp && *argp)
903 i = editfile (&ed, args, file, NOUSE, NULL, NULL, NULL, 0);
906 return (i ? NOTOK : OK);
911 * Check if draft is a mhbuild composition file
915 check_draft (char *msgnam)
918 char buf[BUFSIZ], name[NAMESZ];
921 if ((fp = fopen (msgnam, "r")) == NULL)
924 switch (state = m_getfld (state, name, buf, sizeof(buf), fp)) {
929 * If draft already contains any of the
930 * Content-XXX fields, then assume it already
933 if (uprf (name, XXX_FIELD_PRF)) {
937 while (state == FLDPLUS)
938 state = m_getfld (state, name, buf, sizeof(buf), fp);
945 for (bp = buf; *bp; bp++)
946 if (*bp != ' ' && *bp != '\t' && *bp != '\n') {
951 state = m_getfld (state, name, buf, sizeof(buf), fp);
952 } while (state == BODY);
963 # define SASLminc(a) (a)
964 #else /* CYRUS_SASL */
965 # define SASLminc(a) 0
966 #endif /* CYRUS_SASL */
969 # define TLSminc(a) (a)
970 #else /* TLS_SUPPORT */
971 # define TLSminc(a) 0
972 #endif /* TLS_SUPPORT */
974 static struct swit sendswitches[] = {
976 { "alias aliasfile", 0 },
980 { "filter filterfile", 0 },
1004 { "split seconds", 0 },
1018 { "width columns", 0 },
1019 #define SVERSIONSW 22
1023 #define BITSTUFFSW 24
1024 { "dashstuffing", -12 },
1025 #define NBITSTUFFSW 25
1026 { "nodashstuffing", -14 },
1036 { "client host", -6 },
1038 { "server host", 6 },
1042 { "draftfolder +folder", -6 },
1044 { "draftmessage msg", -6 },
1046 { "nodraftfolder", -3 },
1048 { "sasl", SASLminc(-4) },
1050 { "nosasl", SASLminc(-6) },
1051 #define SASLMXSSFSW 38
1052 { "saslmaxssf", SASLminc(-10) },
1053 #define SASLMECHSW 39
1054 { "saslmech", SASLminc(-5) },
1056 { "user", SASLminc(-4) },
1057 #define SNDATTACHSW 41
1058 { "attach file", 6 },
1059 #define SNDNOATTACHSW 42
1061 #define SNDATTACHFORMAT 43
1062 { "attachformat", 7 },
1064 { "port server-port-name/number", 4 },
1066 { "tls", TLSminc(-3) },
1068 { "notls", TLSminc(-5) },
1073 extern int debugsw; /* from sendsbr.c */
1081 extern char *altmsg; /* .. */
1082 extern char *annotext;
1083 extern char *distfile;
1087 sendit (char *sp, char **arg, char *file, int pushed)
1090 char *cp, buf[BUFSIZ], **argp;
1091 char **arguments, *vec[MAXARGS];
1093 char *attach = NMH_ATTACH_HEADER;/* attachment header field name */
1094 int attachformat = 1; /* 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 if ((cp = context_find ("fileproc"))) {
1148 vec[vecp++] = "-fileproc";
1152 if ((cp = context_find ("mhlproc"))) {
1153 vec[vecp++] = "-mhlproc";
1157 while ((cp = *argp++)) {
1159 switch (smatch (++cp, sendswitches)) {
1161 ambigsw (cp, sendswitches);
1164 advise (NULL, "-%s unknown\n", cp);
1168 snprintf (buf, sizeof(buf), "%s [switches]", sp);
1169 print_help (buf, sendswitches, 1);
1172 print_version (invo_name);
1183 if (!(cp = *argp++) || sscanf (cp, "%d", &splitsw) != 1) {
1184 advise (NULL, "missing argument to %s", argp[-2]);
1212 debugsw++; /* fall */
1246 if (!(cp = *argp++) || *cp == '-') {
1247 advise (NULL, "missing argument to %s", argp[-2]);
1255 if (!(cp = *argp++) || *cp == '-') {
1256 advise (NULL, "missing argument to %s", argp[-2]);
1263 if (!(attach = *argp++) || *attach == '-') {
1264 advise (NULL, "missing argument to %s", argp[-2]);
1272 case SNDATTACHFORMAT:
1273 if (! *argp || **argp == '-')
1274 adios (NULL, "missing argument to %s", argp[-1]);
1276 attachformat = atoi (*argp);
1277 if (attachformat < 0 ||
1278 attachformat > ATTACHFORMATS - 1) {
1279 advise (NULL, "unsupported attachformat %d",
1288 advise (NULL, "usage: %s [switches]", sp);
1292 /* allow Aliasfile: profile entry */
1293 if ((cp = context_find ("Aliasfile"))) {
1297 for (ap = brkstring (dp, " ", "\n"); ap && *ap; ap++) {
1298 vec[vecp++] = "-alias";
1303 if ((cp = getenv ("SIGNATURE")) == NULL || *cp == 0)
1304 if ((cp = context_find ("signature")) && *cp)
1305 m_putenv ("SIGNATURE", cp);
1307 if ((annotext = getenv ("mhannotate")) == NULL || *annotext == 0)
1309 if ((altmsg = getenv ("mhaltmsg")) == NULL || *altmsg == 0)
1311 if (annotext && ((cp = getenv ("mhinplace")) != NULL && *cp != 0))
1312 inplace = atoi (cp);
1314 if ((cp = getenv ("mhdist"))
1317 && (distsw = atoi (cp))
1318 #endif /* not lint */
1320 vec[vecp++] = "-dist";
1321 distfile = getcpy (m_mktemp2(altmsg, invo_name, NULL, NULL));
1323 if (link (altmsg, distfile) == NOTOK)
1324 adios (distfile, "unable to link %s to", altmsg);
1329 if (altmsg == NULL || stat (altmsg, &st) == NOTOK) {
1334 if ((pushsw = pushed))
1337 vec[0] = r1bindex (postproc, '/');
1340 if (sendsbr (vec, vecp, file, &st, 1, attach, attachformat) == OK)
1349 whomfile (char **arg, char *file)
1355 context_save (); /* save the context file */
1358 switch (pid = vfork()) {
1360 advise ("fork", "unable to");
1365 vec[vecp++] = r1bindex (whomproc, '/');
1369 vec[vecp++] = *arg++;
1372 execvp (whomproc, vec);
1373 fprintf (stderr, "unable to exec ");
1375 _exit (-1); /* NOTREACHED */
1378 return (pidwait (pid, NOTOK) & 0377 ? 1 : 0);
1384 * Remove the draft file
1388 removefile (char *drft)
1390 if (unlink (drft) == NOTOK)
1391 adios (drft, "unable to unlink");