]>
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/ambigsw.h"
10 #include "sbr/print_version.h"
11 #include "sbr/print_help.h"
12 #include "sbr/error.h"
13 #include "h/dropsbr.h"
14 #include "h/rcvmail.h"
20 #define RCVPACK_SWITCHES \
21 X("mbox", 0, MBOXSW) \
22 X("mmdf", 0, MMDFSW) \
23 X("version", 0, VERSIONSW) \
24 X("help", 0, HELPSW) \
26 #define X(sw, minchars, id) id,
27 DEFINE_SWITCH_ENUM(RCVPACK
);
30 #define X(sw, minchars, id) { sw, minchars, id },
31 DEFINE_SWITCH_ARRAY(RCVPACK
, switches
);
35 * default format in which to save messages
37 static int mbx_style
= MBOX_FORMAT
;
41 main (int argc
, char **argv
)
44 char *cp
, *file
= NULL
, buf
[BUFSIZ
];
45 char **argp
, **arguments
;
47 if (nmh_init(argv
[0], true, false)) { return 1; }
50 arguments
= getarguments (invo_name
, argc
, argv
, 1);
54 while ((cp
= *argp
++)) {
56 switch (smatch (++cp
, switches
)) {
58 ambigsw (cp
, switches
);
61 die("-%s unknown", cp
);
64 snprintf (buf
, sizeof(buf
), "%s [switches] file", invo_name
);
65 print_help (buf
, switches
, 1);
68 print_version(invo_name
);
72 mbx_style
= MBOX_FORMAT
;
75 mbx_style
= MMDF_FORMAT
;
80 die("only one file at a time!");
85 die("%s [switches] file", invo_name
);
89 /* open and lock the file */
90 if ((md
= mbx_open (file
, mbx_style
, getuid(), getgid(), m_gmprot())) == NOTOK
)
93 /* append the message */
94 if (mbx_copy (file
, mbx_style
, md
, fileno(stdin
), NULL
) == NOTOK
) {
99 /* close and unlock the file */
100 if (mbx_close (file
, md
) == NOTOK
)