]>
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/smatch.h"
10 #include "sbr/ambigsw.h"
11 #include "sbr/print_version.h"
12 #include "sbr/print_help.h"
13 #include "sbr/error.h"
14 #include "h/dropsbr.h"
15 #include "h/rcvmail.h"
21 #define RCVPACK_SWITCHES \
22 X("mbox", 0, MBOXSW) \
23 X("mmdf", 0, MMDFSW) \
24 X("version", 0, VERSIONSW) \
25 X("help", 0, HELPSW) \
27 #define X(sw, minchars, id) id,
28 DEFINE_SWITCH_ENUM(RCVPACK
);
31 #define X(sw, minchars, id) { sw, minchars, id },
32 DEFINE_SWITCH_ARRAY(RCVPACK
, switches
);
36 * default format in which to save messages
38 static int mbx_style
= MBOX_FORMAT
;
42 main (int argc
, char **argv
)
45 char *cp
, *file
= NULL
, buf
[BUFSIZ
];
46 char **argp
, **arguments
;
48 if (nmh_init(argv
[0], true, false)) { return 1; }
51 arguments
= getarguments (invo_name
, argc
, argv
, 1);
55 while ((cp
= *argp
++)) {
57 switch (smatch (++cp
, switches
)) {
59 ambigsw (cp
, switches
);
62 die("-%s unknown", cp
);
65 snprintf (buf
, sizeof(buf
), "%s [switches] file", invo_name
);
66 print_help (buf
, switches
, 1);
69 print_version(invo_name
);
73 mbx_style
= MBOX_FORMAT
;
76 mbx_style
= MMDF_FORMAT
;
81 die("only one file at a time!");
86 die("%s [switches] file", invo_name
);
90 /* open and lock the file */
91 if ((md
= mbx_open (file
, mbx_style
, getuid(), getgid(), m_gmprot())) == NOTOK
)
94 /* append the message */
95 if (mbx_copy (file
, mbx_style
, md
, fileno(stdin
), NULL
) == NOTOK
) {
100 /* close and unlock the file */
101 if (mbx_close (file
, md
) == NOTOK
)