]>
diplodocus.org Git - nmh/blob - uip/rcvpack.c
1 /* rcvpack.c -- append message to a file
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.
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/rcvmail.h"
23 #define RCVPACK_SWITCHES \
24 X("mbox", 0, MBOXSW) \
25 X("mmdf", 0, MMDFSW) \
26 X("version", 0, VERSIONSW) \
27 X("help", 0, HELPSW) \
29 #define X(sw, minchars, id) id,
30 DEFINE_SWITCH_ENUM(RCVPACK
);
33 #define X(sw, minchars, id) { sw, minchars, id },
34 DEFINE_SWITCH_ARRAY(RCVPACK
, switches
);
38 * default format in which to save messages
40 static int mbx_style
= MBOX_FORMAT
;
44 main (int argc
, char **argv
)
47 char *cp
, *file
= NULL
, buf
[BUFSIZ
];
48 char **argp
, **arguments
;
50 if (nmh_init(argv
[0], true, false)) { return 1; }
53 arguments
= getarguments (invo_name
, argc
, argv
, 1);
57 while ((cp
= *argp
++)) {
59 switch (smatch (++cp
, switches
)) {
61 ambigsw (cp
, switches
);
64 die("-%s unknown", cp
);
67 snprintf (buf
, sizeof(buf
), "%s [switches] file", invo_name
);
68 print_help (buf
, switches
, 1);
71 print_version(invo_name
);
75 mbx_style
= MBOX_FORMAT
;
78 mbx_style
= MMDF_FORMAT
;
83 die("only one file at a time!");
88 die("%s [switches] file", invo_name
);
92 /* open and lock the file */
93 if ((md
= mbx_open (file
, mbx_style
, getuid(), getgid(), m_gmprot())) == NOTOK
)
96 /* append the message */
97 if (mbx_copy (file
, mbx_style
, md
, fileno(stdin
), NULL
) == NOTOK
) {
102 /* close and unlock the file */
103 if (mbx_close (file
, md
) == NOTOK
)