]>
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.
10 #include <h/rcvmail.h>
15 #define RCVPACK_SWITCHES \
16 X("mbox", 0, MBOXSW) \
17 X("mmdf", 0, MMDFSW) \
18 X("version", 0, VERSIONSW) \
19 X("help", 0, HELPSW) \
21 #define X(sw, minchars, id) id,
22 DEFINE_SWITCH_ENUM(RCVPACK
);
25 #define X(sw, minchars, id) { sw, minchars, id },
26 DEFINE_SWITCH_ARRAY(RCVPACK
, switches
);
30 * default format in which to save messages
32 static int mbx_style
= MBOX_FORMAT
;
36 main (int argc
, char **argv
)
39 char *cp
, *file
= NULL
, buf
[BUFSIZ
];
40 char **argp
, **arguments
;
42 if (nmh_init(argv
[0], 2)) { return 1; }
45 arguments
= getarguments (invo_name
, argc
, argv
, 1);
49 while ((cp
= *argp
++)) {
51 switch (smatch (++cp
, switches
)) {
53 ambigsw (cp
, switches
);
56 adios (NULL
, "-%s unknown", cp
);
59 snprintf (buf
, sizeof(buf
), "%s [switches] file", invo_name
);
60 print_help (buf
, switches
, 1);
63 print_version(invo_name
);
67 mbx_style
= MBOX_FORMAT
;
70 mbx_style
= MMDF_FORMAT
;
75 adios (NULL
, "only one file at a time!");
80 adios (NULL
, "%s [switches] file", invo_name
);
84 /* open and lock the file */
85 if ((md
= mbx_open (file
, mbx_style
, getuid(), getgid(), m_gmprot())) == NOTOK
)
88 /* append the message */
89 if (mbx_copy (file
, mbx_style
, md
, fileno(stdin
), NULL
) == NOTOK
) {
94 /* close and unlock the file */
95 if (mbx_close (file
, md
) == NOTOK
)