empress icon indicating copy to clipboard operation
empress copied to clipboard

Migrating INBOX

Open taoeffect opened this issue 9 years ago • 3 comments

Related issues: #50, #52, #47

  1. Migrate using larch --all
  2. Iterate over subfolders of INBOX using doveadm mailbox list -u {{ email }} "INBOX.*"
  3. If a mailbox of the same name as that subfolder exists in the parent directory already (mailbox A), move all of the email inside of A into the subfolder (mailbox B), delete A, then move B up one directory

Note that some people actually have INBOX.INBOX. If this is found, skip it and all subfolders of INBOX.INBOX.

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/6711400-migrating-inbox?utm_campaign=plugin&utm_content=tracker%2F8064840&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F8064840&utm_medium=issues&utm_source=github).

taoeffect avatar Dec 02 '14 23:12 taoeffect

Relevant documentation:

  • http://wiki2.dovecot.org/Tools/Doveadm/Mailbox
  • http://wiki2.dovecot.org/Tools/Doveadm/Search
  • http://wiki2.dovecot.org/Tools/Doveadm/Move

Example: List info about all top-level mailboxes

This will show how the size of all top-level folders and how many messages are in them:

doveadm mailbox list -u [email protected] \
    | grep -v "INBOX." \
    | xargs -I {} doveadm mailbox status -u [email protected] "messages vsize guid" {}

taoeffect avatar Mar 19 '16 00:03 taoeffect

Example: Move messages in root folders into corresponding INBOX. folders

Note that this command skips the messages in INBOX (unlike the previous example) as it does grep -v "INBOX" instead of grep -v "INBOX.".

The sed command is used to handle folders with spaces in their name.

[email protected]
doveadm mailbox list -u $EMAIL \
    | grep -v "INBOX" \
    | xargs -I {} doveadm mailbox status -u $EMAIL messages {} \
    | grep -v "messages=0" \
    | sed -n 's/\(.*\) messages=.*/\1/p' \
    | xargs -I {} doveadm move -u $EMAIL "INBOX.{}" mailbox "{}" ALL

Note the quotes around "INBOX.{}" and "{}"! These are important to handle mailboxes with spaces!

taoeffect avatar Mar 19 '16 01:03 taoeffect

Important note on use of separators!

The example at the bottom here indicates that the folder separator may be a variable, so it's best to write these scripts like "INBOX${SEP}{}" instead of assuming it's . as in "INBOX.{}"

Relevant links on where this setting is stored:

  • http://wiki.dovecot.org/Namespaces
  • http://wiki.dovecot.org/UserDatabase/ExtraFields

In my case the separator was stored like so:

$ doveconf -S namespace/inbox/separator
namespace/inbox/separator=
$ doveconf -S namespace/default/separator
    # empty results, nothing returned

Where doveconf -S namespace returned:

namespace=inbox
namespace/inbox/name=inbox
namespace/inbox/type=private
namespace/inbox/separator=
... [snip] ...

The file /etc/dovecot/conf.d/10-mail.conf states:

The default however depends on the underlying mail storage format.

And the rules for that are outlined here, and apparently there are two types of separators ("layout" and "namespace" separators).

taoeffect avatar Mar 19 '16 01:03 taoeffect