Changeset 3705 in subversion
- Timestamp:
- Jun 3, 2010 5:12:44 AM (3 years ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
plugins/squirrelmail_usercopy/config.inc.php.dist (modified) (1 diff)
-
plugins/squirrelmail_usercopy/squirrelmail_usercopy.php (modified) (7 diffs)
-
roundcubemail/CHANGELOG (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/plugins/squirrelmail_usercopy/config.inc.php.dist
r2699 r3705 1 1 <?php 2 3 // Driver - 'file' or 'sql' 4 $rcmail_config['squirrelmail_driver'] = 'sql'; 2 5 3 6 // full path to the squirrelmail data directory 4 7 $rcmail_config['squirrelmail_data_dir'] = ''; 8 $rcmail_config['squirrelmail_data_dir_hash_level'] = 0; 5 9 10 // 'mysql://dbuser:dbpass@localhost/database' 11 $rcmail_config['squirrelmail_dsn'] = 'mysql://user:password@localhost/webmail'; 12 $rcmail_config['squirrelmail_db_charset'] = 'iso-8859-1'; 13 14 $rcmail_config['squirrelmail_address_table'] = 'address'; 15 $rcmail_config['squirrelmail_userprefs_table'] = 'userprefs'; 16 -
trunk/plugins/squirrelmail_usercopy/squirrelmail_usercopy.php
r3286 r3705 4 4 * Copy a new users identity and settings from a nearby Squirrelmail installation 5 5 * 6 * Currently only file-based data storage of Squirrelmail is supported. 7 * 8 * @version 1.1 9 * @author Thomas Bruederli 6 * @version 1.2 7 * @author Thomas Bruederli, Johannes Hessellund, pommi, Thomas Lueder 10 8 */ 11 9 class squirrelmail_usercopy extends rcube_plugin … … 14 12 15 13 private $prefs = null; 14 private $identities_level = 0; 16 15 private $abook = array(); 17 16 18 17 public function init() 19 18 { 19 $rcmail = rcmail::get_instance(); 20 $this->identities_level = intval($rcmail->config->get('identities_level', 0)); 21 20 22 $this->add_hook('create_user', array($this, 'create_user')); 21 23 $this->add_hook('create_identity', array($this, 'create_identity')); … … 26 28 // read prefs and add email address 27 29 $this->read_squirrel_prefs($p['user']); 28 if ( $this->prefs['email_address'])30 if (($this->identities_level == 0 || $identities_level == 2) && $this->prefs['email_address']) 29 31 $p['user_email'] = $this->prefs['email_address']; 30 31 32 return $p; 32 33 } … … 40 41 if ($this->prefs['full_name']) 41 42 $p['record']['name'] = $this->prefs['full_name']; 42 if ( $this->prefs['email_address'])43 if (($this->identities_level == 0 || $this->identities_level == 2) && $this->prefs['email_address']) 43 44 $p['record']['email'] = $this->prefs['email_address']; 44 if ($this->prefs['signature']) 45 $p['record']['signature'] = $this->prefs['signature']; 46 if ($this->prefs['reply-to']) 47 $p['record']['reply-to'] = $this->prefs['reply-to']; 45 if ($this->prefs['___signature___']) 46 $p['record']['signature'] = $this->prefs['___signature___']; 47 if ($this->prefs['reply-to']) 48 $p['record']['reply-to'] = $this->prefs['reply-to']; 49 if (($this->identities_level == 0 || $this->identities_level == 1) && isset($this->prefs['identities']) && $this->prefs['identities'] > 1) { 50 for ($i=1; $i < $this->prefs['identities']; $i++) { 51 unset($ident_data); 52 $ident_data = array('name' => '', 'email' => ''); // required data 53 if ($this->prefs['full_name'.$i]) 54 $ident_data['name'] = $this->prefs['full_name'.$i]; 55 if ($this->identities_level == 0 && $this->prefs['email_address'.$i]) 56 $ident_data['email'] = $this->prefs['email_address'.$i]; 57 else 58 $ident_data['email'] = $p['record']['email']; 59 if ($this->prefs['reply_to'.$i]) 60 $ident_data['reply-to'] = $this->prefs['reply_to'.$i]; 61 if ($this->prefs['___sig'.$i.'___']) 62 $ident_data['signature'] = $this->prefs['___sig'.$i.'___']; 63 // insert identity 64 $identid = $rcmail->user->insert_identity($ident_data); 65 } 66 } 48 67 49 68 // copy address book … … 66 85 $rcmail = rcmail::get_instance(); 67 86 68 if ($srcdir = $rcmail->config->get('squirrelmail_data_dir')) { 87 /**** File based backend ****/ 88 if ($rcmail->config->get('squirrelmail_driver') == 'file' && ($srcdir = $rcmail->config->get('squirrelmail_data_dir'))) { 89 if (($hash_level = $rcmail->config->get('squirrelmail_data_dir_hash_level')) > 0) 90 $srcdir = slashify($srcdir).chunk_split(substr(base_convert(crc32($uname), 10, 16), 0, $hash_level), 1, '/'); 69 91 $prefsfile = slashify($srcdir) . $uname . '.pref'; 70 92 $abookfile = slashify($srcdir) . $uname . '.abook'; 71 93 $sigfile = slashify($srcdir) . $uname . '.sig'; 72 94 $sigbase = slashify($srcdir) . $uname . '.si'; 95 73 96 if (is_readable($prefsfile)) { 74 97 $this->prefs = array(); … … 80 103 // also read signature file if exists 81 104 if (is_readable($sigfile)) { 82 $this->prefs['signature'] = utf8_encode(file_get_contents($sigfile)); 105 $this->prefs['___signature___'] = utf8_encode(file_get_contents($sigfile)); 106 } 107 108 if (isset($this->prefs['identities']) && $this->prefs['identities'] > 1) { 109 for ($i=1; $i < $this->prefs['identities']; $i++) { 110 // read signature file if exists 111 if (is_readable($sigbase.$i)) { 112 $this->prefs['___sig'.$i.'___'] = utf8_encode(file_get_contents($sigbase.$i)); 113 } 114 } 83 115 } 84 116 … … 92 124 } 93 125 } 94 } 126 } 127 /**** Database backend ****/ 128 else if ($rcmail->config->get('squirrelmail_driver') == 'sql') { 129 $this->prefs = array(); 130 131 /* connect to squirrelmail database */ 132 $db = new rcube_mdb2($rcmail->config->get('squirrelmail_dsn')); 133 $db->db_connect('r'); // connect in read mode 134 135 // $db->set_debug(true); 136 137 /* retrieve prefs */ 138 $userprefs_table = $rcmail->config->get('squirrelmail_userprefs_table'); 139 $address_table = $rcmail->config->get('squirrelmail_address_table'); 140 $db_charset = $rcmail->config->get('squirrelmail_db_charset'); 141 142 $db->query('SET CHARACTER SET '.$db_charset); 143 $db->query('SET NAMES '.$db_encoding); 144 145 $sql_result = $db->query('SELECT * FROM '.$userprefs_table.' WHERE user=?', $uname); // ? is replaced with emailaddress 146 147 while ($sql_array = $db->fetch_assoc($sql_result) ) { // fetch one row from result 148 $this->prefs[$sql_array['prefkey']] = rcube_charset_convert(rtrim($sql_array['prefval']), $db_charset); 149 } 150 151 /* retrieve address table data */ 152 $sql_result = $db->query('SELECT * FROM '.$address_table.' WHERE owner=?', $uname); // ? is replaced with emailaddress 153 154 // parse addres book 155 while ($sql_array = $db->fetch_assoc($sql_result) ) { // fetch one row from result 156 $rec['name'] = rcube_charset_convert(rtrim($sql_array['nickname']), $db_charset); 157 $rec['firstname'] = rcube_charset_convert(rtrim($sql_array['firstname']), $db_charset); 158 $rec['surname'] = rcube_charset_convert(rtrim($sql_array['lastname']), $db_charset); 159 $rec['email'] = rcube_charset_convert(rtrim($sql_array['email']), $db_charset); 160 $rec['note'] = rcube_charset_convert(rtrim($sql_array['label']), $db_charset); 161 162 if ($rec['name'] && $rec['email']) 163 $this->abook[] = $rec; 164 } 165 } // end if 'sql'-driver 95 166 } 96 167 -
trunk/roundcubemail/CHANGELOG
r3701 r3705 2 2 =========================== 3 3 4 - Multiple identity and database support for squirrelmail_usercopy plugin (#1486517) 4 5 - Support dynamic hostname (%d/%n) variables in configuration options (#1485438) 5 6 - Add 'messages_list' hook (#1486266)
Note: See TracChangeset
for help on using the changeset viewer.
