]> granicus.if.org Git - mutt/commitdiff
patch-bac.imapurl-2, with small modifications.
authorThomas Roessler <roessler@does-not-exist.org>
Fri, 25 Aug 2000 06:28:22 +0000 (06:28 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Fri, 25 Aug 2000 06:28:22 +0000 (06:28 +0000)
account.c
account.h
browser.c
imap/imap.c
imap/imap_ssl.c
imap/imap_ssl.h
imap/util.c
mutt_socket.c
mx.c
url.c
url.h

index 2853d254938d0ca5f328cc48436c72a58832dc07..22a60a73e24bc00a18fe6a22aa4673b8d196a06a 100644 (file)
--- a/account.c
+++ b/account.c
@@ -18,8 +18,9 @@
 
 /* remote host account manipulation (POP/IMAP) */
 
-#include "account.h"
 #include "mutt.h"
+#include "account.h"
+#include "url.h"
 
 /* mutt_account_match: compare account info (host/port/user) */
 int mutt_account_match (const ACCOUNT* a1, const ACCOUNT* a2)
@@ -53,6 +54,34 @@ int mutt_account_match (const ACCOUNT* a1, const ACCOUNT* a2)
   return 1;
 }
 
+/* mutt_account_fromurl: fill account with information from url. */
+int mutt_account_fromurl (ACCOUNT* account, ciss_url_t* url)
+{
+  /* must be present */
+  if (url->host)
+    strfcpy (account->host, url->host, sizeof (account->host));
+  else
+    return -1;
+
+  if (url->user)
+  {
+    strfcpy (account->user, url->user, sizeof (account->user));
+    account->flags |= M_ACCT_USER;
+  }
+  if (url->pass)
+  {
+    strfcpy (account->pass, url->pass, sizeof (account->pass));
+    account->flags |= M_ACCT_PASS;
+  }
+  if (url->port)
+  {
+    account->port = url->port;
+    account->flags |= M_ACCT_PORT;
+  }
+
+  return 0;
+}
+
 /* mutt_account_getuser: retrieve username into ACCOUNT, if neccessary */
 int mutt_account_getuser (ACCOUNT* account)
 {
index 9e21c2693f006b4afe758b9d27070ffa7065b0b5..bae65297c7c3cfca5d35b85bab7bb0b42088dbf4 100644 (file)
--- a/account.h
+++ b/account.h
@@ -21,6 +21,8 @@
 #ifndef _MUTT_ACCOUNT_H_
 #define _MUTT_ACCOUNT_H_ 1
 
+#include "url.h"
+
 /* account types */
 enum
 {
@@ -46,6 +48,7 @@ typedef struct
 } ACCOUNT;
 
 int mutt_account_match (const ACCOUNT* a1, const ACCOUNT* m2);
+int mutt_account_fromurl (ACCOUNT* account, ciss_url_t* url);
 int mutt_account_getuser (ACCOUNT* account);
 int mutt_account_getpass (ACCOUNT* account);
 
index 4b8d5631d376db498014243a734048f51ddb1a1b..2f5d527a5a66e7f188e6f533d0140f05ae687cbe 100644 (file)
--- a/browser.c
+++ b/browser.c
@@ -144,6 +144,7 @@ folder_format_str (char *dest, size_t destlen, char op, const char *src,
   FOLDER *folder = (FOLDER *) data;
   struct passwd *pw;
   struct group *gr;
+  int optional = (flags & M_FORMAT_OPTIONAL);
 
   switch (op)
   {
@@ -257,8 +258,13 @@ folder_format_str (char *dest, size_t destlen, char op, const char *src,
 #ifdef USE_IMAP
       if (mx_is_imap (folder->ff->desc))
       {
-       snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
-       snprintf (dest, destlen, tmp, folder->ff->new);
+       if (!optional)
+       {
+         snprintf (tmp, sizeof (tmp), "%%%sd", fmt);
+         snprintf (dest, destlen, tmp, folder->ff->new);
+       }
+       else if (!folder->ff->new)
+         optional = 0;
        break;
       }
 #endif
@@ -310,6 +316,12 @@ folder_format_str (char *dest, size_t destlen, char op, const char *src,
       snprintf (dest, destlen, tmp, op);
       break;
   }
+
+  if (optional)
+    mutt_FormatString (dest, destlen, ifstring, folder_format_str, data, 0);
+  else if (flags & M_FORMAT_OPTIONAL)
+    mutt_FormatString (dest, destlen, elsestring, folder_format_str, data, 0);
+
   return (src);
 }
 
index 2fbdad7eca5989919a4277e36ebd9f68487806f1..558833df842fe7e3b897e5e6a002d10548aa077c 100644 (file)
@@ -310,7 +310,9 @@ IMAP_DATA* imap_conn_find (const ACCOUNT* account, int flags)
   IMAP_DATA* idata;
   ACCOUNT* creds;
 
-  conn = mutt_conn_find (NULL, account);
+  if (!(conn = mutt_conn_find (NULL, account)))
+    return NULL;
+
   /* if opening a new UNSELECTED connection, preserve existing creds */
   creds = &(conn->account);
 
@@ -318,11 +320,11 @@ IMAP_DATA* imap_conn_find (const ACCOUNT* account, int flags)
   if (flags & M_IMAP_CONN_NOSELECT)
     while (conn->data && ((IMAP_DATA*) conn->data)->state == IMAP_SELECTED)
     {
-      conn = mutt_conn_find (conn, account);
+      if (!(conn = mutt_conn_find (conn, account)))
+       return NULL;
       memcpy (&(conn->account), creds, sizeof (ACCOUNT));
     }
   
-  
   idata = (IMAP_DATA*) conn->data;
 
   /* don't open a new connection if one isn't wanted */
@@ -1272,7 +1274,7 @@ int imap_complete(char* dest, size_t dlen, char* path) {
 
   /* reformat path for IMAP list, and append wildcard */
   /* don't use INBOX in place of "" */
-  if (mx.mbox[0])
+  if (mx.mbox && mx.mbox[0])
     imap_fix_path (idata, mx.mbox, list, sizeof(list));
   else
     list[0] = '\0';
@@ -1284,7 +1286,7 @@ int imap_complete(char* dest, size_t dlen, char* path) {
   imap_cmd_start (idata, buf);
 
   /* and see what the results are */
-  strfcpy (completion, mx.mbox, sizeof(completion));
+  strfcpy (completion, NONULL(mx.mbox), sizeof(completion));
   do
   {
     if (imap_parse_list_response(idata, &list_word, &noselect, &noinferiors,
index 42915e68b583a6f18239807dc62503fba15b34bb..6d362ff698f61c48be6dc433b24d83f1fb46fc2c 100644 (file)
@@ -144,13 +144,6 @@ static int add_entropy (const char *file)
   return n;
 }
 
-void imap_set_ssl (ACCOUNT* account)
-{
-  if (! (account->flags & M_ACCT_PORT))
-    account->port = IMAP_SSL_PORT;
-  account->flags |= M_ACCT_SSL;
-}
-
 static int ssl_socket_open_err (CONNECTION *conn)
 {
   mutt_error (_("SSL disabled due the lack of entropy"));
index 8c8ec747e5431cf22ef93e8edb44cab451bfcd03..575580a3cd13ac55a14d1bd7980be4c96df87c9c 100644 (file)
@@ -25,6 +25,5 @@ extern char *SslCertFile;
 extern char *SslEntropyFile;
 
 extern int ssl_socket_setup (CONNECTION *conn);
-extern void imap_set_ssl (ACCOUNT* account);
 
 #endif /* _MUTT_SSL_H_ */
index 51a6311235c9285d9475a81a639ed45d6885f8f3..ecd346ddb3e8039d9dbb6788ef9dd5045476e9b6 100644 (file)
@@ -22,6 +22,7 @@
 
 #include "mutt.h"
 #include "mx.h"        /* for M_IMAP */
+#include "url.h"
 #include "imap_private.h"
 #include "imap_ssl.h"
 
@@ -132,62 +133,90 @@ 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;
-  
-  if (sscanf (path, "{%128[^}]}", tmp) != 1) 
-    return -1;
-
-  mx->account.type = M_ACCT_TYPE_IMAP;
 
-  c = strchr (path, '}');
-  if (!c)
-    return -1;
-  else
-    /* walk past closing '}' */
-    mx->mbox = safe_strdup (c+1);
-  
   /* Defaults */
   mx->account.flags = 0;
   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
 
-  if ((c = strrchr (tmp, '@')))
+  scheme = url_check_scheme (NONULL (path));
+  if (scheme == U_IMAP || scheme == U_IMAPS)
   {
-    *c = '\0';
-    strfcpy (mx->account.user, tmp, sizeof (mx->account.user));
-    strfcpy (tmp, c+1, sizeof (tmp));
-    mx->account.flags |= M_ACCT_USER;
+    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)
+    {
+      FREE (&url.path);
+      return -1;
+    }
+      
+    mx->mbox = url.path;
+
+    if (scheme == U_IMAPS)
+      mx->account.flags |= M_ACCT_SSL;
   }
-  
-  if ((n = sscanf (tmp, "%128[^:/]%128s", mx->account.host, tmp)) < 1)
+  /* old PINE-compatibility code */
+  else
   {
-    dprint (1, (debugfile, "imap_parse_path: NULL host in %s\n", path));
-    FREE (&mx->mbox);
-    return -1;
-  }
+    if (sscanf (path, "{%128[^}]}", tmp) != 1) 
+      return -1;
+
+    c = strchr (path, '}');
+    if (!c)
+      return -1;
+    else
+      /* walk past closing '}' */
+      mx->mbox = safe_strdup (c+1);
   
-  if (n > 1) {
-    if (sscanf (tmp, ":%hd%128s", &(mx->account.port), tmp) >= 1)
-      mx->account.flags |= M_ACCT_PORT;
-    if (sscanf (tmp, "/%s", tmp) == 1)
+    if ((c = strrchr (tmp, '@')))
     {
-#ifdef USE_SSL
-      if (!strncmp (tmp, "ssl", 3))
-       imap_set_ssl (&(mx->account));
-      else
-#endif
+      *c = '\0';
+      strfcpy (mx->account.user, tmp, sizeof (mx->account.user));
+      strfcpy (tmp, c+1, sizeof (tmp));
+      mx->account.flags |= M_ACCT_USER;
+    }
+  
+    if ((n = sscanf (tmp, "%128[^:/]%128s", mx->account.host, tmp)) < 1)
+    {
+      dprint (1, (debugfile, "imap_parse_path: NULL host in %s\n", path));
+      FREE (&mx->mbox);
+      return -1;
+    }
+  
+    if (n > 1) {
+      if (sscanf (tmp, ":%hd%128s", &(mx->account.port), tmp) >= 1)
+       mx->account.flags |= M_ACCT_PORT;
+      if (sscanf (tmp, "/%s", tmp) == 1)
       {
-       dprint (1, (debugfile, "imap_parse_path: Unknown connection type in %s\n", path));
-       FREE (&mx->mbox);
-       return -1;
+       if (!strncmp (tmp, "ssl", 3))
+         mx->account.flags |= M_ACCT_SSL;
+       else
+       {
+         dprint (1, (debugfile, "imap_parse_path: Unknown connection type in %s\n", path));
+         FREE (&mx->mbox);
+         return -1;
+       }
       }
     }
   }
-
-#ifdef USE_SSL
-  if (option (OPTIMAPFORCESSL))
-    imap_set_ssl (&(mx->account));
-#endif
+  
+  if ((mx->account.flags & M_ACCT_SSL) && !(mx->account.flags & M_ACCT_PORT))
+    mx->account.port = IMAP_SSL_PORT;
 
   return 0;
 }
index fd3e2eb6ad6039dd239f8ce7b847361cd155fb85..97d06bb9eaa5a6e6a23194013a82c0b6075a3103 100644 (file)
@@ -191,11 +191,19 @@ CONNECTION* mutt_conn_find (const CONNECTION* start, const ACCOUNT* account)
   conn->next = Connections;
   Connections = conn;
 
-#ifdef USE_SSL
   if (account->flags & M_ACCT_SSL) 
+  {
+#ifdef USE_SSL
     ssl_socket_setup (conn);
-  else
+#else
+    mutt_error _("SSL is unavailable.");
+    sleep (2);
+    FREE (&conn);
+
+    return NULL;
 #endif
+  }
+  else
   {
     conn->read = raw_socket_read;
     conn->write = raw_socket_write;
diff --git a/mx.c b/mx.c
index 45f3986df7a2725a1b3ec01540e6e062e0fc12e8..74e4d286c795a271727fb7a0179320d6ff6d1b00 100644 (file)
--- a/mx.c
+++ b/mx.c
@@ -24,7 +24,7 @@
 #include "mailbox.h"
 #include "copy.h"
 #include "keymap.h"
-
+#include "url.h"
 
 #ifdef HAVE_PGP
 #include "pgp.h"
@@ -313,7 +313,19 @@ void mx_unlink_empty (const char *path)
 
 int mx_is_imap(const char *p)
 {
-  return p && (*p == '{');
+  url_scheme_t scheme;
+
+  if (!p)
+    return 0;
+
+  if (*p == '{')
+    return 1;
+
+  scheme = url_check_scheme (p);
+  if (scheme == U_IMAP || scheme == U_IMAPS)
+    return 1;
+
+  return 0;
 }
 
 #endif
diff --git a/url.c b/url.c
index fa210325c4ab8802c12a941959b5ad62b105bde3..6c7ae30d78544b38e435219edf3c4b7c0baf875c 100644 (file)
--- a/url.c
+++ b/url.c
 static struct mapping_t UrlMap[] =
 {
   { "file",    U_FILE },
-#ifdef USE_IMAP
   { "imap",    U_IMAP },
-#endif
-#ifdef USE_POP
-  { "pop",     U_POP  },
-#endif
-#ifdef USE_SSL
-# ifdef USE_IMAP
   { "imaps",   U_IMAPS },
-# endif
-# ifdef USE_POP
+  { "pop",     U_POP  },
   { "pops",    U_POPS  },
-# endif
-#endif
   { "mailto",  U_MAILTO },
   { NULL,      U_UNKNOWN}
 };
@@ -53,6 +43,10 @@ static struct mapping_t UrlMap[] =
 static void url_pct_decode (char *s)
 {
   char *d;
+
+  if (!s)
+    return;
+  
   for (d = s; *s; s++)
   {
     if (*s == '%' && s[1] && s[2] &&
@@ -106,12 +100,17 @@ static char *ciss_parse_userhost (ciss_url_t *ciss, char *src)
   char *t;
   char *p;
   char *path;
-  
+
+  ciss->user = NULL;
+  ciss->pass = NULL;
+  ciss->host = NULL;
+  ciss->port = 0;
+
   if (strncmp (src, "//", 2))
     return src;
   
   src += 2;
-  
+
   if ((path = strchr (src, '/')))
     *path++ = '\0';
   
@@ -122,8 +121,10 @@ static char *ciss_parse_userhost (ciss_url_t *ciss, char *src)
     {
       *p = '\0';
       ciss->pass = safe_strdup (p + 1);
+      url_pct_decode (ciss->pass);
     }
     ciss->user = safe_strdup (src);
+    url_pct_decode (ciss->user);
     t++;
   }
   else
@@ -138,12 +139,13 @@ static char *ciss_parse_userhost (ciss_url_t *ciss, char *src)
     ciss->port = 0;
   
   ciss->host = safe_strdup (t);
+  url_pct_decode (ciss->host);
   return path;
 }
 
 static void ciss_parse_path (ciss_url_t *ciss, char *src)
 {
-  ciss->path = src;
+  ciss->path = safe_strdup (src);
   url_pct_decode (ciss->path);
 }
 
diff --git a/url.h b/url.h
index 5648c342b5db26edb6e1436783371d0641980a13..63024e04513abf730eb7c500836df5e55299e171 100644 (file)
--- a/url.h
+++ b/url.h
@@ -1,25 +1,13 @@
 #ifndef _URL_H
 # define _URL_H
 
-# include "config.h"
-
 typedef enum url_scheme
 {
   U_FILE,
-# ifdef USE_POP
   U_POP,
-# endif
-# ifdef USE_IMAP
+  U_POPS,
   U_IMAP,
-# endif
-# ifdef USE_SSL
-#  ifdef USE_IMAP
   U_IMAPS,
-#  endif
-#  ifdef USE_POP
-  U_POPS,
-#  endif
-# endif
   U_MAILTO,
   U_UNKNOWN
 }