From 93101e24d40387124515d55d00fc65d1dd43e23c Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Sat, 25 Aug 2018 13:35:03 +0100 Subject: [PATCH] add MxOps:path_parent() --- compress.c | 21 +++++++++++++++++++++ imap/imap.c | 13 +++++++++++++ maildir/mh.c | 22 ++++++++++++++++++++++ mbox/mbox.c | 22 ++++++++++++++++++++++ mx.c | 11 +++++++++++ mx.h | 28 ++++++++++++++++++++-------- nntp/nntp.c | 10 ++++++++++ notmuch/mutt_notmuch.c | 10 ++++++++++ pop/pop.c | 10 ++++++++++ 9 files changed, 139 insertions(+), 8 deletions(-) diff --git a/compress.c b/compress.c index 4798e7e88..7deccc672 100644 --- a/compress.c +++ b/compress.c @@ -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 diff --git a/imap/imap.c b/imap/imap.c index b0490b96e..da4ea6379 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -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 diff --git a/maildir/mh.c b/maildir/mh.c index 49e88746a..3e8597cf0 100644 --- a/maildir/mh.c +++ b/maildir/mh.c @@ -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 diff --git a/mbox/mbox.c b/mbox/mbox.c index d57a9c305..fc2f6e8e3 100644 --- a/mbox/mbox.c +++ b/mbox/mbox.c @@ -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 ec653a23a..d5185336e 100644 --- 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 1b7babfff..7ea7be1c6 100644 --- 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); diff --git a/nntp/nntp.c b/nntp/nntp.c index 14a7355dc..c3c9283c3 100644 --- a/nntp/nntp.c +++ b/nntp/nntp.c @@ -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 diff --git a/notmuch/mutt_notmuch.c b/notmuch/mutt_notmuch.c index f5acdd863..add93fe9f 100644 --- a/notmuch/mutt_notmuch.c +++ b/notmuch/mutt_notmuch.c @@ -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 diff --git a/pop/pop.c b/pop/pop.c index 2d303e681..d4a86217e 100644 --- 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 -- 2.40.0