1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211
|
<?php
/**
* Support functions for importing SquirreMail preferences.
*
* @author Ben Chavet <ben@horde.org>
*/
function savePrefs($user, $basename, $prefs_cache)
{
global $prefs;
// Load default SquirrelMail signature
$prefs_cache['signature'] = getSignature($basename);
// Loop through the SquirrelMail prefs and translate them to Horde prefs
foreach ($prefs_cache as $key => $val) {
$horde_pref = convert($key, $val);
if (!$horde_pref) {
continue;
}
foreach ($horde_pref as $pref) {
$prefs->retrieve($pref['scope']);
$prefs->setValue($pref['name'], $pref['value']);
}
}
// Import identities
if (isset($prefs_cache['identities']) && $prefs_cache['identities'] > 1) {
$identity = &Identity::singleton(array('imp', 'imp'), $user);
// Intentionally off-by-one
for ($i = 1; $i < $prefs_cache['identities']; $i++) {
$new_identity = array('id' => 'Identity #' . ($i + 1),
'fullname' => $prefs_cache['full_name' . $i],
'replyto_addr' => $prefs_cache['reply_to' . $i],
'from_addr' => $prefs_cache['email_address' . $i],
'signature' => getSignature($basename, $i));
if (isset($prefs_cache['prefix_sig'])) {
$new_identity['sig_dashes'] = $prefs_cache['prefix_sig'];
}
if (isset($prefs_cache['sig_first'])) {
$new_identity['sig_first'] = $prefs_cache['sig_first'];
}
if (isset($prefs_cache['sent_folder'])) {
if ($prefs_cache['sent_folder'] == '[ ' . _("Do not use Sent") . ' ]') {
$new_identity['save_sent_mail'] = 0;
} else {
$new_identity['save_sent_mail'] = 1;
}
}
$identity->add($new_identity);
}
$identity->save();
}
// Store prefs
$prefs->store();
}
/**
* Returns the horde pref value(s) that correspond with the given squirrelmail
* pref.
*
* @return array of pref arrays ('name', 'scope', 'value').
* false if there is no horde pref equivalent, or the horde default
* should be used.
*/
function convert($sm_pref_name, $sm_pref_value)
{
switch ($sm_pref_name) {
case 'compose_new_win':
return array(array('name' => 'compose_popup', 'scope' => 'imp', 'value' => $sm_pref_value));
break;
case 'draft_folder':
if ($sm_pref_value != '[ ' . _("Do not use Drafts") . ' ]') {
return array(array('name' => 'drafts_folder', 'scope' => 'imp', 'value' => $sm_pref_value));
}
break;
case 'email_address':
return array(array('name' => 'from_addr', 'scope' => 'horde', 'value' => $sm_pref_value));
break;
case 'full_name':
return array(array('name' => 'fullname', 'scope' => 'horde', 'value' => $sm_pref_value));
break;
case 'hour_format':
return array(array('name' => 'twentyFour', 'scope' => 'horde', 'value' => ($sm_pref_value == 1)));
break;
case 'internal_date_sort':
if ($sm_pref_value == 1) {
return array(array('name' => 'sortby', 'scope' => 'imp', 'value' => '1'));
}
break;
case 'language':
return array(array('name' => 'language', 'scope' => 'horde', 'value' => $sm_pref_value));
break;
case 'left_refresh':
return array(array('name' => 'menu_refresh_time', 'scope' => 'horde', 'value' => $sm_pref_value));
break;
case 'left_size':
return array(array('name' => 'sidebar_width', 'scope' => 'horde', 'value' => $sm_pref_value));
break;
case 'mdn_user_support':
$value = 'ask';
if ($sm_pref_value == 0) {
$value = 'never';
}
return array(array('name' => 'disposition_request_read',
'scope' => 'imp',
'value' => $value));
break;
case 'prefix_sig':
return array(array('name' => 'sig_dashes', 'scope' => 'imp', 'value' => $sm_pref_value));
break;
case 'reply_citation_style':
switch ($sm_pref_value) {
case 'none':
return array(array('name' => 'attrib_text', 'scope' => 'imp', 'value' => ''));
break;
case 'author_said':
return array(array('name' => 'attrib_text', 'scope' => 'imp', 'value' => '%p wrote'));
break;
case 'date_time_author':
return array(array('name' => 'attrib_text', 'scope' => 'imp', 'value' => 'On %c, %p wrote'));
break;
}
break;
case 'reply_to':
return array(array('name' => 'replyto_addr', 'scope' => 'imp', 'value' => $sm_pref_value));
break;
case 'sent_folder':
if ($sm_pref_value == '[ ' . _("Do not use Sent") . ' ]') {
return array(array('name' => 'save_sent_mail', 'scope' => 'imp', 'value' => '0'));
}
return array(array('name' => 'save_sent_mail', 'scope' => 'imp', 'value' => '1'),
array('name' => 'sent_mail_folder', 'scope' => 'imp', 'value' => $sm_pref_value));
break;
case 'show_num':
return array(array('name' => 'max_msgs', 'scope' => 'imp', 'value' => $sm_pref_value));
break;
case 'show_xmailer_default':
if ($sm_pref_value == 1) {
$GLOBALS['prefs']->retrieve('imp');
$value = "X-Mailer\n" . $GLOBALS['prefs']->getValue('mail_hdr');
return array(array('name' => 'mail_hdr', 'scope' => 'imp', 'value' => trim($value)));
}
break;
case 'sig_first':
return array(array('name' => 'sig_first', 'scope' => 'imp', 'value' => $sm_pref_value));
break;
case 'signature':
return array(array('name' => 'signature', 'scope' => 'imp', 'value' => $sm_pref_value));
break;
case 'sort_by_ref':
if ($sm_pref_value == 1) {
return array(array('name' => 'sortby', 'scope' => 'imp', 'value' => '161'));
}
break;
case 'timezone':
return array(array('name' => 'timezone', 'scope' => 'horde', 'value' => $sm_pref_value));
break;
case 'trash_folder':
if ($sm_pref_value == '[ ' . _("Do not use Trash") . ' ]') {
return array(array('name' => 'use_trash', 'scope' => 'imp', 'value' => '0'));
}
return array(array('name' => 'use_trash', 'scope' => 'imp', 'value' => '1'),
array('name' => 'trash_folder', 'scope' => 'imp', 'value' => $sm_pref_value));
break;
case 'unseen_notify':
if ($sm_pref_value == 2) {
return array(array('name' => 'nav_poll_all', 'scope' => 'imp', 'value' => false));
} else if ($sm_pref_value == 3) {
return array(array('name' => 'nav_poll_all', 'scope' => 'imp', 'value' => true));
}
break;
case 'use_signature':
if ($sm_pref_value == 0) {
return array(array('name' => 'signature', 'scope' => 'imp', 'value' => ''));
}
break;
// The rest of the SquirrelMail options do not translate
default:
return false;
}
// Default to no conversion.
return false;
}
|