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)
{
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);
else if (state.imap_browse)
{
int n;
+ ciss_url_t url;
strfcpy (LastDir, state.entry[menu->current].name,
sizeof (LastDir));
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)))
{
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;
safe_free ((void **) &Context);
}
done = 1;
-#ifdef USE_IMAP
- /* Close all open IMAP connections */
- imap_logout_all ();
-#endif
}
break;
if (done) break;
}
+#ifdef USE_IMAP
+ /* Close all open IMAP connections */
+ imap_logout_all ();
+#endif
+
mutt_menuDestroy (&menu);
return (close);
}
/* 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--;
}
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;
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);
}
}
/* 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);
}
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 */
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);
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);
/* 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);
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);
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;
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;
}
}
+#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);
}
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;
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++;
}
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;
}
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