]> diplodocus.org Git - nmh/blob - uip/rcvpack.c
Reverted commit 9a4b4a3d3b27fe4a7ff6d0b8724ce1c06b5917eb.
[nmh] / uip / rcvpack.c
1
2 /*
3 * rcvpack.c -- append message to a file
4 *
5 * This code is Copyright (c) 2002, by the authors of nmh. See the
6 * COPYRIGHT file in the root directory of the nmh distribution for
7 * complete copyright information.
8 */
9
10 #include <h/mh.h>
11 #include <h/dropsbr.h>
12 #include <h/rcvmail.h>
13 #include <h/tws.h>
14 #include <h/mts.h>
15
16 #define RCVPACK_SWITCHES \
17 X("mbox", 0, MBOXSW) \
18 X("mmdf", 0, MMDFSW) \
19 X("version", 0, VERSIONSW) \
20 X("help", 0, HELPSW) \
21
22 #define X(sw, minchars, id) id,
23 DEFINE_SWITCH_ENUM(RCVPACK);
24 #undef X
25
26 #define X(sw, minchars, id) { sw, minchars, id },
27 DEFINE_SWITCH_ARRAY(RCVPACK, switches);
28 #undef X
29
30 /*
31 * default format in which to save messages
32 */
33 static int mbx_style = MBOX_FORMAT;
34
35
36 int
37 main (int argc, char **argv)
38 {
39 int md;
40 char *cp, *file = NULL, buf[BUFSIZ];
41 char **argp, **arguments;
42
43 if (nmh_init(argv[0], 2)) { return 1; }
44
45 mts_init ();
46 arguments = getarguments (invo_name, argc, argv, 1);
47 argp = arguments;
48
49 /* parse arguments */
50 while ((cp = *argp++)) {
51 if (*cp == '-') {
52 switch (smatch (++cp, switches)) {
53 case AMBIGSW:
54 ambigsw (cp, switches);
55 done (1);
56 case UNKWNSW:
57 adios (NULL, "-%s unknown", cp);
58
59 case HELPSW:
60 snprintf (buf, sizeof(buf), "%s [switches] file", invo_name);
61 print_help (buf, switches, 1);
62 done (0);
63 case VERSIONSW:
64 print_version(invo_name);
65 done (0);
66
67 case MBOXSW:
68 mbx_style = MBOX_FORMAT;
69 continue;
70 case MMDFSW:
71 mbx_style = MMDF_FORMAT;
72 continue;
73 }
74 }
75 if (file)
76 adios (NULL, "only one file at a time!");
77 else
78 file = cp;
79 }
80
81 if (!file)
82 adios (NULL, "%s [switches] file", invo_name);
83
84 rewind (stdin);
85
86 /* open and lock the file */
87 if ((md = mbx_open (file, mbx_style, getuid(), getgid(), m_gmprot())) == NOTOK)
88 done (RCV_MBX);
89
90 /* append the message */
91 if (mbx_copy (file, mbx_style, md, fileno(stdin), 1, NULL, 0) == NOTOK) {
92 mbx_close (file, md);
93 done (RCV_MBX);
94 }
95
96 /* close and unlock the file */
97 if (mbx_close (file, md) == NOTOK)
98 done (RCV_MBX);
99
100 done (RCV_MOK);
101 return 1;
102 }