| 1 |
<?php
|
| 2 |
// $Id$
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* This is the main code file for the Basic webmail module. This module
|
| 7 |
* allows users to send and receive e-mail through an IMAP mail server.
|
| 8 |
*/
|
| 9 |
|
| 10 |
|
| 11 |
/**
|
| 12 |
* Display help and module information.
|
| 13 |
* @param section The section of the site we're displaying help on.
|
| 14 |
* @return The help text for the section.
|
| 15 |
*/
|
| 16 |
function basic_webmail_help($section='') {
|
| 17 |
$output = '';
|
| 18 |
|
| 19 |
switch ($section) {
|
| 20 |
case 'admin/settings/basic_webmail':
|
| 21 |
$output = t('Send and/or receive e-mail through an IMAP mail server.');
|
| 22 |
break;
|
| 23 |
}
|
| 24 |
|
| 25 |
return $output;
|
| 26 |
} // End of basic_webmail_help().
|
| 27 |
|
| 28 |
|
| 29 |
/* *
|
| 30 |
* The valid permissions for this module.
|
| 31 |
* @return array An array of valid permissions for the module.
|
| 32 |
* /
|
| 33 |
function basic_webmail_perm() {
|
| 34 |
return array('administrator basic_webmail users');
|
| 35 |
} // End of basic_webmail_perm().
|
| 36 |
*/
|
| 37 |
|
| 38 |
/**
|
| 39 |
* The stub for the menu callback.
|
| 40 |
* @param may_cache A boolean indicating whether cacheable menu items should be returned.
|
| 41 |
* @return An array of menu items.
|
| 42 |
*/
|
| 43 |
function basic_webmail_menu($may_cache) {
|
| 44 |
$items = array();
|
| 45 |
|
| 46 |
$items[] = array(
|
| 47 |
'path' => 'admin/settings/basic_webmail',
|
| 48 |
'title' => t('Basic webmail'),
|
| 49 |
'callback' => 'drupal_get_form',
|
| 50 |
'callback arguments' => array('basic_webmail_admin_settings'),
|
| 51 |
'access' => user_access('administer site configuration'),
|
| 52 |
'description' => t('Configure the mail server.'),
|
| 53 |
);
|
| 54 |
$items[] = array(
|
| 55 |
'path' => 'basic_webmail',
|
| 56 |
'title' => t('E-mail'),
|
| 57 |
'callback' => '_basic_webmail_mail_list',
|
| 58 |
'description' => t('Send and/or receive e-mail.'),
|
| 59 |
'access' => user_access('access content'),
|
| 60 |
'type' => MENU_NORMAL_ITEM,
|
| 61 |
);
|
| 62 |
$items[] = array(
|
| 63 |
'path' => 'basic_webmail/message',
|
| 64 |
'callback' => '_basic_webmail_message',
|
| 65 |
'type' => MENU_CALLBACK,
|
| 66 |
);
|
| 67 |
$items[] = array(
|
| 68 |
'path' => 'basic_webmail/delete',
|
| 69 |
'callback' => 'drupal_get_form',
|
| 70 |
'callback arguments' => array('_basic_webmail_delete_message_form'),
|
| 71 |
'type' => MENU_CALLBACK,
|
| 72 |
);
|
| 73 |
$items[] = array(
|
| 74 |
'path' => 'basic_webmail/sendmail',
|
| 75 |
'callback' => 'drupal_get_form',
|
| 76 |
'callback arguments' => array('_basic_webmail_send_mail_form'),
|
| 77 |
'type' => MENU_CALLBACK,
|
| 78 |
);
|
| 79 |
|
| 80 |
return $items;
|
| 81 |
} // End of basic_webmail_menu().
|
| 82 |
|
| 83 |
|
| 84 |
/**
|
| 85 |
* Administration settings form.
|
| 86 |
*/
|
| 87 |
function basic_webmail_admin_settings() {
|
| 88 |
$form = array();
|
| 89 |
|
| 90 |
$form['basic_webmail_general_settings'] = array(
|
| 91 |
'#type' => 'fieldset',
|
| 92 |
'#title' => t('General settings'),
|
| 93 |
);
|
| 94 |
|
| 95 |
$form['basic_webmail_general_settings']['basic_webmail_account_info'] = array(
|
| 96 |
'#type' => 'checkbox',
|
| 97 |
'#title' => t("Use the user's account e-mail address and password"),
|
| 98 |
'#default_value' => variable_get('basic_webmail_account_info', 0),
|
| 99 |
'#description' => "Instead of providing additional form fields to get the user's e-mail address and password, just use what is provided within the account settings.",
|
| 100 |
);
|
| 101 |
// I'm not sure I want to go this far...
|
| 102 |
// $options = array(t('1) Additional form'), t('2) Account settings'));
|
| 103 |
// $description = "Where should the user's e-mail address and password be taken from. 1) An addtional form added to the user's registration form. 2) Use the information that is provided as a part of setting up thier account.";
|
| 104 |
// if (module_exists('couriermta')) {
|
| 105 |
// $options = array(t('1) Additional form'), t('2) Account settings'), t('3) Courier MTA module'));
|
| 106 |
// $description .= " 3) Use the information that is saved in the Courier MTA module's database table.";
|
| 107 |
// }
|
| 108 |
// $form['basic_webmail_general_settings']['basic_webmail_account_info'] = array(
|
| 109 |
// '#type' => 'radios',
|
| 110 |
// '#title' => t('Where to get account e-mail address and password'),
|
| 111 |
// '#default_value' => variable_get('basic_webmail_account_info', 0),
|
| 112 |
// '#options' => $options,
|
| 113 |
// '#description' => $description,
|
| 114 |
// );
|
| 115 |
|
| 116 |
$form['basic_webmail_server_settings'] = array(
|
| 117 |
'#type' => 'fieldset',
|
| 118 |
'#title' => t('Server settings'),
|
| 119 |
);
|
| 120 |
$form['basic_webmail_server_settings']['basic_webmail_server_address'] = array(
|
| 121 |
'#type' => 'textfield',
|
| 122 |
'#title' => t('Server address'),
|
| 123 |
'#default_value' => variable_get('basic_webmail_server_address', ''),
|
| 124 |
'#description' => t('The address to the server you wish to connect to.'),
|
| 125 |
);
|
| 126 |
$form['basic_webmail_server_settings']['basic_webmail_server_port'] = array(
|
| 127 |
'#type' => 'textfield',
|
| 128 |
'#title' => t('Connection port'),
|
| 129 |
'#default_value' => variable_get('basic_webmail_server_port', '143'),
|
| 130 |
'#description' => t('The defalut IMAP port is 143 if one is not specified.'),
|
| 131 |
);
|
| 132 |
$form['basic_webmail_server_settings']['basic_webmail_secure_log_in'] = array(
|
| 133 |
'#type' => 'checkbox',
|
| 134 |
'#title' => t('Secure login.'),
|
| 135 |
'#default_value' => variable_get('basic_webmail_secure_log_in', 0),
|
| 136 |
'#description' => t('Check to make a secure connection to your IMAP Server.'),
|
| 137 |
);
|
| 138 |
$form['basic_webmail_server_settings']['basic_webmail_use_ssl'] = array(
|
| 139 |
'#type' => 'checkbox',
|
| 140 |
'#title' => t('Encrypt session using SSL.'),
|
| 141 |
'#default_value' => variable_get('basic_webmail_use_ssl', 0),
|
| 142 |
'#description' => t('Use SSL to connect to the server.'),
|
| 143 |
);
|
| 144 |
$form['basic_webmail_server_settings']['basic_webmail_validate_cert'] = array(
|
| 145 |
'#type' => 'checkbox',
|
| 146 |
'#title' => t('Validate certificate.'),
|
| 147 |
'#default_value' => variable_get('basic_webmail_validate_cert', 0),
|
| 148 |
'#description' => t('When using a secure connection, validate the certificate.'),
|
| 149 |
);
|
| 150 |
$form['basic_webmail_server_settings']['basic_webmail_use_tls'] = array(
|
| 151 |
'#type' => 'checkbox',
|
| 152 |
'#title' => t('Encrypt session using TLS.'),
|
| 153 |
'#default_value' => variable_get('basic_webmail_use_tls', 0),
|
| 154 |
'#description' => t('Use TLS to connect to the server.'),
|
| 155 |
);
|
| 156 |
|
| 157 |
return system_settings_form($form);
|
| 158 |
} // End of basic_webmail_admin_settings().
|
| 159 |
|
| 160 |
|
| 161 |
/**
|
| 162 |
* Implementation of hook_user.
|
| 163 |
*/
|
| 164 |
function basic_webmail_user($op, &$edit, &$account, $category = NULL) {
|
| 165 |
switch ($op) {
|
| 166 |
case 'delete':
|
| 167 |
break;
|
| 168 |
|
| 169 |
case 'form':
|
| 170 |
if (!variable_get('basic_webmail_account_info', 0)) {
|
| 171 |
$form['basic_webmail_email_settings'] = array(
|
| 172 |
'#type' => 'fieldset',
|
| 173 |
'#title' => t('Basic webmail account settings'),
|
| 174 |
'#collapsible' => TRUE,
|
| 175 |
'#weight' => 1,
|
| 176 |
);
|
| 177 |
$form['basic_webmail_email_settings']['basic_webmail_username'] = array(
|
| 178 |
'#type' => 'textfield',
|
| 179 |
'#title' => t('E-mail account login'),
|
| 180 |
'#default_value' => $account->basic_webmail_username,
|
| 181 |
'#description' => t('The login id of your e-mail account.'),
|
| 182 |
);
|
| 183 |
$form['basic_webmail_email_settings']['basic_webmail_passsword'] = array(
|
| 184 |
'#type' => 'password',
|
| 185 |
'#title' => t('E-mail account password'),
|
| 186 |
'#default_value' => $account->basic_webmail_passsword,
|
| 187 |
'#description' => t('The login password of your e-mail account.'),
|
| 188 |
);
|
| 189 |
}
|
| 190 |
return $form;
|
| 191 |
break;
|
| 192 |
|
| 193 |
case 'insert':
|
| 194 |
break;
|
| 195 |
|
| 196 |
case 'register':
|
| 197 |
if (!variable_get('basic_webmail_account_info', 0)) {
|
| 198 |
$form['basic_webmail_email_settings'] = array(
|
| 199 |
'#type' => 'fieldset',
|
| 200 |
'#title' => t('Basic webmail account settings'),
|
| 201 |
'#collapsible' => TRUE,
|
| 202 |
'#weight' => 1,
|
| 203 |
);
|
| 204 |
$form['basic_webmail_email_settings']['basic_webmail_username'] = array(
|
| 205 |
'#type' => 'textfield',
|
| 206 |
'#title' => t('E-mail account login'),
|
| 207 |
'#default_value' => $account->basic_webmail_username,
|
| 208 |
'#description' => t('The login id of your e-mail account.'),
|
| 209 |
);
|
| 210 |
$form['basic_webmail_email_settings']['basic_webmail_passsword'] = array(
|
| 211 |
'#type' => 'password',
|
| 212 |
'#title' => t('E-mail account password'),
|
| 213 |
'#default_value' => $account->basic_webmail_passsword,
|
| 214 |
'#description' => t('The login password of your e-mail account.'),
|
| 215 |
);
|
| 216 |
}
|
| 217 |
return $form;
|
| 218 |
break;
|
| 219 |
|
| 220 |
case 'update':
|
| 221 |
break;
|
| 222 |
|
| 223 |
case 'validate':
|
| 224 |
break;
|
| 225 |
}
|
| 226 |
} // End of basic_webmail_user().
|
| 227 |
|
| 228 |
|
| 229 |
/**
|
| 230 |
* The main mail listing page.
|
| 231 |
*/
|
| 232 |
function _basic_webmail_mail_list() {
|
| 233 |
//var_dump(get_defined_vars());
|
| 234 |
$output = '';
|
| 235 |
|
| 236 |
// Connect to the server.
|
| 237 |
if (variable_get('basic_webmail_server_address', '') == '' || variable_get('basic_webmail_server_port', '') == '') {
|
| 238 |
$output = t("The Basic webmail's server settings have not been configured yet. Please do that before checking your e-mail.");
|
| 239 |
return $output;
|
| 240 |
}
|
| 241 |
|
| 242 |
// Set the title of the page to the current mailbox, if there is one.
|
| 243 |
if (arg(1)) {
|
| 244 |
drupal_set_title(t(arg(1)));
|
| 245 |
}
|
| 246 |
|
| 247 |
$imap_flags = '';
|
| 248 |
if (variable_get('basic_webmail_secure_log_in', 0) == 1) {
|
| 249 |
$imap_flags .= '/secure';
|
| 250 |
}
|
| 251 |
if (variable_get('basic_webmail_use_ssl', 0) == 1) {
|
| 252 |
$imap_flags .= '/ssl';
|
| 253 |
}
|
| 254 |
if (variable_get('basic_webmail_validate_cert', 0) == 1) {
|
| 255 |
$imap_flags .= '/validate-cert';
|
| 256 |
}
|
| 257 |
else {
|
| 258 |
$imap_flags .= '/novalidate-cert';
|
| 259 |
}
|
| 260 |
if (variable_get('basic_webmail_use_tls', 0) == 1) {
|
| 261 |
$imap_flags .= '/tls';
|
| 262 |
}
|
| 263 |
else {
|
| 264 |
$imap_flags .= '/notls';
|
| 265 |
}
|
| 266 |
|
| 267 |
$mailbox = '{'. variable_get('basic_webmail_server_address', '') .':'. variable_get('basic_webmail_server_port', '') . $imap_flags .'}'. arg(1);
|
| 268 |
global $user;
|
| 269 |
$username = $user->basic_webmail_username;
|
| 270 |
$password = $user->basic_webmail_passsword;
|
| 271 |
|
| 272 |
// Open the mailbox.
|
| 273 |
if (($imap_resource = imap_open($mailbox, $username, $password)) == FALSE) {
|
| 274 |
$output = t('There was an error accessing the remote server: ') . imap_last_error();
|
| 275 |
watchdog('basic_webmail', $output, WATCHDOG_ERROR);
|
| 276 |
return $output;
|
| 277 |
}
|
| 278 |
|
| 279 |
/*
|
| 280 |
// Retrieve and display the list of folders.
|
| 281 |
$output = "<h4>Folders:</h4>\n";
|
| 282 |
$folders = imap_list($imap_resource, $mailbox, '*');
|
| 283 |
|
| 284 |
// if ($folders == FALSE) {
|
| 285 |
// $output = t('There was an error getting the list of folders: ') . imap_last_error();
|
| 286 |
// watchdog('basic_webmail', $output, WATCHDOG_ERROR);
|
| 287 |
// return $output;
|
| 288 |
// }
|
| 289 |
// else {
|
| 290 |
if ($folders) {
|
| 291 |
foreach ($folders as $folder) {
|
| 292 |
$output .= l(imap_utf7_decode(substr($folder, strpos($folder, '}') + 1, strlen($folder))), 'basic_webmail/'. imap_utf7_decode(substr($folder, strpos($folder, '}') + 1, strlen($folder)))) ."<br />\n";
|
| 293 |
}
|
| 294 |
}
|
| 295 |
|
| 296 |
$output .= '<hr>';
|
| 297 |
*/
|
| 298 |
|
| 299 |
|
| 300 |
if (imap_num_msg($imap_resource) > 0) {
|
| 301 |
// Retrieve and display the mail in the current folder.
|
| 302 |
$threads = imap_thread($imap_resource);
|
| 303 |
// if ($threads == FALSE) {
|
| 304 |
// $output = t('There was an error getting the list of messages: ') . imap_last_error();
|
| 305 |
// watchdog('basic_webmail', $output, WATCHDOG_ERROR);
|
| 306 |
// return $output;
|
| 307 |
// }
|
| 308 |
if ($threads) {
|
| 309 |
if (!db_query('DELETE FROM {basic_webmail_messages} WHERE user_id = %d', $user->uid)) {
|
| 310 |
watchdog('basic_webmail', 'There was an error deleting old message records from the basic_webmail_messages table.', WATCHDOG_ERROR);
|
| 311 |
}
|
| 312 |
|
| 313 |
// $new_messages = 0;
|
| 314 |
|
| 315 |
// Save the message information in a temporary table.
|
| 316 |
foreach ($threads as $key => $message) {
|
| 317 |
$tree = explode('.', $key);
|
| 318 |
if ($tree[1] == 'num') {
|
| 319 |
$message_header = imap_headerinfo($imap_resource, $message);
|
| 320 |
|
| 321 |
if ($message_header->Recent == 'N' || $message_header->Unseen == 'U') {
|
| 322 |
$new_messages++;
|
| 323 |
|
| 324 |
if (!$message_header->subject) {
|
| 325 |
$message_subject = '<strong>'. l('(No subject given.)', 'basic_webmail/message/'. $message) .'</strong>';
|
| 326 |
}
|
| 327 |
else {
|
| 328 |
$message_subject = '<strong>'. l($message_header->subject, 'basic_webmail/message/'. $message) .'</strong>';
|
| 329 |
}
|
| 330 |
}
|
| 331 |
else {
|
| 332 |
if (!$message_header->subject) {
|
| 333 |
$message_subject = l('(No subject given.)', 'basic_webmail/message/'. $message);
|
| 334 |
}
|
| 335 |
else {
|
| 336 |
$message_subject = l($message_header->subject, 'basic_webmail/message/'. $message);
|
| 337 |
}
|
| 338 |
}
|
| 339 |
|
| 340 |
if ($message_header->from[0]->mailbox .'@'. $message_header->from[0]->host == '@') {
|
| 341 |
$from_address = '(Unknown.)';
|
| 342 |
}
|
| 343 |
elseif ($message_header->from[0]->personal) {
|
| 344 |
// $from_address = l($message_header->from[0]->personal, 'basic_webmail/sendmail/"'. $message_header->from[0]->personal .'" <'. $message_header->from[0]->mailbox .'@'. $message_header->from[0]->host .'>');
|
| 345 |
$from_address = l($message_header->from[0]->personal, 'basic_webmail/sendmail/'. $message_header->from[0]->personal .' <'. $message_header->from[0]->mailbox .'@'. $message_header->from[0]->host .'>');
|
| 346 |
}
|
| 347 |
else {
|
| 348 |
$from_address = l($message_header->from[0]->mailbox .'@'. $message_header->from[0]->host, 'basic_webmail/sendmail/'. $message_header->from[0]->mailbox .'@'. $message_header->from[0]->host);
|
| 349 |
}
|
| 350 |
|
| 351 |
if (!$message_header->date) {
|
| 352 |
$message_date = 0;
|
| 353 |
}
|
| 354 |
else {
|
| 355 |
// Format the date so we can sort on it.
|
| 356 |
$message_hour = (int)substr($message_header->date, strpos($message_header->date, ':') - 2, 2);
|
| 357 |
$message_minute = (int)substr($message_header->date, strpos($message_header->date, ':') + 1, 2);
|
| 358 |
$message_second = (int)substr($message_header->date, strpos($message_header->date, ':') + 4, 2);
|
| 359 |
|
| 360 |
// Start at the second space.
|
| 361 |
$message_month_start = (int)strpos($message_header->date, ' ', strpos($message_header->date, ' ') + 1) + 1;
|
| 362 |
$message_month_length = (int)strpos($message_header->date, ' ', $message_month_start) - $message_month_start;
|
| 363 |
// $message_month = substr($message_header->date, $message_month_start, $message_month_length);
|
| 364 |
switch (substr($message_header->date, $message_month_start, $message_month_length)) {
|
| 365 |
case 'Jan':
|
| 366 |
$message_month = 1;
|
| 367 |
break;
|
| 368 |
case 'Feb':
|
| 369 |
$message_month = 2;
|
| 370 |
break;
|
| 371 |
case 'Mar':
|
| 372 |
$message_month = 3;
|
| 373 |
break;
|
| 374 |
case 'Apr':
|
| 375 |
$message_month = 4;
|
| 376 |
break;
|
| 377 |
case 'May':
|
| 378 |
$message_month = 5;
|
| 379 |
break;
|
| 380 |
case 'Jun':
|
| 381 |
$message_month = 6;
|
| 382 |
break;
|
| 383 |
case 'Jul':
|
| 384 |
$message_month = 7;
|
| 385 |
break;
|
| 386 |
case 'Aug':
|
| 387 |
$message_month = 8;
|
| 388 |
break;
|
| 389 |
case 'Sep':
|
| 390 |
$message_month = 9;
|
| 391 |
break;
|
| 392 |
case 'Oct':
|
| 393 |
$message_month = 10;
|
| 394 |
break;
|
| 395 |
case 'Nov':
|
| 396 |
$message_month = 11;
|
| 397 |
break;
|
| 398 |
case 'Dec':
|
| 399 |
$message_month = 12;
|
| 400 |
break;
|
| 401 |
}
|
| 402 |
|
| 403 |
// Start at the first space.
|
| 404 |
$message_day_start = (int)strpos($message_header->date, ' ') + 1;
|
| 405 |
$message_day_length = (int)strpos($message_header->date, ' ', $message_day_start) - $message_day_start;
|
| 406 |
$message_day = (int)substr($message_header->date, $message_day_start, $message_day_length);
|
| 407 |
|
| 408 |
// Start at the third space.
|
| 409 |
$message_year_start = (int)strpos($message_header->date, ' ', strpos($message_header->date, ' ', strpos($message_header->date, ' ') + 1) + 1) + 1;
|
| 410 |
$message_year_length = (int)strpos($message_header->date, ' ', $message_year_start) - $message_year_start;
|
| 411 |
$message_year = (int)substr($message_header->date, $message_year_start, $message_year_length);
|
| 412 |
|
| 413 |
$message_date = mktime($message_hour, $message_minute, $message_second, $message_month, $message_day, $message_year);
|
| 414 |
}
|
| 415 |
|
| 416 |
if (!db_query('INSERT INTO {basic_webmail_messages} (user_id, message_id, message_subject, from_address, message_date) VALUES (%d, %d, "%s", "%s", "%s")', $user->uid, $message, $message_subject, $from_address, $message_date)) {
|
| 417 |
watchdog('basic_webmail', 'There was an error inserting message records into the basic_webmail_messages table.', WATCHDOG_ERROR);
|
| 418 |
}
|
| 419 |
}
|
| 420 |
|
| 421 |
// Set the title of the page to the current mailbox, if there is one.
|
| 422 |
if (arg(1)) {
|
| 423 |
drupal_set_title(t(arg(1) .' ('. imap_num_msg($imap_resource) .' total, '. $new_messages .' unread)'));
|
| 424 |
}
|
| 425 |
else {
|
| 426 |
drupal_set_title(t('E-mail ('. imap_num_msg($imap_resource) .' total, '. $new_messages .' unread)'));
|
| 427 |
}
|
| 428 |
}
|
| 429 |
|
| 430 |
|
| 431 |
// Display the message information in a sortable table.
|
| 432 |
$header = array(
|
| 433 |
array('data' => t('Num'), 'field' => 'message_id'),
|
| 434 |
array('data' => t('Subject'), 'field' => 'message_subject'),
|
| 435 |
array('data' => t('From'), 'field' => 'from_address'),
|
| 436 |
array('data' => t('Date/Time'), 'field' => 'message_date'),
|
| 437 |
);
|
| 438 |
// TODO: Change the default sort order to descending by date.
|
| 439 |
$tablesort = tablesort_sql($header);
|
| 440 |
//drupal_set_message('two', 'error');
|
| 441 |
// $ts = tablesort_get_order($headers);
|
| 442 |
//drupal_set_message('three', 'error');
|
| 443 |
// $ts['name'] = t('Date');
|
| 444 |
// $ts['sql'] = 'message_date';
|
| 445 |
|
| 446 |
//tablesort_init($header);
|
| 447 |
$rows = array();
|
| 448 |
|
| 449 |
$result = pager_query('SELECT message_id, message_subject, from_address, message_date FROM {basic_webmail_messages} WHERE user_id = %d'. $tablesort, 25, 0, NULL, $user->uid);
|
| 450 |
while ($row = db_fetch_array($result)) {
|
| 451 |
if ($row['message_date'] == 0) {
|
| 452 |
$row['message_date'] = '(Invalid date.)';
|
| 453 |
}
|
| 454 |
else {
|
| 455 |
$row['message_date'] = format_date($row['message_date'], 'custom', 'D, M j, Y - g:i:s a');
|
| 456 |
}
|
| 457 |
$rows[] = $row;
|
| 458 |
}
|
| 459 |
|
| 460 |
$output .= theme('table', $header, $rows);
|
| 461 |
}
|
| 462 |
|
| 463 |
// Add the page numbers at the bottom of the table.
|
| 464 |
$output .= '<br />'. theme('pager');
|
| 465 |
}
|
| 466 |
else {
|
| 467 |
$output .= 'You have no e-mail.';
|
| 468 |
}
|
| 469 |
|
| 470 |
// Clean up.
|
| 471 |
if (!imap_close($imap_resource)) {
|
| 472 |
watchdog('basic_webmail', t('There was an error closing the IMAP stream: ') . imap_last_error(), WATCHDOG_WARNING);
|
| 473 |
}
|
| 474 |
|
| 475 |
return $output;
|
| 476 |
} // End of _basic_webmail_mail_list().
|
| 477 |
|
| 478 |
|
| 479 |
/**
|
| 480 |
* The message display page.
|
| 481 |
*/
|
| 482 |
function _basic_webmail_message() {
|
| 483 |
$output = '';
|
| 484 |
|
| 485 |
// Sanity check -- make sure we have an actual message to display.
|
| 486 |
if (arg(0) == 'basic_webmail' && arg(1) == 'message' && arg(2) == '') {
|
| 487 |
$output = '<h2 class="title">Error</h2>';
|
| 488 |
$output .= t('No message_id was given when attempting to view a message.');
|
| 489 |
return $output;
|
| 490 |
}
|
| 491 |
|
| 492 |
|
| 493 |
// Connect to the server.
|
| 494 |
if (variable_get('basic_webmail_server_address', '') == '' || variable_get('basic_webmail_server_port', '') == '') {
|
| 495 |
$output = '<h2 class="title">Error</h2>';
|
| 496 |
$output .= t("The Basic webmail's server settings have not been configured yet. Please do that before checking your e-mail.");
|
| 497 |
return $output;
|
| 498 |
}
|
| 499 |
|
| 500 |
$imap_flags = '';
|
| 501 |
if (variable_get('basic_webmail_secure_log_in', 0) == 1) {
|
| 502 |
$imap_flags .= '/secure';
|
| 503 |
}
|
| 504 |
if (variable_get('basic_webmail_use_ssl', 0) == 1) {
|
| 505 |
$imap_flags .= '/ssl';
|
| 506 |
}
|
| 507 |
if (variable_get('basic_webmail_validate_cert', 0) == 1) {
|
| 508 |
$imap_flags .= '/validate-cert';
|
| 509 |
}
|
| 510 |
else {
|
| 511 |
$imap_flags .= '/novalidate-cert';
|
| 512 |
}
|
| 513 |
if (variable_get('basic_webmail_use_tls', 0) == 1) {
|
| 514 |
$imap_flags .= '/tls';
|
| 515 |
}
|
| 516 |
else {
|
| 517 |
$imap_flags .= '/notls';
|
| 518 |
}
|
| 519 |
|
| 520 |
$mailbox = '{'. variable_get('basic_webmail_server_address', '') .':'. variable_get('basic_webmail_server_port', '') . $imap_flags .'}';
|
| 521 |
global $user;
|
| 522 |
$username = $user->basic_webmail_username;
|
| 523 |
$password = $user->basic_webmail_passsword;
|
| 524 |
if (($imap_resource = imap_open($mailbox, $username, $password)) == FALSE) {
|
| 525 |
$output = '<h2 class="title">Error</h2>';
|
| 526 |
$output .= t('There was an error accessing the remote server: ') . imap_last_error();
|
| 527 |
watchdog('basic_webmail', $output, WATCHDOG_ERROR);
|
| 528 |
return $output;
|
| 529 |
}
|
| 530 |
|
| 531 |
|
| 532 |
// Show the message.
|
| 533 |
// Get, configure and display the message header.
|
| 534 |
if (!$message_header = imap_headerinfo($imap_resource, arg(2))) {
|
| 535 |
$output = '<h2 class="title">Error</h2>';
|
| 536 |
$output .= t('There was an error retrieving the message header: ') . imap_last_error();
|
| 537 |
watchdog('basic_webmail', $output, WATCHDOG_ERROR);
|
| 538 |
return $output;
|
| 539 |
}
|
| 540 |
|
| 541 |
$output .= '<h2 class="title">'. $message_header->subject .'</h2>';
|
| 542 |
$output .= l('Return to message listing', 'basic_webmail');
|
| 543 |
$output .= '<hr>';
|
| 544 |
$output .= '<table>';
|
| 545 |
|
| 546 |
if ($message_header->from[0]->personal) {
|
| 547 |
// $output .= '<tr><td>From:</td><td>'. l($message_header->from[0]->personal, 'basic_webmail/sendmail/"'. $message_header->from[0]->personal .'" <'. $message_header->from[0]->mailbox .'@'. $message_header->from[0]->host .'>') .'</td></tr>';
|
| 548 |
$output .= '<tr><td>From:</td><td>'. l($message_header->from[0]->personal, 'basic_webmail/sendmail/'. $message_header->from[0]->personal .' <'. $message_header->from[0]->mailbox .'@'. $message_header->from[0]->host .'>') .'</td></tr>';
|
| 549 |
}
|
| 550 |
else {
|
| 551 |
$output .= '<tr><td>From:</td><td>'. l($message_header->from[0]->mailbox .'@'. $message_header->from[0]->host, 'basic_webmail/sendmail/'. $message_header->from[0]->mailbox .'@'. $message_header->from[0]->host) .'</td></tr>';
|
| 552 |
}
|
| 553 |
|
| 554 |
for ($i = 0; $i < count($message_header->to); $i++) {
|
| 555 |
if ($message_header->to[$i]->personal) {
|
| 556 |
// $toaddresses .= l($message_header->to[$i]->personal, 'basic_webmail/sendmail/"'. $message_header->to[0]->personal .'" <'. $message_header->to[$i]->mailbox .'@'. $message_header->to[$i]->host .'>') .', ';
|
| 557 |
$toaddresses .= l($message_header->to[$i]->personal, 'basic_webmail/sendmail/'. $message_header->to[0]->personal .' <'. $message_header->to[$i]->mailbox .'@'. $message_header->to[$i]->host .'>') .', ';
|
| 558 |
}
|
| 559 |
else {
|
| 560 |
$toaddresses .= l($message_header->to[$i]->mailbox .'@'. $message_header->to[$i]->host, 'basic_webmail/sendmail/'. $message_header->to[$i]->mailbox .'@'. $message_header->to[$i]->host) .', ';
|
| 561 |
}
|
| 562 |
}
|
| 563 |
$output .= '<tr><td>To:</td><td>'. substr($toaddresses, 0, strlen($toaddresses) - 2) .'</td></tr>';
|
| 564 |
|
| 565 |
if ($message_header->ccaddress) {
|
| 566 |
for ($i = 0; $i < count($message_header->cc); $i++) {
|
| 567 |
if ($message_header->cc[$i]->personal) {
|
| 568 |
// $ccaddresses .= l($message_header->cc[$i]->personal, 'basic_webmail/sendmail/"'. $message_header->cc[0]->personal .'" <'. $message_header->cc[$i]->mailbox .'@'. $message_header->cc[$i]->host .'>') .', ';
|
| 569 |
$ccaddresses .= l($message_header->cc[$i]->personal, 'basic_webmail/sendmail/'. $message_header->cc[0]->personal .' <'. $message_header->cc[$i]->mailbox .'@'. $message_header->cc[$i]->host .'>') .', ';
|
| 570 |
}
|
| 571 |
else {
|
| 572 |
$ccaddresses .= l($message_header->cc[$i]->mailbox .'@'. $message_header->cc[$i]->host, 'basic_webmail/sendmail/'. $message_header->cc[$i]->mailbox .'@'. $message_header->cc[$i]->host) .', ';
|
| 573 |
}
|
| 574 |
}
|
| 575 |
|
| 576 |
$output .= '<tr><td>CC:</td><td>'. substr($ccaddresses, 0, strlen($ccaddresses) - 2) .'</td></tr>';
|
| 577 |
}
|
| 578 |
|
| 579 |
if ($message_header->bccaddress) {
|
| 580 |
for ($i = 0; $i < count($message_header->bcc); $i++) {
|
| 581 |
if ($message_header->bcc[$i]->personal) {
|
| 582 |
// $bccaddresses .= l($message_header->bcc[$i]->personal, 'basic_webmail/sendmail/"'. $message_header->bcc[0]->personal .'" <'. $message_header->bcc[$i]->mailbox .'@'. $message_header->bcc[$i]->host .'>') .', ';
|
| 583 |
$bccaddresses .= l($message_header->bcc[$i]->personal, 'basic_webmail/sendmail/'. $message_header->bcc[0]->personal .' <'. $message_header->bcc[$i]->mailbox .'@'. $message_header->bcc[$i]->host .'>') .', ';
|
| 584 |
}
|
| 585 |
else {
|
| 586 |
$bccaddresses .= l($message_header->bcc[$i]->mailbox .'@'. $message_header->bcc[$i]->host, 'basic_webmail/sendmail/'. $message_header->bcc[$i]->mailbox .'@'. $message_header->bcc[$i]->host) .', ';
|
| 587 |
}
|
| 588 |
}
|
| 589 |
|
| 590 |
$output .= '<tr><td>BCC:</td><td>'. substr($bccaddresses, 0, strlen($bccaddresses) - 2) .'</td></tr>';
|
| 591 |
}
|
| 592 |
|
| 593 |
$output .= '<tr><td>Date:</td><td>'. $message_header->date .'</td></tr>';
|
| 594 |
|
| 595 |
$output .= '</table>';
|
| 596 |
$output .= '<hr>';
|
| 597 |
|
| 598 |
// Get, configure and display the message body.
|
| 599 |
if (!$message_body = imap_body($imap_resource, arg(2))) {
|
| 600 |
$output = '<h2 class="title">Error</h2>';
|
| 601 |
$output .= t('There was an error retrieving the message body: ') . imap_last_error();
|
| 602 |
watchdog('basic_webmail', $output, WATCHDOG_ERROR);
|
| 603 |
return $output;
|
| 604 |
}
|
| 605 |
$output .= check_markup($message_body);
|
| 606 |
|
| 607 |
$output .= '<hr>';
|
| 608 |
|
| 609 |
// $delete_link = l('Delete', 'basic_webmail/delete/'. arg(2));
|
| 610 |
$reply_link = l('Reply', 'basic_webmail/sendmail/reply/'. arg(2));
|
| 611 |
$reply_to_all_link = l('Reply to all', 'basic_webmail/sendmail/replytoall/'. arg(2));
|
| 612 |
$forward_link = l('Forward', 'basic_webmail/sendmail/forward/'. arg(2));
|
| 613 |
$output .= $delete_link .' -- '. $reply_link .' -- '. $reply_to_all_link .' -- '. $forward_link;
|
| 614 |
|
| 615 |
// Clean up.
|
| 616 |
if (!imap_close($imap_resource)) {
|
| 617 |
watchdog('basic_webmail', t('There was an error closing the IMAP stream: ') . imap_last_error(), WATCHDOG_WARNING);
|
| 618 |
}
|
| 619 |
|
| 620 |
return $output;
|
| 621 |
} // End of _basic_webmail_message().
|
| 622 |
|
| 623 |
|
| 624 |
/**
|
| 625 |
* This is where we send e-mail.
|
| 626 |
*/
|
| 627 |
function _basic_webmail_send_mail() {
|
| 628 |
basic_webmail_mail_form();
|
| 629 |
} // End of _basic_webmail_send_mail().
|
| 630 |
|
| 631 |
|
| 632 |
/**
|
| 633 |
* This is the form for sending e-mail.
|
| 634 |
* @param send_mail_type Whether the message is new, a reply or a forward. Valid types are new, reply, replytoall and forward. If it is a new message, then the send_mail_message_number parameter is ignored.
|
| 635 |
* @param send_mail_message_number The ID of the message being replied to or forwarded.
|
| 636 |
* @return The completed form.
|
| 637 |
*/
|
| 638 |
function _basic_webmail_send_mail_form($send_mail_type = 'new', $send_mail_message_id = '') {
|
| 639 |
/*
|
| 640 |
* If $send_mail_type = 'new', then all fields are left blank.
|
| 641 |
* If $send_mail_type = 'reply', then to field is filled with the from
|
| 642 |
address of the message and the subject and body fields are filled.
|
| 643 |
* If $send_mail_type = 'replytoall', then the to field is filled with the
|
| 644 |
from address, the cc field is filled with all of the addresses in the to
|
| 645 |
and cc fields of the message, and the subject and body fields are filled.
|
| 646 |
* If $send_mail_type = 'forward', then a message, then the to, cc and bcc
|
| 647 |
fields are blank, but the subject and body fields are not.
|
| 648 |
* Otherwise, $send_mail_type holds the address of a person to send a new
|
| 649 |
e-mail to, and that will go in the to field with no other fields filled
|
| 650 |
in.
|
| 651 |
|
| 652 |
* If $send_mail_type = 'reply', 'replytoall' or 'forward', then
|
| 653 |
$send_mail_message_id may not be blank, otherwise $send_mail_message_id
|
| 654 |
will be ignred.
|
| 655 |
*/
|
| 656 |
|
| 657 |
$form = array();
|
| 658 |
|
| 659 |
// Check to see if this is a reply or forward.
|
| 660 |
if ($send_mail_type == 'reply' || $send_mail_type == 'replytoall' || $send_mail_type == 'forward') {
|
| 661 |
// Make sure we have a message id.
|
| 662 |
if (!$send_mail_message_id) {
|
| 663 |
$output = t('There was an attempt to reply to or forward a message w/o including the message id.');
|
| 664 |
watchdog('basic_webmail', $output, WATCHDOG_ERROR);
|
| 665 |
}
|
| 666 |
// Get the message information for use in filling the form.
|
| 667 |
else {
|
| 668 |
// Connect to the server.
|
| 669 |
$imap_flags = '';
|
| 670 |
if (variable_get('basic_webmail_secure_log_in', 0) == 1) {
|
| 671 |
$imap_flags .= '/secure';
|
| 672 |
}
|
| 673 |
if (variable_get('basic_webmail_use_ssl', 0) == 1) {
|
| 674 |
$imap_flags .= '/ssl';
|
| 675 |
}
|
| 676 |
if (variable_get('basic_webmail_validate_cert', 0) == 1) {
|
| 677 |
$imap_flags .= '/validate-cert';
|
| 678 |
}
|
| 679 |
else {
|
| 680 |
$imap_flags .= '/novalidate-cert';
|
| 681 |
}
|
| 682 |
if (variable_get('basic_webmail_use_tls', 0) == 1) {
|
| 683 |
$imap_flags .= '/tls';
|
| 684 |
}
|
| 685 |
else {
|
| 686 |
$imap_flags .= '/notls';
|
| 687 |
}
|
| 688 |
|
| 689 |
$mailbox = '{'. variable_get('basic_webmail_server_address', '') .':'. variable_get('basic_webmail_server_port', '') . $imap_flags .'}';
|
| 690 |
global $user;
|
| 691 |
$username = $user->basic_webmail_username;
|
| 692 |
$password = $user->basic_webmail_passsword;
|
| 693 |
if (($imap_resource = imap_open($mailbox, $username, $password)) == FALSE) {
|
| 694 |
$output = t('There was an error accessing the remote server: ') . imap_last_error();
|
| 695 |
watchdog('basic_webmail', $output, WATCHDOG_ERROR);
|
| 696 |
}
|
| 697 |
|
| 698 |
// Show the message.
|
| 699 |
// Get the message header.
|
| 700 |
if (!$message_header = imap_headerinfo($imap_resource, $send_mail_message_id)) {
|
| 701 |
$output = t('There was an error retrieving the message header: ') . imap_last_error();
|
| 702 |
watchdog('basic_webmail', $output, WATCHDOG_ERROR);
|
| 703 |
}
|
| 704 |
|
| 705 |
// Get the message body.
|
| 706 |
if (!$message_body = imap_body($imap_resource, $send_mail_message_id)) {
|
| 707 |
$output .= t('There was an error retrieving the message body: ') . imap_last_error();
|
| 708 |
watchdog('basic_webmail', $output, WATCHDOG_ERROR);
|
| 709 |
}
|
| 710 |
|
| 711 |
|
| 712 |
// Set the title.
|
| 713 |
drupal_set_title(t($message_header->subject));
|
| 714 |
|
| 715 |
// Add a link back to the listing.
|
| 716 |
if (!$send_mail_message_id) {
|
| 717 |
$form['basic_webmail_send_mail_list_link'] = array(
|
| 718 |
'#value' => l('Return to message listing', 'basic_webmail') .'<hr>',
|
| 719 |
);
|
| 720 |
}
|
| 721 |
else {
|
| 722 |
$form['basic_webmail_send_mail_list_link'] = array(
|
| 723 |
'#value' => l('Return to message listing', 'basic_webmail') .' -- '. l('Return to message', 'basic_webmail/message/'. $send_mail_message_id) .'<hr>',
|
| 724 |
);
|
| 725 |
}
|
| 726 |
|
| 727 |
|
| 728 |
// Set defaluts based on $send_mail_type.
|
| 729 |
if ($send_mail_type == 'reply' || $send_mail_type == 'replytoall') {
|
| 730 |
// Set the subject of the message.
|
| 731 |
$send_mail_subject = 'Re: '. $message_header->subject;
|
| 732 |
|
| 733 |
// Set the to of the message.
|
| 734 |
if ($message_header->from[0]->personal) {
|
| 735 |
// $send_mail_to = '"'. $message_header->from[0]->personal .'" <'. $message_header->from[0]->mailbox .'@'. $message_header->from[0]->host .'>';
|
| 736 |
$send_mail_to = $message_header->from[0]->personal .' <'. $message_header->from[0]->mailbox .'@'. $message_header->from[0]->host .'>';
|
| 737 |
}
|
| 738 |
else {
|
| 739 |
$send_mail_to = $message_header->from[0]->mailbox .'@'. $message_header->from[0]->host;
|
| 740 |
}
|
| 741 |
|
| 742 |
// Set the body of the message.
|
| 743 |
// TODO: Configure the body to have the '>' marks in it.
|
| 744 |
$send_mail_body = $message_body;
|
| 745 |
}
|
| 746 |
|
| 747 |
|
| 748 |
// Set defaluts based on $send_mail_type.
|
| 749 |
if ($send_mail_type == 'replytoall') {
|
| 750 |
//cc field is filled with all of the addresses in the to and cc fields of the message
|
| 751 |
// Set the cc of the message.
|
| 752 |
// Make sure we don't have any bad information, by setting it to an empty string.
|
| 753 |
$send_mail_cc = '';
|
| 754 |
|
| 755 |
// Add all addresses in the to field.
|
| 756 |
for ($i = 0; $i < count($message_header->to); $i++) {
|
| 757 |
if ($message_header->to[$i]->personal) {
|
| 758 |
// $send_mail_cc .= '"'. $message_header->to[$i]->personal .'" <'. $message_header->to[$i]->mailbox .'@'. $message_header->to[$i]->host .'>, ';
|
| 759 |
$send_mail_cc .= $message_header->to[$i]->personal .' <'. $message_header->to[$i]->mailbox .'@'. $message_header->to[$i]->host .'>, ';
|
| 760 |
}
|
| 761 |
else {
|
| 762 |
$send_mail_cc .= $message_header->to[$i]->mailbox .'@'. $message_header->to[$i]->host .', ';
|
| 763 |
}
|
| 764 |
}
|
| 765 |
|
| 766 |
// Add all addresses in the cc field.
|
| 767 |
if ($message_header->ccaddress) {
|
| 768 |
for ($i = 0; $i < count($message_header->cc); $i++) {
|
| 769 |
if ($message_header->cc[$i]->personal) {
|
| 770 |
// $send_mail_cc .= '"'. $message_header->cc[$i]->personal .'" <'. $message_header->cc[$i]->mailbox .'@'. $message_header->cc[$i]->host .'>, ';
|
| 771 |
$send_mail_cc .= $message_header->cc[$i]->personal .' <'. $message_header->cc[$i]->mailbox .'@'. $message_header->cc[$i]->host .'>, ';
|
| 772 |
}
|
| 773 |
else {
|
| 774 |
$send_mail_cc .= $message_header->cc[$i]->mailbox .'@'. $message_header->cc[$i]->host .', ';
|
| 775 |
}
|
| 776 |
}
|
| 777 |
}
|
| 778 |
|
| 779 |
$send_mail_cc = substr($send_mail_cc, 0, strlen($send_mail_cc) - 1);
|
| 780 |
}
|
| 781 |
|
| 782 |
|
| 783 |
// Set defaluts based on $send_mail_type.
|
| 784 |
if ($send_mail_type == 'forward') {
|
| 785 |
// Set the subject of the message.
|
| 786 |
$send_mail_subject = 'Fw: '. $message_header->subject;
|
| 787 |
|
| 788 |
// Set the body of the message.
|
| 789 |
// TODO: Configure the body to have the forward marks in it.
|
| 790 |
$send_mail_body = $message_body;
|
| 791 |
}
|
| 792 |
}
|
| 793 |
}
|
| 794 |
// If this is true, then $send_mail_type holds the e-mail address to send
|
| 795 |
// the message to.
|
| 796 |
elseif ($send_mail_type != 'new') {
|
| 797 |
// Set the title.
|
| 798 |
drupal_set_title(t('New mail message'));
|
| 799 |
|
| 800 |
// Set the to field.
|
| 801 |
$send_mail_to = $send_mail_type;
|
| 802 |
}
|
| 803 |
|
| 804 |
$form['basic_webmail_send_mail_from'] = array(
|
| 805 |
'#type' => 'hidden',
|
| 806 |
// '#value' => '"'. $user->name .'" <'. $username .'>',
|
| 807 |
'#value' => $user->name .' <'. $user->mail .'>',
|
| 808 |
);
|
| 809 |
|
| 810 |
$form['basic_webmail_send_mail_to'] = array(
|
| 811 |
'#type' => 'textfield',
|
| 812 |
'#title' => t('To'),
|
| 813 |
'#default_value' => $send_mail_to,
|
| 814 |
'#maxlength' => 1024,
|
| 815 |
'#description' => t('One or more recepients of this message. Separate the addresses with a comma (,).'),
|
| 816 |
'#required' => TRUE,
|
| 817 |
);
|
| 818 |
$form['basic_webmail_send_mail_cc'] = array(
|
| 819 |
'#type' => 'textfield',
|
| 820 |
'#title' => t('CC'),
|
| 821 |
'#default_value' => $send_mail_cc,
|
| 822 |
'#maxlength' => 1024,
|
| 823 |
'#description' => t('One or more e-mail addresses to receive a carbon copy. Separate the addresses with a comma (,).'),
|
| 824 |
);
|
| 825 |
$form['basic_webmail_send_mail_bcc'] = array(
|
| 826 |
'#type' => 'textfield',
|
| 827 |
'#title' => t('BCC'),
|
| 828 |
'#default_value' => $send_mail_bcc,
|
| 829 |
'#maxlength' => 1024,
|
| 830 |
'#description' => t('One or more e-mail addresses to receive a blind carbon copy. These e-mail addresses will not be visible in the message. Separate the addresses with a comma (,).'),
|
| 831 |
);
|
| 832 |
$form['basic_webmail_send_mail_subject'] = array(
|
| 833 |
'#type' => 'textfield',
|
| 834 |
'#title' => t('Subject'),
|
| 835 |
'#default_value' => $send_mail_subject,
|
| 836 |
// '#description' => t(''),
|
| 837 |
);
|
| 838 |
$form['basic_webmail_send_mail_body'] = array(
|
| 839 |
'#type' => 'textarea',
|
| 840 |
'#title' => t('Message'),
|
| 841 |
'#default_value' => $send_mail_body,
|
| 842 |
'#rows' => 15,
|
| 843 |
// '#description' => t(''),
|
| 844 |
);
|
| 845 |
|
| 846 |
$form['basic_webmail_attachment_1'] = array(
|
| 847 |
'#type' => 'file',
|
| 848 |
'#title' => t('Attachment #1'),
|
| 849 |
);
|
| 850 |
$form['basic_webmail_attachment_2'] = array(
|
| 851 |
'#type' => 'file',
|
| 852 |
'#title' => t('Attachment #2'),
|
| 853 |
);
|
| 854 |
$form['basic_webmail_attachment_3'] = array(
|
| 855 |
'#type' => 'file',
|
| 856 |
'#title' => t('Attachment #3'),
|
| 857 |
);
|
| 858 |
|
| 859 |
$form['basic_webmail_send_mail_self'] = array(
|
| 860 |
'#type' => 'checkbox',
|
| 861 |
'#title' => t('Send a copy to myself.'),
|
| 862 |
// '#default_value' => variable_get('basic_webmail_send_mail_self', 0),
|
| 863 |
// '#description' => t('Check to make a secure connection to your IMAP Server.'),
|
| 864 |
);
|
| 865 |
|
| 866 |
$form['basic_webmail_send_mail_preview'] = array(
|
| 867 |
'#type' => 'button',
|
| 868 |
'#value' => t('Preview'),
|
| 869 |
);
|
| 870 |
$form['basic_webmail_send_mail_submit'] = array(
|
| 871 |
'#type' => 'submit',
|
| 872 |
'#value' => t('Send'),
|
| 873 |
);
|
| 874 |
|
| 875 |
return $form;
|
| 876 |
} // End of _basic_webmail_send_mail_form().
|
| 877 |
|
| 878 |
|
| 879 |
/**
|
| 880 |
* This is the form for sending e-mail.
|
| 881 |
* /
|
| 882 |
function _basic_webmail_send_mail_form_validate($form_id, $form_values) {
|
| 883 |
|
| 884 |
} // End of _basic_webmail_send_mail_form_validate().
|
| 885 |
|
| 886 |
|
| 887 |
/**
|
| 888 |
* This is the form for sending e-mail.
|
| 889 |
*/
|
| 890 |
function _basic_webmail_send_mail_form_submit($form_id, $form_values) {
|
| 891 |
global $user;
|
| 892 |
// $send_mail_from = '"'. $user->name .'" <'. $user->basic_webmail_username .'>';
|
| 893 |
$send_mail_from = $user->name .' <'. $user->basic_webmail_username .'>';
|
| 894 |
|
| 895 |
/**
|
| 896 |
* Send an e-mail message, using Drupal variables and default settings.
|
| 897 |
* More information in the PHP function reference for mail()
|
| 898 |
* @param $mailkey
|
| 899 |
* A key to identify the mail sent, for altering.
|
| 900 |
* @param $to
|
| 901 |
* The mail address or addresses where the message will be send to. The
|
| 902 |
* formatting of this string must comply with RFC 2822. Some examples are:
|
| 903 |
* user@example.com
|
| 904 |
* user@example.com, anotheruser@example.com
|
| 905 |
* User <user@example.com>
|
| 906 |
* User <user@example.com>, Another User <anotheruser@example.com>
|
| 907 |
* @param $subject
|
| 908 |
* Subject of the e-mail to be sent. This must not contain any newline
|
| 909 |
* characters, or the mail may not be sent properly.
|
| 910 |
* @param $body
|
| 911 |
* Message to be sent. Drupal will format the correct line endings for you.
|
| 912 |
* @param $from
|
| 913 |
* Sets From, Reply-To, Return-Path and Error-To to this value, if given.
|
| 914 |
* @param $headers
|
| 915 |
* Associative array containing the headers to add. This is typically
|
| 916 |
* used to add extra headers (From, Cc, and Bcc).
|
| 917 |
* <em>When sending mail, the mail must contain a From header.</em>
|
| 918 |
* @return Returns TRUE if the mail was successfully accepted for delivery,
|
| 919 |
* FALSE otherwise.
|
| 920 |
*/
|
| 921 |
drupal_set_message('$form_values[basic_webmail_send_mail_from] = "'. $form_values['basic_webmail_send_mail_from'] .'"');
|
| 922 |
if (drupal_mail(
|
| 923 |
'basic_webmail_send_mail',
|
| 924 |
$form_values['basic_webmail_send_mail_to'],
|
| 925 |
$form_values['basic_webmail_send_mail_subject'],
|
| 926 |
$form_values['basic_webmail_send_mail_body'],
|
| 927 |
'jason@flattfamily.com'
|
| 928 |
)) {
|
| 929 |
drupal_set_message('Your message was successfully sent.');
|
| 930 |
drupal_goto('/basic_webmail/message/'. arg(3));
|
| 931 |
}
|
| 932 |
else {
|
| 933 |
drupal_set_message('There was an error sending your message.');
|
| 934 |
}
|
| 935 |
// $send_mail_from
|
| 936 |
// $defaults = array('MIME-Version' => '1.0', 'Content-Type' => 'text/plain; charset=UTF-8; format=flowed', 'Content-Transfer-Encoding' => '8Bit', 'X-Mailer' => 'Drupal');
|
| 937 |
|
| 938 |
|
| 939 |
/*
|
| 940 |
//function mimemail($sender, $recipient, $subject, $body, $plaintext=null, $headers=array(), $text=null, $attachments=array()) {
|
| 941 |
if (mimemail(
|
| 942 |
$send_mail_from,
|
| 943 |
$form_values['basic_webmail_send_mail_to'],
|
| 944 |
$form_values['basic_webmail_send_mail_subject'],
|
| 945 |
$form_values['basic_webmail_send_mail_body'],
|
| 946 |
NULL,
|
| 947 |
array(),
|
| 948 |
NULL,
|
| 949 |
array()
|
| 950 |
)) {
|
| 951 |
drupal_set_message('TRUE');
|
| 952 |
}
|
| 953 |
else {
|
| 954 |
drupal_set_message('FALSE');
|
| 955 |
}
|
| 956 |
*/
|
| 957 |
} // End of _basic_webmail_send_mail_form_submit().
|