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