Koozali.org: home of the SME Server

User leaving company - moving e-mail to other person

Offline Jáder

  • *
  • 1,099
  • +0/-0
    • LinuxFacil
User leaving company - moving e-mail to other person
« on: December 10, 2012, 04:54:27 PM »
Hi

I'd like to find out a way to move all messages from user A, leaving company, to user B .

I'd like to be able to browse them using e-mail client or webmail/horde/imp as a new folder (old_users_A)  of user B.

How I can do it ?

I've tried to just move messages and fix permissions but this just show the inbox! :(
...

Offline hawk

  • *
  • 141
  • +0/-0
    • hawkelectronics
Re: User leaving company - moving e-mail to other person
« Reply #1 on: December 10, 2012, 05:22:06 PM »
i used thunderbird setup 2 accounts, then moved the mail from one user folder to another, takes a while but works. took about 1/2hr to move 20k emails, did all the folders. not sure if it is the correct way but it worked.

thanks

Offline janet

  • *****
  • 4,812
  • +0/-0
Re: User leaving company - moving e-mail to other person
« Reply #2 on: December 10, 2012, 06:12:11 PM »
jader

I think you need to copy each folder one at a time



Please search before asking, an answer may already exist.
The Search & other links to useful information are at top of Forum.

Offline Stefano

  • *
  • 10,894
  • +3/-0
Re: User leaving company - moving e-mail to other person
« Reply #3 on: December 10, 2012, 06:13:36 PM »
Hi

I'd like to find out a way to move all messages from user A, leaving company, to user B .

I'd like to be able to browse them using e-mail client or webmail/horde/imp as a new folder (old_users_A)  of user B.

How I can do it ?

I've tried to just move messages and fix permissions but this just show the inbox! :(

imapsync is the answer :-)

Offline Jáder

  • *
  • 1,099
  • +0/-0
    • LinuxFacil
Re: User leaving company - moving e-mail to other person
« Reply #4 on: December 10, 2012, 07:51:42 PM »
I appreciate the tips about to move using IMAP / imapsync... but that would be REALLY SLOW...  if user has GB of e-mail .
I'd prefer to move files in filesystem and fix permissions.

I can do that just for inbox... but not working for other folders.
Found out this: http://www.yellowbugcomputers.com/techdocs/movingamaildir.html

But it's not clear to me! :(
I 'll try it later... try to understand this instructions!

In mean time... if someone would like to help me to discover how to to it... I'll document for next time on our wiki.

Thanks

Jáder
...

Offline Stefano

  • *
  • 10,894
  • +3/-0
Re: User leaving company - moving e-mail to other person
« Reply #5 on: December 10, 2012, 09:18:54 PM »
I appreciate the tips about to move using IMAP / imapsync... but that would be REALLY SLOW...  if user has GB of e-mail

jader.. if both users are on the same server, process will be fast, believe me ;-)

Offline Jáder

  • *
  • 1,099
  • +0/-0
    • LinuxFacil
Re: User leaving company - moving e-mail to other person
« Reply #6 on: December 10, 2012, 11:13:02 PM »
ok... next time I'll try... right now I already have deleted user. :$
So I'll have to figure out how to transfer the hard way.
BTW: I read imapsync need to be compiled... Have someone already compiled and would like to share binary  for RHEL5/Centos5/SME8?

Thanks

Jáder
...

Offline janet

  • *****
  • 4,812
  • +0/-0
Re: User leaving company - moving e-mail to other person
« Reply #7 on: December 11, 2012, 12:50:03 AM »
jader

Here is one approach.
Generally speaking you need to copy messages in batches for each folder, one folder at a time (using the Linux command prompt) and then fix ownership.

Due to the folder structure created by the mail system ie each folder name has system subfolders of cur, new, tmp, and the folders need to be named in the format .../Maildir/foldername.subfoldername, it's an easier approach to create the main folder structure in a mail client. By doing that you will automatically create those necessary system subfolders with the correct name format & system subfolders.
Then at the command prompt copy the message files in each folder to the corresponding folder in the userB .../Maildir/....
eg
For userB in a mail client, create the main folder named userA-mail
Then (still using the mail client for userB) under that folder create all the original subfolders ie Inbox, Archives, Sales, Technical etc.

Then use the command prompt to copy the messages one folder at a time ie
cp /home/e-smith/files/users/userA/Maildir/cur/* /home/e-smith/files/users/userB/Maildir/.userA-mail.Inbox/cur

cp /home/e-smith/files/users/userA/Maildir/.Sales/cur/* /home/e-smith/files/users/userB/Maildir/.userA-mail.Sales/cur

cp /home/e-smith/files/users/userA/Maildir/.Sales/new/* /home/e-smith/files/users/userB/Maildir/.userA-mail.Sales/new

and so on, if a folder ie any .../new or .../tmp does not have any messages in it, then no need to copy that

Then fix ownership (not permissions) by doing
cd /home/e-smith/files/users/userB/
chown -R userB:userB Maildir

Do not overlook the . (dot) at the beginning of the folder names, and that each folder/subfolder is named in the format .userA-mail.Sales

You could use midnight commander (mc) & copy the messages from mc window to mc window to make this process a little easier.

The other approach is where you have copied the userA Maildir folder in totality to userB.
I think this is what you have done and is the source of your problem (ie only "seeing" the Inbox).

I think the problem with this method is that the subfolders are not named correctly, and in the wrong location.
As mentioned above, subfolder names are like .../Maildir/.userA-mail.Sales/

When copying the folders create the new folders in the format as above, which really means you have to copy & rename each folder & subfolder, either manually or with a script.

I recall the dovecot index files are automatically recreated with correct indexing etc.

Edited with corrections.
« Last Edit: December 11, 2012, 03:48:06 AM by mary »
Please search before asking, an answer may already exist.
The Search & other links to useful information are at top of Forum.

Offline Jáder

  • *
  • 1,099
  • +0/-0
    • LinuxFacil
Re: User leaving company - moving e-mail to other person
« Reply #8 on: December 11, 2012, 01:39:01 AM »
I was able to follow page about howto... it was REALLY tricky to understand.
So now I'm creating a script to do hard work... AND NEED HELP!

The script will accept 2 usernames and move mails from first to second.

What I've done so far:

Code: [Select]
[root@guepardo ~]# cat MoveEmails.sh
$origem=$1
$destino=$2
$prefixo=.AntigoFuncionario_

cd ~$2/Maildir
maildirmake $prefixo_$1
cp -pR ~$1/cur/ ~$2/Maildir/$prefixo_$1/
for diretorio in (ls -d1 ~$1/Maildir/.*)
do
  cp -pR %diretorio $prefixo_$1.%diretorio
  chmod -R 755 $prefixo_$1.%diretorio
  chown -R $2:$2  $prefixo_$1.%diretorio
done
ls -1d $prefixo_$1* >/tmp/novas-pastas
sed -e "1,$s/^\.//g" /tmp/novas-pastas
cat /tmp/novas-pastas >> subscriptions

I'm sure IT DO NOT WORK neither is finished... neither is tested.
I'll finish it tomorrow (as time permit) because it's 10:30pm here... bed time!

...

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: User leaving company - moving e-mail to other person
« Reply #9 on: December 11, 2012, 04:29:44 PM »
Generally speaking you need to copy messages in batches for each folder, one folder at a time (using the Linux command prompt) and then fix ownership.

It would be much quicker and more space efficient to rename/move the folders than to copy them.

mv ~usera/Maildir/.foo ~userb/Maildir/.foo
chown userb.userb ~userb/Maildir/.foo

Be careful that userb does not already have a folder called 'foo'.

I forget exactly how nested folders work in dovecot, but it might just be possible to do all folders in one step via:

mv ~usera/Maildir ~userb/Maildir/.fromusera
mkdir ~userb/Maildir/.oldinbox
mv ~userb/Maildir/{new,cur,tmp} ~userb/Maildir/.oldinbox
chown userb.userb ~userb/Maildir/.fromusera

Offline Jáder

  • *
  • 1,099
  • +0/-0
    • LinuxFacil
Re: User leaving company - moving e-mail to other person
« Reply #10 on: December 21, 2012, 05:44:58 PM »
My script is almost finished... still there are space to

[root@rinoceronte ~]# cat MoveEmails.sh
Code: [Select]
#!/bin/bash
echo -ne "\n\n\n\n"
origem=$1
destino=$2
prefixo=".AntigoFuncionario"
echo "Usando como prefixo = $prefixo"

pushd /home/e-smith/files/users/$destino/Maildir/ >/dev/nul
echo -ne "\n"
echo "Diretorio Atual = `pwd`"
echo "Criando /home/e-smith/files/users/$destino/Maildir/$prefixo-$origem"
maildirmake /home/e-smith/files/users/$destino/Maildir/$prefixo-$origem
echo "Copiando CUR"
# cp -pR /home/e-smith/files/users/$origem/Maildir/cur/ /home/e-smith/files/users/$destino/Maildir/$prefixo-$origem/
echo -ne "\n"
for diretorio in `ls -1d /home/e-smith/files/users/priscila/Maildir/.*|awk 'BEGIN {FS = "." } ; { print $2  }'`
do
 echo "Copiando diretorio = $diretorio"
 cp -pR .$diretorio   /home/e-smith/files/users/$destino/Maildir/$prefixo-$origem.$diretorio
done

echo "Trocando Permissoes para 755"
chmod -R 755                /home/e-smith/files/users/$destino/Maildir/$prefixo-$origem*
echo "Trocando proprietario para $destino"
chown -R $destino:$destino  /home/e-smith/files/users/$destino/Maildir/$prefixo-$origem*

ls -1d /home/e-smith/files/users/$destino/Maildir/$prefixo-$origem*|awk 'BEGIN {FS = "." } ; { print $3  }' >/tmp/novas-pastas
sed -i -e "s#^\.##g" /tmp/novas-pastas
cat /tmp/novas-pastas >> subscriptions
popd
echo "Diretorio Atual = `pwd`"

There are some problem with .sent .templates folders...

there are someone who could help me find out what's wrong ?
Later I'd like to put verifications about if dir exist before create/change to... but that's for later versions... v1 must JUST WORK! ;)

Thanks

Jáder
PS: After it it's working 100%, I'll replace mv (copy) with mv (move) ;)
...

Offline Stefano

  • *
  • 10,894
  • +3/-0
Re: User leaving company - moving e-mail to other person
« Reply #11 on: December 21, 2012, 06:10:46 PM »
jader, you are, simply, re-inventing the wheel ;-)

Offline CharlieBrady

  • *
  • 6,918
  • +3/-0
Re: User leaving company - moving e-mail to other person
« Reply #12 on: December 21, 2012, 06:43:46 PM »
My script is almost finished...

So, you ignored all my advice...

Offline Jáder

  • *
  • 1,099
  • +0/-0
    • LinuxFacil
Re: User leaving company - moving e-mail to other person
« Reply #13 on: December 21, 2012, 08:58:10 PM »
jader, you are, simply, re-inventing the wheel ;-)
I prefer to use a script than imapsync for several reasons:
1) I need nothing but the script
2) I can do it quickly... REALLY quickly if using MOVE instead to use imap commands (something like 5s x 1h for a 2 GB account)
3) I can include it as part an bigger script to delete ex-employees
4) I do not need to know/change user password (yes, I'll change it as soon as I'm communicated it will leave company!) to use script

Just for your info, I've used IMAPSYNC to move another client e-mail  (2.5 GB w/200+ folders) from one ISP to another.
It was funny. :)

...