]>
diplodocus.org Git - nmh/blob - uip/rcvpack.c
58fe40402cc23dc1d595076700473e773763bae4
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/print_help.h"
10 #include "sbr/error.h"
11 #include "h/dropsbr.h"
12 #include "h/rcvmail.h"
18 #define RCVPACK_SWITCHES \
19 X("mbox", 0, MBOXSW) \
20 X("mmdf", 0, MMDFSW) \
21 X("version", 0, VERSIONSW) \
22 X("help", 0, HELPSW) \
24 #define X(sw, minchars, id) id,
25 DEFINE_SWITCH_ENUM(RCVPACK
);
28 #define X(sw, minchars, id) { sw, minchars, id },
29 DEFINE_SWITCH_ARRAY(RCVPACK
, switches
);
33 * default format in which to save messages
35 static int mbx_style
= MBOX_FORMAT
;
39 main (int argc
, char **argv
)
42 char *cp
, *file
= NULL
, buf
[BUFSIZ
];
43 char **argp
, **arguments
;
45 if (nmh_init(argv
[0], true, false)) { return 1; }
48 arguments
= getarguments (invo_name
, argc
, argv
, 1);
52 while ((cp
= *argp
++)) {
54 switch (smatch (++cp
, switches
)) {
56 ambigsw (cp
, switches
);
59 die("-%s unknown", cp
);
62 snprintf (buf
, sizeof(buf
), "%s [switches] file", invo_name
);
63 print_help (buf
, switches
, 1);
66 print_version(invo_name
);
70 mbx_style
= MBOX_FORMAT
;
73 mbx_style
= MMDF_FORMAT
;
78 die("only one file at a time!");
83 die("%s [switches] file", invo_name
);
87 /* open and lock the file */
88 if ((md
= mbx_open (file
, mbx_style
, getuid(), getgid(), m_gmprot())) == NOTOK
)
91 /* append the message */
92 if (mbx_copy (file
, mbx_style
, md
, fileno(stdin
), NULL
) == NOTOK
) {
97 /* close and unlock the file */
98 if (mbx_close (file
, md
) == NOTOK
)