3

When an employee has left the company I want to move their entire Maildir to be a folder in an "old employees" account.

Given that Maildir uses the filesystem exclusively, I feel it should be possible to just mv ~fred/Maildir ~oldemployees/Maildir/fred or similar.

If I do that, how to I trigger the mail client to notice there's a new directory?

RickMeasham
  • 153
  • 2
  • 6

3 Answers3

4

Given that Maildir uses the filesystem exclusively, I feel it should be possible to just mv ~fred/Maildir ~oldemployees/Maildir/fred or similar

It depends on dovecot configuration

By default dovecot use Maildir++ layout to store the email.

  • ~/Maildir/new, ~/Maildir/cur and ~/Maildir/tmp directories contain the messages for INBOX. The tmp directory is used during delivery, new messages arrive in new and read shall be moved to cur by the clients.
  • ~/Maildir/.folder/ is a mailbox folder
  • ~/Maildir/.folder.subfolder/ is a subfolder of a folder (ie. "folder/subfolder")

So, in this case you can use command

mv ~fred/Maildir ~oldemployees/Maildir/.fred

You can also optionally use the "fs" layout by appending :LAYOUT=fs to mail_location. This makes the folder structure look like:

  • ~/Maildir/new, ~/Maildir/cur and ~/Maildir/tmp directories contain the messages for INBOX, just like with Maildir++.
  • ~/Maildir/folder/ is a mailbox folder
  • ~/Maildir/folder/subfolder/ is a subfolder of a folder

If I do that, how to I trigger the mail client to notice there's a new directory?

It also depends on mail client.

My Squirrelmail always subscribe new folder automatically. Thunderbird required you to click [File] - [Subscribe...] and activate new folder so it appear in the screen.

masegaloeh
  • 18,236
  • 10
  • 57
  • 106
2

On our IMAP server with Dovecot, I do it like this, to copy a whole Maildir hierarchy into a subfolder of another user's mail box:

Define variables so that rest can be copy/pasted

olduser=martina
olddir=/home/$olduser/Maildir

newuser=jasmin
newgroup=users
newdir=/home/$newuser/Maildir
newfolder="Martina"
newdest="$newdir/.$newfolder"

Move all folders and subfolders into a subfolder of another user

mkdir -v "$newdest"
for d in cur new tmp; do mv -vi "$olddir/$d" "$newdest/"; done

# Move only folders which contain mails,
# and exclude some special folders like Trash, etc.

cd $olddir
for d in .??*; do
  if [[ "$d" =~ ^.(Junk|Trash)$ ]] || [ -z "$(find "$d"/{cur,new,tmp} -type f)" ]; then
    echo ignore "$d"; continue;
  fi;
  mv -vi "$d" "$newdest/$d";
done

# subscribe new user to new folders

find "$newdir" -maxdepth 1 -type d -name ".$newfolder*" -printf "%f\n"
 | while read d; do echo ${d/#./}; done
 | cat - "$newdir/subscriptions"
 | sort -u > "$newdir/subscriptions.new"

mv "$newdir/subscriptions.new" "$newdir/subscriptions"

# fix ownership/permissions

chmod -R u=rwX,go=          "$newdir"
chown -R $newuser:$newgroup "$newdir"

# Check ownership/permissions
find "$newdir" -not -perm 700 -type d -ls
find "$newdir" -not -perm 600 -type f -ls
find "$newdir" -not -user  $newuser   -ls
find "$newdir" -not -group $newgroup  -ls
mivk
  • 4,004
  • 3
  • 37
  • 32
-2
  1. doveadm mailbox create '!!New folder 2!!' -u touser@example.com
  2. doveadm mailbox subscribe '!!New folder 2!!' -u touser@example.com
  3. doveadm copy -u touser@example.com '!!New folder 2!!' user fromuser@example.com mailbox 'Old folder' ALL
Pavel
  • 1
  • This does not work in non-vmail environments due to limitation of `doveadm` command: "Currently the users, specified by -u user and user source_user, must share the same UID and GID." – fukawi2 Jun 19 '18 at 04:43