Added all of the MH sources, including RCS files, in
[mmh] / docs / historical / mh-6.8.5 / uip / RCS / rcvstore.c,v
1 head    1.9;
2 access;
3 symbols;
4 locks; strict;
5 comment @ * @;
6
7
8 1.9
9 date    92.12.15.00.20.22;      author jromine; state Exp;
10 branches;
11 next    1.8;
12
13 1.8
14 date    92.11.04.00.57.54;      author jromine; state Exp;
15 branches;
16 next    1.7;
17
18 1.7
19 date    92.10.27.00.12.13;      author jromine; state Exp;
20 branches;
21 next    1.6;
22
23 1.6
24 date    92.02.04.00.03.16;      author jromine; state Exp;
25 branches;
26 next    1.5;
27
28 1.5
29 date    92.01.31.22.25.00;      author jromine; state Exp;
30 branches;
31 next    1.4;
32
33 1.4
34 date    90.04.05.14.58.56;      author sources; state Exp;
35 branches;
36 next    1.3;
37
38 1.3
39 date    90.02.06.17.05.37;      author sources; state Exp;
40 branches;
41 next    1.2;
42
43 1.2
44 date    89.11.17.16.12.46;      author sources; state Exp;
45 branches;
46 next    1.1;
47
48 1.1
49 date    89.11.17.16.10.29;      author sources; state Exp;
50 branches;
51 next    ;
52
53
54 desc
55 @@
56
57
58 1.9
59 log
60 @endif sugar
61 @
62 text
63 @/* rcvstore.c - incorporate new mail asynchronously
64                 originally from Julian Onions */
65 #ifndef lint
66 static char ident[] = "@@(#)$Id: rcvstore.c,v 1.8 1992/11/04 00:57:54 jromine Exp jromine $";
67 #endif  /* lint */
68
69 #include "../h/mh.h"
70 #include <errno.h>
71 #include <signal.h>
72 #include <stdio.h>
73 #include <sys/types.h>
74 #include <sys/stat.h>
75 #ifdef LOCALE
76 #include        <locale.h>
77 #endif
78
79 /* \f */
80
81 static struct swit switches[] = {
82 #define CRETSW  0
83     "create",   0,
84 #define NCRETSW 1
85     "nocreate", 0,
86
87 #define PUBSW   2
88     "public",   0,
89 #define NPUBSW  3
90     "nopublic",  0,
91
92 #define SEQSW   4
93     "sequence name", 0,
94
95 #define ZEROSW  5
96     "zero",     0,
97 #define NZEROSW 6
98     "nozero",   0,
99
100 #define HELPSW  7
101     "help", 4,
102
103     NULL, 0
104 };
105
106 /* \f */
107
108 extern int  errno;
109
110 static char *tmpfilenam = NULLCP;
111 /* \f */
112
113 /* ARGSUSED */
114
115 main (argc, argv)
116 int     argc;
117 char   *argv[];
118 {
119     int     publicsw = -1,
120             zerosw = 0,
121             msgnum,
122             create = 1,
123             fd,
124             seqp = 0;
125     char   *cp,
126            *maildir,
127            *folder = NULL,
128             buf[100],
129           **ap,
130           **argp,
131            *arguments[MAXARGS],
132            *seqs[NATTRS+1];
133     struct msgs *mp;
134     struct stat st;
135
136 #ifdef LOCALE
137         setlocale(LC_ALL, "");
138 #endif
139     invo_name = r1bindex (argv[0], '/');
140     mts_init (invo_name);
141     if ((cp = m_find (invo_name)) != NULL) {
142         ap = brkstring (cp = getcpy (cp), " ", "\n");
143         ap = copyip (ap, arguments);
144     }
145     else
146         ap = arguments;
147     (void) copyip (argv + 1, ap);
148     argp = arguments;
149
150 /* \f */
151
152     while (cp = *argp++) {
153         if (*cp == '-')
154             switch (smatch (++cp, switches)) {
155                 case AMBIGSW: 
156                     ambigsw (cp, switches);
157                     done (1);
158                 case UNKWNSW: 
159                     adios (NULLCP, "-%s unknown", cp);
160                 case HELPSW: 
161                     (void) sprintf (buf, "%s [+folder] [switches]", invo_name);
162                     help (buf, switches);
163                     done (1);
164
165                 case SEQSW: 
166                     if (!(cp = *argp++) || *cp == '-')
167                         adios (NULLCP, "missing argument name to %s",
168                                 argp[-2]);
169                     if (seqp < NATTRS)
170                         seqs[seqp++] = cp;
171                     else
172                         adios (NULLCP, "only %d sequences allowed!", NATTRS);
173                     continue;
174                 case PUBSW: 
175                     publicsw = 1;
176                     continue;
177                 case NPUBSW: 
178                     publicsw = 0;
179                     continue;
180                 case ZEROSW: 
181                     zerosw++;
182                     continue;
183                 case NZEROSW: 
184                     zerosw = 0;
185                     continue;
186
187                 case CRETSW: 
188                     create++;
189                     continue;
190                 case NCRETSW: 
191                     create = 0;
192                     continue;
193             }
194         if (*cp == '+' || *cp == '@@') {
195             if (folder)
196                 adios (NULLCP, "only one folder at a time!");
197             else
198                 folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
199         }
200         else
201             adios (NULLCP, "usage: %s [+folder] [switches]", invo_name);
202     }
203
204 /* \f */
205
206     if (!m_find ("path"))
207         free (path ("./", TFOLDER));
208     if (!folder && !(folder = m_find (inbox)))
209         folder = defalt;
210     maildir = m_maildir (folder);
211
212     if (stat (maildir, &st) == NOTOK) {
213         if (errno != ENOENT)
214             adios (maildir, "error on folder");
215         if (!create)
216             adios (NULLCP, "folder %s doesn't exist", maildir);
217         if (!makedir (maildir))
218             adios (NULLCP, "unable to create folder %s", maildir);
219     }
220
221     if (chdir (maildir) == NOTOK)
222         adios (maildir, "unable to change directory to");
223     if (!(mp = m_gmsg (folder)))
224         adios (NULLCP, "unable to read folder %s", folder);
225
226     (void) signal (SIGHUP, SIG_IGN);
227     (void) signal (SIGINT, SIG_IGN);
228     (void) signal (SIGQUIT, SIG_IGN);
229     (void) signal (SIGTERM, SIG_IGN);
230
231 /* \f */
232
233     if ((fd = creat (tmpfilenam = m_scratch ("", invo_name), m_gmprot ()))
234             == NOTOK)
235         adios (tmpfilenam, "unable to create");
236     (void) chmod (tmpfilenam, m_gmprot ());
237
238     cpydata (fileno (stdin), fd, "standard input", tmpfilenam);
239
240     if (fstat (fd, &st) == NOTOK) {
241         (void) unlink (tmpfilenam);
242         adios (tmpfilenam, "unable to fstat");
243     }
244     if (close (fd) == NOTOK)
245         adios (tmpfilenam, "error closing");
246     if (st.st_size == 0) {
247         (void) unlink (tmpfilenam);
248         advise (NULLCP, "empty file");
249         done (0);
250     }
251
252     msgnum = mp -> hghmsg;
253     do {
254         msgnum++, mp -> hghmsg++;
255         if (msgnum > mp -> hghoff)
256             if ((mp = m_remsg (mp, 0, mp -> hghoff + MAXFOLDER)) == NULL)
257                 adios (NULLCP, "unable to allocate folder storage");
258
259         mp -> msgstats[msgnum] |= EXISTS | UNSEEN;
260         errno = 0;
261     } while (link (tmpfilenam, m_name (msgnum)) == NOTOK && errno == EEXIST);
262
263     (void) unlink (tmpfilenam);
264     tmpfilenam = NULLCP;
265     if (errno != 0)
266         adios (NULLCP, "can't file message %d", msgnum);
267
268     if (mp -> lowmsg == 0)
269         mp -> lowmsg = msgnum;
270     mp -> msgflags |= SEQMOD;
271
272     seqs[seqp] = NULL;
273     for (seqp = 0; seqs[seqp]; seqp++) {
274         if (zerosw && !m_seqnew (mp, seqs[seqp], publicsw))
275             done (1);
276         if (!m_seqadd (mp, seqs[seqp], msgnum, publicsw))
277             done (1);
278     }
279
280     m_setvis (mp, 0);
281     m_sync (mp);
282     m_update ();
283
284     done (0);
285 }
286
287 void done (status)
288 register int     status;
289 {
290     if (tmpfilenam && *tmpfilenam)
291         (void) unlink (tmpfilenam);
292     exit (status);
293 }
294 @
295
296
297 1.8
298 log
299 @LOCALE
300 TYPESIG
301 @
302 text
303 @d4 2
304 a5 2
305 static char ident[] = "@@(#)$Id: rcvstore.c,v 1.7 1992/10/27 00:12:13 jromine Exp jromine $";
306 #endif  lint
307 @
308
309
310 1.7
311 log
312 @NATTRS->NATTRS+1
313 @
314 text
315 @d4 1
316 a4 1
317 static char ident[] = "@@(#)$Id: rcvstore.c,v 1.6 1992/02/04 00:03:16 jromine Exp jromine $";
318 d13 3
319 d74 3
320 @
321
322
323 1.6
324 log
325 @contributed patch
326 @
327 text
328 @d4 1
329 a4 1
330 static char ident[] = "@@(#)$Id: rcvstore.c,v 1.5 1992/01/31 22:25:00 jromine Exp jromine $";
331 d67 1
332 a67 1
333            *seqs[NATTRS];
334 @
335
336
337 1.5
338 log
339 @kerberos
340 @
341 text
342 @d4 1
343 a4 1
344 static char ident[] = "@@(#)$Id: rcvstore.c,v 1.4 1990/04/05 14:58:56 sources Exp jromine $";
345 d140 1
346 a140 1
347     if (!folder)
348 @
349
350
351 1.4
352 log
353 @add ID
354 @
355 text
356 @d4 1
357 a4 1
358 static char ident[] = "@@(#)$Id:$";
359 d38 1
360 a38 1
361     NULL, NULL
362 @
363
364
365 1.3
366 log
367 @some fixes from J. Onions for bad close() return
368 @
369 text
370 @d3 3
371 @
372
373
374 1.2
375 log
376 @add explicit chmod to override umask
377 @
378 text
379 @d42 1
380 d162 4
381 a165 3
382     if ((fd = creat (cp = m_scratch ("", invo_name), m_gmprot ())) == NOTOK)
383         adios (cp, "unable to create");
384     (void) chmod (cp, m_gmprot ()); /* creat ANDs with umask, do it right */
385 d167 1
386 a167 1
387     cpydata (fileno (stdin), fd, "standard input", cp);
388 d170 2
389 a171 2
390         (void) unlink (cp);
391         adios (cp, "unable to fstat");
392 d173 2
393 a174 1
394     (void) close (fd);
395 d176 1
396 a176 1
397         (void) unlink (cp);
398 d190 1
399 a190 1
400     } while (link (cp, m_name (msgnum)) == NOTOK && errno == EEXIST);
401 d192 2
402 a193 1
403     (void) unlink (cp);
404 d214 8
405 @
406
407
408 1.1
409 log
410 @Initial revision
411 @
412 text
413 @d163 1
414 @