]> granicus.if.org Git - neomutt/commitdiff
patch-bac.imapurl-4
authorThomas Roessler <roessler@does-not-exist.org>
Mon, 4 Sep 2000 10:49:46 +0000 (10:49 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Mon, 4 Sep 2000 10:49:46 +0000 (10:49 +0000)
account.c
account.h
browser.c
curs_main.c
imap/browse.c
imap/imap.c
imap/imap.h
imap/imap_private.h
imap/util.c
url.c
url.h

index 22a60a73e24bc00a18fe6a22aa4673b8d196a06a..fc29e86ff2ddaffe60fdc70a8864327e0a842d1b 100644 (file)
--- 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)
 {
index bae65297c7c3cfca5d35b85bab7bb0b42088dbf4..246a04c937f2c587e0e8b182eb586018b3d5b078 100644 (file)
--- 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);
 
index 0f2a7f828d980c356fc19a1690a977230872a450..c30bea45d2c3200dbaab046941d7943233ee8031 100644 (file)
--- 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)))
              {
index 0006fc987bf4716cab4eb490623ff0cc4eba710e..418a266b8d3b86051d7f741af6cdfef1559573a9 100644 (file)
@@ -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);
 }
index cfd77c793ff2715ec2aa5e0574ca9e70f128689b..cf7c4bc51116ca4bbb57cfe44ec28513d1ed88bf 100644 (file)
@@ -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 */
index 21da0e59276fd4f1a5d9abadbda2b101b7214815..323997221a5ec0d6c9b858cdde974ab96b9e6426 100644 (file)
@@ -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);
index 1e26941e5f712f16a53e034f057b2547fe07486c..a89ba032a29f60c2a05f41415004b9f4977941c7 100644 (file)
@@ -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);
index 0c980925dc7645182ff3a3d4caaa5f73cd221169..5e2bac23ca86ed80cdf1928a6d1fd1914ce3ed5a 100644 (file)
@@ -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);
index fdb540b0039aeb5d4103b3d23b43cc70feec0496..8e15d0438dacb8439dde51e50d34dc93bfd002eb 100644 (file)
@@ -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 6c7ae30d78544b38e435219edf3c4b7c0baf875c..d4f7a4d1c78e6898f1ee72ba44a5eb0123f0692b 100644 (file)
--- 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 63024e04513abf730eb7c500836df5e55299e171..27dd0e13305994db21579a142bb405d706aa659b 100644 (file)
--- 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