PDA

View Full Version : Manually convert to Maildir



dannygoh
12-21-2005, 01:58 AM
Hi,

I have converted to dovecot and one account is deleted all the email while converting.

I have daily backup on my server and it only have mbox format. How do i manually convert the mbox to Maildir for the particular users

hostpc.com
12-21-2005, 09:40 AM
I dont KNOW for certain, but this line will upgrade all users:

echo "action=convert&value=todovecot" >> /usr/local/directadmin/data/task.queue

it MIGHT be possible to insert a user= to that line - John would have to comment on that however... I'm NOT playing with it at this point - got enough problems with this version of dovecot :(

dannygoh
12-22-2005, 02:27 AM
John give a simple script to convert individual users.

Work like a charm

sander815
12-22-2005, 02:42 PM
why is this script not posted here??

DirectAdmin Support
12-22-2005, 11:25 PM
Taken from http://www.qmail.org/mbox2maildir
and modified very lightly:
#!/usr/bin/perl
#
# mbox2maildir: coverts mbox file to maildir directory - the reverse of
# maildir2mbox from the qmail distribution.
#
# Usage: mbox2maildir uses the same environment variables as maildir2mbox:
# MAILDIR is the name of your maildir directory; MAIL is the name of your
# mbox file; MAILTMP is ignored.
# WARNING: there is no locking; don't run more than one of these! you
# have been warned.
#
# based on convert-and-create by Russell Nelson <nelson@qmail.org>
# kludged into this by Ivan Kohler <ivan@voicenet.com> 97-sep-17

require 'stat.pl';

local $SIG{HUP} = 'IGNORE';
local $SIG{INT} = 'IGNORE';
local $SIG{QUIT} = 'IGNORE';
local $SIG{TERM} = 'IGNORE';
local $SIG{TSTP} = 'IGNORE';

($name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell) =
getpwuid($<);

die "fatal: home dir $dir doesn't exist\n" unless -e $dir;
&Stat($dir);
die "fatal: $name is $uid, but $dir is owned by $st_uid\n" if $uid != $st_uid;

chdir($dir) or die "fatal: unable to chdir to $dir\n";
$spoolname = "$ENV{MAILDIR}";
-d $spoolname or mkdir $spoolname,0770
or die("fatal: $spoolname doesn't exist and can't be created.\n");

chdir($spoolname) or die("fatal: unable to chdir to $spoolname.\n");
-d "tmp" or mkdir("tmp",0770) or die("fatal: unable to make tmp/ subdir\n");
-d "new" or mkdir("new",0770) or die("fatal: unable to make new/ subdir\n");
-d "cur" or mkdir("cur",0770) or die("fatal: unable to make cur/ subdir\n");

open(SPOOL, "<$ENV{MAIL}")
or die "Unable to open $ENV{$MAIL}\n";
$i = time;
while(<SPOOL>) {
if (/^From /) {
$fn = sprintf("new/%d.$$.mbox", $i);
open(OUT, ">$fn") or die("fatal: unable to create new message");
$i++;
next;
}
s/^>From /From /;
print OUT or die("fatal: unable to write to new message");
}
close(SPOOL);
close(OUT);
Usage:
[server]# MAIL=/var/spool/virtual/domain.com/user MAILDIR=/home/username/imap/domain.com/user/Maildir ./mbox2maildir
Just make sure that the directories are chmod 770 and chown username:mail when it's done.

John

interfasys
12-23-2005, 01:42 AM
This is the script that doesn't understand subfolders, changes all the dates and marks all the emails as unread, right?

Geffy
12-26-2005, 08:05 AM
btw if you want to set the dates to "hopefully" the right thing then you can use touch -t YYYYMMDDHHMM.SS filename

you should be able to get the date out of the email from the Delivery-date header

also if you want the files to be marked as unread then change the sprintf command to write to cur/ instead of new/ I think

interfasys
01-09-2006, 05:03 PM
The default conversion script does a very poor job, at least on FreeBSD.

I'd recommend using mb2md:
http://batleth.sapienti-sat.org/projects/mb2md

I used it manually on some accounts with lots of imap folders and it worked well.

nobaloney
01-09-2006, 05:24 PM
Does mb2md manage to find and convert subfolders?

Jeff

interfasys
01-09-2006, 05:36 PM
Yes indeed.

I used something like that:

mb2md -s /home/username/imap/domain/user/mail -R -d /home/username/imap/domain/user/Maildir

There are shorter ways if you manage to run the script as the user (username).

-s is the source
-d is the destination
-R tells it to do it recursively

Dates are kept and emails are correctly put in "cur", so no more unread emails. Also the annoying "DO NOT DELETE" message is automatically removed.

gerrybakker
03-10-2006, 12:38 AM
I have Redhat 9, Redhat ES3 and Centos 4 and this worked well on all of them.

I created the mb2md.pl file as per the instructions above and copied it to a new folder called mb2mb in my root folder so I could use it as shown below.
remember to chmod it to 777 so you can execute it.

This works for the virtual email accounts.It Works well.

cd /root/mb2mb
./mb2md.pl -s /var/spool/virtual/yourdomain.com/emailusername -R -d /home/username/imap/yourdomain.com/emailusername/Maildir
cd /home/username/imap/yourdomain.com/emailusername/Maildir/cur
chown username:mail *
chmod 660 *

this is for the site's root email account

cd /root/mb2md
./mb2md.pl -s /var/spool/mail/username -R -d /home/username/Maildir/
cd /home/username/Maildir/cur
chown username.mail *
chmod 660 *

diradmin
03-19-2006, 10:24 AM
Simple way to convert all at once IMAP folders (mbox) on server to Maildir



#!/bin/sh

for u in `ls /usr/local/directadmin/data/users`; do
{
for d in `cat /usr/local/directadmin/data/users/$u/domains.list`; do
{
for e in `cat /etc/virtual/$d/passwd`; do
{
for r in `echo $e | cut -d: -f1`; do
{
mb2md -s /home/$u/imap/$d/$r/mail/mail -R -d /home/$u/imap/$d/$r/Maildir
}
done;
}
done;
}
done;
}
done;


and for all main system accounts



#!/bin/sh

for u in `ls /usr/local/directadmin/data/users`; do
{
mb2md -s /home/$u/mail/mail -R -d /home/$u/Maildir
}
done;


This works if IMAP folders placed in
/home/username/imap/domain.com/email_user/mail/mail (as for Horde on our
servers). You can change path as you want

vingertop
09-29-2006, 12:42 PM
Hi All,

Is it possible to convert some users to maildir while not yet using Dovecot ?

Cheers,

Vingertop

gerrybakker
09-29-2006, 02:55 PM
YOU can't have it both ways - you need to convert all users to maildir at the same time which is what will happen if you use Dovecot.
I did the move to Dovecot last January and never regretted the move. Things are much faster and easier to manage.

vingertop
09-29-2006, 03:25 PM
OK i believe in the conversion, but i put some custom paths in my mailflow, (i had to change var/mail and var/spool/virtual) , that`s actually what is still holding me back.

Can anyone assure that the paths to be used during conversion are paths read from the various directadmin.conf & exim.conf files ?

Superdeboer
01-24-2007, 05:02 AM
Simple way to convert all at once IMAP folders (mbox) on server to Maildir



#!/bin/sh
...
mb2md ...
...


Is this script nowadays also used for the 'todovecot'-conversion which is executed by the task.queue? Or is Directadmin still using the old way of converting mbox to maildirs? (which seemed to make some mistakes with time and status)

toml
01-24-2007, 01:20 PM
This is what I used for those customers that actually used IMAP on my server. I made a few modifications to the original, so that the time stamps weren't changed and it maintained read/unread status. If it can't figure out the sent date/time it will default to current time. This worked fine for me.

Download the text file rename to perfect_maildir.pl and to use
perfect_maildir.pl /path/to/Maildir < mbox

This would need to be used with a script, to process folders, but it does the mbox conversion better than most other utilities I tried.