From: Kevin McCarthy Date: Thu, 26 Jul 2018 00:52:40 +0000 (-0700) Subject: Add mx_ops.msg_padding_size to return the padding for a mx type X-Git-Tag: 2019-10-25~671^2~15 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=8d63edb8d6764edf5fafb24b4edc65af7e495100;p=neomutt Add mx_ops.msg_padding_size to return the padding for a mx type Mbox pads with a 1 byte, while mmdf pads with 10. Because compress depends on the child type, we create a mx_ops, which allows compress.c to delegate to the child ops. --- diff --git a/compress.c b/compress.c index f77586fc6..b01041d30 100644 --- a/compress.c +++ b/compress.c @@ -892,6 +892,25 @@ int mutt_comp_valid_command(const char *cmd) return strstr(cmd, "%f") && strstr(cmd, "%t"); } +/** + * comp_msg_padding_size - Returns the padding between messages. + */ +static int comp_msg_padding_size(struct Context *ctx) +{ + if (!ctx) + return 0; + + struct CompressInfo *ci = ctx->compress_info; + if (!ci) + return 0; + + struct MxOps *ops = ci->child_ops; + if (!ops || !ops->msg_padding_size) + return 0; + + return ops->msg_padding_size(ctx); +} + /** * comp_path_probe - Is this a compressed mailbox? - Implements MxOps::path_probe */ @@ -969,7 +988,7 @@ int comp_path_parent(char *buf, size_t buflen) // clang-format off /** - * struct mx_comp_ops - Compressed mailbox - Implements ::MxOps + * struct mx_comp_ops - Compressed mailbox - Implements ::MxOps * * Compress only uses open, close and check. * The message functions are delegated to mbox. @@ -986,6 +1005,7 @@ struct MxOps mx_comp_ops = { .msg_open_new = comp_msg_open_new, .msg_commit = comp_msg_commit, .msg_close = comp_msg_close, + .msg_padding_size = comp_msg_padding_size, .tags_edit = NULL, .tags_commit = NULL, .path_probe = comp_path_probe, diff --git a/mbox/mbox.c b/mbox/mbox.c index c99256531..fadc93e83 100644 --- a/mbox/mbox.c +++ b/mbox/mbox.c @@ -604,6 +604,16 @@ static int mbox_msg_open_new(struct Context *ctx, struct Message *msg, struct He return 0; } +static int mbox_msg_padding_size(struct Context *ctx) +{ + return 1; +} + +static int mmdf_msg_padding_size(struct Context *ctx) +{ + return 10; +} + /** * reopen_mailbox - Close and reopen a mailbox * @param ctx Mailbox @@ -1449,6 +1459,7 @@ struct MxOps mx_mbox_ops = { .msg_open_new = mbox_msg_open_new, .msg_commit = mbox_msg_commit, .msg_close = mbox_msg_close, + .msg_padding_size = mbox_msg_padding_size, .tags_edit = NULL, .tags_commit = NULL, .path_probe = mbox_path_probe, @@ -1472,6 +1483,7 @@ struct MxOps mx_mmdf_ops = { .msg_open_new = mbox_msg_open_new, .msg_commit = mmdf_msg_commit, .msg_close = mbox_msg_close, + .msg_padding_size = mmdf_msg_padding_size, .tags_edit = NULL, .tags_commit = NULL, .path_probe = mbox_path_probe, diff --git a/mx.c b/mx.c index ff09e2eca..214ea29e7 100644 --- a/mx.c +++ b/mx.c @@ -1488,3 +1488,17 @@ int mx_path_parent(char *buf, size_t buflen) return 0; } + +/* mx_msg_padding_size: Returns the padding size between messages for the + * mailbox type pointed to by ctx. + * + * mmdf and mbox add separators, which leads a small discrepancy when computing + * vsize for a limited view. + */ +int mx_msg_padding_size(struct Context *ctx) +{ + if (!ctx->mx_ops || !ctx->mx_ops->msg_padding_size) + return 0; + + return ctx->mx_ops->msg_padding_size(ctx); +} diff --git a/mx.h b/mx.h index a1e24e21c..2a5054f14 100644 --- a/mx.h +++ b/mx.h @@ -180,6 +180,7 @@ struct MxOps * @retval 0 Success * @retval -1 Failure */ + int (*msg_padding_size)(struct Context *ctx); int (*tags_edit) (struct Context *ctx, const char *tags, char *buf, size_t buflen); /** * tags_edit - Prompt and validate new messages tags @@ -228,20 +229,21 @@ struct MxOps }; /* Wrappers for the Mailbox API, see MxOps */ -int mx_mbox_check (struct Context *ctx, int *index_hint); -int mx_mbox_close (struct Context **pctx, int *index_hint); -struct Context *mx_mbox_open (const char *path, int flags); -int mx_mbox_sync (struct Context *ctx, int *index_hint); -int mx_msg_close (struct Context *ctx, struct Message **msg); -int mx_msg_commit (struct Context *ctx, struct Message *msg); -struct Message *mx_msg_open_new(struct Context *ctx, struct Header *hdr, int flags); -struct Message *mx_msg_open (struct Context *ctx, int msgno); -int mx_path_canon (char *buf, size_t buflen, const char *folder); -int mx_path_parent (char *buf, size_t buflen); -int mx_path_pretty (char *buf, size_t buflen, const char *folder); -int mx_path_probe (const char *path, const struct stat *st); -int mx_tags_commit (struct Context *ctx, struct Header *hdr, char *tags); -int mx_tags_edit (struct Context *ctx, const char *tags, char *buf, size_t buflen); +int mx_mbox_check (struct Context *ctx, int *index_hint); +int mx_mbox_close (struct Context **pctx, int *index_hint); +struct Context *mx_mbox_open (const char *path, int flags); +int mx_mbox_sync (struct Context *ctx, int *index_hint); +int mx_msg_close (struct Context *ctx, struct Message **msg); +int mx_msg_commit (struct Context *ctx, struct Message *msg); +struct Message *mx_msg_open_new (struct Context *ctx, struct Header *hdr, int flags); +struct Message *mx_msg_open (struct Context *ctx, int msgno); +int mx_msg_padding_size(struct Context *ctx); +int mx_path_canon (char *buf, size_t buflen, const char *folder); +int mx_path_parent (char *buf, size_t buflen); +int mx_path_pretty (char *buf, size_t buflen, const char *folder); +int mx_path_probe (const char *path, const struct stat *st); +int mx_tags_commit (struct Context *ctx, struct Header *hdr, char *tags); +int mx_tags_edit (struct Context *ctx, const char *tags, char *buf, size_t buflen); int mx_access(const char *path, int flags); void mx_alloc_memory(struct Context *ctx);