You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

imap_fast_trash.patch 3.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. From: Antonio Radici <antonio@debian.org>
  2. Date: Thu, 27 Feb 2014 14:29:03 +0100
  3. Subject: imap_fast_trash
  4. Make "move to trash folder" use IMAP COPY.
  5. By Paul Miller
  6. Gbp-Pq: Topic features
  7. ---
  8. imap/imap.c | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  9. imap/imap.h | 3 +++
  10. mx.c | 5 +++++
  11. 3 files changed, 65 insertions(+)
  12. diff --git a/imap/imap.c b/imap/imap.c
  13. index 93dc06a..393d4ec 100644
  14. --- a/imap/imap.c
  15. +++ b/imap/imap.c
  16. @@ -886,6 +886,12 @@ static int imap_make_msg_set (IMAP_DATA* idata, BUFFER* buf, int flag,
  17. if (hdrs[n]->deleted != HEADER_DATA(hdrs[n])->deleted)
  18. match = invert ^ hdrs[n]->deleted;
  19. break;
  20. + case M_EXPIRED: /* imap_fast_trash version of M_DELETED */
  21. + if (hdrs[n]->purged)
  22. + break;
  23. + if (hdrs[n]->deleted != HEADER_DATA(hdrs[n])->deleted)
  24. + match = invert ^ (hdrs[n]->deleted && !hdrs[n]->appended);
  25. + break;
  26. case M_FLAG:
  27. if (hdrs[n]->flagged != HEADER_DATA(hdrs[n])->flagged)
  28. match = invert ^ hdrs[n]->flagged;
  29. @@ -2017,3 +2023,54 @@ int imap_complete(char* dest, size_t dlen, char* path) {
  30. return -1;
  31. }
  32. +
  33. +int imap_fast_trash() {
  34. +
  35. + if( Context->magic == M_IMAP && mx_is_imap(TrashPath) ) {
  36. + IMAP_MBOX mx;
  37. + IMAP_DATA *idata = (IMAP_DATA *) Context->data;
  38. + char mbox[LONG_STRING];
  39. + char mmbox[LONG_STRING];
  40. + int rc;
  41. + dprint(1, (debugfile, "[itf] trashcan seems to be on imap.\n"));
  42. +
  43. + if ( imap_parse_path(TrashPath, &mx) == 0 ) {
  44. + if( mutt_account_match(&(idata->conn->account), &(mx.account)) ) {
  45. + dprint(1, (debugfile, "[itf] trashcan seems to be on the same account.\n"));
  46. +
  47. + imap_fix_path (idata, mx.mbox, mbox, sizeof (mbox));
  48. + if (!*mbox)
  49. + strfcpy (mbox, "INBOX", sizeof (mbox));
  50. + imap_munge_mbox_name (mmbox, sizeof (mmbox), mbox);
  51. +
  52. + rc = imap_exec_msgset (idata, "UID COPY", mmbox, M_EXPIRED, 0, 0);
  53. + if (!rc) {
  54. + dprint (1, (debugfile, "imap_copy_messages: No messages del-tagged\n"));
  55. + rc = -1;
  56. + goto old_way;
  57. +
  58. + } else if (rc < 0) {
  59. + dprint (1, (debugfile, "could not queue copy\n"));
  60. + goto old_way;
  61. +
  62. + } else {
  63. + mutt_message (_("Copying %d messages to %s..."), rc, mbox);
  64. + return 0;
  65. + }
  66. +
  67. + } else {
  68. + dprint(1, (debugfile, "[itf] trashcan seems to be on a different account.\n"));
  69. + }
  70. +
  71. + old_way:
  72. + FREE (&mx.mbox); /* we probably only need to free this when the parse works */
  73. +
  74. + } else {
  75. + dprint(1, (debugfile, "[itf] failed to parse TrashPath.\n" ));
  76. + }
  77. +
  78. + dprint(1, (debugfile, "[itf] giving up and trying old fasioned way.\n" ));
  79. + }
  80. +
  81. + return 1;
  82. +}
  83. diff --git a/imap/imap.h b/imap/imap.h
  84. index 74d7e13..99cd454 100644
  85. --- a/imap/imap.h
  86. +++ b/imap/imap.h
  87. @@ -72,4 +72,7 @@ void imap_keepalive (void);
  88. int imap_account_match (const ACCOUNT* a1, const ACCOUNT* a2);
  89. +/* trash */
  90. +int imap_fast_trash();
  91. +
  92. #endif
  93. diff --git a/mx.c b/mx.c
  94. index 89b9431..cc60517 100644
  95. --- a/mx.c
  96. +++ b/mx.c
  97. @@ -802,6 +802,11 @@ static int trash_append (CONTEXT *ctx)
  98. && stc.st_dev == st.st_dev && stc.st_rdev == st.st_rdev)
  99. return 0; /* we are in the trash folder: simple sync */
  100. + #ifdef USE_IMAP
  101. + if( !imap_fast_trash() )
  102. + return 0;
  103. + #endif
  104. +
  105. if ((ctx_trash = mx_open_mailbox (TrashPath, M_APPEND, NULL)) != NULL)
  106. {
  107. for (i = 0 ; i < ctx->msgcount ; i++)