Added all of the MH sources, including RCS files, in
[mmh] / docs / historical / mh-6.8.5 / support / pop / mmdfII / pop / ch_pop.c
1 #include "util.h"
2 #include "mmdf.h"
3 #ifndef POP
4
5 /* 
6  *                         C H _ B B O A R D S . C
7  *
8  *                         the new BBoards channel
9  */
10
11 #else   POP
12
13 /* 
14  *                             C H _ P O P . C
15  *
16  *                             the POP channel
17  */
18
19 #endif  POP
20
21 /* \f */
22
23 #ifndef POP
24
25 /*
26  *      This is the channel that is used to handle Internet BBoard
27  *      distribution in an intelligent fashion.  In order to run it, you
28  *      need the UCI BBoards facility installed.  This requires the
29  *      establishment of a special login called ``bboards'', and the
30  *      getbbent() package.
31  *
32  *      The idea is simple.  Distribution lists get aliased to go through
33  *      this channel.  Suppose that the relay (or site) using ch_bboards
34  *      subscribes to UNIX-WIZARDS.  The maintainer of the list is given
35  *      the address ``dist-unix-wizards'' to send to for this relay and all
36  *      sites that it serves.  The site manager then defines the following
37  *      alias in the aliases file:
38  *
39  *              dist-unix-wizards:      unix-wizards@bboards
40  *
41  *      This channel (and this channel alone) is then defined to serve the
42  *      ``bboards'' host.  When it gets invoked, the channel does two
43  *      things:  First, if the relay itself subscribes to the BBoard (the
44  *      bb_file entry in the BBoards file is non-empty), then it delivers
45  *      the message to the file.  Second, if other sites subscribe to the
46  *      BBoard, then ch_bboards will enter the message back into the queue
47  *      system using the ``bboards'' login as the sender.
48  *
49  *      This achieves two goals:  first, the incoming bandwidth of relays
50  *      is not degraded by many sites subscribing to the same BBoard;
51  *      second, if an address goes bad down the line, the relay's
52  *      ``bboards'' login gets the message back (not the originator).  Since
53  *      the relay's PostMaster is assumed to monitor this mailbox, problems
54  *      can be found and corrected.
55  *
56  *      Finally, ch_bboards can be run by a site that does not relay for
57  *      other sites.  In this case, the bb_dist field is empty.
58  */
59
60 /*      Unlike previous versions of ch_bboards, this version does not change
61  *      the contents of the headers of the message being re-distributed.
62  *      The following changes are made:
63  *
64  *          Envelope:   The failure address is changed to
65                                 bboards@locname.locdomain
66  *          Headers:    Another Received: is added
67  *
68  *      The local copy going to the BBoard has two entries prepended to the
69  *      headers:
70  *
71  *          BBoard-ID: n
72  *          BB-Posted: RFC822 date/time
73  */
74
75 #else   POP
76
77 /* 
78  *      The POP channel is a subset of the BBoards channel, and just
79  *      handles local mail delivery for remote users.  As such, it
80  *      only needs to know how to store a maildrop locally, and doesn't
81  *      have to mess around with .cnt files and remote delivery.
82  */
83
84 #endif  POP
85
86 /* \f */
87
88 #include <signal.h>
89 #include "ch.h"
90 #include "phs.h"
91
92 extern LLog chanlog;
93 LLog   *logptr = &chanlog;
94 extern char *logdfldir;
95
96 /* \f */
97
98 main (argc, argv)
99 int     argc;
100 char  **argv;
101 {
102     Chan    *chanptr;
103     char    *dupfpath ();
104     short   retval;
105
106     mmdf_init (argv[0]);
107
108 #ifdef RUNALON
109     logptr -> ll_fd = 1;
110     ll_init (logptr);
111 #endif
112
113     siginit ();
114     signal (SIGINT, SIG_IGN);
115
116     if ((chanptr = ch_nm2struct (argv[0])) == (Chan *) NOTOK)
117         err_abrt (RP_PARM, "unknown channel name '%s'", argv[0]);
118
119     ch_llinit (chanptr);
120
121     retval = ch_bboards (argc, argv, chanptr);
122     ll_close (logptr);
123
124     exit (retval);
125 }
126
127 /* \f */
128 /* ****************  (ch_) BBOARD DELIVERY **************** */
129
130 ch_bboards (argc, argv, chanptr)
131 int     argc;
132 char  **argv;
133 Chan  *chanptr;
134 {
135 #ifdef  DEBUG
136     ll_log (logptr, LLOGBTR, "ch_bboards(argc=%d,*argv='%s')", argc, *argv);
137 #endif
138
139     if (rp_isbad (qu_init (argc, argv)))
140         return RP_NO;
141     if (rp_isbad (bb_init (chanptr)))
142         return RP_NO;
143
144     phs_note (chanptr, PHS_WRSTRT);
145     
146     if (rp_isbad (qu2bb_send (chanptr)))
147         return RP_NO;
148
149     phs_note (chanptr, PHS_WREND);
150
151     qu_end (OK);
152     bb_end (OK);
153
154     return RP_OK;
155 }
156
157 /* \f */
158
159 /* VARARGS2 */
160 err_abrt (code, fmt, b, c, d)
161 short   code;
162 char   *fmt,
163        *b,
164        *c,
165        *d;
166 {
167     char    linebuf[LINESIZE];
168
169     qu_end (NOTOK);
170     bb_end (NOTOK);
171
172     sprintf (linebuf, "%s%s", "err [ ABEND (%s) ]\t", fmt);
173     ll_log (logptr, LLOGFAT, linebuf, rp_valstr (code), b, c, d);
174     ll_close (logptr);
175
176     exit (code);
177 }