]>
diplodocus.org Git - nmh/blob - uip/whatnowsbr.c
3 * whatnowsbr.c -- the WhatNow shell
7 * This code is Copyright (c) 2002, by the authors of nmh. See the
8 * COPYRIGHT file in the root directory of the nmh distribution for
9 * complete copyright information.
11 * Several options have been added to ease the inclusion of attachments
12 * using the header field name mechanism added to anno and send. The
13 * -attach option is used to specify the header field name for attachments.
15 * Several commands have been added at the whatnow prompt:
17 * cd [ directory ] This option works just like the shell's
18 * cd command and lets the user change the
19 * directory from which attachments are
20 * taken so that long path names are not
21 * needed with every file.
23 * ls [ ls-options ] This option works just like the normal
24 * ls command and exists to allow the user
25 * to verify file names in the directory.
27 * pwd This option works just like the normal
28 * pwd command and exists to allow the user
29 * to verify the directory.
31 * attach files This option attaches the named files to
34 * alist [-ln] This option lists the attachments on the
35 * draft. -l gets long listings, -n gets
38 * detach files This option removes attachments from the
39 * detach -n numbers draft. This can be done by file name or
40 * by attachment number.
49 static struct swit whatnowswitches
[] = {
51 { "draftfolder +folder", 0 },
53 { "draftmessage msg", 0 },
55 { "nodraftfolder", 0 },
57 { "editor editor", 0 },
61 { "prompt string", 4 },
67 { "attach header-field-name", 0 },
72 * Options at the "whatnow" prompt
74 static struct swit aleqs
[] = {
76 { "edit [<editor> <switches>]", 0 },
78 { "refile [<switches>] +folder", 0 },
80 { "mime [<switches>]", 0 },
82 { "display [<switches>]", 0 },
84 { "list [<switches>]", 0 },
86 { "send [<switches>]", 0 },
88 { "push [<switches>]", 0 },
90 { "whom [<switches>]", 0 },
92 { "quit [-delete]", 0 },
96 { "cd [directory]", 0 },
101 #define ATTACHCMDSW 13
103 #define DETACHCMDSW 14
104 { "detach [-n]", 2 },
105 #define ALISTCMDSW 15
106 { "alist [-ln] ", 2 },
110 static char *myprompt
= "\nWhat now? ";
115 static int editfile (char **, char **, char *, int, struct msgs
*,
116 char *, char *, int);
117 static int sendfile (char **, char *, int);
118 static void sendit (char *, char **, char *, int);
119 static int buildfile (char **, char *);
120 static int check_draft (char *);
121 static int whomfile (char **, char *);
122 static int removefile (char *);
125 static int copyf (char *, char *);
130 WhatNow (int argc
, char **argv
)
132 int isdf
= 0, nedit
= 0, use
= 0;
133 char *cp
, *dfolder
= NULL
, *dmsg
= NULL
;
134 char *ed
= NULL
, *drft
= NULL
, *msgnam
= NULL
;
135 char buf
[BUFSIZ
], prompt
[BUFSIZ
];
136 char **argp
, **arguments
;
138 char *attach
= (char *)0; /* attachment header field name */
139 char cwd
[MAXPATHLEN
+ 1]; /* current working directory */
140 char file
[MAXPATHLEN
+ 1]; /* file name buffer */
141 char shell
[MAXPATHLEN
+ 1]; /* shell response buffer */
142 FILE *f
; /* read pointer for bgnd proc */
143 char *l
; /* set on -l to alist command */
144 int n
; /* set on -n to alist command */
146 invo_name
= r1bindex (argv
[0], '/');
148 /* read user profile/context */
151 arguments
= getarguments (invo_name
, argc
, argv
, 1);
155 * Get the initial current working directory.
158 if (getcwd(cwd
, sizeof (cwd
)) == (char *)0) {
159 adios("getcwd", "could not get working directory");
162 while ((cp
= *argp
++)) {
164 switch (smatch (++cp
, whatnowswitches
)) {
166 ambigsw (cp
, whatnowswitches
);
169 adios (NULL
, "-%s unknown", cp
);
172 snprintf (buf
, sizeof(buf
), "%s [switches] [file]", invo_name
);
173 print_help (buf
, whatnowswitches
, 1);
176 print_version(invo_name
);
181 adios (NULL
, "only one draft folder at a time!");
182 if (!(cp
= *argp
++) || *cp
== '-')
183 adios (NULL
, "missing argument to %s", argp
[-2]);
184 dfolder
= path (*cp
== '+' || *cp
== '@' ? cp
+ 1 : cp
,
185 *cp
!= '@' ? TFOLDER
: TSUBCWF
);
189 adios (NULL
, "only one draft message at a time!");
190 if (!(dmsg
= *argp
++) || *dmsg
== '-')
191 adios (NULL
, "missing argument to %s", argp
[-2]);
199 if (!(ed
= *argp
++) || *ed
== '-')
200 adios (NULL
, "missing argument to %s", argp
[-2]);
208 if (!(myprompt
= *argp
++) || *myprompt
== '-')
209 adios (NULL
, "missing argument to %s", argp
[-2]);
213 if (attach
!= (char *)0)
214 adios(NULL
, "only one attachment header field name at a time!");
215 if (!(attach
= *argp
++) || *attach
== '-')
216 adios (NULL
, "missing argument to %s", argp
[-2]);
221 adios (NULL
, "only one draft at a time!");
226 if ((drft
== NULL
&& (drft
= getenv ("mhdraft")) == NULL
) || *drft
== 0)
227 drft
= getcpy (m_draft (dfolder
, dmsg
, 1, &isdf
));
229 msgnam
= (cp
= getenv ("mhaltmsg")) && *cp
? getcpy (cp
) : NULL
;
231 if ((cp
= getenv ("mhuse")) && *cp
)
234 if (ed
== NULL
&& ((ed
= getenv ("mheditor")) == NULL
|| *ed
== 0)) {
239 /* start editing the draft, unless -noedit was given */
240 if (!nedit
&& editfile (&ed
, NULL
, drft
, use
, NULL
, msgnam
, NULL
, 1) < 0)
243 snprintf (prompt
, sizeof(prompt
), myprompt
, invo_name
);
245 if (!(argp
= getans (prompt
, aleqs
))) {
249 switch (smatch (*argp
, aleqs
)) {
251 /* display the message being replied to, or distributed */
253 showfile (++argp
, msgnam
);
255 advise (NULL
, "no alternate message to display");
259 /* Translate MIME composition file */
260 buildfile (++argp
, drft
);
264 /* Call an editor on the draft file */
267 if (editfile (&ed
, argp
, drft
, NOUSE
, NULL
, msgnam
, NULL
, 1) == NOTOK
)
272 /* display the draft file */
273 showfile (++argp
, drft
);
277 /* Check to whom the draft would be sent */
278 whomfile (++argp
, drft
);
282 /* Quit, and possibly delete the draft */
283 if (*++argp
&& (*argp
[0] == 'd' ||
284 ((*argp
)[0] == '-' && (*argp
)[1] == 'd'))) {
287 if (stat (drft
, &st
) != NOTOK
)
288 advise (NULL
, "draft left on %s", drft
);
293 /* Delete draft and exit */
298 /* Send draft in background */
299 if (sendfile (++argp
, drft
, 1))
305 sendfile (++argp
, drft
, 0);
309 /* Refile the draft */
310 if (refile (++argp
, drft
) == 0)
315 /* Change the working directory for attachments
317 * Run the directory through the user's shell so that
318 * we can take advantage of any syntax that the user
319 * is accustomed to. Read back the absolute path.
322 if (*++argp
== (char *)0) {
323 (void)sprintf(buf
, "$SHELL -c \"cd;pwd\"");
325 else if (strlen(*argp
) >= BUFSIZ
) {
326 adios((char *)0, "arguments too long");
329 (void)sprintf(buf
, "$SHELL -c \"cd %s;cd %s;pwd\"", cwd
, *argp
);
331 if ((f
= popen(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.
357 cp
= buf
+ sprintf(buf
, "$SHELL -c \" cd %s;ls", cwd
);
359 while (*++argp
!= (char *)0) {
360 if (cp
+ strlen(*argp
) + 2 >= buf
+ BUFSIZ
)
361 adios((char *)0, "arguments too long");
363 cp
+= sprintf(cp
, " %s", *argp
);
366 (void)strcat(cp
, "\"");
372 * List attachments on current draft. Options are:
374 * -l long listing (full path names)
378 if (attach
== (char *)0) {
379 advise((char *)0, "can't list because no header field name was given.");
386 while (*++argp
!= (char *)0) {
387 if (strcmp(*argp
, "-l") == 0)
390 else if (strcmp(*argp
, "-n") == 0)
393 else if (strcmp(*argp
, "-ln") == 0 || strcmp(*argp
, "-nl") == 0) {
405 advise((char *)0, "usage is alist [-ln].");
408 annolist(drft
, attach
, l
, n
);
414 * Attach files to current draft.
417 if (attach
== (char *)0) {
418 advise((char *)0, "can't attach because no header field name was given.");
423 * Build a command line that causes the user's shell to list the file name
424 * arguments. This handles and wildcard expansion, tilde expansion, etc.
427 cp
= buf
+ sprintf(buf
, "$SHELL -c \" cd %s;ls", cwd
);
429 while (*++argp
!= (char *)0) {
430 if (cp
+ strlen(*argp
) + 3 >= buf
+ BUFSIZ
)
431 adios((char *)0, "arguments too long");
433 cp
+= sprintf(cp
, " %s", *argp
);
436 (void)strcat(cp
, "\"");
439 * Read back the response from the shell, which contains a number of lines
440 * with one file name per line. Remove off the newline. Determine whether
441 * we have an absolute or relative path name. Prepend the current working
442 * directory to relative path names. Add the attachment annotation to the
446 if ((f
= popen(buf
, "r")) != (FILE *)0) {
447 while (fgets(shell
, sizeof (shell
), f
) != (char *)0) {
448 *(strchr(shell
, '\n')) = '\0';
451 (void)annotate(drft
, attach
, shell
, 1, 0, -2, 1);
453 (void)sprintf(file
, "%s/%s", cwd
, shell
);
454 (void)annotate(drft
, attach
, file
, 1, 0, -2, 1);
461 advise("popen", "could not get file from shell");
468 * Detach files from current draft.
471 if (attach
== (char *)0) {
472 advise((char *)0, "can't detach because no header field name was given.");
477 * Scan the arguments for a -n. Mixed file names and numbers aren't allowed,
478 * so this catches a -n anywhere in the argument list.
481 for (n
= 0, arguments
= argp
+ 1; *arguments
!= (char *)0; arguments
++) {
482 if (strcmp(*arguments
, "-n") == 0) {
489 * A -n was found so interpret the arguments as attachment numbers.
490 * Decrement any remaining argument number that is greater than the one
491 * just processed after processing each one so that the numbering stays
496 for (arguments
= argp
+ 1; *arguments
!= (char *)0; arguments
++) {
497 if (strcmp(*arguments
, "-n") == 0)
500 if (**arguments
!= '\0') {
501 n
= atoi(*arguments
);
502 (void)annotate(drft
, attach
, (char *)0, 1, 0, n
, 1);
504 for (argp
= arguments
+ 1; *argp
!= (char *)0; argp
++) {
505 if (atoi(*argp
) > n
) {
506 if (atoi(*argp
) == 1)
509 (void)sprintf(*argp
, "%d", atoi(*argp
) - 1);
517 * The arguments are interpreted as file names. Run them through the
518 * user's shell for wildcard expansion and other goodies. Do this from
519 * the current working directory if the argument is not an absolute path
520 * name (does not begin with a /).
524 for (arguments
= argp
+ 1; *arguments
!= (char *)0; arguments
++) {
525 if (**arguments
== '/') {
526 if (strlen(*arguments
) + sizeof ("$SHELL -c \"ls \"") >= sizeof (buf
))
527 adios((char *)0, "arguments too long");
529 (void)sprintf(buf
, "$SHELL -c \"ls %s\"", *arguments
);
532 if (strlen(cwd
) + strlen(*arguments
) + sizeof ("$SHELL -c \" cd ; ls \"") >= sizeof (buf
))
533 adios((char *)0, "arguments too long");
535 (void)sprintf(buf
, "$SHELL -c \" cd %s;ls %s\"", cwd
, *arguments
);
538 if ((f
= popen(buf
, "r")) != (FILE *)0) {
539 while (fgets(shell
, sizeof (cwd
), f
) != (char *)0) {
540 *(strchr(shell
, '\n')) = '\0';
541 (void)annotate(drft
, attach
, shell
, 1, 0, 0, 1);
547 advise("popen", "could not get file from shell");
555 /* Unknown command */
556 advise (NULL
, "say what?");
567 static int reedit
= 0; /* have we been here before? */
568 static char *edsave
= NULL
; /* the editor we used previously */
572 editfile (char **ed
, char **arg
, char *file
, int use
, struct msgs
*mp
,
573 char *altmsg
, char *cwd
, int save_editor
)
575 int pid
, status
, vecp
;
576 char altpath
[BUFSIZ
], linkpath
[BUFSIZ
];
577 char *cp
, *vec
[MAXARGS
];
583 int oumask
; /* PJS: for setting permissions on symlinks. */
585 #endif /* HAVE_LSTAT */
587 /* Was there a previous edit session? */
589 if (!*ed
) { /* no explicit editor */
590 *ed
= edsave
; /* so use the previous one */
591 if ((cp
= r1bindex (*ed
, '/')) == NULL
)
594 /* unless we've specified it via "editor-next" */
595 cp
= concat (cp
, "-next", NULL
);
596 if ((cp
= context_find (cp
)) != NULL
)
600 /* set initial editor */
601 if (*ed
== NULL
&& (*ed
= context_find ("editor")) == NULL
)
606 if (mp
== NULL
|| *altmsg
== '/' || cwd
== NULL
)
607 strncpy (altpath
, altmsg
, sizeof(altpath
));
609 snprintf (altpath
, sizeof(altpath
), "%s/%s", mp
->foldpath
, altmsg
);
611 strncpy (linkpath
, LINK
, sizeof(linkpath
));
613 snprintf (linkpath
, sizeof(linkpath
), "%s/%s", cwd
, LINK
);
619 if (link (altpath
, linkpath
) == NOTOK
) {
621 /* I don't think permission on symlinks matters /JLR */
622 oumask
= umask(0044); /* PJS: else symlinks are world 'r' */
624 symlink (altpath
, linkpath
);
626 umask(oumask
); /* PJS: else symlinks are world 'r' */
632 #else /* not HAVE_LSTAT */
633 link (altpath
, linkpath
);
634 #endif /* not HAVE_LSTAT */
637 context_save (); /* save the context file */
640 switch (pid
= vfork ()) {
642 advise ("fork", "unable to");
651 m_putenv ("mhfolder", mp
->foldpath
);
652 m_putenv ("editalt", altpath
);
656 vec
[vecp
++] = r1bindex (*ed
, '/');
659 vec
[vecp
++] = *arg
++;
664 fprintf (stderr
, "unable to exec ");
669 if ((status
= pidwait (pid
, NOTOK
))) {
671 if ((cp
= r1bindex (*ed
, '/'))
672 && strcmp (cp
, "vi") == 0
673 && (status
& 0x00ff) == 0)
677 if (((status
& 0xff00) != 0xff00)
678 && (!reedit
|| (status
& 0x00ff))) {
679 if (!use
&& (status
& 0xff00) &&
680 (rename (file
, cp
= m_backup (file
)) != NOTOK
)) {
681 advise (NULL
, "problems with edit--draft left in %s", cp
);
683 advise (NULL
, "problems with edit--%s preserved", file
);
686 status
= -2; /* maybe "reedit ? -2 : -1"? */
699 ? lstat (linkpath
, &st
) != NOTOK
700 && S_ISREG(st
.st_mode
)
701 && copyf (linkpath
, altpath
) == NOTOK
702 : stat (linkpath
, &st
) != NOTOK
704 && (unlink (altpath
) == NOTOK
705 || link (linkpath
, altpath
) == NOTOK
)))
706 advise (linkpath
, "unable to update %s from", altmsg
);
707 #else /* HAVE_LSTAT */
711 && stat (linkpath
, &st
) != NOTOK
713 && (unlink (altpath
) == NOTOK
714 || link (linkpath
, altpath
) == NOTOK
))
715 advise (linkpath
, "unable to update %s from", altmsg
);
716 #endif /* HAVE_LSTAT */
719 /* normally, we remember which editor we used */
721 edsave
= getcpy (*ed
);
733 copyf (char *ifile
, char *ofile
)
738 if ((in
= open (ifile
, O_RDONLY
)) == NOTOK
)
740 if ((out
= open (ofile
, O_WRONLY
| O_TRUNC
)) == NOTOK
) {
741 admonish (ofile
, "unable to open and truncate");
746 while ((i
= read (in
, buffer
, sizeof(buffer
))) > OK
)
747 if (write (out
, buffer
, i
) != i
) {
748 advise (ofile
, "may have damaged");
757 #endif /* HAVE_LSTAT */
765 sendfile (char **arg
, char *file
, int pushsw
)
769 char *cp
, *sp
, *vec
[MAXARGS
];
771 /* Translate MIME composition file, if necessary */
772 if ((cp
= context_find ("automimeproc"))
773 && (!strcmp (cp
, "1"))
774 && !getenv ("NOMHNPROC")
775 && check_draft (file
)
776 && (buildfile (NULL
, file
) == NOTOK
))
779 /* For backwards compatibility */
780 if ((cp
= context_find ("automhnproc"))
781 && !getenv ("NOMHNPROC")
782 && check_draft (file
)
783 && (i
= editfile (&cp
, NULL
, file
, NOUSE
, NULL
, NULL
, NULL
, 0)))
787 * If the sendproc is the nmh command `send', then we call
788 * those routines directly rather than exec'ing the command.
790 if (strcmp (sp
= r1bindex (sendproc
, '/'), "send") == 0) {
792 sendit (invo_name
= sp
, arg
, file
, pushsw
);
797 context_save (); /* save the context file */
800 for (i
= 0; (child_id
= vfork()) == NOTOK
&& i
< 5; i
++)
804 advise (NULL
, "unable to fork, so sending directly...");
807 vec
[vecp
++] = invo_name
;
809 vec
[vecp
++] = "-push";
812 vec
[vecp
++] = *arg
++;
816 execvp (sendproc
, vec
);
817 fprintf (stderr
, "unable to exec ");
822 if (pidwait(child_id
, OK
) == 0)
830 * Translate MIME composition file (call buildmimeproc)
834 buildfile (char **argp
, char *file
)
841 /* allocate space for arguments */
847 args
= (char **) mh_xmalloc((i
+ 2) * sizeof(char *));
850 * For backward compatibility, we need to add -build
851 * if we are using mhn as buildmimeproc
854 if (strcmp (r1bindex (ed
, '/'), "mhn") == 0)
855 args
[i
++] = "-build";
857 /* copy any other arguments */
858 while (argp
&& *argp
)
862 i
= editfile (&ed
, args
, file
, NOUSE
, NULL
, NULL
, NULL
, 0);
865 return (i
? NOTOK
: OK
);
870 * Check if draft is a mhbuild composition file
874 check_draft (char *msgnam
)
877 char buf
[BUFSIZ
], name
[NAMESZ
];
880 if ((fp
= fopen (msgnam
, "r")) == NULL
)
883 switch (state
= m_getfld (state
, name
, buf
, sizeof(buf
), fp
)) {
888 * If draft already contains any of the
889 * Content-XXX fields, then assume it already
892 if (uprf (name
, XXX_FIELD_PRF
)) {
896 while (state
== FLDPLUS
)
897 state
= m_getfld (state
, name
, buf
, sizeof(buf
), fp
);
904 for (bp
= buf
; *bp
; bp
++)
905 if (*bp
!= ' ' && *bp
!= '\t' && *bp
!= '\n') {
910 state
= m_getfld (state
, name
, buf
, sizeof(buf
), fp
);
911 } while (state
== BODY
);
922 # define SASLminc(a) (a)
923 #else /* CYRUS_SASL */
924 # define SASLminc(a) 0
925 #endif /* CYRUS_SASL */
927 static struct swit sendswitches
[] = {
929 { "alias aliasfile", 0 },
933 { "filter filterfile", 0 },
957 { "split seconds", 0 },
971 { "width columns", 0 },
972 #define SVERSIONSW 22
976 #define BITSTUFFSW 24
977 { "dashstuffing", -12 },
978 #define NBITSTUFFSW 25
979 { "nodashstuffing", -14 },
989 { "client host", -6 },
991 { "server host", -6 },
995 { "draftfolder +folder", -6 },
997 { "draftmessage msg", -6 },
999 { "nodraftfolder", -3 },
1001 { "sasl", SASLminc(-4) },
1002 #define SASLMECHSW 37
1003 { "saslmech", SASLminc(-5) },
1005 { "user", SASLminc(-4) },
1006 #define SNDATTACHSW 39
1007 { "attach file", 6 },
1008 #define SNDATTACHFORMAT 40
1009 { "attachformat", 7 },
1014 extern int debugsw
; /* from sendsbr.c */
1022 extern char *altmsg
; /* .. */
1023 extern char *annotext
;
1024 extern char *distfile
;
1028 sendit (char *sp
, char **arg
, char *file
, int pushed
)
1031 char *cp
, buf
[BUFSIZ
], **argp
;
1032 char **arguments
, *vec
[MAXARGS
];
1034 char *attach
= (char *)0; /* attachment header field name */
1035 int attachformat
= 0; /* mhbuild format specifier for
1046 * Make sure these are defined. In particular, we need
1047 * vec[1] to be NULL, in case "arg" is NULL below. It
1048 * doesn't matter what is the value of vec[0], but we
1049 * set it to NULL, to help catch "off-by-one" errors.
1055 * Temporarily copy arg to vec, since the brkstring() call in
1056 * getarguments() will wipe it out before it is merged in.
1057 * Also, we skip the first element of vec, since getarguments()
1058 * skips it. Then we count the number of arguments
1059 * copied. The value of "n" will be one greater than
1060 * this in order to simulate the standard argc/argv.
1065 copyip (arg
, vec
+1, MAXARGS
-1);
1072 * Merge any arguments from command line (now in vec)
1073 * and arguments from profile.
1075 arguments
= getarguments (sp
, n
, vec
, 1);
1087 vecp
= 1; /* we'll get the zero'th element later */
1088 vec
[vecp
++] = "-library";
1089 vec
[vecp
++] = getcpy (m_maildir (""));
1091 while ((cp
= *argp
++)) {
1093 switch (smatch (++cp
, sendswitches
)) {
1095 ambigsw (cp
, sendswitches
);
1098 advise (NULL
, "-%s unknown\n", cp
);
1102 snprintf (buf
, sizeof(buf
), "%s [switches]", sp
);
1103 print_help (buf
, sendswitches
, 1);
1106 print_version (invo_name
);
1117 if (!(cp
= *argp
++) || sscanf (cp
, "%d", &splitsw
) != 1) {
1118 advise (NULL
, "missing argument to %s", argp
[-2]);
1146 debugsw
++; /* fall */
1175 if (!(cp
= *argp
++) || *cp
== '-') {
1176 advise (NULL
, "missing argument to %s", argp
[-2]);
1184 if (!(cp
= *argp
++) || *cp
== '-') {
1185 advise (NULL
, "missing argument to %s", argp
[-2]);
1192 if (!(attach
= *argp
++) || *attach
== '-') {
1193 advise (NULL
, "missing argument to %s", argp
[-2]);
1198 case SNDATTACHFORMAT
:
1199 if (! *argp
|| **argp
== '-')
1200 adios (NULL
, "missing argument to %s", argp
[-1]);
1202 attachformat
= atoi (*argp
);
1203 if (attachformat
< 0 ||
1204 attachformat
> ATTACHFORMATS
- 1) {
1205 advise (NULL
, "unsupported attachformat %d",
1214 advise (NULL
, "usage: %s [switches]", sp
);
1218 /* allow Aliasfile: profile entry */
1219 if ((cp
= context_find ("Aliasfile"))) {
1223 for (ap
= brkstring (dp
, " ", "\n"); ap
&& *ap
; ap
++) {
1224 vec
[vecp
++] = "-alias";
1229 if ((cp
= getenv ("SIGNATURE")) == NULL
|| *cp
== 0)
1230 if ((cp
= context_find ("signature")) && *cp
)
1231 m_putenv ("SIGNATURE", cp
);
1234 snprintf (buf
, sizeof(buf
), "%s/.signature", mypath
);
1235 if ((fp
= fopen (buf
, "r")) != NULL
1236 && fgets (buf
, sizeof(buf
), fp
) != NULL
) {
1238 if (cp
= strchr (buf
, '\n'))
1240 m_putenv ("SIGNATURE", buf
);
1245 if ((annotext
= getenv ("mhannotate")) == NULL
|| *annotext
== 0)
1247 if ((altmsg
= getenv ("mhaltmsg")) == NULL
|| *altmsg
== 0)
1249 if (annotext
&& ((cp
= getenv ("mhinplace")) != NULL
&& *cp
!= 0))
1250 inplace
= atoi (cp
);
1252 if ((cp
= getenv ("mhdist"))
1255 && (distsw
= atoi (cp
))
1256 #endif /* not lint */
1258 vec
[vecp
++] = "-dist";
1259 distfile
= getcpy (m_scratch (altmsg
, invo_name
));
1260 if (link (altmsg
, distfile
) == NOTOK
)
1261 adios (distfile
, "unable to link %s to", altmsg
);
1266 if (altmsg
== NULL
|| stat (altmsg
, &st
) == NOTOK
) {
1271 if ((pushsw
= pushed
))
1274 vec
[0] = r1bindex (postproc
, '/');
1277 if (sendsbr (vec
, vecp
, file
, &st
, 1, attach
, attachformat
) == OK
)
1286 whomfile (char **arg
, char *file
)
1292 context_save (); /* save the context file */
1295 switch (pid
= vfork ()) {
1297 advise ("fork", "unable to");
1302 vec
[vecp
++] = r1bindex (whomproc
, '/');
1306 vec
[vecp
++] = *arg
++;
1309 execvp (whomproc
, vec
);
1310 fprintf (stderr
, "unable to exec ");
1312 _exit (-1); /* NOTREACHED */
1315 return (pidwait (pid
, NOTOK
) & 0377 ? 1 : 0);
1321 * Remove the draft file
1325 removefile (char *drft
)
1327 if (unlink (drft
) == NOTOK
)
1328 adios (drft
, "unable to unlink");