a whole lot of size_t -> ssize_t.
[apps/madmutt.git] / mx.c
diff --git a/mx.c b/mx.c
index b1efdce..c5576d6 100644 (file)
--- a/mx.c
+++ b/mx.c
 # include "config.h"
 #endif
 
+#include <dirent.h>
+#include <fcntl.h>
+#include <sys/file.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <utime.h>
+
 #include <lib-lib/mem.h>
 #include <lib-lib/ascii.h>
 #include <lib-lib/str.h>
 #include <lib-lib/macros.h>
 #include <lib-lib/file.h>
+#include <lib-lib/debug.h>
+#include <lib-lib/url.h>
+
+#include <lib-sys/unix.h>
 
 #include <lib-mime/mime.h>
 
@@ -29,7 +44,6 @@
 #include "thread.h"
 #include "copy.h"
 #include "keymap.h"
-#include "url.h"
 #include "sidebar.h"
 #include "compress.h"
 
 #include <lib-crypt/crypt.h>
 
 #include "lib/list.h"
-#include "lib/debug.h"
-
-#include <dirent.h>
-#include <fcntl.h>
-#include <sys/file.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <unistd.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <utime.h>
 
 static list2_t* MailboxFormats = NULL;
 #define MX_COMMAND(idx,cmd) ((mx_t*) MailboxFormats->data[idx])->cmd
@@ -165,9 +167,9 @@ static int mx_get_idx (const char* path) {
 /* Args:
  *     excl            if excl != 0, request an exclusive lock
  *     dot             if dot != 0, try to dotlock the file
- *     timeout         should retry locking?
+ *     time_out        should retry locking?
  */
-int mx_lock_file (const char *path, int fd, int excl, int dot, int timeout)
+int mx_lock_file (const char *path, int fd, int excl, int dot, int time_out)
 {
 #if defined (USE_FCNTL) || defined (USE_FLOCK)
   int count;
@@ -204,8 +206,8 @@ int mx_lock_file (const char *path, int fd, int excl, int dot, int timeout)
 
     /* only unlock file if it is unchanged */
     if (prev_sb.st_size == sb.st_size
-        && ++count >= (timeout ? MAXLOCKATTEMPT : 0)) {
-      if (timeout)
+        && ++count >= (time_out ? MAXLOCKATTEMPT : 0)) {
+      if (time_out)
         mutt_error _("Timeout exceeded while attempting fcntl lock!");
 
       return (-1);
@@ -238,8 +240,8 @@ int mx_lock_file (const char *path, int fd, int excl, int dot, int timeout)
 
     /* only unlock file if it is unchanged */
     if (prev_sb.st_size == sb.st_size
-        && ++count >= (timeout ? MAXLOCKATTEMPT : 0)) {
-      if (timeout)
+        && ++count >= (time_out ? MAXLOCKATTEMPT : 0)) {
+      if (time_out)
         mutt_error _("Timeout exceeded while attempting flock lock!");
 
       r = -1;
@@ -255,7 +257,7 @@ int mx_lock_file (const char *path, int fd, int excl, int dot, int timeout)
 
 #ifdef USE_DOTLOCK
   if (r == 0 && dot)
-    r = dotlock_file (path, fd, timeout);
+    r = dotlock_file (path, fd, time_out);
 #endif /* USE_DOTLOCK */
 
   if (r == -1) {
@@ -592,7 +594,7 @@ void mx_fastclose_mailbox (CONTEXT * ctx)
     hash_destroy (&ctx->id_hash, NULL);
   mutt_clear_threads (ctx);
   for (i = 0; i < ctx->msgcount; i++)
-    mutt_free_header (&ctx->hdrs[i]);
+    header_delete(&ctx->hdrs[i]);
   p_delete(&ctx->hdrs);
   p_delete(&ctx->v2r);
 
@@ -947,7 +949,7 @@ void mx_update_tables (CONTEXT * ctx, int committing)
       if (ctx->id_hash && ctx->hdrs[i]->env->message_id)
         hash_delete (ctx->id_hash, ctx->hdrs[i]->env->message_id,
                      ctx->hdrs[i], NULL);
-      mutt_free_header (&ctx->hdrs[i]);
+      header_delete(&ctx->hdrs[i]);
     }
   }
 #undef this_body
@@ -1423,3 +1425,27 @@ int mx_rebuild_cache (void) {
   return (0);
 #endif
 }
+
+void mutt_parse_mime_message (CONTEXT * ctx, HEADER * cur)
+{
+  MESSAGE *msg;
+  int flags = 0;
+
+  do {
+    if (cur->content->type != TYPEMESSAGE
+        && cur->content->type != TYPEMULTIPART)
+      break;                     /* nothing to do */
+
+    if (cur->content->parts)
+      break;                     /* The message was parsed earlier. */
+
+    if ((msg = mx_open_message (ctx, cur->msgno))) {
+      mutt_parse_part (msg->fp, cur->content);
+
+      cur->security = crypt_query (cur->content);
+
+      mx_close_message (&msg);
+    }
+  } while (0);
+  mutt_count_body_parts (cur, flags | M_PARTS_RECOUNT);
+}