Roundcube Community Forum

Third Party Contributions => Old Style Plug-Ins => Topic started by: daddyfix on October 18, 2006, 10:00:46 AM

Title: Import Address Book from Squirrelmail Table
Post by: daddyfix on October 18, 2006, 10:00:46 AM
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
Code: [Select]
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.

Title: Import Address Book from Squirrelmail Table
Post by: lacri on March 05, 2009, 06:29:58 AM
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
Title: Import Address Book from Squirrelmail Table
Post by: zamri on March 08, 2009, 04:16:02 AM
Quote from: lacri;17465

Importantly 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?
Title: Import Address Book from Squirrelmail Table
Post by: lacri on March 09, 2009, 05:26:35 AM
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
Title: Import Address Book from Squirrelmail Table
Post by: zamri on March 10, 2009, 05:55:19 AM
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.
Title: Import Address Book from Squirrelmail Table
Post by: lacri on March 10, 2009, 10:17:49 AM
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.