-static int mmdf_parse_mailbox (CONTEXT * ctx)
-{
- char buf[HUGE_STRING];
- char return_path[LONG_STRING];
- int count = 0, oldmsgcount = ctx->msgcount;
- int lines;
- time_t t, tz;
- off_t loc, tmploc;
- HEADER *hdr;
- struct stat sb;
-
- if (stat (ctx->path, &sb) == -1) {
- mutt_perror (ctx->path);
- return (-1);
- }
- ctx->mtime = sb.st_mtime;
- ctx->size = sb.st_size;
-
- /* precompute the local timezone to speed up calculation of the
- received time */
- tz = mutt_local_tz (0);
-
- buf[sizeof (buf) - 1] = 0;
-
- for (;;) {
- if (fgets (buf, sizeof (buf) - 1, ctx->fp) == NULL)
- break;
-
- if (m_strcmp(buf, MMDF_SEP) == 0) {
- loc = ftello (ctx->fp);
-
- count++;
- if (!ctx->quiet && ReadInc && ((count % ReadInc == 0) || count == 1))
- mutt_message (_("Reading %s... %d (%d%%)"), ctx->path, count,
- (int) (loc / (ctx->size / 100 + 1)));
-
-
- if (ctx->msgcount == ctx->hdrmax)
- mx_alloc_memory (ctx);
- ctx->hdrs[ctx->msgcount] = hdr = header_new();
- hdr->offset = loc;
- hdr->index = ctx->msgcount;
-
- if (fgets (buf, sizeof (buf) - 1, ctx->fp) == NULL) {
- /* TODO: memory leak??? */
- break;
- }
-
- return_path[0] = 0;
-
- if (!is_from (buf, return_path, sizeof (return_path), &t)) {
- if (fseeko (ctx->fp, loc, SEEK_SET) != 0) {
- mutt_error _("Mailbox is corrupt!");
-
- return (-1);
- }
- }
- else
- hdr->received = t - tz;
-
- hdr->env = mutt_read_rfc822_header (ctx->fp, hdr, 0, 0);
-
- loc = ftello (ctx->fp);
-
- if (hdr->content->length > 0 && hdr->lines > 0) {
- tmploc = loc + hdr->content->length;
-
- if (0 < tmploc && tmploc < ctx->size) {
- if (fseeko (ctx->fp, tmploc, SEEK_SET) != 0 ||
- fgets (buf, sizeof (buf) - 1, ctx->fp) == NULL ||
- m_strcmp(MMDF_SEP, buf) != 0) {
- fseeko (ctx->fp, loc, SEEK_SET);
- hdr->content->length = -1;
- }
- }
- else
- hdr->content->length = -1;
- }
- else
- hdr->content->length = -1;
-
- if (hdr->content->length < 0) {
- lines = -1;
- do {
- loc = ftello (ctx->fp);
- if (fgets (buf, sizeof (buf) - 1, ctx->fp) == NULL)
- break;
- lines++;
- } while (m_strcmp(buf, MMDF_SEP) != 0);
-
- hdr->lines = lines;
- hdr->content->length = loc - hdr->content->offset;
- }
-
- if (!hdr->env->return_path && return_path[0])
- hdr->env->return_path =
- rfc822_parse_adrlist (hdr->env->return_path, return_path);
-
- if (!hdr->env->from)
- hdr->env->from = address_list_dup (hdr->env->return_path);
-
- ctx->msgcount++;
- }
- else {
- mutt_error _("Mailbox is corrupt!");
-
- return (-1);
- }
- }
-
- if (ctx->msgcount > oldmsgcount)
- mx_update_context (ctx, ctx->msgcount - oldmsgcount);
-
- return (0);
-}
-