#include <ctype.h>
#include "mutt.h"
+#include "ascii.h"
+#include "buffer.h"
#include "mutt_curses.h"
#include "imap_private.h"
#include "message.h"
#include "mx.h"
+#include "hcache.h"
#ifdef HAVE_PGP
#include "pgp.h"
rewind (fp);
memset (&h, 0, sizeof (h));
- h.data = safe_calloc (1, sizeof (IMAP_HEADER_DATA));
+ h.data = mem_calloc (1, sizeof (IMAP_HEADER_DATA));
do {
mfhrc = 0;
rewind (fp);
- FREE (&uid_validity);
+ mem_free (&uid_validity);
}
while ((rc != IMAP_CMD_OK) && ((mfhrc == -1) ||
/* freshen fp, h */
rewind (fp);
memset (&h, 0, sizeof (h));
- h.data = safe_calloc (1, sizeof (IMAP_HEADER_DATA));
+ h.data = mem_calloc (1, sizeof (IMAP_HEADER_DATA));
/* this DO loop does two things:
* 1. handles untagged messages, so we can try again on the same msg
IMAP_CACHE *cache;
int read;
int rc;
+ progress_t bar;
/* Sam's weird courier server returns an OK response even when FETCH
* fails. Thanks Sam. */
cache = &idata->cache[cacheno];
if (cache->path) {
- if (cache->uid == HEADER_DATA (h)->uid) {
- /* yes, so just return a pointer to the message */
- if (!(msg->fp = fopen (cache->path, "r"))) {
- mutt_perror (cache->path);
- return (-1);
- }
+ /* don't treat cache errors as fatal, just fall back. */
+ if (cache->uid == HEADER_DATA(h)->uid && (msg->fp = fopen (cache->path, "r")))
return 0;
- }
else {
- /* clear the previous entry */
unlink (cache->path);
- FREE (&cache->path);
+ mem_free (&cache->path);
}
}
cache->uid = HEADER_DATA (h)->uid;
mutt_mktemp (path);
- cache->path = safe_strdup (path);
+ cache->path = str_dup (path);
if (!(msg->fp = safe_fopen (path, "w+"))) {
- FREE (&cache->path);
+ mem_free (&cache->path);
return -1;
}
imap_error ("imap_fetch_message()", buf);
goto bail;
}
- if (imap_read_literal (msg->fp, idata, bytes) < 0)
+ bar.size = bytes;
+ bar.msg = _("Fetching message...");
+ mutt_progress_bar (&bar, 0);
+ if (imap_read_literal (msg->fp, idata, bytes, &bar) < 0)
goto bail;
/* pick up trailing line */
if ((rc = imap_cmd_step (idata)) != IMAP_CMD_CONTINUE)
/* see comment before command start. */
h->active = 1;
+ fflush (msg->fp);
+ if (ferror (msg->fp)) {
+ mutt_perror (cache->path);
+ goto bail;
+ }
+
if (rc != IMAP_CMD_OK)
goto bail;
safe_fclose (&msg->fp);
if (cache->path) {
unlink (cache->path);
- FREE (&cache->path);
+ mem_free (&cache->path);
}
return -1;
int c, last;
IMAP_MBOX mx;
int rc;
+ progress_t bar;
+ size_t sent;
idata = (IMAP_DATA *) ctx->data;
}
rewind (fp);
+ bar.msg = _("Uploading message...");
+ bar.size = len;
+ mutt_progress_bar (&bar, 0);
+
imap_munge_mbox_name (mbox, sizeof (mbox), mailbox);
snprintf (buf, sizeof (buf), "APPEND %s (%s%s%s%s%s) {%lu}", mbox,
msg->flags.read ? "\\Seen" : "",
goto fail;
}
- mutt_message _("Uploading message ...");
-
- for (last = EOF, len = 0; (c = fgetc (fp)) != EOF; last = c) {
+ for (last = EOF, sent = len = 0; (c = fgetc (fp)) != EOF; last = c) {
if (c == '\n' && last != '\r')
buf[len++] = '\r';
buf[len++] = c;
- if (len > sizeof (buf) - 3)
+ if (len > sizeof (buf) - 3) {
+ sent += len;
flush_buffer (buf, &len, idata->conn);
+ mutt_progress_bar (&bar, sent);
+ }
}
if (len)
goto fail;
}
- FREE (&mx.mbox);
+ mem_free (&mx.mbox);
return 0;
fail:
- FREE (&mx.mbox);
+ mem_free (&mx.mbox);
return -1;
}
}
if (cmd.data)
- FREE (&cmd.data);
+ mem_free (&cmd.data);
if (sync_cmd.data)
- FREE (&sync_cmd.data);
- FREE (&mx.mbox);
+ mem_free (&sync_cmd.data);
+ mem_free (&mx.mbox);
return 0;
fail:
if (cmd.data)
- FREE (&cmd.data);
+ mem_free (&cmd.data);
if (sync_cmd.data)
- FREE (&sync_cmd.data);
- FREE (&mx.mbox);
+ mem_free (&sync_cmd.data);
+ mem_free (&mx.mbox);
return -1;
}
while (keywords) {
if (msg_has_flag (mailbox_flags, keywords->data)) {
- safe_strcat (s, slen, keywords->data);
- safe_strcat (s, slen, " ");
+ str_cat (s, slen, keywords->data);
+ str_cat (s, slen, " ");
}
keywords = keywords->next;
}
/* this should be safe even if the list wasn't used */
mutt_free_list (&(((IMAP_HEADER_DATA *) * data)->keywords));
- FREE (data);
+ mem_free (data);
}
/* imap_set_flags: fill out the message header according to the flags from
unsigned char readonly;
memset (&newh, 0, sizeof (newh));
- newh.data = safe_calloc (1, sizeof (IMAP_HEADER_DATA));
+ newh.data = mem_calloc (1, sizeof (IMAP_HEADER_DATA));
debug_print (2, ("parsing FLAGS\n"));
if ((s = msg_parse_flags (&newh, s)) == NULL) {
- FREE (&newh.data);
+ mem_free (&newh.data);
return NULL;
}
mutt_free_list (&(HEADER_DATA (h)->keywords));
HEADER_DATA (h)->keywords = newh.data->keywords;
- FREE (&newh.data);
+ mem_free (&newh.data);
return s;
}
return rc;
if (imap_get_literal_count (buf, &bytes) == 0) {
- imap_read_literal (fp, idata, bytes);
+ imap_read_literal (fp, idata, bytes, NULL);
/* we may have other fields of the FETCH _after_ the literal
* (eg Domino puts FLAGS here). Nothing wrong with that, either.
#if USE_HCACHE
static size_t imap_hcache_keylen (const char *fn)
{
- return mutt_strlen (fn);
+ return str_len (fn);
}
/* msg_fetch_header: import IMAP FETCH response into an IMAP_HEADER.
flag_list = flag_list->next;
while (flag_list) {
- if (!ascii_strncasecmp (flag_list->data, flag, mutt_strlen (flag_list->data)))
+ if (!ascii_strncasecmp (flag_list->data, flag, str_len (flag_list->data)))
return 1;
flag_list = flag_list->next;