static int maildir_parse_entry(CONTEXT *ctx, struct maildir ***last, const char *subdir, const char *fname, int *count, int is_old) { struct maildir *entry; HEADER *h; char buf[_POSIX_PATH_MAX]; if(subdir) snprintf(buf, sizeof(buf), "%s/%s/%s", ctx->path, subdir, fname); else snprintf(buf, sizeof(buf), "%s/%s", ctx->path, fname); if((h = maildir_parse_message(ctx->magic, buf, is_old)) != NULL) { if(count) { (*count)++; if (!ctx->quiet && ReadInc && ((*count % ReadInc) == 0 || *count == 1)) mutt_message (_("Reading %s... %d"), ctx->path, *count); } if (subdir) { snprintf (buf, sizeof (buf), "%s/%s", subdir, fname); h->path = safe_strdup (buf); } else h->path = safe_strdup (fname); entry = safe_calloc(sizeof(struct maildir), 1); entry->h = h; **last = entry; *last = &entry->next; return 0; } return -1; }
static void append_message(CONTEXT *ctx, notmuch_query_t *q, notmuch_message_t *msg, int dedup) { char *newpath = NULL; const char *path; HEADER *h = NULL; /* deduplicate */ if (dedup && get_mutt_header(ctx, msg)) { get_ctxdata(ctx)->ignmsgcount++; nm_progress_update(ctx, q); dprint(2, (debugfile, "nm: ignore id=%s, already in the context\n", notmuch_message_get_message_id(msg))); return; } path = get_message_last_filename(msg); if (!path) return; dprint(2, (debugfile, "nm: appending message, i=%d, id=%s, path=%s\n", ctx->msgcount, notmuch_message_get_message_id(msg), path)); if (ctx->msgcount >= ctx->hdrmax) { dprint(2, (debugfile, "nm: allocate mx memory\n")); mx_alloc_memory(ctx); } if (access(path, F_OK) == 0) h = maildir_parse_message(M_MAILDIR, path, 0, NULL); else { /* maybe moved try find it... */ char *folder = get_folder_from_path(path); if (folder) { FILE *f = maildir_open_find_message(folder, path, &newpath); if (f) { h = maildir_parse_stream(M_MAILDIR, f, newpath, 0, NULL); fclose(f); dprint(1, (debugfile, "nm: not up-to-date: %s -> %s\n", path, newpath)); } } FREE(&folder); } if (!h) { dprint(1, (debugfile, "nm: failed to parse message: %s\n", path)); goto done; } if (init_header(h, newpath ? newpath : path, msg) != 0) { mutt_free_header(&h); dprint(1, (debugfile, "nm: failed to append header!\n")); goto done; } h->active = 1; h->index = ctx->msgcount; ctx->size += h->content->length + h->content->offset - h->content->hdr_offset; ctx->hdrs[ctx->msgcount] = h; ctx->msgcount++; if (newpath) { /* remember that file has been moved -- nm_sync() will update the DB */ struct nm_hdrdata *hd = (struct nm_hdrdata *) h->data; if (hd) { dprint(1, (debugfile, "nm: remember obsolete path: %s\n", path)); hd->oldpath = safe_strdup(path); } } nm_progress_update(ctx, q); done: FREE(&newpath); }