/* Read a MH/maildir style mailbox. * * args: * ctx [IN/OUT] context for this mailbox * subdir [IN] NULL for MH mailboxes, otherwise the subdir of the * maildir mailbox to read from */ int mh_read_dir (CONTEXT *ctx, const char *subdir) { struct maildir *md; struct mh_sequences mhs; struct maildir **last; int count; md = NULL; last = &md; count = 0; memset (&mhs, 0, sizeof (mhs)); maildir_update_mtime(ctx); if(maildir_parse_dir(ctx, &last, subdir, &count) == -1) return -1; if (ctx->magic == M_MH) { mh_read_sequences (&mhs, ctx->path); mh_update_maildir (md, &mhs); mhs_free_sequences (&mhs); } maildir_move_to_context(ctx, &md); return 0; }
int mh_sync_mailbox (CONTEXT * ctx, int *index_hint) { char path[_POSIX_PATH_MAX], tmp[_POSIX_PATH_MAX]; int i, j; if ((i = mh_check_mailbox(ctx, index_hint)) != 0) return i; for (i = 0; i < ctx->msgcount; i++) { if (ctx->hdrs[i]->deleted) { snprintf (path, sizeof (path), "%s/%s", ctx->path, ctx->hdrs[i]->path); if (ctx->magic == M_MAILDIR || (option (OPTMHPURGE) && ctx->magic == M_MH)) unlink (path); else if (ctx->magic == M_MH) { /* MH just moves files out of the way when you delete them */ if(*ctx->hdrs[i]->path != ',') { snprintf (tmp, sizeof (tmp), "%s/,%s", ctx->path, ctx->hdrs[i]->path); unlink (tmp); rename (path, tmp); } } } else if (ctx->hdrs[i]->changed || ctx->hdrs[i]->attach_del) { if (ctx->magic == M_MAILDIR) { if (maildir_sync_message (ctx, i) == -1) return -1; } else { if (mh_sync_message (ctx, i) == -1) return -1; } } } /* XXX race condition? */ maildir_update_mtime(ctx); /* adjust indices */ if (ctx->deleted) { for (i = 0, j = 0; i < ctx->msgcount; i++) { if (!ctx->hdrs[i]->deleted) ctx->hdrs[i]->index = j++; } } return 0; }
/* Read a MH/maildir style mailbox. * * args: * ctx [IN/OUT] context for this mailbox * subdir [IN] NULL for MH mailboxes, otherwise the subdir of the * maildir mailbox to read from */ int mh_read_dir (CONTEXT *ctx, const char *subdir) { struct maildir *md; struct maildir **last; int count; md = NULL; last = &md; count = 0; maildir_update_mtime(ctx); if(maildir_parse_dir(ctx, &last, subdir, &count) == -1) return -1; maildir_move_to_context(ctx, &md); return 0; }