]>
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/print_version.h"
10 #include "sbr/print_help.h"
11 #include "sbr/error.h"
12 #include "h/dropsbr.h"
13 #include "h/rcvmail.h"
19 #define RCVPACK_SWITCHES \
20 X("mbox", 0, MBOXSW) \
21 X("mmdf", 0, MMDFSW) \
22 X("version", 0, VERSIONSW) \
23 X("help", 0, HELPSW) \
25 #define X(sw, minchars, id) id,
26 DEFINE_SWITCH_ENUM(RCVPACK
);
29 #define X(sw, minchars, id) { sw, minchars, id },
30 DEFINE_SWITCH_ARRAY(RCVPACK
, switches
);
34 * default format in which to save messages
36 static int mbx_style
= MBOX_FORMAT
;
40 main (int argc
, char **argv
)
43 char *cp
, *file
= NULL
, buf
[BUFSIZ
];
44 char **argp
, **arguments
;
46 if (nmh_init(argv
[0], true, false)) { return 1; }
49 arguments
= getarguments (invo_name
, argc
, argv
, 1);
53 while ((cp
= *argp
++)) {
55 switch (smatch (++cp
, switches
)) {
57 ambigsw (cp
, switches
);
60 die("-%s unknown", cp
);
63 snprintf (buf
, sizeof(buf
), "%s [switches] file", invo_name
);
64 print_help (buf
, switches
, 1);
67 print_version(invo_name
);
71 mbx_style
= MBOX_FORMAT
;
74 mbx_style
= MMDF_FORMAT
;
79 die("only one file at a time!");
84 die("%s [switches] file", invo_name
);
88 /* open and lock the file */
89 if ((md
= mbx_open (file
, mbx_style
, getuid(), getgid(), m_gmprot())) == NOTOK
)
92 /* append the message */
93 if (mbx_copy (file
, mbx_style
, md
, fileno(stdin
), NULL
) == NOTOK
) {
98 /* close and unlock the file */
99 if (mbx_close (file
, md
) == NOTOK
)