anno: Undid the ``preserve argument hack''.
[mmh] / uip / whatnow.c
1 /*
2 ** whatnow.c -- the WhatNow shell
3 **
4 ** This code is Copyright (c) 2002, by the authors of nmh.  See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
7 **
8 **  The inclusion of attachments is eased by
9 **  using the header field name mechanism added to anno and send.
10 **  The header field name for attachments is predefined.
11 **
12 **  Several commands have been added at the whatnow prompt:
13 **
14 **        cd [ directory ]        This option works just like the shell's
15 **                                cd command and lets the user change the
16 **                                directory from which attachments are
17 **                                taken so that long path names are not
18 **                                needed with every file.
19 **
20 **        ls [ ls-options ]       This option works just like the normal
21 **                                ls command and exists to allow the user
22 **                                to verify file names in the directory.
23 **
24 **        pwd                     This option works just like the normal
25 **                                pwd command and exists to allow the user
26 **                                to verify the directory.
27 **
28 **        attach files            This option attaches the named files to
29 **                                the draft.
30 **
31 **        alist [-ln]             This option lists the attachments on the
32 **                                draft.  -l gets long listings, -n gets
33 **                                numbered listings.
34 **
35 **        detach files            This option removes attachments from the
36 **        detach -n numbers       draft.  This can be done by file name or
37 **                                by attachment number.
38 */
39
40 #include <h/mh.h>
41 #include <fcntl.h>
42 #include <signal.h>
43 #include <h/mime.h>
44 #include <h/utils.h>
45
46 static struct swit whatnowswitches[] = {
47 #define EDITRSW  0
48         { "editor editor", 0 },
49 #define NEDITSW  1
50         { "noedit", 0 },
51 #define PRMPTSW  2
52         { "prompt string", 4 },
53 #define VERSIONSW  3
54         { "version", 0 },
55 #define HELPSW  4
56         { "help", 0 },
57         { NULL, 0 }
58 };
59
60 /*
61 ** Options at the "whatnow" prompt
62 */
63 static struct swit aleqs[] = {
64 #define EDITSW  0
65         { "edit [<editor> <switches>]", 0 },
66 #define REFILEOPT  1
67         { "refile [<switches>] +folder", 0 },
68 #define DISPSW  2
69         { "display", 0 },
70 #define LISTSW  3
71         { "list", 0 },
72 #define SENDSW  4
73         { "send [<switches>]", 0 },
74 #define PUSHSW  5
75         { "push [<switches>]", 0 },
76 #define QUITSW  6
77         { "quit", 0 },
78 #define DELETESW  7
79         { "delete", 0 },
80 #define CDCMDSW  8
81         { "cd [directory]", 0 },
82 #define PWDCMDSW  9
83         { "pwd", 0 },
84 #define LSCMDSW  10
85         { "ls", 0 },
86 #define ATTACHCMDSW  11
87         { "attach", 0 },
88 #define DETACHCMDSW  12
89         { "detach [-n]", 2 },
90 #define ALISTCMDSW  13
91         { "alist [-ln] ", 2 },
92         { NULL, 0 }
93 };
94
95 static char *myprompt = "\nWhat now? ";
96
97 /*
98 ** static prototypes
99 */
100 static int editfile(char **, char **, char *, int, struct msgs *,
101         char *, char *, int);
102 static int sendfile(char **, char *, int);
103 static int removefile(char *);
104 static void writelscmd(char *, int, char **);
105 static void writesomecmd(char *buf, int bufsz, char *cmd, char *trailcmd, char **argp);
106 static FILE* popen_in_dir(const char *dir, const char *cmd, const char *type);
107 static int system_in_dir(const char *dir, const char *cmd);
108
109
110 #ifdef HAVE_LSTAT
111 static int copyf(char *, char *);
112 #endif
113
114
115 int
116 main(int argc, char **argv)
117 {
118         int nedit = 0, use = 0;
119         char *cp;
120         char *ed = NULL, *drft = NULL, *msgnam = NULL;
121         char buf[BUFSIZ], prompt[BUFSIZ];
122         char **argp, **arguments;
123         struct stat st;
124         char cwd[MAXPATHLEN + 1];  /* current working directory */
125         char file[MAXPATHLEN + 1];  /* file name buffer */
126         char shell[MAXPATHLEN + 1];  /* shell response buffer */
127         FILE *f;  /* read pointer for bgnd proc */
128         char *l;  /* set on -l to alist  command */
129         int n;  /* set on -n to alist command */
130
131 #ifdef LOCALE
132         setlocale(LC_ALL, "");
133 #endif
134
135         invo_name = mhbasename(argv[0]);
136
137         /* read user profile/context */
138         context_read();
139
140         arguments = getarguments(invo_name, argc, argv, 1);
141         argp = arguments;
142
143         /*
144         ** Get the initial current working directory.
145         */
146
147         if (getcwd(cwd, sizeof (cwd)) == NULL) {
148                 adios("getcwd", "could not get working directory");
149         }
150
151         while ((cp = *argp++)) {
152                 if (*cp == '-') {
153                         switch (smatch(++cp, whatnowswitches)) {
154                         case AMBIGSW:
155                                 ambigsw(cp, whatnowswitches);
156                                 done(1);
157                         case UNKWNSW:
158                                 adios(NULL, "-%s unknown", cp);
159
160                         case HELPSW:
161                                 snprintf(buf, sizeof(buf),
162                                                 "%s [switches] [file]",
163                                                 invo_name);
164                                 print_help(buf, whatnowswitches, 1);
165                                 done(1);
166                         case VERSIONSW:
167                                 print_version(invo_name);
168                                 done(1);
169
170                         case EDITRSW:
171                                 if (!(ed = *argp++) || *ed == '-')
172                                         adios(NULL, "missing argument to %s",
173                                                         argp[-2]);
174                                 nedit = 0;
175                                 continue;
176                         case NEDITSW:
177                                 nedit++;
178                                 continue;
179
180                         case PRMPTSW:
181                                 if (!(myprompt = *argp++) || *myprompt == '-')
182                                         adios(NULL, "missing argument to %s",
183                                                         argp[-2]);
184                                 continue;
185
186                         }
187                 }
188                 if (drft)
189                         adios(NULL, "only one draft at a time!");
190                 else
191                         drft = cp;
192         }
193
194         if ((drft == NULL && (drft = getenv("mhdraft")) == NULL) || *drft == 0)
195                 drft = getcpy(m_draft(seq_cur));
196
197         msgnam = (cp = getenv("mhaltmsg")) && *cp ? getcpy(cp) : NULL;
198
199         if ((cp = getenv("mhuse")) && *cp)
200                 use = atoi(cp);
201
202         if (ed == NULL && ((ed = getenv("mheditor")) == NULL || *ed == 0)) {
203                 ed = NULL;
204                 nedit++;
205         }
206
207         /* start editing the draft, unless -noedit was given */
208         if (!nedit && editfile(&ed, NULL, drft, use, NULL, msgnam, NULL, 1)
209                         < 0)
210                 done(1);
211
212         snprintf(prompt, sizeof(prompt), myprompt, invo_name);
213         for (;;) {
214                 if (!(argp = getans(prompt, aleqs))) {
215                         unlink(altmsglink);
216                         done(1);
217                 }
218                 switch (smatch(*argp, aleqs)) {
219                 case DISPSW:
220                         /* display the msg being replied to or distributed */
221                         if (msgnam) {
222                                 snprintf(buf, sizeof buf, "%s '%s'",
223                                                 lproc, msgnam);
224                                 system(buf);
225                         } else {
226                                 advise(NULL, "no alternate message to display");
227                         }
228                         break;
229
230                 case EDITSW:
231                         /* Call an editor on the draft file */
232                         if (*++argp)
233                                 ed = *argp++;
234                         if (editfile(&ed, argp, drft, NOUSE, NULL,
235                                         msgnam, NULL, 1) == NOTOK)
236                                 done(1);
237                         break;
238
239                 case LISTSW:
240                         /* display the draft file */
241                         snprintf(buf, sizeof buf, "%s '%s'", lproc, drft);
242                         system(buf);
243                         break;
244
245                 case QUITSW:
246                         /* quit */
247                         if (stat(drft, &st) != NOTOK) {
248                                 advise(NULL, "draft left on %s", drft);
249                         }
250                         done(1);
251
252                 case DELETESW:
253                         /* Delete draft and exit */
254                         removefile(drft);
255                         done(1);
256
257                 case PUSHSW:
258                         /* Send draft in background */
259                         if (sendfile(++argp, drft, 1))
260                                 done(1);
261                         break;
262
263                 case SENDSW:
264                         /* Send draft */
265                         sendfile(++argp, drft, 0);
266                         break;
267
268                 case REFILEOPT:
269                         /* Refile the draft */
270                         if (refile(++argp, drft) == 0)
271                                 done(0);
272                         break;
273
274                 case CDCMDSW:
275                         /*
276                         ** Change the working directory for attachments
277                         **
278                         ** Run the directory through the user's shell
279                         ** so that we can take advantage of any syntax
280                         ** that the user is accustomed to.  Read back
281                         ** the absolute path.
282                         */
283
284                         if (*(argp+1) == NULL) {
285                                 sprintf(buf, "$SHELL -c \"cd;pwd\"");
286                         } else {
287                                 writesomecmd(buf, BUFSIZ, "cd", "pwd", argp);
288                         }
289                         if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
290                                 fgets(cwd, sizeof (cwd), f);
291
292                                 if (strchr(cwd, '\n') != NULL)
293                                                 *strchr(cwd, '\n') = '\0';
294
295                                 pclose(f);
296                         } else {
297                                 advise("popen", "could not get directory");
298                         }
299
300                         break;
301
302                 case PWDCMDSW:
303                         /* Print the working directory for attachments */
304                         printf("%s\n", cwd);
305                         break;
306
307                 case LSCMDSW:
308                         /*
309                         ** List files in the current attachment working
310                         ** directory
311                         **
312                         ** Use the user's shell so that we can take
313                         ** advantage of any syntax that the user is
314                         ** accustomed to.
315                         */
316                         writelscmd(buf, sizeof(buf), argp);
317                         system_in_dir(cwd, buf);
318                         break;
319
320                 case ALISTCMDSW:
321                         /*
322                         ** List attachments on current draft.  Options are:
323                         **
324                         ** -l    long listing (full path names)
325                         ** -n    numbers listing
326                         */
327
328                         l = NULL;
329                         n = 0;
330
331                         while (*++argp != NULL) {
332                                 if (strcmp(*argp, "-l") == 0)
333                                         l = "/";
334
335                                 else if (strcmp(*argp, "-n") == 0)
336                                         n = 1;
337
338                                 else if (strcmp(*argp, "-ln") == 0 ||
339                                                 strcmp(*argp, "-nl") == 0) {
340                                         l = "/";
341                                         n = 1;
342                                 } else {
343                                         n = -1;
344                                         break;
345                                 }
346                         }
347
348                         if (n == -1)
349                                 advise(NULL, "usage is alist [-ln].");
350
351                         else
352                                 annolist(drft, attach_hdr, l, n);
353
354                         break;
355
356                 case ATTACHCMDSW:
357                         /*
358                         ** Attach files to current draft.
359                         */
360
361                         if (*(argp+1) == NULL) {
362                                 advise(NULL, "attach command requires file argument(s).");
363                                 break;
364                         }
365
366                         /*
367                         ** Build a command line that causes the user's
368                         ** shell to list the file name arguments.
369                         ** This handles and wildcard expansion, tilde
370                         ** expansion, etc.
371                         */
372                         writelscmd(buf, sizeof(buf), argp);
373
374                         /*
375                         ** Read back the response from the shell,
376                         ** which contains a number of lines with one
377                         ** file name per line.  Remove off the newline.
378                         ** Determine whether we have an absolute or
379                         ** relative path name.  Prepend the current
380                         ** working directory to relative path names.
381                         ** Add the attachment annotation to the draft.
382                         */
383                         if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
384                                 while (fgets(shell, sizeof (shell), f)
385                                                 != NULL) {
386                                         *(strchr(shell, '\n')) = '\0';
387
388                                         if (*shell == '/')
389                                                 annotate(drft, attach_hdr,
390                                                                 shell, 0,
391                                                                 -2, 1, 0);
392                                         else {
393                                                 sprintf(file, "%s/%s", cwd,
394                                                                 shell);
395                                                 annotate(drft, attach_hdr,
396                                                                 file, 0,
397                                                                 -2, 1, 0);
398                                         }
399                                 }
400
401                                 pclose(f);
402                         } else {
403                                 advise("popen", "could not get file from shell");
404                         }
405
406                         break;
407
408                 case DETACHCMDSW:
409                         /*
410                         ** Detach files from current draft.
411                         **
412                         ** Scan the arguments for a -n.  Mixed file
413                         ** names and numbers aren't allowed, so this
414                         ** catches a -n anywhere in the argument list.
415                         */
416
417                         for (n = 0, arguments = argp + 1;
418                                         *arguments != NULL;
419                                         arguments++) {
420                                 if (strcmp(*arguments, "-n") == 0) {
421                                                 n = 1;
422                                                 break;
423                                 }
424                         }
425
426                         /*
427                         ** A -n was found so interpret the arguments as
428                         ** attachment numbers.  Decrement any remaining
429                         ** argument number that is greater than the one
430                         ** just processed after processing each one so
431                         ** that the numbering stays correct.
432                         */
433
434                         if (n == 1) {
435                                 for (arguments = argp + 1;
436                                                 *arguments != NULL;
437                                                 arguments++) {
438                                         if (strcmp(*arguments, "-n") == 0)
439                                                 continue;
440
441                                         if (**arguments != '\0') {
442                                                 n = atoi(*arguments);
443                                                 annotate(drft, attach_hdr,
444                                                                 NULL, 0,
445                                                                 n, 1, 0);
446
447                                                 for (argp = arguments + 1; *argp != NULL; argp++) {
448                                                         if (atoi(*argp) > n) {
449                                                                 if (atoi(*argp) == 1)
450                                                                         *argp = "";
451                                                                 else
452                                                                         sprintf(*argp, "%d", atoi(*argp) - 1);
453                                                         }
454                                                 }
455                                         }
456                                 }
457                         }
458
459                         /*
460                         ** The arguments are interpreted as file names.
461                         ** Run them through the user's shell for wildcard
462                         ** expansion and other goodies.  Do this from
463                         ** the current working directory if the argument
464                         ** is not an absolute path name (does not begin
465                         ** with a /).
466                         **
467                         ** We feed all the file names to the shell at
468                         ** once, otherwise you can't provide a file name
469                         ** with a space in it.
470                         */
471                         writelscmd(buf, sizeof(buf), argp);
472                         if ((f = popen_in_dir(cwd, buf, "r")) != (FILE *)0) {
473                                 while (fgets(shell, sizeof (shell), f)
474                                                 != NULL) {
475                                         *(strchr(shell, '\n')) = '\0';
476                                         annotate(drft, attach_hdr, shell,
477                                                         0, 0, 1, 0);
478                                 }
479                                 pclose(f);
480                         } else {
481                                 advise("popen", "could not get file from shell");
482                         }
483
484                         break;
485
486                 default:
487                         /* Unknown command */
488                         advise(NULL, "say what?");
489                         break;
490                 }
491         }
492         /*NOTREACHED*/
493 }
494
495
496
497 /*
498 ** Build a command line of the form $SHELL -c "cd 'cwd'; cmd argp ... ;
499 ** trailcmd".
500 */
501 static void
502 writesomecmd(char *buf, int bufsz, char *cmd, char *trailcmd, char **argp)
503 {
504         char *cp;
505         /*
506         ** Note that we do not quote -- the argp from the user
507         ** is assumed to be quoted as they desire. (We can't treat
508         ** it as pure literal as that would prevent them using ~,
509         ** wildcards, etc.) The buffer produced by this function
510         ** should be given to popen_in_dir() or system_in_dir() so
511         ** that the current working directory is set correctly.
512         */
513         int ln = snprintf(buf, bufsz, "$SHELL -c \"%s", cmd);
514         /*
515         ** NB that some snprintf() return -1 on overflow rather than the
516         ** new C99 mandated 'number of chars that would have been written'
517         */
518         /*
519         ** length checks here and inside the loop allow for the
520         ** trailing ';', trailcmd, '"' and NUL
521         */
522         int trailln = strlen(trailcmd) + 3;
523         if (ln < 0 || ln + trailln > bufsz)
524                 adios(NULL, "arguments too long");
525
526         cp = buf + ln;
527
528         while (*++argp != NULL) {
529                 ln = strlen(*argp);
530                 /* +1 for leading space */
531                 if (ln + trailln + 1 > bufsz - (cp-buf))
532                         adios(NULL, "arguments too long");
533                 *cp++ = ' ';
534                 memcpy(cp, *argp, ln+1);
535                 cp += ln;
536         }
537         if (*trailcmd) {
538                 *cp++ = ';';
539                 strcpy(cp, trailcmd);
540                 cp += trailln - 3;
541         }
542         *cp++ = '"';
543         *cp = 0;
544 }
545
546 /*
547 ** Build a command line that causes the user's shell to list the file name
548 ** arguments.  This handles and wildcard expansion, tilde expansion, etc.
549 */
550 static void
551 writelscmd(char *buf, int bufsz, char **argp)
552 {
553         writesomecmd(buf, bufsz, "ls", "", argp);
554 }
555
556 /*
557 ** Like system(), but run the command in directory dir.
558 ** This assumes the program is single-threaded!
559 */
560 static int
561 system_in_dir(const char *dir, const char *cmd)
562 {
563         char olddir[BUFSIZ];
564         int r;
565         if (getcwd(olddir, sizeof(olddir)) == 0)
566                 adios("getcwd", "could not get working directory");
567         if (chdir(dir) != 0)
568                 adios("chdir", "could not change working directory");
569         r = system(cmd);
570         if (chdir(olddir) != 0)
571                 adios("chdir", "could not change working directory");
572         return r;
573 }
574
575 /* ditto for popen() */
576 static FILE*
577 popen_in_dir(const char *dir, const char *cmd, const char *type)
578 {
579         char olddir[BUFSIZ];
580         FILE *f;
581         if (getcwd(olddir, sizeof(olddir)) == 0)
582                 adios("getcwd", "could not get working directory");
583         if (chdir(dir) != 0)
584                 adios("chdir", "could not change working directory");
585         f = popen(cmd, type);
586         if (chdir(olddir) != 0)
587                 adios("chdir", "could not change working directory");
588         return f;
589 }
590
591
592 /*
593 ** EDIT
594 */
595
596 static int  reedit = 0;  /* have we been here before? */
597 static char *edsave = NULL;  /* the editor we used previously */
598
599
600 static int
601 editfile(char **ed, char **arg, char *file, int use, struct msgs *mp,
602         char *altmsg, char *cwd, int save_editor)
603 {
604         int pid, status, vecp;
605         char altpath[BUFSIZ], linkpath[BUFSIZ];
606         char *cp, *vec[MAXARGS];
607         struct stat st;
608
609 #ifdef HAVE_LSTAT
610         int slinked = 0;
611 #endif /* HAVE_LSTAT */
612
613         /* Was there a previous edit session? */
614         if (reedit) {
615                 if (!*ed) {  /* no explicit editor */
616                         *ed = edsave;  /* so use the previous one */
617                         if ((cp = mhbasename(*ed)) == NULL)
618                                 cp = *ed;
619
620                         /* unless we've specified it via "editor-next" */
621                         cp = concat(cp, "-next", NULL);
622                         if ((cp = context_find(cp)) != NULL)
623                                 *ed = cp;
624                 }
625         } else {
626                 /* set initial editor */
627                 if (*ed == NULL && (*ed = context_find("editor")) == NULL)
628                         *ed = defaulteditor;
629         }
630
631         if (altmsg) {
632                 if (mp == NULL || *altmsg == '/' || cwd == NULL)
633                         strncpy(altpath, altmsg, sizeof(altpath));
634                 else
635                         snprintf(altpath, sizeof(altpath), "%s/%s",
636                                         mp->foldpath, altmsg);
637                 if (cwd == NULL)
638                         strncpy(linkpath, altmsglink, sizeof(linkpath));
639                 else
640                         snprintf(linkpath, sizeof(linkpath), "%s/%s",
641                                         cwd, altmsglink);
642         }
643
644         if (altmsg) {
645                 unlink(linkpath);
646 #ifdef HAVE_LSTAT
647                 if (link(altpath, linkpath) == NOTOK) {
648                         symlink(altpath, linkpath);
649                         slinked = 1;
650                 } else {
651                         slinked = 0;
652                 }
653 #else /* not HAVE_LSTAT */
654                 link(altpath, linkpath);
655 #endif /* not HAVE_LSTAT */
656         }
657
658         context_save();  /* save the context file */
659         fflush(stdout);
660
661         switch (pid = fork()) {
662         case NOTOK:
663                 advise("fork", "unable to");
664                 status = NOTOK;
665                 break;
666
667         case OK:
668                 if (cwd)
669                         chdir(cwd);
670                 if (altmsg) {
671                         if (mp)
672                                 m_putenv("mhfolder", mp->foldpath);
673                         m_putenv("editalt", altpath);
674                 }
675
676                 vecp = 0;
677                 vec[vecp++] = mhbasename(*ed);
678                 if (arg)
679                         while (*arg)
680                                 vec[vecp++] = *arg++;
681                 vec[vecp++] = file;
682                 vec[vecp] = NULL;
683
684                 execvp(*ed, vec);
685                 fprintf(stderr, "unable to exec ");
686                 perror(*ed);
687                 _exit(-1);
688
689         default:
690                 if ((status = pidwait(pid, NOTOK))) {
691                         if (((status & 0xff00) != 0xff00)
692                                 && (!reedit || (status & 0x00ff))) {
693                                 if (!use && (status & 0xff00) && (rename(file, cp = m_backup (file)) != NOTOK)) {
694                                         advise(NULL, "problems with edit--draft left in %s", cp);
695                                 } else {
696                                         advise(NULL, "problems with edit--%s preserved", file);
697                                 }
698                         }
699                         status = -2;  /* maybe "reedit ? -2 : -1"? */
700                         break;
701                 }
702
703                 reedit++;
704 #ifdef HAVE_LSTAT
705                 if (altmsg && mp && !is_readonly(mp) && (slinked ?
706                                 lstat (linkpath, &st) != NOTOK &&
707                                 S_ISREG(st.st_mode) &&
708                                 copyf(linkpath, altpath) == NOTOK :
709                                 stat(linkpath, &st) != NOTOK &&
710                                 st.st_nlink == 1 &&
711                                 (unlink(altpath) == NOTOK ||
712                                 link(linkpath, altpath) == NOTOK)))
713                         advise(linkpath, "unable to update %s from", altmsg);
714 #else /* HAVE_LSTAT */
715                 if (altmsg && mp && !is_readonly(mp) &&
716                                 stat(linkpath, &st) != NOTOK &&
717                                 st.st_nlink == 1 &&
718                                 (unlink(altpath) == NOTOK ||
719                                 link(linkpath, altpath) == NOTOK))
720                         advise(linkpath, "unable to update %s from", altmsg);
721 #endif /* HAVE_LSTAT */
722         }
723
724         /* normally, we remember which editor we used */
725         if (save_editor)
726                 edsave = getcpy(*ed);
727
728         *ed = NULL;
729         if (altmsg)
730                 unlink(linkpath);
731
732         return status;
733 }
734
735
736 #ifdef HAVE_LSTAT
737 static int
738 copyf(char *ifile, char *ofile)
739 {
740         int i, in, out;
741         char buffer[BUFSIZ];
742
743         if ((in = open(ifile, O_RDONLY)) == NOTOK)
744                 return NOTOK;
745         if ((out = open(ofile, O_WRONLY | O_TRUNC)) == NOTOK) {
746                 admonish(ofile, "unable to open and truncate");
747                 close(in);
748                 return NOTOK;
749         }
750
751         while ((i = read(in, buffer, sizeof(buffer))) > OK)
752                 if (write(out, buffer, i) != i) {
753                         advise(ofile, "may have damaged");
754                         i = NOTOK;
755                         break;
756                 }
757
758         close(in);
759         close(out);
760         return i;
761 }
762 #endif /* HAVE_LSTAT */
763
764
765 /*
766 ** SEND
767 */
768
769 static int
770 sendfile(char **arg, char *file, int pushsw)
771 {
772         pid_t child_id;
773         int i, vecp;
774         char *vec[MAXARGS];
775
776         context_save();  /* save the context file */
777         fflush(stdout);
778
779         for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++)
780                 sleep(5);
781         switch (child_id) {
782         case NOTOK:
783                 advise(NULL, "unable to fork, so sending directly...");
784                 /* fall */
785         case OK:
786                 vecp = 0;
787                 vec[vecp++] = invo_name;
788                 if (pushsw)
789                         vec[vecp++] = "-push";
790                 if (arg)
791                         while (*arg)
792                                 vec[vecp++] = *arg++;
793                 vec[vecp++] = file;
794                 vec[vecp] = NULL;
795
796                 execvp(sendproc, vec);
797                 fprintf(stderr, "unable to exec ");
798                 perror(sendproc);
799                 _exit(-1);
800
801         default:
802                 if (pidwait(child_id, OK) == 0)
803                         done(0);
804                 return 1;
805         }
806 }
807
808
809 /*
810 ** Remove the draft file
811 */
812
813 static int
814 removefile(char *drft)
815 {
816         if (unlink(drft) == NOTOK)
817                 adios(drft, "unable to unlink");
818
819         return OK;
820 }