Rocco Rutte:
[apps/madmutt.git] / mbox.c
diff --git a/mbox.c b/mbox.c
index d3ecea5..1cd5a0c 100644 (file)
--- a/mbox.c
+++ b/mbox.c
@@ -564,6 +564,8 @@ static int _mbox_sync_mailbox (CONTEXT * ctx, int unused, int *index_hint)
     save_sort = Sort;
     Sort = SORT_ORDER;
     mutt_sort_headers (ctx, 0);
+    Sort = save_sort;
+    need_sort = 1;
   }
 
   /* need to open the file for writing in such a way that it does not truncate
@@ -593,11 +595,9 @@ static int _mbox_sync_mailbox (CONTEXT * ctx, int unused, int *index_hint)
     rc = i;
     goto bail;
   }
-  else if (i < 0) {
+  else if (i < 0)
     /* fatal error */
-    Sort = save_sort;
     return (-1);
-  }
 
   /* Create a temporary file to write the new version of the mailbox in. */
   mutt_mktemp (tempfile);
@@ -811,8 +811,6 @@ static int _mbox_sync_mailbox (CONTEXT * ctx, int unused, int *index_hint)
     mutt_unblock_signals ();
     mx_fastclose_mailbox (ctx);
     mutt_error _("Fatal error!  Could not reopen mailbox!");
-
-    Sort = save_sort;
     return (-1);
   }
 
@@ -829,7 +827,6 @@ static int _mbox_sync_mailbox (CONTEXT * ctx, int unused, int *index_hint)
   FREE (&oldOffset);
   unlink (tempfile);            /* remove partial copy of the mailbox */
   mutt_unblock_signals ();
-  Sort = save_sort;             /* Restore the default value. */
 
   return (0);                   /* signal success */
 
@@ -862,12 +859,10 @@ bail:                          /* Come here in case of disaster */
     return (-1);
   }
 
-  if (need_sort || save_sort != Sort) {
-    Sort = save_sort;
+  if (need_sort)
     /* if the mailbox was reopened, the thread tree will be invalid so make
      * sure to start threading from scratch.  */
     mutt_sort_headers (ctx, (need_sort == M_REOPENED));
-  }
 
   return rc;
 }