| 1 |
|
<?php |
| 2 |
|
// $Id$ |
| 3 |
|
|
| 4 |
|
/** |
| 5 |
|
* @file |
| 6 |
|
* Administrative section for Mail API module |
| 7 |
|
* |
| 8 |
|
*/ |
| 9 |
|
|
| 10 |
|
function mail_api_admin($type = 'list') { |
| 11 |
|
|
| 12 |
|
|
| 13 |
|
if ($type == 'list') { |
| 14 |
|
return drupal_get_form('mail_api_settings_overview'); |
| 15 |
|
} |
| 16 |
|
else if ($type == 'add') { |
| 17 |
|
return drupal_get_form('mail_api_add_server'); |
| 18 |
|
} |
| 19 |
|
|
| 20 |
|
|
| 21 |
|
} |
| 22 |
|
|
| 23 |
|
/** |
| 24 |
|
* Main Mail API settings page. |
| 25 |
|
* |
| 26 |
|
* This will show links that any other modules have put in the |
| 27 |
|
* admin/settings/mail_api path. This is recommended for any |
| 28 |
|
* spam filtering modules, mail server modules, front-end modules, |
| 29 |
|
* etc., that need some site-wide configurations. |
| 30 |
|
*/ |
| 31 |
|
function mail_api_settings() { |
| 32 |
|
$item = menu_get_item(); |
| 33 |
|
$content = system_admin_menu_block($item); |
| 34 |
|
return theme('mail_api_settings', $content); |
| 35 |
|
} |
| 36 |
|
|
| 37 |
|
/** |
| 38 |
|
* Theme the Mail API settings page. |
| 39 |
|
*/ |
| 40 |
|
function theme_mail_api_settings($content) { |
| 41 |
|
|
| 42 |
|
$output = ''; |
| 43 |
|
|
| 44 |
|
if ($content) { |
| 45 |
|
$output = '<dl class="admin-list">'; |
| 46 |
|
foreach ($content as $item) { |
| 47 |
|
$output .= '<dt>'. l($item['title'], $item['href'], $item['options']) .'</dt>'; |
| 48 |
|
$output .= '<dd>'. $item['description'] .'</dd>'; |
| 49 |
|
} |
| 50 |
|
$output .= '</dl>'; |
| 51 |
|
} |
| 52 |
|
|
| 53 |
|
return $output; |
| 54 |
|
} |
| 55 |
|
|
| 56 |
|
/** |
| 57 |
|
* List mail server configurations. |
| 58 |
|
*/ |
| 59 |
|
function mail_api_settings_overview() { |
| 60 |
|
|
| 61 |
|
$servers = mail_api_get_servers(); |
| 62 |
|
$protocols = mail_api_protocols(); |
| 63 |
|
$encryption = mail_api_encryption_options(); |
| 64 |
|
|
| 65 |
|
|
| 66 |
|
$options['unsuspend']='Unsuspend selected servers'; |
| 67 |
|
$options['suspend']='Suspend selected servers'; |
| 68 |
|
$options['delete']='Delete selected servers'; |
| 69 |
|
|
| 70 |
|
$form['action'] = array( |
| 71 |
|
'#type' => 'fieldset', '#title' => t('Actions'), |
| 72 |
|
'#prefix' => '<div class="container-inline">', '#suffix' => '</div>' |
| 73 |
|
); |
| 74 |
|
|
| 75 |
|
$form['action']['operation'] = array('#type' => 'select', '#options' => $options, '#default_value' => 'suspend'); |
| 76 |
|
$form['action']['submit'] = array('#type' => 'submit', '#value' => t('Update')); |
| 77 |
|
|
| 78 |
|
$form['header'] = array('#type' => 'value', '#value' => array( |
| 79 |
|
theme('table_select_header_cell'), |
| 80 |
|
array('data' => t('Domain'), 'field' => 'domain'), |
| 81 |
|
array('data' => t('Protocol'), 'field' => 'protocol'), |
| 82 |
|
//array('data' => t('Hostname'), 'field' => 'hostname'), |
| 83 |
|
//array('data' => t('Port'), 'field' => 'port'), |
| 84 |
|
//array('data' => t('Encryption'), 'field' => 'encryption'), |
| 85 |
|
array('data' => t('Status'), 'field' => 'suspended'), |
| 86 |
|
array('data' => t('Operations')) |
| 87 |
|
)); |
| 88 |
|
|
| 89 |
|
$result = pager_query('SELECT * FROM {mail_api_servers}', 50); |
| 90 |
|
|
| 91 |
|
$destination = drupal_get_destination(); |
| 92 |
|
|
| 93 |
|
while ($server = db_fetch_object($result)) { |
| 94 |
|
|
| 95 |
|
$selected[$server->id] = ''; |
| 96 |
|
$server_extra = array(); |
| 97 |
|
$server_extra_str = ""; |
| 98 |
|
|
| 99 |
|
// we need to mark suspended servers |
| 100 |
|
if ($server->suspended==1) { |
| 101 |
|
$server_extra[] = t('suspended'); |
| 102 |
|
} |
| 103 |
|
|
| 104 |
|
// create a string to append to the domain |
| 105 |
|
if ($server_extra) $server_extra_str = " (". implode(", ", $server_extra) .")"; |
| 106 |
|
|
| 107 |
|
$form['domain'][$server->id] = array('#value' => trim($server->domain . $server_extra_str)); |
| 108 |
|
$form['protocol'][$server->id] = array('#value' => $server->protocol); |
| 109 |
|
|
| 110 |
|
if ($server->suspended) { |
| 111 |
|
$form['status'][$server->id] = array('#value' => t('Suspended')); |
| 112 |
|
} |
| 113 |
|
else { |
| 114 |
|
$form['status'][$server->id] = array('#value' => t('Active')); |
| 115 |
|
} |
| 116 |
|
$form['operations'][$server->id] = array('#value' => l(t('edit'), 'admin/settings/mail_api/edit/'. $server->id, array('query' => $destination))); |
| 117 |
|
} |
| 118 |
|
|
| 119 |
|
$form['selected'] = array('#type' => 'checkboxes', '#options' => $selected); |
| 120 |
|
$form['pager'] = array('#value' => theme('pager', NULL, 50, 0)); |
| 121 |
|
|
| 122 |
|
return $form; |
| 123 |
|
} |
| 124 |
|
|
| 125 |
|
|
| 126 |
|
function theme_mail_api_settings_overview($form) { |
| 127 |
|
|
| 128 |
|
if (sizeof($form['domain'])<=0) { |
| 129 |
|
$content .= t('No servers configured. Click \'Add Server\' above to configure a new server.'); |
| 130 |
|
return $content; |
| 131 |
|
} |
| 132 |
|
|
| 133 |
|
$output = drupal_render($form['action']); |
| 134 |
|
|
| 135 |
|
if (isset($form['protocol'])) { |
| 136 |
|
foreach (element_children($form['protocol']) as $key) { |
| 137 |
|
$row = array(); |
| 138 |
|
$row[] = drupal_render($form['selected'][$key]); |
| 139 |
|
$row[] = drupal_render($form['domain'][$key]); |
| 140 |
|
//$row[] = drupal_render($form['name'][$key]); |
| 141 |
|
$row[] = drupal_render($form['protocol'][$key]); |
| 142 |
|
//$row[] = drupal_render($form['hostname'][$key]); |
| 143 |
|
//$row[] = drupal_render($form['port'][$key]); |
| 144 |
|
//$row[] = drupal_render($form['encryption'][$key]); |
| 145 |
|
$row[] = drupal_render($form['status'][$key]); |
| 146 |
|
$row[] = drupal_render($form['operations'][$key]); |
| 147 |
|
$rows[] = $row; |
| 148 |
|
} |
| 149 |
|
|
| 150 |
|
} |
| 151 |
|
else { |
| 152 |
|
$rows[] = array(array('data' => t('No servers available.'), 'colspan' => '6')); |
| 153 |
|
} |
| 154 |
|
|
| 155 |
|
$output .= theme('table', $form['header']['#value'], $rows); |
| 156 |
|
|
| 157 |
|
if ($form['pager']['#value']) { |
| 158 |
|
$output .= drupal_render($form['pager']); |
| 159 |
|
} |
| 160 |
|
|
| 161 |
|
$output .= drupal_render($form); |
| 162 |
|
|
| 163 |
|
return $output; |
| 164 |
|
|
| 165 |
|
} |
| 166 |
|
|
| 167 |
|
/** |
| 168 |
|
* hook_submit processes the mail_api_settings_overview form |
| 169 |
|
* |
| 170 |
|
* @param unknown_type $form_id |
| 171 |
|
* @param unknown_type $form_state |
| 172 |
|
*/ |
| 173 |
|
function mail_api_settings_overview_submit($form_id, &$form_state) { |
| 174 |
|
$destination = drupal_get_destination(); |
| 175 |
|
|
| 176 |
|
if ($form_state['values']['operation'] == 'suspend' && sizeof($form_state['values']['selected'])>0) { |
| 177 |
|
foreach ($form_state['values']['selected'] as $id => $selected) { |
| 178 |
|
if ($id != $selected) continue; |
| 179 |
|
db_query("UPDATE {mail_api_servers} SET suspended=1 WHERE id=%d", $id); |
| 180 |
|
} |
| 181 |
|
} |
| 182 |
|
|
| 183 |
|
if ($form_state['values']['operation'] == 'unsuspend' && sizeof($form_state['values']['selected'])>0) { |
| 184 |
|
foreach ($form_state['values']['selected'] as $id => $selected) { |
| 185 |
|
|
| 186 |
|
if ($id != $selected) continue; |
| 187 |
|
db_query("UPDATE {mail_api_servers} SET suspended=0 WHERE id=%d", $id); |
| 188 |
|
|
| 189 |
|
} |
| 190 |
|
} |
| 191 |
|
|
| 192 |
|
|
| 193 |
|
if ($form_state['values']['operation'] == 'delete' && sizeof($form_state['values']['selected'])>0) { |
| 194 |
|
foreach ($form_state['values']['selected'] as $id => $selected) { |
| 195 |
|
if ($id != $selected) continue; |
| 196 |
|
db_query("DELETE FROM {mail_api_servers} WHERE id=%d", $id); |
| 197 |
|
} |
| 198 |
|
} |
| 199 |
|
|
| 200 |
|
$form_state['redirect'] = 'admin/settings/mail_api'; |
| 201 |
|
|
| 202 |
|
} |
| 203 |
|
|
| 204 |
|
function mail_api_edit_server() { |
| 205 |
|
return drupal_get_form('mail_api_edit_server_form'); |
| 206 |
|
} |
| 207 |
|
|
| 208 |
|
|
| 209 |
|
function mail_api_edit_server_form() { |
| 210 |
|
|
| 211 |
|
//drupal_set_message('editing!'); |
| 212 |
|
|
| 213 |
|
$id = arg(4); |
| 214 |
|
$server = db_fetch_object(db_query("SELECT * FROM {mail_api_servers} WHERE id=%d", $id)); |
| 215 |
|
|
| 216 |
|
|
| 217 |
|
$encryption = mail_api_value_mirror_key(mail_api_encryption_options()); |
| 218 |
|
$protocols = mail_api_protocols(); |
| 219 |
|
|
| 220 |
|
|
| 221 |
|
|
| 222 |
|
$form['mail_api'] = array( |
| 223 |
|
'#title' => t('Mail Server Information'), |
| 224 |
|
'#type' => 'fieldset', |
| 225 |
|
); |
| 226 |
|
|
| 227 |
|
$form['mail_api']['id'] = array( |
| 228 |
|
'#type' => 'hidden', |
| 229 |
|
'#value' => $id |
| 230 |
|
); |
| 231 |
|
|
| 232 |
|
/* |
| 233 |
|
$form['mail_api']['mail_api_connection_name'] = array( |
| 234 |
|
'#title' => t('Name'), |
| 235 |
|
'#description' => t('Give this connection a unique name.'), |
| 236 |
|
'#type' => 'textfield', |
| 237 |
|
'#default_value' => $server->name, |
| 238 |
|
'#required' => TRUE, |
| 239 |
|
); |
| 240 |
|
*/ |
| 241 |
|
|
| 242 |
|
$form['mail_api']['mail_api_protocol'] = array( |
| 243 |
|
'#title' => t('Protocol'), |
| 244 |
|
'#type' => 'select', |
| 245 |
|
'#default_value' => $server->protocol, |
| 246 |
|
'#options' => $protocols, |
| 247 |
|
); |
| 248 |
|
|
| 249 |
|
$form['mail_api']['mail_api_protocol_module'] = array( |
| 250 |
|
'#type' => 'hidden', |
| 251 |
|
'#value' => $protocols[$name]['module'], |
| 252 |
|
); |
| 253 |
|
|
| 254 |
|
$form['mail_api']['mail_api_hostname'] = array( |
| 255 |
|
'#title' => t('Server Hostname'), |
| 256 |
|
'#description' => t('Host name or IP address of the mail server host'), |
| 257 |
|
'#type' => 'textfield', |
| 258 |
|
'#default_value' => $server->hostname, |
| 259 |
|
'#required' => TRUE, |
| 260 |
|
); |
| 261 |
|
|
| 262 |
|
$form['mail_api']['mail_api_port'] = array( |
| 263 |
|
'#title' => t('Server Port'), |
| 264 |
|
'#type' => 'textfield', |
| 265 |
|
'#default_value' => $server->port, |
| 266 |
|
'#required' => TRUE, |
| 267 |
|
); |
| 268 |
|
|
| 269 |
|
$form['mail_api']['mail_api_encryption_values'] = array( |
| 270 |
|
'#type' => 'value', |
| 271 |
|
'#value' => $protocols[$name]['encryption'], |
| 272 |
|
); |
| 273 |
|
|
| 274 |
|
$form['mail_api']['mail_api_encryption'] = array( |
| 275 |
|
'#title' => t('Encryption'), |
| 276 |
|
'#description' => t('Encryption method used to log into the server'), |
| 277 |
|
'#type' => 'select', |
| 278 |
|
'#default_value' => $server->encryption, |
| 279 |
|
'#options' => $encryption |
| 280 |
|
); |
| 281 |
|
|
| 282 |
|
$form['mail_api']['mail_api_domain'] = array( |
| 283 |
|
'#title' => t('Domain'), |
| 284 |
|
'#description' => t('Domain associated with this connection, e.g. domain.com.'), |
| 285 |
|
'#type' => 'textfield', |
| 286 |
|
'#default_value' => $server->domain, |
| 287 |
|
'#description' => t('The domain name in the users email address. This is how Mail API can determine which server module to use for a user to access their email.'), |
| 288 |
|
); |
| 289 |
|
|
| 290 |
|
$form['mail_api']['mail_api_folder_prefix'] = array( |
| 291 |
|
'#title' => t('Folder Prefix'), |
| 292 |
|
'#description' => t('A prefix for folders, e.g. INBOX.'), |
| 293 |
|
'#type' => 'textfield', |
| 294 |
|
'#default_value' => $server->folder_prefix, |
| 295 |
|
'#description' => t('Some servers store folders as subfolders of INBOX so the full folder name looks like INBOX.folder. If this is the case, specify \'INBOX.\'.'), |
| 296 |
|
); |
| 297 |
|
|
| 298 |
|
$form['mail_api']['mail_api_hide_folder_prefix'] = array( |
| 299 |
|
'#title' => t('Hide Folder Prefix'), |
| 300 |
|
'#description' => t('Hide folder prefix.'), |
| 301 |
|
'#type' => 'checkbox', |
| 302 |
|
'#default_value' => $server->hide_folder_prefix, |
| 303 |
|
'#description' => t('If your folders have a prefix and you want to hide it, check this box.'), |
| 304 |
|
); |
| 305 |
|
|
| 306 |
|
$form['mail_api']['mail_api_inbox_folder'] = array( |
| 307 |
|
'#title' => t('Inbox Folder'), |
| 308 |
|
'#description' => t('Full path to the Inbox folder.'), |
| 309 |
|
'#type' => 'textfield', |
| 310 |
|
'#default_value' => $server->inbox_folder, |
| 311 |
|
'#description' => t('The folder where all incoming mail arroves. If not sure set to INBOX'), |
| 312 |
|
); |
| 313 |
|
|
| 314 |
|
$form['mail_api']['mail_api_trash_folder'] = array( |
| 315 |
|
'#title' => t('Trash Folder'), |
| 316 |
|
'#description' => t('Full path to the Trash folder.'), |
| 317 |
|
'#type' => 'textfield', |
| 318 |
|
'#default_value' => $server->trash_folder, |
| 319 |
|
'#description' => t('If your server uses a folder prefix, specify PREFIX.Trash, e.g. INBOX.Trash.'), |
| 320 |
|
); |
| 321 |
|
|
| 322 |
|
$form['mail_api']['mail_api_sent_folder'] = array( |
| 323 |
|
'#title' => t('Sent Folder'), |
| 324 |
|
'#description' => t('Full path to the Sent folder.'), |
| 325 |
|
'#type' => 'textfield', |
| 326 |
|
'#default_value' => $server->sent_folder, |
| 327 |
|
'#description' => t('If your server uses a folder prefix, specify PREFIX.Sent, e.g. INBOX.Sent.'), |
| 328 |
|
); |
| 329 |
|
|
| 330 |
|
$form['mail_api']['mail_api_drafts_folder'] = array( |
| 331 |
|
'#title' => t('Drafts Folder'), |
| 332 |
|
'#description' => t('Full path to the Drafts folder.'), |
| 333 |
|
'#type' => 'textfield', |
| 334 |
|
'#default_value' => $server->drafts_folder, |
| 335 |
|
'#description' => t('If your server uses a folder prefix, specify PREFIX.Drafts, e.g. INBOX.Drafts.'), |
| 336 |
|
); |
| 337 |
|
|
| 338 |
|
$form['mail_api']['mail_api_outbox_folder'] = array( |
| 339 |
|
'#title' => t('Outbox Folder'), |
| 340 |
|
'#type' => 'textfield', |
| 341 |
|
'#default_value' => $server->outbox_folder, |
| 342 |
|
'#description' => t("This is the path to the 'Outbox' folder, if the mail server supports sending emails in this manner. If this folder does not exist in the user's account, it will be created. Any SMTP settings will be ignored if this is used."), |
| 343 |
|
); |
| 344 |
|
|
| 345 |
|
|
| 346 |
|
$form['mail_api']['mail_api_options'] = array( |
| 347 |
|
'#title' => t('Connection options'), |
| 348 |
|
'#description' => t('Additional options, if any, to pass to the connection. Usually these are IMAP options.'), |
| 349 |
|
'#type' => 'textfield', |
| 350 |
|
'#default_value' => $server->options, |
| 351 |
|
'#description' => t('Some connections may require additional options, please specify them here.'), |
| 352 |
|
); |
| 353 |
|
|
| 354 |
|
|
| 355 |
|
|
| 356 |
|
$form['mail_api']['mail_api_login_suffix'] = array( |
| 357 |
|
'#title' => t('Login Suffix'), |
| 358 |
|
'#description' => t('A suffix supplied with the username during login.'), |
| 359 |
|
'#type' => 'textfield', |
| 360 |
|
'#default_value' => $server->login_suffix, |
| 361 |
|
'#description' => t('If your mail server requires a string appended to the username, e.g. user@domain.com or user+domain.com, enter it here.'), |
| 362 |
|
); |
| 363 |
|
|
| 364 |
|
|
| 365 |
|
|
| 366 |
|
|
| 367 |
|
$form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') ); |
| 368 |
|
$form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') ); |
| 369 |
|
|
| 370 |
|
|
| 371 |
|
return $form; |
| 372 |
|
|
| 373 |
|
} |
| 374 |
|
|
| 375 |
|
function theme_mail_api_edit_server_form($form) { |
| 376 |
|
return drupal_render($form); |
| 377 |
|
} |
| 378 |
|
|
| 379 |
|
|
| 380 |
|
function mail_api_edit_server_form_validate($form, &$form_state) { |
| 381 |
|
$count = db_result(db_query("SELECT COUNT(*) FROM {mail_api_servers} WHERE id<>%d AND domain='%s'", $form_state['values']['id'], $form_state['values']['mail_api_domain'])); |
| 382 |
|
|
| 383 |
|
if ($count>0) form_set_error('mail_api][domain', t('A connection for this domain already exists.')); |
| 384 |
|
} |
| 385 |
|
|
| 386 |
|
function mail_api_edit_server_form_submit($form, &$form_state) { |
| 387 |
|
|
| 388 |
|
|
| 389 |
|
if (module_exists('aes')) { |
| 390 |
|
if ($form_state['values']['smtp_primary_password']) { |
| 391 |
|
$smtp_primary_password = aes_encrypt($form_state['values']['smtp_primary_password']); |
| 392 |
|
} |
| 393 |
|
|
| 394 |
|
if ($form_state['values']['smtp_backup_password']) { |
| 395 |
|
$smtp_backup_password = aes_encrypt($form_state['values']['smtp_backup_password']); |
| 396 |
|
} |
| 397 |
|
} |
| 398 |
|
else { |
| 399 |
|
$smtp_primary_password = $form_state['values']['smtp_primary_password']; |
| 400 |
|
$smtp_backup_password = $form_state['values']['smtp_backup_password']; |
| 401 |
|
} |
| 402 |
|
|
| 403 |
|
|
| 404 |
|
|
| 405 |
|
db_query( |
| 406 |
|
"UPDATE {mail_api_servers} SET protocol='%s', protocol_module='%s', hostname='%s', port='%s', encryption='%s', domain='%s', folder_prefix='%s', hide_folder_prefix=%d, inbox_folder='%s', trash_folder='%s', sent_folder='%s', drafts_folder='%s', outbox_folder='%s', options='%s', login_suffix='%s' WHERE id=%d", |
| 407 |
|
$form_state['values']['mail_api_protocol'], |
| 408 |
|
$form_state['values']['mail_api_protocol_module'], |
| 409 |
|
$form_state['values']['mail_api_hostname'], |
| 410 |
|
(int) $form_state['values']['mail_api_port'], |
| 411 |
|
$form_state['values']['mail_api_encryption'], |
| 412 |
|
$form_state['values']['mail_api_domain'], |
| 413 |
|
$form_state['values']['mail_api_folder_prefix'], |
| 414 |
|
$form_state['values']['mail_api_hide_folder_prefix'], |
| 415 |
|
$form_state['values']['mail_api_inbox_folder'], |
| 416 |
|
$form_state['values']['mail_api_trash_folder'], |
| 417 |
|
$form_state['values']['mail_api_sent_folder'], |
| 418 |
|
$form_state['values']['mail_api_drafts_folder'], |
| 419 |
|
$form_state['values']['mail_api_outbox_folder'], |
| 420 |
|
$form_state['values']['mail_api_options'], |
| 421 |
|
$form_state['values']['mail_api_login_suffix'], |
| 422 |
|
$form_state['values']['id'] |
| 423 |
|
); |
| 424 |
|
|
| 425 |
|
drupal_set_message(t('The server configuration has been updated.')); |
| 426 |
|
|
| 427 |
|
$form_state['redirect'] = 'admin/settings/mail_api'; |
| 428 |
|
|
| 429 |
|
|
| 430 |
|
} |
| 431 |
|
|
| 432 |
|
|
| 433 |
|
/** |
| 434 |
|
* Create a form for adding new mail server configuration to database. |
| 435 |
|
*/ |
| 436 |
|
function mail_api_add_server() { |
| 437 |
|
$encryption = mail_api_value_mirror_key(mail_api_encryption_options()); |
| 438 |
|
|
| 439 |
|
|
| 440 |
|
//print_r($encryption); |
| 441 |
|
|
| 442 |
|
$protocols = mail_api_protocols(); |
| 443 |
|
|
| 444 |
|
|
| 445 |
|
/* |
| 446 |
|
foreach($protocols as $name => $value) { |
| 447 |
|
if($name == $p_name['name']) { |
| 448 |
|
break; |
| 449 |
|
} |
| 450 |
|
} |
| 451 |
|
*/ |
| 452 |
|
|
| 453 |
|
$form['mail_api'] = array( |
| 454 |
|
'#title' => t('Mail Server Information'), |
| 455 |
|
'#type' => 'fieldset', |
| 456 |
|
); |
| 457 |
|
|
| 458 |
|
/* |
| 459 |
|
$form['mail_api']['mail_api_connection_name'] = array( |
| 460 |
|
'#title' => t('Name'), |
| 461 |
|
'#description' => t('Give this connection a unique name.'), |
| 462 |
|
'#type' => 'textfield', |
| 463 |
|
'#required' => TRUE, |
| 464 |
|
); |
| 465 |
|
*/ |
| 466 |
|
|
| 467 |
|
$form['mail_api']['mail_api_protocol'] = array( |
| 468 |
|
'#title' => t('Protocol'), |
| 469 |
|
'#type' => 'select', |
| 470 |
|
'#options' => $protocols, |
| 471 |
|
); |
| 472 |
|
|
| 473 |
|
$form['mail_api']['mail_api_protocol_module'] = array( |
| 474 |
|
'#type' => 'hidden', |
| 475 |
|
'#value' => $protocols[$name]['module'], |
| 476 |
|
); |
| 477 |
|
|
| 478 |
|
$form['mail_api']['mail_api_hostname'] = array( |
| 479 |
|
'#title' => t('Server Hostname'), |
| 480 |
|
'#description' => t('Host name or IP address of the mail server host'), |
| 481 |
|
'#type' => 'textfield', |
| 482 |
|
'#required' => TRUE, |
| 483 |
|
); |
| 484 |
|
$form['mail_api']['mail_api_port'] = array( |
| 485 |
|
'#title' => t('Server Port'), |
| 486 |
|
'#type' => 'textfield', |
| 487 |
|
'#default_value' => 143, |
| 488 |
|
'#required' => TRUE, |
| 489 |
|
); |
| 490 |
|
$form['mail_api']['mail_api_encryption_values'] = array( |
| 491 |
|
'#type' => 'value', |
| 492 |
|
'#value' => $protocols[$name]['encryption'], |
| 493 |
|
); |
| 494 |
|
$form['mail_api']['mail_api_encryption'] = array( |
| 495 |
|
'#title' => t('Encryption'), |
| 496 |
|
'#description' => t('Encryption method used to log into the server'), |
| 497 |
|
'#type' => 'select', |
| 498 |
|
'#options' => $encryption |
| 499 |
|
); |
| 500 |
|
|
| 501 |
|
$form['mail_api']['mail_api_domain'] = array( |
| 502 |
|
'#title' => t('Domain'), |
| 503 |
|
'#description' => t('Domain associated with this connection, e.g. domain.com.'), |
| 504 |
|
'#type' => 'textfield', |
| 505 |
|
'#description' => t('The domain name in the users email address. This is how Mail API can determine which server module to use for a user to access their email.'), |
| 506 |
|
); |
| 507 |
|
|
| 508 |
|
|
| 509 |
|
$form['mail_api']['mail_api_folder_prefix'] = array( |
| 510 |
|
'#title' => t('Folder Prefix'), |
| 511 |
|
'#description' => t('A prefix for folders, e.g. INBOX.'), |
| 512 |
|
'#type' => 'textfield', |
| 513 |
|
'#default_value' => $server->folder_prefix, |
| 514 |
|
'#description' => t('Some servers store folders as subfolders of INBOX so the full folder name looks like INBOX.folder. If this is the case, specify \'INBOX.\'.'), |
| 515 |
|
); |
| 516 |
|
|
| 517 |
|
$form['mail_api']['mail_api_hide_folder_prefix'] = array( |
| 518 |
|
'#title' => t('Hide Folder Prefix'), |
| 519 |
|
'#description' => t('Hide folder prefix.'), |
| 520 |
|
'#type' => 'checkbox', |
| 521 |
|
'#description' => t('If your folders have a prefix and you want to hide it, check this box.'), |
| 522 |
|
); |
| 523 |
|
|
| 524 |
|
$form['mail_api']['mail_api_inbox_folder'] = array( |
| 525 |
|
'#title' => t('Inbox Folder'), |
| 526 |
|
'#description' => t('Full path to the Inbox folder.'), |
| 527 |
|
'#type' => 'textfield', |
| 528 |
|
'#default_value' => 'INBOX', |
| 529 |
|
'#description' => t('The folder where all incoming mail arrives.'), |
| 530 |
|
); |
| 531 |
|
|
| 532 |
|
$form['mail_api']['mail_api_trash_folder'] = array( |
| 533 |
|
'#title' => t('Trash Folder'), |
| 534 |
|
'#description' => t('Full path to the Trash folder.'), |
| 535 |
|
'#type' => 'textfield', |
| 536 |
|
'#default_value' => 'Trash', |
| 537 |
|
'#description' => t('If your server uses a folder prefix, specify PREFIX.Trash, e.g. INBOX.Trash.'), |
| 538 |
|
); |
| 539 |
|
|
| 540 |
|
$form['mail_api']['mail_api_sent_folder'] = array( |
| 541 |
|
'#title' => t('Sent Folder'), |
| 542 |
|
'#description' => t('Full path to the Sent folder.'), |
| 543 |
|
'#type' => 'textfield', |
| 544 |
|
'#default_value' => 'Sent', |
| 545 |
|
'#description' => t('If your server uses a folder prefix, specify PREFIX.Sent, e.g. INBOX.Sent.'), |
| 546 |
|
); |
| 547 |
|
|
| 548 |
|
$form['mail_api']['mail_api_drafts_folder'] = array( |
| 549 |
|
'#title' => t('Drafts Folder'), |
| 550 |
|
'#description' => t('Full path to the Drafts folder.'), |
| 551 |
|
'#type' => 'textfield', |
| 552 |
|
'#default_value' => 'Drafts', |
| 553 |
|
'#description' => t('If your server uses a folder prefix, specify PREFIX.Drafts, e.g. INBOX.Drafts.'), |
| 554 |
|
); |
| 555 |
|
|
| 556 |
|
$form['mail_api']['mail_api_outbox'] = array( |
| 557 |
|
'#title' => t('Outbox Folder'), |
| 558 |
|
'#type' => 'textfield', |
| 559 |
|
'#description' => t("This is the path to the 'Outbox' folder, if the mail server supports sending emails in this manner. If this folder does not exist in the user's account, it will be created. Any SMTP settings will be ignored if this is used."), |
| 560 |
|
); |
| 561 |
|
|
| 562 |
|
|
| 563 |
|
$form['mail_api']['mail_api_options'] = array( |
| 564 |
|
'#title' => t('Connection options'), |
| 565 |
|
'#description' => t('Additional options, if any, to pass to the connection.'), |
| 566 |
|
'#type' => 'textfield', |
| 567 |
|
'#default_value' => '/notls', |
| 568 |
|
'#description' => t('Some connections may require additional options, please specify them here.'), |
| 569 |
|
); |
| 570 |
|
|
| 571 |
|
|
| 572 |
|
$form['mail_api']['mail_api_login_suffix'] = array( |
| 573 |
|
'#title' => t('Login Suffix'), |
| 574 |
|
'#description' => t('A suffix supplied with the username during login.'), |
| 575 |
|
'#type' => 'textfield', |
| 576 |
|
'#description' => t('If your mail server requires a string appended to the username, e.g. user@domain.com or user+domain.com, enter it here.'), |
| 577 |
|
); |
| 578 |
|
|
| 579 |
|
|
| 580 |
|
/* |
| 581 |
|
$form['smtp'] = array( |
| 582 |
|
'#title' => t('SMTP Server Configuration'), |
| 583 |
|
'#type' => 'fieldset', |
| 584 |
|
); |
| 585 |
|
$form['smtp']['primary'] = array( |
| 586 |
|
'#title' => t('Primary SMTP Server'), |
| 587 |
|
'#type' => 'fieldset', |
| 588 |
|
'#collapsible' => TRUE, |
| 589 |
|
'#collapsed' => TRUE, |
| 590 |
|
); |
| 591 |
|
$form['smtp']['primary']['smtp_primary_hostname'] = array( |
| 592 |
|
'#title' => t('Hostname'), |
| 593 |
|
'#type' => 'textfield', |
| 594 |
|
); |
| 595 |
|
$form['smtp']['primary']['smtp_primary_port'] = array( |
| 596 |
|
'#title' => t('Port'), |
| 597 |
|
'#type' => 'textfield', |
| 598 |
|
); |
| 599 |
|
$form['smtp']['primary']['smtp_primary_encryption_values'] = array( |
| 600 |
|
'#type' => 'value', |
| 601 |
|
'#value' => $encryption, |
| 602 |
|
); |
| 603 |
|
$form['smtp']['primary']['smtp_primary_encryption'] = array( |
| 604 |
|
'#title' => t('Encryption'), |
| 605 |
|
'#type' => 'select', |
| 606 |
|
'#options' => $form['smtp']['primary']['smtp_primary_encryption_values']['#value'], |
| 607 |
|
); |
| 608 |
|
$form['smtp']['primary']['auth'] = array( |
| 609 |
|
'#title' => t('SMTP Authentication'), |
| 610 |
|
'#type' => 'fieldset', |
| 611 |
|
'#collapsible' => TRUE, |
| 612 |
|
'#collapsed' => TRUE, |
| 613 |
|
); |
| 614 |
|
$form['smtp']['primary']['auth']['smtp_primary_auth'] = array( |
| 615 |
|
'#title' => t('Enable SMTP Authentication'), |
| 616 |
|
'#type' => 'checkbox', |
| 617 |
|
'#default_value' => FALSE, |
| 618 |
|
'#description' => t('Leave username and password blank to use user credentials.'), |
| 619 |
|
); |
| 620 |
|
$form['smtp']['primary']['auth']['smtp_primary_username'] = array( |
| 621 |
|
'#title' => t('Username'), |
| 622 |
|
'#type' => 'textfield', |
| 623 |
|
'#description' => t('Remove user name to clear password.'), |
| 624 |
|
); |
| 625 |
|
$form['smtp']['primary']['auth']['smtp_primary_password'] = array( |
| 626 |
|
'#title' => t('Password'), |
| 627 |
|
'#type' => 'password', |
| 628 |
|
'#description' => t('Leave this blank unless setting a new password.'), |
| 629 |
|
); |
| 630 |
|
|
| 631 |
|
$form['smtp']['backup'] = array( |
| 632 |
|
'#title' => t('Backup SMTP Server'), |
| 633 |
|
'#type' => 'fieldset', |
| 634 |
|
'#collapsible' => TRUE, |
| 635 |
|
'#collapsed' => TRUE, |
| 636 |
|
); |
| 637 |
|
$form['smtp']['backup']['smtp_backup_hostname'] = array( |
| 638 |
|
'#title' => t('Hostname'), |
| 639 |
|
'#type' => 'textfield', |
| 640 |
|
); |
| 641 |
|
$form['smtp']['backup']['smtp_backup_port'] = array( |
| 642 |
|
'#title' => t('Port'), |
| 643 |
|
'#type' => 'textfield', |
| 644 |
|
); |
| 645 |
|
$form['smtp']['backup']['smtp_backup_encryption_values'] = array( |
| 646 |
|
'#type' => 'value', |
| 647 |
|
'#value' => $encryption, |
| 648 |
|
); |
| 649 |
|
$form['smtp']['backup']['smtp_backup_encryption'] = array( |
| 650 |
|
'#title' => t('Encryption'), |
| 651 |
|
'#type' => 'select', |
| 652 |
|
'#options' => $form['smtp']['backup']['smtp_backup_encryption_values']['#value'], |
| 653 |
|
); |
| 654 |
|
$form['smtp']['backup']['auth'] = array( |
| 655 |
|
'#title' => t('SMTP Authentication'), |
| 656 |
|
'#type' => 'fieldset', |
| 657 |
|
'#collapsible' => TRUE, |
| 658 |
|
'#collapsed' => TRUE, |
| 659 |
|
); |
| 660 |
|
$form['smtp']['backup']['auth']['smtp_backup_auth'] = array( |
| 661 |
|
'#title' => t('Enable SMTP Authentication'), |
| 662 |
|
'#type' => 'checkbox', |
| 663 |
|
'#default_value' => FALSE, |
| 664 |
|
'#description' => t('Leave username and password blank to use user credentials.'), |
| 665 |
|
); |
| 666 |
|
$form['smtp']['backup']['auth']['smtp_backup_username'] = array( |
| 667 |
|
'#title' => t('Username'), |
| 668 |
|
'#type' => 'textfield', |
| 669 |
|
'#description' => t('Remove user name to clear password.'), |
| 670 |
|
); |
| 671 |
|
$form['smtp']['backup']['auth']['smtp_backup_password'] = array( |
| 672 |
|
'#title' => t('Password'), |
| 673 |
|
'#type' => 'password', |
| 674 |
|
'#description' => t('Leave this blank unless setting a new password.'), |
| 675 |
|
); |
| 676 |
|
|
| 677 |
|
*/ |
| 678 |
|
$form['buttons']['submit'] = array('#type' => 'submit', '#value' => t('Save configuration') ); |
| 679 |
|
$form['buttons']['reset'] = array('#type' => 'submit', '#value' => t('Reset to defaults') ); |
| 680 |
|
|
| 681 |
|
return $form; |
| 682 |
|
} |
| 683 |
|
|
| 684 |
|
|
| 685 |
|
/** |
| 686 |
|
* Insert new mail server configuration into database. |
| 687 |
|
*/ |
| 688 |
|
function mail_api_add_server_submit($form, &$form_state) { |
| 689 |
|
|
| 690 |
|
if (module_exists('aes')) { |
| 691 |
|
$smtp_primary_password = aes_encrypt($form_state['values']['smtp_primary_password']); |
| 692 |
|
$smtp_backup_password = aes_encrypt($form_state['values']['smtp_backup_password']);; |
| 693 |
|
} |
| 694 |
|
else { |
| 695 |
|
$smtp_primary_password = $form_state['values']['smtp_primary_password']; |
| 696 |
|
$smtp_backup_password = $form_state['values']['smtp_backup_password']; |
| 697 |
|
} |
| 698 |
|
|
| 699 |
|
db_query( |
| 700 |
|
'INSERT INTO {mail_api_servers} ( |
| 701 |
|
`protocol`, |
| 702 |
|
`protocol_module`, |
| 703 |
|
`hostname`, |
| 704 |
|
`port`, |
| 705 |
|
`encryption`, |
| 706 |
|
`domain`, |
| 707 |
|
`folder_prefix`, |
| 708 |
|
`hide_folder_prefix`, |
| 709 |
|
`inbox_folder`, |
| 710 |
|
`trash_folder`, |
| 711 |
|
`sent_folder`, |
| 712 |
|
`drafts_folder`, |
| 713 |
|
`outbox_folder`, |
| 714 |
|
`options`, |
| 715 |
|
`login_suffix` |
| 716 |
|
|
| 717 |
|
) VALUES ( |
| 718 |
|
"%s", |
| 719 |
|
"%s", |
| 720 |
|
"%s", |
| 721 |
|
%d, |
| 722 |
|
"%s", |
| 723 |
|
"%s", |
| 724 |
|
"%s", |
| 725 |
|
%d, |
| 726 |
|
"%s", |
| 727 |
|
"%s", |
| 728 |
|
"%s", |
| 729 |
|
"%s", |
| 730 |
|
"%s", |
| 731 |
|
"%s", |
| 732 |
|
"%s" |
| 733 |
|
)', |
| 734 |
|
$form_state['values']['mail_api_protocol'], |
| 735 |
|
$form_state['values']['mail_api_protocol_module'], |
| 736 |
|
$form_state['values']['mail_api_hostname'], |
| 737 |
|
(int) $form_state['values']['mail_api_port'], |
| 738 |
|
$form_state['values']['mail_api_encryption'], |
| 739 |
|
$form_state['values']['mail_api_domain'], |
| 740 |
|
$form_state['values']['mail_api_folder_prefix'], |
| 741 |
|
$form_state['values']['mail_api_hide_folder_prefix'], |
| 742 |
|
$form_state['values']['mail_api_inbox_folder'], |
| 743 |
|
$form_state['values']['mail_api_trash_folder'], |
| 744 |
|
$form_state['values']['mail_api_sent_folder'], |
| 745 |
|
$form_state['values']['mail_api_drafts_folder'], |
| 746 |
|
$form_state['values']['mail_api_outbox_folder'], |
| 747 |
|
$form_state['values']['mail_api_options'], |
| 748 |
|
$form_state['values']['mail_api_login_suffix'] |
| 749 |
|
); |
| 750 |
|
|
| 751 |
|
drupal_set_message(t('The server configuration has been saved.')); |
| 752 |
|
|
| 753 |
|
$form_state['redirect'] = 'admin/settings/mail_api'; |
| 754 |
|
} |
| 755 |
|
|
| 756 |
|
|
| 757 |
|
|
| 758 |
|
|
| 759 |
|
function mail_api_add_server_validate($form, &$form_state) { |
| 760 |
|
/* |
| 761 |
|
if(strlen($form_state['values']['mail_api_connection_name'])>USERNAME_MAX_LENGTH) { |
| 762 |
|
form_set_error('mail_api][connection_name', t('Connection name can not be longer than 64 characters.')); |
| 763 |
|
|
| 764 |
|
} |
| 765 |
|
*/ |
| 766 |
|
|
| 767 |
|
$count = db_result(db_query("SELECT COUNT(*) FROM {mail_api_servers} WHERE domain='%s'", $form_state['values']['mail_api_domain'])); |
| 768 |
|
|
| 769 |
|
if ($count>0) form_set_error('mail_api][connection_name', t('A connection with this name already exists.')); |
| 770 |
|
} |
| 771 |
|
|
| 772 |
|
/** |
| 773 |
|
* takes an array and returns an array where each key equals to value |
| 774 |
|
* |
| 775 |
|
* @param unknown_type $array |
| 776 |
|
* @return unknown |
| 777 |
|
*/ |
| 778 |
|
function mail_api_value_mirror_key($array) { |
| 779 |
|
if (sizeof($array)<=0) return FALSE; |
| 780 |
|
|
| 781 |
|
foreach ($array as $key => $value) { |
| 782 |
|
$new[$value]=$value; |
| 783 |
|
} |
| 784 |
|
|
| 785 |
|
return $new; |
| 786 |
|
} |