bodyText() 공개 메소드

Body text is defined only for the base RFC 2822 message or message/rfc822 parts.
public bodyText ( array $opts = [] )
$opts array The following options are available: - id: (string) The MIME ID to obtain the body text for. DEFAULT: The body text for the entire message will be returned. - length: (integer) The length of the substring to return. DEFAULT: The entire text is returned. - peek: (boolean) If set, does not set the '\Seen' flag on the message. DEFAULT: The seen flag is set. - start: (integer) If a portion of the full text is desired to be returned, the starting position is identified here. DEFAULT: The entire text is returned.
예제 #1
0
파일: Generate.php 프로젝트: DSNS-LAB/Dmail
 /**
  * Generates a string that can be saved out to an mbox format mailbox file
  * for a mailbox (or set of mailboxes), optionally including all
  * subfolders of the selected mailbox(es) as well. All mailboxes will be
  * output in the same string.
  *
  * @param mixed $mboxes  A mailbox name (UTF-8), or list of mailbox names,
  *                       to generate a mbox file for.
  *
  * @return resource  A stream resource containing the text of a mbox
  *                   format mailbox file.
  */
 public function generate($mboxes)
 {
     $body = fopen('php://temp', 'r+');
     if (!is_array($mboxes)) {
         if (!strlen($mboxes)) {
             return $body;
         }
         $mboxes = array($mboxes);
     }
     if (empty($mboxes)) {
         return $body;
     }
     $query = new Horde_Imap_Client_Fetch_Query();
     $query->envelope();
     $query->imapDate();
     $query->headerText(array('peek' => true));
     $query->bodyText(array('peek' => true));
     foreach (IMP_Mailbox::get($mboxes) as $val) {
         $imp_imap = $val->imp_imap;
         $slices = $imp_imap->getSlices($val, $imp_imap->getIdsOb(Horde_Imap_Client_Ids::ALL, true));
         foreach ($slices as $slice) {
             try {
                 $res = $imp_imap->fetch($val, $query, array('ids' => $slice, 'nocache' => true));
             } catch (IMP_Imap_Exception $e) {
                 continue;
             }
             foreach ($res as $ptr) {
                 $from_env = $ptr->getEnvelope()->from;
                 $from = count($from_env) ? $from_env[0]->bare_address : '<>';
                 /* We need this long command since some MUAs (e.g. pine)
                  * require a space in front of single digit days. */
                 $imap_date = $ptr->getImapDate();
                 $date = sprintf('%s %2s %s', $imap_date->format('D M'), $imap_date->format('j'), $imap_date->format('H:i:s Y'));
                 fwrite($body, 'From ' . $from . ' ' . $date . "\r\n");
                 /* Remove spurious 'From ' line in headers. */
                 $stream = $ptr->getHeaderText(0, Horde_Imap_Client_Data_Fetch::HEADER_STREAM);
                 while (!feof($stream)) {
                     $line = fgets($stream);
                     if (substr($line, 0, 5) != 'From ') {
                         fwrite($body, $line);
                     }
                 }
                 fwrite($body, "\r\n");
                 /* Add Body text. */
                 $stream = $ptr->getBodyText(0, true);
                 while (!feof($stream)) {
                     fwrite($body, fread($stream, 8192));
                 }
                 fwrite($body, "\r\n");
             }
         }
     }
     return $body;
 }
예제 #2
0
 /**
  * Given an IMAP URL, fetches the corresponding part.
  *
  * @param Horde_Imap_Client_Url $url  An IMAP URL.
  *
  * @return resource  The section contents in a stream. Returns null if
  *                   the part could not be found.
  *
  * @throws Horde_Imap_Client_Exception
  */
 public function fetchFromUrl(Horde_Imap_Client_Url $url)
 {
     $ids_ob = $this->_socket->getIdsOb($url->uid);
     // BODY[]
     if (is_null($section)) {
         $query = new Horde_Imap_Client_Fetch_Query();
         $query->fullText(array('peek' => true));
         $fetch = $this->_socket->fetch($url->mailbox, $query, array('ids' => $ids_ob));
         return $fetch[$url->uid]->getFullMsg(true);
     }
     $section = trim($url->section);
     // BODY[<#.>HEADER.FIELDS<.NOT>()]
     if (($pos = stripos($section, 'HEADER.FIELDS')) !== false) {
         $hdr_pos = strpos($section, '(');
         $cmd = substr($section, 0, $hdr_pos);
         $query = new Horde_Imap_Client_Fetch_Query();
         $query->headers('section', explode(' ', substr($section, $hdr_pos + 1, strrpos($section, ')') - $hdr_pos)), array('id' => $pos ? substr($section, 0, $pos - 1) : 0, 'notsearch' => stripos($cmd, '.NOT') !== false, 'peek' => true));
         $fetch = $this->_socket->fetch($url->mailbox, $query, array('ids' => $ids_ob));
         return $fetch[$url->uid]->getHeaders('section', Horde_Imap_Client_Data_Fetch::HEADER_STREAM);
     }
     // BODY[#]
     if (is_numeric(substr($section, -1))) {
         $query = new Horde_Imap_Client_Fetch_Query();
         $query->bodyPart($section, array('peek' => true));
         $fetch = $this->_socket->fetch($url->mailbox, $query, array('ids' => $ids_ob));
         return $fetch[$url->uid]->getBodyPart($section, true);
     }
     // BODY[<#.>HEADER]
     if (($pos = stripos($section, 'HEADER')) !== false) {
         $id = $pos ? substr($section, 0, $pos - 1) : 0;
         $query = new Horde_Imap_Client_Fetch_Query();
         $query->headerText(array('id' => $id, 'peek' => true));
         $fetch = $this->_socket->fetch($url->mailbox, $query, array('ids' => $ids_ob));
         return $fetch[$url->uid]->getHeaderText($id, Horde_Imap_Client_Data_Fetch::HEADER_STREAM);
     }
     // BODY[<#.>TEXT]
     if (($pos = stripos($section, 'TEXT')) !== false) {
         $id = $pos ? substr($section, 0, $pos - 1) : 0;
         $query = new Horde_Imap_Client_Fetch_Query();
         $query->bodyText(array('id' => $id, 'peek' => true));
         $fetch = $this->_socket->fetch($url->mailbox, $query, array('ids' => $ids_ob));
         return $fetch[$url->uid]->getBodyText($id, true);
     }
     // BODY[<#.>MIMEHEADER]
     if (($pos = stripos($section, 'MIME')) !== false) {
         $id = $pos ? substr($section, 0, $pos - 1) : 0;
         $query = new Horde_Imap_Client_Fetch_Query();
         $query->mimeHeader($id, array('peek' => true));
         $fetch = $this->_socket->fetch($url->mailbox, $query, array('ids' => $ids_ob));
         return $fetch[$url->uid]->getMimeHeader($id, Horde_Imap_Client_Data_Fetch::HEADER_STREAM);
     }
     return null;
 }
예제 #3
0
 private function getmsg()
 {
     $headers = array();
     $fetch_query = new \Horde_Imap_Client_Fetch_Query();
     $fetch_query->envelope();
     //		$fetch_query->fullText();
     $fetch_query->bodyText();
     $fetch_query->flags();
     $fetch_query->seq();
     $fetch_query->size();
     $fetch_query->uid();
     $fetch_query->imapDate();
     $headers = array_merge($headers, array('importance', 'list-post', 'x-priority'));
     $headers[] = 'content-type';
     $fetch_query->headers('imp', $headers, array('cache' => true, 'peek' => true));
     // $list is an array of Horde_Imap_Client_Data_Fetch objects.
     $ids = new \Horde_Imap_Client_Ids($this->message_id);
     $headers = $this->conn->fetch($this->folder_id, $fetch_query, array('ids' => $ids));
     $this->plainmsg = $headers[$this->message_id]->getBodyText();
     //
     //		// HEADER
     //		$this->header = $this->conn->fetchHeader($this->folder_id, $this->message_id);
     //
     //		// BODY
     //		$bodystructure= $this->conn->getStructure($this->folder_id, $this->message_id);
     //		$a= \rcube_imap_generic::getStructurePartData($bodystructure, 0);
     //		if ($a['type'] == 'multipart') {
     //			for ($i=0; $i < count($bodystructure); $i++) {
     //				if (!is_array($bodystructure[$i]))
     //					break;
     //				$this->getpart($bodystructure[$i],$i+1);
     //			}
     //		} else {
     //			// get part no 1
     //			$this->getpart($bodystructure,1);
     //		}
 }
예제 #4
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+');
 }
예제 #5
0
파일: Imap.php 프로젝트: horde/horde
 /**
  * @depends testOptimizedSearches
  */
 public function testComplexFetch()
 {
     // Fetching message information from complex MIME message.
     $complex_fetch = new Horde_Imap_Client_Fetch_Query();
     $complex_fetch->fullText(array('length' => 100, 'peek' => true));
     // Header of entire message
     $complex_fetch->headerText(array('length' => 100, 'peek' => true));
     // Header of message/rfc822 part
     $complex_fetch->headerText(array('id' => 2, 'length' => 100, 'peek' => true));
     // Body text of entire message
     $complex_fetch->bodyText(array('length' => 100, 'peek' => true));
     // Body text of message/rfc822 part
     $complex_fetch->bodyText(array('id' => 2, 'length' => 100, 'peek' => true));
     // MIME Header of multipart/alternative part
     $complex_fetch->mimeHeader('1', array('length' => 100, 'peek' => true));
     // MIME Header of text/plain part embedded in message/rfc822 part
     $complex_fetch->mimeHeader('2.1', array('length' => 100, 'peek' => true));
     // Body text of multipart/alternative part
     $complex_fetch->bodyPart('1', array('length' => 100, 'peek' => true));
     // Body text of image/png part embedded in message/rfc822 part
     // Try to do server-side decoding, if available
     $complex_fetch->mimeHeader('2.2', array('decode' => true, 'length' => 100, 'peek' => true));
     // If supported, return decoded body part size
     $complex_fetch->bodyPartSize('2.2');
     // Select message-id header from base message header
     $complex_fetch->headers('headersearch1', array('message-id'), array('length' => 100, 'peek' => true));
     // Select everything but message-id header from message/rfc822 header
     $complex_fetch->headers('headersearch2', array('message-id'), array('id' => '2', 'length' => 100, 'notsearch' => true, 'peek' => true));
     $complex_fetch->structure();
     $complex_fetch->flags();
     $complex_fetch->imapDate();
     $complex_fetch->size();
     $complex_fetch->uid();
     if (self::$live->capability->query('CONDSTORE')) {
         $complex_fetch->modseq();
     }
     try {
         $res = self::$live->fetch(self::$test_mbox, $complex_fetch, array('ids' => new Horde_Imap_Client_Ids(3, true)));
     } catch (Horde_Imap_Client_Exception $e) {
         if ($e->getCode() === $e::MBOXNOMODSEQ) {
             $this->markTestSkipped('Mailbox does not support MODSEQ.');
         }
         throw $e;
     }
     $this->assertInstanceOf('Horde_Imap_Client_Fetch_Results', $res);
     $this->assertEquals(1, count($res));
     $this->assertEquals('Message-ID: <*****@*****.**>', trim($res[3]->getHeaders('headersearch1')));
     /* Return stream instead. */
     $this->assertInternalType('resource', $res[3]->getHeaders('headersearch1', Horde_Imap_Client_Data_Fetch::HEADER_STREAM));
     /* Parse headers instead. */
     $this->assertInstanceOf('Horde_Mime_Headers', $res[3]->getHeaders('headersearch1', Horde_Imap_Client_Data_Fetch::HEADER_PARSE));
 }