setDuration() public method

Set the content duration of the data contained in this part (see RFC 3803).
public setDuration ( integer $duration )
$duration integer The duration of the data, in seconds. If null, clears the duration information.
Example #1
0
 public function testNullCharactersNotAllowedInMimeHeaderData()
 {
     $part = new Horde_Mime_Part();
     $part->setType("text/plain");
     $this->assertEquals('text/plain', $part->getType());
     $part->setDisposition("inline");
     $this->assertEquals('inline', $part->getDisposition());
     $part->setDispositionParameter('size', '123' . "" . '456');
     $this->assertEquals(123456, $part->getDispositionParameter('size'));
     $part->setDispositionParameter('foo', "foobar");
     $this->assertEquals('foobar', $part->getDispositionParameter('foo'));
     $part->setCharset("utf-8");
     $this->assertEquals('utf-8', $part->getCharset());
     $part->setName("foobar");
     $this->assertEquals('foobar', $part->getName());
     $this->assertEquals('foobar', $part->getDispositionParameter('filename'));
     $this->assertEquals('foobar', $part->getContentTypeParameter('name'));
     $part->setLanguage("en");
     $this->assertEquals(array('en'), $part->getLanguage());
     $part->setLanguage(array("en", "de"));
     $this->assertEquals(array('en', 'de'), $part->getLanguage());
     $part->setDuration('123' . "" . '456');
     $this->assertEquals(123456, $part->getDuration());
     $part->setBytes('123' . "" . '456');
     $this->assertEquals(123456, $part->getBytes());
     $part->setDescription("foobar");
     $this->assertEquals('foobar', $part->getDescription());
     $part->setContentTypeParameter('foo', "foobar");
     $this->assertEquals('foobar', $part->getContentTypeParameter('foo'));
     $part->setContentId("foobar");
     $this->assertEquals('foobar', $part->getContentId());
 }
Example #2
0
 /**
  * Creates a MIME object from the text of one part of a MIME message.
  *
  * @param string $header  The header text.
  * @param string $body    The body text.
  * @param array $opts     Additional options:
  * <pre>
  *   - ctype: (string) The default content-type.
  *   - forcemime: (boolean) If true, the message data is assumed to be
  *                MIME data. If not, a MIME-Version header must exist to
  *                be parsed as a MIME message.
  *   - level: (integer) Current nesting level.
  *   - no_body: (boolean) If true, don't set body contents of parts.
  * </pre>
  *
  * @return Horde_Mime_Part  The MIME part object.
  */
 protected static function _getStructure($header, $body, array $opts = array())
 {
     $opts = array_merge(array('ctype' => 'text/plain', 'forcemime' => false, 'level' => 0, 'no_body' => false), $opts);
     /* Parse headers text into a Horde_Mime_Headers object. */
     $hdrs = Horde_Mime_Headers::parseHeaders($header);
     $ob = new Horde_Mime_Part();
     /* This is not a MIME message. */
     if (!$opts['forcemime'] && !isset($hdrs['MIME-Version'])) {
         $ob->setType('text/plain');
         if ($len = strlen($body)) {
             if ($opts['no_body']) {
                 $ob->setBytes($len);
             } else {
                 $ob->setContents($body);
             }
         }
         return $ob;
     }
     /* Content type. */
     if ($tmp = $hdrs['Content-Type']) {
         $ob->setType($tmp->value);
         foreach ($tmp->params as $key => $val) {
             $ob->setContentTypeParameter($key, $val);
         }
     } else {
         $ob->setType($opts['ctype']);
     }
     /* Content transfer encoding. */
     if ($tmp = $hdrs['Content-Transfer-Encoding']) {
         $ob->setTransferEncoding(strval($tmp));
     }
     /* Content-Description. */
     if ($tmp = $hdrs['Content-Description']) {
         $ob->setDescription(strval($tmp));
     }
     /* Content-Disposition. */
     if ($tmp = $hdrs['Content-Disposition']) {
         $ob->setDisposition($tmp->value);
         foreach ($tmp->params as $key => $val) {
             $ob->setDispositionParameter($key, $val);
         }
     }
     /* Content-Duration */
     if ($tmp = $hdrs['Content-Duration']) {
         $ob->setDuration(strval($tmp));
     }
     /* Content-ID. */
     if ($tmp = $hdrs['Content-Id']) {
         $ob->setContentId(strval($tmp));
     }
     if (($len = strlen($body)) && $ob->getPrimaryType() != 'multipart') {
         if ($opts['no_body']) {
             $ob->setBytes($len);
         } else {
             $ob->setContents($body);
         }
     }
     if (++$opts['level'] >= self::NESTING_LIMIT) {
         return $ob;
     }
     /* Process subparts. */
     switch ($ob->getPrimaryType()) {
         case 'message':
             if ($ob->getSubType() == 'rfc822') {
                 $ob[] = self::parseMessage($body, array('forcemime' => true, 'no_body' => $opts['no_body']));
             }
             break;
         case 'multipart':
             $boundary = $ob->getContentTypeParameter('boundary');
             if (!is_null($boundary)) {
                 foreach (self::_findBoundary($body, 0, $boundary) as $val) {
                     if (!isset($val['length'])) {
                         break;
                     }
                     $subpart = substr($body, $val['start'], $val['length']);
                     $hdr_pos = self::_findHeader($subpart, self::EOL);
                     $ob[] = self::_getStructure(substr($subpart, 0, $hdr_pos), substr($subpart, $hdr_pos + 2), array('ctype' => $ob->getSubType() == 'digest' ? 'message/rfc822' : 'text/plain', 'forcemime' => true, 'level' => $opts['level'], 'no_body' => $opts['no_body']));
                 }
             }
             break;
     }
     return $ob;
 }
Example #3
0
 /**
  * Creates a structure object from the text of one part of a MIME message.
  *
  * @param string $header      The header text.
  * @param string $body        The body text.
  * @param string $ctype       The default content-type.
  * @param boolean $forcemime  If true, the message data is assumed to be
  *                            MIME data. If not, a MIME-Version header
  *                            must exist to be parsed as a MIME message.
  *
  * @return Horde_Mime_Part  TODO
  */
 protected static function _getStructure($header, $body, $ctype = 'application/octet-stream', $forcemime = false)
 {
     /* Parse headers text into a Horde_Mime_Headers object. */
     $hdrs = Horde_Mime_Headers::parseHeaders($header);
     $ob = new Horde_Mime_Part();
     /* This is not a MIME message. */
     if (!$forcemime && !$hdrs->getValue('mime-version')) {
         $ob->setType('text/plain');
         if (!empty($body)) {
             $ob->setContents($body);
             $ob->setBytes(strlen(str_replace(array("\r\n", "\n"), array("\n", "\r\n"), $body)));
         }
         return $ob;
     }
     /* Content type. */
     if ($tmp = $hdrs->getValue('content-type', Horde_Mime_Headers::VALUE_BASE)) {
         $ob->setType($tmp);
         $ctype_params = $hdrs->getValue('content-type', Horde_Mime_Headers::VALUE_PARAMS);
         foreach ($ctype_params as $key => $val) {
             $ob->setContentTypeParameter($key, $val);
         }
     } else {
         $ob->setType($ctype);
         $ctype_params = array();
     }
     /* Content transfer encoding. */
     if ($tmp = $hdrs->getValue('content-transfer-encoding')) {
         $ob->setTransferEncoding($tmp);
     }
     /* Content-Description. */
     if ($tmp = $hdrs->getValue('content-description')) {
         $ob->setDescription($tmp);
     }
     /* Content-Disposition. */
     if ($tmp = $hdrs->getValue('content-disposition', Horde_Mime_Headers::VALUE_BASE)) {
         $ob->setDisposition($tmp);
         foreach ($hdrs->getValue('content-disposition', Horde_Mime_Headers::VALUE_PARAMS) as $key => $val) {
             $ob->setDispositionParameter($key, $val);
         }
     }
     /* Content-Duration */
     if ($tmp = $hdrs->getValue('content-duration')) {
         $ob->setDuration($tmp);
     }
     /* Content-ID. */
     if ($tmp = $hdrs->getValue('content-id')) {
         $ob->setContentId($tmp);
     }
     /* Get file size (if 'body' text is set). */
     if (!empty($body) && $ob->getPrimaryType() != 'multipart') {
         $ob->setContents($body);
         if ($ob->getType() != '/message/rfc822') {
             $ob->setBytes(strlen(str_replace(array("\r\n", "\n"), array("\n", "\r\n"), $body)));
         }
     }
     /* Process subparts. */
     switch ($ob->getPrimaryType()) {
         case 'message':
             if ($ob->getSubType() == 'rfc822') {
                 $ob->addPart(self::parseMessage($body, array('forcemime' => true)));
             }
             break;
         case 'multipart':
             if (isset($ctype_params['boundary'])) {
                 $b_find = self::_findBoundary($body, 0, $ctype_params['boundary']);
                 foreach ($b_find as $val) {
                     $subpart = substr($body, $val['start'], $val['length']);
                     list($hdr_pos, $eol) = self::_findHeader($subpart);
                     $ob->addPart(self::_getStructure(substr($subpart, 0, $hdr_pos), substr($subpart, $hdr_pos + $eol), $ob->getSubType() == 'digest' ? 'message/rfc822' : 'text/plain', true));
                 }
             }
             break;
     }
     return $ob;
 }