changeset: 6748:01541185e6f4 user: Kevin McCarthy <ke...@8t8.us> date: Tue Aug 02 19:18:46 2016 -0700 link: http://dev.mutt.org/hg/mutt/rev/01541185e6f4
Use the ctx->mx_ops instead of calling mx_get_ops() With mx_open_mailbox_append() setting the ctx->mx_ops, all contexts should have mx_ops set. Remove calls to mx_get_ops() and instead directly use ctx->mx_ops. changeset: 6749:f9a4023b86ad user: Kevin McCarthy <ke...@8t8.us> date: Tue Aug 02 19:18:53 2016 -0700 link: http://dev.mutt.org/hg/mutt/rev/f9a4023b86ad Explicitly NULL unimplemented pop mx_ops functions. The struct initialization already does this for unlisted fields, but I'd rather be explicit about unimplemented operations. diffs (111 lines): diff -r e778db6e693c -r f9a4023b86ad mx.c --- a/mx.c Mon Aug 01 18:25:28 2016 -0700 +++ b/mx.c Tue Aug 02 19:18:53 2016 -0700 @@ -1238,14 +1238,10 @@ */ MESSAGE *mx_open_new_message (CONTEXT *dest, HEADER *hdr, int flags) { - /* TODO: Convert this to use dest->mx_ops after - * mx_open_mailbox_append() is changed to set mx_ops. - */ - struct mx_ops *ops = mx_get_ops (dest->magic); ADDRESS *p = NULL; MESSAGE *msg; - if (!ops || !ops->open_new_msg) + if (!dest->mx_ops->open_new_msg) { dprint (1, (debugfile, "mx_open_new_message(): function unimplemented for mailbox type %d.\n", dest->magic)); @@ -1267,7 +1263,7 @@ if(msg->received == 0) time(&msg->received); - if (ops->open_new_msg (msg, dest, hdr) == 0) + if (dest->mx_ops->open_new_msg (msg, dest, hdr) == 0) { if (dest->magic == MUTT_MMDF) fputs (MMDF_SEP, msg->fp); @@ -1297,37 +1293,28 @@ /* check for new mail */ int mx_check_mailbox (CONTEXT *ctx, int *index_hint) { - struct mx_ops *ops; - if (!ctx) { dprint (1, (debugfile, "mx_check_mailbox: null or invalid context.\n")); return -1; } - ops = mx_get_ops (ctx->magic); - if (!ops) - return -1; - - return ops->check (ctx, index_hint); + return ctx->mx_ops->check (ctx, index_hint); } /* return a stream pointer for a message */ MESSAGE *mx_open_message (CONTEXT *ctx, int msgno) { - struct mx_ops *ops = mx_get_ops (ctx->magic); MESSAGE *msg; - int ret; - if (!ops || !ops->open_msg) + if (!ctx->mx_ops->open_msg) { dprint (1, (debugfile, "mx_open_message(): function not implemented for mailbox type %d.\n", ctx->magic)); return NULL; } msg = safe_calloc (1, sizeof (MESSAGE)); - ret = ops->open_msg (ctx, msg, msgno); - if (ret) + if (ctx->mx_ops->open_msg (ctx, msg, msgno)) FREE (&msg); return msg; @@ -1337,9 +1324,7 @@ int mx_commit_message (MESSAGE *msg, CONTEXT *ctx) { - struct mx_ops *ops = mx_get_ops (ctx->magic); - - if (!ops || !ops->commit_msg) + if (!ctx->mx_ops->commit_msg) return -1; if (!(msg->write && ctx->append)) @@ -1349,17 +1334,16 @@ return -1; } - return ops->commit_msg (ctx, msg); + return ctx->mx_ops->commit_msg (ctx, msg); } /* close a pointer to a message */ int mx_close_message (CONTEXT *ctx, MESSAGE **msg) { - struct mx_ops *ops = mx_get_ops (ctx->magic); int r = 0; - if (ops && ops->close_msg) - r = ops->close_msg (ctx, *msg); + if (ctx->mx_ops->close_msg) + r = ctx->mx_ops->close_msg (ctx, *msg); if ((*msg)->path) { diff -r e778db6e693c -r f9a4023b86ad pop.c --- a/pop.c Mon Aug 01 18:25:28 2016 -0700 +++ b/pop.c Tue Aug 02 19:18:53 2016 -0700 @@ -942,4 +942,6 @@ .open_msg = pop_fetch_message, .close_msg = pop_close_message, .check = pop_check_mailbox, + .commit_msg = NULL, + .open_new_msg = NULL, };