/** */ public function report(IMP_Contents $contents, $action) { global $injector, $registry; $imp_compose = $injector->getInstance('IMP_Factory_Compose')->create(); switch ($this->_format) { case 'redirect': /* Send the message. */ try { $imp_compose->redirectMessage($contents->getIndicesOb()); $imp_compose->sendRedirectMessage($this->_email, false); return true; } catch (IMP_Compose_Exception $e) { $e->log(); } break; case 'digest': default: try { $from_line = $injector->getInstance('IMP_Identity')->getFromLine(); } catch (Horde_Exception $e) { $from_line = null; } /* Build the MIME structure. */ $mime = new Horde_Mime_Part(); $mime->setType('multipart/digest'); $rfc822 = new Horde_Mime_Part(); $rfc822->setType('message/rfc822'); $rfc822->setContents($contents->fullMessageText(array('stream' => true))); $mime->addPart($rfc822); $spam_headers = new Horde_Mime_Headers(); $spam_headers->addMessageIdHeader(); $spam_headers->addHeader('Date', date('r')); $spam_headers->addHeader('To', $this->_email); if (!is_null($from_line)) { $spam_headers->addHeader('From', $from_line); } $spam_headers->addHeader('Subject', sprintf(_("%s report from %s"), $action == IMP_Spam::SPAM ? 'spam' : 'innocent', $registry->getAuth())); /* Send the message. */ try { $recip_list = $imp_compose->recipientList(array('to' => $this->_email)); $imp_compose->sendMessage($recip_list['list'], $spam_headers, $mime, 'UTF-8'); $rfc822->clearContents(); return true; } catch (IMP_Compose_Exception $e) { $e->log(); $rfc822->clearContents(); } break; } return false; }
/** * Determine the text and headers for a forwarded message. * * @param integer $type The forward type (self::FORWARD* * constant). * @param IMP_Contents $contents An IMP_Contents object. * @param boolean $attach Attach the forwarded message? * @param array $opts Additional options: * - format: (string) Force to this format. * DEFAULT: Auto-determine. * * @return array An array with the following keys: * - attach: (boolean) True if original message was attached. * - body: (string) The text of the body part. * - format: (string) The format of the body message ('html', 'text'). * - identity: (mixed) See IMP_Prefs_Identity#getMatchingIdentity(). * - subject: (string) Formatted subject. * - title: (string) Title to use on page. * - type: (integer) - The compose type. * @throws IMP_Exception */ public function forwardMessage($type, $contents, $attach = true, array $opts = array()) { global $prefs; if (!$contents instanceof IMP_Contents) { throw new IMP_Exception(_("Could not retrieve message data from the mail server.")); } if ($type == self::FORWARD_AUTO) { switch ($prefs->getValue('forward_default')) { case 'body': $type = self::FORWARD_BODY; break; case 'both': $type = self::FORWARD_BOTH; break; case 'editasnew': $ret = $this->editAsNew(new IMP_Indices($contents)); $ret['title'] = _("New Message"); return $ret; case 'attach': default: $type = self::FORWARD_ATTACH; break; } } $h = $contents->getHeader(); $this->_replytype = $type; $this->_setMetadata('indices', $contents->getIndicesOb()); if (strlen($s = $h['Subject'])) { $s = strval(new Horde_Imap_Client_Data_BaseSubject($s, array('keepblob' => true))); $subject = 'Fwd: ' . $s; $title = _("Forward") . ': ' . $s; } else { $subject = 'Fwd:'; $title = _("Forward"); } $fwd_attach = false; if ($attach && in_array($type, array(self::FORWARD_ATTACH, self::FORWARD_BOTH))) { try { $this->attachImapMessage(new IMP_Indices($contents)); $fwd_attach = true; } catch (IMP_Exception $e) { } } if (in_array($type, array(self::FORWARD_BODY, self::FORWARD_BOTH))) { $ret = $this->forwardMessageText($contents, array('format' => isset($opts['format']) ? $opts['format'] : null)); unset($ret['charset']); } else { $ret = array('body' => '', 'format' => $prefs->getValue('compose_html') ? 'html' : 'text'); } return array_merge(array('attach' => $fwd_attach, 'identity' => $this->_getMatchingIdentity($h), 'subject' => $subject, 'title' => $title, 'type' => $type), $ret); }