]> granicus.if.org Git - neomutt/commitdiff
imap: always parse account in imap_parse_path2()
authorMehdi Abaakouk <sileht@sileht.net>
Wed, 14 Nov 2018 09:12:06 +0000 (10:12 +0100)
committerRichard Russon <rich@flatcap.org>
Thu, 15 Nov 2018 00:26:28 +0000 (00:26 +0000)
imap/util.c

index a529d42e89809bd7975e89a274278c27a917260b..5d9bce6dcd29da807d00256c5ac61cef7b42ca24 100644 (file)
@@ -564,48 +564,42 @@ int imap_parse_path2(const char *path, struct ConnAccount *account, char *mailbo
   struct Url url;
   char *c = NULL;
 
-  if (account)
+  if (!ImapPort)
   {
-    if (!ImapPort)
-    {
-      service = getservbyname("imap", "tcp");
-      if (service)
-        ImapPort = ntohs(service->s_port);
-      else
-        ImapPort = IMAP_PORT;
-      mutt_debug(3, "Using default IMAP port %d\n", ImapPort);
-    }
-    if (!ImapsPort)
-    {
-      service = getservbyname("imaps", "tcp");
-      if (service)
-        ImapsPort = ntohs(service->s_port);
-      else
-        ImapsPort = IMAP_SSL_PORT;
-      mutt_debug(3, "Using default IMAPS port %d\n", ImapsPort);
-    }
-
-    /* Defaults */
-    account->port = ImapPort;
-    account->type = MUTT_ACCT_TYPE_IMAP;
+    service = getservbyname("imap", "tcp");
+    if (service)
+      ImapPort = ntohs(service->s_port);
+    else
+      ImapPort = IMAP_PORT;
+    mutt_debug(3, "Using default IMAP port %d\n", ImapPort);
+  }
+  if (!ImapsPort)
+  {
+    service = getservbyname("imaps", "tcp");
+    if (service)
+      ImapsPort = ntohs(service->s_port);
+    else
+      ImapsPort = IMAP_SSL_PORT;
+    mutt_debug(3, "Using default IMAPS port %d\n", ImapsPort);
   }
 
+  /* Defaults */
+  account->port = ImapPort;
+  account->type = MUTT_ACCT_TYPE_IMAP;
+
   c = mutt_str_strdup(path);
   url_parse(&url, c);
 
   if (url.scheme == U_IMAP || url.scheme == U_IMAPS)
   {
-    if (account)
+    if (mutt_account_fromurl(account, &url) < 0 || !*account->host)
     {
-      if (mutt_account_fromurl(account, &url) < 0 || !*account->host)
-      {
-        url_free(&url);
-        FREE(&c);
-        return -1;
-      }
-      if (url.scheme == U_IMAPS)
-        account->flags |= MUTT_ACCT_SSL;
+      url_free(&url);
+      FREE(&c);
+      return -1;
     }
+    if (url.scheme == U_IMAPS)
+      account->flags |= MUTT_ACCT_SSL;
 
     mutt_str_strfcpy(mailbox, url.path, mailboxlen);
 
@@ -630,43 +624,40 @@ int imap_parse_path2(const char *path, struct ConnAccount *account, char *mailbo
       mutt_str_strfcpy(mailbox, c + 1, mailboxlen);
     }
 
-    if (account)
+    c = strrchr(tmp, '@');
+    if (c)
     {
-      c = strrchr(tmp, '@');
-      if (c)
-      {
-        *c = '\0';
-        mutt_str_strfcpy(account->user, tmp, sizeof(account->user));
-        mutt_str_strfcpy(tmp, c + 1, sizeof(tmp));
-        account->flags |= MUTT_ACCT_USER;
-      }
+      *c = '\0';
+      mutt_str_strfcpy(account->user, tmp, sizeof(account->user));
+      mutt_str_strfcpy(tmp, c + 1, sizeof(tmp));
+      account->flags |= MUTT_ACCT_USER;
+    }
 
-      const int n = sscanf(tmp, "%127[^:/]%127s", account->host, tmp);
-      if (n < 1)
-      {
-        mutt_debug(1, "NULL host in %s\n", path);
-        return -1;
-      }
+    const int n = sscanf(tmp, "%127[^:/]%127s", account->host, tmp);
+    if (n < 1)
+    {
+      mutt_debug(1, "NULL host in %s\n", path);
+      return -1;
+    }
 
-      if (n > 1)
+    if (n > 1)
+    {
+      if (sscanf(tmp, ":%hu%127s", &(account->port), tmp) >= 1)
+        account->flags |= MUTT_ACCT_PORT;
+      if (sscanf(tmp, "/%s", tmp) == 1)
       {
-        if (sscanf(tmp, ":%hu%127s", &(account->port), tmp) >= 1)
-          account->flags |= MUTT_ACCT_PORT;
-        if (sscanf(tmp, "/%s", tmp) == 1)
+        if (mutt_str_startswith(tmp, "ssl", CASE_MATCH))
+          account->flags |= MUTT_ACCT_SSL;
+        else
         {
-          if (mutt_str_startswith(tmp, "ssl", CASE_MATCH))
-            account->flags |= MUTT_ACCT_SSL;
-          else
-          {
-            mutt_debug(1, "Unknown connection type in %s\n", path);
-            return -1;
-          }
+          mutt_debug(1, "Unknown connection type in %s\n", path);
+          return -1;
         }
       }
     }
   }
 
-  if (account && (account->flags & MUTT_ACCT_SSL) && !(account->flags & MUTT_ACCT_PORT))
+  if ((account->flags & MUTT_ACCT_SSL) && !(account->flags & MUTT_ACCT_PORT))
     account->port = ImapsPort;
 
   return 0;