Replace done with exit at uip
[mmh] / uip / rcvpack.c
1 /*
2 ** rcvpack.c -- append message to a file
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/dropsbr.h>
11 #include <h/rcvmail.h>
12 #include <h/tws.h>
13
14 static struct swit switches[] = {
15 #define VERSIONSW  0
16         { "Version", 0 },
17 #define HELPSW  1
18         { "help", 0 },
19         { NULL, 0 }
20 };
21
22
23 int
24 main(int argc, char **argv)
25 {
26         int md;
27         char *cp, *file = NULL, buf[BUFSIZ];
28         char **argp, **arguments;
29
30         setlocale(LC_ALL, "");
31         invo_name = mhbasename(argv[0]);
32
33         /* read user profile/context */
34         context_read();
35
36         arguments = getarguments(invo_name, argc, argv, 1);
37         argp = arguments;
38
39         /* parse arguments */
40         while ((cp = *argp++)) {
41                 if (*cp == '-') {
42                         switch (smatch(++cp, switches)) {
43                         case AMBIGSW:
44                                 ambigsw(cp, switches);
45                                 exit(1);
46                         case UNKWNSW:
47                                 adios(NULL, "-%s unknown", cp);
48
49                         case HELPSW:
50                                 snprintf(buf, sizeof(buf),
51                                                 "%s [switches] file",
52                                                 invo_name);
53                                 print_help(buf, switches, 1);
54                                 exit(0);
55                         case VERSIONSW:
56                                 print_version(invo_name);
57                                 exit(0);
58                         }
59                 }
60                 if (file)
61                         adios(NULL, "only one file at a time!");
62                 else
63                         file = cp;
64         }
65
66         /* copy stdin to stdout, converting rfc822 message to mbox */
67         if (!file) {
68                 if (mbox_copy(fileno(stdout), fileno(stdin)) == NOTOK) {
69                         exit(RCV_MBX);
70                 }
71                 exit(RCV_MOK);
72                 return 1;
73         }
74
75         /* open and lock the file */
76         if ((md = mbox_open(file, getuid(), getgid(), m_gmprot()))
77                         == NOTOK)
78                 exit(RCV_MBX);
79
80         /* append the message */
81         if (mbox_copy(md, fileno(stdin)) == NOTOK) {
82                 mbox_close(file, md);
83                 exit(RCV_MBX);
84         }
85
86         /* close and unlock the file */
87         if (mbox_close(file, md) == NOTOK)
88                 exit(RCV_MBX);
89
90         exit(RCV_MOK);
91         return 1;
92 }