More modular way to open messages.
[apps/madmutt.git] / lib-mx / mh.c
index 23d21fe..5e889d6 100644 (file)
@@ -922,7 +922,24 @@ static int maildir_open_new_message (MESSAGE * msg, CONTEXT * dest, HEADER * hdr
   return 0;
 }
 
+static int maildir_open_message(MESSAGE *msg, CONTEXT *ctx, int msgno)
+{
+    HEADER *cur = ctx->hdrs[msgno];
+    char path[_POSIX_PATH_MAX];
+
+    snprintf (path, sizeof (path), "%s/%s", ctx->path, cur->path);
 
+    if ((msg->fp = fopen(path, "r")) == NULL
+    && errno == ENOENT && ctx->magic == M_MAILDIR) {
+        msg->fp = maildir_open_find_message (ctx->path, cur->path);
+    }
+
+    if (msg->fp == NULL) {
+        mutt_perror (path);
+        return -1;
+    }
+    return 0;
+}
 
 /*
  * Commit a message to a maildir folder.
@@ -1812,6 +1829,7 @@ mx_t const maildir_mx = {
     access,
     maildir_read_dir,
     maildir_open_new_message,
+    maildir_open_message,
     NULL,
     maildir_check_mailbox,
     NULL,
@@ -1827,6 +1845,7 @@ mx_t const mh_mx = {
     access,
     mh_read_dir,
     mh_open_new_message,
+    maildir_open_message,
     NULL,
     mh_check_mailbox,
     NULL,