]>
diplodocus.org Git - nmh/blob - uip/rcvpack.c
f63a89d066fb034146074d477ea2e35bbb8b1f9f
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.
10 #include "h/dropsbr.h"
11 #include "h/rcvmail.h"
17 #define RCVPACK_SWITCHES \
18 X("mbox", 0, MBOXSW) \
19 X("mmdf", 0, MMDFSW) \
20 X("version", 0, VERSIONSW) \
21 X("help", 0, HELPSW) \
23 #define X(sw, minchars, id) id,
24 DEFINE_SWITCH_ENUM(RCVPACK
);
27 #define X(sw, minchars, id) { sw, minchars, id },
28 DEFINE_SWITCH_ARRAY(RCVPACK
, switches
);
32 * default format in which to save messages
34 static int mbx_style
= MBOX_FORMAT
;
38 main (int argc
, char **argv
)
41 char *cp
, *file
= NULL
, buf
[BUFSIZ
];
42 char **argp
, **arguments
;
44 if (nmh_init(argv
[0], true, false)) { return 1; }
47 arguments
= getarguments (invo_name
, argc
, argv
, 1);
51 while ((cp
= *argp
++)) {
53 switch (smatch (++cp
, switches
)) {
55 ambigsw (cp
, switches
);
58 die("-%s unknown", cp
);
61 snprintf (buf
, sizeof(buf
), "%s [switches] file", invo_name
);
62 print_help (buf
, switches
, 1);
65 print_version(invo_name
);
69 mbx_style
= MBOX_FORMAT
;
72 mbx_style
= MMDF_FORMAT
;
77 die("only one file at a time!");
82 die("%s [switches] file", invo_name
);
86 /* open and lock the file */
87 if ((md
= mbx_open (file
, mbx_style
, getuid(), getgid(), m_gmprot())) == NOTOK
)
90 /* append the message */
91 if (mbx_copy (file
, mbx_style
, md
, fileno(stdin
), NULL
) == NOTOK
) {
96 /* close and unlock the file */
97 if (mbx_close (file
, md
) == NOTOK
)