$Call['Link'] = F::Run(null, 'Open', $Call); } self::$_Perfect = false; if (isset($Call['From'])) { $Screen = $Call['From']; } elseif (isset($Call['Project']['Title'])) { $Screen = $Call['Project']['Title'] . ' <' . $Call['Username'] . '>'; } else { $Screen = 'Codeine <' . $Call['Username'] . '>'; } $Call['Headers']['From'] = $Screen; $Call['Headers']['To'] = $Call['Scope']; $Call['Headers']['Subject'] = $Call['Where']['ID']; $mime = new Mail_mime(); // Setting the body of the email $mime->setParam('html_charset', 'utf-8'); $mime->setParam('text_charset', 'utf-8'); $mime->setParam('head_charset', 'utf-8'); if (is_array($Call['Data'])) { $Call['Data'] = implode(PHP_EOL, $Call['Data']); } if (isset($Call['HTML Mail']) && $Call['HTML Mail']) { $mime->setHTMLBody($Call['Data']); $Call['Headers']['Content-Type'] = 'text/html; charset=utf-8'; } else { $mime->setTXTBody(strip_tags($Call['Data'])); } $Call['Data'] = $mime->get(['text_charset' => 'utf-8']); $Call['Headers'] = $mime->headers($Call['Headers']); F::Log('Sending mail "' . $Call['Where']['ID'] . '" to ' . $Call['Scope'] . ' with ' . $Call['Server'], LOG_INFO, 'Administrator'); $Result = $Call['Link']->send($Call['Scope'], $Call['Headers'], $Call['Data']);
/** * Helper function to build a Mail_mime object to send an iTip message * * @param array Event object to send * @param string iTip method (REQUEST|REPLY|CANCEL) * @param boolean Request RSVP * @return object Mail_mime object with message data */ public function compose_itip_message($event, $method, $rsvp = true) { $from = rcube_utils::idn_to_ascii($this->sender['email']); $from_utf = rcube_utils::idn_to_utf8($from); $sender = format_email_recipient($from, $this->sender['name']); // truncate list attendees down to the recipient of the iTip Reply. // constraints for a METHOD:REPLY according to RFC 5546 if ($method == 'REPLY') { $replying_attendee = null; $reply_attendees = array(); foreach ($event['attendees'] as $attendee) { if ($attendee['role'] == 'ORGANIZER') { $reply_attendees[] = $attendee; } else { if (strcasecmp($attendee['email'], $from) == 0 || strcasecmp($attendee['email'], $from_utf) == 0) { $replying_attendee = $attendee; if ($attendee['status'] != 'DELEGATED') { unset($replying_attendee['rsvp']); // unset the RSVP attribute } } else { if (!empty($attendee['delegated-to']) && (strcasecmp($attendee['delegated-to'], $from) == 0 || strcasecmp($attendee['delegated-to'], $from_utf) == 0) || !empty($attendee['delegated-from']) && (strcasecmp($attendee['delegated-from'], $from) == 0 || strcasecmp($attendee['delegated-from'], $from_utf) == 0)) { $reply_attendees[] = $attendee; } } } } if ($replying_attendee) { array_unshift($reply_attendees, $replying_attendee); $event['attendees'] = $reply_attendees; } if ($event['recurrence']) { unset($event['recurrence']['EXCEPTIONS']); } } else { if ($method == 'REQUEST') { foreach ($event['attendees'] as $i => $attendee) { if (($rsvp || !isset($attendee['rsvp'])) && ($attendee['status'] != 'DELEGATED' && $attendee['role'] != 'NON-PARTICIPANT')) { $event['attendees'][$i]['rsvp'] = (bool) $rsvp; } } } else { if ($method == 'CANCEL') { if ($event['recurrence']) { unset($event['recurrence']['EXCEPTIONS']); } } } } // compose multipart message using PEAR:Mail_Mime $message = new Mail_mime("\r\n"); $message->setParam('text_encoding', 'quoted-printable'); $message->setParam('head_encoding', 'quoted-printable'); $message->setParam('head_charset', RCUBE_CHARSET); $message->setParam('text_charset', RCUBE_CHARSET . ";\r\n format=flowed"); $message->setContentType('multipart/alternative'); // compose common headers array $headers = array('From' => $sender, 'Date' => $this->rc->user_date(), 'Message-ID' => $this->rc->gen_message_id(), 'X-Sender' => $from); if ($agent = $this->rc->config->get('useragent')) { $headers['User-Agent'] = $agent; } $message->headers($headers); // attach ics file for this event $ical = libcalendaring::get_ical(); $ics = $ical->export(array($event), $method, false, $method == 'REQUEST' && $this->plugin->driver ? array($this->plugin->driver, 'get_attachment_body') : false); $filename = $event['_type'] == 'task' ? 'todo.ics' : 'event.ics'; $message->addAttachment($ics, 'text/calendar', $filename, false, '8bit', '', RCUBE_CHARSET . "; method=" . $method); return $message; }
/** * Helper function to build a Mail_mime object to send an iTip message * * @param array Event object to send * @param string iTip method (REQUEST|REPLY|CANCEL) * @return object Mail_mime object with message data */ public function compose_itip_message($event, $method) { $from = rcube_idn_to_ascii($this->sender['email']); $from_utf = rcube_idn_to_utf8($from); $sender = format_email_recipient($from, $this->sender['name']); // truncate list attendees down to the recipient of the iTip Reply. // constraints for a METHOD:REPLY according to RFC 5546 if ($method == 'REPLY') { $replying_attendee = null; $reply_attendees = array(); foreach ($event['attendees'] as $attendee) { if ($attendee['role'] == 'ORGANIZER') { $reply_attendees[] = $attendee; } else { if (strcasecmp($attedee['email'], $from) == 0 || strcasecmp($attendee['email'], $from_utf) == 0) { $replying_attendee = $attendee; } } } if ($replying_attendee) { $reply_attendees[] = $replying_attendee; $event['attendees'] = $reply_attendees; } } // compose multipart message using PEAR:Mail_Mime $message = new Mail_mime("\r\n"); $message->setParam('text_encoding', 'quoted-printable'); $message->setParam('head_encoding', 'quoted-printable'); $message->setParam('head_charset', RCMAIL_CHARSET); $message->setParam('text_charset', RCMAIL_CHARSET . ";\r\n format=flowed"); $message->setContentType('multipart/alternative'); // compose common headers array $headers = array('From' => $sender, 'Date' => $this->rc->user_date(), 'Message-ID' => $this->rc->gen_message_id(), 'X-Sender' => $from); if ($agent = $this->rc->config->get('useragent')) { $headers['User-Agent'] = $agent; } $message->headers($headers); // attach ics file for this event $ical = $this->cal->get_ical(); $ics = $ical->export(array($event), $method, false, $method == 'REQUEST' ? array($this->cal->driver, 'get_attachment_body') : false); $message->addAttachment($ics, 'text/calendar', 'event.ics', false, '8bit', '', RCMAIL_CHARSET . "; method=" . $method); return $message; }
private function _do_emaillearn($uids, $spam) { $rcmail = rcube::get_instance(); $identity_arr = $rcmail->user->get_identity(); $from = $identity_arr['email']; if ($spam) { $mailto = $rcmail->config->get('markasjunk2_email_spam'); } else { $mailto = $rcmail->config->get('markasjunk2_email_ham'); } $mailto = str_replace('%u', $_SESSION['username'], $mailto); $mailto = str_replace('%l', $rcmail->user->get_username('local'), $mailto); $mailto = str_replace('%d', $rcmail->user->get_username('domain'), $mailto); $mailto = str_replace('%i', $from, $mailto); if (!$mailto) { return; } $message_charset = $rcmail->output->get_charset(); // 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'; $temp_dir = realpath($rcmail->config->get('temp_dir')); $subject = $rcmail->config->get('markasjunk2_email_subject'); $subject = str_replace('%u', $_SESSION['username'], $subject); $subject = str_replace('%t', $spam ? 'spam' : 'ham', $subject); $subject = str_replace('%l', $rcmail->user->get_username('local'), $subject); $subject = str_replace('%d', $rcmail->user->get_username('domain'), $subject); // compose headers array $headers = array(); $headers['Date'] = date('r'); $headers['From'] = format_email_recipient($identity_arr['email'], $identity_arr['name']); $headers['To'] = $mailto; $headers['Subject'] = $subject; foreach ($uids as $uid) { $MESSAGE = new rcube_message($uid); // set message charset as default if (!empty($MESSAGE->headers->charset)) { $rcmail->storage->set_charset($MESSAGE->headers->charset); } $MAIL_MIME = new Mail_mime($rcmail->config->header_delimiter()); if ($rcmail->config->get('markasjunk2_email_attach', false)) { $tmpPath = tempnam($temp_dir, 'rcmMarkASJunk2'); // send mail as attachment $MAIL_MIME->setTXTBody(($spam ? 'Spam' : 'Ham') . ' report from ' . $rcmail->config->get('product_name'), false, true); $raw_message = $rcmail->storage->get_raw_body($uid); $subject = $MESSAGE->get_header('subject'); if (isset($subject) && $subject != "") { $disp_name = $subject . ".eml"; } else { $disp_name = "message_rfc822.eml"; } if (file_put_contents($tmpPath, $raw_message)) { $MAIL_MIME->addAttachment($tmpPath, "message/rfc822", $disp_name, true, $transfer_encoding, 'attachment', '', '', '', $rcmail->config->get('mime_param_folding') ? 'quoted-printable' : NULL, $rcmail->config->get('mime_param_folding') == 2 ? 'quoted-printable' : NULL, '', RCUBE_CHARSET); } // encoding settings for mail composing $MAIL_MIME->setParam('text_encoding', $transfer_encoding); $MAIL_MIME->setParam('html_encoding', 'quoted-printable'); $MAIL_MIME->setParam('head_encoding', 'quoted-printable'); $MAIL_MIME->setParam('head_charset', $message_charset); $MAIL_MIME->setParam('html_charset', $message_charset); $MAIL_MIME->setParam('text_charset', $message_charset); // pass headers to message object $MAIL_MIME->headers($headers); } else { $headers['Resent-From'] = $headers['From']; $headers['Resent-Date'] = $headers['Date']; $headers['Date'] = $MESSAGE->headers->date; $headers['From'] = $MESSAGE->headers->from; $headers['Subject'] = $MESSAGE->headers->subject; $MAIL_MIME->headers($headers); if ($MESSAGE->has_html_part()) { $body = $MESSAGE->first_html_part(); $MAIL_MIME->setHTMLBody($body); } $body = $MESSAGE->first_text_part(); $MAIL_MIME->setTXTBody($body, false, true); foreach ($MESSAGE->attachments as $attachment) { $MAIL_MIME->addAttachment($MESSAGE->get_part_body($attachment->mime_id, true), $attachment->mimetype, $attachment->filename, false, $attachment->encoding, $attachment->disposition, '', $attachment->charset); } foreach ($MESSAGE->mime_parts as $attachment) { if (!empty($attachment->content_id)) { // covert CID to Mail_MIME format $attachment->content_id = str_replace('<', '', $attachment->content_id); $attachment->content_id = str_replace('>', '', $attachment->content_id); if (empty($attachment->filename)) { $attachment->filename = $attachment->content_id; } $message_body = $MAIL_MIME->getHTMLBody(); $dispurl = 'cid:' . $attachment->content_id; $message_body = str_replace($dispurl, $attachment->filename, $message_body); $MAIL_MIME->setHTMLBody($message_body); $MAIL_MIME->addHTMLImage($MESSAGE->get_part_body($attachment->mime_id, true), $attachment->mimetype, $attachment->filename, false); } } // encoding settings for mail composing $MAIL_MIME->setParam('head_encoding', $MESSAGE->headers->encoding); $MAIL_MIME->setParam('head_charset', $MESSAGE->headers->charset); foreach ($MESSAGE->mime_parts as $mime_id => $part) { $mimetype = strtolower($part->ctype_primary . '/' . $part->ctype_secondary); if ($mimetype == 'text/html') { $MAIL_MIME->setParam('text_encoding', $part->encoding); $MAIL_MIME->setParam('html_charset', $part->charset); } else { if ($mimetype == 'text/plain') { $MAIL_MIME->setParam('html_encoding', $part->encoding); $MAIL_MIME->setParam('text_charset', $part->charset); } } } } $rcmail->deliver_message($MAIL_MIME, $from, $mailto, $smtp_error, $body_file); // clean up if (file_exists($tmpPath)) { unlink($tmpPath); } if ($rcmail->config->get('markasjunk2_debug')) { if ($spam) { rcube::write_log('markasjunk2', $uid . ' SPAM ' . $mailto . ' (' . $subject . ')'); } else { rcube::write_log('markasjunk2', $uid . ' HAM ' . $mailto . ' (' . $subject . ')'); } if ($smtp_error['vars']) { rcube::write_log('markasjunk2', $smtp_error['vars']); } } } }
public function as_text() { $script = ''; $variables = ''; $exts = array(); // rules $activeRules = 0; foreach ($this->content as $rule) { $tests = array(); $i = 0; if ($rule['disabled'] == 1) { $script .= '# rule:[' . $rule['name'] . "]" . RCUBE_SIEVE_NEWLINE; $script .= '# disabledRule:[' . $this->_safe_serial(serialize($rule)) . "]" . RCUBE_SIEVE_NEWLINE; } else { // header $script .= '# rule:[' . $rule['name'] . "]" . RCUBE_SIEVE_NEWLINE; // constraints expressions foreach ($rule['tests'] as $test) { $tests[$i] = ''; switch ($test['type']) { case 'size': $tests[$i] .= $test['not'] ? 'not ' : ''; $tests[$i] .= 'size :' . ($test['operator'] == 'under' ? 'under ' : 'over ') . $test['target']; break; case 'virustest': case 'spamtest': array_push($exts, $test['type']); array_push($exts, 'relational'); array_push($exts, 'comparator-i;ascii-numeric'); $tests[$i] .= $test['not'] ? 'not ' : ''; $tests[$i] .= $test['type'] . ' :value ' . ($test['operator'] == 'eq' ? '"eq" ' : ($test['operator'] == 'le' ? '"le" ' : '"ge" ')) . ':comparator "i;ascii-numeric" "' . $test['target'] . '"'; break; case 'true': $tests[$i] .= $test['not'] ? 'not true' : 'true'; break; case 'exists': $tests[$i] .= $test['not'] ? 'not ' : ''; if (is_array($test['header'])) { $tests[$i] .= 'exists ["' . implode('", "', $this->_escape_string($test['header'])) . '"]'; } else { $tests[$i] .= 'exists "' . $this->_escape_string($test['header']) . '"'; } break; case 'envelope': array_push($exts, 'envelope'); case 'header': case 'address': if ($test['operator'] == 'regex') { array_push($exts, 'regex'); } elseif (substr($test['operator'], 0, 5) == 'count' || substr($test['operator'], 0, 5) == 'value') { array_push($exts, 'relational'); } elseif ($test['operator'] == 'user' || $test['operator'] == 'detail' || $test['operator'] == 'domain') { array_push($exts, 'subaddress'); } $tests[$i] .= $test['not'] ? 'not ' : ''; $tests[$i] .= $test['type'] . ' :' . $test['operator']; if ($test['comparator'] != '') { if ($test['comparator'] != 'i;ascii-casemap' && $test['comparator'] != 'i;octet') { array_push($exts, 'comparator-' . $test['comparator']); } $tests[$i] .= ' :comparator "' . $test['comparator'] . '"'; } if (is_array($test['header'])) { $tests[$i] .= ' ["' . implode('", "', $this->_escape_string($test['header'])) . '"]'; } else { $tests[$i] .= ' "' . $this->_escape_string($test['header']) . '"'; } if (is_array($test['target'])) { $tests[$i] .= ' ["' . implode('", "', $this->_escape_string($test['target'])) . '"]'; } else { $tests[$i] .= ' "' . $this->_escape_string($test['target']) . '"'; } break; case 'body': array_push($exts, 'body'); if ($test['operator'] == 'regex') { array_push($exts, 'regex'); } elseif (substr($test['operator'], 0, 5) == 'count' || substr($test['operator'], 0, 5) == 'value') { array_push($exts, 'relational'); } $tests[$i] .= $test['not'] ? 'not ' : ''; $tests[$i] .= $test['type']; if ($test['bodypart'] != '') { $tests[$i] .= ' :' . $test['bodypart']; } if ($test['contentpart'] != '') { $tests[$i] .= ' "' . $test['contentpart'] . '"'; } $tests[$i] .= ' :' . $test['operator']; if ($test['comparator'] != '') { if ($test['comparator'] != 'i;ascii-casemap' && $test['comparator'] != 'i;octet') { array_push($exts, 'comparator-' . $test['comparator']); } $tests[$i] .= ' :comparator "' . $test['comparator'] . '"'; } if (is_array($test['target'])) { $tests[$i] .= ' ["' . implode('", "', $this->_escape_string($test['target'])) . '"]'; } else { $tests[$i] .= ' "' . $this->_escape_string($test['target']) . '"'; } break; case 'date': array_push($exts, 'date'); if ($test['operator'] == 'regex') { array_push($exts, 'regex'); } elseif (substr($test['operator'], 0, 5) == 'count' || substr($test['operator'], 0, 5) == 'value') { array_push($exts, 'relational'); } $tests[$i] .= $test['not'] ? 'not ' : ''; $tests[$i] .= $test['header']; $timezone = rcmail::get_instance()->config->get('timezone', 'auto'); if ($timezone != 'auto') { $server_time = gmdate('U'); $user_time = format_date(time(), 'U'); if ($server_time == $user_time) { $zone = '+0000'; } else { if ($user_time > $server_time) { $user_time -= $server_time; // hours $zone = '+' . str_pad(intval(intval($user_time) / 3600), 2, "0", STR_PAD_LEFT); // minutes $zone .= str_pad(intval($user_time / 60 % 60), 2, "0", STR_PAD_LEFT); } else { $server_time -= $user_time; // hours $zone = '-' . str_pad(intval(intval($server_time) / 3600), 2, "0", STR_PAD_LEFT); // minutes $zone .= str_pad(intval($server_time / 60 % 60), 2, "0", STR_PAD_LEFT); } } $tests[$i] .= ' :zone ' . '"' . $zone . '"'; } $tests[$i] .= ' :' . $test['operator']; if ($test['comparator'] != '') { if ($test['comparator'] != 'i;ascii-casemap' && $test['comparator'] != 'i;octet') { array_push($exts, 'comparator-' . $test['comparator']); } $tests[$i] .= ' :comparator "' . $test['comparator'] . '"'; } $tests[$i] .= ' "' . $this->_escape_string($test['datepart']) . '"'; $tests[$i] .= ' "' . $this->_escape_string($test['target']) . '"'; break; } $i++; } $script .= ($activeRules > 0 && $this->elsif ? 'els' : '') . ($rule['join'] ? 'if allof (' : 'if anyof ('); $activeRules++; if (sizeof($tests) > 1) { $script .= implode("," . RCUBE_SIEVE_NEWLINE . RCUBE_SIEVE_INDENT, $tests); } elseif (sizeof($tests)) { $script .= $tests[0]; } else { $script .= 'true'; } $script .= ")" . RCUBE_SIEVE_NEWLINE . "{" . RCUBE_SIEVE_NEWLINE; // action(s) $actions = ''; foreach ($rule['actions'] as $action) { switch ($action['type']) { case 'fileinto': case 'fileinto_copy': array_push($exts, 'fileinto'); $args = ''; if ($action['type'] == 'fileinto_copy') { array_push($exts, 'copy'); $args .= ' :copy'; } if ($action['create']) { array_push($exts, 'mailbox'); $args .= ' :create'; } // variables support in fileinto by David Warden if (preg_match('/\\$\\{\\d+\\}/', $action['target'])) { array_push($exts, 'variables'); } $actions .= RCUBE_SIEVE_INDENT . "fileinto" . $args . " \"" . $this->_escape_string($action['target']) . "\";" . RCUBE_SIEVE_NEWLINE; break; case 'redirect': case 'redirect_copy': $args = ''; if ($action['type'] == 'redirect_copy') { array_push($exts, 'copy'); $args .= ' :copy'; } $tokens = preg_split('/[,;\\s]/', $action['target']); foreach ($tokens as $email) { $actions .= RCUBE_SIEVE_INDENT . "redirect" . $args . " \"" . $this->_escape_string($email) . "\";" . RCUBE_SIEVE_NEWLINE; } break; case 'reject': case 'ereject': array_push($exts, $action['type']); if (strpos($action['target'], "\n") !== false) { $actions .= RCUBE_SIEVE_INDENT . $action['type'] . " text:" . RCUBE_SIEVE_NEWLINE . $action['target'] . RCUBE_SIEVE_NEWLINE . "." . RCUBE_SIEVE_NEWLINE . ";" . RCUBE_SIEVE_NEWLINE; } else { $actions .= RCUBE_SIEVE_INDENT . $action['type'] . " \"" . $this->_escape_string($action['target']) . "\";" . RCUBE_SIEVE_NEWLINE; } break; case 'vacation': array_push($exts, 'vacation'); $action['subject'] = $this->_escape_string($action['subject']); // // encoding subject header with mb_encode provides better results with asian characters // if (function_exists("mb_encode_mimeheader")) // { // mb_internal_encoding($action['charset']); // $action['subject'] = mb_encode_mimeheader($action['subject'], $action['charset'], 'Q'); // mb_internal_encoding(RCMAIL_CHARSET); // } // detect original recipient if ($action['from'] == 'auto' && strpos($variables, 'set "from"') === false) { array_push($exts, 'variables'); $variables .= 'set "from" "";' . RCUBE_SIEVE_NEWLINE; $variables .= 'if header :matches "to" "*" {' . RCUBE_SIEVE_NEWLINE; $variables .= RCUBE_SIEVE_INDENT . 'set "from" "${1}";' . RCUBE_SIEVE_NEWLINE; $variables .= '}' . RCUBE_SIEVE_NEWLINE; $action['from'] = "\${from}"; } // append original subject if ($action['origsubject'] == '1' && strpos($variables, 'set "subject"') === false) { array_push($exts, 'variables'); $variables .= 'set "subject" "";' . RCUBE_SIEVE_NEWLINE; $variables .= 'if header :matches "subject" "*" {' . RCUBE_SIEVE_NEWLINE; $variables .= RCUBE_SIEVE_INDENT . 'set "subject" "${1}";' . RCUBE_SIEVE_NEWLINE; $variables .= '}' . RCUBE_SIEVE_NEWLINE; $action['subject'] = trim($action['subject']); if (substr($action['subject'], -1, 1) != ":") { $action['subject'] .= ":"; } $action['subject'] .= " \${subject}"; } $actions .= RCUBE_SIEVE_INDENT . "vacation" . RCUBE_SIEVE_NEWLINE; $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":days " . $action['days'] . RCUBE_SIEVE_NEWLINE; if (!empty($action['addresses'])) { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":addresses [\"" . str_replace(",", "\",\"", $this->_escape_string($action['addresses'])) . "\"]" . RCUBE_SIEVE_NEWLINE; } if (!empty($action['subject'])) { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":subject \"" . $action['subject'] . "\"" . RCUBE_SIEVE_NEWLINE; } if (!empty($action['handle'])) { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":handle \"" . $this->_escape_string($action['handle']) . "\"" . RCUBE_SIEVE_NEWLINE; } if (!empty($action['from'])) { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":from \"" . $this->_escape_string($action['from']) . "\"" . RCUBE_SIEVE_NEWLINE; } if ($action['htmlmsg']) { $MAIL_MIME = new Mail_mime("\r\n"); $action['msg'] = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN">' . "\r\n<html><body>\r\n" . $action['msg'] . "\r\n</body></html>\r\n"; $MAIL_MIME->setHTMLBody($action['msg']); // add a plain text version of the e-mail as an alternative part. $h2t = new html2text($action['msg'], false, true, 0); $plainTextPart = $h2t->get_text(); if (!$plainTextPart) { // empty message body breaks attachment handling in drafts $plainTextPart = "\r\n"; } else { // make sure all line endings are CRLF (#1486712) $plainTextPart = preg_replace('/\\r?\\n/', "\r\n", $plainTextPart); } $MAIL_MIME->setTXTBody($plainTextPart); $MAIL_MIME->setParam('html_charset', $action['charset']); $MAIL_MIME->setParam('text_charset', $action['charset']); $action['msg'] = $MAIL_MIME->getMessage(); } // escape lines which start is a . $action['msg'] = preg_replace('/(^|\\r?\\n)\\./', "\$1..", $action['msg']); if ($action['htmlmsg']) { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":mime text:" . RCUBE_SIEVE_NEWLINE . $action['msg'] . RCUBE_SIEVE_NEWLINE . "." . RCUBE_SIEVE_NEWLINE . ";" . RCUBE_SIEVE_NEWLINE; } elseif ($action['charset'] != "UTF-8") { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":mime text:" . RCUBE_SIEVE_NEWLINE . "Content-Type: text/plain; charset=" . $action['charset'] . RCUBE_SIEVE_NEWLINE . RCUBE_SIEVE_NEWLINE . $action['msg'] . RCUBE_SIEVE_NEWLINE . "." . RCUBE_SIEVE_NEWLINE . ";" . RCUBE_SIEVE_NEWLINE; } elseif (strpos($action['msg'], "\n") !== false) { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . "text:" . RCUBE_SIEVE_NEWLINE . $action['msg'] . RCUBE_SIEVE_NEWLINE . "." . RCUBE_SIEVE_NEWLINE . ";" . RCUBE_SIEVE_NEWLINE; } else { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . "\"" . $this->_escape_string($action['msg']) . "\";" . RCUBE_SIEVE_NEWLINE; } break; case 'imapflags': case 'imap4flags': array_push($exts, $action['type']); if (strpos($actions, "setflag") !== false) { $actions .= RCUBE_SIEVE_INDENT . "addflag \"" . $this->_escape_string($action['target']) . "\";" . RCUBE_SIEVE_NEWLINE; } else { $actions .= RCUBE_SIEVE_INDENT . "setflag \"" . $this->_escape_string($action['target']) . "\";" . RCUBE_SIEVE_NEWLINE; } break; case 'notify': array_push($exts, 'notify'); $actions .= RCUBE_SIEVE_INDENT . "notify" . RCUBE_SIEVE_NEWLINE; $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":method \"" . $this->_escape_string($action['method']) . "\"" . RCUBE_SIEVE_NEWLINE; if (!empty($action['options'])) { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":options [\"" . str_replace(",", "\",\"", $this->_escape_string($action['options'])) . "\"]" . RCUBE_SIEVE_NEWLINE; } if (!empty($action['from'])) { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":from \"" . $this->_escape_string($action['from']) . "\"" . RCUBE_SIEVE_NEWLINE; } if (!empty($action['importance'])) { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":importance \"" . $this->_escape_string($action['importance']) . "\"" . RCUBE_SIEVE_NEWLINE; } $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":message \"" . $this->_escape_string($action['msg']) . "\";" . RCUBE_SIEVE_NEWLINE; break; case 'enotify': array_push($exts, 'enotify'); $actions .= RCUBE_SIEVE_INDENT . "notify" . RCUBE_SIEVE_NEWLINE; if (!empty($action['options'])) { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":options [\"" . str_replace(",", "\",\"", $this->_escape_string($action['options'])) . "\"]" . RCUBE_SIEVE_NEWLINE; } if (!empty($action['from'])) { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":from \"" . $this->_escape_string($action['from']) . "\"" . RCUBE_SIEVE_NEWLINE; } if (!empty($action['importance'])) { $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":importance \"" . $this->_escape_string($action['importance']) . "\"" . RCUBE_SIEVE_NEWLINE; } $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . ":message \"" . $this->_escape_string($action['msg']) . "\"" . RCUBE_SIEVE_NEWLINE; $actions .= RCUBE_SIEVE_INDENT . RCUBE_SIEVE_INDENT . "\"" . $this->_escape_string($action['method']) . "\";" . RCUBE_SIEVE_NEWLINE; break; case 'keep': case 'discard': case 'stop': $actions .= RCUBE_SIEVE_INDENT . $action['type'] . ";" . RCUBE_SIEVE_NEWLINE; break; } } $script .= $actions . "}" . RCUBE_SIEVE_NEWLINE; } } if ($variables) { $variables .= RCUBE_SIEVE_NEWLINE; } // requires $exts = array_unique($exts); if (sizeof($exts)) { $script = 'require ["' . implode('","', $exts) . "\"];" . RCUBE_SIEVE_NEWLINE . RCUBE_SIEVE_NEWLINE . $variables . $script; } // author if ($script && RCUBE_SIEVE_HEADER) { $script = RCUBE_SIEVE_HEADER . RCUBE_SIEVE_NEWLINE . $script; } return $script; }
/** * Remove attachments from a message */ function remove_attachments() { $rcmail = rcmail::get_instance(); $imap = $rcmail->storage; $MESSAGE = new rcube_message(get_input_value('_uid', RCUBE_INPUT_GET)); $headers = $this->_parse_headers($imap->get_raw_headers($MESSAGE->uid)); // set message charset as default if (!empty($MESSAGE->headers->charset)) { $imap->set_charset($MESSAGE->headers->charset); } // Remove old MIME headers unset($headers['MIME-Version']); unset($headers['Content-Type']); $MAIL_MIME = new Mail_mime($rcmail->config->header_delimiter()); $MAIL_MIME->headers($headers); if ($MESSAGE->has_html_part()) { $body = $MESSAGE->first_html_part(); $MAIL_MIME->setHTMLBody($body); } $body = $MESSAGE->first_text_part(); $MAIL_MIME->setTXTBody($body, false, true); foreach ($MESSAGE->attachments as $attachment) { if ($attachment->mime_id != get_input_value('_part', RCUBE_INPUT_GET) && get_input_value('_part', RCUBE_INPUT_GET) != '-1') { $MAIL_MIME->addAttachment($MESSAGE->get_part_content($attachment->mime_id), $attachment->mimetype, $attachment->filename, false, $attachment->encoding, $attachment->disposition, '', $attachment->charset); } } foreach ($MESSAGE->mime_parts as $attachment) { if (!empty($attachment->content_id)) { // covert CID to Mail_MIME format $attachment->content_id = str_replace('<', '', $attachment->content_id); $attachment->content_id = str_replace('>', '', $attachment->content_id); if (empty($attachment->filename)) { $attachment->filename = $attachment->content_id; } $MESSAGE_body = $MAIL_MIME->getHTMLBody(); $dispurl = 'cid:' . $attachment->content_id; $MESSAGE_body = str_replace($dispurl, $attachment->filename, $MESSAGE_body); $MAIL_MIME->setHTMLBody($MESSAGE_body); $MAIL_MIME->addHTMLImage($MESSAGE->get_part_content($attachment->mime_id), $attachment->mimetype, $attachment->filename, false); } } // encoding settings for mail composing $MAIL_MIME->setParam('head_encoding', $MESSAGE->headers->encoding); $MAIL_MIME->setParam('head_charset', $MESSAGE->headers->charset); foreach ($MESSAGE->mime_parts as $mime_id => $part) { $mimetype = strtolower($part->ctype_primary . '/' . $part->ctype_secondary); if ($mimetype == 'text/html') { $MAIL_MIME->setParam('text_encoding', $part->encoding); $MAIL_MIME->setParam('html_charset', $part->charset); } else { if ($mimetype == 'text/plain') { $MAIL_MIME->setParam('html_encoding', $part->encoding); $MAIL_MIME->setParam('text_charset', $part->charset); } } } $saved = $imap->save_message($_SESSION['mbox'], $MAIL_MIME->getMessage()); //write_log("debug","saved=".$saved); if ($saved) { $imap->delete_message($MESSAGE->uid); // Assume the one we just added has the highest UID //dsoares $uids = $imap->conn->fetchUIDs($imap->mod_mailbox($_SESSION['mbox'])); //dsoares $uid = end($uids); $uid = $saved; //dsoares // set flags foreach ($MESSAGE->headers->flags as $flag) { $imap->set_flag($uid, strtoupper($flag), $_SESSION['mbox']); } $this->api->output->command('display_message', $this->gettext('attachmentremoved'), 'confirmation'); $this->api->output->command('removeattachments_reload', $uid); } else { $this->api->output->command('display_message', $this->gettext('removefailed'), 'error'); } $this->api->output->send(); }