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: mutt-1-11-rel~107 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=9806d24984eeb09d249d25a8654626c713edb180;p=mutt 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 68a54b7a..a09295d8 100644 --- a/compress.c +++ b/compress.c @@ -939,6 +939,29 @@ mutt_comp_valid_command (const char *cmd) return (strstr (cmd, "%f") && strstr (cmd, "%t")); } +/** + * compress_msg_padding_size - Returns the padding between messages. + */ +static int +compress_msg_padding_size (CONTEXT *ctx) +{ + COMPRESS_INFO *ci; + struct mx_ops *ops; + + if (!ctx) + return 0; + + ci = ctx->compress_info; + if (!ci) + return 0; + + ops = ci->child_ops; + if (!ops || !ops->msg_padding_size) + return 0; + + return ops->msg_padding_size (ctx); +} + /** * mx_comp_ops - Mailbox callback functions @@ -956,6 +979,7 @@ struct mx_ops mx_comp_ops = .open_msg = open_message, .close_msg = close_message, .commit_msg = commit_message, - .open_new_msg = open_new_message + .open_new_msg = open_new_message, + .msg_padding_size = compress_msg_padding_size, }; diff --git a/mailbox.h b/mailbox.h index 35fb6013..6ae29e23 100644 --- a/mailbox.h +++ b/mailbox.h @@ -81,6 +81,7 @@ int mx_is_pop (const char *); int mx_access (const char*, int); int mx_check_empty (const char *); +int mx_msg_padding_size (CONTEXT *); int mx_is_maildir (const char *); int mx_is_mh (const char *); diff --git a/mbox.c b/mbox.c index 265398ae..0f07cc49 100644 --- a/mbox.c +++ b/mbox.c @@ -1385,6 +1385,16 @@ int mbox_check_empty (const char *path) return ((st.st_size == 0)); } +static int mbox_msg_padding_size (CONTEXT *ctx) +{ + return 1; +} + +static int mmdf_msg_padding_size (CONTEXT *ctx) +{ + return 10; +} + struct mx_ops mx_mbox_ops = { .open = mbox_open_mailbox, .open_append = mbox_open_mailbox_append, @@ -1395,6 +1405,7 @@ struct mx_ops mx_mbox_ops = { .open_new_msg = mbox_open_new_message, .check = mbox_check_mailbox, .sync = mbox_sync_mailbox, + .msg_padding_size = mbox_msg_padding_size, }; struct mx_ops mx_mmdf_ops = { @@ -1407,4 +1418,5 @@ struct mx_ops mx_mmdf_ops = { .open_new_msg = mbox_open_new_message, .check = mbox_check_mailbox, .sync = mbox_sync_mailbox, + .msg_padding_size = mmdf_msg_padding_size, }; diff --git a/mutt.h b/mutt.h index 09e38194..87df6a4a 100644 --- a/mutt.h +++ b/mutt.h @@ -979,6 +979,7 @@ struct mx_ops int (*close_msg) (struct _context *, struct _message *); int (*commit_msg) (struct _context *, struct _message *); int (*open_new_msg) (struct _message *, struct _context *, HEADER *); + int (*msg_padding_size) (struct _context *); }; typedef struct _context diff --git a/mx.c b/mx.c index 9d21fb18..c5d86fc5 100644 --- a/mx.c +++ b/mx.c @@ -1504,4 +1504,18 @@ int mx_check_empty (const char *path) /* not reached */ } +/* 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 (CONTEXT *ctx) +{ + if (!ctx->mx_ops || !ctx->mx_ops->msg_padding_size) + return 0; + + return ctx->mx_ops->msg_padding_size (ctx); +} + /* vim: set sw=2: */