]> granicus.if.org Git - mutt/commitdiff
Consult /etc/services for imaps port. From Brendan Cully.
authorThomas Roessler <roessler@does-not-exist.org>
Mon, 28 May 2001 19:14:47 +0000 (19:14 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Mon, 28 May 2001 19:14:47 +0000 (19:14 +0000)
imap/util.c

index 46a4c6e7a12846c0d28a9264f6888c0627419d1f..7c240f74dd951a679760159541c24d5440e3fffd 100644 (file)
@@ -32,6 +32,7 @@
 #include <sys/types.h>
 #include <sys/wait.h>
 #include <signal.h>
+#include <netdb.h>
 
 #include <errno.h>
 
@@ -67,14 +68,36 @@ int imap_expand_path (char* path, size_t len)
  * mx.mbox is malloc'd, caller must free it */
 int imap_parse_path (const char* path, IMAP_MBOX* mx)
 {
+  static unsigned short ImapPort = 0;
+  static unsigned short ImapsPort = 0;
+  struct servent* service;
   char tmp[128];
   ciss_url_t url;
   char *c;
   int n;
 
+  if (!ImapPort)
+  {
+    service = getservbyname ("imap", "tcp");
+    if (service)
+      ImapPort = ntohs (service->s_port);
+    else
+      ImapPort = IMAP_PORT;
+    dprint (3, (debugfile, "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;
+    dprint (3, (debugfile, "Using default IMAPS port %d\n", ImapsPort));
+  }
+
   /* Defaults */
   mx->account.flags = 0;
-  mx->account.port = IMAP_PORT;
+  mx->account.port = ImapPort;
   mx->account.type = M_ACCT_TYPE_IMAP;
 
   c = safe_strdup (path);
@@ -146,7 +169,7 @@ int imap_parse_path (const char* path, IMAP_MBOX* mx)
 #endif
 
   if ((mx->account.flags & M_ACCT_SSL) && !(mx->account.flags & M_ACCT_PORT))
-    mx->account.port = IMAP_SSL_PORT;
+    mx->account.port = ImapsPort;
 
   return 0;
 }