summaryrefslogtreecommitdiffstats
path: root/imap
diff options
context:
space:
mode:
authorThomas Roessler <roessler@does-not-exist.org>1999-10-26 08:12:00 +0000
committerThomas Roessler <roessler@does-not-exist.org>1999-10-26 08:12:00 +0000
commit584dea47be9645b08b47f6dbac2c528c75f5ce51 (patch)
treec189c9f498f1afb1a3b5ddaae626292b49919e89 /imap
parente5283b9aa3faed2538cf55cf58c82563146dfaae (diff)
* stops mutt from logging CRAM secrets in debug mode.
* 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>)
Diffstat (limited to 'imap')
-rw-r--r--imap/auth.c7
-rw-r--r--imap/browse.c5
-rw-r--r--imap/command.c68
-rw-r--r--imap/imap.c22
-rw-r--r--imap/imap_private.h1
-rw-r--r--imap/util.c17
6 files changed, 72 insertions, 48 deletions
diff --git a/imap/auth.c b/imap/auth.c
index 5b48ec79..6f85acc2 100644
--- a/imap/auth.c
+++ b/imap/auth.c
@@ -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");
diff --git a/imap/browse.c b/imap/browse.c
index 35af24dc..f48a9d7e 100644
--- a/imap/browse.c
+++ b/imap/browse.c
@@ -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));
diff --git a/imap/command.c b/imap/command.c
index 3b05d93a..4755e013 100644
--- a/imap/command.c
+++ b/imap/command.c
@@ -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))
{
diff --git a/imap/imap.c b/imap/imap.c
index fd598700..9b081d32 100644
--- a/imap/imap.c
+++ b/imap/imap.c
@@ -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;
diff --git a/imap/imap_private.h b/imap/imap_private.h
index 4d1e128f..70cc3d22 100644
--- a/imap/imap_private.h
+++ b/imap/imap_private.h
@@ -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);
diff --git a/imap/util.c b/imap/util.c
index ad305017..02a94ba1 100644
--- a/imap/util.c
+++ b/imap/util.c
@@ -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++;