Roundcube Community Forum

 

Import Address Book from Squirrelmail Table

Started by daddyfix, October 18, 2006, 10:00:46 AM

Previous topic - Next topic

daddyfix

This is what I did to insert my email addresses from Squirrelmail into roundmail, providing yuor squirrelmail address are saved into a MySQL table


Just change your owner name from Michael to and your user_id to
INSERT INTO roundcube.contacts(
name,
firstname,
surname,
email,
user_id
)
SELECT nickname, firstname, lastname, email, '2'
FROM squirrelmail.address
WHERE owner = 'michael'
ORDER BY lastname ASC

Hope this helps someone.


lacri

#1
Thanks for the solution, I have the solution modified for RoundCube 0.2 stable that the Squirrelmail Address Book with the first login users after to put on automatically adapted is imported.

Importantly the Squirrelmail and RoundCube tables must lie in the same data base on the same MySQL server.

serach in /program/include/rcube_user.php in the static function create


if ($user_id $dbh->insert_id(get_sequence_name('users')))
{


and insert behind it


//Import Users Squirrelmail Address Book on first login start
$dbh->query(
      
"INSERT INTO ".get_table_name('contacts')."
      
	
(name, firstname, surname, email, user_id)
	
	
	
 SELECT nickname, firstname, lastname, email, '"
.$user_id."'
	
	
	
 FROM address
	
	
	
 WHERE owner = '"
.strip_newlines($user)."'
       ORDER BY lastname ASC"
);
//Import Users Squirrelmail Address Book on first login end


so it should look then


if ($user_id $dbh->insert_id(get_sequence_name('users')))
{
//Import Users Squirrelmail Address Book on first login start
    
$dbh->query(
      
"INSERT INTO ".get_table_name('contacts')."
      
	
(name, firstname, surname, email, user_id)
	
	
	
 SELECT nickname, firstname, lastname, email, '"
.$user_id."'
	
	
	
 FROM address
	
	
	
 WHERE owner = '"
.strip_newlines($user)."'
       ORDER BY lastname ASC"
);
//Import Users Squirrelmail Address Book on first login end


Additionally one can arrange also over the configurable over main.inc.php

inserts for this into /config/main.inc.php


// Import SquirrelMail Address Book after Auto Create User
// The Squirrelmail and RoundCube Tables must on the same DB
$rcmail_config['import_squirrel_addresses'] = TRUE//or FALSE


and modifie the /program/include/rcube_user.php in the static function create

so it should look then


if ($user_id $dbh->insert_id(get_sequence_name('users')))
    {
      
//Import Users Squirrelmail Address Book on first login start
      
if($rcmail->config->get('import_squirrel_addresses')) {
      
$dbh->query(
        
"INSERT INTO ".get_table_name('contacts')."
      
	
  (name, firstname, surname, email, user_id)
	
	
	
   SELECT nickname, firstname, lastname, email, '"
.$user_id."'
	
	
	
   FROM address
	
	
	
   WHERE owner = '"
.strip_newlines($user)."'
         ORDER BY lastname ASC"
);
      }
      
//Import Users Squirrelmail Address Book on first login end

zamri

#2
Quote from: lacri;17465Importantly the Squirrelmail and RoundCube tables must lie in the same data base on the same MySQL server.

It would be nice if it can import from different database. Are u planning on an update for this? If yes, i'm looking forward to testing it.

One more thing, does it run for the first time only or everytime a user logged?

lacri

No with each login, only with the first login the Address Book is not imported, then additional modifications are overwritten and are not put on not doubly contacts. A small fast solution is like that without large checking of the input.

If the data base server is the same and the Squirrelmail tables should be appropriate in another railways it also to function the railways before the name to indicate... so long the RoundCube entrance also for vintage right in the Squirrelmail table has.


if ($user_id $dbh->insert_id(get_sequence_name('users'))) 
    { 
      
//Import Users Squirrelmail Address Book on first login start 
      //Insert for squirrelmail the name of the squirrelmail DB
      
if($rcmail->config->get('import_squirrel_addresses')) { 
      
$dbh->query
        
"INSERT INTO ".get_table_name('contacts').
            (name, firstname, surname, email, user_id) 
               SELECT nickname, firstname, lastname, email, '"
.$user_id."' 
               FROM squirrelmail.address 
               WHERE owner = '"
.strip_newlines($user)."' 
         ORDER BY lastname ASC"
); 
      } 
      
//Import Users Squirrelmail Address Book on first login end

zamri

Thanks lacri. It's simple.

Can i put the code for inserting data into contacts before or after this line in rcube_user.php?

$mail_domain = $rcmail->config->mail_domain($host);

I got blank page after logged in for the first time. Refreshing the page didn't help.

lacri

the code must placed in the static function create (rcube_user.php)
before  $mail_domain = $rcmail->config->mail_domain($host);

show in the RC log folder what says the error logfile or show on you server in the php_error logfile to resolve the Problem with the blank page.