]> granicus.if.org Git - neomutt/commitdiff
* stops mutt from logging CRAM secrets in debug mode.
authorThomas Roessler <roessler@does-not-exist.org>
Tue, 26 Oct 1999 08:12:00 +0000 (08:12 +0000)
committerThomas Roessler <roessler@does-not-exist.org>
Tue, 26 Oct 1999 08:12:00 +0000 (08:12 +0000)
* should fix mutt segfaulting when trying to open {}
* helps with the problem of mutt detecting new mail in the wrong
  folder. Now, IMAP commands from the SELECTED state should call
  imap_cmd_finish after they've executed commands. I've only put
  this is imap_buffy_check for now - in my opinion the command
  execution path is still not stable, and rewrites may obviate the
  need for this...

(From: Brendan Cully <brendan@kublai.com>)

imap/auth.c
imap/browse.c
imap/command.c
imap/imap.c
imap/imap_private.h
imap/util.c

index 5b48ec79fb09e78b1bb8a73933b4ac9d1cdbdce6..6f85acc208a94460276ef9387cac8392aa80d75b 100644 (file)
@@ -366,9 +366,8 @@ static int imap_auth_cram_md5 (IMAP_DATA* idata, const char* user,
    *   around them when the bug report comes in. Until then, we'll remain
    *   blissfully RFC-compliant.
    */
-   hmac_md5 (pass, obuf, hmac_response);
-   dprint (2, (debugfile, "CRAM response: %s,[%s]->", obuf, pass));
-   /* dubious optimisation I saw elsewhere: make the whole string in one call */
+  hmac_md5 (pass, obuf, hmac_response);
+  /* dubious optimisation I saw elsewhere: make the whole string in one call */
   snprintf (obuf, sizeof (obuf),
     "%s %02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
     user,
@@ -376,7 +375,7 @@ static int imap_auth_cram_md5 (IMAP_DATA* idata, const char* user,
     hmac_response[4], hmac_response[5], hmac_response[6], hmac_response[7],
     hmac_response[8], hmac_response[9], hmac_response[10], hmac_response[11],
     hmac_response[12], hmac_response[13], hmac_response[14], hmac_response[15]);
-  dprint(2, (debugfile, "%s\n", obuf));
+  dprint(2, (debugfile, "CRAM response: %s\n", obuf));
 
   mutt_to_base64 ((unsigned char*) ibuf, (unsigned char*) obuf, strlen (obuf));
   strcpy (ibuf + strlen (ibuf), "\r\n");
index 35af24dc32cf509c4498b6568e67e1bc2b4aa12a..f48a9d7e10a9aa7accf6afdb5c76de6c29ea92ec 100644 (file)
@@ -61,7 +61,10 @@ int imap_init_browse (char *path, struct browser_state *state)
   int noinferiors;
 
   if (imap_parse_path (path, host, sizeof (host), &port, &ipath))
-    return (-1);
+  {
+    mutt_error ("%s is an invalid IMAP path", path);
+    return -1;
+  }
 
   strfcpy (list_cmd, option (OPTIMAPLSUB) ? "LSUB" : "LIST", sizeof (list_cmd));
 
index 3b05d93abc848a53d9528eb8c43fb5c9a3eaf9b5..4755e013fbbd480af4625feaedf0d2de1d8e4be8 100644 (file)
@@ -37,6 +37,42 @@ static char *Capabilities[] = {"IMAP4", "IMAP4rev1", "STATUS", "ACL",
   "LOGIN-REFERRALS", "MAILBOX-REFERRALS", "QUOTA", "SCAN", "SORT", 
   "THREAD=ORDEREDSUBJECT", "UIDPLUS", "AUTH=ANONYMOUS", NULL};
 
+/* imap_cmd_finish: When the caller has finished reading command responses,
+ *   it must call this routine to perform cleanup (eg fetch new mail if
+ *   detected, do expunge) */
+void imap_cmd_finish (const char* seq, IMAP_DATA* idata)
+{
+  if ((idata->state == IMAP_SELECTED) && 
+      !idata->selected_ctx->closing && 
+      (idata->status == IMAP_NEW_MAIL || 
+       idata->status == IMAP_EXPUNGE))
+  {
+    int count = idata->newMailCount;
+
+    if (idata->status == IMAP_NEW_MAIL && count > idata->selected_ctx->msgcount)
+    {
+      /* read new mail messages */
+      dprint (1, (debugfile, "imap_cmd_finish: fetching new mail\n"));
+
+      while (count > idata->selected_ctx->hdrmax)
+       mx_alloc_memory (idata->selected_ctx);
+
+      count = imap_read_headers (idata->selected_ctx, 
+        idata->selected_ctx->msgcount, count - 1) + 1;
+      idata->check_status = IMAP_NEW_MAIL;
+    }
+    else
+    {
+      imap_reopen_mailbox (idata->selected_ctx, NULL);
+      idata->check_status = IMAP_REOPENED;
+    }
+
+    idata->status = 0;
+
+    mutt_clear_error ();
+  }
+}
+
 /* imap_code: returns 1 if the command result was OK, or 0 if NO or BAD */
 int imap_code (const char *s)
 {
@@ -57,7 +93,6 @@ int imap_exec (char* buf, size_t buflen, IMAP_DATA* idata, const char* cmd,
   char* out;
   int outlen;
   char seq[8];
-  int count;
 
   /* create sequence for command */
   imap_make_sequence (seq, sizeof (seq));
@@ -80,36 +115,7 @@ int imap_exec (char* buf, size_t buflen, IMAP_DATA* idata, const char* cmd,
   }
   while (mutt_strncmp (buf, seq, SEQLEN) != 0);
 
-  if ((idata->state == IMAP_SELECTED) && 
-      !idata->selected_ctx->closing && 
-      (idata->status == IMAP_NEW_MAIL || 
-       idata->status == IMAP_EXPUNGE))
-  {
-
-    count = idata->newMailCount;
-
-    if (idata->status == IMAP_NEW_MAIL && count > idata->selected_ctx->msgcount)
-    {
-      /* read new mail messages */
-      dprint (1, (debugfile, "imap_exec(): new mail detected\n"));
-
-      while (count > idata->selected_ctx->hdrmax)
-       mx_alloc_memory (idata->selected_ctx);
-
-      count = imap_read_headers (idata->selected_ctx, 
-         idata->selected_ctx->msgcount, count - 1) + 1;
-      idata->check_status = IMAP_NEW_MAIL;
-    }
-    else
-    {
-      imap_reopen_mailbox (idata->selected_ctx, NULL);
-      idata->check_status = IMAP_REOPENED;
-    }
-
-    idata->status = 0;
-
-    mutt_clear_error ();
-  }
+  imap_cmd_finish (seq, idata);
 
   if (!imap_code (buf))
   {
index fd5987006e51e4d38b58e104fb77ccd422b767f3..9b081d326b044e5706ae5ab2ab44eaf5956cfce1 100644 (file)
@@ -514,7 +514,10 @@ int imap_open_mailbox (CONTEXT *ctx)
   int port;
 
   if (imap_parse_path (ctx->path, host, sizeof (host), &port, &pc))
-    return (-1);
+  {
+    mutt_error ("%s is an invalid IMAP path", ctx->path);
+    return -1;
+  }
 
   conn = mutt_socket_select_connection (host, port, 0);
   idata = CONN_DATA;
@@ -959,7 +962,7 @@ int imap_sync_mailbox (CONTEXT* ctx, int expunge)
     /* if we have a message set, then let's delete */
     if (deleted)
     {
-      snprintf (tmp, sizeof (tmp), _("Marking %d messages for deletion..."),
+      snprintf (tmp, sizeof (tmp), _("Marking %d messages deleted..."),
         deleted);
       mutt_message (tmp);
       snprintf (tmp, sizeof (tmp), "STORE %s +FLAGS.SILENT (\\Deleted)", buf);
@@ -1166,7 +1169,7 @@ int imap_mailbox_check (char *path, int new)
     /* If passive is selected, then we don't open connections to check
      * for new mail */
     if (option (OPTIMAPPASSIVE))
-      return (-1);
+      return -1;
     if (!idata)
     {
       /* The current connection is a new connection */
@@ -1175,7 +1178,7 @@ int imap_mailbox_check (char *path, int new)
       idata->conn = conn;
     }
     if (imap_open_connection (idata, conn))
-      return (-1);
+      return -1;
   }
 
   imap_fix_path (idata, pc, buf, sizeof (buf));
@@ -1207,7 +1210,7 @@ int imap_mailbox_check (char *path, int new)
   {
     /* Server does not support STATUS, and this is not the current mailbox.
      * There is no lightweight way to check recent arrivals */
-      return (-1);
+      return -1;
   }
 
   mutt_socket_write (conn, buf);
@@ -1215,9 +1218,7 @@ int imap_mailbox_check (char *path, int new)
   do 
   {
     if (mutt_socket_read_line_d (buf, sizeof (buf), conn) < 0)
-    {
-      return (-1);
-    }
+      return -1;
 
     if (buf[0] == '*') 
     {
@@ -1243,12 +1244,15 @@ int imap_mailbox_check (char *path, int new)
       {
        if (conn->data && 
            imap_handle_untagged (idata, buf) != 0)
-         return (-1);
+         return -1;
       }
     }
   }
   while ((mutt_strncmp (buf, seq, SEQLEN) != 0));
 
+  imap_cmd_finish (seq, idata);
+
+  /* what does this do? */
   conn->uses--;
 
   return msgcount;
index 4d1e128f6adfd839fbf54f22e19e64f72353d705..70cc3d22e9a14666901101f093f194944237453a 100644 (file)
@@ -162,6 +162,7 @@ int imap_reopen_mailbox (CONTEXT *ctx, int *index_hint);
 int imap_authenticate (IMAP_DATA *idata, CONNECTION *conn);
 
 /* command.c */
+void imap_cmd_finish (const char* seq, IMAP_DATA* idata);
 int imap_code (const char* s);
 int imap_exec (char* buf, size_t buflen, IMAP_DATA* idata, const char* cmd,
   int flags);
index ad3050171b71d9daf0af1ff962f90a28966eeba7..02a94ba17cea62c577c4089f6f91859ce63e5aa8 100644 (file)
@@ -122,23 +122,34 @@ int imap_parse_path (char* path, char* host, size_t hlen, int* port,
   *port = IMAP_PORT;
   pc = path;
   if (*pc != '{')
-    return (-1);
+    return -1;
   pc++;
   n = 0;
   while (*pc && *pc != '}' && *pc != ':' && (n < hlen-1))
     host[n++] = *pc++;
   host[n] = 0;
+  /* catch NULL hosts */
+  if (!*host)
+  {
+    dprint (1, (debugfile, "imap_parse_path: NULL host in %s\n", path));
+    return -1;
+  }
   if (!*pc)
-    return (-1);
+    return -1;
   if (*pc == ':')
   {
     pc++;
     pt = pc;
     while (*pc && *pc != '}') pc++;
     if (!*pc)
-      return (-1);
+      return -1;
     *pc = '\0';
     *port = atoi (pt);
+    if (!port)
+    {
+      dprint (1, (debugfile, "imap_parse_path: bad port in %s\n", path));
+      return -1;
+    }
     *pc = '}';
   }
   pc++;