we don't really need md5 for hcache at all.
[apps/madmutt.git] / imap / message.c
index 930f4d3..d780c9c 100644 (file)
@@ -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);
@@ -376,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
@@ -500,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);
@@ -575,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;
   }
 
@@ -596,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);
@@ -970,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)