From b2e02f2b15a76db85655d1d5772a0f17b3ef8ca6 Mon Sep 17 00:00:00 2001 From: Thomas Roessler Date: Tue, 4 Sep 2001 09:30:04 +0000 Subject: [PATCH] patch-bac.canonifypath-4. The attached patch reverts the IMAP canonification patch I reverted a version ago (sorry for being so wishy-washy). This time I put in some code to preserve IMAP URL passwords in the initial pass, so people who like to use those sorts of URLs still can. That was the only reason I had reverted the patch before. (From Brendan Cully.) --- imap/util.c | 6 +++--- mutt_socket.c | 2 +- muttlib.c | 7 +++++++ pop.c | 2 +- url.c | 14 +++++++++----- url.h | 4 +++- 6 files changed, 24 insertions(+), 11 deletions(-) diff --git a/imap/util.c b/imap/util.c index 64d9dfe37..7f88dbac9 100644 --- a/imap/util.c +++ b/imap/util.c @@ -58,7 +58,7 @@ int imap_expand_path (char* path, size_t len) mutt_account_tourl (&mx.account, &url); url.path = mx.mbox; - rc = url_ciss_tostring (&url, path, len); + rc = url_ciss_tostring (&url, path, len, U_DECODE_PASSWD); FREE (&mx.mbox); return rc; @@ -223,7 +223,7 @@ void imap_pretty_mailbox (char* path) /* FIXME: That hard-coded constant is bogus. But we need the actual * size of the buffer from mutt_pretty_mailbox. And these pretty * operations usually shrink the result. Still... */ - url_ciss_tostring (&url, path, 1024); + url_ciss_tostring (&url, path, 1024, 0); } FREE (&target.mbox); @@ -426,7 +426,7 @@ void imap_qualify_path (char *dest, size_t len, IMAP_MBOX *mx, char* path) mutt_account_tourl (&mx->account, &url); url.path = path; - url_ciss_tostring (&url, dest, len); + url_ciss_tostring (&url, dest, len, 0); } diff --git a/mutt_socket.c b/mutt_socket.c index 5f43fdc81..eaeeffbfb 100644 --- a/mutt_socket.c +++ b/mutt_socket.c @@ -229,7 +229,7 @@ CONNECTION* mutt_conn_find (const CONNECTION* start, const ACCOUNT* account) /* account isn't actually modified, since url isn't either */ mutt_account_tourl ((ACCOUNT*) account, &url); url.path = NULL; - url_ciss_tostring (&url, hook, sizeof (hook)); + url_ciss_tostring (&url, hook, sizeof (hook), 0); mutt_account_hook (hook); conn = start ? start->next : Connections; diff --git a/muttlib.c b/muttlib.c index 532009b10..7f06f71a2 100644 --- a/muttlib.c +++ b/muttlib.c @@ -461,6 +461,13 @@ char *_mutt_expand_path (char *s, size_t slen, int rx) } while (recurse); +#ifdef USE_IMAP + /* Rewrite IMAP path in canonical form - aids in string comparisons of + * folders. May possibly fail, in which case s should be the same. */ + if (mx_is_imap (s)) + imap_expand_path (s, slen); +#endif + return (s); } diff --git a/pop.c b/pop.c index d4e0c73a4..6d7289d82 100644 --- a/pop.c +++ b/pop.c @@ -246,7 +246,7 @@ int pop_open_mailbox (CONTEXT *ctx) mutt_account_tourl (&acct, &url); url.path = NULL; - url_ciss_tostring (&url, buf, sizeof (buf)); + url_ciss_tostring (&url, buf, sizeof (buf), 0); FREE (&ctx->path); ctx->path = safe_strdup (buf); diff --git a/url.c b/url.c index 450f588ac..289acb971 100644 --- a/url.c +++ b/url.c @@ -164,7 +164,7 @@ int url_parse_ciss (ciss_url_t *ciss, char *src) } /* url_ciss_tostring: output the URL string for a given CISS object. */ -int url_ciss_tostring (ciss_url_t* ciss, char* dest, size_t len) +int url_ciss_tostring (ciss_url_t* ciss, char* dest, size_t len, int flags) { if (ciss->scheme == U_UNKNOWN) return -1; @@ -174,10 +174,14 @@ int url_ciss_tostring (ciss_url_t* ciss, char* dest, size_t len) if (ciss->host) { strncat (dest, "//", len - strlen (dest)); - if (ciss->user) - snprintf (dest + strlen (dest), len - strlen (dest), "%s@", - ciss->user); - /* password deliberately omitted. */ + if (ciss->user) { + if (flags & U_DECODE_PASSWD && ciss->pass) + snprintf (dest + strlen (dest), len - strlen (dest), "%s:%s@", + ciss->user, ciss->pass); + else + snprintf (dest + strlen (dest), len - strlen (dest), "%s@", + ciss->user); + } if (ciss->port) snprintf (dest + strlen (dest), len - strlen (dest), "%s:%hu/", diff --git a/url.h b/url.h index 6d00c096a..0bcc4bdc4 100644 --- a/url.h +++ b/url.h @@ -13,6 +13,8 @@ typedef enum url_scheme } url_scheme_t; +#define U_DECODE_PASSWD (1) + typedef struct ciss_url { url_scheme_t scheme; @@ -27,7 +29,7 @@ ciss_url_t; url_scheme_t url_check_scheme (const char *s); int url_parse_file (char *d, const char *src, size_t dl); int url_parse_ciss (ciss_url_t *ciss, char *src); -int url_ciss_tostring (ciss_url_t* ciss, char* dest, size_t len); +int url_ciss_tostring (ciss_url_t* ciss, char* dest, size_t len, int flags); int url_parse_mailto (ENVELOPE *e, char **body, const char *src); #endif -- 2.40.0