2 ** rcvpack.c -- append message to a file
4 ** This code is Copyright (c) 2002, by the authors of nmh. See the
5 ** COPYRIGHT file in the root directory of the nmh distribution for
6 ** complete copyright information.
10 #include <h/dropsbr.h>
11 #include <h/rcvmail.h>
17 static struct swit switches[] = {
25 char *version=VERSION;
28 main(int argc, char **argv)
31 char *cp, *file = NULL, buf[BUFSIZ];
32 char **argp, **arguments;
34 setlocale(LC_ALL, "");
35 invo_name = mhbasename(argv[0]);
37 /* read user profile/context */
40 arguments = getarguments(invo_name, argc, argv, 1);
44 while ((cp = *argp++)) {
46 switch (smatch(++cp, switches)) {
48 ambigsw(cp, switches);
51 adios(EX_USAGE, NULL, "-%s unknown", cp);
54 snprintf(buf, sizeof(buf),
57 print_help(buf, switches, 1);
58 exit(argc == 2 ? EX_OK : EX_USAGE);
60 print_version(invo_name);
61 exit(argc == 2 ? EX_OK : EX_USAGE);
65 adios(EX_USAGE, NULL, "only one file at a time!");
70 /* copy stdin to stdout, converting rfc822 message to mbox */
72 if (mbox_copy(fileno(stdout), fileno(stdin)) == NOTOK) {
79 /* open and lock the file */
80 if ((md = mbox_open(file, getuid(), getgid(), m_gmprot()))
84 /* append the message */
85 if (mbox_copy(md, fileno(stdin)) == NOTOK) {
90 /* close and unlock the file */
91 if (mbox_close(file, md) == NOTOK)