| 1 |
.. _imap-admin-sop-restoring-expunged-messages: |
| 2 |
|
| 3 |
============================================ |
| 4 |
Deleting and Undeleting Messages and Folders |
| 5 |
============================================ |
| 6 |
|
| 7 |
Terminology & Definitions |
| 8 |
========================= |
| 9 |
|
| 10 |
This section clarifies some of the subtle nuances between delete, |
| 11 |
expunge and expire in different contexts, used throughout this chapter. |
| 12 |
|
| 13 |
Message context |
| 14 |
--------------- |
| 15 |
|
| 16 |
Delete |
| 17 |
|
| 18 |
sets the ``\Deleted`` flag on the message using |
| 19 |
``STORE +Flags \Deleted`` via IMAP client |
| 20 |
|
| 21 |
Expunge |
| 22 |
|
| 23 |
delete messages from the cyrus folder index that have the |
| 24 |
``\Deleted`` flag set using EXPUNGE via IMAP client. With |
| 25 |
``expunge_mode: delayed``, this doesn't delete the file from |
| 26 |
the filesystem. |
| 27 |
|
| 28 |
Unexpunge |
| 29 |
|
| 30 |
recover messages into the cyrus folder index based on filesystem |
| 31 |
content (only possible with ``expunge_mode: delayed``) |
| 32 |
|
| 33 |
Undelete |
| 34 |
|
| 35 |
remove the ``\Deleted`` flag on the message using |
| 36 |
``STORE -Flags \Deleted`` via IMAP client. |
| 37 |
|
| 38 |
Folder context |
| 39 |
-------------- |
| 40 |
|
| 41 |
Delete |
| 42 |
|
| 43 |
deletes the folder and all messages inside it using ``DELETE`` |
| 44 |
via IMAP client. If using ``delete_mode: delayed``, this renames |
| 45 |
the folder, rather than deletes the folder, as discussed below. |
| 46 |
|
| 47 |
Otherwise, the folder and messages are removed from the mailbox |
| 48 |
list and the filesystem. |
| 49 |
|
| 50 |
Undelete |
| 51 |
|
| 52 |
rename the deleted folder back to the original location using |
| 53 |
``renamemailbox`` in ``cyradm``. |
| 54 |
|
| 55 |
Expiring Deleted Messages and Folders |
| 56 |
===================================== |
| 57 |
|
| 58 |
In the EVENTS block of cyrus.conf, you should have a line similar to the |
| 59 |
following:: |
| 60 |
|
| 61 |
delprune cmd="cyr_expire -E 1 -D 7 -X 7 -a" at=2300 |
| 62 |
|
| 63 |
-D 7 |
| 64 |
|
| 65 |
permanently deletes from the filesystem mailboxes and folders that |
| 66 |
were deleted more than 7 days ago. |
| 67 |
|
| 68 |
-E 1 |
| 69 |
|
| 70 |
prunes entries older than 1 day from the duplicate delivery |
| 71 |
suppression database. |
| 72 |
|
| 73 |
-X 7 |
| 74 |
|
| 75 |
permanently deletes from the filesystem expunged messages that were |
| 76 |
expunged more than 7 days ago. |
| 77 |
|
| 78 |
To use delayed deletion of mailboxes, you need the following entry in |
| 79 |
:cyrusman:`imapd.conf(5)`: |
| 80 |
|
| 81 |
.. parsed-literal:: |
| 82 |
|
| 83 |
delete_mode: delayed |
| 84 |
|
| 85 |
.. versionadded:: 2.3.9 |
| 86 |
|
| 87 |
The default prefix for deleted mailboxes is ``DELETED`` but it probably |
| 88 |
doesn't hurt to specify it in :cyrusman:`imapd.conf(5)` as well: |
| 89 |
|
| 90 |
.. parsed-literal:: |
| 91 |
|
| 92 |
deletedprefix: DELETED |
| 93 |
|
| 94 |
.. versionadded:: 2.3.9 |
| 95 |
|
| 96 |
Undeleting Folders |
| 97 |
================== |
| 98 |
|
| 99 |
The following assumes that you are using the UNIX hierarchy separator. |
| 100 |
If it's off then replace '/' in the names with '.' |
| 101 |
|
| 102 |
With the previous configuration options in place, whenever a mail folder |
| 103 |
or mailbox is deleted, it will be renamed to |
| 104 |
``DELETED/mailfoldername/4D5C6B7A`` where ``4D5C6B7A`` is a hex-encoded |
| 105 |
timestamp and ``DELETED`` is the prefix for deleted mailboxes. |
| 106 |
|
| 107 |
``4D5C6B7A`` can be converted back to a human-readable time using a |
| 108 |
simple one-liner in Perl: |
| 109 |
|
| 110 |
.. parsed-literal:: |
| 111 |
|
| 112 |
$ :command:`perl -le 'print scalar(localtime(hex("4D5C6B7A")));'` |
| 113 |
Thu Feb 17 00:27:38 2011 |
| 114 |
|
| 115 |
.. NOTE:: |
| 116 |
|
| 117 |
The ACL on the deleted folder remains the same so undeleting it is |
| 118 |
as simple as renaming it as a sub-folder of the recreated mailbox or |
| 119 |
back to the original folder name depending on whether the mailbox |
| 120 |
has been recreated or not. If you have to add an ACL to be able to |
| 121 |
delete the mailbox, you may wish to remove the ACL after the |
| 122 |
undelete has been finished. |
| 123 |
|
| 124 |
The following examples assume a mailbox for [email protected] has been |
| 125 |
deleted: |
| 126 |
|
| 127 |
.. parsed-literal:: |
| 128 |
|
| 129 |
cyradm> :command:`listmailbox user/john*@example.org` |
| 130 |
|
| 131 |
If there's no output from the above command, the mailbox has not been |
| 132 |
recreated since being deleted and you can rename the mailbox and any |
| 133 |
folders back to the original name as follows. If the mailbox has been |
| 134 |
recreated, you will probably want to rename the deleted folders into a |
| 135 |
subfolder of the new mailbox, for example |
| 136 |
``user/john/[email protected]`` becomes |
| 137 |
``user/john/[email protected]`` and |
| 138 |
``user/john/Sent/[email protected]`` becomes |
| 139 |
``user/john/restored/[email protected]`` |
| 140 |
|
| 141 |
In either case the commands are similar but with the latter option you |
| 142 |
need to insert the extra "/restored" after the ``user/john``: |
| 143 |
|
| 144 |
.. parsed-literal:: |
| 145 |
|
| 146 |
cyradm> :command:`listmailbox DELETED/user/john*@example.org` |
| 147 |
DELETED/user/john/[email protected] (\HasNoChildren) |
| 148 |
DELETED/user/john/Drafts/[email protected] (\HasNoChildren) |
| 149 |
DELETED/user/john/Sent/[email protected] (\HasNoChildren) |
| 150 |
DELETED/user/john/Trash/[email protected] (\HasNoChildren) |
| 151 |
cyradm> :command:`renamemailbox DELETED/user/john/[email protected] user/[email protected]` |
| 152 |
cyradm> :command:`renamemailbox DELETED/user/john/Drafts/[email protected] user/john/[email protected]` |
| 153 |
cyradm> :command:`renamemailbox DELETED/user/john/Sent/[email protected] user/john/[email protected]` |
| 154 |
cyradm> :command:`renamemailbox DELETED/user/john/Trash/[email protected] user/john/[email protected]` |
| 155 |
|
| 156 |
Unfortunately there's no easy way to rename the entire mailbox back |
| 157 |
including all the subfolders and the hex timestamp can vary between |
| 158 |
folders in the same mailbox if it was a mailbox with some large folders. |
| 159 |
|
| 160 |
This is because it's the time that particular folder was deleted, not |
| 161 |
when the first folder was deleted. |
| 162 |
|
| 163 |
Undeleting messages in a mailbox |
| 164 |
================================ |
| 165 |
|
| 166 |
The following examples assume you have an installation of cyrus where |
| 167 |
there are binaries in ``/usr/lib/cyrus-imapd/`` - if not, adjust path to |
| 168 |
suit. |
| 169 |
|
| 170 |
List messages available to unexpunge: |
| 171 |
|
| 172 |
.. parsed-literal:: |
| 173 |
|
| 174 |
# :command:`/usr/lib/cyrus-imapd/unexpunge -l user/[email protected]` |
| 175 |
|
| 176 |
Each message will give you something like the following: |
| 177 |
|
| 178 |
.. parsed-literal:: |
| 179 |
|
| 180 |
UID: 11422 |
| 181 |
Size: 7786 |
| 182 |
Sent: Mon Mar 10 12:00:00 2014 |
| 183 |
Recv: Mon Mar 10 16:06:32 2014 |
| 184 |
Expg: Mon Mar 10 16:53:55 2014 |
| 185 |
From: john doe <[email protected]> |
| 186 |
To : <[email protected]> |
| 187 |
Cc : |
| 188 |
Bcc : |
| 189 |
Subj: {44} |
| 190 |
re: some random subject of length 44 chars." |
| 191 |
|
| 192 |
To unexpunge a single message: |
| 193 |
|
| 194 |
.. parsed-literal:: |
| 195 |
|
| 196 |
# :command:`/usr/lib/cyrus-imapd/unexpunge -udv user/[email protected] 11422` |
| 197 |
restoring expunged messages in mailbox 'user/[email protected]' |
| 198 |
Unexpunged user/[email protected]: 11422 => 11438 |
| 199 |
restored 1 expunged messages |
| 200 |
|
| 201 |
To unexpunge all the messages and mark them as undeleted as well: |
| 202 |
|
| 203 |
.. parsed-literal:: |
| 204 |
|
| 205 |
# :command:`/usr/lib/cyrus-imapd/unexpunge -adv user/[email protected]` |
| 206 |
|
| 207 |
.. NOTE:: |
| 208 |
|
| 209 |
This isn't recursive. It will only restore the messages in the |
| 210 |
folder specified. |
| 211 |
|
| 212 |
To find other folders, :ref:`imap-reference-manpages-systemcommands-ctl_mboxlist` can be |
| 213 |
used. |
| 214 |
|
| 215 |
.. parsed-literal:: |
| 216 |
|
| 217 |
# :command:`/usr/lib/cyrus-imapd/ctl_mboxlist -d | grep example.org` |
| 218 |
example.org!user.john 0 default [email protected] lrswipkxtecda |
| 219 |
example.org!user.john.Lists 0 default [email protected] lrswipkxtecda |
| 220 |
example.org!user.john.Lists.cyrus 0 default [email protected] lrswipkxtecda |
| 221 |
example.org!user.john.Deleted Messages 0 default [email protected] lrswipkxtecda |
| 222 |
|
| 223 |
.. TODO:: |
| 224 |
|
| 225 |
The above output format no longer applies. |
| 226 |
|
| 227 |
Run the unexpunge command for every folder that needs to have mail |
| 228 |
undeleted. |
| 229 |
|
| 230 |
For folder names that have spaces ' ', the spaces need to be escaped |
| 231 |
with a backslash. |
| 232 |
|
| 233 |
.. parsed-literal:: |
| 234 |
|
| 235 |
# :command:`/usr/lib/cyrus-imapd/unexpunge -adv user/john/Deleted\ [email protected]` |