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 *, 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), "-d", 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), "-d", 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) + 4;
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);
582 *cp++ = '&'; *cp++ = '&';
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 *lsoptions, char **argp)
597 char *lscmd = concat ("ls ", lsoptions, " --", NULL);
598 writesomecmd(buf, bufsz, lscmd, "", argp);
602 /* Like system(), but run the command in directory dir.
603 * This assumes the program is single-threaded!
606 system_in_dir(const char *dir, const char *cmd)
611 /* ensure that $SHELL exists, as the cmd was written relying on
612 a non-blank $SHELL... */
613 setenv("SHELL","/bin/sh",0); /* don't overwrite */
615 if (getcwd(olddir, sizeof(olddir)) == 0)
616 adios("getcwd", "could not get working directory");
618 adios("chdir", "could not change working directory");
620 if (chdir(olddir) != 0)
621 adios("chdir", "could not change working directory");
625 /* ditto for popen() */
627 popen_in_dir(const char *dir, const char *cmd, const char *type)
632 /* ensure that $SHELL exists, as the cmd was written relying on
633 a non-blank $SHELL... */
634 setenv("SHELL","/bin/sh",0); /* don't overwrite */
636 if (getcwd(olddir, sizeof(olddir)) == 0)
637 adios("getcwd", "could not get working directory");
639 adios("chdir", "could not change working directory");
640 f = popen(cmd, type);
641 if (chdir(olddir) != 0)
642 adios("chdir", "could not change working directory");
651 static int reedit = 0; /* have we been here before? */
652 static char *edsave = NULL; /* the editor we used previously */
656 editfile (char **ed, char **arg, char *file, int use, struct msgs *mp,
657 char *altmsg, char *cwd, int save_editor, int atfile)
659 int pid, status, vecp;
660 char altpath[BUFSIZ], linkpath[BUFSIZ];
661 char *cp, *vec[MAXARGS];
666 #endif /* HAVE_LSTAT */
668 /* Was there a previous edit session? */
670 if (!*ed) { /* no explicit editor */
671 *ed = edsave; /* so use the previous one */
672 if ((cp = r1bindex (*ed, '/')) == NULL)
675 /* unless we've specified it via "editor-next" */
676 cp = concat (cp, "-next", NULL);
677 if ((cp = context_find (cp)) != NULL)
681 /* set initial editor */
682 if (*ed == NULL && (*ed = context_find ("editor")) == NULL)
687 if (mp == NULL || *altmsg == '/' || cwd == NULL)
688 strncpy (altpath, altmsg, sizeof(altpath));
690 snprintf (altpath, sizeof(altpath), "%s/%s", mp->foldpath, altmsg);
692 strncpy (linkpath, LINK, sizeof(linkpath));
694 snprintf (linkpath, sizeof(linkpath), "%s/%s", cwd, LINK);
699 if (link (altpath, linkpath) == NOTOK) {
700 symlink (altpath, linkpath);
705 #else /* not HAVE_LSTAT */
706 link (altpath, linkpath);
707 #endif /* not HAVE_LSTAT */
711 context_save (); /* save the context file */
714 switch (pid = vfork()) {
716 advise ("fork", "unable to");
725 m_putenv ("mhfolder", mp->foldpath);
726 m_putenv ("editalt", altpath);
730 vec[vecp++] = r1bindex (*ed, '/');
733 vec[vecp++] = *arg++;
738 fprintf (stderr, "unable to exec ");
743 if ((status = pidwait (pid, NOTOK))) {
744 if (((status & 0xff00) != 0xff00)
745 && (!reedit || (status & 0x00ff))) {
746 if (!use && (status & 0xff00) &&
747 (rename (file, cp = m_backup (file)) != NOTOK)) {
748 advise (NULL, "problems with edit--draft left in %s", cp);
750 advise (NULL, "problems with edit--%s preserved", file);
753 status = -2; /* maybe "reedit ? -2 : -1"? */
763 ? lstat (linkpath, &st) != NOTOK
764 && S_ISREG(st.st_mode)
765 && copyf (linkpath, altpath) == NOTOK
766 : stat (linkpath, &st) != NOTOK
768 && (unlink (altpath) == NOTOK
769 || link (linkpath, altpath) == NOTOK)))
770 advise (linkpath, "unable to update %s from", altmsg);
771 #else /* HAVE_LSTAT */
775 && stat (linkpath, &st) != NOTOK
777 && (unlink (altpath) == NOTOK
778 || link (linkpath, altpath) == NOTOK))
779 advise (linkpath, "unable to update %s from", altmsg);
780 #endif /* HAVE_LSTAT */
783 /* normally, we remember which editor we used */
785 edsave = getcpy (*ed);
788 if (altmsg && atfile)
797 copyf (char *ifile, char *ofile)
802 if ((in = open (ifile, O_RDONLY)) == NOTOK)
804 if ((out = open (ofile, O_WRONLY | O_TRUNC)) == NOTOK) {
805 admonish (ofile, "unable to open and truncate");
810 while ((i = read (in, buffer, sizeof(buffer))) > OK)
811 if (write (out, buffer, i) != i) {
812 advise (ofile, "may have damaged");
821 #endif /* HAVE_LSTAT */
829 sendfile (char **arg, char *file, int pushsw)
833 char *cp, *sp, *vec[MAXARGS];
835 /* Translate MIME composition file, if necessary */
836 if ((cp = context_find ("automimeproc"))
837 && (!strcmp (cp, "1"))
838 && check_draft (file)
839 && (buildfile (NULL, file) == NOTOK))
842 /* For backwards compatibility */
843 if ((cp = context_find ("automhnproc"))
844 && check_draft (file)
845 && (i = editfile (&cp, NULL, file, NOUSE, NULL, NULL, NULL, 0, 0)))
849 * If the sendproc is the nmh command `send', then we call
850 * those routines directly rather than exec'ing the command.
852 if (strcmp (sp = r1bindex (sendproc, '/'), "send") == 0) {
854 sendit (invo_name = sp, arg, file, pushsw);
859 context_save (); /* save the context file */
862 for (i = 0; (child_id = vfork()) == NOTOK && i < 5; i++)
866 advise (NULL, "unable to fork, so sending directly...");
869 vec[vecp++] = invo_name;
871 vec[vecp++] = "-push";
874 vec[vecp++] = *arg++;
878 execvp (sendproc, vec);
879 fprintf (stderr, "unable to exec ");
884 if (pidwait(child_id, OK) == 0)
892 * Translate MIME composition file (call buildmimeproc)
896 buildfile (char **argp, char *file)
903 /* allocate space for arguments */
909 args = (char **) mh_xmalloc((i + 2) * sizeof(char *));
912 * For backward compatibility, we need to add -build
913 * if we are using mhn as buildmimeproc
916 if (strcmp (r1bindex (ed, '/'), "mhn") == 0)
917 args[i++] = "-build";
919 /* copy any other arguments */
920 while (argp && *argp)
924 i = editfile (&ed, args, file, NOUSE, NULL, NULL, NULL, 0, 0);
927 return (i ? NOTOK : OK);
932 * Check if draft is a mhbuild composition file
936 check_draft (char *msgnam)
939 char buf[BUFSIZ], name[NAMESZ];
942 if ((fp = fopen (msgnam, "r")) == NULL)
945 switch (state = m_getfld (state, name, buf, sizeof(buf), fp)) {
950 * If draft already contains any of the
951 * Content-XXX fields, then assume it already
954 if (uprf (name, XXX_FIELD_PRF)) {
958 while (state == FLDPLUS)
959 state = m_getfld (state, name, buf, sizeof(buf), fp);
966 for (bp = buf; *bp; bp++)
967 if (*bp != ' ' && *bp != '\t' && *bp != '\n') {
972 state = m_getfld (state, name, buf, sizeof(buf), fp);
973 } while (state == BODY);
984 # define SASLminc(a) (a)
985 #else /* CYRUS_SASL */
986 # define SASLminc(a) 0
987 #endif /* CYRUS_SASL */
990 # define TLSminc(a) (a)
991 #else /* TLS_SUPPORT */
992 # define TLSminc(a) 0
993 #endif /* TLS_SUPPORT */
995 static struct swit sendswitches[] = {
997 { "alias aliasfile", 0 },
1001 { "filter filterfile", 0 },
1025 { "split seconds", 0 },
1039 { "width columns", 0 },
1040 #define SVERSIONSW 22
1044 #define BITSTUFFSW 24
1045 { "dashstuffing", -12 },
1046 #define NBITSTUFFSW 25
1047 { "nodashstuffing", -14 },
1057 { "client host", -6 },
1059 { "server host", 6 },
1063 { "draftfolder +folder", -6 },
1065 { "draftmessage msg", -6 },
1067 { "nodraftfolder", -3 },
1069 { "sasl", SASLminc(-4) },
1071 { "nosasl", SASLminc(-6) },
1072 #define SASLMXSSFSW 38
1073 { "saslmaxssf", SASLminc(-10) },
1074 #define SASLMECHSW 39
1075 { "saslmech", SASLminc(-5) },
1077 { "user", SASLminc(-4) },
1078 #define SNDATTACHSW 41
1079 { "attach file", 6 },
1080 #define SNDNOATTACHSW 42
1082 #define SNDATTACHFORMAT 43
1083 { "attachformat", 7 },
1085 { "port server-port-name/number", 4 },
1087 { "tls", TLSminc(-3) },
1089 { "notls", TLSminc(-5) },
1091 { "mts smtp|sendmail/smtp|sendmail/pipe", 2 },
1092 #define MESSAGEIDSW 48
1093 { "messageid localname|random", 2 },
1098 extern int debugsw; /* from sendsbr.c */
1106 extern char *altmsg; /* .. */
1107 extern char *annotext;
1108 extern char *distfile;
1112 sendit (char *sp, char **arg, char *file, int pushed)
1115 char *cp, buf[BUFSIZ], **argp;
1116 char **arguments, *vec[MAXARGS];
1118 char *attach = NMH_ATTACH_HEADER;/* attachment header field name */
1119 int attachformat = 1; /* mhbuild format specifier for
1127 * Make sure these are defined. In particular, we need
1128 * vec[1] to be NULL, in case "arg" is NULL below. It
1129 * doesn't matter what is the value of vec[0], but we
1130 * set it to NULL, to help catch "off-by-one" errors.
1136 * Temporarily copy arg to vec, since the brkstring() call in
1137 * getarguments() will wipe it out before it is merged in.
1138 * Also, we skip the first element of vec, since getarguments()
1139 * skips it. Then we count the number of arguments
1140 * copied. The value of "n" will be one greater than
1141 * this in order to simulate the standard argc/argv.
1146 copyip (arg, vec+1, MAXARGS-1);
1153 * Merge any arguments from command line (now in vec)
1154 * and arguments from profile.
1156 arguments = getarguments (sp, n, vec, 1);
1168 vecp = 1; /* we'll get the zero'th element later */
1169 vec[vecp++] = "-library";
1170 vec[vecp++] = getcpy (m_maildir (""));
1172 if ((cp = context_find ("fileproc"))) {
1173 vec[vecp++] = "-fileproc";
1177 if ((cp = context_find ("mhlproc"))) {
1178 vec[vecp++] = "-mhlproc";
1182 while ((cp = *argp++)) {
1184 switch (smatch (++cp, sendswitches)) {
1186 ambigsw (cp, sendswitches);
1189 advise (NULL, "-%s unknown\n", cp);
1193 snprintf (buf, sizeof(buf), "%s [switches]", sp);
1194 print_help (buf, sendswitches, 1);
1197 print_version (invo_name);
1208 if (!(cp = *argp++) || sscanf (cp, "%d", &splitsw) != 1) {
1209 advise (NULL, "missing argument to %s", argp[-2]);
1237 debugsw++; /* fall */
1273 if (!(cp = *argp++) || *cp == '-') {
1274 advise (NULL, "missing argument to %s", argp[-2]);
1282 if (!(cp = *argp++) || *cp == '-') {
1283 advise (NULL, "missing argument to %s", argp[-2]);
1290 if (!(attach = *argp++) || *attach == '-') {
1291 advise (NULL, "missing argument to %s", argp[-2]);
1299 case SNDATTACHFORMAT:
1300 if (! *argp || **argp == '-')
1301 adios (NULL, "missing argument to %s", argp[-1]);
1303 attachformat = atoi (*argp);
1304 if (attachformat < 0 ||
1305 attachformat > ATTACHFORMATS - 1) {
1306 advise (NULL, "unsupported attachformat %d",
1315 advise (NULL, "usage: %s [switches]", sp);
1319 /* allow Aliasfile: profile entry */
1320 if ((cp = context_find ("Aliasfile"))) {
1324 for (ap = brkstring (dp, " ", "\n"); ap && *ap; ap++) {
1325 vec[vecp++] = "-alias";
1330 if ((cp = getenv ("SIGNATURE")) == NULL || *cp == 0)
1331 if ((cp = context_find ("signature")) && *cp)
1332 m_putenv ("SIGNATURE", cp);
1334 if ((annotext = getenv ("mhannotate")) == NULL || *annotext == 0)
1336 if ((altmsg = getenv ("mhaltmsg")) == NULL || *altmsg == 0)
1338 if (annotext && ((cp = getenv ("mhinplace")) != NULL && *cp != 0))
1339 inplace = atoi (cp);
1341 if ((cp = getenv ("mhdist"))
1344 && (distsw = atoi (cp))
1345 #endif /* not lint */
1347 vec[vecp++] = "-dist";
1348 distfile = getcpy (m_mktemp2(altmsg, invo_name, NULL, NULL));
1350 if (link (altmsg, distfile) == NOTOK)
1351 adios (distfile, "unable to link %s to", altmsg);
1356 if (altmsg == NULL || stat (altmsg, &st) == NOTOK) {
1361 if ((pushsw = pushed))
1364 vec[0] = r1bindex (postproc, '/');
1367 if (sendsbr (vec, vecp, file, &st, 1, attach, attachformat) == OK)
1376 whomfile (char **arg, char *file)
1382 context_save (); /* save the context file */
1385 switch (pid = vfork()) {
1387 advise ("fork", "unable to");
1392 vec[vecp++] = r1bindex (whomproc, '/');
1396 vec[vecp++] = *arg++;
1399 execvp (whomproc, vec);
1400 fprintf (stderr, "unable to exec ");
1402 _exit (-1); /* NOTREACHED */
1405 return (pidwait (pid, NOTOK) & 0377 ? 1 : 0);
1411 * Remove the draft file
1415 removefile (char *drft)
1417 if (unlink (drft) == NOTOK)
1418 adios (drft, "unable to unlink");