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