From: Thomas Roessler Date: Mon, 4 Sep 2000 10:49:46 +0000 (+0000) Subject: patch-bac.imapurl-4 X-Git-Tag: mutt-1-3-9-rel~22 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=643690a1274d0598ee973b272c934bb147e6cda4;p=mutt patch-bac.imapurl-4 --- diff --git a/account.c b/account.c index 22a60a73..fc29e86f 100644 --- a/account.c +++ b/account.c @@ -82,6 +82,46 @@ int mutt_account_fromurl (ACCOUNT* account, ciss_url_t* url) return 0; } +/* mutt_account_tourl: fill URL with info from account. The URL information + * is a set of pointers into account - don't free or edit account until + * you've finished with url (make a copy of account if you need it for + * a while). */ +void mutt_account_tourl (ACCOUNT* account, ciss_url_t* url) +{ + url->scheme = U_UNKNOWN; + url->user = NULL; + url->pass = NULL; + url->port = 0; + +#ifdef USE_IMAP + if (account->type == M_ACCT_TYPE_IMAP) + { + if (account->flags & M_ACCT_SSL) + url->scheme = U_IMAPS; + else + url->scheme = U_IMAP; + } +#endif + +#ifdef USE_POP + if (account->type == M_ACCT_TYPE_POP) + { + if (account->flags & M_ACCT_SSL) + url->scheme = U_POPS; + else + url->scheme = U_POP; + } +#endif + + url->host = account->host; + if (account->flags & M_ACCT_PORT) + url->port = account->port; + if (account->flags & M_ACCT_USER) + url->user = account->user; + if (account->flags & M_ACCT_PASS) + url->pass = account->pass; +} + /* mutt_account_getuser: retrieve username into ACCOUNT, if neccessary */ int mutt_account_getuser (ACCOUNT* account) { diff --git a/account.h b/account.h index bae65297..246a04c9 100644 --- a/account.h +++ b/account.h @@ -49,6 +49,7 @@ typedef struct int mutt_account_match (const ACCOUNT* a1, const ACCOUNT* m2); int mutt_account_fromurl (ACCOUNT* account, ciss_url_t* url); +void mutt_account_tourl (ACCOUNT* account, ciss_url_t* url); int mutt_account_getuser (ACCOUNT* account); int mutt_account_getpass (ACCOUNT* account); diff --git a/browser.c b/browser.c index 0f2a7f82..c30bea45 100644 --- a/browser.c +++ b/browser.c @@ -677,6 +677,7 @@ void _mutt_select_file (char *f, size_t flen, int buffy, else if (state.imap_browse) { int n; + ciss_url_t url; strfcpy (LastDir, state.entry[menu->current].name, sizeof (LastDir)); @@ -684,7 +685,8 @@ void _mutt_select_file (char *f, size_t flen, int buffy, n = strlen (LastDir)+1; /* special case "" needs no delimiter */ - if ((strlen (strchr (LastDir, '}')) > 0) && + url_parse_ciss (&url, state.entry[menu->current].name); + if (url.path && (state.entry[menu->current].delim != '\0') && (n < sizeof (LastDir))) { diff --git a/curs_main.c b/curs_main.c index 0006fc98..418a266b 100644 --- a/curs_main.c +++ b/curs_main.c @@ -789,11 +789,6 @@ int mutt_index_menu (void) menu->redraw = REDRAW_FULL; /* new mail arrived? */ set_option (OPTSEARCHINVALID); } - -#ifdef USE_IMAP - /* Close all remaining open connections (frees server resources) */ - imap_logout_all (); -#endif } break; @@ -1040,10 +1035,6 @@ int mutt_index_menu (void) safe_free ((void **) &Context); } done = 1; -#ifdef USE_IMAP - /* Close all open IMAP connections */ - imap_logout_all (); -#endif } break; @@ -1858,6 +1849,11 @@ int mutt_index_menu (void) if (done) break; } +#ifdef USE_IMAP + /* Close all open IMAP connections */ + imap_logout_all (); +#endif + mutt_menuDestroy (&menu); return (close); } diff --git a/imap/browse.c b/imap/browse.c index cfd77c79..cf7c4bc5 100644 --- a/imap/browse.c +++ b/imap/browse.c @@ -133,7 +133,7 @@ int imap_browse (char* path, struct browser_state* state) /* don't show parents in the home namespace */ if (!home_namespace) showparents = 1; - imap_qualify_path (buf, sizeof (buf), &mx, mbox, NULL); + imap_qualify_path (buf, sizeof (buf), &mx, mbox); state->folder = safe_strdup (buf); n--; } @@ -165,7 +165,7 @@ int imap_browse (char* path, struct browser_state* state) mbox[n++] = ctmp; ctmp = mbox[n]; mbox[n] = '\0'; - imap_qualify_path (buf, sizeof (buf), &mx, mbox, NULL); + imap_qualify_path (buf, sizeof (buf), &mx, mbox); state->folder = safe_strdup (buf); } mbox[n] = ctmp; @@ -180,7 +180,7 @@ int imap_browse (char* path, struct browser_state* state) imap_add_folder (idata->delim, relpath, 1, 0, state, 1); if (!state->folder) { - imap_qualify_path (buf, sizeof (buf), &mx, relpath, NULL); + imap_qualify_path (buf, sizeof (buf), &mx, relpath); state->folder = safe_strdup (buf); } } @@ -189,7 +189,7 @@ int imap_browse (char* path, struct browser_state* state) /* no namespace, no folder: set folder to host only */ if (!state->folder) { - imap_qualify_path (buf, sizeof (buf), &mx, NULL, NULL); + imap_qualify_path (buf, sizeof (buf), &mx, NULL); state->folder = safe_strdup (buf); } @@ -362,7 +362,7 @@ static void imap_add_folder (char delim, char *folder, int noselect, return; } - imap_qualify_path (tmp, sizeof (tmp), &mx, folder, NULL); + imap_qualify_path (tmp, sizeof (tmp), &mx, folder); (state->entry)[state->entrylen].name = safe_strdup (tmp); /* mark desc with delim in browser if it can have subfolders */ diff --git a/imap/imap.c b/imap/imap.c index 21da0e59..32399722 100644 --- a/imap/imap.c +++ b/imap/imap.c @@ -484,7 +484,7 @@ int imap_open_mailbox (CONTEXT* ctx) imap_fix_path (idata, mx.mbox, buf, sizeof (buf)); FREE(&(idata->mailbox)); idata->mailbox = safe_strdup (buf); - imap_qualify_path (buf, sizeof (buf), &mx, idata->mailbox, NULL); + imap_qualify_path (buf, sizeof (buf), &mx, idata->mailbox); FREE (&(ctx->path)); ctx->path = safe_strdup (buf); @@ -1330,7 +1330,7 @@ int imap_complete(char* dest, size_t dlen, char* path) { if (completions) { /* reformat output */ - imap_qualify_path (dest, dlen, &mx, completion, NULL); + imap_qualify_path (dest, dlen, &mx, completion); mutt_pretty_mailbox (dest); FREE (&mx.mbox); diff --git a/imap/imap.h b/imap/imap.h index 1e26941e..a89ba032 100644 --- a/imap/imap.h +++ b/imap/imap.h @@ -60,8 +60,6 @@ void imap_logout_all (void); /* util.c */ int imap_parse_path (const char* path, IMAP_MBOX* mx); -void imap_qualify_path (char* dest, size_t len, const IMAP_MBOX* mx, - const char* path, const char* name); int imap_wait_keepalive (pid_t pid); void imap_keepalive (void); diff --git a/imap/imap_private.h b/imap/imap_private.h index 0c980925..5e2bac23 100644 --- a/imap/imap_private.h +++ b/imap/imap_private.h @@ -207,6 +207,7 @@ char* imap_fix_path (IMAP_DATA* idata, char* mailbox, char* path, int imap_get_literal_count (const char* buf, long* bytes); char* imap_get_qualifier (char* buf); char* imap_next_word (char* s); +void imap_qualify_path (char *dest, size_t len, IMAP_MBOX *mx, char* path); void imap_quote_string (char* dest, size_t slen, const char* src); void imap_unquote_string (char* s); void imap_munge_mbox_name (char *dest, size_t dlen, const char *src); diff --git a/imap/util.c b/imap/util.c index fdb540b0..8e15d043 100644 --- a/imap/util.c +++ b/imap/util.c @@ -133,7 +133,6 @@ char *imap_next_word (char *s) int imap_parse_path (const char* path, IMAP_MBOX* mx) { char tmp[128]; - url_scheme_t scheme; ciss_url_t url; char *c; int n; @@ -143,36 +142,27 @@ int imap_parse_path (const char* path, IMAP_MBOX* mx) mx->account.port = IMAP_PORT; mx->account.type = M_ACCT_TYPE_IMAP; -#ifdef USE_SSL - if (option (OPTIMAPFORCESSL)) - mx->account.flags |= M_ACCT_SSL; -#endif - - scheme = url_check_scheme (NONULL (path)); - if (scheme == U_IMAP || scheme == U_IMAPS) + c = safe_strdup (path); + url_parse_ciss (&url, c); + if (url.scheme == U_IMAP || url.scheme == U_IMAPS) { - if (url_parse_ciss (&url, path) < 0) - return -1; - - n = mutt_account_fromurl (&mx->account, &url); - FREE (&url.user); - FREE (&url.pass); - FREE (&url.host); - - if (n < 0) + if (mutt_account_fromurl (&mx->account, &url) < 0) { - FREE (&url.path); + FREE (&c); return -1; } - - mx->mbox = url.path; - if (scheme == U_IMAPS) + mx->mbox = safe_strdup (url.path); + + if (url.scheme == U_IMAPS) mx->account.flags |= M_ACCT_SSL; + + FREE (&c); } /* old PINE-compatibility code */ else { + FREE (&c); if (sscanf (path, "{%128[^}]}", tmp) != 1) return -1; @@ -215,38 +205,27 @@ int imap_parse_path (const char* path, IMAP_MBOX* mx) } } +#ifdef USE_SSL + if (option (OPTIMAPFORCESSL)) + mx->account.flags |= M_ACCT_SSL; +#endif + if ((mx->account.flags & M_ACCT_SSL) && !(mx->account.flags & M_ACCT_PORT)) mx->account.port = IMAP_SSL_PORT; return 0; } - -/* imap_qualify_path: make an absolute IMAP folder target, given host, port - * and relative path. Use this and maybe it will be easy to convert to - * IMAP URLs */ -void imap_qualify_path (char *dest, size_t len, const IMAP_MBOX *mx, - const char* path, const char* name) +/* imap_qualify_path: make an absolute IMAP folder target, given IMAP_MBOX + * and relative path. */ +void imap_qualify_path (char *dest, size_t len, IMAP_MBOX *mx, char* path) { - char tmp[128]; - - strcpy (dest, "{"); - if ((mx->account.flags & M_ACCT_USER) && (!ImapUser || strcmp (mx->account.user, ImapUser))) - { - snprintf (tmp, sizeof (tmp), "%s@", mx->account.user); - strncat (dest, tmp, len); - } - strncat (dest, mx->account.host, len); - if (mx->account.flags & M_ACCT_PORT) - { - snprintf (tmp, sizeof (tmp), ":%d", mx->account.port); - strncat (dest, tmp, len); - } - if (mx->account.flags & M_ACCT_SSL) - strncat (dest, "/ssl", len); + ciss_url_t url; + + mutt_account_tourl (&mx->account, &url); + url.path = path; - snprintf (tmp, sizeof (tmp), "}%s%s", NONULL (path), NONULL (name)); - strncat (dest, tmp, len); + url_ciss_tostring (&url, dest, len); } diff --git a/url.c b/url.c index 6c7ae30d..d4f7a4d1 100644 --- a/url.c +++ b/url.c @@ -95,6 +95,9 @@ int url_parse_file (char *d, const char *src, size_t dl) return 0; } +/* ciss_parse_userhost: fill in components of ciss with info from src. Note + * these are pointers into src, which is altered with '\0's. Port of 0 + * means no port given. */ static char *ciss_parse_userhost (ciss_url_t *ciss, char *src) { char *t; @@ -120,10 +123,10 @@ static char *ciss_parse_userhost (ciss_url_t *ciss, char *src) if ((p = strchr (src, ':'))) { *p = '\0'; - ciss->pass = safe_strdup (p + 1); + ciss->pass = p + 1; url_pct_decode (ciss->pass); } - ciss->user = safe_strdup (src); + ciss->user = src; url_pct_decode (ciss->user); t++; } @@ -138,30 +141,51 @@ static char *ciss_parse_userhost (ciss_url_t *ciss, char *src) else ciss->port = 0; - ciss->host = safe_strdup (t); + ciss->host = t; url_pct_decode (ciss->host); return path; } -static void ciss_parse_path (ciss_url_t *ciss, char *src) +int url_parse_ciss (ciss_url_t *ciss, char *src) { - ciss->path = safe_strdup (src); + char *tmp; + + if ((ciss->scheme = url_check_scheme (src)) == U_UNKNOWN) + return -1; + + tmp = strchr (src, ':') + 1; + + ciss->path = ciss_parse_userhost (ciss, tmp); url_pct_decode (ciss->path); + + return 0; } -int url_parse_ciss (ciss_url_t *ciss, const 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) { - char *t, *tmp; - - if (!(t = strchr (src, ':'))) + if (ciss->scheme == U_UNKNOWN) return -1; - - tmp = safe_strdup (t + 1); - t = ciss_parse_userhost (ciss, tmp); - ciss_parse_path (ciss, t); - - safe_free ((void **) &tmp); + snprintf (dest, len, "%s:", mutt_getnamebyvalue (ciss->scheme, UrlMap)); + + 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->port) + snprintf (dest + strlen (dest), len - strlen (dest), "%s:%hu/", + ciss->host, ciss->port); + else + snprintf (dest + strlen (dest), len - strlen (dest), "%s/", ciss->host); + } + + if (ciss->path) + strncat (dest, ciss->path, len - strlen (dest)); return 0; } diff --git a/url.h b/url.h index 63024e04..27dd0e13 100644 --- a/url.h +++ b/url.h @@ -15,17 +15,19 @@ url_scheme_t; typedef struct ciss_url { + url_scheme_t scheme; char *user; char *pass; char *host; short port; - char *path; + char *path; } 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, const char *src); +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_parse_mailto (ENVELOPE *e, char **body, const char *src); #endif