]> granicus.if.org Git - neomutt/commitdiff
Add mx_ops.msg_padding_size to return the padding for a mx type
authorKevin McCarthy <kevin@8t8.us>
Thu, 26 Jul 2018 00:52:40 +0000 (17:52 -0700)
committerRichard Russon <rich@flatcap.org>
Sat, 1 Sep 2018 17:06:08 +0000 (18:06 +0100)
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.

compress.c
mbox/mbox.c
mx.c
mx.h

index f77586fc6de56c21d3182f7533972df9954b33ce..b01041d3031d251a29f763cd7e049b69c9d5acda 100644 (file)
@@ -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,
index c992565313eacf2f774005976864db38150f80ca..fadc93e83f0773fa8f0c1a0473b24f679f7083ba 100644 (file)
@@ -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 ff09e2ecaedf93d9393f3e3b4e36056432f2f1ec..214ea29e75440727f8ccc43445a95c699d92a02b 100644 (file)
--- 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 a1e24e21cf239b4ef269e6fc8ff7366fd47fdcf2..2a5054f14007ae285d102481812a6017bce6fc47 100644 (file)
--- 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);