Lines 815-820
static int sync_mailbox (CONTEXT *ctx, i
Link Here
|
815 |
return rc; |
815 |
return rc; |
816 |
} |
816 |
} |
817 |
|
817 |
|
|
|
818 |
/* move deleted mails to the trash folder */ |
819 |
static int trash_append (CONTEXT *ctx) |
820 |
{ |
821 |
CONTEXT *ctx_trash; |
822 |
int i = 0; |
823 |
struct stat st, stc; |
824 |
|
825 |
if (!TrashPath || !ctx->deleted || |
826 |
(ctx->magic == M_MAILDIR && option (OPTMAILDIRTRASH))) |
827 |
return 0; |
828 |
|
829 |
for (;i < ctx->msgcount && (!ctx->hdrs[i]->deleted || |
830 |
ctx->hdrs[i]->appended); i++); |
831 |
if (i == ctx->msgcount) |
832 |
return 0; /* nothing to be done */ |
833 |
|
834 |
if (mutt_save_confirm (TrashPath, &st) != 0) |
835 |
{ |
836 |
mutt_error _("message(s) not deleted"); |
837 |
return -1; |
838 |
} |
839 |
|
840 |
if (lstat (ctx->path, &stc) == 0 && stc.st_ino == st.st_ino |
841 |
&& stc.st_dev == st.st_dev && stc.st_rdev == st.st_rdev) |
842 |
return 0; /* we are in the trash folder: simple sync */ |
843 |
|
844 |
if ((ctx_trash = mx_open_mailbox (TrashPath, M_APPEND, NULL)) != NULL) |
845 |
{ |
846 |
for (i = 0 ; i < ctx->msgcount ; i++) |
847 |
if (ctx->hdrs[i]->deleted && !ctx->hdrs[i]->appended |
848 |
&& mutt_append_message (ctx_trash, ctx, ctx->hdrs[i], 0, 0) == -1) |
849 |
{ |
850 |
mx_close_mailbox (ctx_trash, NULL); |
851 |
return -1; |
852 |
} |
853 |
|
854 |
mx_close_mailbox (ctx_trash, NULL); |
855 |
} |
856 |
else |
857 |
{ |
858 |
mutt_error _("Can't open trash folder"); |
859 |
return -1; |
860 |
} |
861 |
|
862 |
return 0; |
863 |
} |
864 |
|
818 |
/* save changes and close mailbox */ |
865 |
/* save changes and close mailbox */ |
819 |
int mx_close_mailbox (CONTEXT *ctx, int *index_hint) |
866 |
int mx_close_mailbox (CONTEXT *ctx, int *index_hint) |
820 |
{ |
867 |
{ |
Lines 954-959
int mx_close_mailbox (CONTEXT *ctx, int
Link Here
|
954 |
if (mutt_append_message (&f, ctx, ctx->hdrs[i], 0, CH_UPDATE_LEN) == 0) |
1001 |
if (mutt_append_message (&f, ctx, ctx->hdrs[i], 0, CH_UPDATE_LEN) == 0) |
955 |
{ |
1002 |
{ |
956 |
mutt_set_flag (ctx, ctx->hdrs[i], M_DELETE, 1); |
1003 |
mutt_set_flag (ctx, ctx->hdrs[i], M_DELETE, 1); |
|
|
1004 |
mutt_set_flag (ctx, ctx->hdrs[i], M_APPENDED, 1); |
957 |
} |
1005 |
} |
958 |
else |
1006 |
else |
959 |
{ |
1007 |
{ |
Lines 975-980
int mx_close_mailbox (CONTEXT *ctx, int
Link Here
|
975 |
return 0; |
1023 |
return 0; |
976 |
} |
1024 |
} |
977 |
|
1025 |
|
|
|
1026 |
/* copy mails to the trash before expunging */ |
1027 |
if (purge && ctx->deleted) |
1028 |
if (trash_append (ctx) != 0) |
1029 |
{ |
1030 |
ctx->closing = 0; |
1031 |
return -1; |
1032 |
} |
1033 |
|
978 |
#ifdef USE_IMAP |
1034 |
#ifdef USE_IMAP |
979 |
/* allow IMAP to preserve the deleted flag across sessions */ |
1035 |
/* allow IMAP to preserve the deleted flag across sessions */ |
980 |
if (ctx->magic == M_IMAP) |
1036 |
if (ctx->magic == M_IMAP) |
Lines 1167-1172
int mx_sync_mailbox (CONTEXT *ctx, int *
Link Here
|
1167 |
* mx_update_tables, so ctx->deleted is 0 when it comes back */ |
1223 |
* mx_update_tables, so ctx->deleted is 0 when it comes back */ |
1168 |
msgcount = ctx->msgcount; |
1224 |
msgcount = ctx->msgcount; |
1169 |
deleted = ctx->deleted; |
1225 |
deleted = ctx->deleted; |
|
|
1226 |
|
1227 |
if (purge && ctx->deleted) |
1228 |
{ |
1229 |
if (trash_append (ctx) == -1) |
1230 |
return -1; |
1231 |
} |
1170 |
|
1232 |
|
1171 |
#ifdef USE_IMAP |
1233 |
#ifdef USE_IMAP |
1172 |
if (ctx->magic == M_IMAP) |
1234 |
if (ctx->magic == M_IMAP) |