Activated Jon's attachment system by default and steamlined it.
[mmh] / uip / sendsbr.c
1 /*
2 ** sendsbr.c -- routines to help WhatNow/Send along
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
9 #include <h/mh.h>
10 #include <h/signals.h>
11 #include <setjmp.h>
12 #include <signal.h>
13 #include <fcntl.h>
14 #include <h/mime.h>
15 #include <h/tws.h>
16 #include <h/utils.h>
17
18 #ifdef TIME_WITH_SYS_TIME
19 # include <sys/time.h>
20 # include <time.h>
21 #else
22 # ifdef TM_IN_SYS_TIME
23 #  include <sys/time.h>
24 # else
25 #  include <time.h>
26 # endif
27 #endif
28
29 int debugsw = 0;  /* global */
30 int forwsw  = 1;
31 int inplace = 1;
32 int pushsw  = 0;
33 int unique  = 0;
34 int verbsw  = 0;
35
36 char *altmsg   = NULL;  /*  .. */
37 char *annotext = NULL;
38 char *distfile = NULL;
39
40 static jmp_buf env;
41
42 /* name of temp file for body content */
43 static char body_file_name[MAXPATHLEN + 1];
44 /* name of mhbuild composition temporary file */
45 static char composition_file_name[MAXPATHLEN + 1]; 
46 static int field_size;  /* size of header field buffer */
47 static char *field;  /* header field buffer */
48 static FILE *draft_file;  /* draft file pointer */
49 static FILE *body_file;  /* body file pointer */
50 static FILE *composition_file;  /* composition file pointer */
51
52 /*
53 ** external prototypes
54 */
55 int sendsbr(char **, int, char *, struct stat *, int);
56 char *getusername(void);
57
58 /*
59 ** static prototypes
60 */
61 static void armed_done(int) NORETURN;
62 static void alert(char *, int);
63 static int tmp_fd(void);
64 static void anno(int, struct stat *);
65 static void annoaux(int);
66 static int sendaux(char **, int, char *, struct stat *);
67
68 static int attach(char *);
69 static void clean_up_temporary_files(void);
70 static int get_line(void);
71 static void make_mime_composition_file_entry(char *);
72
73
74 /*
75 ** Entry point into (back-end) routines to send message.
76 */
77
78 int
79 sendsbr(char **vec, int vecp, char *drft, struct stat *st, int rename_drft)
80 {
81         int status;
82         char buffer[BUFSIZ], file[BUFSIZ];
83         char *original_draft;  /* name of original draft file */
84         char *p;  /* string pointer for building file name */
85
86         /*
87         ** Save the original name of the draft file.  The name of the
88         ** draft file is changed to a temporary file containing the built
89         ** MIME message if there are attachments.  We need the original
90         ** name so that it can be renamed after the message is sent.
91         */
92
93         original_draft = drft;
94
95         /*
96         ** Convert the draft to a MIME message.
97         ** Use the mhbuild composition file for the draft if there was
98         ** a successful conversion because that now contains the MIME
99         ** message.  A nice side effect of this is that it leaves the
100         ** original draft file untouched so that it can be retrieved
101         ** and modified if desired.
102         */
103         switch (attach(drft)) {
104         case OK:
105                 drft = composition_file_name;
106                 break;
107
108         case NOTOK:
109                 return (NOTOK);
110
111         case DONE:
112                 break;
113         }
114
115         done=armed_done;
116         switch (setjmp(env)) {
117         case OK:
118                 /*
119                 ** If given -push and -unique (which is undocumented), then
120                 ** rename the draft file.  I'm not quite sure why.
121                 */
122                 if (pushsw && unique) {
123                         char *cp = m_mktemp2(drft, invo_name, NULL, NULL);
124                         if (cp == NULL) {
125                                 adios("sendsbr", "unable to create temporary file");
126                         }
127                         if (rename(drft, strncpy(file, cp, sizeof(file)))
128                                         == NOTOK)
129                                 adios(file, "unable to rename %s to", drft);
130                         drft = file;
131                 }
132
133                 status = sendaux(vec, vecp, drft, st) ? NOTOK : OK;
134
135                 /* rename the original draft */
136                 if (rename_drft && status == OK &&
137                                 rename(original_draft, strncpy(buffer,
138                                 m_backup(original_draft), sizeof(buffer)))
139                                 == NOTOK)
140                         advise(buffer, "unable to rename %s to", drft);
141                 break;
142
143         default:
144                 status = DONE;
145                 break;
146         }
147
148         done=exit;
149         if (distfile)
150                 unlink(distfile);
151
152         /*
153         ** Get rid of any temporary files that we created for attachments.
154         ** Also get rid of the renamed composition file that mhbuild
155         ** leaves as a turd.  It looks confusing, but we use the body
156         ** file name to help build the renamed composition file name.
157         */
158
159         if (drft == composition_file_name) {
160                 clean_up_temporary_files();
161
162                 if (strlen(composition_file_name) >=
163                                 sizeof (composition_file_name) - 6)
164                         advise(NULL, "unable to remove original composition file.");
165
166                 else {
167                         if ((p = strrchr(composition_file_name, '/')) == NULL)
168                                 p = composition_file_name;
169                         else
170                                 p++;
171
172                         strcpy(body_file_name, p);
173                         *p++ = ',';
174                         strcpy(p, body_file_name);
175                         strcat(p, ".orig");
176
177                         unlink(composition_file_name);
178                 }
179         }
180
181         return status;
182 }
183
184 static int
185 attach(char *draft_file_name)
186 {
187         char buf[MAXPATHLEN + 6];  /* miscellaneous buffer */
188         int c;  /* current character for body copy */
189         int has_attachment;  /* draft has at least one attachment */
190         int has_body;  /* draft has a message body */
191         int non_ascii; /* msg body contains non-ASCII chars */
192         int length;  /* length of attachment header field name */
193         char *p;  /* miscellaneous string pointer */
194
195         /*
196         ** Open up the draft file.
197         */
198
199         if ((draft_file = fopen(draft_file_name, "r")) == (FILE *)0)
200                 adios(NULL, "can't open draft file `%s'.",
201                                 draft_file_name);
202
203         /*
204         **  Allocate a buffer to hold the header components as they're read in.
205         **  This buffer might need to be quite large, so we grow it as needed.
206         */
207
208         field = (char *)mh_xmalloc(field_size = 256);
209
210         /*
211         ** Scan the draft file for an attachment header field name.
212         ** The existence of one indicates that the
213         ** draft has attachments.  Bail out if there are no attachments
214         ** because we're done.  Read to the end of the headers even if
215         ** we have no attachments.
216         */
217
218         length = strlen(attach_hdr);
219
220         has_attachment = 0;
221
222         while (get_line() != EOF && *field != '\0' && *field != '-')
223                 if (strncasecmp(field, attach_hdr, length) == 0 &&
224                                 field[length] == ':')
225                         has_attachment = 1;
226
227         /*
228         ** We have at least one attachment.  Look for at least one
229         ** non-blank line in the body of the message which indicates
230         ** content in the body.
231         ** Check if body contains at least one non-blank (= not empty)
232         ** and if it contains any non-ASCII chars (= need MIME).
233         */
234
235         has_body = 0;
236         non_ascii = 0;
237
238         while (get_line() != EOF) {
239                 for (p = field; *p != '\0'; p++) {
240                         if (*p != ' ' && *p != '\t') {
241                                 has_body = 1;
242                         }
243                         if (*p > 127 || *p < 0) {
244                                 non_ascii = 1;
245                         }
246                 }
247                 if (has_body && non_ascii)
248                         break;
249         }
250
251         /*
252         ** Bail out if there are no attachments and only ASCII text.
253         ** This means we don't need to convert it to MIME.
254         */
255         if (!has_attachment && non_ascii==0) {
256                 return DONE;
257         }
258
259         /*
260         ** Else: mimify
261         */
262
263         /* Make names for the temporary files.  */
264         strncpy(body_file_name,
265                         m_mktemp(toabsdir(invo_name), NULL, NULL),
266                         sizeof (body_file_name));
267         strncpy(composition_file_name,
268                         m_mktemp(toabsdir(invo_name), NULL, NULL),
269                         sizeof (composition_file_name));
270
271         if (has_body)
272                 body_file = fopen(body_file_name, "w");
273
274         composition_file = fopen(composition_file_name, "w");
275
276         if ((has_body && body_file == (FILE *)0) ||
277                         composition_file == (FILE *)0) {
278                 clean_up_temporary_files();
279                 adios(NULL, "unable to open all of the temporary files.");
280         }
281
282         /*
283         ** Start at the beginning of the draft file.  Copy all
284         ** non-attachment header fields to the temporary composition file.
285         ** Then add the dashed line separator.
286         */
287         rewind(draft_file);
288         while (get_line() != EOF && *field != '\0' && *field != '-')
289                 if (strncasecmp(field, attach_hdr, length) != 0 ||
290                                 field[length] != ':')
291                         fprintf(composition_file, "%s\n", field);
292         fputs("--------\n", composition_file);
293
294         /*
295         ** Copy the message body to a temporary file.
296         */
297         if (has_body) {
298                 while ((c = getc(draft_file)) != EOF)
299                                 putc(c, body_file);
300                 fclose(body_file);
301         }
302
303         /*
304         ** Add a mhbuild MIME composition file line for the body if
305         ** there was one.
306         */
307         if (has_body) {
308                 /* old: make_mime_composition_file_entry(body_file_name); */
309                 /* charset will be discovered/guessed by buildmimeproc */
310                 fprintf(composition_file, "#text/plain %s\n", body_file_name);
311         }
312
313         /*
314         ** Now, go back to the beginning of the draft file and look for
315         ** header fields that specify attachments.  Add a mhbuild MIME
316         ** composition file for each.
317         */
318         rewind(draft_file);
319         while (get_line() != EOF && *field != '\0' && *field != '-') {
320                 if (strncasecmp(field, attach_hdr, length) == 0 &&
321                                 field[length] == ':') {
322                         for (p = field + length + 1; *p == ' ' || *p == '\t';
323                                         p++)
324                                 ;
325                         make_mime_composition_file_entry(p);
326                 }
327         }
328
329         fclose(composition_file);
330
331         /*
332         ** We're ready to roll!  Run mhbuild on the composition file.
333         ** Note that mhbuild is in the context as buildmimeproc.
334         */
335         sprintf(buf, "%s %s", buildmimeproc, composition_file_name);
336
337         if (system(buf) != 0) {
338                 clean_up_temporary_files();
339                 return (NOTOK);
340         }
341
342         return (OK);
343 }
344
345 static void
346 clean_up_temporary_files(void)
347 {
348         unlink(body_file_name);
349         unlink(composition_file_name);
350
351         return;
352 }
353
354 static int
355 get_line(void)
356 {
357         int c;  /* current character */
358         int n;  /* number of bytes in buffer */
359         char *p;  /* buffer pointer */
360
361         /*
362         ** Get a line from the input file, growing the field buffer as
363         ** needed.  We do this so that we can fit an entire line in the
364         ** buffer making it easy to do a string comparison on both the
365         ** field name and the field body which might be a long path name.
366         */
367
368         for (n = 0, p = field; (c = getc(draft_file)) != EOF; *p++ = c) {
369                 if (c == '\n' && (c = getc(draft_file)) != ' ' && c != '\t') {
370                         ungetc(c, draft_file);
371                         c = '\n';
372                         break;
373                 }
374
375                 if (++n >= field_size - 1) {
376                         field = (char *)mh_xrealloc((void *)field, field_size += 256);
377
378                         p = field + n - 1;
379                 }
380         }
381
382         /* NUL-terminate the field. */
383         *p = '\0';
384
385         return (c);
386 }
387
388 static void
389 make_mime_composition_file_entry(char *file_name)
390 {
391         int binary;  /* binary character found flag */
392         int c;  /* current character */
393         char *content_type;  /* mime content type */
394         FILE *fp;  /* content and pipe file pointer */
395         struct node *np;  /* context scan node pointer */
396         char *p;  /* miscellaneous string pointer */
397
398         content_type = NULL;
399
400         /*
401         ** Check the file name for a suffix.  Scan the context for that
402         ** suffix on a mhshow-suffix- entry.  We use these entries to
403         ** be compatible with mhshow, and there's no reason to make the
404         ** user specify each suffix twice.  Context entries of the form
405         ** "mhshow-suffix-contenttype" in the name have the suffix in
406         ** the field, including the dot.
407         */
408
409         if ((p = strrchr(file_name, '.')) != NULL) {
410                 for (np = m_defs; np; np = np->n_next) {
411                         if (strncasecmp(np->n_name, "mhshow-suffix-", 14) == 0
412                                         && mh_strcasecmp(p, np->n_field) == 0)
413                                         {
414                                 content_type = np->n_name + 14;
415                                 break;
416                         }
417                 }
418         }
419
420         /*
421         ** No content type was found, either because there was no matching
422         ** entry in the context or because the file name has no suffix.
423         ** Open the file and check for non-ASCII characters.  Choose the
424         ** content type based on this check.
425         */
426
427         if (content_type == NULL) {
428                 if ((fp = fopen(file_name, "r")) == (FILE *)0) {
429                         clean_up_temporary_files();
430                         adios(NULL, "unable to access file \"%s\"",
431                                         file_name);
432                 }
433
434                 binary = 0;
435
436                 while ((c = getc(fp)) != EOF) {
437                         if (c > 127 || c < 0) {
438                                 binary = 1;
439                                 break;
440                         }
441                 }
442
443                 fclose(fp);
444
445                 content_type = binary ?
446                                 "application/octet-stream" : "text/plain";
447         }
448
449         /*
450         ** Make sure that the attachment file exists and is readable.
451         ** Append a mhbuild directive to the draft file.  This starts with
452         ** the content type.  Append a file name attribute and a private
453         ** x-unix-mode attribute.  Also append a description obtained
454         ** (if possible) by running the "file" command on the file.
455         */
456
457         if (access(file_name, R_OK) != 0) {
458                 clean_up_temporary_files();
459                 adios(NULL, "unable to access file \"%s\"", file_name);
460         }
461
462
463         if (stringdex(toabsdir(invo_name), file_name) == 0) {
464                 /*
465                 ** Content had been placed by send into a temp file.
466                 ** Don't generate Content-Disposition header, because
467                 ** it confuses Microsoft Outlook, Build 10.0.6626, at
468                 ** least.
469                 */
470                 fprintf(composition_file, "#%s <>", content_type);
471         } else {
472                 /*
473                 ** Suppress Content-Id, insert simple
474                 ** Content-Disposition.
475                 */
476                 fprintf(composition_file,
477                         "#%s; name=\"%s\" <>{attachment}",
478                         content_type,
479                         ((p = strrchr(file_name, '/')) == NULL) ?
480                         file_name : p + 1);
481         }
482
483         /* Finish up with the file name. */
484         fprintf(composition_file, " %s\n", file_name);
485
486         return;
487 }
488
489 /*
490 ** Annotate original message, and
491 ** call `postproc' to send message.
492 */
493
494 static int
495 sendaux(char **vec, int vecp, char *drft, struct stat *st)
496 {
497         pid_t child_id;
498         int i, status, fd, fd2;
499         char backup[BUFSIZ], buf[BUFSIZ];
500
501         fd = pushsw ? tmp_fd() : NOTOK;
502         fd2 = NOTOK;
503
504         vec[vecp++] = drft;
505         if (annotext) {
506                 if ((fd2 = tmp_fd()) != NOTOK) {
507                         vec[vecp++] = "-idanno";
508                         snprintf(buf, sizeof(buf), "%d", fd2);
509                         vec[vecp++] = buf;
510                 } else {
511                         admonish(NULL, "unable to create file for annotation list");
512                 }
513         }
514         if (distfile && distout(drft, distfile, backup) == NOTOK)
515                 done(1);
516         vec[vecp] = NULL;
517
518         for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++)
519                 sleep(5);
520
521         switch (child_id) {
522         case -1:
523                 /* oops -- fork error */
524                 adios("fork", "unable to");
525                 break;  /* NOT REACHED */
526
527         case 0:
528                 /*
529                 ** child process -- send it
530                 **
531                 ** If fd is ok, then we are pushing and fd points to temp
532                 ** file, so capture anything on stdout and stderr there.
533                 */
534                 if (fd != NOTOK) {
535                         dup2(fd, fileno(stdout));
536                         dup2(fd, fileno(stderr));
537                         close(fd);
538                 }
539                 execvp(postproc, vec);
540                 fprintf(stderr, "unable to exec ");
541                 perror(postproc);
542                 _exit(-1);
543                 break;  /* NOT REACHED */
544
545         default:
546                 /*
547                 ** parent process -- wait for it
548                 */
549                 if ((status = pidwait(child_id, NOTOK)) == OK) {
550                         if (annotext && fd2 != NOTOK)
551                                 anno(fd2, st);
552                 } else {
553                         /*
554                         ** If postproc failed, and we have good fd (which
555                         ** means we pushed), then mail error message
556                         ** (and possibly the draft) back to the user.
557                         */
558                         if (fd != NOTOK) {
559                                 alert(drft, fd);
560                                 close(fd);
561                         } else {
562                                 advise(NULL, "message not delivered to anyone");
563                         }
564                         if (annotext && fd2 != NOTOK)
565                                 close(fd2);
566                         if (distfile) {
567                                 unlink(drft);
568                                 if (rename(backup, drft) == NOTOK)
569                                         advise(drft, "unable to rename %s to",
570                                                         backup);
571                         }
572                 }
573                 break;
574         }
575
576         return status;
577 }
578
579
580 /*
581 ** Mail error notification (and possibly a copy of the
582 ** message) back to the user, using the mailproc
583 */
584
585 static void
586 alert(char *file, int out)
587 {
588         pid_t child_id;
589         int i, in;
590         char buf[BUFSIZ];
591
592         for (i = 0; (child_id = fork()) == NOTOK && i < 5; i++)
593                 sleep(5);
594
595         switch (child_id) {
596         case NOTOK:
597                 /* oops -- fork error */
598                 advise("fork", "unable to");
599
600         case OK:
601                 /* child process -- send it */
602                 SIGNAL(SIGHUP, SIG_IGN);
603                 SIGNAL(SIGINT, SIG_IGN);
604                 SIGNAL(SIGQUIT, SIG_IGN);
605                 SIGNAL(SIGTERM, SIG_IGN);
606                 if (forwsw) {
607                         if ((in = open(file, O_RDONLY)) == NOTOK) {
608                                 admonish(file, "unable to re-open");
609                         } else {
610                                 lseek(out, (off_t) 0, SEEK_END);
611                                 strncpy(buf, "\nMessage not delivered to anyone.\n", sizeof(buf));
612                                 write(out, buf, strlen(buf));
613                                 strncpy(buf, "\n------- Unsent Draft\n\n", sizeof(buf));
614                                 write(out, buf, strlen(buf));
615                                 cpydgst(in, out, file, "temporary file");
616                                 close(in);
617                                 strncpy(buf, "\n------- End of Unsent Draft\n", sizeof(buf));
618                                 write(out, buf, strlen(buf));
619                                 if (rename(file, strncpy(buf, m_backup(file), sizeof(buf))) == NOTOK)
620                                         admonish(buf, "unable to rename %s to", file);
621                         }
622                 }
623                 lseek(out, (off_t) 0, SEEK_SET);
624                 dup2(out, fileno(stdin));
625                 close(out);
626                 /* create subject for error notification */
627                 snprintf(buf, sizeof(buf), "send failed on %s",
628                                 forwsw ? "enclosed draft" : file);
629
630                 execlp(mailproc, mhbasename(mailproc), getusername(),
631                                 "-subject", buf, NULL);
632                 fprintf(stderr, "unable to exec ");
633                 perror(mailproc);
634                 _exit(-1);
635
636         default:  /* no waiting... */
637                 break;
638         }
639 }
640
641
642 static int
643 tmp_fd(void)
644 {
645         int fd;
646         char *tfile = NULL;
647
648         tfile = m_mktemp2(NULL, invo_name, &fd, NULL);
649         if (tfile == NULL) return NOTOK;
650         fchmod(fd, 0600);
651
652         if (debugsw)
653                 advise(NULL, "temporary file %s selected", tfile);
654         else
655                 if (unlink(tfile) == NOTOK)
656                         advise(tfile, "unable to remove");
657
658         return fd;
659 }
660
661
662 static void
663 anno(int fd, struct stat *st)
664 {
665         pid_t child_id;
666         sigset_t set, oset;
667         static char *cwd = NULL;
668         struct stat st2;
669
670         if (altmsg && (stat(altmsg, &st2) == NOTOK ||
671                         st->st_mtime != st2.st_mtime ||
672                         st->st_dev != st2.st_dev ||
673                         st->st_ino != st2.st_ino)) {
674                 if (debugsw)
675                         admonish(NULL, "$mhaltmsg mismatch");
676                 return;
677         }
678
679         child_id = debugsw ? NOTOK : fork();
680         switch (child_id) {
681         case NOTOK:  /* oops */
682                 if (!debugsw)
683                         advise(NULL, "unable to fork, so doing annotations by hand...");
684                 if (cwd == NULL)
685                         cwd = getcpy(pwd());
686
687         case OK:
688                 /* block a few signals */
689                 sigemptyset(&set);
690                 sigaddset(&set, SIGHUP);
691                 sigaddset(&set, SIGINT);
692                 sigaddset(&set, SIGQUIT);
693                 sigaddset(&set, SIGTERM);
694                 SIGPROCMASK(SIG_BLOCK, &set, &oset);
695
696                 annoaux(fd);
697                 if (child_id == OK)
698                         _exit(0);
699
700                 /* reset the signal mask */
701                 SIGPROCMASK(SIG_SETMASK, &oset, &set);
702
703                 chdir(cwd);
704                 break;
705
706         default:  /* no waiting... */
707                 close(fd);
708                 break;
709         }
710 }
711
712
713 static void
714 annoaux(int fd)
715 {
716         int fd2, fd3, msgnum;
717         char *cp, *folder, *maildir;
718         char buffer[BUFSIZ], **ap;
719         FILE *fp;
720         struct msgs *mp;
721
722         if ((folder = getenv("mhfolder")) == NULL || *folder == 0) {
723                 if (debugsw)
724                         admonish(NULL, "$mhfolder not set");
725                 return;
726         }
727         maildir = toabsdir(folder);
728         if (chdir(maildir) == NOTOK) {
729                 if (debugsw)
730                         admonish(maildir, "unable to change directory to");
731                 return;
732         }
733         if (!(mp = folder_read(folder))) {
734                 if (debugsw)
735                         admonish(NULL, "unable to read folder %s", folder);
736                 return;
737         }
738
739         /* check for empty folder */
740         if (mp->nummsg == 0) {
741                 if (debugsw)
742                         admonish(NULL, "no messages in %s", folder);
743                 goto oops;
744         }
745
746         if ((cp = getenv("mhmessages")) == NULL || *cp == 0) {
747                 if (debugsw)
748                         admonish(NULL, "$mhmessages not set");
749                 goto oops;
750         }
751         if (!debugsw  /* MOBY HACK... */
752                         && pushsw
753                         && (fd3 = open("/dev/null", O_RDWR)) != NOTOK
754                         && (fd2 = dup(fileno(stderr))) != NOTOK) {
755                 dup2(fd3, fileno(stderr));
756                 close(fd3);
757         }
758         else
759                 fd2 = NOTOK;
760         for (ap = brkstring(cp = getcpy(cp), " ", NULL); *ap; ap++)
761                 m_convert(mp, *ap);
762         free(cp);
763         if (fd2 != NOTOK)
764                 dup2(fd2, fileno(stderr));
765         if (mp->numsel == 0) {
766                 if (debugsw)
767                         admonish(NULL, "no messages to annotate");
768                 goto oops;
769         }
770
771         lseek(fd, (off_t) 0, SEEK_SET);
772         if ((fp = fdopen(fd, "r")) == NULL) {
773                 if (debugsw)
774                         admonish(NULL, "unable to fdopen annotation list");
775                 goto oops;
776         }
777         cp = NULL;
778         while (fgets(buffer, sizeof(buffer), fp) != NULL)
779                 cp = add(buffer, cp);
780         fclose(fp);
781
782         if (debugsw)
783                 advise(NULL, "annotate%s with %s: \"%s\"",
784                                 inplace ? " inplace" : "", annotext, cp);
785         for (msgnum = mp->lowsel; msgnum <= mp->hghsel; msgnum++) {
786                 if (is_selected(mp, msgnum)) {
787                         if (debugsw)
788                                 advise(NULL, "annotate message %d", msgnum);
789                         annotate(m_name (msgnum), annotext, cp, inplace,
790                                         1, -2, 0);
791                 }
792         }
793
794         free(cp);
795
796 oops:
797         folder_free(mp);  /* free folder/message structure */
798 }
799
800
801 static void
802 armed_done(int status)
803 {
804         longjmp(env, status ? status : NOTOK);
805
806         exit(status);
807 }