* Copyright (C) 1996-8 Michael R. Elkins <me@mutt.org>
* Copyright (C) 1996-9 Brandon Long <blong@fiction.net>
* Copyright (C) 1999-2009 Brendan Cully <brendan@kublai.com>
- *
+ *
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
- *
+ *
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
+ *
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- */
+ */
/* Support for IMAP4rev1, with the occasional nod to IMAP 4. */
imap_munge_mbox_name (mbox, sizeof (mbox), mailbox);
snprintf (buf, sizeof (buf), "CREATE %s", mbox);
-
+
if (imap_exec (idata, buf, 0) != 0)
{
mutt_error (_("CREATE failed: %s"), imap_cmd_trailer (idata));
/* imap_logout_all: close all open connections. Quick and dirty until we can
* make sure we've got all the context we need. */
-void imap_logout_all (void)
+void imap_logout_all (void)
{
CONNECTION* conn;
CONNECTION* tmp;
mutt_message (_("Closing connection to %s..."), conn->account.host);
imap_logout ((IMAP_DATA**) (void*) &conn->data);
mutt_clear_error ();
- mutt_socket_close (conn);
mutt_socket_free (conn);
}
int r = 0;
dprint (2, (debugfile, "imap_read_literal: reading %ld bytes\n", bytes));
-
+
for (pos = 0; pos < bytes; pos++)
{
if (mutt_socket_readchar (idata->conn, &c) != 1)
{
dprint (1, (debugfile, "imap_read_literal: error during read, %ld bytes read\n", pos));
idata->status = IMAP_FATAL;
-
+
return -1;
}
r = 0;
#endif
fputc (c, fp);
-
+
if (pbar && !(pos % 1024))
mutt_progress_update (pbar, pos, -1);
#ifdef DEBUG
}
else
mutt_account_unsetpass (&idata->conn->account);
-
+
FREE (&idata->capstr);
}
if (new && idata->state == IMAP_AUTHENTICATED)
mutt_bit_isset (idata->capabilities, STARTTLS)))
{
int rc;
-
+
if (option(OPTSSLFORCETLS))
rc = M_YES;
else if ((rc = query_quadoption (OPT_SSLSTARTTLS,
mutt_sleep (1);
goto err_close_conn;
}
-#endif
+#endif
}
else if (ascii_strncasecmp ("* PREAUTH", idata->buf, 9) == 0)
{
if (imap_check_capabilities (idata) != 0)
goto bail;
FREE (&idata->capstr);
- }
+ }
else
{
imap_error ("imap_open_connection()", buf);
void imap_close_connection(IMAP_DATA* idata)
{
- mutt_socket_close (idata->conn);
- idata->state = IMAP_DISCONNECTED;
+ if (idata->state != IMAP_DISCONNECTED)
+ {
+ mutt_socket_close (idata->conn);
+ idata->state = IMAP_DISCONNECTED;
+ }
idata->seqno = idata->nextcmd = idata->lastcmd = idata->status = 0;
memset (idata->cmds, 0, sizeof (IMAP_COMMAND) * idata->cmdslots);
}
int count = 0;
IMAP_MBOX mx, pmx;
int rc;
-
+
if (imap_parse_path (ctx->path, &mx))
{
mutt_error (_("%s is an invalid IMAP path"), ctx->path);
mutt_message (_("Selecting %s..."), idata->mailbox);
imap_munge_mbox_name (buf, sizeof(buf), idata->mailbox);
-
+
/* pipeline ACL test */
if (mutt_bit_isset (idata->capabilities, ACL))
{
do
{
char *pc;
-
+
if ((rc = imap_cmd_step (idata)) != IMAP_CMD_CONTINUE)
break;
while (imap_cmd_step (*idata) == IMAP_CMD_CONTINUE)
;
+ mutt_socket_close ((*idata)->conn);
imap_free_idata (idata);
}
{
if (!flag_list)
return 0;
-
+
flag_list = flag_list->next;
while (flag_list)
{
if (!ascii_strncasecmp (flag_list->data, flag, strlen (flag_list->data)))
return 1;
-
+
if (!ascii_strncmp (flag_list->data, "\\*", strlen (flag_list->data)))
return 1;
-
+
flag_list = flag_list->next;
}
-
+
return 0;
}
int started = 0;
hdrs = idata->ctx->hdrs;
-
+
for (n = *pos;
n < idata->ctx->msgcount && buf->dptr - buf->data < IMAP_MAX_CMDLEN;
n++)
}
}
while (rc > 0);
-
+
rc = count;
out:
mutt_buffer_addstr (cmd, uid);
flags[0] = '\0';
-
+
imap_set_flag (idata, M_ACL_SEEN, hdr->read, "\\Seen ",
flags, sizeof (flags));
imap_set_flag (idata, M_ACL_WRITE, hdr->old,
/* update the IMAP server to reflect message changes done within mutt.
* Arguments
* ctx: the current context
- * expunge: 0 or 1 - do expunge?
+ * expunge: 0 or 1 - do expunge?
*/
int imap_sync_mailbox (CONTEXT* ctx, int expunge, int* index_hint)
{
int oldsort;
int n;
int rc;
-
+
idata = (IMAP_DATA*) ctx->data;
if (idata->state < IMAP_SELECTED)
return -1;
}
- /* This function is only called when the calling code expects the context
+ /* This function is only called when the calling code expects the context
* to be changed. */
imap_allow_reopen (ctx);
return rc;
/* if we are expunging anyway, we can do deleted messages very quickly... */
- if (expunge && mutt_bit_isset (idata->ctx->rights, M_ACL_DELETE))
+ if (expunge && mutt_bit_isset (ctx->rights, M_ACL_DELETE))
{
if ((rc = imap_exec_msgset (idata, "UID STORE", "+FLAGS.SILENT (\\Deleted)",
M_DELETED, 1, 0)) < 0)
imap_hcache_del (idata, HEADER_DATA(h)->uid);
#endif
}
-
+
if (h->active && h->changed)
{
+#if USE_HCACHE
+ imap_hcache_put (idata, h);
+#endif
/* if the message has been rethreaded or attachments have been deleted
* we delete the message and reupload it.
* This works better if we're expunging, of course. */
/* We must send an EXPUNGE command if we're not closing. */
if (expunge && !(ctx->closing) &&
- mutt_bit_isset(idata->ctx->rights, M_ACL_DELETE))
+ mutt_bit_isset(ctx->rights, M_ACL_DELETE))
{
mutt_message _("Expunging messages from server...");
/* Set expunge bit so we don't get spurious reopened messages */
}
}
- if ((force ||
+ if ((force ||
(idata->state != IMAP_IDLE && time(NULL) >= idata->lastread + Timeout))
&& imap_exec (idata, "NOOP", 0) != 0)
return -1;
FREE (&mx.mbox);
return -1;
}
-
+
imap_fix_path (*hidata, mx.mbox, buf, blen);
if (!*buf)
strfcpy (buf, "INBOX", blen);
if (mx_is_imap (mailbox->path))
mailbox->magic = M_IMAP;
}
-
+
if (mailbox->magic != M_IMAP)
continue;
continue;
/* Don't issue STATUS on the selected mailbox, it will be NOOPed or
- * IDLEd elsewhere */
- if (!imap_mxcmp (name, idata->mailbox))
+ * IDLEd elsewhere.
+ * idata->mailbox may be NULL for connections other than the current
+ * mailbox's, and shouldn't expand to INBOX in that case. #3216. */
+ if (idata->mailbox && !imap_mxcmp (name, idata->mailbox))
continue;
if (!mutt_bit_isset (idata->capabilities, IMAP4REV1) &&
queued = 0;
if ((status = imap_mboxcache_get (idata, mbox, 0)))
return status->messages;
-
+
return 0;
}
unsigned int *uidvalidity = NULL;
unsigned int *uidnext = NULL;
#endif
-
+
for (cur = idata->mboxcache; cur; cur = cur->next)
{
status = (IMAP_STATUS*)cur->data;
if (pat->child && do_search (pat->child, 1))
rc++;
}
-
+
if (!allpats)
break;
}
-
+
return rc;
}
if (pat->op == M_OR && clauses > 1)
mutt_buffer_addstr (buf, "OR ");
clauses--;
-
+
if (imap_compile_search (clause, buf) < 0)
return -1;
if (clauses)
mutt_buffer_addch (buf, ' ');
-
+
}
clause = clause->next;
}
imap_quote_string (term, sizeof (term), pat->p.str);
mutt_buffer_addstr (buf, term);
mutt_buffer_addch (buf, ' ');
-
+
/* and field */
*delim = ':';
delim++;
}
if (!(idata = imap_conn_find (&(mx.account), 0)))
goto fail;
-
+
conn = idata->conn;
imap_fix_path (idata, mx.mbox, buf, sizeof (buf));
dprint (1, (debugfile, "Error adding subscribed mailbox: %s\n", errstr));
FREE (&token.data);
}
-
+
if (subscribe)
mutt_message (_("Subscribing to %s..."), buf);
else
longest_common_prefix (char *dest, const char* src, int start, size_t dlen)
{
int pos = start;
-
+
while (pos < dlen && dest[pos] && dest[pos] == src[pos])
pos++;
dest[pos] = '\0';
CONNECTION* conn;
int rc = -1;
int matchlen;
-
+
matchlen = mutt_strlen (dest);
for (mailbox = Incoming; mailbox; mailbox = mailbox->next)
{
longest_common_prefix (dest, mailbox->path, matchlen, len);
}
}
-
+
for (conn = mutt_socket_head (); conn; conn = conn->next)
{
ciss_url_t url;
FREE (&mx.mbox);
return 0;
}
-
+
return -1;
}