Migrating emails from one Inbox (User A) to another (User B)
Mailbox Structure
All mailboxes are stored in the following directory format:
/var/vmail/{domain.name}/{user.name}/Maildir
Within the Maildir
all available folders are named beginning with a ".
"
These are the Default folders:
.Drafts --> Drafts .Sent --> Sent .Spam --> Spam .Trash --> Trash
Furthermore the user-created custom folders also begins with a ".
" as well.
.Favourites --> Favourites
The default emails in the Inbox folder of the user resides in cur
directory.
Correspondingly each individual folder has their own cur
directory to store their respective emails.
/var/vmail/{domain.name}/{user.name}/Maildir/cur --> Inbox /var/vmail/{domain.name}/{user.name}/Maildir/.Drafts/cur --> Drafts /var/vmail/{domain.name}/{user.name}/Maildir/.Favourites/cur --> Favourites /var/vmail/{domain.name}/{user.name}/Maildir/.Sent/cur --> Sent /var/vmail/{domain.name}/{user.name}/Maildir/.Spam/cur --> Spam /var/vmail/{domain.name}/{user.name}/Maildir/.Trash/cur --> Trash
Migrating Mailboxes
In order to migrate mailboxes from one user (User A) of arditi.pt to another user (User B) of iti.larsys.pt, we need to simply copy the contents of the cur
directory of their respective folders and subsequently fix their ownership.
Example
Here is an example of migrating the contents of User A's Inbox into User B's Inbox.
cp -r "/var/vmail/{arditi.pt}/{user.a}/Maildir/cur/*" "/var/vmail/{iti.larsys.pt}/{user.b}/Maildir/cur/"
This can be done for all the sub-folders via copying their respective cur
directory.
cp -r "/var/vmail/{arditi.pt}/{user.a}/Maildir/.Drafts/cur/*" "/var/vmail/{iti.larsys.pt}/{user.b}/Maildir/.Drafts/cur/" cp -r "/var/vmail/{arditi.pt}/{user.a}/Maildir/.Sent/cur/*" "/var/vmail/{iti.larsys.pt}/{user.b}/Maildir/.Sent/cur/" cp -r "/var/vmail/{arditi.pt}/{user.a}/Maildir/.Spam/cur/*" "/var/vmail/{iti.larsys.pt}/{user.b}/Maildir/.Spam/cur/" cp -r "/var/vmail/{arditi.pt}/{user.a}/Maildir/.Trash/cur/*" "/var/vmail/{iti.larsys.pt}/{user.b}/Maildir/.Trash/cur/"
Finally we need to fix the ownership of the files (ebox:ebox
by default):
chown -r ebox:ebox "/var/vmail/{iti.larsys.pt}/{user.b}/Maildir/"