setContents() public method

Set the body contents of this part.
public setContents ( mixed $contents, array $options = [] )
$contents mixed The part body. Either a string or a stream resource, or an array containing both.
$options array Additional options: - encoding: (string) The encoding of $contents. DEFAULT: Current transfer encoding value. - usestream: (boolean) If $contents is a stream, should we directly use that stream? DEFAULT: $contents copied to a new stream.
Exemplo n.º 1
0
 /**
  * Sends a message to an email address supposed to be added to the
  * identity.
  *
  * A message is send to this address containing a time-sensitive link to
  * confirm that the address really belongs to that user.
  *
  * @param integer $id       The identity's ID.
  * @param string $old_addr  The old From: address.
  *
  * @throws Horde_Mime_Exception
  */
 public function verifyIdentity($id, $old_addr)
 {
     global $injector, $notification, $registry;
     $hash = strval(new Horde_Support_Randomid());
     $pref = $this->_confirmEmail();
     $pref[$hash] = $this->get($id);
     $pref[$hash][self::EXPIRE] = time() + self::EXPIRE_SECS;
     $this->_confirmEmail($pref);
     $new_addr = $this->getValue($this->_prefnames['from_addr'], $id);
     $confirm = Horde::url($registry->getServiceLink('emailconfirm')->add('h', $hash)->setRaw(true), true);
     $message = sprintf(Horde_Core_Translation::t("You have requested to add the email address \"%s\" to the list of your personal email addresses.\n\nGo to the following link to confirm that this is really your address:\n%s\n\nIf you don't know what this message means, you can delete it."), $new_addr, $confirm);
     $msg_headers = new Horde_Mime_Headers();
     $msg_headers->addHeaderOb(Horde_Mime_Headers_MessageId::create());
     $msg_headers->addHeaderOb(Horde_Mime_Headers_UserAgent::create());
     $msg_headers->addHeaderOb(Horde_Mime_Headers_Date::create());
     $msg_headers->addHeader('To', $new_addr);
     $msg_headers->addHeader('From', $old_addr);
     $msg_headers->addHeader('Subject', Horde_Core_Translation::t("Confirm new email address"));
     $body = new Horde_Mime_Part();
     $body->setType('text/plain');
     $body->setContents(Horde_String::wrap($message, 76));
     $body->setCharset('UTF-8');
     $body->send($new_addr, $msg_headers, $injector->getInstance('Horde_Mail'));
     $notification->push(sprintf(Horde_Core_Translation::t("A message has been sent to \"%s\" to verify that this is really your address. The new email address is activated as soon as you confirm this message."), $new_addr), 'horde.message');
 }
Exemplo n.º 2
0
 /**
  * If this MIME part can contain embedded MIME part(s), and those part(s)
  * exist, return a representation of that data.
  *
  * @return mixed  A Horde_Mime_Part object representing the embedded data.
  *                Returns null if no embedded MIME part(s) exist.
  */
 protected function _getEmbeddedMimeParts()
 {
     /* Get the data from the attachment. */
     try {
         if (!($tnef = $this->getConfigParam('tnef'))) {
             $tnef = Horde_Compress::factory('Tnef');
             $this->setConfigParam('tnef', $tnef);
         }
         $tnefData = $tnef->decompress($this->_mimepart->getContents());
     } catch (Horde_Compress_Exception $e) {
         $tnefData = array();
     }
     if (!count($tnefData)) {
         return null;
     }
     $mixed = new Horde_Mime_Part();
     $mixed->setType('multipart/mixed');
     reset($tnefData);
     while (list(, $data) = each($tnefData)) {
         $temp_part = new Horde_Mime_Part();
         $temp_part->setName($data['name']);
         $temp_part->setDescription($data['name']);
         $temp_part->setContents($data['stream']);
         /* Short-circuit MIME-type guessing for winmail.dat parts;
          * we're showing enough entries for them already. */
         $type = $data['type'] . '/' . $data['subtype'];
         if (in_array($type, array('application/octet-stream', 'application/base64'))) {
             $type = Horde_Mime_Magic::filenameToMIME($data['name']);
         }
         $temp_part->setType($type);
         $mixed->addPart($temp_part);
     }
     return $mixed;
 }
Exemplo n.º 3
0
 /**
  * Return the MIME part object.
  *
  * @param boolean $build  If true, ensures the part contains the data.
  *
  * @return Horde_Mime_Part  MIME part object.
  * @throws IMP_Compose_Exception
  */
 public function getPart($build = false)
 {
     if ($build && !$this->_isBuilt) {
         $this->_part->setContents($this->storage->read()->stream, array('stream' => true));
         $this->_isBuilt = true;
     }
     return $this->_part;
 }
Exemplo n.º 4
0
 /**
  * Generates a Horde_Mime_Part object, in accordance with RFC 3156, that
  * contains a public key.
  *
  * @return Horde_Mime_Part  Object that contains the armored public key.
  */
 public function createMimePart()
 {
     $part = new Horde_Mime_Part();
     $part->setType('application/pgp-keys');
     $part->setHeaderCharset('UTF-8');
     $part->setDescription(Horde_Pgp_Translation::t("PGP Public Key"));
     $part->setContents(strval($this), array('encoding' => '7bit'));
     return $part;
 }
Exemplo n.º 5
0
 /**
  * Renders a token into text matching the requested format.
  *
  * @param array $options The "options" portion of the token (second
  * element).
  *
  * @return string The text rendered from the token options.
  */
 public function token($options)
 {
     $part = new Horde_Mime_Part();
     $part->setContents($options['text']);
     $part->setType('application/x-extension-' . $options['attr']['type']);
     $viewer = Horde_Mime_Viewer::factory('Horde_Core_Mime_Viewer_Syntaxhighlighter', $part, array('registry' => $GLOBALS['registry']));
     $data = $viewer->render('inline');
     $data = reset($data);
     return $data['data'];
 }
Exemplo n.º 6
0
 /**
  */
 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;
 }
Exemplo n.º 7
0
 private function load()
 {
     $headers = [];
     $fetch_query = new \Horde_Imap_Client_Fetch_Query();
     $fetch_query->bodyPart($this->attachmentId);
     $fetch_query->mimeHeader($this->attachmentId);
     $headers = array_merge($headers, ['importance', 'list-post', 'x-priority']);
     $headers[] = 'content-type';
     $fetch_query->headers('imp', $headers, ['cache' => true]);
     // $list is an array of Horde_Imap_Client_Data_Fetch objects.
     $ids = new \Horde_Imap_Client_Ids($this->messageId);
     $headers = $this->conn->fetch($this->mailBox, $fetch_query, ['ids' => $ids]);
     /** @var $fetch Horde_Imap_Client_Data_Fetch */
     if (!isset($headers[$this->messageId])) {
         throw new DoesNotExistException('Unable to load the attachment.');
     }
     $fetch = $headers[$this->messageId];
     $mimeHeaders = $fetch->getMimeHeader($this->attachmentId, Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
     $this->mimePart = new \Horde_Mime_Part();
     // To prevent potential problems with the SOP we serve all files with the
     // MIME type "application/octet-stream"
     $this->mimePart->setType('application/octet-stream');
     // Serve all files with a content-disposition of "attachment" to prevent Cross-Site Scripting
     $this->mimePart->setDisposition('attachment');
     // Extract headers from part
     $contentDisposition = $mimeHeaders->getValue('content-disposition', \Horde_Mime_Headers::VALUE_PARAMS);
     if (!is_null($contentDisposition)) {
         $vars = ['filename'];
         foreach ($contentDisposition as $key => $val) {
             if (in_array($key, $vars)) {
                 $this->mimePart->setDispositionParameter($key, $val);
             }
         }
     } else {
         $contentDisposition = $mimeHeaders->getValue('content-type', \Horde_Mime_Headers::VALUE_PARAMS);
         $vars = ['name'];
         foreach ($contentDisposition as $key => $val) {
             if (in_array($key, $vars)) {
                 $this->mimePart->setContentTypeParameter($key, $val);
             }
         }
     }
     /* Content transfer encoding. */
     if ($tmp = $mimeHeaders->getValue('content-transfer-encoding')) {
         $this->mimePart->setTransferEncoding($tmp);
     }
     $body = $fetch->getBodyPart($this->attachmentId);
     $this->mimePart->setContents($body);
 }
Exemplo n.º 8
0
 public function testReplaceMime()
 {
     $fixture = file_get_contents(__DIR__ . '/fixtures/signed_attachment.eml');
     $mime = new Horde_ActiveSync_Mime(Horde_Mime_Part::parseMessage($fixture));
     foreach ($mime->contentTypeMap() as $id => $type) {
         if ($mime->isAttachment($id, $type)) {
             $part = new Horde_Mime_Part();
             $part->setType('text/plain');
             $part->setContents(sprintf('An attachment named %s was removed by Horde_ActiveSync_Test', $mime->getPart($id)->getName(true)));
             $mime->removePart($id);
             $mime->addPart($part);
         }
     }
     $this->assertEquals(true, $mime->hasAttachments());
     $this->assertEquals('An attachment named foxtrotjobs.png was removed by Horde_ActiveSync_Test', $mime->getPart('3')->getContents());
 }
Exemplo n.º 9
0
    public function testBug10431()
    {
        $text = 'Das könnte zum Beispiel so aussehen, dass wir bei entsprechenden Anfragen diese an eine Kontaktperson bei Euch weiterleiten. Oder Ihr schnürt ein entsprechendes Paket, dass wir in unseren Angeboten mit anführen. Bei erfolgreicher Vermittlung bekämen wir eine Vermittlungsgebühr.
Wir ständen dann weiterhin für 3rd-Level-Support zur Verfügung, d.h. für alle Anfragen des Kunden bzgl. Horde, die nicht zum Tagesgeschäft gehören.';
        $text = Horde_String::convertCharset($text, 'UTF-8', 'ISO-8859-1');
        $textBody = new Horde_Mime_Part();
        $textBody->setType('text/plain');
        $textBody->setCharset('ISO-8859-1');
        $flowed = new Horde_Text_Flowed($text, 'ISO-8859-1');
        $flowed->setDelSp(true);
        $textBody->setContents($flowed->toFlowed());
        $flowed_txt = $textBody->toString(array('headers' => false));
        $textBody2 = new Horde_Mime_Part();
        $textBody2->setType('text/plain');
        $textBody2->setCharset('ISO-8859-1');
        $textBody2->setContents($flowed_txt, array('encoding' => 'quoted-printable'));
        $flowed2 = new Horde_Text_Flowed($textBody2->getContents(), 'ISO-8859-1');
        $flowed2->setMaxLength(0);
        $flowed2->setDelSp(true);
        $this->assertEquals($text, trim($flowed2->toFixed()));
    }
Exemplo n.º 10
0
 /**
  * Returns a MIME part for an image to be embedded into a HTML document.
  *
  * @param string $file  An image file name.
  *
  * @return Horde_Mime_Part  A MIME part representing the image.
  */
 public static function getImagePart($file)
 {
     $background = Horde_Themes::img($file);
     $image = new Horde_Mime_Part();
     $image->setType('image/png');
     $image->setContents(file_get_contents($background->fs));
     $image->setContentId();
     $image->setDisposition('attachment');
     return $image;
 }
Exemplo n.º 11
0
 /**
  * Process the messagedata and part data to extract the content of this part.
  *
  * @param \Horde_Imap_Client_Data_Fetch $messagedata The structure and part of the message body
  * @param \Horde_Mime_Part $partdata The part data
  * @param string $part The part ID
  * @return string
  */
 private function process_message_part_body($messagedata, $partdata, $part)
 {
     // This is a content section for the main body.
     // Get the string version of it.
     $content = $messagedata->getBodyPart($part);
     if (!$messagedata->getBodyPartDecode($part)) {
         // Decode the content.
         $partdata->setContents($content);
         $content = $partdata->getContents();
     }
     // Convert the text from the current encoding to UTF8.
     $content = \core_text::convert($content, $partdata->getCharset());
     // Fix any invalid UTF8 characters.
     // Note: XSS cleaning is not the responsibility of this code. It occurs immediately before display when
     // format_text is called.
     $content = clean_param($content, PARAM_RAW);
     return $content;
 }
Exemplo n.º 12
0
$gollem_vfs = $injector->getInstance('Gollem_Vfs');
$stream = null;
$data = '';
try {
    if (is_callable(array($gollem_vfs, 'readStream'))) {
        $stream = $gollem_vfs->readStream($vars->dir, $vars->file);
    } else {
        $data = $gollem_vfs->read($vars->dir, $vars->file);
    }
} catch (Horde_Vfs_Exception $e) {
    Horde::log($e, 'NOTICE');
    throw $e;
}
$mime_part = new Horde_Mime_Part();
$mime_part->setType(Horde_Mime_Magic::extToMime($vars->type));
$mime_part->setContents(is_resource($stream) ? $stream : $data);
$mime_part->setName($vars->file);
// We don't know better.
$mime_part->setCharset('US-ASCII');
$ret = $injector->getInstance('Horde_Core_Factory_MimeViewer')->create($mime_part)->render('full');
reset($ret);
$key = key($ret);
try {
    $size = $gollem_vfs->size($vars->dir, $vars->file);
} catch (Horde_Vfs_Exception $e) {
    $size = null;
}
if (empty($ret)) {
    $browser->downloadHeaders($vars->file, null, false, $size);
    if (is_resource($stream)) {
        fseek($stream, 0);
Exemplo n.º 13
0
 /**
  * Builds a proper AS mail message object.
  *
  * @param Horde_Imap_Client_Mailbox    $mbox  The IMAP mailbox.
  * @param Horde_Imap_Client_Data_Fetch $data  The fetch results.
  * @param array $options                      Additional Options:
  *   - truncation:  (integer) Truncate the message body to this length.
  *                  DEFAULT: No truncation.
  *   - bodyprefs: (array)  Bodyprefs, if sent from device.
  *                DEFAULT: none (No body prefs sent or enforced).
  *   - bodypartprefs: (array)  Bodypartprefs, if sent from device.
  *                DEFAULT: none (No body part prefs sent or enforced).
  *   - mimesupport: (integer)  Indicates if MIME is supported or not.
  *                  Possible values: 0 - Not supported 1 - Only S/MIME or
  *                  2 - All MIME.
  *                  DEFAULT: 0 (No MIME support)
  *   - protocolversion: (float)  The EAS protocol version to support.
  *                      DEFAULT: 2.5
  *
  * @return Horde_ActiveSync_Message_Mail  The message object suitable for
  *                                        streaming to the device.
  */
 protected function _buildMailMessage(Horde_Imap_Client_Mailbox $mbox, Horde_Imap_Client_Data_Fetch $data, $options = array())
 {
     $version = empty($options['protocolversion']) ? Horde_ActiveSync::VERSION_TWOFIVE : $options['protocolversion'];
     $imap_message = new Horde_ActiveSync_Imap_Message($this->_getImapOb(), $mbox, $data);
     $eas_message = Horde_ActiveSync::messageFactory('Mail');
     // Build To: data (POOMMAIL_TO has a max length of 32768).
     $to = $imap_message->getToAddresses();
     $eas_message->to = array_pop($to['to']);
     foreach ($to['to'] as $to_atom) {
         if (strlen($eas_message->to) + strlen($to_atom) > 32768) {
             break;
         }
         $eas_message->to .= ',' . $to_atom;
     }
     $eas_message->displayto = implode(';', $to['displayto']);
     if (empty($eas_message->displayto)) {
         $eas_message->displayto = $eas_message->to;
     }
     // Ensure we don't send broken UTF8 data to the client. It makes clients
     // angry. And we don't like angry clients.
     $hdr_charset = $imap_message->getStructure()->getHeaderCharset();
     // Fill in other header data
     try {
         $eas_message->from = $imap_message->getFromAddress();
     } catch (Horde_ActiveSync_Exception $e) {
         $this->_logger->err($e->getMessage());
     }
     try {
         $eas_message->cc = $imap_message->getCc();
     } catch (Horde_ActiveSync_Exception $e) {
         $this->_logger->err($e->getMessage());
     }
     try {
         $eas_message->reply_to = $imap_message->getReplyTo();
     } catch (Horde_ActiveSync_Exception $e) {
         $this->_logger->err($e->getMessage());
     }
     $eas_message->subject = Horde_ActiveSync_Utils::ensureUtf8($imap_message->getSubject(), $hdr_charset);
     $eas_message->threadtopic = $eas_message->subject;
     $eas_message->datereceived = $imap_message->getDate();
     $eas_message->read = $imap_message->getFlag(Horde_Imap_Client::FLAG_SEEN);
     // Default to IPM.Note - may change below depending on message content.
     $eas_message->messageclass = 'IPM.Note';
     // Codepage id. MS recommends to always set to UTF-8 when possible.
     // See http://msdn.microsoft.com/en-us/library/windows/desktop/dd317756%28v=vs.85%29.aspx
     $eas_message->cpid = Horde_ActiveSync_Message_Mail::INTERNET_CPID_UTF8;
     // Message importance. First try X-Priority, then Importance since
     // Outlook sends the later.
     if ($priority = $imap_message->getHeaders()->getValue('X-priority')) {
         $priority = preg_replace('/\\D+/', '', $priority);
     } else {
         $priority = $imap_message->getHeaders()->getValue('Importance');
     }
     $eas_message->importance = $this->_getEASImportance($priority);
     // Get the body data.
     $mbd = $imap_message->getMessageBodyDataObject($options);
     if ($version == Horde_ActiveSync::VERSION_TWOFIVE) {
         $eas_message->body = $mbd->plain['body']->stream;
         $eas_message->bodysize = $mbd->plain['body']->length(true);
         $eas_message->bodytruncated = $mbd->plain['truncated'];
         $eas_message->attachments = $imap_message->getAttachments($version);
     } else {
         // Get the message body and determine original type.
         if ($mbd->html) {
             $eas_message->airsyncbasenativebodytype = Horde_ActiveSync::BODYPREF_TYPE_HTML;
         } else {
             $eas_message->airsyncbasenativebodytype = Horde_ActiveSync::BODYPREF_TYPE_PLAIN;
         }
         $airsync_body = Horde_ActiveSync::messageFactory('AirSyncBaseBody');
         $body_type_pref = $mbd->getBodyTypePreference();
         if ($body_type_pref == Horde_ActiveSync::BODYPREF_TYPE_MIME) {
             $this->_logger->info(sprintf('[%s] Sending MIME Message.', $this->_procid));
             // ActiveSync *REQUIRES* all data sent to be in UTF-8, so we
             // must convert the body parts to UTF-8. Unfortunately if the
             // email is signed (or encrypted for that matter) we can't
             // alter the data in anyway or the signature will not be
             // verified, so we fetch the entire message and hope for the best.
             if (!$imap_message->isSigned() && !$imap_message->isEncrypted()) {
                 $mime = new Horde_Mime_Part();
                 if ($mbd->plain) {
                     $plain_mime = new Horde_Mime_Part();
                     $plain_mime->setType('text/plain');
                     $plain_mime->setContents($mbd->plain['body']->stream, array('usestream' => true));
                     $plain_mime->setCharset('UTF-8');
                 }
                 if ($mbd->html) {
                     $html_mime = new Horde_Mime_Part();
                     $html_mime->setType('text/html');
                     $html_mime->setContents($mbd->html['body']->stream, array('usestream' => true));
                     $html_mime->setCharset('UTF-8');
                 }
                 // Sanity check the mime type
                 if (!$mbd->html && !empty($plain_mime)) {
                     $mime = $plain_mime;
                 } elseif (!$mbd->plain && !empty($html_mime)) {
                     $mime = $html_mime;
                 } elseif (!empty($plain_mime) && !empty($html_mime)) {
                     $mime->setType('multipart/alternative');
                     $mime->addPart($plain_mime);
                     $mime->addPart($html_mime);
                 }
                 $html_mime = null;
                 $plain_mime = null;
                 // If we have attachments, create a multipart/mixed wrapper.
                 if ($imap_message->hasAttachments()) {
                     $base = new Horde_Mime_Part();
                     $base->setType('multipart/mixed');
                     $base->addPart($mime);
                     $atc = $imap_message->getAttachmentsMimeParts();
                     foreach ($atc as $atc_part) {
                         $base->addPart($atc_part);
                     }
                     $eas_message->airsyncbaseattachments = $imap_message->getAttachments($version);
                 } else {
                     $base = $mime;
                 }
                 $mime = null;
                 // Populate the EAS body structure with the MIME data, but
                 // remove the Content-Type and Content-Transfer-Encoding
                 // headers since we are building this ourselves.
                 $headers = $imap_message->getHeaders();
                 $headers->removeHeader('Content-Type');
                 $headers->removeHeader('Content-Transfer-Encoding');
                 $airsync_body->data = $base->toString(array('headers' => $headers, 'stream' => true));
                 $airsync_body->estimateddatasize = $base->getBytes();
             } else {
                 // Signed/Encrypted message - can't mess with it at all.
                 $raw = new Horde_ActiveSync_Rfc822($imap_message->getFullMsg(true), false);
                 $airsync_body->estimateddatasize = $raw->getBytes();
                 $airsync_body->data = $raw->getString();
                 $eas_message->airsyncbaseattachments = $imap_message->getAttachments($version);
             }
             $airsync_body->type = Horde_ActiveSync::BODYPREF_TYPE_MIME;
             // MIME Truncation
             // @todo Remove this sanity-check hack in 3.0. This is needed
             // since truncationsize incorrectly defaulted to a
             // MIME_TRUNCATION constant and could be cached in the sync-cache.
             $ts = !empty($options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_MIME]['truncationsize']) ? $options['bodyprefs'][Horde_ActiveSync::BODYPREF_TYPE_MIME]['truncationsize'] : false;
             $mime_truncation = !empty($ts) && $ts > 9 ? $ts : (!empty($options['truncation']) && $options['truncation'] > 9 ? $options['truncation'] : false);
             $this->_logger->info(sprintf('[%s] Checking MIMETRUNCATION: %s, ServerData: %s', $this->_procid, $mime_truncation, $airsync_body->estimateddatasize));
             if (!empty($mime_truncation) && $airsync_body->estimateddatasize > $mime_truncation) {
                 ftruncate($airsync_body->data, $mime_truncation);
                 $airsync_body->truncated = '1';
             } else {
                 $airsync_body->truncated = '0';
             }
             $eas_message->airsyncbasebody = $airsync_body;
         } elseif ($body_type_pref == Horde_ActiveSync::BODYPREF_TYPE_HTML) {
             // Sending non MIME encoded HTML message text.
             $eas_message->airsyncbasebody = $this->_buildHtmlPart($mbd, $airsync_body);
             $eas_message->airsyncbaseattachments = $imap_message->getAttachments($version);
         } elseif ($body_type_pref == Horde_ActiveSync::BODYPREF_TYPE_PLAIN) {
             // Non MIME encoded plaintext
             $this->_logger->info(sprintf('[%s] Sending PLAINTEXT Message.', $this->_procid));
             if (!empty($mbd->plain['size'])) {
                 $airsync_body->estimateddatasize = $mbd->plain['size'];
                 $airsync_body->truncated = $mbd->plain['truncated'];
                 $airsync_body->data = $mbd->plain['body']->stream;
                 $airsync_body->type = Horde_ActiveSync::BODYPREF_TYPE_PLAIN;
                 $eas_message->airsyncbasebody = $airsync_body;
             }
             $eas_message->airsyncbaseattachments = $imap_message->getAttachments($version);
         }
         // It's legal to have both a BODY and a BODYPART, so we must also
         // check for that.
         if ($version > Horde_ActiveSync::VERSION_FOURTEEN && !empty($options['bodypartprefs'])) {
             $body_part = Horde_ActiveSync::messageFactory('AirSyncBaseBodypart');
             $eas_message->airsyncbasebodypart = $this->_buildBodyPart($mbd, $options, $body_part);
         }
         if ($version > Horde_ActiveSync::VERSION_TWELVEONE) {
             $flags = array();
             $msgFlags = $this->_getMsgFlags();
             foreach ($imap_message->getFlags() as $flag) {
                 if (!empty($msgFlags[Horde_String::lower($flag)])) {
                     $flags[] = $msgFlags[Horde_String::lower($flag)];
                 }
             }
             $eas_message->categories = $flags;
         }
     }
     // Body Preview? Note that this is different from BodyPart's preview
     if ($version >= Horde_ActiveSync::VERSION_FOURTEEN && !empty($options['bodyprefs']['preview'])) {
         $mbd->plain['body']->rewind();
         $eas_message->airsyncbasebody->preview = $mbd->plain['body']->substring(0, $options['bodyprefs']['preview']);
     }
     $mbd = null;
     // Check for special message types.
     if ($imap_message->isEncrypted()) {
         $eas_message->messageclass = 'IPM.Note.SMIME';
     } elseif ($imap_message->isSigned()) {
         $eas_message->messageclass = 'IPM.Note.SMIME.MultipartSigned';
     }
     $part = $imap_message->getStructure();
     if ($part->getType() == 'multipart/report') {
         $ids = array_keys($imap_message->contentTypeMap());
         reset($ids);
         $part1_id = next($ids);
         $part2_id = Horde_Mime::mimeIdArithmetic($part1_id, 'next');
         $lines = explode(chr(13), $imap_message->getBodyPart($part2_id, array('decode' => true)));
         switch ($part->getContentTypeParameter('report-type')) {
             case 'delivery-status':
                 foreach ($lines as $line) {
                     if (strpos(trim($line), 'Action:') === 0) {
                         switch (trim(substr(trim($line), 7))) {
                             case 'failed':
                                 $eas_message->messageclass = 'REPORT.IPM.NOTE.NDR';
                                 break 2;
                             case 'delayed':
                                 $eas_message->messageclass = 'REPORT.IPM.NOTE.DELAYED';
                                 break 2;
                             case 'delivered':
                                 $eas_message->messageclass = 'REPORT.IPM.NOTE.DR';
                                 break 2;
                         }
                     }
                 }
                 break;
             case 'disposition-notification':
                 foreach ($lines as $line) {
                     if (strpos(trim($line), 'Disposition:') === 0) {
                         if (strpos($line, 'displayed') !== false) {
                             $eas_message->messageclass = 'REPORT.IPM.NOTE.IPNRN';
                         } elseif (strpos($line, 'deleted') !== false) {
                             $eas_message->messageclass = 'REPORT.IPM.NOTE.IPNNRN';
                         }
                         break;
                     }
                 }
         }
     }
     $part = null;
     // Check for meeting requests and POOMMAIL_FLAG data
     if ($version >= Horde_ActiveSync::VERSION_TWELVE) {
         $eas_message->contentclass = 'urn:content-classes:message';
         if ($mime_part = $imap_message->hasiCalendar()) {
             $data = Horde_ActiveSync_Utils::ensureUtf8($mime_part->getContents(), $mime_part->getCharset());
             $vCal = new Horde_Icalendar();
             if ($vCal->parsevCalendar($data, 'VCALENDAR', $mime_part->getCharset())) {
                 $classes = $vCal->getComponentClasses();
             } else {
                 $classes = array();
             }
             if (!empty($classes['horde_icalendar_vevent'])) {
                 try {
                     $method = $vCal->getAttribute('METHOD');
                     $eas_message->contentclass = 'urn:content-classes:calendarmessage';
                 } catch (Horde_Icalendar_Exception $e) {
                 }
                 switch ($method) {
                     case 'REQUEST':
                     case 'PUBLISH':
                         $eas_message->messageclass = 'IPM.Schedule.Meeting.Request';
                         $mtg = Horde_ActiveSync::messageFactory('MeetingRequest');
                         $mtg->fromvEvent($vCal);
                         $eas_message->meetingrequest = $mtg;
                         break;
                     case 'REPLY':
                         try {
                             $reply_status = $this->_getiTipStatus($vCal);
                             switch ($reply_status) {
                                 case 'ACCEPTED':
                                     $eas_message->messageclass = 'IPM.Schedule.Meeting.Resp.Pos';
                                     break;
                                 case 'DECLINED':
                                     $eas_message->messageclass = 'IPM.Schedule.Meeting.Resp.Neg';
                                     break;
                                 case 'TENTATIVE':
                                     $eas_message->messageclass = 'IPM.Schedule.Meeting.Resp.Tent';
                             }
                             $mtg = Horde_ActiveSync::messageFactory('MeetingRequest');
                             $mtg->fromvEvent($vCal);
                             $eas_message->meetingrequest = $mtg;
                         } catch (Horde_ActiveSync_Exception $e) {
                             $this->_logger->err($e->getMessage());
                         }
                 }
             }
         }
         if ($imap_message->getFlag(Horde_Imap_Client::FLAG_FLAGGED)) {
             $poommail_flag = Horde_ActiveSync::messageFactory('Flag');
             $poommail_flag->subject = $imap_message->getSubject();
             $poommail_flag->flagstatus = Horde_ActiveSync_Message_Flag::FLAG_STATUS_ACTIVE;
             $poommail_flag->flagtype = Horde_Imap_Client::FLAG_FLAGGED;
             $eas_message->flag = $poommail_flag;
         }
     }
     if ($version >= Horde_ActiveSync::VERSION_FOURTEEN) {
         $eas_message->messageid = $imap_message->getHeaders()->getValue('Message-ID');
         $eas_message->forwarded = $imap_message->getFlag(Horde_Imap_Client::FLAG_FORWARDED);
         $eas_message->answered = $imap_message->getFlag(Horde_Imap_Client::FLAG_ANSWERED);
     }
     $imap_message = null;
     return $eas_message;
 }
Exemplo n.º 14
0
Arquivo: Mime.php Projeto: horde/horde
 /**
  * Converts armored input into a Horde_Mime_Part object.
  *
  * @param mixed $input  Armored input.
  * @param array $opts   Additional options:
  *   - charset: (string) Charset of the armored input.
  *
  * @return mixed  Either null if no PGP data was found, or a
  *                Horde_Mime_Part object.
  */
 public function armorToPart($input, array $opts = array())
 {
     $opts = array_merge(array('charset' => 'UTF-8'), $opts);
     $armor = Horde_Pgp_Armor::create($input);
     $new_part = new Horde_Mime_Part();
     $new_part->setType('multipart/mixed');
     foreach ($armor as $val) {
         switch (get_class($val)) {
             case 'Horde_Pgp_Element_Text':
                 $part = new Horde_Mime_Part();
                 $part->setType('text/plain');
                 $part->setCharset($opts['charset']);
                 $part->setContents($val->message[0]->data);
                 $new_part[] = $part;
                 break;
             case 'Horde_Pgp_Element_PrivateKey':
             case 'Horde_Pgp_Element_PublicKey':
                 $part = new Horde_Mime_Part();
                 $part->setType('application/pgp-keys');
                 $part->setContents(strval($val));
                 $new_part[] = $part;
                 break;
             case 'Horde_Pgp_Element_Message':
                 // TODO: Message can also be text or signature
                 $part = $this->_encryptBase($val);
                 $part->setMetadata(self::PGP_ARMOR, true);
                 $part['2']->setMetadata(self::PGP_CHARSET, isset($val->headers['Charset']) ? $val->headers['Charset'] : 'UTF-8');
                 $new_part[] = $part;
                 break;
             case 'Horde_Pgp_Element_SignedMessage':
                 $part = $this->_signPart($val->text, $val->signature);
                 $new_part[] = $part;
                 break;
         }
     }
     return count($new_part->getParts()) ? $new_part : null;
 }
Exemplo n.º 15
0
 /**
  * Build the data needed for the BodyPart part.
  *
  * @param  Horde_Imap_Client_Data_Fetch $data  The FETCH results.
  * @param  Horde_Mime_Part $mime  The plaintext MIME part.
  * @param boolean $to_html        If true, $id is assumed to be a text/plain
  *                                part and is converted to html.
  *
  * @return array  The BodyPart data.
  *     - charset:  (string)   The charset of the text.
  *     - body: (string)       The body text.
  *     - truncated: (boolean) True if text was truncated.
  *     - size: (integer)      The original part size, in bytes.
  */
 protected function _getBodyPart(Horde_Imap_Client_Data_Fetch $data, Horde_Mime_Part $mime, $to_html)
 {
     $id = $mime->getMimeId();
     $text = $data->getBodyPart($id);
     if (!$data->getBodyPartDecode($id)) {
         $mime->setContents($text);
         $text = $mime->getContents();
     }
     if ($to_html) {
         $text = Horde_Text_Filter::filter($text, 'Text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO, 'charset' => $mime->getCharset()));
         $size = strlen($text);
     } else {
         $size = !is_null($data->getBodyPartSize($id)) ? $data->getBodyPartSize($id) : strlen($text);
     }
     if (!empty($this->_options['bodypartprefs']['truncationsize'])) {
         $text = Horde_String::substr($text, 0, $this->_options['bodypartprefs']['truncationsize'], $mime->getCharset());
     }
     return array('charset' => $mime->getCharset(), 'body' => $text, 'truncated' => $size > strlen($text), 'size' => $size);
 }
Exemplo n.º 16
0
 /**
  * Sends this message.
  *
  * @param Mail $mailer     A Mail object.
  * @param boolean $resend  If true, the message id and date are re-used;
  *                         If false, they will be updated.
  * @param boolean $flowed  Send message in flowed text format.
  *
  * @throws Horde_Mime_Exception
  */
 public function send($mailer, $resend = false, $flowed = true)
 {
     /* Add mandatory headers if missing. */
     $has_header = $this->_headers->getValue('Message-ID');
     if (!$resend || !$has_header) {
         if ($has_header) {
             $this->_headers->removeHeader('Message-ID');
         }
         $this->_headers->addMessageIdHeader();
     }
     if (!$this->_headers->getValue('User-Agent')) {
         $this->_headers->addUserAgentHeader();
     }
     $has_header = $this->_headers->getValue('Date');
     if (!$resend || !$has_header) {
         if ($has_header) {
             $this->_headers->removeHeader('Date');
         }
         $this->_headers->addHeader('Date', date('r'));
     }
     if (isset($this->_base)) {
         $basepart = $this->_base;
     } else {
         /* Send in flowed format. */
         if ($flowed && !empty($this->_body)) {
             $flowed = new Horde_Text_Flowed($this->_body->getContents(), $this->_body->getCharset());
             $flowed->setDelSp(true);
             $this->_body->setContentTypeParameter('format', 'flowed');
             $this->_body->setContentTypeParameter('DelSp', 'Yes');
             $this->_body->setContents($flowed->toFlowed());
         }
         /* Build mime message. */
         $body = new Horde_Mime_Part();
         if (!empty($this->_body) && !empty($this->_htmlBody)) {
             $body->setType('multipart/alternative');
             $this->_body->setDescription(Horde_Mime_Translation::t("Plaintext Version of Message"));
             $body->addPart($this->_body);
             $this->_htmlBody->setDescription(Horde_Mime_Translation::t("HTML Version of Message"));
             $body->addPart($this->_htmlBody);
         } elseif (!empty($this->_htmlBody)) {
             $body = $this->_htmlBody;
         } elseif (!empty($this->_body)) {
             $body = $this->_body;
         }
         if (count($this->_parts)) {
             $basepart = new Horde_Mime_Part();
             $basepart->setType('multipart/mixed');
             $basepart->isBasePart(true);
             if ($body) {
                 $basepart->addPart($body);
             }
             foreach ($this->_parts as $mime_part) {
                 $basepart->addPart($mime_part);
             }
         } else {
             $basepart = $body;
             $basepart->isBasePart(true);
         }
     }
     $basepart->setHeaderCharset($this->_charset);
     /* Build recipients. */
     $recipients = clone $this->_recipients;
     foreach (array('to', 'cc') as $header) {
         $recipients->add($this->_headers->getOb($header));
     }
     if ($this->_bcc) {
         $recipients->add($this->_bcc);
     }
     /* Trick Horde_Mime_Part into re-generating the message headers. */
     $this->_headers->removeHeader('MIME-Version');
     /* Send message. */
     $recipients->unique();
     $basepart->send($recipients->writeAddress(), $this->_headers, $mailer);
     /* Remember the basepart */
     $this->_base = $basepart;
 }
Exemplo n.º 17
0
 /**
  * Rebuilds $part and forces it to be a base64 encoded
  * application/octet-stream part.
  *
  * @param  Horde_Mime_Part $part   The MIME part.
  */
 protected function _reEncodeMessageAttachment(Horde_Mime_Part $part)
 {
     $new_part = Horde_Mime_Part::parseMessage($part->getContents());
     $part->setContents($new_part->getContents(array('stream' => true)), array('encoding' => self::ENCODE_BINARY));
     $part->setTransferEncoding('base64', array('send' => true));
 }
Exemplo n.º 18
0
 /**
  * Parses an armored message into a Horde_Mime_Part object.
  *
  * @param mixed $text  Either the text to parse or a Horde_Stream object.
  *
  * @return mixed  Either null if no PGP data was found, or a
  *                Horde_Mime_Part object. For detached signature data:
  *                the full contents of the armored text (data + sig) is
  *                contained in the SIG_RAW metadata, and the charset is
  *                contained in the SIG_CHARSET metadata, within the
  *                application/pgp-signature part.
  */
 public function parseToPart($text, $charset = 'UTF-8')
 {
     $parts = $this->parse($text);
     if (empty($parts) || count($parts) == 1 && $parts[0]['type'] == self::ARMOR_TEXT) {
         return null;
     }
     $new_part = new Horde_Mime_Part();
     $new_part->setType('multipart/mixed');
     foreach ($parts as $val) {
         switch ($val['type']) {
             case self::ARMOR_TEXT:
                 $part = new Horde_Mime_Part();
                 $part->setType('text/plain');
                 $part->setCharset($charset);
                 $part->setContents(implode("\n", $val['data']));
                 $new_part->addPart($part);
                 break;
             case self::ARMOR_PUBLIC_KEY:
                 $part = new Horde_Mime_Part();
                 $part->setType('application/pgp-keys');
                 $part->setContents(implode("\n", $val['data']));
                 $new_part->addPart($part);
                 break;
             case self::ARMOR_MESSAGE:
                 $part = new Horde_Mime_Part();
                 $part->setType('multipart/encrypted');
                 $part->setMetadata(self::PGP_ARMOR, true);
                 $part->setContentTypeParameter('protocol', 'application/pgp-encrypted');
                 $part1 = new Horde_Mime_Part();
                 $part1->setType('application/pgp-encrypted');
                 $part1->setContents("Version: 1\n");
                 $part2 = new Horde_Mime_Part();
                 $part2->setType('application/octet-stream');
                 $part2->setContents(implode("\n", $val['data']));
                 $part2->setDisposition('inline');
                 $part->addPart($part1);
                 $part->addPart($part2);
                 $new_part->addPart($part);
                 break;
             case self::ARMOR_SIGNED_MESSAGE:
                 if (($sig = current($parts)) && $sig['type'] == self::ARMOR_SIGNATURE) {
                     $part = new Horde_Mime_Part();
                     $part->setType('multipart/signed');
                     // TODO: add micalg parameter
                     $part->setContentTypeParameter('protocol', 'application/pgp-signature');
                     $part1 = new Horde_Mime_Part();
                     $part1->setType('text/plain');
                     $part1->setCharset($charset);
                     $part1_data = implode("\n", $val['data']);
                     $part1->setContents(substr($part1_data, strpos($part1_data, "\n\n") + 2));
                     $part2 = new Horde_Mime_Part();
                     $part2->setType('application/pgp-signature');
                     $part2->setContents(implode("\n", $sig['data']));
                     $part2->setMetadata(self::SIG_CHARSET, $charset);
                     $part2->setMetadata(self::SIG_RAW, implode("\n", $val['data']) . "\n" . implode("\n", $sig['data']));
                     $part->addPart($part1);
                     $part->addPart($part2);
                     $new_part->addPart($part);
                     next($parts);
                 }
         }
     }
     return $new_part;
 }
Exemplo n.º 19
0
 /**
  * Convert a TNEF attachment into a multipart/mixed part.
  *
  * @param  integer|Horde_Mime_part $data  Either a mime part id or a
  *                                        Horde_Mime_Part object containing
  *                                        the TNEF attachment.
  *
  * @return Horde_Mime_Part  The multipart/mixed MIME part containing any
  *                          attachment data we can decode.
  */
 protected function _decodeTnefData($data)
 {
     $wrapper = new Horde_Mime_Part();
     $wrapper->setType('multipart/mixed');
     if (!$data instanceof Horde_Mime_Part) {
         $mime_part = $this->getMimePart($data);
     } else {
         $mime_part = $data;
     }
     $tnef_parser = Horde_Compress::factory('Tnef');
     try {
         $tnef_data = $tnef_parser->decompress($mime_part->getContents());
     } catch (Horde_Compress_Exception $e) {
         return false;
     }
     if (!count($tnef_data)) {
         return false;
     }
     reset($tnef_data);
     while (list(, $data) = each($tnef_data)) {
         $tmp_part = new Horde_Mime_Part();
         $tmp_part->setName($data['name']);
         $tmp_part->setDescription($data['name']);
         $tmp_part->setContents($data['stream']);
         $type = $data['type'] . '/' . $data['subtype'];
         if (in_array($type, array('application/octet-stream', 'application/base64'))) {
             $type = Horde_Mime_Magic::filenameToMIME($data['name']);
         }
         $tmp_part->setType($type);
         $wrapper->addPart($tmp_part);
     }
     return $wrapper;
 }
Exemplo n.º 20
0
asort($apps);
$application = $vars->get('app', 'horde');
$command = trim($vars->php);
$title = _("PHP Shell");
$view = new Horde_View(array('templatePath' => HORDE_TEMPLATES . '/admin'));
$view->addHelper('Horde_Core_View_Helper_Help');
$view->addHelper('Text');
$view->action = Horde::url('admin/phpshell.php');
$view->application = $application;
$view->apps = $apps;
$view->command = $command;
$view->title = $title;
if ($command) {
    $pushed = $registry->pushApp($application);
    $part = new Horde_Mime_Part();
    $part->setContents($command);
    $part->setType('application/x-httpd-phps');
    $part->buildMimeIds();
    $pretty = $injector->getInstance('Horde_Core_Factory_MimeViewer')->create($part)->render('inline');
    $view->pretty = $pretty[1]['data'];
    Horde::startBuffer();
    try {
        eval($command);
    } catch (Exception $e) {
        echo $e;
    }
    $view->command_exec = Horde::endBuffer();
    if ($pushed) {
        $registry->popApp();
    }
}
Exemplo n.º 21
0
 /**
  * Scan text for UUencode data an, if it exists, convert the part to the
  * embedded MIME representation.
  *
  * @return mixed  See self::_getEmbeddedMimeParts().
  */
 protected function _parseUUencode()
 {
     $text = Horde_String::convertCharset($this->_mimepart->getContents(), $this->_mimepart->getCharset(), 'UTF-8');
     $files = Horde_Mime::uudecode($text);
     if (empty($files)) {
         return null;
     }
     $new_part = new Horde_Mime_Part();
     $new_part->setType('multipart/mixed');
     $text_part = new Horde_Mime_Part();
     $text_part->setType('text/plain');
     $text_part->setCharset($this->getConfigParam('charset'));
     $text_part->setContents(preg_replace("/begin [0-7]{3} .+\r?\n.+\r?\nend/Us", "\n", $text));
     $new_part->addPart($text_part);
     reset($files);
     while (list(, $file) = each($files)) {
         $uupart = new Horde_Mime_Part();
         $uupart->setType('application/octet-stream');
         $uupart->setContents($file['data']);
         $uupart->setName(strip_tags($file['name']));
         $new_part->addPart($uupart);
     }
     return $new_part;
 }
Exemplo n.º 22
0
 /**
  * Embed the Kolab content into a new MIME Part.
  *
  * @param resource $content The Kolab content.
  *
  * @return Horde_Mime_Part The MIME part that encapsules the Kolab content.
  */
 protected function createFreshKolabPart($content)
 {
     $part = new Horde_Mime_Part();
     $part->setCharset('utf-8');
     $part->setDisposition('inline');
     $part->setDispositionParameter('x-kolab-type', 'xml');
     $part->setName('kolab.xml');
     $part->setType(Horde_Kolab_Storage_Object_MimeType::getMimeTypeFromObjectType($this->getType()));
     $part->setContents($content, array('encoding' => 'quoted-printable'));
     return $part;
 }
Exemplo n.º 23
0
 /**
  * Save an object in this folder.
  *
  * @param array  $object       The array that holds the data of the object.
  * @param int    $data_version The format handler version.
  * @param string $object_type  The type of the kolab object.
  * @param string $id           The IMAP id of the old object if it
  *                             existed before
  * @param array  $old_object   The array that holds the current data of the
  *                             object.
  *
  * @return boolean True on success.
  */
 public function saveObject(&$object, $data_version, $object_type, $id = null, &$old_object = null)
 {
     // Select folder
     $this->_driver->select($this->_path);
     $new_headers = new Horde_Mime_Headers();
     $new_headers->setEOL("\r\n");
     $formats = $this->getFormats();
     $handlers = array();
     foreach ($formats as $type) {
         $handlers[$type] =& Horde_Kolab_Format::factory($type, $object_type, $data_version);
         if (is_a($handlers[$type], 'PEAR_Error')) {
             if ($type == 'XML') {
                 return $handlers[$type];
             }
             Horde::log(sprintf('Loading format handler "%s" failed: %s', $type, $handlers[$type]->getMessage()), 'ERR');
             continue;
         }
     }
     if ($id != null) {
         /** Update an existing kolab object */
         if (!in_array($id, $this->_driver->getUids($this->_path))) {
             return PEAR::raiseError(sprintf(Horde_Kolab_Storage_Translation::t("The message with ID %s does not exist. This probably means that the Kolab object has been modified by somebody else while you were editing it. Your edits have been lost."), $id));
         }
         /** Parse email and load Kolab format structure */
         $result = $this->parseMessage($id, $handlers['XML']->getMimeType(), true, $formats);
         if (is_a($result, 'PEAR_Error')) {
             return $result;
         }
         list($old_message, $part_ids, $mime_message, $mime_headers) = $result;
         if (is_a($old_message, 'PEAR_Error')) {
             return $old_message;
         }
         if (isset($object['_attachments']) && isset($old_object['_attachments'])) {
             $attachments = array_keys($object['_attachments']);
             foreach (array_keys($old_object['_attachments']) as $attachment) {
                 if (!in_array($attachment, $attachments)) {
                     foreach ($mime_message->getParts() as $part) {
                         if ($part->getName() === $attachment) {
                             foreach (array_keys($mime_message->_parts) as $key) {
                                 if ($mime_message->_parts[$key]->getMimeId() == $part->getMimeId()) {
                                     unset($mime_message->_parts[$key]);
                                     break;
                                 }
                             }
                             $mime_message->_generateIdMap($mime_message->_parts);
                         }
                     }
                 }
             }
         }
         $object = array_merge($old_object, $object);
         if (isset($attachments)) {
             foreach ($mime_message->getParts() as $part) {
                 $name = $part->getName();
                 foreach ($attachments as $attachment) {
                     if ($name === $attachment) {
                         $object['_attachments'][$attachment]['id'] = $part->getMimeId();
                     }
                 }
             }
         }
         /** Copy email header */
         if (!empty($mime_headers) && !$mime_headers === false) {
             foreach ($mime_headers as $header => $value) {
                 $new_headers->addheader($header, $value);
             }
         }
     } else {
         $mime_message = $this->_prepareNewMessage($new_headers);
         $mime_part_id = false;
     }
     if (isset($object['_attachments'])) {
         $attachments = array_keys($object['_attachments']);
         foreach ($attachments as $attachment) {
             $data = $object['_attachments'][$attachment];
             if (!isset($data['content']) && !isset($data['path'])) {
                 /**
                  * There no new content and no new path. Do not rewrite the
                  * attachment.
                  */
                 continue;
             }
             $part = new Horde_Mime_Part();
             $part->setType(isset($data['type']) ? $data['type'] : null);
             $part->setContents(isset($data['content']) ? $data['content'] : file_get_contents($data['path']));
             $part->setCharset('UTF-8');
             $part->setTransferEncoding('quoted-printable');
             $part->setDisposition('attachment');
             $part->setName($attachment);
             if (!isset($data['id'])) {
                 $mime_message->addPart($part);
             } else {
                 $mime_message->alterPart($data['id'], $part);
             }
         }
     }
     foreach ($formats as $type) {
         $new_content = $handlers[$type]->save($object);
         if (is_a($new_content, 'PEAR_Error')) {
             return $new_content;
         }
         /** Update mime part */
         $part = new Horde_Mime_Part();
         $part->setType($handlers[$type]->getMimeType());
         $part->setContents($new_content);
         $part->setCharset('UTF-8');
         $part->setTransferEncoding('quoted-printable');
         $part->setDisposition($handlers[$type]->getDisposition());
         $part->setDispositionParameter('x-kolab-type', $type);
         $part->setName($handlers[$type]->getName());
         if (!isset($part_ids) || $part_ids[$type] === false) {
             $mime_message->addPart($part);
         } else {
             $mime_message->alterPart($part_ids[$type], $part);
         }
     }
     // Update email headers
     $new_headers->addHeader('From', $this->_driver->getAuth());
     $new_headers->addHeader('To', $this->_driver->getAuth());
     $new_headers->addHeader('Date', date('r'));
     $new_headers->addHeader('X-Kolab-Type', $handlers['XML']->getMimeType());
     $new_headers->addHeader('Subject', $object['uid']);
     $new_headers->addHeader('User-Agent', 'Horde::Kolab::Storage v0.2');
     $new_headers->addHeader('MIME-Version', '1.0');
     $mime_message->addMimeHeaders(array('headers' => $new_headers));
     $msg = $new_headers->toString() . $mime_message->toString(array('canonical' => true, 'headers' => false));
     // delete old email?
     if ($id != null) {
         $this->_driver->deleteMessages($this->_path, $id);
     }
     // store new email
     try {
         $result = $this->_driver->appendMessage($this->_path, $msg);
     } catch (Horde_Kolab_Storage_Exception $e) {
         if ($id != null) {
             $this->_driver->undeleteMessages($id);
         }
     }
     // remove deleted object
     if ($id != null) {
         $this->_driver->expunge($this->_path);
     }
 }
Exemplo n.º 24
0
 /**
  * Sends out iTip task notification to the assignee.
  *
  * Can be used to send task invitations, updates, and cancellations.
  *
  * @param Nag_Task $task  The task in question.
  * @param Horde_Notification_Handler $notification
  *        A notification object used to show result status.
  * @param integer $action
  *        The type of notification to send. One of the Nag::ITIP_* values.
  * @param Horde_Date $instance
  *        If cancelling a single instance of a recurring task, the date of
  *        this instance.
  * @param  string $range  The range parameter if this is a recurring event.
  *                        Possible values are self::RANGE_THISANDFUTURE
  */
 public static function sendITipNotifications(Nag_Task $task, Horde_Notification_Handler $notification, $action, Horde_Date $instance = null, $range = null)
 {
     global $injector, $registry, $nag_shares;
     if (!$task->assignee) {
         return;
     }
     $ident = $injector->getInstance('Horde_Core_Factory_Identity')->create($task->creator);
     if (!$ident->getValue('from_addr')) {
         $notification->push(sprintf(_("You do not have an email address configured in your Personal Information Preferences. You must set one %shere%s before event notifications can be sent."), $registry->getServiceLink('prefs', 'kronolith')->add(array('app' => 'horde', 'group' => 'identities'))->link(), '</a>'), 'horde.error', array('content.raw'));
         return;
     }
     // Generate image mime part first and only once, because we
     // need the Content-ID.
     $image = self::getImagePart('big_invitation.png');
     $share = $nag_shares->getShare($task->tasklist);
     $view = new Horde_View(array('templatePath' => NAG_TEMPLATES . '/itip'));
     new Horde_View_Helper_Text($view);
     $view->identity = $ident;
     $view->task = $task;
     $view->imageId = $image->getContentId();
     $email = Nag::getUserEmail($task->assignee);
     if (strpos($email, '@') === false) {
         continue;
     }
     /* Determine all notification-specific strings. */
     $method = 'REQUEST';
     switch ($action) {
         case self::ITIP_CANCEL:
             /* Cancellation. */
             $method = 'CANCEL';
             $filename = 'task-cancellation.ics';
             $view->subject = sprintf(_("Cancelled: %s"), $task->name);
             if (empty($instance)) {
                 $view->header = sprintf(_("%s has cancelled \"%s\"."), $ident->getName(), $task->name);
             } else {
                 $view->header = sprintf(_("%s has cancelled an instance of the recurring \"%s\"."), $ident->getName(), $task->name);
             }
             break;
         case self::ITIP_UPDATE:
             if (!empty($task->organizer) && $task->organizer != Nag::getUserEmail($task->creator)) {
                 // Sending a progress update.
                 $method = 'REPLY';
             } else {
                 $method = 'UPDATE';
             }
         case self::ITIP_REQUEST:
         default:
             if (empty($task->status) || $task->status == self::RESPONSE_NONE) {
                 /* Invitation. */
                 $filename = 'task-invitation.ics';
                 $view->subject = $task->name;
                 $view->header = sprintf(_("%s wishes to make you aware of \"%s\"."), $ident->getName(), $task->name);
             } else {
                 $filename = 'task-update.ics';
                 $view->subject = sprintf(_("Updated: %s."), $task->name);
                 $view->header = sprintf(_("%s wants to notify you about changes of \"%s\"."), $ident->getName(), $task->name);
             }
             break;
     }
     $view->attendees = $email;
     $view->organizer = empty($task->organizer) ? $registry->convertUserName($task->creator, false) : $task->organizer;
     /* Build the iCalendar data */
     $iCal = new Horde_Icalendar();
     $iCal->setAttribute('METHOD', $method);
     $vevent = $task->toiCalendar($iCal);
     $iCal->addComponent($vevent);
     /* text/calendar part */
     $ics = new Horde_Mime_Part();
     $ics->setType('text/calendar');
     $ics->setContents($iCal->exportvCalendar());
     $ics->setName($filename);
     $ics->setContentTypeParameter('METHOD', $method);
     $ics->setCharset('UTF-8');
     $ics->setEOL("\r\n");
     /* application/ics part */
     $ics2 = clone $ics;
     $ics2->setType('application/ics');
     /* multipart/mixed part */
     $multipart = new Horde_Mime_Part();
     $multipart->setType('multipart/mixed');
     $inner = self::buildMimeMessage($view, 'notification', $image);
     $inner->addPart($ics);
     $multipart->addPart($inner);
     $multipart->addPart($ics2);
     $recipient = $method != 'REPLY' ? new Horde_Mail_Rfc822_Address($email) : new Horde_Mail_Rfc822_Address($task->organizer);
     $mail = new Horde_Mime_Mail(array('Subject' => $view->subject, 'To' => $recipient, 'From' => $ident->getDefaultFromAddress(true), 'User-Agent' => 'Nag ' . $registry->getVersion()));
     $mail->setBasePart($multipart);
     try {
         $mail->send($injector->getInstance('Horde_Mail'));
         $notification->push(sprintf(_("The task request notification to %s was successfully sent."), $recipient), 'horde.success');
     } catch (Horde_Mime_Exception $e) {
         $notification->push(sprintf(_("There was an error sending a task request notification to %s: %s"), $recipient, $e->getMessage(), $e->getCode()), 'horde.error');
     }
 }
Exemplo n.º 25
0
 /**
  * Generate the MDN according to the specifications listed in RFC
  * 3798 [3].
  *
  * @param boolean $action   Was this MDN type a result of a manual
  *                          action on part of the user?
  * @param boolean $sending  Was this MDN sent as a result of a manual
  *                          action on part of the user?
  * @param string $type      The type of action performed by the user.
  *                          Per RFC 3798 [3.2.6.2] the following types are
  *                          valid:
  *                            - deleted
  *                            - displayed
  * @param string $name      The name of the local server.
  * @param Horde_Mail_Transport $mailer  Mail transport object.
  * @param array $opts       Additional options:
  *   - charset: (string) Default charset.
  *              DEFAULT: NONE
  *   - from_addr: (string) From address.
  *                DEFAULT: NONE
  * @param array $mod        The list of modifications. Per RFC 3798
  *                          [3.2.6.3] the following modifications are
  *                          valid:
  *                            - error
  * @param array $err        If $mod is 'error', the additional
  *                          information to provide. Key is the type of
  *                          modification, value is the text.
  */
 public function generate($action, $sending, $type, $name, $mailer, array $opts = array(), array $mod = array(), array $err = array())
 {
     $opts = array_merge(array('charset' => null, 'from_addr' => null), $opts);
     if (!($hdr = $this->_headers[self::MDN_HEADER])) {
         throw new RuntimeException('Need at least one address to send MDN to.');
     }
     $to = $hdr->getAddressList(true);
     $ua = Horde_Mime_Headers_UserAgent::create();
     if ($orig_recip = $this->_headers['Original-Recipient']) {
         $orig_recip = $orig_recip->value_single;
     }
     /* Set up the mail headers. */
     $msg_headers = new Horde_Mime_Headers();
     $msg_headers->addHeaderOb(Horde_Mime_Headers_MessageId::create());
     $msg_headers->addHeaderOb($ua);
     /* RFC 3834 [5.2] */
     $msg_headers->addHeader('Auto-Submitted', 'auto-replied');
     $msg_headers->addHeaderOb(Horde_Mime_Headers_Date::create());
     if ($opts['from_addr']) {
         $msg_headers->addHeader('From', $opts['from_addr']);
     }
     $msg_headers->addHeader('To', $to);
     $msg_headers->addHeader('Subject', Horde_Mime_Translation::t("Disposition Notification"));
     /* MDNs are a subtype of 'multipart/report'. */
     $msg = new Horde_Mime_Part();
     $msg->setType('multipart/report');
     $msg->setContentTypeParameter('report-type', 'disposition-notification');
     /* The first part is a human readable message. */
     $part_one = new Horde_Mime_Part();
     $part_one->setType('text/plain');
     $part_one->setCharset($opts['charset']);
     if ($type == 'displayed') {
         $contents = sprintf(Horde_Mime_Translation::t("The message sent on %s to %s with subject \"%s\" has been displayed.\n\nThis is no guarantee that the message has been read or understood."), $this->_headers['Date'], $this->_headers['To'], $this->_headers['Subject']);
         $flowed = new Horde_Text_Flowed($contents, $opts['charset']);
         $flowed->setDelSp(true);
         $part_one->setContentTypeParameter('format', 'flowed');
         $part_one->setContentTypeParameter('DelSp', 'Yes');
         $part_one->setContents($flowed->toFlowed());
     }
     // TODO: Messages for other notification types.
     $msg[] = $part_one;
     /* The second part is a machine-parseable description. */
     $part_two = new Horde_Mime_Part();
     $part_two->setType('message/disposition-notification');
     $part_two_h = new Horde_Mime_Headers();
     $part_two_h->addHeader('Reporting-UA', $name . '; ' . $ua);
     if (!empty($orig_recip)) {
         $part_two_h->addHeader('Original-Recipient', 'rfc822;' . $orig_recip);
     }
     if ($opts['from_addr']) {
         $part_two_h->addHeader('Final-Recipient', 'rfc822;' . $opts['from_addr']);
     }
     if ($msg_id = $this->_headers['Message-ID']) {
         $part_two_h->addHeader('Original-Message-ID', strval($msg_id));
     }
     /* Create the Disposition field now (RFC 3798 [3.2.6]). */
     $dispo = ($action ? 'manual-action' : 'automatic-action') . '/' . ($sending ? 'MDN-sent-manually' : 'MDN-sent-automatically') . '; ' . $type;
     if (!empty($mod)) {
         $dispo .= '/' . implode(', ', $mod);
     }
     $part_two_h->addHeader('Disposition', $dispo);
     if (in_array('error', $mod) && isset($err['error'])) {
         $part_two_h->addHeader('Error', $err['error']);
     }
     $part_two->setContents(trim($part_two_h->toString()) . "\n");
     $msg[] = $part_two;
     /* The third part is the text of the original message.  RFC 3798 [3]
      * allows us to return only a portion of the entire message - this
      * is left up to the user. */
     $part_three = new Horde_Mime_Part();
     $part_three->setType('message/rfc822');
     $part_three_text = array(trim($this->_headers->toString()) . "\n");
     if (!empty($this->_msgtext)) {
         $part_three_text[] = "\n" . $this->_msgtext;
     }
     $part_three->setContents($part_three_text);
     $msg[] = $part_three;
     return $msg->send($to, $msg_headers, $mailer);
 }
Exemplo n.º 26
0
Arquivo: Pgp.php Projeto: horde/horde
 /**
  * Generates a Horde_Mime_Part object, in accordance with RFC 3156, that
  * contains a public key.
  *
  * @param string $key  The public key.
  *
  * @return Horde_Mime_Part  An object that contains the public key.
  */
 public function publicKeyMIMEPart($key)
 {
     $part = new Horde_Mime_Part();
     $part->setType('application/pgp-keys');
     $part->setHeaderCharset('UTF-8');
     $part->setDescription(Horde_Crypt_Translation::t("PGP Public Key"));
     $part->setContents($key, array('encoding' => '7bit'));
     return $part;
 }
Exemplo n.º 27
0
 /**
  * Strips one or all MIME parts out of a message.
  *
  * @param string $partid  The MIME ID of the part to strip. All parts are
  *                        stripped if null.
  *
  * @return IMP_Indices  Returns the new indices object.
  * @throws IMP_Exception
  */
 public function stripPart($partid = null)
 {
     global $injector;
     list($mbox, $uid) = $this->getSingle();
     if (!$uid) {
         return;
     }
     if ($mbox->readonly) {
         throw new IMP_Exception(_("Cannot strip the part as the mailbox is read-only."));
     }
     $uidvalidity = $mbox->uidvalid;
     $contents = $injector->getInstance('IMP_Factory_Contents')->create($this);
     $message = $contents->getMIMEMessage();
     $boundary = trim($message->getContentTypeParameter('boundary'), '"');
     $url = new Horde_Imap_Client_Url();
     $url->mailbox = $mbox;
     $url->uid = $uid;
     $url->uidvalidity = $uidvalidity;
     $imp_imap = $mbox->imp_imap;
     /* Always add the header to output. */
     $url->section = 'HEADER';
     $parts = array(array('t' => 'url', 'v' => strval($url)));
     for ($id = 1;; ++$id) {
         if (!($part = $message[$id])) {
             break;
         }
         $parts[] = array('t' => 'text', 'v' => "\r\n--" . $boundary . "\r\n");
         if ($id != 1 && is_null($partid) || $id == $partid) {
             $newPart = new Horde_Mime_Part();
             $newPart->setType('text/plain');
             /* Need to make sure all text is in the correct charset. */
             $newPart->setCharset('UTF-8');
             $newPart->setContents(sprintf(_("[Part stripped: Original part type: %s, name: %s]"), $part->getType(), $contents->getPartName($part)));
             $newPart->setDisposition('attachment');
             $parts[] = array('t' => 'text', 'v' => $newPart->toString(array('canonical' => true, 'headers' => true, 'stream' => true)));
         } else {
             $url->section = $id . '.MIME';
             $parts[] = array('t' => 'url', 'v' => strval($url));
             $url->section = $id;
             $parts[] = array('t' => 'url', 'v' => strval($url));
         }
     }
     $parts[] = array('t' => 'text', 'v' => "\r\n--" . $boundary . "--\r\n");
     /* Get the headers for the message. */
     $query = new Horde_Imap_Client_Fetch_Query();
     $query->imapDate();
     $query->flags();
     try {
         $res = $imp_imap->fetch($mbox, $query, array('ids' => $imp_imap->getIdsOb($uid)))->first();
         if (is_null($res)) {
             throw new IMP_Imap_Exception();
         }
         $flags = $res->getFlags();
         /* If in Virtual Inbox, we need to reset flag to unseen so that it
          * appears again in the mailbox list. */
         if ($mbox->vinbox) {
             $flags = array_values(array_diff($flags, array(Horde_Imap_Client::FLAG_SEEN)));
         }
         $new_uid = $imp_imap->append($mbox, array(array('data' => $parts, 'flags' => $flags, 'internaldate' => $res->getImapDate())))->ids;
         $new_uid = reset($new_uid);
     } catch (IMP_Imap_Exception $e) {
         throw new IMP_Exception(_("An error occured while attempting to strip the part."));
     }
     $this->delete(array('keeplog' => true, 'nuke' => true));
     $indices_ob = $mbox->getIndicesOb($new_uid);
     /* We need to replace the old UID(s) in the URL params. */
     $vars = $injector->getInstance('Horde_Variables');
     if (isset($vars->buid)) {
         list(, $vars->buid) = $mbox->toBuids($indices_ob)->getSingle();
     }
     if (isset($vars->uid)) {
         $vars->uid = $new_uid;
     }
     return $indices_ob;
 }
Exemplo n.º 28
0
 public function _getMimePart($id)
 {
     $part = new Horde_Mime_Part();
     $part->setContents($this->_contentsData);
     return $part;
 }
Exemplo n.º 29
0
 /**
  * Variables required in form input:
  *   - identity (TODO: ? Code uses it, but it is never set anywhere)
  *   - imple_submit: itip_action(s)
  *   - mime_id
  *   - muid
  *
  * @return boolean  True on success.
  */
 protected function _handle(Horde_Variables $vars)
 {
     global $injector, $notification, $registry;
     $actions = (array) $vars->imple_submit;
     $result = false;
     $vCal = new Horde_Icalendar();
     /* Retrieve the calendar data from the message. */
     try {
         $contents = $injector->getInstance('IMP_Factory_Contents')->create(new IMP_Indices_Mailbox($vars));
         $mime_part = $contents->getMIMEPart($vars->mime_id);
         if (empty($mime_part)) {
             throw new IMP_Exception(_("Cannot retrieve calendar data from message."));
         } elseif (!$vCal->parsevCalendar($mime_part->getContents(), 'VCALENDAR', $mime_part->getCharset())) {
             throw new IMP_Exception(_("The calendar data is invalid"));
         }
         $components = $vCal->getComponents();
     } catch (Exception $e) {
         $notification->push($e, 'horde.error');
         $actions = array();
     }
     foreach ($actions as $key => $action) {
         $pos = strpos($key, '[');
         $key = substr($key, $pos + 1, strlen($key) - $pos - 2);
         switch ($action) {
             case 'delete':
                 // vEvent cancellation.
                 if ($registry->hasMethod('calendar/delete')) {
                     $guid = $components[$key]->getAttribute('UID');
                     $recurrenceId = null;
                     try {
                         // This is a cancellation of a recurring event instance.
                         $recurrenceId = $components[$key]->getAttribute('RECURRENCE-ID');
                         $atts = $components[$key]->getAttribute('RECURRENCE-ID', true);
                         $range = null;
                         foreach ($atts as $att) {
                             if (array_key_exists('RANGE', $att)) {
                                 $range = $att['RANGE'];
                             }
                         }
                     } catch (Horde_Icalendar_Exception $e) {
                     }
                     try {
                         $registry->call('calendar/delete', array($guid, $recurrenceId, $range));
                         $notification->push(_("Event successfully deleted."), 'horde.success');
                         $result = true;
                     } catch (Horde_Exception $e) {
                         $notification->push(sprintf(_("There was an error deleting the event: %s"), $e->getMessage()), 'horde.error');
                     }
                 } else {
                     $notification->push(_("This action is not supported."), 'horde.warning');
                 }
                 break;
             case 'update':
                 // vEvent reply.
                 if ($registry->hasMethod('calendar/updateAttendee')) {
                     try {
                         $from = $contents->getHeader()->getOb('from');
                         $registry->call('calendar/updateAttendee', array($components[$key], $from[0]->bare_address));
                         $notification->push(_("Respondent Status Updated."), 'horde.success');
                         $result = true;
                     } catch (Horde_Exception $e) {
                         $notification->push(sprintf(_("There was an error updating the event: %s"), $e->getMessage()), 'horde.error');
                     }
                 } else {
                     $notification->push(_("This action is not supported."), 'horde.warning');
                 }
                 break;
             case 'import':
             case 'accept-import':
                 // vFreebusy reply.
                 // vFreebusy publish.
                 // vEvent request.
                 // vEvent publish.
                 // vTodo publish.
                 // vJournal publish.
                 switch ($components[$key]->getType()) {
                     case 'vEvent':
                         $result = $this->_handlevEvent($key, $components, $mime_part);
                         // Must check for exceptions.
                         foreach ($components as $k => $component) {
                             try {
                                 if ($component->getType() == 'vEvent' && $component->getAttribute('RECURRENCE-ID')) {
                                     $uid = $component->getAttribute('UID');
                                     if ($uid == $components[$key]->getAttribute('UID')) {
                                         $this->_handlevEvent($k, $components, $mime_part);
                                     }
                                 }
                             } catch (Horde_Icalendar_Exception $e) {
                             }
                         }
                         break;
                     case 'vFreebusy':
                         // Import into Kronolith.
                         if ($registry->hasMethod('calendar/import_vfreebusy')) {
                             try {
                                 $registry->call('calendar/import_vfreebusy', array($components[$key]));
                                 $notification->push(_("The user's free/busy information was sucessfully stored."), 'horde.success');
                                 $result = true;
                             } catch (Horde_Exception $e) {
                                 $notification->push(sprintf(_("There was an error importing user's free/busy information: %s"), $e->getMessage()), 'horde.error');
                             }
                         } else {
                             $notification->push(_("This action is not supported."), 'horde.warning');
                         }
                         break;
                     case 'vTodo':
                         // Import into Nag.
                         if ($registry->hasMethod('tasks/import')) {
                             try {
                                 $guid = $registry->call('tasks/import', array($components[$key], $mime_part->getType()));
                                 $url = Horde::url($registry->link('tasks/show', array('uid' => $guid)));
                                 $notification->push(_("The task has been added to your tasklist.") . '&nbsp;' . Horde::link($url, _("View task"), null, '_blank') . Horde_Themes_Image::tag('mime/icalendar.png', array('alt' => _("View task"))) . '</a>', 'horde.success', array('content.raw'));
                                 $result = true;
                             } catch (Horde_Exception $e) {
                                 $notification->push(sprintf(_("There was an error importing the task: %s"), $e->getMessage()), 'horde.error');
                             }
                         } else {
                             $notification->push(_("This action is not supported."), 'horde.warning');
                         }
                         break;
                     case 'vJournal':
                     default:
                         $notification->push(_("This action is not supported."), 'horde.warning');
                 }
                 if ($action == 'import') {
                     break;
                 }
                 // Fall-through for 'accept-import'
             // Fall-through for 'accept-import'
             case 'accept':
             case 'deny':
             case 'tentative':
                 // vEvent request.
                 if (isset($components[$key]) && $components[$key]->getType() == 'vEvent') {
                     $vEvent = $components[$key];
                     $resource = new Horde_Itip_Resource_Identity($injector->getInstance('IMP_Identity'), $vEvent->getAttribute('ATTENDEE'), $vars->identity);
                     switch ($action) {
                         case 'accept':
                         case 'accept-import':
                             $type = new Horde_Itip_Response_Type_Accept($resource);
                             break;
                         case 'deny':
                             $type = new Horde_Itip_Response_Type_Decline($resource);
                             break;
                         case 'tentative':
                             $type = new Horde_Itip_Response_Type_Tentative($resource);
                             break;
                     }
                     try {
                         // Send the reply.
                         Horde_Itip::factory($vEvent, $resource)->sendMultiPartResponse($type, new Horde_Core_Itip_Response_Options_Horde('UTF-8', array()), $injector->getInstance('IMP_Mail'));
                         $notification->push(_("Reply Sent."), 'horde.success');
                         $result = true;
                     } catch (Horde_Itip_Exception $e) {
                         $notification->push(sprintf(_("Error sending reply: %s."), $e->getMessage()), 'horde.error');
                     }
                 } else {
                     $notification->push(_("This action is not supported."), 'horde.warning');
                 }
                 break;
             case 'send':
             case 'reply':
             case 'reply2m':
                 // vfreebusy request.
                 if (isset($components[$key]) && $components[$key]->getType() == 'vFreebusy') {
                     $vFb = $components[$key];
                     // Get the organizer details.
                     try {
                         $organizer = parse_url($vFb->getAttribute('ORGANIZER'));
                     } catch (Horde_Icalendar_Exception $e) {
                         break;
                     }
                     $organizerEmail = $organizer['path'];
                     $organizer = $vFb->getAttribute('ORGANIZER', true);
                     $organizerFullEmail = new Horde_Mail_Rfc822_Address($organizerEmail);
                     if (isset($organizer['cn'])) {
                         $organizerFullEmail->personal = $organizer['cn'];
                     }
                     if ($action == 'reply2m') {
                         $startStamp = time();
                         $endStamp = $startStamp + 60 * 24 * 3600;
                     } else {
                         try {
                             $startStamp = $vFb->getAttribute('DTSTART');
                         } catch (Horde_Icalendar_Exception $e) {
                             $startStamp = time();
                         }
                         try {
                             $endStamp = $vFb->getAttribute('DTEND');
                         } catch (Horde_Icalendar_Exception $e) {
                         }
                         if (!$endStamp) {
                             try {
                                 $duration = $vFb->getAttribute('DURATION');
                                 $endStamp = $startStamp + $duration;
                             } catch (Horde_Icalendar_Exception $e) {
                                 $endStamp = $startStamp + 60 * 24 * 3600;
                             }
                         }
                     }
                     $vfb_reply = $registry->call('calendar/getFreeBusy', array($startStamp, $endStamp));
                     // Find out who we are and update status.
                     $identity = $injector->getInstance('IMP_Identity');
                     $email = $identity->getFromAddress();
                     // Build the reply.
                     $msg_headers = new Horde_Mime_Headers();
                     $vCal = new Horde_Icalendar();
                     $vCal->setAttribute('PRODID', '-//The Horde Project//' . $msg_headers->getUserAgent() . '//EN');
                     $vCal->setAttribute('METHOD', 'REPLY');
                     $vCal->addComponent($vfb_reply);
                     $message = _("Attached is a reply to a calendar request you sent.");
                     $body = new Horde_Mime_Part();
                     $body->setType('text/plain');
                     $body->setCharset('UTF-8');
                     $body->setContents(Horde_String::wrap($message, 76));
                     $ics = new Horde_Mime_Part();
                     $ics->setType('text/calendar');
                     $ics->setCharset('UTF-8');
                     $ics->setContents($vCal->exportvCalendar());
                     $ics->setName('icalendar.ics');
                     $ics->setContentTypeParameter('METHOD', 'REPLY');
                     $mime = new Horde_Mime_Part();
                     $mime->addPart($body);
                     $mime->addPart($ics);
                     // Build the reply headers.
                     $msg_headers->addReceivedHeader(array('dns' => $injector->getInstance('Net_DNS2_Resolver'), 'server' => $conf['server']['name']));
                     $msg_headers->addMessageIdHeader();
                     $msg_headers->addHeader('Date', date('r'));
                     $msg_headers->addHeader('From', $email);
                     $msg_headers->addHeader('To', $organizerFullEmail);
                     $identity->setDefault($vars->identity);
                     $replyto = $identity->getValue('replyto_addr');
                     if (!empty($replyto) && !$email->match($replyto)) {
                         $msg_headers->addHeader('Reply-To', $replyto);
                     }
                     $msg_headers->addHeader('Subject', _("Free/Busy Request Response"));
                     // Send the reply.
                     try {
                         $mime->send($organizerEmail, $msg_headers, $injector->getInstance('IMP_Mail'));
                         $notification->push(_("Reply Sent."), 'horde.success');
                         $result = true;
                     } catch (Exception $e) {
                         $notification->push(sprintf(_("Error sending reply: %s."), $e->getMessage()), 'horde.error');
                     }
                 } else {
                     $notification->push(_("Invalid Action selected for this component."), 'horde.warning');
                 }
                 break;
             case 'nosup':
                 // vFreebusy request.
             // vFreebusy request.
             default:
                 $notification->push(_("This action is not supported."), 'horde.warning');
                 break;
         }
     }
     return $result;
 }
Exemplo n.º 30
0
 /* Check for required elements. */
 $from = Horde_Util::getFormData('ecard_retaddr');
 if (empty($from)) {
     $notification->push(_("You must enter your e-mail address."), 'horde.error');
     break;
 }
 $to = Horde_Util::getFormData('ecard_addr');
 if (empty($to)) {
     $notification->push(_("You must enter an e-mail address to send the message to."), 'horde.error');
     break;
 }
 /* Create the text part. */
 $textpart = new Horde_Mime_Part();
 $textpart->setType('text/plain');
 $textpart->setCharset('UTF-8');
 $textpart->setContents(_("You have been sent an Ecard. To view the Ecard, you must be able to view text/html messages in your mail reader. If you are viewing this message, then most likely your mail reader does not support viewing text/html messages."));
 /* Create the multipart/related part. */
 $related = new Horde_Mime_Part();
 $related->setType('multipart/related');
 /* Create the HTML part. */
 $htmlpart = new Horde_Mime_Part();
 $htmlpart->setType('text/html');
 $htmlpart->setCharset('UTF-8');
 /* The image part */
 $imgpart = new Horde_Mime_Part();
 $imgpart->setType($image->getType('screen'));
 $imgpart->setContents($image->raw('screen'));
 $img_tag = '<img src="cid:' . $imgpart->setContentID() . '" /><p />';
 $comments = $htmlpart->replaceEOL(Horde_Util::getFormData('ecard_comments'));
 if (!Horde_Util::getFormData('rtemode')) {
     $comments = '<pre>' . htmlspecialchars($comments, ENT_COMPAT, 'UTF-8') . '</pre>';