1 | |
---|
2 | /* |
---|
3 | * rcvpack.c -- append message to a file |
---|
4 | * |
---|
5 | * $Id: rcvpack.c,v 1.1.1.1 1999-02-07 18:14:16 danw Exp $ |
---|
6 | */ |
---|
7 | |
---|
8 | #include <h/mh.h> |
---|
9 | #include <h/dropsbr.h> |
---|
10 | #include <h/rcvmail.h> |
---|
11 | #include <zotnet/tws/tws.h> |
---|
12 | #include <zotnet/mts/mts.h> |
---|
13 | |
---|
14 | static struct swit switches[] = { |
---|
15 | #define MBOXSW 0 |
---|
16 | { "mbox", 0 }, |
---|
17 | #define MMDFSW 1 |
---|
18 | { "mmdf", 0 }, |
---|
19 | #define VERSIONSW 2 |
---|
20 | { "version", 0 }, |
---|
21 | #define HELPSW 3 |
---|
22 | { "help", 4 }, |
---|
23 | { NULL, 0 } |
---|
24 | }; |
---|
25 | |
---|
26 | /* |
---|
27 | * default format in which to save messages |
---|
28 | */ |
---|
29 | static int mbx_style = MBOX_FORMAT; |
---|
30 | |
---|
31 | |
---|
32 | int |
---|
33 | main (int argc, char **argv) |
---|
34 | { |
---|
35 | int md; |
---|
36 | char *cp, *file = NULL, buf[BUFSIZ]; |
---|
37 | char **argp, **arguments; |
---|
38 | |
---|
39 | #ifdef LOCALE |
---|
40 | setlocale(LC_ALL, ""); |
---|
41 | #endif |
---|
42 | invo_name = r1bindex (argv[0], '/'); |
---|
43 | |
---|
44 | /* read user profile/context */ |
---|
45 | context_read(); |
---|
46 | |
---|
47 | mts_init (invo_name); |
---|
48 | arguments = getarguments (invo_name, argc, argv, 1); |
---|
49 | argp = arguments; |
---|
50 | |
---|
51 | /* parse arguments */ |
---|
52 | while ((cp = *argp++)) { |
---|
53 | if (*cp == '-') { |
---|
54 | switch (smatch (++cp, switches)) { |
---|
55 | case AMBIGSW: |
---|
56 | ambigsw (cp, switches); |
---|
57 | done (1); |
---|
58 | case UNKWNSW: |
---|
59 | adios (NULL, "-%s unknown", cp); |
---|
60 | |
---|
61 | case HELPSW: |
---|
62 | snprintf (buf, sizeof(buf), "%s [switches] file", invo_name); |
---|
63 | print_help (buf, switches, 1); |
---|
64 | done (1); |
---|
65 | case VERSIONSW: |
---|
66 | print_version(invo_name); |
---|
67 | done (1); |
---|
68 | |
---|
69 | case MBOXSW: |
---|
70 | mbx_style = MBOX_FORMAT; |
---|
71 | continue; |
---|
72 | case MMDFSW: |
---|
73 | mbx_style = MMDF_FORMAT; |
---|
74 | continue; |
---|
75 | } |
---|
76 | } |
---|
77 | if (file) |
---|
78 | adios (NULL, "only one file at a time!"); |
---|
79 | else |
---|
80 | file = cp; |
---|
81 | } |
---|
82 | |
---|
83 | if (!file) |
---|
84 | adios (NULL, "%s [switches] file", invo_name); |
---|
85 | |
---|
86 | rewind (stdin); |
---|
87 | |
---|
88 | /* open and lock the file */ |
---|
89 | if ((md = mbx_open (file, mbx_style, getuid(), getgid(), m_gmprot())) == NOTOK) |
---|
90 | done (RCV_MBX); |
---|
91 | |
---|
92 | /* append the message */ |
---|
93 | if (mbx_copy (file, mbx_style, md, fileno(stdin), 1, NULL, 0) == NOTOK) { |
---|
94 | mbx_close (file, md); |
---|
95 | done (RCV_MBX); |
---|
96 | } |
---|
97 | |
---|
98 | /* close and unlock the file */ |
---|
99 | if (mbx_close (file, md) == NOTOK) |
---|
100 | done (RCV_MBX); |
---|
101 | |
---|
102 | done (RCV_MOK); |
---|
103 | } |
---|