-/*
-** Check/prepare MBOX style maildrop for appending.
-*/
-
-static int
-mbx_chk_mbox (int fd)
-{
- /* just seek to the end */
- if (lseek (fd, (off_t) 0, SEEK_END) == (off_t) NOTOK)
- return NOTOK;
-
- return OK;
-}
-
-
-/*
-** Check/prepare MMDF style maildrop for appending.
-*/
-
-static int
-mbx_chk_mmdf (int fd)
-{
- size_t count;
- char ldelim[BUFSIZ];
-
- count = strlen (mmdlm2);
-
- /* casting -count to off_t, seem to break FreeBSD 2.2.6 */
- if (lseek (fd, (long) (-count), SEEK_END) == (off_t) NOTOK)
- return NOTOK;
- if (read (fd, ldelim, count) != count)
- return NOTOK;
-
- ldelim[count] = 0;
-
- if (strcmp (ldelim, mmdlm2)
- && write (fd, "\n", 1) != 1
- && write (fd, mmdlm2, count) != count)
- return NOTOK;
-
- return OK;
-}
-
-
-int
-mbx_read (FILE *fp, long pos, struct drop **drops, int noisy)
-{
- register int len, size;
- register long ld1, ld2;
- register char *bp;
- char buffer[BUFSIZ];
- register struct drop *cp, *dp, *ep, *pp;
-
- pp = (struct drop *) calloc ((size_t) (len = MAXFOLDER), sizeof(*dp));
- if (pp == NULL) {
- if (noisy)
- admonish (NULL, "unable to allocate drop storage");
- return NOTOK;
- }
-
- ld1 = (long) strlen (mmdlm1);
- ld2 = (long) strlen (mmdlm2);
-
- fseek (fp, pos, SEEK_SET);
- for (ep = (dp = pp) + len - 1; fgets (buffer, sizeof(buffer), fp);) {
- size = 0;
- if (strcmp (buffer, mmdlm1) == 0)
- pos += ld1, dp->d_start = (long) pos;
- else {
- dp->d_start = (long)pos , pos += (long) strlen (buffer);
- for (bp = buffer; *bp; bp++, size++)
- if (*bp == '\n')
- size++;
- }
-
- while (fgets (buffer, sizeof(buffer), fp) != NULL)
- if (strcmp (buffer, mmdlm2) == 0)
- break;
- else {
- pos += (long) strlen (buffer);
- for (bp = buffer; *bp; bp++, size++)
- if (*bp == '\n')
- size++;
- }
-
- if (dp->d_start != (long) pos) {
- dp->d_id = 0;
- dp->d_size = (long) size;
- dp->d_stop = pos;
- dp++;
- }
- pos += ld2;
-
- if (dp >= ep) {
- register int curlen = dp - pp;
-
- cp = (struct drop *) mh_xrealloc ((char *) pp,
- (size_t) (len += MAXFOLDER) * sizeof(*pp));
- dp = cp + curlen, ep = (pp = cp) + len - 1;
- }
- }
-
- if (dp == pp)
- free ((char *) pp);
- else
- *drops = pp;
- return (dp - pp);
-}
-
-
-int
-mbx_write(char *mailbox, int md, FILE *fp, int id, long last,
- long pos, off_t stop, int mapping, int noisy)
-{
- register int i, j, size;
- off_t start;
- long off;
- register char *cp;
- char buffer[BUFSIZ];
-
- off = (long) lseek (md, (off_t) 0, SEEK_CUR);
- j = strlen (mmdlm1);
- if (write (md, mmdlm1, j) != j)
- return NOTOK;
- start = lseek (md, (off_t) 0, SEEK_CUR);
- size = 0;
-
- fseek (fp, pos, SEEK_SET);
- while (fgets (buffer, sizeof(buffer), fp) && (pos < stop)) {
- i = strlen (buffer);
- for (j = 0; (j = stringdex (mmdlm1, buffer)) >= 0; buffer[j]++)
- continue;
- for (j = 0; (j = stringdex (mmdlm2, buffer)) >= 0; buffer[j]++)
- continue;
- if (write (md, buffer, i) != i)
- return NOTOK;
- pos += (long) i;
- if (mapping)
- for (cp = buffer; i-- > 0; size++)
- if (*cp++ == '\n')
- size++;
- }
-
- stop = lseek (md, (off_t) 0, SEEK_CUR);
- j = strlen (mmdlm2);
- if (write (md, mmdlm2, j) != j)
- return NOTOK;
- if (mapping)
- map_write (mailbox, md, id, last, start, stop, off, size, noisy);
-
- return OK;
-}
-