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)
609 /* ensure that $SHELL exists, as the cmd was written relying on
610 a non-blank $SHELL... */
611 setenv("SHELL","/bin/sh",0); /* don't overwrite */
613 if (getcwd(olddir, sizeof(olddir)) == 0)
614 adios("getcwd", "could not get working directory");
616 adios("chdir", "could not change working directory");
618 if (chdir(olddir) != 0)
619 adios("chdir", "could not change working directory");
623 /* ditto for popen() */
625 popen_in_dir(const char *dir, const char *cmd, const char *type)
630 /* ensure that $SHELL exists, as the cmd was written relying on
631 a non-blank $SHELL... */
632 setenv("SHELL","/bin/sh",0); /* don't overwrite */
634 if (getcwd(olddir, sizeof(olddir)) == 0)
635 adios("getcwd", "could not get working directory");
637 adios("chdir", "could not change working directory");
638 f = popen(cmd, type);
639 if (chdir(olddir) != 0)
640 adios("chdir", "could not change working directory");
649 static int reedit = 0; /* have we been here before? */
650 static char *edsave = NULL; /* the editor we used previously */
654 editfile (char **ed, char **arg, char *file, int use, struct msgs *mp,
655 char *altmsg, char *cwd, int save_editor, int atfile)
657 int pid, status, vecp;
658 char altpath[BUFSIZ], linkpath[BUFSIZ];
659 char *cp, *vec[MAXARGS];
664 #endif /* HAVE_LSTAT */
666 /* Was there a previous edit session? */
668 if (!*ed) { /* no explicit editor */
669 *ed = edsave; /* so use the previous one */
670 if ((cp = r1bindex (*ed, '/')) == NULL)
673 /* unless we've specified it via "editor-next" */
674 cp = concat (cp, "-next", NULL);
675 if ((cp = context_find (cp)) != NULL)
679 /* set initial editor */
680 if (*ed == NULL && (*ed = context_find ("editor")) == NULL)
684 if (altmsg && atfile) {
685 if (mp == NULL || *altmsg == '/' || cwd == NULL)
686 strncpy (altpath, altmsg, sizeof(altpath));
688 snprintf (altpath, sizeof(altpath), "%s/%s", mp->foldpath, altmsg);
690 strncpy (linkpath, LINK, sizeof(linkpath));
692 snprintf (linkpath, sizeof(linkpath), "%s/%s", cwd, LINK);
696 if (link (altpath, linkpath) == NOTOK) {
697 symlink (altpath, linkpath);
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))) {
740 if (((status & 0xff00) != 0xff00)
741 && (!reedit || (status & 0x00ff))) {
742 if (!use && (status & 0xff00) &&
743 (rename (file, cp = m_backup (file)) != NOTOK)) {
744 advise (NULL, "problems with edit--draft left in %s", cp);
746 advise (NULL, "problems with edit--%s preserved", file);
749 status = -2; /* maybe "reedit ? -2 : -1"? */
759 ? lstat (linkpath, &st) != NOTOK
760 && S_ISREG(st.st_mode)
761 && copyf (linkpath, altpath) == NOTOK
762 : stat (linkpath, &st) != NOTOK
764 && (unlink (altpath) == NOTOK
765 || link (linkpath, altpath) == NOTOK)))
766 advise (linkpath, "unable to update %s from", altmsg);
767 #else /* HAVE_LSTAT */
771 && stat (linkpath, &st) != NOTOK
773 && (unlink (altpath) == NOTOK
774 || link (linkpath, altpath) == NOTOK))
775 advise (linkpath, "unable to update %s from", altmsg);
776 #endif /* HAVE_LSTAT */
779 /* normally, we remember which editor we used */
781 edsave = getcpy (*ed);
784 if (altmsg && atfile)
793 copyf (char *ifile, char *ofile)
798 if ((in = open (ifile, O_RDONLY)) == NOTOK)
800 if ((out = open (ofile, O_WRONLY | O_TRUNC)) == NOTOK) {
801 admonish (ofile, "unable to open and truncate");
806 while ((i = read (in, buffer, sizeof(buffer))) > OK)
807 if (write (out, buffer, i) != i) {
808 advise (ofile, "may have damaged");
817 #endif /* HAVE_LSTAT */
825 sendfile (char **arg, char *file, int pushsw)
829 char *cp, *sp, *vec[MAXARGS];
831 /* Translate MIME composition file, if necessary */
832 if ((cp = context_find ("automimeproc"))
833 && (!strcmp (cp, "1"))
834 && check_draft (file)
835 && (buildfile (NULL, file) == NOTOK))
838 /* For backwards compatibility */
839 if ((cp = context_find ("automhnproc"))
840 && check_draft (file)
841 && (i = editfile (&cp, NULL, file, NOUSE, NULL, NULL, NULL, 0, 0)))
845 * If the sendproc is the nmh command `send', then we call
846 * those routines directly rather than exec'ing the command.
848 if (strcmp (sp = r1bindex (sendproc, '/'), "send") == 0) {
850 sendit (invo_name = sp, arg, file, pushsw);
855 context_save (); /* save the context file */
858 for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++)
862 advise (NULL, "unable to fork, so sending directly...");
865 vec[vecp++] = invo_name;
867 vec[vecp++] = "-push";
870 vec[vecp++] = *arg++;
874 execvp (sendproc, vec);
875 fprintf (stderr, "unable to exec ");
880 if (pidwait(child_id, OK) == 0)
888 * Translate MIME composition file (call buildmimeproc)
892 buildfile (char **argp, char *file)
899 /* allocate space for arguments */
905 args = (char **) mh_xmalloc((i + 2) * sizeof(char *));
908 * For backward compatibility, we need to add -build
909 * if we are using mhn as buildmimeproc
912 if (strcmp (r1bindex (ed, '/'), "mhn") == 0)
913 args[i++] = "-build";
915 /* copy any other arguments */
916 while (argp && *argp)
920 i = editfile (&ed, args, file, NOUSE, NULL, NULL, NULL, 0, 0);
923 return (i ? NOTOK : OK);
928 * Check if draft is a mhbuild composition file
932 check_draft (char *msgnam)
935 char buf[BUFSIZ], name[NAMESZ];
938 if ((fp = fopen (msgnam, "r")) == NULL)
941 switch (state = m_getfld (state, name, buf, sizeof(buf), fp)) {
946 * If draft already contains any of the
947 * Content-XXX fields, then assume it already
950 if (uprf (name, XXX_FIELD_PRF)) {
954 while (state == FLDPLUS)
955 state = m_getfld (state, name, buf, sizeof(buf), fp);
962 for (bp = buf; *bp; bp++)
963 if (*bp != ' ' && *bp != '\t' && *bp != '\n') {
968 state = m_getfld (state, name, buf, sizeof(buf), fp);
969 } while (state == BODY);
980 # define SASLminc(a) (a)
981 #else /* CYRUS_SASL */
982 # define SASLminc(a) 0
983 #endif /* CYRUS_SASL */
986 # define TLSminc(a) (a)
987 #else /* TLS_SUPPORT */
988 # define TLSminc(a) 0
989 #endif /* TLS_SUPPORT */
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 },
1065 { "sasl", SASLminc(-4) },
1067 { "nosasl", SASLminc(-6) },
1068 #define SASLMXSSFSW 38
1069 { "saslmaxssf", SASLminc(-10) },
1070 #define SASLMECHSW 39
1071 { "saslmech", SASLminc(-5) },
1073 { "user", SASLminc(-4) },
1074 #define SNDATTACHSW 41
1075 { "attach file", 6 },
1076 #define SNDNOATTACHSW 42
1078 #define SNDATTACHFORMAT 43
1079 { "attachformat", 7 },
1081 { "port server-port-name/number", 4 },
1083 { "tls", TLSminc(-3) },
1085 { "notls", TLSminc(-5) },
1087 { "mts smtp|sendmail/smtp|sendmail/pipe", 2 },
1088 #define MESSAGEIDSW 48
1089 { "messageid localname|random", 2 },
1094 extern int debugsw; /* from sendsbr.c */
1102 extern char *altmsg; /* .. */
1103 extern char *annotext;
1104 extern char *distfile;
1108 sendit (char *sp, char **arg, char *file, int pushed)
1111 char *cp, buf[BUFSIZ], **argp;
1112 char **arguments, *vec[MAXARGS];
1114 char *attach = NMH_ATTACH_HEADER;/* attachment header field name */
1115 int attachformat = 1; /* mhbuild format specifier for
1123 * Make sure these are defined. In particular, we need
1124 * vec[1] to be NULL, in case "arg" is NULL below. It
1125 * doesn't matter what is the value of vec[0], but we
1126 * set it to NULL, to help catch "off-by-one" errors.
1132 * Temporarily copy arg to vec, since the brkstring() call in
1133 * getarguments() will wipe it out before it is merged in.
1134 * Also, we skip the first element of vec, since getarguments()
1135 * skips it. Then we count the number of arguments
1136 * copied. The value of "n" will be one greater than
1137 * this in order to simulate the standard argc/argv.
1142 copyip (arg, vec+1, MAXARGS-1);
1149 * Merge any arguments from command line (now in vec)
1150 * and arguments from profile.
1152 arguments = getarguments (sp, n, vec, 1);
1164 vecp = 1; /* we'll get the zero'th element later */
1165 vec[vecp++] = "-library";
1166 vec[vecp++] = getcpy (m_maildir (""));
1168 if ((cp = context_find ("fileproc"))) {
1169 vec[vecp++] = "-fileproc";
1173 if ((cp = context_find ("mhlproc"))) {
1174 vec[vecp++] = "-mhlproc";
1178 while ((cp = *argp++)) {
1180 switch (smatch (++cp, sendswitches)) {
1182 ambigsw (cp, sendswitches);
1185 advise (NULL, "-%s unknown\n", cp);
1189 snprintf (buf, sizeof(buf), "%s [switches]", sp);
1190 print_help (buf, sendswitches, 1);
1193 print_version (invo_name);
1204 if (!(cp = *argp++) || sscanf (cp, "%d", &splitsw) != 1) {
1205 advise (NULL, "missing argument to %s", argp[-2]);
1233 debugsw++; /* fall */
1269 if (!(cp = *argp++) || *cp == '-') {
1270 advise (NULL, "missing argument to %s", argp[-2]);
1278 if (!(cp = *argp++) || *cp == '-') {
1279 advise (NULL, "missing argument to %s", argp[-2]);
1286 if (!(attach = *argp++) || *attach == '-') {
1287 advise (NULL, "missing argument to %s", argp[-2]);
1295 case SNDATTACHFORMAT:
1296 if (! *argp || **argp == '-')
1297 adios (NULL, "missing argument to %s", argp[-1]);
1299 attachformat = atoi (*argp);
1300 if (attachformat < 0 ||
1301 attachformat > ATTACHFORMATS - 1) {
1302 advise (NULL, "unsupported attachformat %d",
1311 advise (NULL, "usage: %s [switches]", sp);
1315 /* allow Aliasfile: profile entry */
1316 if ((cp = context_find ("Aliasfile"))) {
1320 for (ap = brkstring (dp, " ", "\n"); ap && *ap; ap++) {
1321 vec[vecp++] = "-alias";
1326 if ((cp = getenv ("SIGNATURE")) == NULL || *cp == 0)
1327 if ((cp = context_find ("signature")) && *cp)
1328 m_putenv ("SIGNATURE", cp);
1330 if ((annotext = getenv ("mhannotate")) == NULL || *annotext == 0)
1332 if ((altmsg = getenv ("mhaltmsg")) == NULL || *altmsg == 0)
1334 if (annotext && ((cp = getenv ("mhinplace")) != NULL && *cp != 0))
1335 inplace = atoi (cp);
1337 if ((cp = getenv ("mhdist"))
1340 && (distsw = atoi (cp))
1341 #endif /* not lint */
1343 vec[vecp++] = "-dist";
1344 distfile = getcpy (m_mktemp2(altmsg, invo_name, NULL, NULL));
1346 if (link (altmsg, distfile) == NOTOK)
1347 adios (distfile, "unable to link %s to", altmsg);
1352 if (altmsg == NULL || stat (altmsg, &st) == NOTOK) {
1357 if ((pushsw = pushed))
1360 vec[0] = r1bindex (postproc, '/');
1363 if (sendsbr (vec, vecp, file, &st, 1, attach, attachformat) == OK)
1372 whomfile (char **arg, char *file)
1378 context_save (); /* save the context file */
1381 switch (pid = vfork()) {
1383 advise ("fork", "unable to");
1388 vec[vecp++] = r1bindex (whomproc, '/');
1392 vec[vecp++] = *arg++;
1395 execvp (whomproc, vec);
1396 fprintf (stderr, "unable to exec ");
1398 _exit (-1); /* NOTREACHED */
1401 return (pidwait (pid, NOTOK) & 0377 ? 1 : 0);
1407 * Remove the draft file
1411 removefile (char *drft)
1413 if (unlink (drft) == NOTOK)
1414 adios (drft, "unable to unlink");