Recently, I needed to import a lot of squirrelmail addressbooks to Horde after a mass migration from ensim to plesk.
I was looking for an easier way to import all those addresses that my users pains-takingly put into their squirrelmail addressbooks. As I had thousands of addresses for 100s of users, the above method was not of any use for me 'cause it would require me to go into each and every users mailbox in squirrelmail and then export to CSV and then... blah blah blah...
So, I had to come up with a faster and easier method. I wrote up a small perl script to generate mysql statements that can add up all the address book entries for all users.
I thought I would share the script hoping it might help someone. So, here it is:
<code>
#!/usr/bin/perl
#
$file=$ARGV[0];
$ownerid=$file;
$ownerid=~ s/\.abook//;
open (FILE,"<$file");
while(<FILE>) {
chomp($line = $_);
($oalias,$ofirstname,$olastname,$oemail,$onotes) = split('\x7c',$line);
$oname = $ofirstname . " " . $olastname;
$objectid=$ownerid . int(rand(5000));
print "insert into turba_objects (object_id,owner_id,object_alias,object_email,object_name,object_notes) values (MD5('$objectid'), '$ownerid', '$oalias', '$oemail', '$oname', '$onotes')\;\n";
}
close FILE;
</code>
You can also ge the script from
http://zort.org/codes/perl/abook2turba.pl
You can just go into the squirrelmail-data directory of the ensim server (usually /home/virtual/<domain name>/var/www/squirrelmail-data) and run this script this way:
<shell>
# for abook in `ls *.abook`;do ./abook2turba.pl $abook;done;
</shell>
This will throw all the INSERT mysql statements on the screen. You can pipe the output to a file and just import it into horde database using mysqladmin or mysql command.
I wonder why Plesk didn't include this in their PMM. Or, maybe they have it planned.