1 /* rcvstore.c - incorporate new mail asynchronously
2 originally from Julian Onions */
4 static char ident[] = "@(#)$Id: rcvstore.c,v 1.9 1992/12/15 00:20:22 jromine Exp $";
11 #include <sys/types.h>
19 static struct swit switches[] = {
48 static char *tmpfilenam = NULLCP;
75 setlocale(LC_ALL, "");
77 invo_name = r1bindex (argv[0], '/');
79 if ((cp = m_find (invo_name)) != NULL) {
80 ap = brkstring (cp = getcpy (cp), " ", "\n");
81 ap = copyip (ap, arguments);
85 (void) copyip (argv + 1, ap);
90 while (cp = *argp++) {
92 switch (smatch (++cp, switches)) {
94 ambigsw (cp, switches);
97 adios (NULLCP, "-%s unknown", cp);
99 (void) sprintf (buf, "%s [+folder] [switches]", invo_name);
100 help (buf, switches);
104 if (!(cp = *argp++) || *cp == '-')
105 adios (NULLCP, "missing argument name to %s",
110 adios (NULLCP, "only %d sequences allowed!", NATTRS);
132 if (*cp == '+' || *cp == '@') {
134 adios (NULLCP, "only one folder at a time!");
136 folder = path (cp + 1, *cp == '+' ? TFOLDER : TSUBCWF);
139 adios (NULLCP, "usage: %s [+folder] [switches]", invo_name);
144 if (!m_find ("path"))
145 free (path ("./", TFOLDER));
146 if (!folder && !(folder = m_find (inbox)))
148 maildir = m_maildir (folder);
150 if (stat (maildir, &st) == NOTOK) {
152 adios (maildir, "error on folder");
154 adios (NULLCP, "folder %s doesn't exist", maildir);
155 if (!makedir (maildir))
156 adios (NULLCP, "unable to create folder %s", maildir);
159 if (chdir (maildir) == NOTOK)
160 adios (maildir, "unable to change directory to");
161 if (!(mp = m_gmsg (folder)))
162 adios (NULLCP, "unable to read folder %s", folder);
164 (void) signal (SIGHUP, SIG_IGN);
165 (void) signal (SIGINT, SIG_IGN);
166 (void) signal (SIGQUIT, SIG_IGN);
167 (void) signal (SIGTERM, SIG_IGN);
171 if ((fd = creat (tmpfilenam = m_scratch ("", invo_name), m_gmprot ()))
173 adios (tmpfilenam, "unable to create");
174 (void) chmod (tmpfilenam, m_gmprot ());
176 cpydata (fileno (stdin), fd, "standard input", tmpfilenam);
178 if (fstat (fd, &st) == NOTOK) {
179 (void) unlink (tmpfilenam);
180 adios (tmpfilenam, "unable to fstat");
182 if (close (fd) == NOTOK)
183 adios (tmpfilenam, "error closing");
184 if (st.st_size == 0) {
185 (void) unlink (tmpfilenam);
186 advise (NULLCP, "empty file");
190 msgnum = mp -> hghmsg;
192 msgnum++, mp -> hghmsg++;
193 if (msgnum > mp -> hghoff)
194 if ((mp = m_remsg (mp, 0, mp -> hghoff + MAXFOLDER)) == NULL)
195 adios (NULLCP, "unable to allocate folder storage");
197 mp -> msgstats[msgnum] |= EXISTS | UNSEEN;
199 } while (link (tmpfilenam, m_name (msgnum)) == NOTOK && errno == EEXIST);
201 (void) unlink (tmpfilenam);
204 adios (NULLCP, "can't file message %d", msgnum);
206 if (mp -> lowmsg == 0)
207 mp -> lowmsg = msgnum;
208 mp -> msgflags |= SEQMOD;
211 for (seqp = 0; seqs[seqp]; seqp++) {
212 if (zerosw && !m_seqnew (mp, seqs[seqp], publicsw))
214 if (!m_seqadd (mp, seqs[seqp], msgnum, publicsw))
228 if (tmpfilenam && *tmpfilenam)
229 (void) unlink (tmpfilenam);