| | |
| | | return $body; |
| | | } |
| | | |
| | | // parse email address input |
| | | function rcmail_email_input_format($mailto) |
| | | // parse email address input (and count addresses) |
| | | function rcmail_email_input_format($mailto, $count=false) |
| | | { |
| | | global $EMAIL_FORMAT_ERROR; |
| | | global $EMAIL_FORMAT_ERROR, $RECIPIENT_COUNT; |
| | | |
| | | $regexp = array('/[,;]\s*[\r\n]+/', '/[\r\n]+/', '/[,;]\s*$/m', '/;/', '/(\S{1})(<\S+@\S+>)/U'); |
| | | $replace = array(', ', ', ', '', ',', '\\1 \\2'); |
| | |
| | | } |
| | | } |
| | | |
| | | if ($count) { |
| | | $RECIPIENT_COUNT += count($result); |
| | | } |
| | | |
| | | return implode(', ', $result); |
| | | } |
| | | |
| | |
| | | $message_charset = isset($_POST['_charset']) ? $_POST['_charset'] : $input_charset; |
| | | |
| | | $EMAIL_FORMAT_ERROR = NULL; |
| | | $RECIPIENT_COUNT = 0; |
| | | |
| | | $mailto = rcmail_email_input_format(get_input_value('_to', RCUBE_INPUT_POST, TRUE, $message_charset)); |
| | | $mailcc = rcmail_email_input_format(get_input_value('_cc', RCUBE_INPUT_POST, TRUE, $message_charset)); |
| | | $mailbcc = rcmail_email_input_format(get_input_value('_bcc', RCUBE_INPUT_POST, TRUE, $message_charset)); |
| | | $mailto = rcmail_email_input_format(get_input_value('_to', RCUBE_INPUT_POST, TRUE, $message_charset), true); |
| | | $mailcc = rcmail_email_input_format(get_input_value('_cc', RCUBE_INPUT_POST, TRUE, $message_charset), true); |
| | | $mailbcc = rcmail_email_input_format(get_input_value('_bcc', RCUBE_INPUT_POST, TRUE, $message_charset), true); |
| | | |
| | | if ($EMAIL_FORMAT_ERROR) { |
| | | $OUTPUT->show_message('emailformaterror', 'error', array('email' => $EMAIL_FORMAT_ERROR)); |
| | |
| | | if (!empty($mailbcc)) |
| | | $headers['Bcc'] = $mailbcc; |
| | | |
| | | if (!empty($identity_arr['bcc'])) |
| | | if (!empty($identity_arr['bcc'])) { |
| | | $headers['Bcc'] = ($headers['Bcc'] ? $headers['Bcc'].', ' : '') . $identity_arr['bcc']; |
| | | $RECIPIENT_COUNT ++; |
| | | } |
| | | |
| | | if (($max_recipients = (int) $RCMAIL->config->get('max_recipients')) > 0) { |
| | | if ($RECIPIENT_COUNT > $max_recipients) { |
| | | $OUTPUT->show_message('toomanyrecipients', 'error', array('max' => $max_recipients)); |
| | | $OUTPUT->send('iframe'); |
| | | } |
| | | } |
| | | |
| | | // add subject |
| | | $headers['Subject'] = trim(get_input_value('_subject', RCUBE_INPUT_POST, TRUE, $message_charset)); |
| | |
| | | |
| | | if (!empty($_SESSION['compose']['reply_msgid'])) |
| | | $headers['In-Reply-To'] = $_SESSION['compose']['reply_msgid']; |
| | | |
| | | // remember reply/forward UIDs in special headers |
| | | if (!empty($_SESSION['compose']['reply_uid']) && $savedraft) |
| | | $headers['X-Draft-Info'] = array('type' => 'reply', 'uid' => $_SESSION['compose']['reply_uid']); |
| | | else if (!empty($_SESSION['compose']['forward_uid']) && $savedraft) |
| | | $headers['X-Draft-Info'] = array('type' => 'forward', 'uid' => $_SESSION['compose']['forward_uid']); |
| | | |
| | | if (!empty($_SESSION['compose']['references'])) |
| | | $headers['References'] = $_SESSION['compose']['references']; |
| | |
| | | $headers['Message-ID'] = $message_id; |
| | | $headers['X-Sender'] = $from; |
| | | |
| | | if (is_array($headers['X-Draft-Info'])) |
| | | $headers['X-Draft-Info'] = rcmail_draftinfo_encode($headers['X-Draft-Info'] + array('folder' => $_SESSION['compose']['mailbox'])); |
| | | |
| | | if (!empty($CONFIG['useragent'])) |
| | | $headers['User-Agent'] = $CONFIG['useragent']; |
| | | |
| | | $isHtmlVal = strtolower(get_input_value('_is_html', RCUBE_INPUT_POST)); |
| | | $isHtml = ($isHtmlVal == "1"); |
| | | // exec hook for header checking and manipulation |
| | | $data = $RCMAIL->plugins->exec_hook('outgoing_message_headers', array('headers' => $headers)); |
| | | |
| | | // sending aborted by plugin |
| | | if ($data['abort'] && !$savedraft) { |
| | | $OUTPUT->show_message($data['message'] ? $data['message'] : 'sendingfailed'); |
| | | $OUTPUT->send('iframe'); |
| | | } |
| | | else |
| | | $headers = $data['headers']; |
| | | |
| | | |
| | | $isHtml = (bool) get_input_value('_is_html', RCUBE_INPUT_POST); |
| | | |
| | | // fetch message body |
| | | $message_body = get_input_value('_message', RCUBE_INPUT_POST, TRUE, $message_charset); |
| | | |
| | | if (!$savedraft) { |
| | | // remove signature's div ID |
| | | if ($isHtml) |
| | | if ($isHtml) { |
| | | // remove signature's div ID |
| | | $message_body = preg_replace('/\s*id="_rc_sig"/', '', $message_body); |
| | | |
| | | // add inline css for blockquotes |
| | | $bstyle = 'padding-left:5px; border-left:#1010ff 2px solid; margin-left:5px; width:100%'; |
| | | $message_body = preg_replace('/<blockquote>/', |
| | | '<blockquote type="cite" style="'.$bstyle.'">', $message_body); |
| | | } |
| | | // generic footer for all messages |
| | | if (!empty($CONFIG['generic_message_footer'])) { |
| | | $footer = file_get_contents(realpath($CONFIG['generic_message_footer'])); |
| | |
| | | $MAIL_MIME->setTXTBody($plugin['body'], false, true); |
| | | } |
| | | |
| | | // chose transfer encoding |
| | | $charset_7bit = array('ASCII', 'ISO-2022-JP', 'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-15'); |
| | | $transfer_encoding = in_array(strtoupper($message_charset), $charset_7bit) ? '7bit' : '8bit'; |
| | | |
| | | // add stored attachments, if any |
| | | if (is_array($_SESSION['compose']['attachments'])) |
| | | { |
| | |
| | | $ctype, |
| | | $attachment['name'], |
| | | ($attachment['data'] ? false : true), |
| | | ($ctype == 'message/rfc822' ? $transfer_encoding : 'base64'), |
| | | // @TODO: quoted-printable for message/rfc822 is safe, |
| | | // but we should check that 7bit or 8bit is possible here |
| | | ($ctype == 'message/rfc822' ? 'quoted-printable' : 'base64'), |
| | | ($ctype == 'message/rfc822' ? 'inline' : 'attachment'), |
| | | $message_charset, '', '', |
| | | $CONFIG['mime_param_folding'] ? 'quoted-printable' : NULL, |
| | |
| | | } |
| | | } |
| | | |
| | | // choose transfer encoding for plain/text body |
| | | if (preg_match('/[^\x00-\x7F]/', $MAIL_MIME->getTXTBody())) |
| | | $transfer_encoding = $RCMAIL->config->get('force_7bit') ? 'quoted-printable' : '8bit'; |
| | | else |
| | | $transfer_encoding = '7bit'; |
| | | |
| | | // encoding settings for mail composing |
| | | $MAIL_MIME->setParam('text_encoding', $transfer_encoding); |
| | | $MAIL_MIME->setParam('html_encoding', 'quoted-printable'); |
| | |
| | | $MAIL_MIME->setParam('head_charset', $message_charset); |
| | | $MAIL_MIME->setParam('html_charset', $message_charset); |
| | | $MAIL_MIME->setParam('text_charset', $message_charset); |
| | | |
| | | $data = $RCMAIL->plugins->exec_hook('outgoing_message_headers', array('headers' => $headers)); |
| | | $headers = $data['headers']; |
| | | |
| | | // encoding subject header with mb_encode provides better results with asian characters |
| | | if (function_exists('mb_encode_mimeheader')) |
| | |
| | | |
| | | if ($store_target) |
| | | { |
| | | // check if mailbox exists |
| | | if (!in_array($store_target, $IMAP->list_mailboxes())) |
| | | { |
| | | // folder may be existing but not subscribed (#1485241) |
| | | if (!in_array($store_target, $IMAP->list_unsubscribed())) |
| | | $store_folder = $IMAP->create_mailbox($store_target, TRUE); |
| | | else if ($IMAP->subscribe($store_target)) |
| | | $store_folder = TRUE; |
| | | } |
| | | else |
| | | $store_folder = TRUE; |
| | | // check if folder is subscribed |
| | | if ($IMAP->mailbox_exists($store_target, true)) |
| | | $store_folder = true; |
| | | // folder may be existing but not subscribed (#1485241) |
| | | else if (!$IMAP->mailbox_exists($store_target)) |
| | | $store_folder = $IMAP->create_mailbox($store_target, true); |
| | | else if ($IMAP->subscribe($store_target)) |
| | | $store_folder = true; |
| | | |
| | | // append message to sent box |
| | | if ($store_folder) { |
| | |
| | | if ($olddraftmessageid) |
| | | { |
| | | // delete previous saved draft |
| | | $a_deleteid = $IMAP->search($CONFIG['drafts_mbox'], 'HEADER Message-ID '.$olddraftmessageid); |
| | | |
| | | $deleted = $IMAP->delete_message($IMAP->get_uid($a_deleteid[0], $CONFIG['drafts_mbox']), $CONFIG['drafts_mbox']); |
| | | $a_deleteid = $IMAP->search_once($CONFIG['drafts_mbox'], |
| | | 'HEADER Message-ID '.$olddraftmessageid, true); |
| | | $deleted = $IMAP->delete_message($a_deleteid, $CONFIG['drafts_mbox']); |
| | | |
| | | // raise error if deletion of old draft failed |
| | | if (!$deleted) |
| | |
| | | $msgid = strtr($message_id, array('>' => '', '<' => '')); |
| | | |
| | | // remember new draft-uid |
| | | $draftids = $IMAP->search($CONFIG['drafts_mbox'], 'HEADER Message-ID '.$msgid); |
| | | $_SESSION['compose']['param']['_draft_uid'] = $IMAP->get_uid($draftids[0], $CONFIG['drafts_mbox']); |
| | | $draftuids = $IMAP->search_once($CONFIG['drafts_mbox'], 'HEADER Message-ID '.$msgid, true); |
| | | $_SESSION['compose']['param']['_draft_uid'] = $draftuids[0]; |
| | | |
| | | // display success |
| | | $OUTPUT->show_message('messagesaved', 'confirmation'); |