endif
if USE_SASL
-SASLSOURCES = auth_sasl.c
+AUTHENTICATORS = auth_sasl.c $(GSSSOURCES)
else
-CRAMSOURCES = auth_cram.c md5c.c
+AUTHENTICATORS = auth_anon.c auth_cram.c md5c.c $(GSSSOURCES)
endif
if USE_SSL
noinst_LIBRARIES = libimap.a
noinst_HEADERS = auth.h imap_private.h md5.h message.h $(SSLHEADERS)
-libimap_a_SOURCES = auth.c auth_anon.c auth_login.c browse.c \
- command.c imap.c imap.h message.c utf7.c \
- util.c $(GSSSOURCES) $(SASLSOURCES) $(CRAMSOURCES) $(SSLSOURCES)
+libimap_a_SOURCES = auth.c auth_login.c browse.c command.c imap.c imap.h \
+ message.c utf7.c util.c $(AUTHENTICATORS) $(SSLSOURCES)
+
if ((c = mutt_socket_readln (idata->buf + len, idata->blen - len,
idata->conn)) < 0)
{
- dprint (1, (debugfile, "imap_cmd_resp: Error while reading server response.\n"));
+ dprint (1, (debugfile, "imap_cmd_resp: Error while reading server response, closing connection.\n"));
+ mutt_socket_close (idata->conn);
+ idata->state = IMAP_DISCONNECTED;
+ idata->status = IMAP_FATAL;
return IMAP_CMD_FAIL;
}
}
if ((idata->status == IMAP_NEW_MAIL ||
- (idata->reopen & (IMAP_REOPEN_PENDING|IMAP_NEWMAIL_PENDING)))
+ (idata->reopen & (IMAP_EXPUNGE_PENDING|IMAP_NEWMAIL_PENDING)))
&& (idata->reopen & IMAP_REOPEN_ALLOW))
{
int count = idata->newMailCount;
- if (!(idata->reopen & IMAP_REOPEN_PENDING) &&
+ if (!(idata->reopen & IMAP_EXPUNGE_PENDING) &&
((idata->status == IMAP_NEW_MAIL) || (idata->reopen & IMAP_NEWMAIL_PENDING))
&& count > idata->ctx->msgcount)
{
{
imap_expunge_mailbox (idata);
idata->check_status = IMAP_REOPENED;
- idata->reopen &= ~(IMAP_REOPEN_PENDING|IMAP_NEWMAIL_PENDING);
+ idata->reopen &= ~(IMAP_EXPUNGE_PENDING|IMAP_NEWMAIL_PENDING);
}
}
/* new mail arrived */
count = atoi (pn);
- if ( !(idata->reopen & IMAP_REOPEN_PENDING) &&
+ if ( !(idata->reopen & IMAP_EXPUNGE_PENDING) &&
count < idata->ctx->msgcount)
{
/* something is wrong because the server reported fewer messages
"imap_handle_untagged: superfluous EXISTS message.\n"));
else
{
- if (!(idata->reopen & IMAP_REOPEN_PENDING))
+ if (!(idata->reopen & IMAP_EXPUNGE_PENDING))
{
dprint (2, (debugfile,
"imap_handle_untagged: New mail in %s - %d messages total.\n",
HEADER_DATA (h)->sid--;
}
- idata->reopen |= IMAP_REOPEN_PENDING;
+ idata->reopen |= IMAP_EXPUNGE_PENDING;
}
/* cmd_parse_myrights: set rights bits according to MYRIGHTS response */
/* imap_expunge_mailbox: Purge IMAP portion of expunged messages from the
* context. Must not be done while something has a handle on any headers
- * (eg inside pager or editor). mx_update_tables and mutt_sort_headers
- * must be called afterwards. */
+ * (eg inside pager or editor). That is, check IMAP_REOPEN_ALLOW. */
void imap_expunge_mailbox (IMAP_DATA* idata)
{
HEADER* h;
imap_free_header_data (&h->data);
}
}
+
+ /* We may be called on to expunge at any time. We can't rely on the caller
+ * to always know to rethread */
+ mx_update_tables (idata->ctx, 0);
+ mutt_sort_headers (idata->ctx, 1);
}
#if 0
if (*flags && (imap_exec (idata, buf, 0) != 0) &&
(err_continue != M_YES))
{
- err_continue = imap_continue ("imap_sync_mailbox: STORE failed", buf);
+ err_continue = imap_continue ("imap_sync_mailbox: STORE failed",
+ idata->buf);
if (err_continue != M_YES)
return -1;
}
mutt_message _("Expunging messages from server...");
if (imap_exec (idata, "EXPUNGE", 0) != 0)
{
- imap_error ("imap_sync_mailbox: EXPUNGE failed", buf);
+ imap_error ("imap_sync_mailbox: EXPUNGE failed", idata->buf);
return -1;
}
}
if ((idata->state == IMAP_SELECTED) && (ctx == idata->ctx))
{
- if (!(idata->noclose))
- {
- mutt_message _("Closing mailbox...");
- if (imap_exec (idata, "CLOSE", 0) != 0)
- imap_error ("CLOSE failed", idata->buf);
- }
+ if (!(idata->noclose) && imap_exec (idata, "CLOSE", 0))
+ imap_error ("CLOSE failed", idata->buf);
idata->state = IMAP_AUTHENTICATED;
FREE (&(idata->mailbox));
#define SEQLEN 5
#define IMAP_REOPEN_ALLOW (1<<0)
-#define IMAP_REOPEN_PENDING (1<<1)
+#define IMAP_EXPUNGE_PENDING (1<<1)
#define IMAP_NEWMAIL_PENDING (1<<2)
/* imap_exec flags (see imap_exec) */
int uid;
int cacheno;
IMAP_CACHE *cache;
+ /* Sam's weird courier server returns an OK response even when FETCH
+ * fails. Thanks Sam. */
+ short fetched = 0;
int rc;
idata = (IMAP_DATA*) ctx->data;
do
{
if ((rc = imap_cmd_resp (idata)) != IMAP_CMD_CONTINUE)
- continue;
+ break;
pc = idata->buf;
pc = imap_next_word (pc);
pc = imap_next_word (pc);
+
if (!mutt_strncasecmp ("FETCH", pc, 5))
{
while (*pc)
if ((rc = imap_cmd_resp (idata)) != IMAP_CMD_CONTINUE)
goto bail;
pc = idata->buf;
+
+ fetched = 1;
}
/* UW-IMAP will provide a FLAGS update here if the FETCH causes a
* change (eg from \Unseen to \Seen).
if (rc != IMAP_CMD_DONE)
goto bail;
- if (!imap_code (idata->buf))
+ if (!fetched || !imap_code (idata->buf))
goto bail;
/* Update the header information. Previously, we only downloaded a
set_option (OPTLOCALES);
#endif
+ /* Unset suspend by default if we're the session leader */
+ if (getsid(0) == getpid())
+ unset_option (OPTSUSPEND);
+
mutt_init_history ();
dprint (dbg, (debugfile,"> %s", buf));
+ if (conn->fd < 0)
+ {
+ dprint (1, (debugfile, "mutt_socket_write: attempt to write to closed connection\n"));
+ return -1;
+ }
+
if ((rc = conn->write (conn, buf, mutt_strlen (buf))) < 0)
{
dprint (1, (debugfile, "mutt_socket_write: error writing, closing socket\n"));
{
if (conn->bufpos >= conn->available)
{
- conn->available = conn->read (conn);
+ if (conn->fd >= 0)
+ conn->available = conn->read (conn);
+ else
+ {
+ dprint (1, (debugfile, "mutt_socket_readchar: attempt to read closed from connection.\n"));
+ return -1;
+ }
conn->bufpos = 0;
if (conn->available <= 0)
return conn->available; /* returns 0 for EOF or -1 for other error */
{
if (mutt_socket_readchar (conn, &ch) != 1)
{
- dprint (1, (debugfile, "mutt_socket_readln_d: read error, closing socket"));
buf[i] = '\0';
- mutt_socket_close (conn);
return -1;
}
if (ch == '\n')
if (purge)
{
#ifdef USE_IMAP
- /* IMAP uses the active flag, since deleted messages may remain after
- * a sync */
- if (ctx->magic == M_IMAP)
- mx_update_tables (ctx, 0);
- else
+ /* IMAP does this automatically after handling EXPUNGE */
+ if (ctx->magic != M_IMAP)
#endif
+ {
mx_update_tables (ctx, 1);
-
- mutt_sort_headers (ctx, 1); /* rethread from scratch */
+ mutt_sort_headers (ctx, 1); /* rethread from scratch */
+ }
}
}