9 date 92.12.15.00.20.22; author jromine; state Exp;
14 date 92.11.04.00.57.54; author jromine; state Exp;
19 date 92.10.27.00.12.13; author jromine; state Exp;
24 date 92.02.04.00.03.16; author jromine; state Exp;
29 date 92.01.31.22.25.00; author jromine; state Exp;
34 date 90.04.05.14.58.56; author sources; state Exp;
39 date 90.02.06.17.05.37; author sources; state Exp;
44 date 89.11.17.16.12.46; author sources; state Exp;
49 date 89.11.17.16.10.29; author sources; state Exp;
63 @/* rcvstore.c - incorporate new mail asynchronously
64 originally from Julian Onions */
66 static char ident[] = "@@(#)$Id: rcvstore.c,v 1.8 1992/11/04 00:57:54 jromine Exp jromine $";
73 #include <sys/types.h>
81 static struct swit switches[] = {
110 static char *tmpfilenam = NULLCP;
137 setlocale(LC_ALL, "");
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);
147 (void) copyip (argv + 1, ap);
152 while (cp = *argp++) {
154 switch (smatch (++cp, switches)) {
156 ambigsw (cp, switches);
159 adios (NULLCP, "-%s unknown", cp);
161 (void) sprintf (buf, "%s [+folder] [switches]", invo_name);
162 help (buf, switches);
166 if (!(cp = *argp++) || *cp == '-')
167 adios (NULLCP, "missing argument name to %s",
172 adios (NULLCP, "only %d sequences allowed!", NATTRS);
194 if (*cp == '+' || *cp == '@@') {
196 adios (NULLCP, "only one folder at a time!");
198 folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
201 adios (NULLCP, "usage: %s [+folder] [switches]", invo_name);
206 if (!m_find ("path"))
207 free (path ("./", TFOLDER));
208 if (!folder && !(folder = m_find (inbox)))
210 maildir = m_maildir (folder);
212 if (stat (maildir, &st) == NOTOK) {
214 adios (maildir, "error on folder");
216 adios (NULLCP, "folder %s doesn't exist", maildir);
217 if (!makedir (maildir))
218 adios (NULLCP, "unable to create folder %s", maildir);
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);
226 (void) signal (SIGHUP, SIG_IGN);
227 (void) signal (SIGINT, SIG_IGN);
228 (void) signal (SIGQUIT, SIG_IGN);
229 (void) signal (SIGTERM, SIG_IGN);
233 if ((fd = creat (tmpfilenam = m_scratch ("", invo_name), m_gmprot ()))
235 adios (tmpfilenam, "unable to create");
236 (void) chmod (tmpfilenam, m_gmprot ());
238 cpydata (fileno (stdin), fd, "standard input", tmpfilenam);
240 if (fstat (fd, &st) == NOTOK) {
241 (void) unlink (tmpfilenam);
242 adios (tmpfilenam, "unable to fstat");
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");
252 msgnum = mp -> hghmsg;
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");
259 mp -> msgstats[msgnum] |= EXISTS | UNSEEN;
261 } while (link (tmpfilenam, m_name (msgnum)) == NOTOK && errno == EEXIST);
263 (void) unlink (tmpfilenam);
266 adios (NULLCP, "can't file message %d", msgnum);
268 if (mp -> lowmsg == 0)
269 mp -> lowmsg = msgnum;
270 mp -> msgflags |= SEQMOD;
273 for (seqp = 0; seqs[seqp]; seqp++) {
274 if (zerosw && !m_seqnew (mp, seqs[seqp], publicsw))
276 if (!m_seqadd (mp, seqs[seqp], msgnum, publicsw))
290 if (tmpfilenam && *tmpfilenam)
291 (void) unlink (tmpfilenam);
305 static char ident[] = "@@(#)$Id: rcvstore.c,v 1.7 1992/10/27 00:12:13 jromine Exp jromine $";
317 static char ident[] = "@@(#)$Id: rcvstore.c,v 1.6 1992/02/04 00:03:16 jromine Exp jromine $";
330 static char ident[] = "@@(#)$Id: rcvstore.c,v 1.5 1992/01/31 22:25:00 jromine Exp jromine $";
344 static char ident[] = "@@(#)$Id: rcvstore.c,v 1.4 1990/04/05 14:58:56 sources Exp jromine $";
358 static char ident[] = "@@(#)$Id:$";
367 @some fixes from J. Onions for bad close() return
376 @add explicit chmod to override umask
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 */
387 cpydata (fileno (stdin), fd, "standard input", cp);
391 adios (cp, "unable to fstat");
400 } while (link (cp, m_name (msgnum)) == NOTOK && errno == EEXIST);