mutt stable branch with some hacks
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Create mx_ops.sync operation. Refactor compress to use the mx_ops.sync.

Change compress.sync_mailbox() to lock the compressed mailbox around
both the tempfile sync and compress operations. This will prevent
changes made inbetween the two syncs from being overwritten.

Thanks to Damien Riegel for his original patch refactoring
mx_ops.sync, which this patch is partially based upon.

+44 -61
+24 -9
compress.c
··· 816 816 } 817 817 818 818 /** 819 - * mutt_comp_sync - Save changes to the compressed mailbox file 819 + * sync_mailbox - Save changes to the compressed mailbox file 820 820 * @ctx: Mailbox to sync 821 821 * 822 - * Changes in Mutt only affect the tmp file. Calling mutt_comp_sync() 822 + * Changes in Mutt only affect the tmp file. Calling sync_mailbox() 823 823 * will commit them to the compressed file. 824 824 * 825 825 * Returns: 826 826 * 0: Success 827 827 * -1: Failure 828 828 */ 829 - int 830 - mutt_comp_sync (CONTEXT *ctx) 829 + static int 830 + sync_mailbox (CONTEXT *ctx, int *index_hint) 831 831 { 832 832 if (!ctx) 833 833 return -1; ··· 842 842 return -1; 843 843 } 844 844 845 - /* TODO: need to refactor sync so we can lock around the 846 - * path sync as well as the compress operation */ 845 + struct mx_ops *ops = ci->child_ops; 846 + if (!ops) 847 + return -1; 848 + 847 849 if (!lock_realpath (ctx, 1)) 848 850 { 849 851 mutt_error (_("Unable to lock mailbox!")); 850 852 return -1; 851 853 } 852 854 853 - int rc = execute_command (ctx, ci->close, _("Compressing %s")); 855 + /* TODO: check if mailbox changed first! */ 856 + 857 + int rc = ops->sync (ctx, index_hint); 858 + if (rc != 0) 859 + { 860 + unlock_realpath (ctx); 861 + return rc; 862 + } 863 + 864 + rc = execute_command (ctx, ci->close, _("Compressing %s")); 854 865 if (rc == 0) 866 + { 867 + unlock_realpath (ctx); 855 868 return -1; 869 + } 856 870 857 - unlock_realpath (ctx); 871 + store_size (ctx); 858 872 859 - store_size (ctx); 873 + unlock_realpath (ctx); 860 874 861 875 return 0; 862 876 } ··· 894 908 .open_append = open_append_mailbox, 895 909 .close = close_mailbox, 896 910 .check = check_mailbox, 911 + .sync = sync_mailbox, 897 912 .open_msg = open_message, 898 913 .close_msg = close_message, 899 914 .commit_msg = commit_message,
-1
compress.h
··· 23 23 24 24 int mutt_comp_can_append (CONTEXT *ctx); 25 25 int mutt_comp_can_read (const char *path); 26 - int mutt_comp_sync (CONTEXT *ctx); 27 26 int mutt_comp_valid_command (const char *cmd); 28 27 29 28 extern struct mx_ops mx_comp_ops;
+1
imap/imap.c
··· 2188 2188 .commit_msg = imap_commit_message, 2189 2189 .open_new_msg = imap_open_new_message, 2190 2190 .check = imap_check_mailbox_reopen, 2191 + .sync = NULL, /* imap syncing is handled by imap_sync_mailbox */ 2191 2192 };
+11 -1
mbox.c
··· 802 802 * 0 success 803 803 * -1 failure 804 804 */ 805 - int mbox_sync_mailbox (CONTEXT *ctx, int *index_hint) 805 + static int mbox_sync_mailbox (CONTEXT *ctx, int *index_hint) 806 806 { 807 807 char tempfile[_POSIX_PATH_MAX]; 808 808 char buf[32]; ··· 817 817 FILE *fp = NULL; 818 818 progress_t progress; 819 819 char msgbuf[STRING]; 820 + BUFFY *tmp = NULL; 820 821 821 822 /* sort message by their position in the mailbox on disk */ 822 823 if (Sort != SORT_ORDER) ··· 1114 1115 unlink (tempfile); /* remove partial copy of the mailbox */ 1115 1116 mutt_unblock_signals (); 1116 1117 1118 + if (option(OPTCHECKMBOXSIZE)) 1119 + { 1120 + tmp = mutt_find_mailbox (ctx->path); 1121 + if (tmp && tmp->new == 0) 1122 + mutt_update_mailbox (tmp); 1123 + } 1124 + 1117 1125 return (0); /* signal success */ 1118 1126 1119 1127 bail: /* Come here in case of disaster */ ··· 1354 1362 .commit_msg = mbox_commit_message, 1355 1363 .open_new_msg = mbox_open_new_message, 1356 1364 .check = mbox_check_mailbox, 1365 + .sync = mbox_sync_mailbox, 1357 1366 }; 1358 1367 1359 1368 struct mx_ops mx_mmdf_ops = { ··· 1365 1374 .commit_msg = mmdf_commit_message, 1366 1375 .open_new_msg = mbox_open_new_message, 1367 1376 .check = mbox_check_mailbox, 1377 + .sync = mbox_sync_mailbox, 1368 1378 };
+2
mh.c
··· 2536 2536 .commit_msg = maildir_commit_message, 2537 2537 .open_new_msg = maildir_open_new_message, 2538 2538 .check = maildir_check_mailbox, 2539 + .sync = mh_sync_mailbox, 2539 2540 }; 2540 2541 2541 2542 struct mx_ops mx_mh_ops = { ··· 2547 2548 .commit_msg = mh_commit_message, 2548 2549 .open_new_msg = mh_open_new_message, 2549 2550 .check = mh_check_mailbox, 2551 + .sync = mh_sync_mailbox, 2550 2552 };
+1
mutt.h
··· 908 908 int (*open_append) (struct _context *, int flags); 909 909 int (*close) (struct _context *); 910 910 int (*check) (struct _context *ctx, int *index_hint); 911 + int (*sync) (struct _context *ctx, int *index_hint); 911 912 int (*open_msg) (struct _context *, struct _message *, int msgno); 912 913 int (*close_msg) (struct _context *, struct _message *); 913 914 int (*commit_msg) (struct _context *, struct _message *);
+3 -46
mx.c
··· 682 682 /* save changes to disk */ 683 683 static int sync_mailbox (CONTEXT *ctx, int *index_hint) 684 684 { 685 - BUFFY *tmp = NULL; 686 - int rc = -1; 685 + if (!ctx->mx_ops || !ctx->mx_ops->sync) 686 + return -1; 687 687 688 688 if (!ctx->quiet) 689 689 mutt_message (_("Writing %s..."), ctx->path); 690 690 691 - switch (ctx->magic) 692 - { 693 - case MUTT_MBOX: 694 - case MUTT_MMDF: 695 - rc = mbox_sync_mailbox (ctx, index_hint); 696 - if (option(OPTCHECKMBOXSIZE)) 697 - tmp = mutt_find_mailbox (ctx->path); 698 - break; 699 - 700 - case MUTT_MH: 701 - case MUTT_MAILDIR: 702 - rc = mh_sync_mailbox (ctx, index_hint); 703 - break; 704 - 705 - #ifdef USE_IMAP 706 - case MUTT_IMAP: 707 - /* extra argument means EXPUNGE */ 708 - rc = imap_sync_mailbox (ctx, 1, index_hint); 709 - break; 710 - #endif /* USE_IMAP */ 711 - 712 - #ifdef USE_POP 713 - case MUTT_POP: 714 - rc = pop_sync_mailbox (ctx, index_hint); 715 - break; 716 - #endif /* USE_POP */ 717 - } 718 - 719 - #if 0 720 - if (!ctx->quiet && !ctx->shutup && rc == -1) 721 - mutt_error ( _("Could not synchronize mailbox %s!"), ctx->path); 722 - #endif 723 - 724 - if (tmp && tmp->new == 0) 725 - mutt_update_mailbox (tmp); 726 - 727 - #ifdef USE_COMPRESSED 728 - /* If everything went well, the mbox handler saved the changes to our 729 - * temporary file. Next, mutt_comp_sync() will compress the temporary file. */ 730 - if ((rc == 0) && ctx->compress_info) 731 - return mutt_comp_sync (ctx); 732 - #endif 733 - 734 - return rc; 691 + return ctx->mx_ops->sync (ctx, index_hint); 735 692 } 736 693 737 694 /* move deleted mails to the trash folder */
-2
mx.h
··· 47 47 #define MMDF_SEP "\001\001\001\001\n" 48 48 #define MAXLOCKATTEMPT 5 49 49 50 - int mbox_sync_mailbox (CONTEXT *, int *); 51 50 int mbox_lock_mailbox (CONTEXT *, int, int); 52 51 int mbox_parse_mailbox (CONTEXT *); 53 52 int mmdf_parse_mailbox (CONTEXT *); ··· 55 54 int mbox_check_empty (const char *); 56 55 void mbox_reset_atime (CONTEXT *, struct stat *); 57 56 58 - int mh_sync_mailbox (CONTEXT *, int *); 59 57 int mh_check_empty (const char *); 60 58 61 59 int maildir_check_empty (const char *);
+2 -1
pop.c
··· 664 664 } 665 665 666 666 /* update POP mailbox - delete messages from server */ 667 - int pop_sync_mailbox (CONTEXT *ctx, int *index_hint) 667 + static int pop_sync_mailbox (CONTEXT *ctx, int *index_hint) 668 668 { 669 669 int i, j, ret = 0; 670 670 char buf[LONG_STRING]; ··· 944 944 .check = pop_check_mailbox, 945 945 .commit_msg = NULL, 946 946 .open_new_msg = NULL, 947 + .sync = pop_sync_mailbox, 947 948 };
-1
pop.h
··· 105 105 void pop_error (POP_DATA *, char *); 106 106 107 107 /* pop.c */ 108 - int pop_sync_mailbox (CONTEXT *, int *); 109 108 int pop_close_mailbox (CONTEXT *); 110 109 void pop_fetch_mail (void); 111 110