]> granicus.if.org Git - mutt/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)
committerKevin McCarthy <kevin@8t8.us>
Thu, 26 Jul 2018 01:21:40 +0000 (18:21 -0700)
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
mailbox.h
mbox.c
mutt.h
mx.c

index 68a54b7a98808b67797fbed115739ad19549e2f5..a09295d87517368726f92b0a816a1d95abd9b4c4 100644 (file)
@@ -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,
 };
 
index 35fb6013c3d02c570647c486470612e0c99bfeed..6ae29e23631477e21eb06f21bc4c2eda3414d71a 100644 (file)
--- 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 265398ae6bac47ec3c7c053700cc108e662c056c..0f07cc496fa78ddb619eb8732a7508d6ba7ce865 100644 (file)
--- 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 09e381944eddd02367b143df8e2af0756f322bd1..87df6a4a4edc75b71bd3a93fbbb3c44718ab0600 100644 (file)
--- 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 9d21fb184575e29b519ecc6b6a101f3fcd14fed9..c5d86fc590b1e5c955d2163390fbcb76a3e70781 100644 (file)
--- 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: */