X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=imap%2Fmessage.c;h=d780c9c99e2cad46f7126ffd92ecd1af6198e0bb;hp=8412c61d2fdd2e4d3c9b916ecdc60400eeb2be97;hb=9eb790d6eb4a56416d342816e1140aabd9c12de8;hpb=1ee89902de184a640c171ae3285bff6882a791bd diff --git a/imap/message.c b/imap/message.c index 8412c61..d780c9c 100644 --- a/imap/message.c +++ b/imap/message.c @@ -13,12 +13,12 @@ #include #include +#include +#include #include "mutt.h" #include "imap_private.h" #include "message.h" -#include "mx.h" -#include "hcache.h" #ifdef HAVE_PGP #include "pgp.h" @@ -54,10 +54,10 @@ int imap_read_headers (IMAP_DATA * idata, int msgbegin, int msgend) int rc, mfhrc, oldmsgcount; int fetchlast = 0; const char *want_headers = - "DATE FROM SUBJECT TO CC MESSAGE-ID REFERENCES CONTENT-TYPE CONTENT-DESCRIPTION IN-REPLY-TO REPLY-TO LINES string_list_t-POST X-LABEL"; + "DATE FROM SUBJECT TO CC MESSAGE-ID REFERENCES CONTENT-TYPE CONTENT-DESCRIPTION IN-REPLY-TO REPLY-TO LINES LIST-POST X-LABEL"; #ifdef USE_HCACHE - void *hc = NULL; + hcache_t *hc = NULL; unsigned long *uid_validity = NULL; char uid_buf[64]; #endif /* USE_HCACHE */ @@ -83,13 +83,13 @@ int imap_read_headers (IMAP_DATA * idata, int msgbegin, int msgend) /* instead of downloading all headers and then parsing them, we parse them * as they come in. */ - mutt_mktemp (tempfile); - if (!(fp = safe_fopen (tempfile, "w+"))) { - mutt_error (_("Could not create temporary file %s"), tempfile); - mutt_sleep (2); + fp = m_tempfile(tempfile, sizeof(tempfile), NONULL(MCore.tmpdir), NULL); + if (!fp) { + mutt_error(_("Could not create temporary file")); + mutt_sleep(2); return -1; } - unlink (tempfile); + unlink(tempfile); /* make sure context has room to hold the mailbox */ while ((msgend) >= idata->ctx->hdrmax) @@ -163,8 +163,8 @@ int imap_read_headers (IMAP_DATA * idata, int msgbegin, int msgend) if ((mfhrc < -1) || ((rc != IMAP_CMD_CONTINUE) && (rc != IMAP_CMD_OK))) { imap_free_header_data((void *)&h.data); - fclose (fp); - mutt_hcache_close (hc); + m_fclose(&fp); + mutt_hcache_close (&hc); return -1; } } @@ -262,9 +262,9 @@ int imap_read_headers (IMAP_DATA * idata, int msgbegin, int msgend) if ((mfhrc < -1) || ((rc != IMAP_CMD_CONTINUE) && (rc != IMAP_CMD_OK))) { imap_free_header_data ((void *)&h.data); - fclose (fp); + m_fclose(&fp); #ifdef USE_HCACHE - mutt_hcache_close (hc); + mutt_hcache_close (&hc); #endif /* USE_HCACHE */ return -1; } @@ -280,10 +280,10 @@ int imap_read_headers (IMAP_DATA * idata, int msgbegin, int msgend) } #ifdef USE_HCACHE - mutt_hcache_close (hc); + mutt_hcache_close (&hc); #endif /* USE_HCACHE */ - fclose (fp); + m_fclose(&fp); if (ctx->msgcount > oldmsgcount) mx_update_context (ctx, ctx->msgcount - oldmsgcount); @@ -291,6 +291,50 @@ int imap_read_headers (IMAP_DATA * idata, int msgbegin, int msgend) return msgend; } +/* move all the headers from extra not present in base into base */ +static void mutt_merge_envelopes(ENVELOPE* base, ENVELOPE** extra) +{ + /* copies each existing element if necessary, and sets the element + * to NULL in the source so that envelope_delete doesn't leave us + * with dangling pointers. */ +#define MOVE_ELEM(h) if (!base->h) { base->h = (*extra)->h; (*extra)->h = NULL; } + MOVE_ELEM(return_path); + MOVE_ELEM(from); + MOVE_ELEM(to); + MOVE_ELEM(cc); + MOVE_ELEM(bcc); + MOVE_ELEM(sender); + MOVE_ELEM(reply_to); + MOVE_ELEM(mail_followup_to); + MOVE_ELEM(list_post); + MOVE_ELEM(message_id); + MOVE_ELEM(supersedes); + MOVE_ELEM(date); + MOVE_ELEM(x_label); + if (!base->refs_changed) { + MOVE_ELEM(references); + } + if (!base->irt_changed) { + MOVE_ELEM(in_reply_to); + } + /* real_subj is subordinate to subject */ + if (!base->subject) { + base->subject = (*extra)->subject; + base->real_subj = (*extra)->real_subj; + (*extra)->subject = NULL; + (*extra)->real_subj = NULL; + } + /* spam and user headers should never be hashed, and the new envelope may + * have better values. Use new versions regardless. */ + mutt_buffer_free (&base->spam); + string_list_wipe(&base->userhdrs); + MOVE_ELEM(spam); + MOVE_ELEM(userhdrs); +#undef MOVE_ELEM + + envelope_delete(extra); +} + int imap_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno) { IMAP_DATA *idata; @@ -332,12 +376,11 @@ int imap_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno) mutt_message _("Fetching message..."); cache->uid = HEADER_DATA (h)->uid; - mutt_mktemp (path); - cache->path = m_strdup(path); - if (!(msg->fp = safe_fopen (path, "w+"))) { - p_delete(&cache->path); + msg->fp = m_tempfile(path, sizeof(path), NONULL(MCore.tmpdir), NULL); + if (!msg->fp) { return -1; } + cache->path = m_strdup(path); /* mark this header as currently inactive so the command handler won't * also try to update it. HACK until all this code can be moved into the @@ -456,7 +499,7 @@ int imap_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno) return 0; bail: - safe_fclose (&msg->fp); + m_fclose(&msg->fp); if (cache->path) { unlink (cache->path); p_delete(&cache->path); @@ -531,7 +574,7 @@ int imap_append_message (CONTEXT * ctx, MESSAGE * msg) pc = imap_next_word (pc); mutt_error ("%s", pc); mutt_sleep (1); - fclose (fp); + m_fclose(&fp); goto fail; } @@ -552,7 +595,7 @@ int imap_append_message (CONTEXT * ctx, MESSAGE * msg) flush_buffer (buf, &len, idata->conn); mutt_socket_write (idata->conn, "\r\n"); - fclose (fp); + m_fclose(&fp); do rc = imap_cmd_step (idata); @@ -926,7 +969,7 @@ static int msg_has_flag (string_list_t * flag_list, const char *flag) /* msg_parse_fetch: handle headers returned from header fetch */ static int msg_parse_fetch (IMAP_HEADER * h, char *s) { - char tmp[SHORT_STRING]; + char tmp[STRING]; char *ptmp; if (!s)