X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=imap%2Fmessage.c;h=6c1fce7590d381107b6712ca49099b99158f39d5;hp=466d2dcaa66c0f2b5d7735db0be7f981bd583fdb;hb=7b392ef7b50798f9eb3e7c869e634c5fef0092d1;hpb=230399f9632c37b66c1c117a17e8327eae6b3235 diff --git a/imap/message.c b/imap/message.c index 466d2dc..6c1fce7 100644 --- a/imap/message.c +++ b/imap/message.c @@ -10,33 +10,20 @@ /* message parsing/updating functions */ -#if HAVE_CONFIG_H -# include "config.h" -#endif - -#include -#include - #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" #endif -#if HAVE_STDINT_H -#include -#elif HAVE_INTTYPES_H -#include -#endif - static void flush_buffer (char *buf, size_t * len, CONNECTION * conn); static int msg_fetch_header (CONTEXT * ctx, IMAP_HEADER * h, char *buf, FILE * fp); @@ -96,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(Tempdir), 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) @@ -304,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; @@ -345,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(Tempdir), 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