toString() 공개 메소드

Return the entire part in MIME format.
public toString ( array $options = [] ) : mixed
$options array Additional options: - canonical: (boolean) Returns the encoded part in strict RFC 822 & 2045 output - namely, all newlines end with the canonical sequence. DEFAULT: false - defserver: (string) The default server to use when creating the header string. DEFAULT: none - encode: (integer) A mask of allowable encodings. DEFAULT: self::ENCODE_7BIT - headers: (mixed) Include the MIME headers? If true, create a new headers object. If a Horde_Mime_Headers object, add MIME headers to this object. If a string, use the string verbatim. DEFAULT: true - id: (string) Return only this MIME ID part. DEFAULT: Returns the base part. - stream: (boolean) Return a stream resource. DEFAULT: false
리턴 mixed The MIME string (returned as a resource if $stream is true).
예제 #1
0
파일: Contents.php 프로젝트: horde/horde
 /**
  * Returns the full message text.
  *
  * @param array $options  Additional options:
  *   - stream: (boolean) If true, return a stream for bodytext.
  *             DEFAULT: No
  *
  * @return mixed  The full message text or a stream resource if 'stream'
  *                is true.
  */
 public function fullMessageText($options = array())
 {
     if (!$this->_indices) {
         return $this->_message->toString();
     }
     $query = new Horde_Imap_Client_Fetch_Query();
     $query->bodyText(array('peek' => true));
     if ($res = $this->_fetchData($query)) {
         try {
             if (empty($options['stream'])) {
                 return $this->getHeader(self::HEADER_TEXT) . $res->getBodyText(0);
             }
             return Horde_Stream_Wrapper_Combine::getStream(array($this->getHeader(self::HEADER_STREAM), $res->getBodyText(0, true)));
         } catch (Horde_Exception $e) {
         }
     }
     return empty($options['stream']) ? '' : fopen('php://temp', 'r+');
 }
예제 #2
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()));
    }
예제 #3
0
파일: Rfc822.php 프로젝트: jubinpatel/horde
 /**
  * Replace the MIME part of the message sent from the client.
  *
  * @param  Horde_Mime_Part $part  The new MIME part.
  * @since 2.19.0
  */
 public function replaceMime(Horde_Mime_Part $part)
 {
     $mime_stream = $part->toString(array('stream' => true, 'headers' => false));
     if (!empty($this->_header_text)) {
         $hdr = $this->_header_text;
     } else {
         $this->_stream->rewind();
         $hdr = $this->_stream->substring(0, $this->_hdr_pos);
     }
     $new_stream = Horde_Stream_Wrapper_Combine::getStream(array($hdr, $mime_stream));
     $this->_parseStream(new Horde_Stream_Existing(array('stream' => $new_stream)));
 }
예제 #4
0
파일: Indices.php 프로젝트: horde/horde
 /**
  * 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;
 }
예제 #5
0
파일: Mime.php 프로젝트: horde/horde
 /**
  * Signs and encrypts a MIME part using PGP.
  *
  * @param Horde_Mime_Part $part  The part to sign and encrypt.
  * @param mixed $privkey         The private key to use for signing (must
  *                               be decrypted).
  * @param array $opts            Additional options:
  *   - cipher: (string) Default symmetric cipher algorithm to use.
  *   - compress: (string) Default compression algorithm.
  *   - pubkeys: (mixed) The public key(s) to use for encryption.
  *   - symmetric: (string) If set, use as symmetric key.
  *
  * @return Horde_Mime_Part  A signed and encrypted part.
  * @throws Horde_Pgp_Exception
  */
 public function signAndEncryptPart(Horde_Mime_Part $part, $privkey, array $opts = array())
 {
     /* We use the combined method of sign & encryption in a single
      * OpenPGP packet (RFC 3156 [6.2]). */
     $signed = $this->sign($part->toString(array('canonical' => true, 'headers' => true)), $privkey, $opts);
     $base = $this->_encryptPart($signed->message, array_merge($opts, array('compress' => 'NONE')));
     $base->setDescription(Horde_Pgp_Translation::t("PGP Signed/Encrypted Data"));
     $base->setContents("This message is in MIME format and has been PGP signed and encrypted.\n");
     return $base;
 }
예제 #6
0
파일: Rfc822.php 프로젝트: horde/horde
 /**
  * Replace the MIME part of the message sent from the client. Headers from
  * the original message are always used.
  *
  * @param  Horde_Mime_Part $part  The new MIME part.
  * @since 2.19.0
  */
 public function replaceMime(Horde_Mime_Part $part)
 {
     $mime_stream = $part->toString(array('stream' => true, 'headers' => false));
     $mime_stream = new Horde_Stream_Existing(array('stream' => $mime_stream));
     // Since we are still using the headers sent from the device, we can
     // simply zero out the position members etc...
     $this->_hdr_pos = 0;
     $this->_stream = $mime_stream;
     $mime_stream->rewind();
 }
예제 #7
0
파일: Object.php 프로젝트: raz0rsdge/horde
 /**
  * Append a new message.
  *
  * @param Horde_Mime_Part $message The message.
  * @param Horde_Mime_Headers $headers The message headers.
  *
  * @return boolean|string The return value of the append operation.
  * @throws Horde_Kolab_Storage_Object_Exception
  */
 protected function _appendMessage(Horde_Mime_Part $message, Horde_Mime_Headers $headers)
 {
     $result = $this->_getDriver()->appendMessage($this->_getFolder(), $message->toString(array('canonical' => true, 'stream' => true, 'headers' => $headers)));
     if (is_object($result) || $result === false || $result === null) {
         throw new Horde_Kolab_Storage_Object_Exception(sprintf('Unexpected return value (%s) when creating an object in folder "%s"!', print_r($result, true), $this->_getFolder()));
     }
     if ($result !== true) {
         $this->_backend_id = $result;
     }
     return $result;
 }
예제 #8
0
파일: Pgp.php 프로젝트: horde/horde
 /**
  * Encrypts a MIME part using PGP.
  *
  * @param Horde_Mime_Part $mime_part  The object to encrypt.
  * @param array $params               The parameters required for
  *                                    encryption
  *                                    ({@see _encryptMessage()}).
  *
  * @return mixed  A Horde_Mime_Part object that is encrypted according to
  *                RFC 3156.
  * @throws Horde_Crypt_Exception
  */
 public function encryptMIMEPart($mime_part, $params = array())
 {
     $params = array_merge($params, array('type' => 'message'));
     $signenc_body = $mime_part->toString(array('canonical' => true, 'headers' => true));
     $message_encrypt = $this->encrypt($signenc_body, $params);
     /* Set up MIME Structure according to RFC 3156. */
     $part = new Horde_Mime_Part();
     $part->setType('multipart/encrypted');
     $part->setHeaderCharset('UTF-8');
     $part->setContentTypeParameter('protocol', 'application/pgp-encrypted');
     $part->setDescription(Horde_Crypt_Translation::t("PGP Encrypted Data"));
     $part->setContents("This message is in MIME format and has been PGP encrypted.\n");
     $part1 = new Horde_Mime_Part();
     $part1->setType('application/pgp-encrypted');
     $part1->setCharset(null);
     $part1->setContents("Version: 1\n", array('encoding' => '7bit'));
     $part->addPart($part1);
     $part2 = new Horde_Mime_Part();
     $part2->setType('application/octet-stream');
     $part2->setCharset(null);
     $part2->setContents($message_encrypt, array('encoding' => '7bit'));
     $part2->setDisposition('inline');
     $part->addPart($part2);
     return $part;
 }
예제 #9
0
파일: PartTest.php 프로젝트: x59/horde-mime
 public function testMultipartDigest()
 {
     $part = new Horde_Mime_Part();
     $part->setType('multipart/digest');
     $part->isBasePart(true);
     $part2 = new Horde_Mime_Part();
     $part2->setType('message/rfc822');
     $part2->setContents(file_get_contents(__DIR__ . '/fixtures/sample_msg4.txt'));
     $part[] = $part2;
     $this->assertStringMatchesFormat("Content-Type: multipart/digest; boundary=\"=_%s\"\nMIME-Version: 1.0\n\nThis message is in MIME format.\n\n--=_%s\n\nMessage-ID: <*****@*****.**>\nDate: Tue, 07 Jul 2013 10:21:48 -0600\nFrom: \"Test Q. User\" <*****@*****.**>\nTo: foo@example.com\nSubject: Test\nMIME-Version: 1.0\n\n\nTest.\n\n--=_%s--", $part->toString(array('headers' => true)));
 }
예제 #10
0
파일: Smime.php 프로젝트: jubinpatel/horde
 /**
  * Encrypt a MIME part using S/MIME. This produces S/MIME Version 3.2
  * compatible data (see RFC 5751 [3.3]).
  *
  * @param Horde_Mime_Part $mime_part  The object to encrypt.
  * @param array $params               The parameters required for
  *                                    encryption.
  *
  * @return Horde_Mime_Part  An encrypted MIME part object.
  * @throws Horde_Crypt_Exception
  */
 public function encryptMIMEPart($mime_part, $params = array())
 {
     /* Sign the part as a message */
     $message = $this->encrypt($mime_part->toString(array('headers' => true, 'canonical' => true)), $params);
     $msg = new Horde_Mime_Part();
     $msg->setCharset($this->_params['email_charset']);
     $msg->setHeaderCharset('UTF-8');
     $msg->setDescription(Horde_Crypt_Translation::t("S/MIME Encrypted Message"));
     $msg->setDisposition('inline');
     $msg->setType('application/pkcs7-mime');
     $msg->setContentTypeParameter('smime-type', 'enveloped-data');
     $msg->setContents(substr($message, strpos($message, "\n\n") + 2), array('encoding' => 'base64'));
     return $msg;
 }
예제 #11
0
파일: Compose.php 프로젝트: raz0rsdge/horde
 /**
  * Save message to sent-mail mailbox, if configured to do so.
  *
  * @param Horde_Mime_Headers $headers     Headers object.
  * @param Horde_Mime_Part $save_msg       Message data to save.
  * @param Horde_Mail_Rfc822_List $recips  Recipient list.
  * @param array $opts                     See buildAndSendMessage()
  */
 protected function _saveToSentMail(Horde_Mime_Headers $headers, Horde_Mime_Part $save_msg, Horde_Mail_Rfc822_List $recips, $opts)
 {
     global $injector, $language, $notification, $prefs;
     if (empty($opts['sent_mail']) || $prefs->isLocked('save_sent_mail') && !$prefs->getValue('save_sent_mail') || !$prefs->isLocked('save_sent_mail') && empty($opts['save_sent'])) {
         return;
     }
     $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
     /* If message contains EAI addresses, we need to verify that the IMAP
      * server can handle this data in order to save. */
     foreach ($recips as $val) {
         if ($val->eai) {
             if ($imp_imap->client_ob->capability->query('UTF8', 'ACCEPT')) {
                 break;
             }
             $notification->push(sprintf(_("Message sent successfully, but not saved to %s."), $sent_mail->display));
             return;
         }
     }
     /* Strip attachments if requested. */
     if (!empty($opts['strip_attachments'])) {
         $save_msg->buildMimeIds();
         /* Don't strip any part if this is a text message with both
          * plaintext and HTML representation. */
         if ($save_msg->getType() != 'multipart/alternative') {
             for ($i = 2;; ++$i) {
                 if (!($oldPart = $save_msg[$i])) {
                     break;
                 }
                 $replace_part = new Horde_Mime_Part();
                 $replace_part->setType('text/plain');
                 $replace_part->setCharset($this->charset);
                 $replace_part->setLanguage($language);
                 $replace_part->setContents('[' . _("Attachment stripped: Original attachment type") . ': "' . $oldPart->getType() . '", ' . _("name") . ': "' . $oldPart->getName(true) . '"]');
                 $save_msg[$i] = $replace_part;
             }
         }
     }
     /* Generate the message string. */
     $fcc = $save_msg->toString(array('defserver' => $imp_imap->config->maildomain, 'headers' => $headers, 'stream' => true));
     /* Make sure sent mailbox is created. */
     $sent_mail = IMP_Mailbox::get($opts['sent_mail']);
     $sent_mail->create();
     $flags = array(Horde_Imap_Client::FLAG_SEEN, Horde_Imap_Client::FLAG_MDNSENT);
     try {
         $imp_imap->append($sent_mail, array(array('data' => $fcc, 'flags' => $flags)));
     } catch (IMP_Imap_Exception $e) {
         $notification->push(sprintf(_("Message sent successfully, but not saved to %s."), $sent_mail->display));
     }
 }
예제 #12
0
 public function testQuotedPrintableNewlines()
 {
     $part = new Horde_Mime_Part();
     $part->setType('text/plain');
     $part->setContents("A\r\nBā\r\nC");
     $this->assertEquals("A\r\nB=C4=81\r\nC", $part->toString());
     $part->setEOL("\r\n");
     $this->assertEquals("A\r\nB=C4=81\r\nC", $part->toString());
     $part2 = new Horde_Mime_Part();
     $part2->setType('multipart/mixed');
     $part2->addPart($part);
     $this->assertStringMatchesFormat("This message is in MIME format.\n\n--=_%s\nContent-Type: text/plain\nContent-Transfer-Encoding: quoted-printable\n\nA\nB=C4=81\nC\n--=_%s--", $part2->toString());
 }
예제 #13
0
파일: Draft.php 프로젝트: horde/horde
 /**
  * Append the current Draft message to the IMAP server.
  *
  * @return array  An array with the following keys:
  *     - uid: (integer)   The new draft message's IMAP UID.
  *     - atchash: (array) An attachment hash of newly added attachments.
  */
 public function append($folderid)
 {
     // Init
     $atc_map = array();
     $atc_hash = array();
     // Create the wrapper part.
     $base = new Horde_Mime_Part();
     $base->setType('multipart/mixed');
     // Check to see if we have any existing parts to add.
     if (!empty($this->_imapMessage)) {
         foreach ($this->_imapMessage->getStructure() as $part) {
             if ($part->isAttachment() && !in_array($part->getMimeId(), $this->_atcDelete)) {
                 $base->addPart($this->_imapMessage->getMimePart($part->getMimeId()));
             }
         }
     }
     // Add body
     $base->addPart($this->_textPart);
     // Add Mime headers
     $base->addMimeHeaders(array('headers' => $this->_headers));
     foreach ($this->_atcAdd as $atc) {
         $base->addPart($atc);
         $atc_map[$atc->displayname] = $atc->clientid;
     }
     $stream = $base->toString(array('stream' => true, 'headers' => $this->_headers->toString()));
     $new_uid = $this->_imap->appendMessage($folderid, $stream, array('\\draft', '\\seen'));
     foreach ($base as $part) {
         if ($part->isAttachment() && !empty($atc_map[$part->getName()])) {
             $atc_hash['add'][$atc_map[$part->getName()]] = $folderid . ':' . $stat['id'] . ':' . $part->getMimeId();
         }
     }
     // If we pulled down an existing Draft, delete it now since the
     // new one will replace it.
     if (!empty($this->_imapMessage)) {
         $this->_imap->deleteMessages(array($this->_draftUid), $folderid);
     }
     return array('uid' => $new_uid, 'atchash' => $atc_hash);
 }