| 1 | <?php |
|---|
| 2 | |
|---|
| 3 | /* |
|---|
| 4 | +-----------------------------------------------------------------------+ |
|---|
| 5 | | program/steps/mail/sendmail.inc | |
|---|
| 6 | | | |
|---|
| 7 | | This file is part of the RoundCube Webmail client | |
|---|
| 8 | | Copyright (C) 2005-2007, RoundCube Dev. - Switzerland | |
|---|
| 9 | | Licensed under the GNU GPL | |
|---|
| 10 | | | |
|---|
| 11 | | PURPOSE: | |
|---|
| 12 | | Compose a new mail message with all headers and attachments | |
|---|
| 13 | | and send it using IlohaMail's SMTP methods or with PHP mail() | |
|---|
| 14 | | | |
|---|
| 15 | +-----------------------------------------------------------------------+ |
|---|
| 16 | | Author: Thomas Bruederli <roundcube@gmail.com> | |
|---|
| 17 | +-----------------------------------------------------------------------+ |
|---|
| 18 | |
|---|
| 19 | $Id$ |
|---|
| 20 | |
|---|
| 21 | */ |
|---|
| 22 | |
|---|
| 23 | |
|---|
| 24 | //require_once('lib/smtp.inc'); |
|---|
| 25 | require_once('include/rcube_smtp.inc'); |
|---|
| 26 | require_once('lib/html2text.inc'); |
|---|
| 27 | require_once('lib/rc_mail_mime.inc'); |
|---|
| 28 | |
|---|
| 29 | |
|---|
| 30 | if (!isset($_SESSION['compose']['id'])) |
|---|
| 31 | { |
|---|
| 32 | rcmail_overwrite_action('list'); |
|---|
| 33 | return; |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | |
|---|
| 37 | /****** message sending functions ********/ |
|---|
| 38 | |
|---|
| 39 | |
|---|
| 40 | function rcmail_get_identity($id) |
|---|
| 41 | { |
|---|
| 42 | global $DB, $OUTPUT; |
|---|
| 43 | |
|---|
| 44 | // get identity record |
|---|
| 45 | $sql_result = $DB->query("SELECT *, email AS mailto |
|---|
| 46 | FROM ".get_table_name('identities')." |
|---|
| 47 | WHERE identity_id=? |
|---|
| 48 | AND user_id=? |
|---|
| 49 | AND del<>1", |
|---|
| 50 | $id,$_SESSION['user_id']); |
|---|
| 51 | |
|---|
| 52 | if ($DB->num_rows($sql_result)) |
|---|
| 53 | { |
|---|
| 54 | $sql_arr = $DB->fetch_assoc($sql_result); |
|---|
| 55 | $out = $sql_arr; |
|---|
| 56 | $name = strpos($sql_arr['name'], ",") ? '"'.$sql_arr['name'].'"' : $sql_arr['name']; |
|---|
| 57 | $out['string'] = sprintf('%s <%s>', |
|---|
| 58 | rcube_charset_convert($name, RCMAIL_CHARSET, $OUTPUT->get_charset()), |
|---|
| 59 | $sql_arr['mailto']); |
|---|
| 60 | return $out; |
|---|
| 61 | } |
|---|
| 62 | |
|---|
| 63 | return FALSE; |
|---|
| 64 | } |
|---|
| 65 | |
|---|
| 66 | /** |
|---|
| 67 | * go from this: |
|---|
| 68 | * <img src=".../tiny_mce/plugins/emotions/images/smiley-cool.gif" border="0" alt="Cool" title="Cool" /> |
|---|
| 69 | * |
|---|
| 70 | * to this: |
|---|
| 71 | * |
|---|
| 72 | * <IMG src="cid:smiley-cool.gif"/> |
|---|
| 73 | * ... |
|---|
| 74 | * ------part... |
|---|
| 75 | * Content-Type: image/gif |
|---|
| 76 | * Content-Transfer-Encoding: base64 |
|---|
| 77 | * Content-ID: <smiley-cool.gif> |
|---|
| 78 | */ |
|---|
| 79 | function rcmail_attach_emoticons(&$mime_message) |
|---|
| 80 | { |
|---|
| 81 | global $CONFIG, $INSTALL_PATH; |
|---|
| 82 | |
|---|
| 83 | $htmlContents = $mime_message->getHtmlBody(); |
|---|
| 84 | |
|---|
| 85 | // remove any null-byte characters before parsing |
|---|
| 86 | $body = preg_replace('/\x00/', '', $htmlContents); |
|---|
| 87 | |
|---|
| 88 | $last_img_pos = 0; |
|---|
| 89 | |
|---|
| 90 | $searchstr = 'program/js/tiny_mce/plugins/emotions/images/'; |
|---|
| 91 | |
|---|
| 92 | // keep track of added images, so they're only added once |
|---|
| 93 | $included_images = array(); |
|---|
| 94 | |
|---|
| 95 | // find emoticon image tags |
|---|
| 96 | while ($pos = strpos($body, $searchstr, $last_img_pos)) |
|---|
| 97 | { |
|---|
| 98 | $pos2 = strpos($body, '"', $pos); |
|---|
| 99 | $body_pre = substr($body, 0, $pos); |
|---|
| 100 | $image_name = substr($body, |
|---|
| 101 | $pos + strlen($searchstr), |
|---|
| 102 | $pos2 - ($pos + strlen($searchstr))); |
|---|
| 103 | // sanitize image name so resulting attachment doesn't leave images dir |
|---|
| 104 | $image_name = preg_replace('/[^a-zA-Z0-9_\.\-]/i','',$image_name); |
|---|
| 105 | |
|---|
| 106 | $body_post = substr($body, $pos2); |
|---|
| 107 | |
|---|
| 108 | if (! in_array($image_name, $included_images)) |
|---|
| 109 | { |
|---|
| 110 | // add the image to the MIME message |
|---|
| 111 | $img_file = $INSTALL_PATH . '/' . $searchstr . $image_name; |
|---|
| 112 | if(! $mime_message->addHTMLImage($img_file, 'image/gif', '', true, '_' . $image_name)) |
|---|
| 113 | $OUTPUT->show_message("emoticonerror", 'error'); |
|---|
| 114 | |
|---|
| 115 | array_push($included_images, $image_name); |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | $body = $body_pre . 'cid:_' . $image_name . $body_post; |
|---|
| 119 | |
|---|
| 120 | $last_img_pos = $pos2; |
|---|
| 121 | } |
|---|
| 122 | |
|---|
| 123 | $mime_message->setHTMLBody($body); |
|---|
| 124 | } |
|---|
| 125 | |
|---|
| 126 | if (strlen($_POST['_draft_saveid']) > 3) |
|---|
| 127 | $olddraftmessageid = get_input_value('_draft_saveid', RCUBE_INPUT_POST); |
|---|
| 128 | |
|---|
| 129 | $message_id = sprintf('<%s@%s>', md5(uniqid('rcmail'.rand(),true)), rcmail_mail_domain($_SESSION['imap_host'])); |
|---|
| 130 | $savedraft = !empty($_POST['_draft']) ? TRUE : FALSE; |
|---|
| 131 | |
|---|
| 132 | // remove all scripts and act as called in frame |
|---|
| 133 | $OUTPUT->reset(); |
|---|
| 134 | $OUTPUT->framed = TRUE; |
|---|
| 135 | |
|---|
| 136 | |
|---|
| 137 | /****** check submission and compose message ********/ |
|---|
| 138 | |
|---|
| 139 | |
|---|
| 140 | if (!$savedraft && empty($_POST['_to']) && empty($_POST['_subject']) && $_POST['_message']) |
|---|
| 141 | { |
|---|
| 142 | $OUTPUT->show_message("sendingfailed", 'error'); |
|---|
| 143 | $OUTPUT->send('iframe'); |
|---|
| 144 | return; |
|---|
| 145 | } |
|---|
| 146 | |
|---|
| 147 | |
|---|
| 148 | // set default charset |
|---|
| 149 | $input_charset = $OUTPUT->get_charset(); |
|---|
| 150 | $message_charset = isset($_POST['_charset']) ? $_POST['_charset'] : $input_charset; |
|---|
| 151 | |
|---|
| 152 | $mailto_regexp = array('/[,;]\s*[\r\n]+/', '/[\r\n]+/', '/[,;]\s*$/m', '/;/'); |
|---|
| 153 | $mailto_replace = array(', ', ', ', '', ','); |
|---|
| 154 | |
|---|
| 155 | // replace new lines and strip ending ', ' |
|---|
| 156 | $mailto = preg_replace($mailto_regexp, $mailto_replace, get_input_value('_to', RCUBE_INPUT_POST, TRUE, $message_charset)); |
|---|
| 157 | |
|---|
| 158 | // decode address strings |
|---|
| 159 | $to_address_arr = $IMAP->decode_address_list($mailto); |
|---|
| 160 | $identity_arr = rcmail_get_identity(get_input_value('_from', RCUBE_INPUT_POST)); |
|---|
| 161 | |
|---|
| 162 | $from = $identity_arr['mailto']; |
|---|
| 163 | $first_to = is_array($to_address_arr[0]) ? $to_address_arr[0]['mailto'] : $mailto; |
|---|
| 164 | |
|---|
| 165 | if (empty($identity_arr['string'])) |
|---|
| 166 | $identity_arr['string'] = $from; |
|---|
| 167 | |
|---|
| 168 | // compose headers array |
|---|
| 169 | $headers = array('Date' => date('D, j M Y H:i:s O'), |
|---|
| 170 | 'From' => rcube_charset_convert($identity_arr['string'], RCMAIL_CHARSET, $message_charset), |
|---|
| 171 | 'To' => $mailto); |
|---|
| 172 | |
|---|
| 173 | // additional recipients |
|---|
| 174 | if (!empty($_POST['_cc'])) |
|---|
| 175 | $headers['Cc'] = preg_replace($mailto_regexp, $mailto_replace, get_input_value('_cc', RCUBE_INPUT_POST, TRUE, $message_charset)); |
|---|
| 176 | |
|---|
| 177 | if (!empty($_POST['_bcc'])) |
|---|
| 178 | $headers['Bcc'] = preg_replace($mailto_regexp, $mailto_replace, get_input_value('_bcc', RCUBE_INPUT_POST, TRUE, $message_charset)); |
|---|
| 179 | |
|---|
| 180 | if (!empty($identity_arr['bcc'])) |
|---|
| 181 | $headers['Bcc'] = ($headers['Bcc'] ? $headers['Bcc'].', ' : '') . $identity_arr['bcc']; |
|---|
| 182 | |
|---|
| 183 | // add subject |
|---|
| 184 | $headers['Subject'] = trim(get_input_value('_subject', RCUBE_INPUT_POST, FALSE, $message_charset)); |
|---|
| 185 | |
|---|
| 186 | if (!empty($identity_arr['organization'])) |
|---|
| 187 | $headers['Organization'] = $identity_arr['organization']; |
|---|
| 188 | |
|---|
| 189 | if (!empty($identity_arr['reply-to'])) |
|---|
| 190 | $headers['Reply-To'] = $identity_arr['reply-to']; |
|---|
| 191 | |
|---|
| 192 | if (!empty($_SESSION['compose']['reply_msgid'])) |
|---|
| 193 | $headers['In-Reply-To'] = $_SESSION['compose']['reply_msgid']; |
|---|
| 194 | |
|---|
| 195 | if (!empty($_SESSION['compose']['references'])) |
|---|
| 196 | $headers['References'] = $_SESSION['compose']['references']; |
|---|
| 197 | |
|---|
| 198 | if (!empty($_POST['_priority'])) |
|---|
| 199 | { |
|---|
| 200 | $priority = (int)$_POST['_priority']; |
|---|
| 201 | $a_priorities = array(1=>'highest', 2=>'high', 4=>'low', 5=>'lowest'); |
|---|
| 202 | if ($str_priority = $a_priorities[$priority]) |
|---|
| 203 | $headers['X-Priority'] = sprintf("%d (%s)", $priority, ucfirst($str_priority)); |
|---|
| 204 | } |
|---|
| 205 | |
|---|
| 206 | if (!empty($_POST['_receipt'])) |
|---|
| 207 | { |
|---|
| 208 | $headers['Return-Receipt-To'] = $identity_arr['string']; |
|---|
| 209 | $headers['Disposition-Notification-To'] = $identity_arr['string']; |
|---|
| 210 | } |
|---|
| 211 | |
|---|
| 212 | // additional headers |
|---|
| 213 | $headers['Message-ID'] = $message_id; |
|---|
| 214 | $headers['X-Sender'] = $from; |
|---|
| 215 | |
|---|
| 216 | if (!empty($CONFIG['useragent'])) |
|---|
| 217 | $headers['User-Agent'] = $CONFIG['useragent']; |
|---|
| 218 | |
|---|
| 219 | // fetch message body |
|---|
| 220 | $message_body = get_input_value('_message', RCUBE_INPUT_POST, TRUE, $message_charset); |
|---|
| 221 | |
|---|
| 222 | // append generic footer to all messages |
|---|
| 223 | if (!empty($CONFIG['generic_message_footer'])) |
|---|
| 224 | { |
|---|
| 225 | $file = realpath($CONFIG['generic_message_footer']); |
|---|
| 226 | if($fp = fopen($file, 'r')) |
|---|
| 227 | { |
|---|
| 228 | $content = fread($fp, filesize($file)); |
|---|
| 229 | fclose($fp); |
|---|
| 230 | $message_body .= "\r\n" . rcube_charset_convert($content, 'UTF-8', $message_charset); |
|---|
| 231 | } |
|---|
| 232 | } |
|---|
| 233 | |
|---|
| 234 | // try to autodetect operating system and use the correct line endings |
|---|
| 235 | // use the configured delimiter for headers |
|---|
| 236 | if (!empty($CONFIG['mail_header_delimiter'])) |
|---|
| 237 | $header_delm = $CONFIG['mail_header_delimiter']; |
|---|
| 238 | else if (strtolower(substr(PHP_OS, 0, 3)=='win')) |
|---|
| 239 | $header_delm = "\r\n"; |
|---|
| 240 | else if (strtolower(substr(PHP_OS, 0, 3)=='mac')) |
|---|
| 241 | $header_delm = "\r\n"; |
|---|
| 242 | else |
|---|
| 243 | $header_delm = "\n"; |
|---|
| 244 | |
|---|
| 245 | |
|---|
| 246 | $isHtmlVal = strtolower(get_input_value('_is_html', RCUBE_INPUT_POST)); |
|---|
| 247 | $isHtml = ($isHtmlVal == "1"); |
|---|
| 248 | |
|---|
| 249 | // create extended PEAR::Mail_mime instance |
|---|
| 250 | $MAIL_MIME = new rc_mail_mime($header_delm); |
|---|
| 251 | |
|---|
| 252 | // For HTML-formatted messages, construct the MIME message with both |
|---|
| 253 | // the HTML part and the plain-text part |
|---|
| 254 | |
|---|
| 255 | if ($isHtml) |
|---|
| 256 | { |
|---|
| 257 | $MAIL_MIME->setHTMLBody($message_body); |
|---|
| 258 | |
|---|
| 259 | // add a plain text version of the e-mail as an alternative part. |
|---|
| 260 | $h2t = new html2text($message_body); |
|---|
| 261 | $plainTextPart = wordwrap($h2t->get_text(), 998, "\r\n", true); |
|---|
| 262 | $MAIL_MIME->setTXTBody($plainTextPart); |
|---|
| 263 | |
|---|
| 264 | // look for "emoticon" images from TinyMCE and copy into message as attachments |
|---|
| 265 | rcmail_attach_emoticons($MAIL_MIME); |
|---|
| 266 | } |
|---|
| 267 | else |
|---|
| 268 | { |
|---|
| 269 | $message_body = wordwrap($message_body, 75, "\r\n"); |
|---|
| 270 | $message_body = wordwrap($message_body, 998, "\r\n", true); |
|---|
| 271 | $MAIL_MIME->setTXTBody($message_body, FALSE, TRUE); |
|---|
| 272 | } |
|---|
| 273 | |
|---|
| 274 | |
|---|
| 275 | // add stored attachments, if any |
|---|
| 276 | if (is_array($_SESSION['compose']['attachments'])) |
|---|
| 277 | foreach ($_SESSION['compose']['attachments'] as $attachment) |
|---|
| 278 | $MAIL_MIME->addAttachment($attachment['path'], $attachment['mimetype'], $attachment['name'], true, 'base64', 'attachment', $message_charset); |
|---|
| 279 | |
|---|
| 280 | // add submitted attachments |
|---|
| 281 | if (is_array($_FILES['_attachments']['tmp_name'])) |
|---|
| 282 | foreach ($_FILES['_attachments']['tmp_name'] as $i => $filepath) |
|---|
| 283 | $MAIL_MIME->addAttachment($filepath, $files['type'][$i], $files['name'][$i], true, 'base64', 'attachment', $message_charset); |
|---|
| 284 | |
|---|
| 285 | |
|---|
| 286 | // chose transfer encoding |
|---|
| 287 | $charset_7bit = array('ASCII', 'ISO-2022-JP', 'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-15'); |
|---|
| 288 | $transfer_encoding = in_array(strtoupper($message_charset), $charset_7bit) ? '7bit' : '8bit'; |
|---|
| 289 | |
|---|
| 290 | // encoding settings for mail composing |
|---|
| 291 | $message_param = array( |
|---|
| 292 | 'text_encoding' => $transfer_encoding, |
|---|
| 293 | 'html_encoding' => 'quoted-printable', |
|---|
| 294 | 'head_encoding' => 'quoted-printable', |
|---|
| 295 | 'head_charset' => $message_charset, |
|---|
| 296 | 'html_charset' => $message_charset, |
|---|
| 297 | 'text_charset' => $message_charset, |
|---|
| 298 | ); |
|---|
| 299 | |
|---|
| 300 | // compose message body and get headers |
|---|
| 301 | $msg_body = $MAIL_MIME->get($message_param); |
|---|
| 302 | // unset to save memory. |
|---|
| 303 | unset($MAIL_MIME->_parts); |
|---|
| 304 | |
|---|
| 305 | // encoding subject header with mb_encode provides better results with asian characters |
|---|
| 306 | if ($MBSTRING && function_exists("mb_encode_mimeheader")) |
|---|
| 307 | { |
|---|
| 308 | mb_internal_encoding($message_charset); |
|---|
| 309 | $mb_subject = mb_encode_mimeheader($headers['Subject'], $message_charset, 'Q'); |
|---|
| 310 | mb_internal_encoding(RCMAIL_CHARSET); |
|---|
| 311 | } |
|---|
| 312 | |
|---|
| 313 | // Begin SMTP Delivery Block |
|---|
| 314 | if (!$savedraft) { |
|---|
| 315 | |
|---|
| 316 | // send thru SMTP server using custom SMTP library |
|---|
| 317 | if ($CONFIG['smtp_server']) |
|---|
| 318 | { |
|---|
| 319 | // generate list of recipients |
|---|
| 320 | $a_recipients = array($mailto); |
|---|
| 321 | |
|---|
| 322 | if (strlen($headers['Cc'])) |
|---|
| 323 | $a_recipients[] = $headers['Cc']; |
|---|
| 324 | if (strlen($headers['Bcc'])) |
|---|
| 325 | $a_recipients[] = $headers['Bcc']; |
|---|
| 326 | |
|---|
| 327 | // clean Bcc from header for recipients |
|---|
| 328 | $send_headers = $headers; |
|---|
| 329 | unset($send_headers['Bcc']); |
|---|
| 330 | |
|---|
| 331 | if (!empty($mb_subject)) |
|---|
| 332 | $send_headers['Subject'] = $mb_subject; |
|---|
| 333 | |
|---|
| 334 | // send message |
|---|
| 335 | $smtp_response = array(); |
|---|
| 336 | $sent = smtp_mail($from, $a_recipients, $MAIL_MIME->txtHeaders($send_headers), $msg_body, $smtp_response); |
|---|
| 337 | |
|---|
| 338 | // log error |
|---|
| 339 | if (!$sent) |
|---|
| 340 | raise_error(array('code' => 800, 'type' => 'smtp', 'line' => __LINE__, 'file' => __FILE__, |
|---|
| 341 | 'message' => "SMTP error: ".join("\n", $smtp_response)), TRUE, FALSE); |
|---|
| 342 | } |
|---|
| 343 | |
|---|
| 344 | // send mail using PHP's mail() function |
|---|
| 345 | else |
|---|
| 346 | { |
|---|
| 347 | // unset some headers because they will be added by the mail() function |
|---|
| 348 | $headers_enc = $MAIL_MIME->headers($headers); |
|---|
| 349 | $headers_php = $MAIL_MIME->_headers; |
|---|
| 350 | unset($headers_php['To'], $headers_php['Subject']); |
|---|
| 351 | |
|---|
| 352 | if (!empty($mb_subject)) |
|---|
| 353 | $headers_enc['Subject'] = $mb_subject; |
|---|
| 354 | |
|---|
| 355 | // reset stored headers and overwrite |
|---|
| 356 | $MAIL_MIME->_headers = array(); |
|---|
| 357 | $header_str = $MAIL_MIME->txtHeaders($headers_php); |
|---|
| 358 | |
|---|
| 359 | if (ini_get('safe_mode')) |
|---|
| 360 | $sent = mail($headers_enc['To'], $headers_enc['Subject'], $msg_body, $header_str); |
|---|
| 361 | else |
|---|
| 362 | $sent = mail($headers_enc['To'], $headers_enc['Subject'], $msg_body, $header_str, "-f$from"); |
|---|
| 363 | } |
|---|
| 364 | |
|---|
| 365 | |
|---|
| 366 | // return to compose page if sending failed |
|---|
| 367 | if (!$sent) |
|---|
| 368 | { |
|---|
| 369 | $OUTPUT->show_message("sendingfailed", 'error'); |
|---|
| 370 | $OUTPUT->send('iframe'); |
|---|
| 371 | return; |
|---|
| 372 | } |
|---|
| 373 | |
|---|
| 374 | |
|---|
| 375 | // set repliead flag |
|---|
| 376 | if ($_SESSION['compose']['reply_uid']) |
|---|
| 377 | $IMAP->set_flag($_SESSION['compose']['reply_uid'], 'ANSWERED'); |
|---|
| 378 | |
|---|
| 379 | } // End of SMTP Delivery Block |
|---|
| 380 | |
|---|
| 381 | |
|---|
| 382 | |
|---|
| 383 | // Determine which folder to save message |
|---|
| 384 | if ($savedraft) |
|---|
| 385 | $store_target = 'drafts_mbox'; |
|---|
| 386 | else |
|---|
| 387 | $store_target = 'sent_mbox'; |
|---|
| 388 | |
|---|
| 389 | if ($CONFIG[$store_target]) |
|---|
| 390 | { |
|---|
| 391 | // create string of complete message headers |
|---|
| 392 | $header_str = $MAIL_MIME->txtHeaders($headers); |
|---|
| 393 | |
|---|
| 394 | // check if mailbox exists |
|---|
| 395 | if (!in_array_nocase($CONFIG[$store_target], $IMAP->list_mailboxes())) |
|---|
| 396 | $store_folder = $IMAP->create_mailbox($CONFIG[$store_target], TRUE); |
|---|
| 397 | else |
|---|
| 398 | $store_folder = TRUE; |
|---|
| 399 | |
|---|
| 400 | // add headers to message body |
|---|
| 401 | $msg_body = $header_str."\r\n".$msg_body; |
|---|
| 402 | |
|---|
| 403 | // append message to sent box |
|---|
| 404 | if ($store_folder) |
|---|
| 405 | $saved = $IMAP->save_message($CONFIG[$store_target], $msg_body); |
|---|
| 406 | |
|---|
| 407 | // raise error if saving failed |
|---|
| 408 | if (!$saved) |
|---|
| 409 | { |
|---|
| 410 | raise_error(array('code' => 800, 'type' => 'imap', 'file' => __FILE__, |
|---|
| 411 | 'message' => "Could not save message in $CONFIG[$store_target]"), TRUE, FALSE); |
|---|
| 412 | |
|---|
| 413 | $OUTPUT->show_message('errorsaving', 'error'); |
|---|
| 414 | $OUTPUT->send('iframe'); |
|---|
| 415 | } |
|---|
| 416 | |
|---|
| 417 | if ($olddraftmessageid) |
|---|
| 418 | { |
|---|
| 419 | // delete previous saved draft |
|---|
| 420 | $a_deleteid = $IMAP->search($CONFIG['drafts_mbox'],'HEADER Message-ID',$olddraftmessageid); |
|---|
| 421 | $deleted = $IMAP->delete_message($IMAP->get_uid($a_deleteid[0],$CONFIG['drafts_mbox']),$CONFIG['drafts_mbox']); |
|---|
| 422 | |
|---|
| 423 | // raise error if deletion of old draft failed |
|---|
| 424 | if (!$deleted) |
|---|
| 425 | raise_error(array('code' => 800, 'type' => 'imap', 'file' => __FILE__, |
|---|
| 426 | 'message' => "Could not delete message from ".$CONFIG['drafts_mbox']), TRUE, FALSE); |
|---|
| 427 | } |
|---|
| 428 | } |
|---|
| 429 | |
|---|
| 430 | if ($savedraft) |
|---|
| 431 | { |
|---|
| 432 | // display success |
|---|
| 433 | $OUTPUT->show_message('messagesaved', 'confirmation'); |
|---|
| 434 | |
|---|
| 435 | // update "_draft_saveid" and the "cmp_hash" to prevent "Unsaved changes" warning |
|---|
| 436 | $OUTPUT->command('set_draft_id', str_replace(array('<','>'), "", $message_id)); |
|---|
| 437 | $OUTPUT->command('compose_field_hash', true); |
|---|
| 438 | |
|---|
| 439 | // start the auto-save timer again |
|---|
| 440 | $OUTPUT->command('auto_save_start'); |
|---|
| 441 | |
|---|
| 442 | $OUTPUT->send('iframe'); |
|---|
| 443 | } |
|---|
| 444 | else |
|---|
| 445 | { |
|---|
| 446 | if ($CONFIG['smtp_log']) |
|---|
| 447 | { |
|---|
| 448 | $log_entry = sprintf( |
|---|
| 449 | "[%s] User: %d on %s; Message for %s; %s\n", |
|---|
| 450 | date("d-M-Y H:i:s O", mktime()), |
|---|
| 451 | $_SESSION['user_id'], |
|---|
| 452 | $_SERVER['REMOTE_ADDR'], |
|---|
| 453 | $mailto, |
|---|
| 454 | !empty($smtp_response) ? join('; ', $smtp_response) : ''); |
|---|
| 455 | |
|---|
| 456 | if ($fp = @fopen($CONFIG['log_dir'].'/sendmail', 'a')) |
|---|
| 457 | { |
|---|
| 458 | fwrite($fp, $log_entry); |
|---|
| 459 | fclose($fp); |
|---|
| 460 | } |
|---|
| 461 | } |
|---|
| 462 | |
|---|
| 463 | rcmail_compose_cleanup(); |
|---|
| 464 | $OUTPUT->command('sent_successfully', rcube_label('messagesent')); |
|---|
| 465 | $OUTPUT->send('iframe'); |
|---|
| 466 | } |
|---|
| 467 | |
|---|
| 468 | |
|---|
| 469 | ?> |
|---|