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