diff options
author | Michael Elkins <me@sigpipe.org> | 2010-08-08 10:41:05 -0700 |
---|---|---|
committer | Michael Elkins <me@sigpipe.org> | 2010-08-08 10:41:05 -0700 |
commit | df537f9422ccbc0230a66f1664971f2c2bb2d673 (patch) | |
tree | 35f527c4612023f4a0ba045ac10b959efd820993 | |
parent | 9b1cf33b613b3b61ccd10f30773b34c6dda56af2 (diff) |
avoid error when the user has requested many extra headers via IMAP
closes #3435
-rw-r--r-- | imap/message.c | 46 |
1 files changed, 26 insertions, 20 deletions
diff --git a/imap/message.c b/imap/message.c index 91847913..1f0f3c02 100644 --- a/imap/message.c +++ b/imap/message.c @@ -62,7 +62,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) { CONTEXT* ctx; char buf[LONG_STRING]; - char hdrreq[STRING]; + char *hdrreq = NULL; FILE *fp; char tempfile[_POSIX_PATH_MAX]; int msgno, idx; @@ -73,6 +73,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) int maxuid = 0; const char *want_headers = "DATE FROM SUBJECT TO CC MESSAGE-ID REFERENCES CONTENT-TYPE CONTENT-DESCRIPTION IN-REPLY-TO REPLY-TO LINES LIST-POST X-LABEL"; progress_t progress; + int retval = -1; #if USE_HCACHE unsigned int *uid_validity = NULL; @@ -85,19 +86,19 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) if (mutt_bit_isset (idata->capabilities,IMAP4REV1)) { - snprintf (hdrreq, sizeof (hdrreq), "BODY.PEEK[HEADER.FIELDS (%s%s%s)]", - want_headers, ImapHeaders ? " " : "", ImapHeaders ? ImapHeaders : ""); + hdrreq = mutt_sprintf ("BODY.PEEK[HEADER.FIELDS (%s%s%s)]", + want_headers, ImapHeaders ? " " : "", NONULL (ImapHeaders)); } else if (mutt_bit_isset (idata->capabilities,IMAP4)) { - snprintf (hdrreq, sizeof (hdrreq), "RFC822.HEADER.LINES (%s%s%s)", - want_headers, ImapHeaders ? " " : "", ImapHeaders ? ImapHeaders : ""); + hdrreq = mutt_sprintf ("RFC822.HEADER.LINES (%s%s%s)", + want_headers, ImapHeaders ? " " : "", NONULL (ImapHeaders)); } else { /* Unable to fetch headers for lower versions */ mutt_error _("Unable to fetch headers from this IMAP server version."); mutt_sleep (2); /* pause a moment to let the user see the error */ - return -1; + goto error_out_0; } /* instead of downloading all headers and then parsing them, we parse them @@ -107,7 +108,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) { mutt_error (_("Could not create temporary file %s"), tempfile); mutt_sleep (2); - return -1; + goto error_out_0; } unlink (tempfile); @@ -220,8 +221,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) if (h.data) imap_free_header_data ((void**) (void*) &h.data); imap_hcache_close (idata); - safe_fclose (&fp); - return -1; + goto error_out_1; } } /* could also look for first null header in case hcache is holey */ @@ -239,13 +239,13 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) /* we may get notification of new mail while fetching headers */ if (msgno + 1 > fetchlast) { - fetchlast = msgend + 1; + char *cmd; - snprintf (buf, sizeof (buf), - "FETCH %d:%d (UID FLAGS INTERNALDATE RFC822.SIZE %s)", msgno + 1, - fetchlast, hdrreq); - - imap_cmd_start (idata, buf); + fetchlast = msgend + 1; + cmd = mutt_sprintf ("FETCH %d:%d (UID FLAGS INTERNALDATE RFC822.SIZE %s)", + msgno + 1, fetchlast, hdrreq); + imap_cmd_start (idata, cmd); + FREE (&cmd); } rewind (fp); @@ -338,8 +338,7 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) #if USE_HCACHE imap_hcache_close (idata); #endif - safe_fclose (&fp); - return -1; + goto error_out_1; } /* in case we get new mail while fetching the headers */ @@ -371,8 +370,6 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) imap_hcache_close (idata); #endif /* USE_HCACHE */ - safe_fclose (&fp); - if (ctx->msgcount > oldmsgcount) { mx_alloc_memory(ctx); @@ -380,7 +377,16 @@ int imap_read_headers (IMAP_DATA* idata, int msgbegin, int msgend) } idata->reopen |= IMAP_REOPEN_ALLOW; - return msgend; + + retval = msgend; + +error_out_1: + safe_fclose (&fp); + +error_out_0: + FREE (&hdrreq); + + return retval; } int imap_fetch_message (MESSAGE *msg, CONTEXT *ctx, int msgno) |