From 68d1a0effc3b2b57a2f7bf2d604deceff9c103b0 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Mon, 15 Oct 2018 16:04:56 +0100 Subject: [PATCH] add MaildirMboxData --- maildir/maildir.h | 22 +++++++++++----------- maildir/mh.c | 48 ++++++++++++++++++++++++----------------------- 2 files changed, 36 insertions(+), 34 deletions(-) diff --git a/maildir/maildir.h b/maildir/maildir.h index 140d70c12..48799a107 100644 --- a/maildir/maildir.h +++ b/maildir/maildir.h @@ -55,24 +55,24 @@ extern char *MhSeqUnseen; extern struct MxOps mx_maildir_ops; extern struct MxOps mx_mh_ops; -int maildir_check_empty(const char *path); -void maildir_gen_flags(char *dest, size_t destlen, struct Email *e); -FILE * maildir_open_find_message(const char *folder, const char *msg, char **newname); -void maildir_parse_flags(struct Email *e, const char *path); +int maildir_check_empty(const char *path); +void maildir_gen_flags(char *dest, size_t destlen, struct Email *e); +FILE * maildir_open_find_message(const char *folder, const char *msg, char **newname); +void maildir_parse_flags(struct Email *e, const char *path); struct Email *maildir_parse_message(enum MailboxType magic, const char *fname, bool is_old, struct Email *e); struct Email *maildir_parse_stream(enum MailboxType magic, FILE *f, const char *fname, bool is_old, struct Email *e); -bool maildir_update_flags(struct Context *ctx, struct Email *o, struct Email *n); +bool maildir_update_flags(struct Context *ctx, struct Email *o, struct Email *n); -bool mh_mailbox(struct Mailbox *mailbox, bool check_stats); -int mh_check_empty(const char *path); +bool mh_mailbox(struct Mailbox *mailbox, bool check_stats); +int mh_check_empty(const char *path); -int maildir_path_probe(const char *path, const struct stat *st); -int mh_path_probe(const char *path, const struct stat *st); +int maildir_path_probe(const char *path, const struct stat *st); +int mh_path_probe(const char *path, const struct stat *st); #ifdef USE_HCACHE -int mh_sync_mailbox_message(struct Context *ctx, int msgno, header_cache_t *hc); +int mh_sync_mailbox_message(struct Context *ctx, int msgno, header_cache_t *hc); #else -int mh_sync_mailbox_message(struct Context *ctx, int msgno); +int mh_sync_mailbox_message(struct Context *ctx, int msgno); #endif #endif /* MUTT_MAILDIR_MAILDIR_H */ diff --git a/maildir/mh.c b/maildir/mh.c index bfd30214b..cb0cb4b9e 100644 --- a/maildir/mh.c +++ b/maildir/mh.c @@ -104,22 +104,24 @@ struct MhSequences }; /** - * struct MhData - MH-specific mailbox data + * struct MaildirMboxData - Maildir-specific mailbox data */ -struct MhData +struct MaildirMboxData { struct timespec mtime_cur; mode_t mh_umask; }; /** - * mh_data - Extract the MhData from the mailbox - * @param mailbox Mailbox - * @retval ptr MhData + * maildir_get_mdata - Get the private data for this Mailbox + * @param m Mailbox + * @retval ptr MaildirMboxData */ -static inline struct MhData *mh_data(struct Mailbox *mailbox) +static struct MaildirMboxData *maildir_get_mdata(struct Mailbox *m) { - return mailbox->data; + if (!m || ((m->magic != MUTT_MAILDIR) && (m->magic != MUTT_MH))) + return NULL; + return m->data; } /** @@ -272,9 +274,9 @@ out: */ static inline mode_t mh_umask(struct Mailbox *mailbox) { - struct MhData *data = mh_data(mailbox); - if (data && data->mh_umask) - return data->mh_umask; + struct MaildirMboxData *mdata = maildir_get_mdata(mailbox); + if (mdata && mdata->mh_umask) + return mdata->mh_umask; struct stat st; if (stat(mailbox->path, &st)) @@ -703,20 +705,20 @@ static void maildir_update_mtime(struct Mailbox *mailbox) { char buf[PATH_MAX]; struct stat st; - struct MhData *data = mh_data(mailbox); + struct MaildirMboxData *mdata = maildir_get_mdata(mailbox); if (mailbox->magic == MUTT_MAILDIR) { snprintf(buf, sizeof(buf), "%s/%s", mailbox->path, "cur"); if (stat(buf, &st) == 0) - mutt_get_stat_timespec(&data->mtime_cur, &st, MUTT_STAT_MTIME); + mutt_get_stat_timespec(&mdata->mtime_cur, &st, MUTT_STAT_MTIME); snprintf(buf, sizeof(buf), "%s/%s", mailbox->path, "new"); } else { snprintf(buf, sizeof(buf), "%s/.mh_sequences", mailbox->path); if (stat(buf, &st) == 0) - mutt_get_stat_timespec(&data->mtime_cur, &st, MUTT_STAT_MTIME); + mutt_get_stat_timespec(&mdata->mtime_cur, &st, MUTT_STAT_MTIME); mutt_str_strfcpy(buf, mailbox->path, sizeof(buf)); } @@ -1239,9 +1241,9 @@ static int mh_read_dir(struct Context *ctx, const char *subdir) if (!ctx->mailbox->data) { - ctx->mailbox->data = mutt_mem_calloc(1, sizeof(struct MhData)); + ctx->mailbox->data = mutt_mem_calloc(1, sizeof(struct MaildirMboxData)); } - struct MhData *data = mh_data(ctx->mailbox); + struct MaildirMboxData *mdata = maildir_get_mdata(ctx->mailbox); maildir_update_mtime(ctx->mailbox); @@ -1271,8 +1273,8 @@ static int mh_read_dir(struct Context *ctx, const char *subdir) maildir_move_to_context(ctx, &md); - if (!data->mh_umask) - data->mh_umask = mh_umask(ctx->mailbox); + if (!mdata->mh_umask) + mdata->mh_umask = mh_umask(ctx->mailbox); return 0; } @@ -2395,7 +2397,7 @@ static int maildir_mbox_check(struct Context *ctx, int *index_hint) int count = 0; struct Hash *fnames = NULL; /* hash table for quickly looking up the base filename for a maildir message */ - struct MhData *data = mh_data(ctx->mailbox); + struct MaildirMboxData *mdata = maildir_get_mdata(ctx->mailbox); /* XXX seems like this check belongs in mx_mbox_check() rather than here. */ if (!CheckNew) @@ -2419,7 +2421,7 @@ static int maildir_mbox_check(struct Context *ctx, int *index_hint) /* determine which subdirectories need to be scanned */ if (mutt_stat_timespec_compare(&st_new, MUTT_STAT_MTIME, &ctx->mailbox->mtime) > 0) changed = 1; - if (mutt_stat_timespec_compare(&st_cur, MUTT_STAT_MTIME, &data->mtime_cur) > 0) + if (mutt_stat_timespec_compare(&st_cur, MUTT_STAT_MTIME, &mdata->mtime_cur) > 0) changed |= 2; if (!changed) @@ -2440,7 +2442,7 @@ static int maildir_mbox_check(struct Context *ctx, int *index_hint) else #endif { - mutt_get_stat_timespec(&data->mtime_cur, &st_cur, MUTT_STAT_MTIME); + mutt_get_stat_timespec(&mdata->mtime_cur, &st_cur, MUTT_STAT_MTIME); mutt_get_stat_timespec(&ctx->mailbox->mtime, &st_new, MUTT_STAT_MTIME); } @@ -2776,7 +2778,7 @@ static int mh_mbox_check(struct Context *ctx, int *index_hint) struct MhSequences mhs = { 0 }; int count = 0; struct Hash *fnames = NULL; - struct MhData *data = mh_data(ctx->mailbox); + struct MaildirMboxData *mdata = maildir_get_mdata(ctx->mailbox); if (!CheckNew) return 0; @@ -2806,7 +2808,7 @@ static int mh_mbox_check(struct Context *ctx, int *index_hint) modified = true; if ((mutt_stat_timespec_compare(&st, MUTT_STAT_MTIME, &ctx->mailbox->mtime) > 0) || - (mutt_stat_timespec_compare(&st_cur, MUTT_STAT_MTIME, &data->mtime_cur) > 0)) + (mutt_stat_timespec_compare(&st_cur, MUTT_STAT_MTIME, &mdata->mtime_cur) > 0)) { modified = true; } @@ -2826,7 +2828,7 @@ static int mh_mbox_check(struct Context *ctx, int *index_hint) else #endif { - mutt_get_stat_timespec(&data->mtime_cur, &st_cur, MUTT_STAT_MTIME); + mutt_get_stat_timespec(&mdata->mtime_cur, &st_cur, MUTT_STAT_MTIME); mutt_get_stat_timespec(&ctx->mailbox->mtime, &st, MUTT_STAT_MTIME); } -- 2.50.0