]> granicus.if.org Git - neomutt/commitdiff
add MxOps:path_parent()
authorRichard Russon <rich@flatcap.org>
Sat, 25 Aug 2018 12:35:03 +0000 (13:35 +0100)
committerRichard Russon <rich@flatcap.org>
Sun, 26 Aug 2018 21:11:03 +0000 (22:11 +0100)
compress.c
imap/imap.c
maildir/mh.c
mbox/mbox.c
mx.c
mx.h
nntp/nntp.c
notmuch/mutt_notmuch.c
pop/pop.c

index 4798e7e8862d76a4a82d0e11e1fba4ab09e622ad..7deccc67293c6f0cb794ca99a909d93838aed9c7 100644 (file)
@@ -947,6 +947,26 @@ int comp_path_pretty(char *buf, size_t buflen, const char *folder)
   return -1;
 }
 
+/**
+ * comp_path_parent - Implements MxOps::path_parent
+ */
+int comp_path_parent(char *buf, size_t buflen)
+{
+  if (!buf)
+    return -1;
+
+  if (mutt_path_parent(buf, buflen))
+    return 0;
+
+  if (buf[0] == '~')
+    mutt_path_canon(buf, buflen, HomeDir);
+
+  if (mutt_path_parent(buf, buflen))
+    return 0;
+
+  return -1;
+}
+
 // clang-format off
 /**
  * struct mx_comp_ops - Mailbox callback functions for compressed mailboxes
@@ -971,5 +991,6 @@ struct MxOps mx_comp_ops = {
   .path_probe       = comp_path_probe,
   .path_canon       = comp_path_canon,
   .path_pretty      = comp_path_pretty,
+  .path_parent      = comp_path_parent,
 };
 // clang-format on
index b0490b96e6e89f7f42481d5fe7647ed677c7bc27..da4ea6379004c8eca36e5ccd956acdf02abd9d7d 100644 (file)
@@ -2774,6 +2774,18 @@ int imap_path_pretty(char *buf, size_t buflen, const char *folder)
   return 0;
 }
 
+/**
+ * imap_path_parent - Implements MxOps::path_parent
+ */
+int imap_path_parent(char *buf, size_t buflen)
+{
+  char tmp[PATH_MAX] = { 0 };
+
+  imap_get_parent_path(buf, tmp, sizeof(tmp));
+  mutt_str_strfcpy(buf, tmp, buflen);
+  return 0;
+}
+
 // clang-format off
 /**
  * struct mx_imap_ops - Mailbox callback functions for IMAP mailboxes
@@ -2795,5 +2807,6 @@ struct MxOps mx_imap_ops = {
   .path_probe       = imap_path_probe,
   .path_canon       = imap_path_canon,
   .path_pretty      = imap_path_pretty,
+  .path_parent      = imap_path_parent,
 };
 // clang-format on
index 49e88746af77bc1ebe1178ccb59917f9c57e04b2..3e8597cf0356b55780e2bfa85c98dfa814c44b39 100644 (file)
@@ -2989,6 +2989,26 @@ int maildir_path_pretty(char *buf, size_t buflen, const char *folder)
   return -1;
 }
 
+/**
+ * maildir_path_parent - Implements MxOps::path_parent
+ */
+int maildir_path_parent(char *buf, size_t buflen)
+{
+  if (!buf)
+    return -1;
+
+  if (mutt_path_parent(buf, buflen))
+    return 0;
+
+  if (buf[0] == '~')
+    mutt_path_canon(buf, buflen, HomeDir);
+
+  if (mutt_path_parent(buf, buflen))
+    return 0;
+
+  return -1;
+}
+
 // clang-format off
 /**
  * struct mx_maildir_ops - Mailbox callback functions for Maildir mailboxes
@@ -3010,6 +3030,7 @@ struct MxOps mx_maildir_ops = {
   .path_probe       = maildir_path_probe,
   .path_canon       = maildir_path_canon,
   .path_pretty      = maildir_path_pretty,
+  .path_parent      = maildir_path_parent,
 };
 
 /**
@@ -3032,5 +3053,6 @@ struct MxOps mx_mh_ops = {
   .path_probe       = mh_path_probe,
   .path_canon       = maildir_path_canon,
   .path_pretty      = maildir_path_pretty,
+  .path_parent      = maildir_path_parent,
 };
 // clang-format on
index d57a9c30537f48265e4c74240a0160788341c36b..fc2f6e8e3392e11b4e83a00fd57bd5a4754c1e55 100644 (file)
@@ -1414,6 +1414,26 @@ int mbox_path_pretty(char *buf, size_t buflen, const char *folder)
   return -1;
 }
 
+/**
+ * mbox_path_parent - Implements MxOps::path_parent
+ */
+int mbox_path_parent(char *buf, size_t buflen)
+{
+  if (!buf)
+    return -1;
+
+  if (mutt_path_parent(buf, buflen))
+    return 0;
+
+  if (buf[0] == '~')
+    mutt_path_canon(buf, buflen, HomeDir);
+
+  if (mutt_path_parent(buf, buflen))
+    return 0;
+
+  return -1;
+}
+
 // clang-format off
 /**
  * struct mx_mbox_ops - Mailbox callback functions for mbox mailboxes
@@ -1435,6 +1455,7 @@ struct MxOps mx_mbox_ops = {
   .path_probe       = mbox_path_probe,
   .path_canon       = mbox_path_canon,
   .path_pretty      = mbox_path_pretty,
+  .path_parent      = mbox_path_parent,
 };
 
 /**
@@ -1457,5 +1478,6 @@ struct MxOps mx_mmdf_ops = {
   .path_probe       = mbox_path_probe,
   .path_canon       = mbox_path_canon,
   .path_pretty      = mbox_path_pretty,
+  .path_parent      = mbox_path_parent,
 };
 // clang-format on
diff --git a/mx.c b/mx.c
index ec653a23a7a4d474fbb4ce0f65118db87efea356..d5185336e82e1c103d1d2c6b7af66ef92df41977 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -1667,3 +1667,14 @@ int mx_path_pretty(char *buf, size_t buflen, const char *folder)
 
   return 0;
 }
+
+/**
+ * mx_path_parent - Find the parent of a mailbox path - Wrapper for MxOps::path_parent
+ */
+int mx_path_parent(char *buf, size_t buflen)
+{
+  if (!buf)
+    return -1;
+
+  return 0;
+}
diff --git a/mx.h b/mx.h
index 1b7babfff4921defd9a01298c63785176334dbe0..7ea7be1c6fdbe273aba79e7c15ad90ea4cd14e3a 100644 (file)
--- a/mx.h
+++ b/mx.h
@@ -170,6 +170,14 @@ struct MxOps
    * @retval -1 Failure
    */
   int (*path_pretty)     (char *buf, size_t buflen, const char *folder);
+  /**
+   * path_parent - Find the parent of a mailbox path
+   * @param buf    Path to modify
+   * @param buflen Length of buffer
+   * @retval  0 Success
+   * @retval -1 Failure
+   */
+  int (*path_parent)     (char *buf, size_t buflen);
 };
 
 #ifdef USE_NOTMUCH
@@ -234,19 +242,23 @@ struct Message
 };
 
 /* The Mailbox API, see MxOps */
-struct Context *mx_mbox_open   (const char *path, int flags, struct Context *pctx);
 int             mx_mbox_check  (struct Context *ctx, int *index_hint);
-int             mx_mbox_sync   (struct Context *ctx, int *index_hint);
 int             mx_mbox_close  (struct Context *ctx, int *index_hint);
-struct Message *mx_msg_open    (struct Context *ctx, int msgno);
-struct Message *mx_msg_open_new(struct Context *ctx, struct Header *hdr, int flags);
-int             mx_msg_commit  (struct Context *ctx, struct Message *msg);
+struct Context *mx_mbox_open   (const char *path, int flags, struct Context *pctx);
+int             mx_mbox_sync   (struct Context *ctx, int *index_hint);
+
 int             mx_msg_close   (struct Context *ctx, struct Message **msg);
-int             mx_tags_edit   (struct Context *ctx, const char *tags, char *buf, size_t buflen);
-int             mx_tags_commit (struct Context *ctx, struct Header *hdr, char *tags);
-int             mx_path_probe  (const char *path, const struct stat *st);
+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);
 
 void mx_fastclose_mailbox(struct Context *ctx);
 
index 14a7355dc52dad5069a0bccabb0e3d4d2f740ef1..c3c9283c3c36a646aae1c8eb0a5d87eab9e170eb 100644 (file)
@@ -2677,6 +2677,15 @@ int nntp_path_pretty(char *buf, size_t buflen, const char *folder)
   return 0;
 }
 
+/**
+ * nntp_path_parent - Implements MxOps::path_parent
+ */
+int nntp_path_parent(char *buf, size_t buflen)
+{
+  /* Succeed, but don't do anything, for now */
+  return 0;
+}
+
 // clang-format off
 /**
  * struct mx_nntp_ops - Mailbox callback functions for NNTP mailboxes
@@ -2698,5 +2707,6 @@ struct MxOps mx_nntp_ops = {
   .path_probe       = nntp_path_probe,
   .path_canon       = nntp_path_canon,
   .path_pretty      = nntp_path_pretty,
+  .path_parent      = nntp_path_parent,
 };
 // clang-format on
index f5acdd863d6cbb6001b2a5346ed4008e94c52101..add93fe9fb6a8ae58436d60425bbc8b3fedc31c4 100644 (file)
@@ -2812,6 +2812,15 @@ int nm_path_pretty(char *buf, size_t buflen, const char *folder)
   return 0;
 }
 
+/**
+ * nm_path_parent - Implements MxOps::path_parent
+ */
+int nm_path_parent(char *buf, size_t buflen)
+{
+  /* Succeed, but don't do anything, for now */
+  return 0;
+}
+
 // clang-format off
 /**
  * struct mx_notmuch_ops - Mailbox callback functions for Notmuch mailboxes
@@ -2833,5 +2842,6 @@ struct MxOps mx_notmuch_ops = {
   .path_probe       = nm_path_probe,
   .path_canon       = nm_path_canon,
   .path_pretty      = nm_path_pretty,
+  .path_parent      = nm_path_parent,
 };
 // clang-format on
index 2d303e6816002f6d6b112974a715ec53bc4cdee7..d4a86217ea9b4a5ff38b69e8c410b8dac8103ac7 100644 (file)
--- a/pop/pop.c
+++ b/pop/pop.c
@@ -1108,6 +1108,15 @@ int pop_path_pretty(char *buf, size_t buflen, const char *folder)
   return 0;
 }
 
+/**
+ * pop_path_parent - Implements MxOps::path_parent
+ */
+int pop_path_parent(char *buf, size_t buflen)
+{
+  /* Succeed, but don't do anything, for now */
+  return 0;
+}
+
 // clang-format off
 /**
  * mx_pop_ops - Mailbox callback functions for POP mailboxes
@@ -1129,5 +1138,6 @@ struct MxOps mx_pop_ops = {
   .path_probe       = pop_path_probe,
   .path_canon       = pop_path_canon,
   .path_pretty      = pop_path_pretty,
+  .path_parent      = pop_path_parent,
 };
 // clang-format on