From 44108e6ba8c1ff2bf3d671ec9d76386e22522a42 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Fri, 24 Aug 2018 17:09:52 +0100 Subject: [PATCH] fill out mx_path_pretty() --- compress.c | 19 ++++++++++++++++++- imap/imap.c | 14 +++++++++++++- maildir/mh.c | 21 +++++++++++++++++++-- mbox/mbox.c | 21 +++++++++++++++++++-- mutt/path.c | 2 +- mx.c | 19 ++++++++++++++++++- nntp/nntp.c | 11 ++++++++++- notmuch/mutt_notmuch.c | 11 ++++++++++- pop/pop.c | 11 ++++++++++- 9 files changed, 118 insertions(+), 11 deletions(-) diff --git a/compress.c b/compress.c index 578ceafa7..4798e7e88 100644 --- a/compress.c +++ b/compress.c @@ -930,6 +930,23 @@ int comp_path_canon(char *buf, size_t buflen, const char *folder) return 0; } +/** + * comp_path_pretty - Implements MxOps::path_pretty + */ +int comp_path_pretty(char *buf, size_t buflen, const char *folder) +{ + if (!buf) + return -1; + + if (mutt_path_abbr_folder(buf, buflen, folder)) + return 0; + + if (mutt_path_pretty(buf, buflen, HomeDir)) + return 0; + + return -1; +} + // clang-format off /** * struct mx_comp_ops - Mailbox callback functions for compressed mailboxes @@ -953,6 +970,6 @@ struct MxOps mx_comp_ops = { .tags_commit = NULL, .path_probe = comp_path_probe, .path_canon = comp_path_canon, - .path_pretty = NULL, + .path_pretty = comp_path_pretty, }; // clang-format on diff --git a/imap/imap.c b/imap/imap.c index df1ebd7a5..b0490b96e 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -2762,6 +2762,18 @@ int imap_path_canon(char *buf, size_t buflen, const char *folder) return imap_expand_path(buf, buflen); } +/** + * imap_path_pretty - Implements MxOps::path_pretty + */ +int imap_path_pretty(char *buf, size_t buflen, const char *folder) +{ + if (!buf || !folder) + return -1; + + imap_pretty_mailbox(buf, folder); + return 0; +} + // clang-format off /** * struct mx_imap_ops - Mailbox callback functions for IMAP mailboxes @@ -2782,6 +2794,6 @@ struct MxOps mx_imap_ops = { .tags_commit = imap_tags_commit, .path_probe = imap_path_probe, .path_canon = imap_path_canon, - .path_pretty = NULL, + .path_pretty = imap_path_pretty, }; // clang-format on diff --git a/maildir/mh.c b/maildir/mh.c index db1d2a5cf..49e88746a 100644 --- a/maildir/mh.c +++ b/maildir/mh.c @@ -2972,6 +2972,23 @@ int maildir_path_canon(char *buf, size_t buflen, const char *folder) return 0; } +/** + * maildir_path_pretty - Implements MxOps::path_pretty + */ +int maildir_path_pretty(char *buf, size_t buflen, const char *folder) +{ + if (!buf) + return -1; + + if (mutt_path_abbr_folder(buf, buflen, folder)) + return 0; + + if (mutt_path_pretty(buf, buflen, HomeDir)) + return 0; + + return -1; +} + // clang-format off /** * struct mx_maildir_ops - Mailbox callback functions for Maildir mailboxes @@ -2992,7 +3009,7 @@ struct MxOps mx_maildir_ops = { .tags_commit = NULL, .path_probe = maildir_path_probe, .path_canon = maildir_path_canon, - .path_pretty = NULL, + .path_pretty = maildir_path_pretty, }; /** @@ -3014,6 +3031,6 @@ struct MxOps mx_mh_ops = { .tags_commit = NULL, .path_probe = mh_path_probe, .path_canon = maildir_path_canon, - .path_pretty = NULL, + .path_pretty = maildir_path_pretty, }; // clang-format on diff --git a/mbox/mbox.c b/mbox/mbox.c index 98edca009..d57a9c305 100644 --- a/mbox/mbox.c +++ b/mbox/mbox.c @@ -1397,6 +1397,23 @@ int mbox_path_canon(char *buf, size_t buflen, const char *folder) return 0; } +/** + * mbox_path_pretty - Implements MxOps::path_pretty + */ +int mbox_path_pretty(char *buf, size_t buflen, const char *folder) +{ + if (!buf) + return -1; + + if (mutt_path_abbr_folder(buf, buflen, folder)) + return 0; + + if (mutt_path_pretty(buf, buflen, HomeDir)) + return 0; + + return -1; +} + // clang-format off /** * struct mx_mbox_ops - Mailbox callback functions for mbox mailboxes @@ -1417,7 +1434,7 @@ struct MxOps mx_mbox_ops = { .tags_commit = NULL, .path_probe = mbox_path_probe, .path_canon = mbox_path_canon, - .path_pretty = NULL, + .path_pretty = mbox_path_pretty, }; /** @@ -1439,6 +1456,6 @@ struct MxOps mx_mmdf_ops = { .tags_commit = NULL, .path_probe = mbox_path_probe, .path_canon = mbox_path_canon, - .path_pretty = NULL, + .path_pretty = mbox_path_pretty, }; // clang-format on diff --git a/mutt/path.c b/mutt/path.c index fac54781d..927214b61 100644 --- a/mutt/path.c +++ b/mutt/path.c @@ -350,7 +350,7 @@ char *mutt_path_concat(char *d, const char *dir, const char *fname, size_t l) * The slash is omitted when dir or fname is of 0 length. */ char *mutt_path_concatn(char *dst, size_t dstlen, const char *dir, - size_t dirlen, const char *fname, size_t fnamelen) + size_t dirlen, const char *fname, size_t fnamelen) { size_t req; size_t offset = 0; diff --git a/mx.c b/mx.c index c6be439e5..ec653a23a 100644 --- a/mx.c +++ b/mx.c @@ -1648,5 +1648,22 @@ int mx_path_canon(char *buf, size_t buflen, const char *folder) */ int mx_path_pretty(char *buf, size_t buflen, const char *folder) { - return -1; + int magic = mx_path_probe(buf, NULL); + const struct MxOps *ops = mx_get_ops(magic); + if (!ops) + return -1; + + if (!ops->path_canon) + return -1; + + if (ops->path_canon(buf, buflen, folder) < 0) + return -1; + + if (!ops->path_pretty) + return -1; + + if (ops->path_pretty(buf, buflen, folder) < 0) + return -1; + + return 0; } diff --git a/nntp/nntp.c b/nntp/nntp.c index a085a68a3..14a7355dc 100644 --- a/nntp/nntp.c +++ b/nntp/nntp.c @@ -2668,6 +2668,15 @@ int nntp_path_canon(char *buf, size_t buflen, const char *folder) return 0; } +/** + * nntp_path_pretty - Implements MxOps::path_pretty + */ +int nntp_path_pretty(char *buf, size_t buflen, const char *folder) +{ + /* Succeed, but don't do anything, for now */ + return 0; +} + // clang-format off /** * struct mx_nntp_ops - Mailbox callback functions for NNTP mailboxes @@ -2688,6 +2697,6 @@ struct MxOps mx_nntp_ops = { .tags_commit = NULL, .path_probe = nntp_path_probe, .path_canon = nntp_path_canon, - .path_pretty = NULL, + .path_pretty = nntp_path_pretty, }; // clang-format on diff --git a/notmuch/mutt_notmuch.c b/notmuch/mutt_notmuch.c index 7468becb5..f5acdd863 100644 --- a/notmuch/mutt_notmuch.c +++ b/notmuch/mutt_notmuch.c @@ -2803,6 +2803,15 @@ int nm_path_canon(char *buf, size_t buflen, const char *folder) return 0; } +/** + * nm_path_pretty - Implements MxOps::path_pretty + */ +int nm_path_pretty(char *buf, size_t buflen, const char *folder) +{ + /* Succeed, but don't do anything, for now */ + return 0; +} + // clang-format off /** * struct mx_notmuch_ops - Mailbox callback functions for Notmuch mailboxes @@ -2823,6 +2832,6 @@ struct MxOps mx_notmuch_ops = { .tags_commit = nm_tags_commit, .path_probe = nm_path_probe, .path_canon = nm_path_canon, - .path_pretty = NULL, + .path_pretty = nm_path_pretty, }; // clang-format on diff --git a/pop/pop.c b/pop/pop.c index 16b7d0081..2d303e681 100644 --- a/pop/pop.c +++ b/pop/pop.c @@ -1099,6 +1099,15 @@ int pop_path_canon(char *buf, size_t buflen, const char *folder) return 0; } +/** + * pop_path_pretty - Implements MxOps::path_pretty + */ +int pop_path_pretty(char *buf, size_t buflen, const char *folder) +{ + /* Succeed, but don't do anything, for now */ + return 0; +} + // clang-format off /** * mx_pop_ops - Mailbox callback functions for POP mailboxes @@ -1119,6 +1128,6 @@ struct MxOps mx_pop_ops = { .tags_commit = NULL, .path_probe = pop_path_probe, .path_canon = pop_path_canon, - .path_pretty = NULL, + .path_pretty = pop_path_pretty, }; // clang-format on -- 2.40.0