public function ham(&$uids, $mbox) { $rcmail = rcube::get_instance(); $storage = $rcmail->storage; $new_uids = array(); foreach ($uids as $uid) { $saved = false; $message = new rcube_message($uid); if (sizeof($message->attachments) > 0) { foreach ($message->attachments as $part) { if ($part->ctype_primary == 'message' && $part->ctype_secondary == 'rfc822' && $part->ctype_parameters['x-spam-type'] == 'original') { $orig_message_raw = $message->get_part_body($part->mime_id); $saved = $storage->save_message($mbox, $orig_message_raw); if ($saved !== false) { $rcmail->output->command('rcmail_markasjunk2_move', null, $uid); array_push($new_uids, $saved); } } } } } if (sizeof($new_uids) > 0) { $uids = $new_uids; } }
/** * Handler for keys/certs import request action */ function import_file() { $uid = rcube_utils::get_input_value('_uid', rcube_utils::INPUT_POST); $mbox = rcube_utils::get_input_value('_mbox', rcube_utils::INPUT_POST); $mime_id = rcube_utils::get_input_value('_part', rcube_utils::INPUT_POST); $storage = $this->rc->get_storage(); $engine = $this->enigma->load_engine(); if ($uid && $mime_id) { // Note: we get the attachment body via rcube_message class // to support keys inside encrypted messages (#5285) $message = new rcube_message($uid, $mbox); // Check if we don't need to ask for password again foreach ($engine->decryptions as $status) { if ($status instanceof enigma_error) { if ($status->getCode() == enigma_error::BADPASS) { $this->password_prompt($status, array('input_uid' => $uid, 'input_mbox' => $mbox, 'input_part' => $mime_id, 'input_task' => 'mail', 'input_action' => 'plugin.enigmaimport', 'action' => '?', 'iframe' => true)); $this->rc->output->send($this->rc->output->type == 'html' ? 'iframe' : null); return; } } } if ($engine->is_keys_part($message->mime_parts[$mime_id])) { $part = $message->get_part_body($mime_id); } } if ($part && is_array($result = $engine->import_key($part))) { $this->rc->output->show_message('enigma.keysimportsuccess', 'confirmation', array('new' => $result['imported'], 'old' => $result['unchanged'])); } else { $this->rc->output->show_message('enigma.keysimportfailed', 'error'); } $this->rc->output->send($this->rc->output->type == 'html' ? 'iframe' : null); }
/** * Handler for attachment download action */ public function download_attachments() { $rcmail = rcmail::get_instance(); $imap = $rcmail->get_storage(); $temp_dir = $rcmail->config->get('temp_dir'); $tmpfname = tempnam($temp_dir, 'zipdownload'); $tempfiles = array($tmpfname); $message = new rcube_message(rcube_utils::get_input_value('_uid', rcube_utils::INPUT_GET)); // open zip file $zip = new ZipArchive(); $zip->open($tmpfname, ZIPARCHIVE::OVERWRITE); foreach ($message->attachments as $part) { $pid = $part->mime_id; $part = $message->mime_parts[$pid]; $filename = $part->filename; if ($filename === null || $filename === '') { $ext = (array) rcube_mime::get_mime_extensions($part->mimetype); $ext = array_shift($ext); $filename = $rcmail->gettext('messagepart') . ' ' . $pid; if ($ext) { $filename .= '.' . $ext; } } $disp_name = $this->_convert_filename($filename); $tmpfn = tempnam($temp_dir, 'zipattach'); $tmpfp = fopen($tmpfn, 'w'); $tempfiles[] = $tmpfn; $message->get_part_body($part->mime_id, false, 0, $tmpfp); $zip->addFile($tmpfn, $disp_name); fclose($tmpfp); } $zip->close(); $filename = ($message->subject ? $message->subject : 'roundcube') . '.zip'; $this->_deliver_zipfile($tmpfname, $filename); // delete temporary files from disk foreach ($tempfiles as $tmpfn) { unlink($tmpfn); } exit; }
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']); } } } }