]>
diplodocus.org Git - nmh/blob - uip/whatnowsbr.c
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
[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 ("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
)
608 if (getcwd(olddir
, sizeof(olddir
)) == 0)
609 adios("getcwd", "could not get working directory");
611 adios("chdir", "could not change working directory");
613 if (chdir(olddir
) != 0)
614 adios("chdir", "could not change working directory");
618 /* ditto for popen() */
620 popen_in_dir(const char *dir
, const char *cmd
, const char *type
)
624 if (getcwd(olddir
, sizeof(olddir
)) == 0)
625 adios("getcwd", "could not get working directory");
627 adios("chdir", "could not change working directory");
628 f
= popen(cmd
, type
);
629 if (chdir(olddir
) != 0)
630 adios("chdir", "could not change working directory");
639 static int reedit
= 0; /* have we been here before? */
640 static char *edsave
= NULL
; /* the editor we used previously */
644 editfile (char **ed
, char **arg
, char *file
, int use
, struct msgs
*mp
,
645 char *altmsg
, char *cwd
, int save_editor
, int atfile
)
647 int pid
, status
, vecp
;
648 char altpath
[BUFSIZ
], linkpath
[BUFSIZ
];
649 char *cp
, *vec
[MAXARGS
];
654 #endif /* HAVE_LSTAT */
656 /* Was there a previous edit session? */
658 if (!*ed
) { /* no explicit editor */
659 *ed
= edsave
; /* so use the previous one */
660 if ((cp
= r1bindex (*ed
, '/')) == NULL
)
663 /* unless we've specified it via "editor-next" */
664 cp
= concat (cp
, "-next", NULL
);
665 if ((cp
= context_find (cp
)) != NULL
)
669 /* set initial editor */
670 if (*ed
== NULL
&& (*ed
= context_find ("editor")) == NULL
)
674 if (altmsg
&& atfile
) {
675 if (mp
== NULL
|| *altmsg
== '/' || cwd
== NULL
)
676 strncpy (altpath
, altmsg
, sizeof(altpath
));
678 snprintf (altpath
, sizeof(altpath
), "%s/%s", mp
->foldpath
, altmsg
);
680 strncpy (linkpath
, LINK
, sizeof(linkpath
));
682 snprintf (linkpath
, sizeof(linkpath
), "%s/%s", cwd
, LINK
);
686 if (link (altpath
, linkpath
) == NOTOK
) {
687 symlink (altpath
, linkpath
);
692 #else /* not HAVE_LSTAT */
693 link (altpath
, linkpath
);
694 #endif /* not HAVE_LSTAT */
697 context_save (); /* save the context file */
700 switch (pid
= vfork()) {
702 advise ("fork", "unable to");
711 m_putenv ("mhfolder", mp
->foldpath
);
712 m_putenv ("editalt", altpath
);
716 vec
[vecp
++] = r1bindex (*ed
, '/');
719 vec
[vecp
++] = *arg
++;
724 fprintf (stderr
, "unable to exec ");
729 if ((status
= pidwait (pid
, NOTOK
))) {
730 if (((status
& 0xff00) != 0xff00)
731 && (!reedit
|| (status
& 0x00ff))) {
732 if (!use
&& (status
& 0xff00) &&
733 (rename (file
, cp
= m_backup (file
)) != NOTOK
)) {
734 advise (NULL
, "problems with edit--draft left in %s", cp
);
736 advise (NULL
, "problems with edit--%s preserved", file
);
739 status
= -2; /* maybe "reedit ? -2 : -1"? */
749 ? lstat (linkpath
, &st
) != NOTOK
750 && S_ISREG(st
.st_mode
)
751 && copyf (linkpath
, altpath
) == NOTOK
752 : stat (linkpath
, &st
) != NOTOK
754 && (unlink (altpath
) == NOTOK
755 || link (linkpath
, altpath
) == NOTOK
)))
756 advise (linkpath
, "unable to update %s from", altmsg
);
757 #else /* HAVE_LSTAT */
761 && stat (linkpath
, &st
) != NOTOK
763 && (unlink (altpath
) == NOTOK
764 || link (linkpath
, altpath
) == NOTOK
))
765 advise (linkpath
, "unable to update %s from", altmsg
);
766 #endif /* HAVE_LSTAT */
769 /* normally, we remember which editor we used */
771 edsave
= getcpy (*ed
);
774 if (altmsg
&& atfile
)
783 copyf (char *ifile
, char *ofile
)
788 if ((in
= open (ifile
, O_RDONLY
)) == NOTOK
)
790 if ((out
= open (ofile
, O_WRONLY
| O_TRUNC
)) == NOTOK
) {
791 admonish (ofile
, "unable to open and truncate");
796 while ((i
= read (in
, buffer
, sizeof(buffer
))) > OK
)
797 if (write (out
, buffer
, i
) != i
) {
798 advise (ofile
, "may have damaged");
807 #endif /* HAVE_LSTAT */
815 sendfile (char **arg
, char *file
, int pushsw
)
819 char *cp
, *sp
, *vec
[MAXARGS
];
821 /* Translate MIME composition file, if necessary */
822 if ((cp
= context_find ("automimeproc"))
823 && (!strcmp (cp
, "1"))
824 && !getenv ("NOMHNPROC")
825 && check_draft (file
)
826 && (buildfile (NULL
, file
) == NOTOK
))
829 /* For backwards compatibility */
830 if ((cp
= context_find ("automhnproc"))
831 && !getenv ("NOMHNPROC")
832 && check_draft (file
)
833 && (i
= editfile (&cp
, NULL
, file
, NOUSE
, NULL
, NULL
, NULL
, 0, 0)))
837 * If the sendproc is the nmh command `send', then we call
838 * those routines directly rather than exec'ing the command.
840 if (strcmp (sp
= r1bindex (sendproc
, '/'), "send") == 0) {
842 sendit (invo_name
= sp
, arg
, file
, pushsw
);
847 context_save (); /* save the context file */
850 for (i
= 0; (child_id
= vfork()) == NOTOK
&& i
< 5; i
++)
854 advise (NULL
, "unable to fork, so sending directly...");
857 vec
[vecp
++] = invo_name
;
859 vec
[vecp
++] = "-push";
862 vec
[vecp
++] = *arg
++;
866 execvp (sendproc
, vec
);
867 fprintf (stderr
, "unable to exec ");
872 if (pidwait(child_id
, OK
) == 0)
880 * Translate MIME composition file (call buildmimeproc)
884 buildfile (char **argp
, char *file
)
891 /* allocate space for arguments */
897 args
= (char **) mh_xmalloc((i
+ 2) * sizeof(char *));
900 * For backward compatibility, we need to add -build
901 * if we are using mhn as buildmimeproc
904 if (strcmp (r1bindex (ed
, '/'), "mhn") == 0)
905 args
[i
++] = "-build";
907 /* copy any other arguments */
908 while (argp
&& *argp
)
912 i
= editfile (&ed
, args
, file
, NOUSE
, NULL
, NULL
, NULL
, 0, 0);
915 return (i
? NOTOK
: OK
);
920 * Check if draft is a mhbuild composition file
924 check_draft (char *msgnam
)
927 char buf
[BUFSIZ
], name
[NAMESZ
];
930 if ((fp
= fopen (msgnam
, "r")) == NULL
)
933 switch (state
= m_getfld (state
, name
, buf
, sizeof(buf
), fp
)) {
938 * If draft already contains any of the
939 * Content-XXX fields, then assume it already
942 if (uprf (name
, XXX_FIELD_PRF
)) {
946 while (state
== FLDPLUS
)
947 state
= m_getfld (state
, name
, buf
, sizeof(buf
), fp
);
954 for (bp
= buf
; *bp
; bp
++)
955 if (*bp
!= ' ' && *bp
!= '\t' && *bp
!= '\n') {
960 state
= m_getfld (state
, name
, buf
, sizeof(buf
), fp
);
961 } while (state
== BODY
);
972 # define SASLminc(a) (a)
973 #else /* CYRUS_SASL */
974 # define SASLminc(a) 0
975 #endif /* CYRUS_SASL */
978 # define TLSminc(a) (a)
979 #else /* TLS_SUPPORT */
980 # define TLSminc(a) 0
981 #endif /* TLS_SUPPORT */
983 static struct swit sendswitches
[] = {
985 { "alias aliasfile", 0 },
989 { "filter filterfile", 0 },
1013 { "split seconds", 0 },
1027 { "width columns", 0 },
1028 #define SVERSIONSW 22
1032 #define BITSTUFFSW 24
1033 { "dashstuffing", -12 },
1034 #define NBITSTUFFSW 25
1035 { "nodashstuffing", -14 },
1045 { "client host", -6 },
1047 { "server host", 6 },
1051 { "draftfolder +folder", -6 },
1053 { "draftmessage msg", -6 },
1055 { "nodraftfolder", -3 },
1057 { "sasl", SASLminc(-4) },
1059 { "nosasl", SASLminc(-6) },
1060 #define SASLMXSSFSW 38
1061 { "saslmaxssf", SASLminc(-10) },
1062 #define SASLMECHSW 39
1063 { "saslmech", SASLminc(-5) },
1065 { "user", SASLminc(-4) },
1066 #define SNDATTACHSW 41
1067 { "attach file", 6 },
1068 #define SNDNOATTACHSW 42
1070 #define SNDATTACHFORMAT 43
1071 { "attachformat", 7 },
1073 { "port server-port-name/number", 4 },
1075 { "tls", TLSminc(-3) },
1077 { "notls", TLSminc(-5) },
1082 extern int debugsw
; /* from sendsbr.c */
1090 extern char *altmsg
; /* .. */
1091 extern char *annotext
;
1092 extern char *distfile
;
1096 sendit (char *sp
, char **arg
, char *file
, int pushed
)
1099 char *cp
, buf
[BUFSIZ
], **argp
;
1100 char **arguments
, *vec
[MAXARGS
];
1102 char *attach
= NMH_ATTACH_HEADER
;/* attachment header field name */
1103 int attachformat
= 1; /* mhbuild format specifier for
1111 * Make sure these are defined. In particular, we need
1112 * vec[1] to be NULL, in case "arg" is NULL below. It
1113 * doesn't matter what is the value of vec[0], but we
1114 * set it to NULL, to help catch "off-by-one" errors.
1120 * Temporarily copy arg to vec, since the brkstring() call in
1121 * getarguments() will wipe it out before it is merged in.
1122 * Also, we skip the first element of vec, since getarguments()
1123 * skips it. Then we count the number of arguments
1124 * copied. The value of "n" will be one greater than
1125 * this in order to simulate the standard argc/argv.
1130 copyip (arg
, vec
+1, MAXARGS
-1);
1137 * Merge any arguments from command line (now in vec)
1138 * and arguments from profile.
1140 arguments
= getarguments (sp
, n
, vec
, 1);
1152 vecp
= 1; /* we'll get the zero'th element later */
1153 vec
[vecp
++] = "-library";
1154 vec
[vecp
++] = getcpy (m_maildir (""));
1156 if ((cp
= context_find ("fileproc"))) {
1157 vec
[vecp
++] = "-fileproc";
1161 if ((cp
= context_find ("mhlproc"))) {
1162 vec
[vecp
++] = "-mhlproc";
1166 while ((cp
= *argp
++)) {
1168 switch (smatch (++cp
, sendswitches
)) {
1170 ambigsw (cp
, sendswitches
);
1173 advise (NULL
, "-%s unknown\n", cp
);
1177 snprintf (buf
, sizeof(buf
), "%s [switches]", sp
);
1178 print_help (buf
, sendswitches
, 1);
1181 print_version (invo_name
);
1192 if (!(cp
= *argp
++) || sscanf (cp
, "%d", &splitsw
) != 1) {
1193 advise (NULL
, "missing argument to %s", argp
[-2]);
1221 debugsw
++; /* fall */
1255 if (!(cp
= *argp
++) || *cp
== '-') {
1256 advise (NULL
, "missing argument to %s", argp
[-2]);
1264 if (!(cp
= *argp
++) || *cp
== '-') {
1265 advise (NULL
, "missing argument to %s", argp
[-2]);
1272 if (!(attach
= *argp
++) || *attach
== '-') {
1273 advise (NULL
, "missing argument to %s", argp
[-2]);
1281 case SNDATTACHFORMAT
:
1282 if (! *argp
|| **argp
== '-')
1283 adios (NULL
, "missing argument to %s", argp
[-1]);
1285 attachformat
= atoi (*argp
);
1286 if (attachformat
< 0 ||
1287 attachformat
> ATTACHFORMATS
- 1) {
1288 advise (NULL
, "unsupported attachformat %d",
1297 advise (NULL
, "usage: %s [switches]", sp
);
1301 /* allow Aliasfile: profile entry */
1302 if ((cp
= context_find ("Aliasfile"))) {
1306 for (ap
= brkstring (dp
, " ", "\n"); ap
&& *ap
; ap
++) {
1307 vec
[vecp
++] = "-alias";
1312 if ((cp
= getenv ("SIGNATURE")) == NULL
|| *cp
== 0)
1313 if ((cp
= context_find ("signature")) && *cp
)
1314 m_putenv ("SIGNATURE", cp
);
1316 if ((annotext
= getenv ("mhannotate")) == NULL
|| *annotext
== 0)
1318 if ((altmsg
= getenv ("mhaltmsg")) == NULL
|| *altmsg
== 0)
1320 if (annotext
&& ((cp
= getenv ("mhinplace")) != NULL
&& *cp
!= 0))
1321 inplace
= atoi (cp
);
1323 if ((cp
= getenv ("mhdist"))
1326 && (distsw
= atoi (cp
))
1327 #endif /* not lint */
1329 vec
[vecp
++] = "-dist";
1330 distfile
= getcpy (m_mktemp2(altmsg
, invo_name
, NULL
, NULL
));
1332 if (link (altmsg
, distfile
) == NOTOK
)
1333 adios (distfile
, "unable to link %s to", altmsg
);
1338 if (altmsg
== NULL
|| stat (altmsg
, &st
) == NOTOK
) {
1343 if ((pushsw
= pushed
))
1346 vec
[0] = r1bindex (postproc
, '/');
1349 if (sendsbr (vec
, vecp
, file
, &st
, 1, attach
, attachformat
) == OK
)
1358 whomfile (char **arg
, char *file
)
1364 context_save (); /* save the context file */
1367 switch (pid
= vfork()) {
1369 advise ("fork", "unable to");
1374 vec
[vecp
++] = r1bindex (whomproc
, '/');
1378 vec
[vecp
++] = *arg
++;
1381 execvp (whomproc
, vec
);
1382 fprintf (stderr
, "unable to exec ");
1384 _exit (-1); /* NOTREACHED */
1387 return (pidwait (pid
, NOTOK
) & 0377 ? 1 : 0);
1393 * Remove the draft file
1397 removefile (char *drft
)
1399 if (unlink (drft
) == NOTOK
)
1400 adios (drft
, "unable to unlink");