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 },
70 * Options at the "whatnow" prompt
72 static struct swit aleqs[] = {
74 { "edit [<editor> <switches>]", 0 },
76 { "refile [<switches>] +folder", 0 },
78 { "mime [<switches>]", 0 },
80 { "display [<switches>]", 0 },
82 { "list [<switches>]", 0 },
84 { "send [<switches>]", 0 },
86 { "push [<switches>]", 0 },
88 { "whom [<switches>]", 0 },
90 { "quit [-delete]", 0 },
94 { "cd [directory]", 0 },
99 #define ATTACHCMDSW 13
101 #define DETACHCMDSW 14
102 { "detach [-n]", 2 },
103 #define ALISTCMDSW 15
104 { "alist [-ln] ", 2 },
108 static char *myprompt = "\nWhat now? ";
113 static int editfile (char **, char **, char *, int, struct msgs *,
114 char *, char *, int);
115 static int sendfile (char **, char *, int);
116 static void sendit (char *, char **, char *, int);
117 static int buildfile (char **, char *);
118 static int check_draft (char *);
119 static int whomfile (char **, char *);
120 static int removefile (char *);
121 static void writelscmd(char *, int, char **);
122 static void writesomecmd(char *buf, int bufsz, char *cmd, char *trailcmd, char **argp);
123 static FILE* popen_in_dir(const char *dir, const char *cmd, const char *type);
124 static int system_in_dir(const char *dir, const char *cmd);
128 static int copyf (char *, char *);
133 WhatNow (int argc, char **argv)
135 int isdf = 0, nedit = 0, use = 0;
136 char *cp, *dfolder = NULL, *dmsg = NULL;
137 char *ed = NULL, *drft = NULL, *msgnam = NULL;
138 char buf[BUFSIZ], prompt[BUFSIZ];
139 char **argp, **arguments;
141 char *attach = (char *)0; /* attachment header field name */
142 char cwd[MAXPATHLEN + 1]; /* current working directory */
143 char file[MAXPATHLEN + 1]; /* file name buffer */
144 char shell[MAXPATHLEN + 1]; /* shell response buffer */
145 FILE *f; /* read pointer for bgnd proc */
146 char *l; /* set on -l to alist command */
147 int n; /* set on -n to alist command */
149 invo_name = r1bindex (argv[0], '/');
151 /* read user profile/context */
154 arguments = getarguments (invo_name, argc, argv, 1);
158 * Get the initial current working directory.
161 if (getcwd(cwd, sizeof (cwd)) == (char *)0) {
162 adios("getcwd", "could not get working directory");
165 while ((cp = *argp++)) {
167 switch (smatch (++cp, whatnowswitches)) {
169 ambigsw (cp, whatnowswitches);
172 adios (NULL, "-%s unknown", cp);
175 snprintf (buf, sizeof(buf), "%s [switches] [file]", invo_name);
176 print_help (buf, whatnowswitches, 1);
179 print_version(invo_name);
184 adios (NULL, "only one draft folder at a time!");
185 if (!(cp = *argp++) || *cp == '-')
186 adios (NULL, "missing argument to %s", argp[-2]);
187 dfolder = path (*cp == '+' || *cp == '@' ? cp + 1 : cp,
188 *cp != '@' ? TFOLDER : TSUBCWF);
192 adios (NULL, "only one draft message at a time!");
193 if (!(dmsg = *argp++) || *dmsg == '-')
194 adios (NULL, "missing argument to %s", argp[-2]);
202 if (!(ed = *argp++) || *ed == '-')
203 adios (NULL, "missing argument to %s", argp[-2]);
211 if (!(myprompt = *argp++) || *myprompt == '-')
212 adios (NULL, "missing argument to %s", argp[-2]);
216 if (attach != (char *)0)
217 adios(NULL, "only one attachment header field name at a time!");
218 if (!(attach = *argp++) || *attach == '-')
219 adios (NULL, "missing argument to %s", argp[-2]);
224 adios (NULL, "only one draft at a time!");
229 if ((drft == NULL && (drft = getenv ("mhdraft")) == NULL) || *drft == 0)
230 drft = getcpy (m_draft (dfolder, dmsg, 1, &isdf));
232 msgnam = (cp = getenv ("mhaltmsg")) && *cp ? getcpy (cp) : NULL;
234 if ((cp = getenv ("mhuse")) && *cp)
237 if (ed == NULL && ((ed = getenv ("mheditor")) == NULL || *ed == 0)) {
242 /* start editing the draft, unless -noedit was given */
243 if (!nedit && editfile (&ed, NULL, drft, use, NULL, msgnam, NULL, 1) < 0)
246 snprintf (prompt, sizeof(prompt), myprompt, invo_name);
248 if (!(argp = getans (prompt, aleqs))) {
252 switch (smatch (*argp, aleqs)) {
254 /* display the message being replied to, or distributed */
256 showfile (++argp, msgnam);
258 advise (NULL, "no alternate message to display");
262 /* Translate MIME composition file */
263 buildfile (++argp, drft);
267 /* Call an editor on the draft file */
270 if (editfile (&ed, argp, drft, NOUSE, NULL, msgnam, NULL, 1) == NOTOK)
275 /* display the draft file */
276 showfile (++argp, drft);
280 /* Check to whom the draft would be sent */
281 whomfile (++argp, drft);
285 /* Quit, and possibly delete the draft */
286 if (*++argp && (*argp[0] == 'd' ||
287 ((*argp)[0] == '-' && (*argp)[1] == 'd'))) {
290 if (stat (drft, &st) != NOTOK)
291 advise (NULL, "draft left on %s", drft);
296 /* Delete draft and exit */
301 /* Send draft in background */
302 if (sendfile (++argp, drft, 1))
308 sendfile (++argp, drft, 0);
312 /* Refile the draft */
313 if (refile (++argp, drft) == 0)
318 /* Change the working directory for attachments
320 * Run the directory through the user's shell so that
321 * we can take advantage of any syntax that the user
322 * is accustomed to. Read back the absolute path.
325 if (*(argp+1) == (char *)0) {
326 (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';
340 advise("popen", "could not get directory");
346 /* Print the working directory for attachments */
351 /* List files in the current attachment working directory
353 * Use the user's shell so that we can take advantage of any
354 * syntax that the user is accustomed to.
356 writelscmd(buf, sizeof(buf), argp);
357 (void)system_in_dir(cwd, buf);
362 * List attachments on current draft. Options are:
364 * -l long listing (full path names)
368 if (attach == (char *)0) {
369 advise((char *)0, "can't list because no header field name was given.");
376 while (*++argp != (char *)0) {
377 if (strcmp(*argp, "-l") == 0)
380 else if (strcmp(*argp, "-n") == 0)
383 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 shell to list the file name
419 * arguments. This handles and wildcard expansion, tilde expansion, etc.
421 writelscmd(buf, sizeof(buf), argp);
424 * Read back the response from the shell, which contains a number of lines
425 * with one file name per line. Remove off the newline. Determine whether
426 * we have an absolute or relative path name. Prepend the current working
427 * directory to relative path names. Add the attachment annotation to the
431 if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
432 while (fgets(shell, sizeof (shell), f) != (char *)0) {
433 *(strchr(shell, '\n')) = '\0';
436 (void)annotate(drft, attach, shell, 1, 0, -2, 1);
438 (void)sprintf(file, "%s/%s", cwd, shell);
439 (void)annotate(drft, attach, file, 1, 0, -2, 1);
446 advise("popen", "could not get file from shell");
453 * Detach files from current draft.
456 if (attach == (char *)0) {
457 advise((char *)0, "can't detach because no header field name was given.");
462 * Scan the arguments for a -n. Mixed file names and numbers aren't allowed,
463 * so this catches a -n anywhere in the argument list.
466 for (n = 0, arguments = argp + 1; *arguments != (char *)0; arguments++) {
467 if (strcmp(*arguments, "-n") == 0) {
474 * A -n was found so interpret the arguments as attachment numbers.
475 * Decrement any remaining argument number that is greater than the one
476 * just processed after processing each one so that the numbering stays
481 for (arguments = argp + 1; *arguments != (char *)0; arguments++) {
482 if (strcmp(*arguments, "-n") == 0)
485 if (**arguments != '\0') {
486 n = atoi(*arguments);
487 (void)annotate(drft, attach, (char *)0, 1, 0, n, 1);
489 for (argp = arguments + 1; *argp != (char *)0; argp++) {
490 if (atoi(*argp) > n) {
491 if (atoi(*argp) == 1)
494 (void)sprintf(*argp, "%d", atoi(*argp) - 1);
502 * The arguments are interpreted as file names. Run them through the
503 * user's shell for wildcard expansion and other goodies. Do this from
504 * the current working directory if the argument is not an absolute path
505 * name (does not begin with a /).
507 * We feed all the file names to the shell at once, otherwise you can't
508 * provide a file name with a space in it.
510 writelscmd(buf, sizeof(buf), argp);
511 if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
512 while (fgets(shell, sizeof (shell), f) != (char *)0) {
513 *(strchr(shell, '\n')) = '\0';
514 (void)annotate(drft, attach, shell, 1, 0, 0, 1);
518 advise("popen", "could not get file from shell");
524 /* Unknown command */
525 advise (NULL, "say what?");
534 /* Build a command line of the form $SHELL -c "cd 'cwd'; cmd argp ... ; trailcmd". */
536 writesomecmd(char *buf, int bufsz, char *cmd, char *trailcmd, char **argp)
539 /* Note that we do not quote -- the argp from the user
540 * is assumed to be quoted as they desire. (We can't treat
541 * it as pure literal as that would prevent them using ~,
542 * wildcards, etc.) The buffer produced by this function
543 * should be given to popen_in_dir() or system_in_dir() so
544 * that the current working directory is set correctly.
546 int ln = snprintf(buf, bufsz, "$SHELL -c \"%s", cmd);
547 /* NB that some snprintf() return -1 on overflow rather than the
548 * new C99 mandated 'number of chars that would have been written'
550 /* length checks here and inside the loop allow for the
551 * trailing ';', trailcmd, '"' and NUL
553 int trailln = strlen(trailcmd) + 3;
554 if (ln < 0 || ln + trailln > bufsz)
555 adios((char *)0, "arguments too long");
559 while (*++argp != (char *)0) {
561 /* +1 for leading space */
562 if (ln + trailln + 1 > bufsz - (cp-buf))
563 adios((char *)0, "arguments too long");
565 memcpy(cp, *argp, ln+1);
570 strcpy(cp, trailcmd);
578 * Build a command line that causes the user's shell to list the file name
579 * arguments. This handles and wildcard expansion, tilde expansion, etc.
582 writelscmd(char *buf, int bufsz, char **argp)
584 writesomecmd(buf, bufsz, "ls", "", argp);
587 /* Like system(), but run the command in directory dir.
588 * This assumes the program is single-threaded!
591 system_in_dir(const char *dir, const char *cmd)
595 if (getcwd(olddir, sizeof(olddir)) == 0)
596 adios("getcwd", "could not get working directory");
598 adios("chdir", "could not change working directory");
600 if (chdir(olddir) != 0)
601 adios("chdir", "could not change working directory");
605 /* ditto for popen() */
607 popen_in_dir(const char *dir, const char *cmd, const char *type)
611 if (getcwd(olddir, sizeof(olddir)) == 0)
612 adios("getcwd", "could not get working directory");
614 adios("chdir", "could not change working directory");
615 f = popen(cmd, type);
616 if (chdir(olddir) != 0)
617 adios("chdir", "could not change working directory");
626 static int reedit = 0; /* have we been here before? */
627 static char *edsave = NULL; /* the editor we used previously */
631 editfile (char **ed, char **arg, char *file, int use, struct msgs *mp,
632 char *altmsg, char *cwd, int save_editor)
634 int pid, status, vecp;
635 char altpath[BUFSIZ], linkpath[BUFSIZ];
636 char *cp, *vec[MAXARGS];
642 int oumask; /* PJS: for setting permissions on symlinks. */
644 #endif /* HAVE_LSTAT */
646 /* Was there a previous edit session? */
648 if (!*ed) { /* no explicit editor */
649 *ed = edsave; /* so use the previous one */
650 if ((cp = r1bindex (*ed, '/')) == NULL)
653 /* unless we've specified it via "editor-next" */
654 cp = concat (cp, "-next", NULL);
655 if ((cp = context_find (cp)) != NULL)
659 /* set initial editor */
660 if (*ed == NULL && (*ed = context_find ("editor")) == NULL)
665 if (mp == NULL || *altmsg == '/' || cwd == NULL)
666 strncpy (altpath, altmsg, sizeof(altpath));
668 snprintf (altpath, sizeof(altpath), "%s/%s", mp->foldpath, altmsg);
670 strncpy (linkpath, LINK, sizeof(linkpath));
672 snprintf (linkpath, sizeof(linkpath), "%s/%s", cwd, LINK);
678 if (link (altpath, linkpath) == NOTOK) {
680 /* I don't think permission on symlinks matters /JLR */
681 oumask = umask(0044); /* PJS: else symlinks are world 'r' */
683 symlink (altpath, linkpath);
685 umask(oumask); /* PJS: else symlinks are world 'r' */
691 #else /* not HAVE_LSTAT */
692 link (altpath, linkpath);
693 #endif /* not HAVE_LSTAT */
696 context_save (); /* save the context file */
699 switch (pid = vfork()) {
701 advise ("fork", "unable to");
710 m_putenv ("mhfolder", mp->foldpath);
711 m_putenv ("editalt", altpath);
715 vec[vecp++] = r1bindex (*ed, '/');
718 vec[vecp++] = *arg++;
723 fprintf (stderr, "unable to exec ");
728 if ((status = pidwait (pid, NOTOK))) {
729 if (((status & 0xff00) != 0xff00)
730 && (!reedit || (status & 0x00ff))) {
731 if (!use && (status & 0xff00) &&
732 (rename (file, cp = m_backup (file)) != NOTOK)) {
733 advise (NULL, "problems with edit--draft left in %s", cp);
735 advise (NULL, "problems with edit--%s preserved", file);
738 status = -2; /* maybe "reedit ? -2 : -1"? */
748 ? lstat (linkpath, &st) != NOTOK
749 && S_ISREG(st.st_mode)
750 && copyf (linkpath, altpath) == NOTOK
751 : stat (linkpath, &st) != NOTOK
753 && (unlink (altpath) == NOTOK
754 || link (linkpath, altpath) == NOTOK)))
755 advise (linkpath, "unable to update %s from", altmsg);
756 #else /* HAVE_LSTAT */
760 && stat (linkpath, &st) != NOTOK
762 && (unlink (altpath) == NOTOK
763 || link (linkpath, altpath) == NOTOK))
764 advise (linkpath, "unable to update %s from", altmsg);
765 #endif /* HAVE_LSTAT */
768 /* normally, we remember which editor we used */
770 edsave = getcpy (*ed);
782 copyf (char *ifile, char *ofile)
787 if ((in = open (ifile, O_RDONLY)) == NOTOK)
789 if ((out = open (ofile, O_WRONLY | O_TRUNC)) == NOTOK) {
790 admonish (ofile, "unable to open and truncate");
795 while ((i = read (in, buffer, sizeof(buffer))) > OK)
796 if (write (out, buffer, i) != i) {
797 advise (ofile, "may have damaged");
806 #endif /* HAVE_LSTAT */
814 sendfile (char **arg, char *file, int pushsw)
818 char *cp, *sp, *vec[MAXARGS];
820 /* Translate MIME composition file, if necessary */
821 if ((cp = context_find ("automimeproc"))
822 && (!strcmp (cp, "1"))
823 && !getenv ("NOMHNPROC")
824 && check_draft (file)
825 && (buildfile (NULL, file) == NOTOK))
828 /* For backwards compatibility */
829 if ((cp = context_find ("automhnproc"))
830 && !getenv ("NOMHNPROC")
831 && check_draft (file)
832 && (i = editfile (&cp, NULL, file, NOUSE, NULL, NULL, NULL, 0)))
836 * If the sendproc is the nmh command `send', then we call
837 * those routines directly rather than exec'ing the command.
839 if (strcmp (sp = r1bindex (sendproc, '/'), "send") == 0) {
841 sendit (invo_name = sp, arg, file, pushsw);
846 context_save (); /* save the context file */
849 for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++)
853 advise (NULL, "unable to fork, so sending directly...");
856 vec[vecp++] = invo_name;
858 vec[vecp++] = "-push";
861 vec[vecp++] = *arg++;
865 execvp (sendproc, vec);
866 fprintf (stderr, "unable to exec ");
871 if (pidwait(child_id, OK) == 0)
879 * Translate MIME composition file (call buildmimeproc)
883 buildfile (char **argp, char *file)
890 /* allocate space for arguments */
896 args = (char **) mh_xmalloc((i + 2) * sizeof(char *));
899 * For backward compatibility, we need to add -build
900 * if we are using mhn as buildmimeproc
903 if (strcmp (r1bindex (ed, '/'), "mhn") == 0)
904 args[i++] = "-build";
906 /* copy any other arguments */
907 while (argp && *argp)
911 i = editfile (&ed, args, file, NOUSE, NULL, NULL, NULL, 0);
914 return (i ? NOTOK : OK);
919 * Check if draft is a mhbuild composition file
923 check_draft (char *msgnam)
926 char buf[BUFSIZ], name[NAMESZ];
929 if ((fp = fopen (msgnam, "r")) == NULL)
932 switch (state = m_getfld (state, name, buf, sizeof(buf), fp)) {
937 * If draft already contains any of the
938 * Content-XXX fields, then assume it already
941 if (uprf (name, XXX_FIELD_PRF)) {
945 while (state == FLDPLUS)
946 state = m_getfld (state, name, buf, sizeof(buf), fp);
953 for (bp = buf; *bp; bp++)
954 if (*bp != ' ' && *bp != '\t' && *bp != '\n') {
959 state = m_getfld (state, name, buf, sizeof(buf), fp);
960 } while (state == BODY);
971 # define SASLminc(a) (a)
972 #else /* CYRUS_SASL */
973 # define SASLminc(a) 0
974 #endif /* CYRUS_SASL */
977 # define TLSminc(a) (a)
978 #else /* TLS_SUPPORT */
979 # define TLSminc(a) 0
980 #endif /* TLS_SUPPORT */
982 static struct swit sendswitches[] = {
984 { "alias aliasfile", 0 },
988 { "filter filterfile", 0 },
1012 { "split seconds", 0 },
1026 { "width columns", 0 },
1027 #define SVERSIONSW 22
1031 #define BITSTUFFSW 24
1032 { "dashstuffing", -12 },
1033 #define NBITSTUFFSW 25
1034 { "nodashstuffing", -14 },
1044 { "client host", -6 },
1046 { "server host", 6 },
1050 { "draftfolder +folder", -6 },
1052 { "draftmessage msg", -6 },
1054 { "nodraftfolder", -3 },
1056 { "sasl", SASLminc(-4) },
1057 #define SASLMECHSW 37
1058 { "saslmech", SASLminc(-5) },
1060 { "user", SASLminc(-4) },
1061 #define SNDATTACHSW 39
1062 { "attach file", 6 },
1063 #define SNDATTACHFORMAT 40
1064 { "attachformat", 7 },
1066 { "port server-port-name/number", 4 },
1068 { "tls", TLSminc(-3) },
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 = (char *)0; /* attachment header field name */
1094 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 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 */
1243 if (!(cp = *argp++) || *cp == '-') {
1244 advise (NULL, "missing argument to %s", argp[-2]);
1252 if (!(cp = *argp++) || *cp == '-') {
1253 advise (NULL, "missing argument to %s", argp[-2]);
1260 if (!(attach = *argp++) || *attach == '-') {
1261 advise (NULL, "missing argument to %s", argp[-2]);
1266 case SNDATTACHFORMAT:
1267 if (! *argp || **argp == '-')
1268 adios (NULL, "missing argument to %s", argp[-1]);
1270 attachformat = atoi (*argp);
1271 if (attachformat < 0 ||
1272 attachformat > ATTACHFORMATS - 1) {
1273 advise (NULL, "unsupported attachformat %d",
1282 advise (NULL, "usage: %s [switches]", sp);
1286 /* allow Aliasfile: profile entry */
1287 if ((cp = context_find ("Aliasfile"))) {
1291 for (ap = brkstring (dp, " ", "\n"); ap && *ap; ap++) {
1292 vec[vecp++] = "-alias";
1297 if ((cp = getenv ("SIGNATURE")) == NULL || *cp == 0)
1298 if ((cp = context_find ("signature")) && *cp)
1299 m_putenv ("SIGNATURE", cp);
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_mktemp2(altmsg, invo_name, NULL, NULL));
1317 if (link (altmsg, distfile) == NOTOK)
1318 adios (distfile, "unable to link %s to", altmsg);
1323 if (altmsg == NULL || stat (altmsg, &st) == NOTOK) {
1328 if ((pushsw = pushed))
1331 vec[0] = r1bindex (postproc, '/');
1334 if (sendsbr (vec, vecp, file, &st, 1, attach, attachformat) == OK)
1343 whomfile (char **arg, char *file)
1349 context_save (); /* save the context file */
1352 switch (pid = vfork()) {
1354 advise ("fork", "unable to");
1359 vec[vecp++] = r1bindex (whomproc, '/');
1363 vec[vecp++] = *arg++;
1366 execvp (whomproc, vec);
1367 fprintf (stderr, "unable to exec ");
1369 _exit (-1); /* NOTREACHED */
1372 return (pidwait (pid, NOTOK) & 0377 ? 1 : 0);
1378 * Remove the draft file
1382 removefile (char *drft)
1384 if (unlink (drft) == NOTOK)
1385 adios (drft, "unable to unlink");