From 6c7664b79896caee6012439b445e98d8f0dff40b Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 24 Nov 2008 14:46:31 -0700 Subject: [PATCH] First attempt at Mime_Message->Mime_Part transition. --- imp/attachment.php | 2 +- imp/compose.php | 2 +- imp/lib/Compose.php | 419 +++++++++++++++++++--------------------- imp/lib/Contents.php | 27 +-- imp/lib/Mime/Viewer/itip.php | 4 +- imp/lib/Mime/Viewer/partial.php | 6 +- imp/lib/Mime/Viewer/pgp.php | 2 +- imp/lib/Mime/Viewer/plain.php | 12 +- imp/lib/Spam.php | 2 +- 9 files changed, 225 insertions(+), 251 deletions(-) diff --git a/imp/attachment.php b/imp/attachment.php index e7cf0c1f2..0961a4cf7 100644 --- a/imp/attachment.php +++ b/imp/attachment.php @@ -103,7 +103,7 @@ if ($conf['compose']['link_attachments_notify']) { $msg_headers->addHeader('To', $mail_address_full); $msg_headers->addHeader('Subject', _("Notification: Linked attachment downloaded")); - $msg = new Horde_Mime_Message(); + $msg = new Horde_Mime_Part(); $msg->setType('text/plain'); $msg->setCharset(NLS::getCharset()); $msg->setContents(String::wrap(sprintf(_("Your linked attachment has been downloaded by at least one user.\n\nAttachment name: %s\nAttachment date: %s\n\nClick on the following link to permanently delete the attachment:\n%s"), $file_name, date('r', $time_stamp), Util::addParameter(Horde::selfUrl(true, false, true), 'd', $id)))); diff --git a/imp/compose.php b/imp/compose.php index 8f926551c..5dc9ec349 100644 --- a/imp/compose.php +++ b/imp/compose.php @@ -1236,7 +1236,7 @@ if ($redirect) { $t->set('numberattach', $imp_compose->numberOfAttachments()); if ($t->get('numberattach')) { require_once IMP_BASE . '/lib/MIME/Contents.php'; - $imp_contents = new IMP_Contents(new Horde_Mime_Message()); + $imp_contents = new IMP_Contents(new Horde_Mime_Part()); $atc = array(); $disp_num = 0; diff --git a/imp/lib/Compose.php b/imp/lib/Compose.php index ca562ad85..d3bc51cfa 100644 --- a/imp/lib/Compose.php +++ b/imp/lib/Compose.php @@ -133,7 +133,7 @@ class IMP_Compose * * @param array $header List of message headers. * @param mixed $message Either the message text (string) or a - * Horde_Mime_Message object that contains the + * Horde_Mime_Part object that contains the * text to send. * @param string $charset The charset that was used for the headers. * @param boolean $html Whether this is an HTML message. @@ -158,7 +158,7 @@ class IMP_Compose * * @param array $headers List of message headers. * @param mixed $message Either the message text (string) or a - * Horde_Mime_Message object that contains the + * Horde_Mime_Part object that contains the * text to send. * @param string $charset The charset that was used for the headers. * @param boolean $html Whether this is an HTML message. @@ -170,14 +170,12 @@ class IMP_Compose $session) { /* Set up the base message now. */ - $mime = new Horde_Mime_Message(); - $body = $this->getMessageBody($message, $charset, $html, array('nofinal' => true, 'noattach' => !$session)); - if (is_a($body, 'PEAR_Error')) { - return $body; + $mime = $this->_createMimeMessage(array(null), $message, $charset, array('html' => $html, 'nofinal' => true, 'noattach' => !$session)); + if (is_a($mime, 'PEAR_Error')) { + return $mime; } - - $mime->addPart($body); - $body = $mime->toString(); + $base = $mime['msg']; + $base->isBasePart(true); /* Initalize a header object for the draft. */ $draft_headers = new Horde_Mime_Headers(); @@ -207,7 +205,7 @@ class IMP_Compose $draft_headers->addMessageIdHeader(); $draft_headers = $mime->addMimeHeaders($draft_headers); - return $draft_headers->toString(array('charset' => $charset, 'defserver' => $session ? $_SESSION['imp']['maildomain'] : null)) . $body; + return $draft_headers->toString(array('charset' => $charset, 'defserver' => $session ? $_SESSION['imp']['maildomain'] : null)) . $base->toString(false); } /** @@ -325,162 +323,11 @@ class IMP_Compose ); } - /** - * Gets the message body and sets up the MIME parts. - * - * @param string $message The raw message body. - * @param string $charset The charset to use. - * @param boolean $html Whether this is an HTML message. - * @param array $options Additional options: - *
-     * 'nofinal' - (boolean) This is not a message which will be sent out.
-     * 'noattach' - (boolean) Don't add attachment information.
-     * 
- * - * @return Horde_Mime_Part The body as a MIME object, or PEAR_Error on - * error. - */ - public function getMessageBody($message, $charset, $html, - $options = array()) - { - $message = String::convertCharset($message, NLS::getCharset(), $charset); - - if ($html) { - $message_html = $message; - require_once 'Horde/Text/Filter.php'; - $message = Text_Filter::filter($message, 'html2text', array('wrap' => false, 'charset' => $charset)); - } - - /* Get trailer message (if any). */ - $trailer = $trailer_file = null; - if (empty($options['nofinal']) && - $GLOBALS['conf']['msg']['append_trailer']) { - if (empty($GLOBALS['conf']['vhosts'])) { - if (is_readable(IMP_BASE . '/config/trailer.txt')) { - $trailer_file = IMP_BASE . '/config/trailer.txt'; - } - } elseif (is_readable(IMP_BASE . '/config/trailer-' . $GLOBALS['conf']['server']['name'] . '.txt')) { - $trailer_file = IMP_BASE . '/config/trailer-' . $GLOBALS['conf']['server']['name'] . '.txt'; - } - - if (!empty($trailer_file)) { - require_once 'Horde/Text/Filter.php'; - $trailer = Text_Filter::filter("\n" . file_get_contents($trailer_file), 'environment'); - /* If there is a user defined function, call it with the - * current trailer as an argument. */ - if (!empty($GLOBALS['conf']['hooks']['trailer'])) { - $trailer = Horde::callHook('_imp_hook_trailer', array($trailer), 'imp'); - } - - $message .= $trailer; - if ($html) { - $message .= $this->text2html($trailer); - } - } - } - - /* Set up the body part now. */ - $textBody = new Horde_Mime_Part(); - $textBody->setType('text/plain'); - $textBody->setCharset($charset); - $htmlBody->setDisposition('inline'); - - /* Send in flowed format. */ - require_once 'Text/Flowed.php'; - $flowed = new Text_Flowed($message, $charset); - $flowed->setDelSp(true); - $textBody->setContentTypeParameter('format', 'flowed'); - $textBody->setContentTypeParameter('DelSp', 'Yes'); - $textBody->setContents($flowed->toFlowed()); - - /* Determine whether or not to send a multipart/alternative - * message with an HTML part. */ - if ($html) { - $htmlBody = new Horde_Mime_Part(); - $htmlBody->setType('text/html'); - $htmlBody->setCharset($charset); - $htmlBody->setDisposition('inline'); - $htmlBody->setDescription(String::convertCharset(_("HTML Version of Message"), NLS::getCharset(), $charset)); - - /* Run tidy on the HTML, if available. */ - if ($tidy_config = IMP::getTidyConfig(strlen($message_html))) { - $tidy = tidy_parse_string(String::convertCharset($message_html, $charset, 'UTF-8'), $tidy_config, 'utf8'); - $tidy->cleanRepair(); - $htmlBody->setContents(String::convertCharset(tidy_get_output($tidy), 'UTF-8', $charset)); - } else { - $htmlBody->setContents($message_html); - } - - $textBody->setDescription(String::convertCharset(_("Plaintext Version of Message"), NLS::getCharset(), $charset)); - - $basepart = new Horde_Mime_Part(); - $basepart->setType('multipart/alternative'); - $basepart->addPart($textBody); - - if (empty($options['nofinal'])) { - /* Any image links will be downloaded and appended to the - * message body. */ - $basepart->addPart($this->_convertToMultipartRelated($htmlBody)); - } else { - $basepart->addPart($htmlBody); - } - } else { - $basepart = $textBody; - } - - /* Add attachments now. */ - $attach_flag = true; - if (empty($options['noattach']) && $this->numberOfAttachments()) { - if (($this->_linkAttach && - $GLOBALS['conf']['compose']['link_attachments']) || - !empty($GLOBALS['conf']['compose']['link_all_attachments'])) { - $body = $this->linkAttachments(Horde::applicationUrl('attachment.php', true), $basepart, Auth::getAuth()); - if (is_a($body, 'PEAR_Error')) { - return $body; - } - - if ($this->_pgpAttachPubkey || $this->_attachVCard) { - $new_body = new Horde_Mime_Part(); - $new_body->setType('multipart/mixed'); - $new_body->addPart($body); - $body = $new_body; - } else { - $attach_flag = false; - } - } else { - $body = new Horde_Mime_Part(); - $body->setType('multipart/mixed'); - $body->addPart($basepart); - foreach (array_keys($this->_cache) as $id) { - $body->addPart($this->buildAttachment($id)); - } - } - } elseif ($this->_pgpAttachPubkey || $this->_attachVCard) { - $body = new Horde_Mime_Part('multipart/mixed'); - $body->addPart($basepart); - } else { - $body = $basepart; - $attach_flag = false; - } - - if ($attach_flag) { - if ($this->_pgpAttachPubkey) { - $imp_pgp = &Horde_Crypt::singleton(array('imp', 'pgp')); - $body->addPart($imp_pgp->publicKeyMIMEPart()); - } - - if ($this->_attachVCard) { - $body->addPart($this->_attachVCard); - } - } - - return $body; - } /** * Builds and sends a MIME message. * - * @param string $message The message body. + * @param string $body The message body. * @param array $header List of message headers. * @param string $charset The sending charset. * @param boolean $html Whether this is an HTML message. @@ -504,7 +351,7 @@ class IMP_Compose * @return boolean Whether the sent message has been saved in the * sent-mail folder, or a PEAR_Error on failure. */ - public function buildAndSendMessage($message, $header, $charset, $html, + public function buildAndSendMessage($body, $header, $charset, $html, $opts = array()) { global $conf, $notification, $prefs, $registry; @@ -517,28 +364,24 @@ class IMP_Compose } $header = array_merge($header, $recip['header']); - $barefrom = Horde_IMAP_Address::bareAddress($header['from'], $_SESSION['imp']['maildomain']); - $recipients = implode(', ', $recip['list']); - - /* Set up the base message now. */ - $body = $this->getMessageBody($message, $charset, $html); - if (is_a($body, 'PEAR_Error')) { - return $body; - } - + $barefrom = Horde_Mime_Address::bareAddress($header['from'], $_SESSION['imp']['maildomain']); $encrypt = empty($opts['encrypt']) ? 0 : $opts['encrypt']; + $recipients = implode(', ', $recip['list']); /* Prepare the array of messages to send out. May be more * than one if we are encrypting for multiple recipients or * are storing an encrypted message locally. */ $send_msgs = array(); + $msg_options = array( + 'encrypt' => $encrypt, + 'html' => $html + ); /* Must encrypt & send the message one recipient at a time. */ - if (!empty($encrypt) && - $prefs->getValue('use_smime') && + if ($prefs->getValue('use_smime') && in_array($encrypt, array(IMP::SMIME_ENCRYPT, IMP::SMIME_SIGNENC))) { foreach ($recip['list'] as $val) { - $res = $this->_createMimeMessage(array($val), $body, $encrypt); + $res = $this->_createMimeMessage(array($val), $body, $charset, $msg_options); if (is_a($res, 'PEAR_Error')) { return $res; } @@ -547,11 +390,12 @@ class IMP_Compose /* Must target the encryption for the sender before saving message * in sent-mail. */ - $save_msg = $this->_createMimeMessage(array($header['from']), $body, $encrypt); + $save_msg = $this->_createMimeMessage(array($header['from']), $body, $charset, $msg_options); } else { /* Can send in clear-text all at once, or PGP can encrypt * multiple addresses in the same message. */ - $send_msgs[] = $save_msg = $this->_createMimeMessage($recip['list'], $body, $encrypt, $barefrom); + $msg_options['from'] = $barefrom; + $send_msgs[] = $save_msg = $this->_createMimeMessage($recip['list'], $body, $charset, $msg_options); } if (is_a($save_msg, 'PEAR_Error')) { @@ -641,13 +485,13 @@ class IMP_Compose /* Tack on any site-specific headers. */ $headers_result = Horde::loadConfiguration('header.php', '_header'); if (!is_a($headers_result, 'PEAR_Error')) { - foreach ($result as $key => $val) { + foreach ($headers_result as $key => $val) { $headers->addHeader(trim($key), String::convertCharset(trim($val), NLS::getCharset(), $charset)); } } /* Send the messages out now. */ - foreach ($messagesToSend as $val) { + foreach ($send_msgs as $val) { $res = $this->sendMessage($val['to'], $headers, $val['msg'], $charset); if (is_a($res, 'PEAR_Error')) { /* Unsuccessful send. */ @@ -690,8 +534,7 @@ class IMP_Compose ($prefs->isLocked('save_sent_mail') && $prefs->getValue('save_sent_mail')))) { - $mime_message = $messageToSave['msg']; - $headers = $mime_message->addMimeHeaders($headers); + $mime_message = $save_msg['msg']; /* Keep Bcc: headers on saved messages. */ if (!empty($header['bcc'])) { @@ -718,7 +561,7 @@ class IMP_Compose } /* Add the body text to the message string. */ - $fcc .= $mime_message->toString(); + $fcc .= $mime_message->toString(false); $imp_folder = &IMP_Folder::singleton(); @@ -742,7 +585,7 @@ class IMP_Compose /* Call post-sent hook. */ if (!empty($conf['hooks']['postsent'])) { - Horde::callHook('_imp_hook_postsent', array($messageToSave['msg'], $msg_headers), 'imp', null); + Horde::callHook('_imp_hook_postsent', array($save_msg['msg'], $msg_headers), 'imp', null); } return $sent_saved; @@ -754,8 +597,7 @@ class IMP_Compose * @param string $email The e-mail list to send to. * @param Horde_Mime_Headers $headers The object holding this message's * headers. - * @param mixed $message Either the message text (string) or - * a Horde_Mime_Message object that + * @param Horde_Mime_Part $message The Horde_Mime_Part object that * contains the text to send. * @param string $charset The charset that was used for the * headers. @@ -790,11 +632,11 @@ class IMP_Compose $recipients += isset($address['grounpname']) ? count($address['addresses']) : 1; } if ($recipients > $timelimit) { - $message = @htmlspecialchars(sprintf(_("You are not allowed to send messages to more than %d recipients within %d hours."), $timelimit, $conf['sentmail']['params']['limit_period']), ENT_COMPAT, NLS::getCharset()); + $error = @htmlspecialchars(sprintf(_("You are not allowed to send messages to more than %d recipients within %d hours."), $timelimit, $conf['sentmail']['params']['limit_period']), ENT_COMPAT, NLS::getCharset()); if (!empty($conf['hooks']['permsdenied'])) { - $message = Horde::callHook('_perms_hook_denied', array('imp:max_timelimit'), 'horde', $message); + $error = Horde::callHook('_perms_hook_denied', array('imp:max_timelimit'), 'horde', $error); } - return PEAR::raiseError($message); + return PEAR::raiseError($error); } } @@ -820,12 +662,7 @@ class IMP_Compose $params['password'] = Secret::read(IMP::getAuthKey(), $_SESSION['imp']['pass']); } - /* If $message is a string, create a Horde_Mime_Message object. */ - if (is_string($message)) { - $mime_message = Horde_Mime_Message::parseMessage($message); - } - - return $mime_message->send($email, $headerArray, $conf['mailer']['type'], $params); + return $message->send($email, $headers, $conf['mailer']['type'], $params); } /** @@ -1015,20 +852,160 @@ class IMP_Compose } /** - * Create the base Horde_Mime_Message for sending. + * Create the base Horde_Mime_Part for sending. * - * @param array $to The recipient list. - * @param string $body Message body. - * @param integer $encrypt The encryption flag. - * @param string $from The outgoing from address - only define if - * using multiple PGP encryption. + * @param array $to The recipient list. + * @param string $body Message body. + * @param string $charset The charset of the message body. + * @param array $options Additional options: + *
+     * 'encrypt' - (integer) The encryption flag.
+     * 'from' - (string) The outgoing from address - only needed for multiple
+     *          PGP encryption.
+     * 'html' - (boolean) Is this a HTML message?
+     * 'nofinal' - (boolean) This is not a message which will be sent out.
+     * 'noattach' - (boolean) Don't add attachment information.
+     * 
* - * @return mixed Array containing MIME message and recipients or - * PEAR_Error on error. + * @return mixed PEAR_Error on error or TODO. */ - protected function _createMimeMessage($to, $body, $encrypt, $from = null) + protected function _createMimeMessage($to, $body, $charset, + $options = array()) { + $nls_charset = NLS::getCharset(); + $body = String::convertCharset($body, $nls_charset, $charset); + + if (!empty($options['html'])) { + $body_html = $body; + require_once 'Horde/Text/Filter.php'; + $body = Text_Filter::filter($body, 'html2text', array('wrap' => false, 'charset' => $charset)); + } + + /* Get trailer message (if any). */ + $trailer = $trailer_file = null; + if (empty($options['nofinal']) && + $GLOBALS['conf']['msg']['append_trailer']) { + if (empty($GLOBALS['conf']['vhosts'])) { + if (is_readable(IMP_BASE . '/config/trailer.txt')) { + $trailer_file = IMP_BASE . '/config/trailer.txt'; + } + } elseif (is_readable(IMP_BASE . '/config/trailer-' . $GLOBALS['conf']['server']['name'] . '.txt')) { + $trailer_file = IMP_BASE . '/config/trailer-' . $GLOBALS['conf']['server']['name'] . '.txt'; + } + + if (!empty($trailer_file)) { + require_once 'Horde/Text/Filter.php'; + $trailer = Text_Filter::filter("\n" . file_get_contents($trailer_file), 'environment'); + /* If there is a user defined function, call it with the + * current trailer as an argument. */ + if (!empty($GLOBALS['conf']['hooks']['trailer'])) { + $trailer = Horde::callHook('_imp_hook_trailer', array($trailer), 'imp'); + } + + $body .= $trailer; + if (!empty($options['html'])) { + $body_html .= $this->text2html($trailer); + } + } + } + + /* Set up the body part now. */ + $textBody = new Horde_Mime_Part(); + $textBody->setType('text/plain'); + $textBody->setCharset($charset); + $textBody->setDisposition('inline'); + + /* Send in flowed format. */ + require_once 'Text/Flowed.php'; + $flowed = new Text_Flowed($body, $charset); + $flowed->setDelSp(true); + $textBody->setContentTypeParameter('format', 'flowed'); + $textBody->setContentTypeParameter('DelSp', 'Yes'); + $textBody->setContents($flowed->toFlowed()); + + /* Determine whether or not to send a multipart/alternative + * message with an HTML part. */ + if (!empty($options['html'])) { + $htmlBody = new Horde_Mime_Part(); + $htmlBody->setType('text/html'); + $htmlBody->setCharset($charset); + $htmlBody->setDisposition('inline'); + $htmlBody->setDescription(String::convertCharset(_("HTML Version of Message"), $nls_charset, $charset)); + + /* Run tidy on the HTML, if available. */ + if ($tidy_config = IMP::getTidyConfig(strlen($body_html))) { + $tidy = tidy_parse_string(String::convertCharset($body_html, $charset, 'UTF-8'), $tidy_config, 'utf8'); + $tidy->cleanRepair(); + $htmlBody->setContents(String::convertCharset(tidy_get_output($tidy), 'UTF-8', $charset)); + } else { + $htmlBody->setContents($body_html); + } + + $textBody->setDescription(String::convertCharset(_("Plaintext Version of Message"), $nls_charset, $charset)); + + $textpart = new Horde_Mime_Part(); + $textpart->setType('multipart/alternative'); + $textpart->addPart($textBody); + + if (empty($options['nofinal'])) { + /* Any image links will be downloaded and appended to the + * message body. */ + $textpart->addPart($this->_convertToMultipartRelated($htmlBody)); + } else { + $textpart->addPart($htmlBody); + } + } else { + $textpart = $textBody; + } + + /* Add attachments now. */ + $attach_flag = true; + if (empty($options['noattach']) && $this->numberOfAttachments()) { + if (($this->_linkAttach && + $GLOBALS['conf']['compose']['link_attachments']) || + !empty($GLOBALS['conf']['compose']['link_all_attachments'])) { + $base = $this->linkAttachments(Horde::applicationUrl('attachment.php', true), $textpart, Auth::getAuth()); + if (is_a($base, 'PEAR_Error')) { + return $base; + } + + if ($this->_pgpAttachPubkey || $this->_attachVCard) { + $new_body = new Horde_Mime_Part(); + $new_body->setType('multipart/mixed'); + $new_body->addPart($base); + $base = $new_body; + } else { + $attach_flag = false; + } + } else { + $base = new Horde_Mime_Part(); + $base->setType('multipart/mixed'); + $base->addPart($textpart); + foreach (array_keys($this->_cache) as $id) { + $base->addPart($this->buildAttachment($id)); + } + } + } elseif ($this->_pgpAttachPubkey || $this->_attachVCard) { + $base = new Horde_Mime_Part('multipart/mixed'); + $base->addPart($textpart); + } else { + $base = $textpart; + $attach_flag = false; + } + + if ($attach_flag) { + if ($this->_pgpAttachPubkey) { + $imp_pgp = &Horde_Crypt::singleton(array('imp', 'pgp')); + $base->addPart($imp_pgp->publicKeyMIMEPart()); + } + + if ($this->_attachVCard) { + $base->addPart($this->_attachVCard); + } + } + /* Set up the base message now. */ + $encrypt = empty($options['encrypt']) ? 0 : $options['encrypt']; if ($GLOBALS['prefs']->getValue('use_pgp') && !empty($GLOBALS['conf']['utils']['gnupg']) && in_array($encrypt, array(IMP::PGP_ENCRYPT, IMP::PGP_SIGN, IMP::PGP_SIGNENC, IMP::PGP_SYM_ENCRYPT, IMP::PGP_SYM_SIGNENC))) { @@ -1059,15 +1036,15 @@ class IMP_Compose /* Do the encryption/signing requested. */ switch ($encrypt) { case IMP::PGP_SIGN: - $body = $imp_pgp->IMPsignMIMEPart($body); + $base = $imp_pgp->IMPsignMIMEPart($base); break; case IMP::PGP_ENCRYPT: case IMP::PGP_SYM_ENCRYPT: - $to_list = is_null($from) + $to_list = empty($options['from']) ? $to - : array_keys(array_flip(array_merge($to, array($from)))); - $body = $imp_pgp->IMPencryptMIMEPart($body, $to_list, $encrypt == IMP::PGP_SYM_ENCRYPT); + : array_keys(array_flip(array_merge($to, array($options['from'])))); + $base = $imp_pgp->IMPencryptMIMEPart($base, $to_list, $encrypt == IMP::PGP_SYM_ENCRYPT); if ($encrypt == IMP::PGP_SYM_ENCRYPT) { $imp_pgp->unsetSymmetricPassphrase(); } @@ -1075,10 +1052,10 @@ class IMP_Compose case IMP::PGP_SIGNENC: case IMP::PGP_SYM_SIGNENC: - $to_list = is_null($from) + $to_list = empty($options['from']) ? $to - : array_keys(array_flip(array_merge($to, array($from)))); - $body = $imp_pgp->IMPsignAndEncryptMIMEPart($body, $to_list, $encrypt == IMP::PGP_SYM_SIGNENC); + : array_keys(array_flip(array_merge($to, array($options['from'])))); + $base = $imp_pgp->IMPsignAndEncryptMIMEPart($base, $to_list, $encrypt == IMP::PGP_SYM_SIGNENC); if ($encrypt == IMP::PGP_SYM_SIGNENC) { $imp_pgp->unsetSymmetricPassphrase(); } @@ -1086,8 +1063,8 @@ class IMP_Compose } /* Check for errors. */ - if (is_a($body, 'PEAR_Error')) { - return PEAR::raiseError(_("PGP Error: ") . $body->getMessage()); + if (is_a($base, 'PEAR_Error')) { + return PEAR::raiseError(_("PGP Error: ") . $base->getMessage()); } } elseif ($GLOBALS['prefs']->getValue('use_smime') && in_array($encrypt, array(IMP::SMIME_ENCRYPT, IMP::SMIME_SIGN, IMP::SMIME_SIGNENC))) { @@ -1104,31 +1081,29 @@ class IMP_Compose /* Do the encryption/signing requested. */ switch ($encrypt) { case IMP::SMIME_SIGN: - $body = $imp_smime->IMPsignMIMEPart($body); + $base = $imp_smime->IMPsignMIMEPart($base); break; case IMP::SMIME_ENCRYPT: - $body = $imp_smime->IMPencryptMIMEPart($body, $to[0]); + $base = $imp_smime->IMPencryptMIMEPart($base, $to[0]); break; case IMP::SMIME_SIGNENC: - $body = $imp_smime->IMPsignAndEncryptMIMEPart($body, $to[0]); + $base = $imp_smime->IMPsignAndEncryptMIMEPart($base, $to[0]); break; } /* Check for errors. */ - if (is_a($body, 'PEAR_Error')) { - return PEAR::raiseError(_("S/MIME Error: ") . $body->getMessage()); + if (is_a($base, 'PEAR_Error')) { + return PEAR::raiseError(_("S/MIME Error: ") . $base->getMessage()); } } - /* Add data to Horde_Mime_Message object. */ - $mime_message = new Horde_Mime_Message(); - $body->setMIMEId(0); - $mime_message->addPart($body); + /* Flag this as the base part. */ + $base->isBasePart(true); return array( - 'msg' => $mime_message, + 'msg' => $base, 'recipients' => $to, 'to' => implode(', ', $to) ); diff --git a/imp/lib/Contents.php b/imp/lib/Contents.php index 48b75b9d8..78899a307 100644 --- a/imp/lib/Contents.php +++ b/imp/lib/Contents.php @@ -46,9 +46,9 @@ class IMP_Contents protected $_mailbox = null; /** - * The Horde_Mime_Message object for the message. + * The Horde_Mime_Part object for the message. * - * @var Horde_Mime_Message + * @var Horde_Mime_Part */ protected $_message; @@ -70,7 +70,7 @@ class IMP_Contents * $imp_contents = &IMP_Contents::singleton($in); * * @param mixed $in Either an index string (see IMP_Contents::singleton() - * for the format) or a Horde_Mime_Message object. + * for the format) or a Horde_Mime_Part object. * * @return IMP_Contents The IMP_Contents object or null. */ @@ -78,7 +78,7 @@ class IMP_Contents { static $instance = array(); - $sig = is_a($in, 'Horde_Mime_Message') + $sig = is_a($in, 'Horde_Mime_Part') ? md5(serialize($in)) : $in; @@ -93,16 +93,16 @@ class IMP_Contents * Constructor. * * @param mixed $in Either an index string (see IMP_Contents::singleton() - * for the format) or a Horde_Mime_Message object. + * for the format) or a Horde_Mime_Part object. */ function __construct($in) { - if (is_a($in, 'Horde_Mime_Message')) { + if (is_a($in, 'Horde_Mime_Part')) { $this->_message = $in; } else { list($this->_index, $this->_mailbox) = explode(IMP::IDX_SEP, $in); - /* Get the Horde_Mime_Message object for the given index. */ + /* Get the Horde_Mime_Part object for the given index. */ try { $ret = $GLOBALS['imp_imap']->ob->fetch($this->_mailbox, array( Horde_Imap_Client::FETCH_STRUCTURE => array('parse' => true) @@ -238,9 +238,9 @@ class IMP_Contents } /** - * Returns the Horde_Mime_Message object. + * Returns the Horde_Mime_Part object. * - * @return Horde_Mime_Message A Horde_Mime_Message object. + * @return Horde_Mime_Part A Horde_Mime_Part object. */ public function getMIMEMessage() { @@ -698,7 +698,7 @@ class IMP_Contents } /** - * Builds the "virtual" Horde_Mime_Message object by checking for embedded + * Builds the "virtual" Horde_Mime_Part object by checking for embedded * parts. * * @param array $parts The parts list to process. @@ -711,6 +711,9 @@ class IMP_Contents } $this->_build = true; $parts = array_keys($this->_message->contentTypeMap()); + $first_id = reset($parts); + } else { + $first_id = null; } $last_id = null; @@ -732,8 +735,8 @@ class IMP_Contents $viewer->setParams(array('contents' => &$this)); $new_parts = $viewer->getEmbeddedMimeParts(); if (!is_null($new_parts)) { - foreach (array_keys($new_parts) as $val) { - if (is_a($new_parts[$val], 'Horde_Mime_Message')) { + foreach (array_keys($new_parts) as $key => $val) { + if ($first_id === $key) { $this->_message = $new_parts[$val]; $this->_build = false; return $this->_buildMessage(); diff --git a/imp/lib/Mime/Viewer/itip.php b/imp/lib/Mime/Viewer/itip.php index 098e962d4..ae5c67a46 100644 --- a/imp/lib/Mime/Viewer/itip.php +++ b/imp/lib/Mime/Viewer/itip.php @@ -287,7 +287,7 @@ class IMP_Horde_Mime_Viewer_itip extends Horde_Mime_Viewer_Driver $vEvent_reply->setAttribute('ATTENDEE', 'mailto:' . $email, $params); $vCal->addComponent($vEvent_reply); - $mime = new Horde_Mime_Message(); + $mime = new Horde_Mime_Part(); $mime->setType('multipart/alternative'); $body = new Horde_Mime_Part(); @@ -392,7 +392,7 @@ class IMP_Horde_Mime_Viewer_itip extends Horde_Mime_Viewer_Driver $vCal->setAttribute('METHOD', 'REPLY'); $vCal->addComponent($vfb_reply); - $mime = new Horde_Mime_Message(); + $mime = new Horde_Mime_Part(); $message = _("Attached is a reply to a calendar request you sent."); $body = new Horde_Mime_Part('text/plain', String::wrap($message, 76, "\n"), diff --git a/imp/lib/Mime/Viewer/partial.php b/imp/lib/Mime/Viewer/partial.php index 5af624409..fe68c247e 100644 --- a/imp/lib/Mime/Viewer/partial.php +++ b/imp/lib/Mime/Viewer/partial.php @@ -75,9 +75,9 @@ class IMP_Horde_Mime_Viewer_partial extends Horde_Mime_Viewer_Driver ksort($parts, SORT_NUMERIC); /* Combine the parts. */ - $mime_message = Horde_Mime_Message::parseMessage(implode('', $parts)); - return ($mime_message === false) + $mime_part = Horde_Mime_Part::parseMessage(implode('', $parts)); + return ($mime_part === false) ? null - : array($id => $mime_message); + : array($id => $mime_part); } } diff --git a/imp/lib/Mime/Viewer/pgp.php b/imp/lib/Mime/Viewer/pgp.php index 2481cc594..94fcba46a 100644 --- a/imp/lib/Mime/Viewer/pgp.php +++ b/imp/lib/Mime/Viewer/pgp.php @@ -204,7 +204,7 @@ class IMP_Horde_Mime_Viewer_pgp extends Horde_Mime_Viewer_Driver unset(self::$_inlinecache[$base_id][$data_id]); $this->_imppgp->unsetSymmetricPassphrase(); - return array($data_id => Horde_Mime_Message::parseMessage($decrypted_data->message, array('mimepart' => true))); + return array($data_id => Horde_Mime_Part::parseMessage($decrypted_data->message)); } /** diff --git a/imp/lib/Mime/Viewer/plain.php b/imp/lib/Mime/Viewer/plain.php index 7880a5234..e07e7e626 100644 --- a/imp/lib/Mime/Viewer/plain.php +++ b/imp/lib/Mime/Viewer/plain.php @@ -163,9 +163,7 @@ class IMP_Horde_Mime_Viewer_plain extends Horde_Mime_Viewer_plain return null; } - $new_part = is_a($this->_mimepart, 'Horde_Mime_Message') - ? new Horde_Mime_Message() - : new Horde_Mime_Part(); + $new_part = new Horde_Mime_Part(); $new_part->setType('multipart/mixed'); $charset = $this->_mimepart->getCharset(); $mime_id = $this->_mimepart->getMimeId(); @@ -236,7 +234,7 @@ class IMP_Horde_Mime_Viewer_plain extends Horde_Mime_Viewer_plain } } - $new_part->buildMimeIds(is_a($new_part, 'Horde_Mime_Message') ? null : $mime_id); + $new_part->setMimeId($mime_id); return array($mime_id => $new_part); } @@ -253,9 +251,7 @@ class IMP_Horde_Mime_Viewer_plain extends Horde_Mime_Viewer_plain return null; } - $new_part = is_a($this->_mimepart, 'Horde_Mime_Message') - ? new Horde_Mime_Message() - : new Horde_Mime_Part(); + $new_part = new Horde_Mime_Part(); $new_part->setType('multipart/mixed'); $mime_id = $this->_mimepart->getMimeId(); @@ -274,7 +270,7 @@ class IMP_Horde_Mime_Viewer_plain extends Horde_Mime_Viewer_plain $new_part->addPart($uupart); } - $new_part->buildMimeIds(is_a($new_part, 'Horde_Mime_Message') ? null : $mime_id); + $new_part->setMimeId($mime_id); return array($mime_id => $new_part); } diff --git a/imp/lib/Spam.php b/imp/lib/Spam.php index 2136f5e03..5d8f6c78c 100644 --- a/imp/lib/Spam.php +++ b/imp/lib/Spam.php @@ -240,7 +240,7 @@ class IMP_Spam protected function _sendSpamReportMessage($action, $data) { /* Build the MIME structure. */ - $mime = new Horde_Mime_Message(); + $mime = new Horde_Mime_Part(); $mime->setType('multipart/digest'); $rfc822 = new Horde_Mime_Part(); -- 2.11.0