本文整理汇总了PHP中Horde_Mime类的典型用法代码示例。如果您正苦于以下问题:PHP Horde_Mime类的具体用法?PHP Horde_Mime怎么用?PHP Horde_Mime使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Horde_Mime类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _IMPrender
/**
* Render the part based on the view mode.
*
* @param boolean $inline True if viewing inline.
*
* @return array See parent::render().
*/
protected function _IMPrender($inline)
{
/* RFC 1740 [4]: There are two parts to an appledouble message:
* (1) application/applefile
* (2) Data embedded in the Mac file
* Since the resource fork is not very useful to us, only provide a
* means to download. */
/* Display the resource fork download link. */
$mime_id = $this->_mimepart->getMimeId();
$parts_list = array_keys($this->_mimepart->contentTypeMap());
reset($parts_list);
$applefile_id = next($parts_list);
$data_id = Horde_Mime::mimeIdArithmetic($applefile_id, 'next');
$applefile_part = $this->_mimepart->getPart($applefile_id);
$data_part = $this->_mimepart->getPart($data_id);
$data_name = $this->getConfigParam('imp_contents')->getPartName($data_part);
$status = new IMP_Mime_Status(array(sprintf(_("This message contains a Macintosh file (named \"%s\")."), $data_name), sprintf(_("The Macintosh resource fork can be downloaded %s."), $this->getConfigParam('imp_contents')->linkViewJS($applefile_part, 'download_attach', _("HERE"), array('jstext' => _("The Macintosh resource fork"))))));
$status->icon('mime/apple.png', _("Macintosh File"));
/* For inline viewing, attempt to display the data inline. */
$ret = array();
if ($inline && ($disp = $this->getConfigParam('imp_contents')->canDisplay($data_part, IMP_Contents::RENDER_INLINE | IMP_Contents::RENDER_INFO))) {
$ret = $this->getConfigParam('imp_contents')->renderMIMEPart($data_id, $disp);
}
foreach ($parts_list as $val) {
if (!isset($ret[$val]) && strcmp($val, $data_id) !== 0) {
$ret[$val] = strcmp($val, $mime_id) === 0 ? array('data' => '', 'status' => $status, 'type' => 'text/html; charset=' . $this->getConfigParam('charset'), 'wrap' => 'mimePartWrap') : null;
}
}
return $ret;
}
示例2: _renderInfo
/**
* Return the rendered information about the Horde_Mime_Part object.
*
* @return array See parent::render().
*/
protected function _renderInfo()
{
$mdn_id = $this->_mimepart->getMimeId();
$parts = array_keys($this->_mimepart->contentTypeMap());
$status = new IMP_Mime_Status(_("A message you have sent has resulted in a return notification from the recipient."));
$status->icon('info_icon.png', _("Info"));
/* RFC 3798 [3]: There are three parts to a delivery status
* multipart/report message:
* (1) Human readable message
* (2) Machine parsable body part (message/disposition-notification)
* (3) Original message (optional) */
/* Get the human readable message. */
reset($parts);
$part1_id = next($parts);
/* Display a link to more detailed message. */
$part2_id = Horde_Mime::mimeIdArithmetic($part1_id, 'next');
$part = $this->getConfigParam('imp_contents')->getMIMEPart($part2_id);
if ($part) {
$status->addText(sprintf(_("Technical details can be viewed %s."), $this->getConfigParam('imp_contents')->linkViewJS($part, 'view_attach', _("HERE"), array('jstext' => _("Technical details"), 'params' => array('ctype' => 'text/plain', 'mode' => IMP_Contents::RENDER_FULL)))));
}
$ret[$part2_id] = null;
/* Display a link to the sent message. */
$part3_id = Horde_Mime::mimeIdArithmetic($part2_id, 'next');
$part = $this->getConfigParam('imp_contents')->getMIMEPart($part3_id);
if ($part) {
$status->addText(sprintf(_("The text of the sent message can be viewed %s."), $this->getConfigParam('imp_contents')->linkViewJS($part, 'view_attach', _("HERE"), array('jstext' => _("The text of the sent message"), 'params' => array('ctype' => 'message/rfc822', 'mode' => IMP_Contents::RENDER_FULL)))));
foreach (array_keys($part->contentTypeMap()) as $key) {
$ret[$key] = null;
}
}
$ret[$mdn_id] = array('data' => '', 'status' => $status, 'type' => 'text/html; charset=' . $this->getConfigParam('charset'), 'wrap' => 'mimePartWrap');
return $ret;
}
示例3: __construct
/**
* Constructor.
*
* @param string $str The subject string.
* @param array $opts Additional options:
* - keepblob: (boolean) Don't remove any "blob" information (i.e. text
* leading text between square brackets) from string.
*
* @return string The cleaned up subject string.
*/
public function __construct($str, array $opts = array())
{
// Rule 1a: MIME decode.
$str = Horde_Mime::decode($str);
// Rule 1b: Remove superfluous whitespace.
$str = preg_replace("/[\t\r\n ]+/", ' ', $str);
do {
/* (2) Remove all trailing text of the subject that matches the
* the subj-trailer ABNF, repeat until no more matches are
* possible. */
$str = preg_replace("/(?:\\s*\\(fwd\\)\\s*)+\$/i", '', $str);
do {
/* (3) Remove all prefix text of the subject that matches the
* subj-leader ABNF. */
$found = $this->_removeSubjLeader($str, !empty($opts['keepblob']));
/* (4) If there is prefix text of the subject that matches
* the subj-blob ABNF, and removing that prefix leaves a
* non-empty subj-base, then remove the prefix text. */
$found = empty($opts['keepblob']) && $this->_removeBlobWhenNonempty($str) || $found;
/* (5) Repeat (3) and (4) until no matches remain. */
} while ($found);
/* (6) If the resulting text begins with the subj-fwd-hdr ABNF and
* ends with the subj-fwd-trl ABNF, remove the subj-fwd-hdr and
* subj-fwd-trl and repeat from step (2). */
} while ($this->_removeSubjFwdHdr($str));
$this->_subject = strval($str);
}
示例4: _setValue
/**
*/
protected function _setValue($value)
{
if ($value instanceof Horde_Mime_Headers_Element) {
$value = $value->value;
} elseif (is_array($value)) {
$value = reset($value);
}
$this->_values = array($this->_sanityCheck(Horde_Mime::decode($value)));
}
示例5: _setValue
/**
*/
protected function _setValue($value)
{
if ($value instanceof Horde_Mime_Headers_Element) {
$value = $value->value;
}
foreach (is_array($value) ? $value : array($value) as $val) {
$this->_values[] = $this->_sanityCheck(Horde_Mime::decode($val));
}
}
示例6: _setValue
/**
* @param mixed $value Either a single language or an array of languages.
*/
protected function _setValue($value)
{
if ($value instanceof Horde_Mime_Headers_Element) {
$value = $value->value;
}
if (!is_array($value)) {
$value = array_map('trim', explode(',', $value));
}
$this->_values = array();
foreach ($value as $val) {
$this->_values[] = Horde_String::lower($this->_sanityCheck(Horde_Mime::decode($val)));
}
}
示例7: testGenerate
public function testGenerate()
{
$h = new Horde_Mime_Headers();
$ob = new Horde_Mime_Mdn($h);
try {
$ob->generate(true, true, 'deleted', 'foo', null);
$this->fail('Expected Exception');
} catch (RuntimeException $e) {
}
$date = 'Tue, 18 Nov 2014 20:14:17 -0700';
$mdn_addr = 'Aäb <foo@example.com>';
$h->addHeader('Date', $date);
$h->addHeader('Subject', 'Test');
$h->addHeader('To', '"BAR" <bar@example.com>');
$ob->addMdnRequestHeaders($mdn_addr);
$mailer = new Horde_Mail_Transport_Mock();
$ob->generate(true, true, 'displayed', 'test.example.com', $mailer, array('from_addr' => 'bar@example.com'), array('error'), array('error' => 'Foo'));
$sent = str_replace("\r\n", "\n", $mailer->sentMessages[0]);
$this->assertEquals('auto-replied', $sent['headers']['Auto-Submitted']);
$this->assertEquals('bar@example.com', $sent['headers']['From']);
$this->assertEquals($mdn_addr, Horde_Mime::decode($sent['headers']['To']));
$this->assertEquals('Disposition Notification', $sent['headers']['Subject']);
$this->assertStringMatchesFormat('This message is in MIME format.
--=%s
Content-Type: text/plain; format=flowed; DelSp=Yes
The message sent on Tue, 18 Nov 2014 20:14:17 -0700 to BAR
<bar@example.com> with subject "Test" has been displayed.
This is no guarantee that the message has been read or understood.
--=%s
Content-Type: message/disposition-notification
Reporting-UA: test.example.com; Horde Application Framework 5
Final-Recipient: rfc822;bar@example.com
Disposition: manual-action/MDN-sent-manually; displayed/error
Error: Foo
--=%s
Content-Type: message/rfc822
Date: Tue, 18 Nov 2014 20:14:17 -0700
Subject: Test
To: BAR <bar@example.com>
Disposition-Notification-To: =?utf-8?b?QcOkYg==?= <foo@example.com>
--=%s
', $sent['body']);
}
示例8: _parseStructureParams
/**
* Helper function to parse a parameters-like tokenized array.
*
* @param array $data The tokenized data.
* @param string $type The header name.
*
* @return array The parameter array.
*/
protected function _parseStructureParams($data, $type)
{
$params = array();
if (is_array($data)) {
for ($i = 0, $cnt = count($data); $i < $cnt; ++$i) {
$params[Horde_String::lower($data[$i])] = $data[++$i];
}
}
$ret = Horde_Mime::decodeParam($type, $params);
return $ret['params'];
}
示例9: __construct
/**
* Constructs a new procmail recipe.
*
* @param array $params Array of parameters.
* REQUIRED FIELDS:
* 'action'
* OPTIONAL FIELDS:
* 'action-value' (only used if the
* 'action' requires it)
* 'disable'
* @param array $scriptparams Array of parameters passed to
* Ingo_Script_Procmail.
*/
public function __construct($params = array(), $scriptparams = array())
{
$this->_disable = !empty($params['disable']);
$this->_params = array_merge($this->_params, $scriptparams);
$delivery = '| ';
if (isset($this->_params['delivery_agent'])) {
$delivery .= $this->_params['delivery_agent'] . ' ';
}
if (isset($this->_params['delivery_mailbox_prefix'])) {
$delivery .= ' ' . $this->_params['delivery_mailbox_prefix'];
}
switch ($params['action']) {
case 'Ingo_Rule_User_Keep':
// Note: you may have to set the DEFAULT variable in your
// backend configuration.
$this->_action[] = $delivery .= '$DEFAULT';
break;
case 'Ingo_Rule_User_Move':
$this->_action[] = $delivery .= $this->procmailPath($params['action-value']);
break;
case 'Ingo_Rule_User_Discard':
$this->_action[] = '/dev/null';
break;
case 'Ingo_Rule_User_Redirect':
$this->_action[] = '! ' . $params['action-value'];
break;
case 'Ingo_Rule_User_RedirectKeep':
$this->_action[] = '{';
$this->_action[] = ' :0 c';
$this->_action[] = ' ! ' . $params['action-value'];
if (strpos($this->_flags, 'c') === false) {
$this->_action[] = '';
$this->_action[] = ' :0' . (isset($this->_params['delivery_agent']) ? ' w' : '');
$this->_action[] = ' ' . $delivery . '$DEFAULT';
}
$this->_action[] = '}';
break;
case 'Ingo_Rule_User_Reject':
$this->_action[] = '{';
$this->_action[] = ' :0 h';
$this->_action[] = ' SUBJECT=| formail -xSubject:';
$this->_action[] = '';
$this->_action[] = ' :0 h';
$this->_action[] = ' SENDER=| formail -zxFrom:';
$this->_action[] = '';
$this->_action[] = ' :0 Wh';
$this->_action[] = ' * !^FROM_DAEMON';
$this->_action[] = ' * !^X-Loop: $SENDER';
$this->_action[] = ' | (formail -rA"X-Loop: $SENDER" \\';
$reason = $params['action-value'];
if (Horde_Mime::is8bit($reason)) {
$this->_action[] = ' -i"Subject: Re: $SUBJECT" \\';
$this->_action[] = ' -i"Content-Transfer-Encoding: quoted-printable" \\';
$this->_action[] = ' -i"Content-Type: text/plain; charset=UTF-8" ; \\';
$reason = Horde_Mime_QuotedPrintable::encode($reason);
} else {
$this->_action[] = ' -i"Subject: Re: $SUBJECT" ; \\';
}
$reason = addcslashes($reason, "\\\n\r\t\"`");
$this->_action[] = ' ' . $this->_params['echo'] . ' -e "' . $reason . '" \\';
$this->_action[] = ' ) | $SENDMAIL -oi -t';
$this->_action[] = '}';
break;
case 'Ingo_Rule_System_Vacation':
$days = $params['action-value']['days'];
$timed = !empty($params['action-value']['start']) && !empty($params['action-value']['end']);
$this->_action[] = '{';
foreach ($params['action-value']['addresses'] as $address) {
if (empty($address)) {
continue;
}
$this->_action[] = ' :0';
$this->_action[] = ' * ^TO_' . $address;
$this->_action[] = ' {';
$this->_action[] = ' FILEDATE=`test -f ${VACATION_DIR:-.}/\'.vacation.' . $address . '\' && ' . $this->_params['ls'] . ' -lcn --time-style=+%s ${VACATION_DIR:-.}/\'.vacation.' . $address . '\' | ' . 'awk \'{ print $6 + (' . $days * 86400 . ') }\'`';
$this->_action[] = ' DATE=`' . $this->_params['date'] . ' +%s`';
$this->_action[] = ' DUMMY=`test -f ${VACATION_DIR:-.}/\'.vacation.' . $address . '\' && ' . 'test $FILEDATE -le $DATE && ' . 'rm ${VACATION_DIR:-.}/\'.vacation.' . $address . '\'`';
if ($timed) {
$this->_action[] = ' START=' . $params['action-value']['start'];
$this->_action[] = ' END=' . $params['action-value']['end'];
}
$this->_action[] = '';
$this->_action[] = ' :0 h';
$this->_action[] = ' SUBJECT=| formail -xSubject:';
$this->_action[] = '';
$this->_action[] = ' :0 Whc: ${VACATION_DIR:-.}/vacation.lock';
if ($timed) {
//.........这里部分代码省略.........
示例10: _parseUUencode
/**
* 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;
}
示例11: _parseStructure
/**
* Parse the output from imap_fetchstructure() into a MIME Part object.
*
* @param object $data Data from imap_fetchstructure().
*
* @return Horde_Mime_Part A MIME Part object.
*/
protected function _parseStructure($data)
{
$ob = new Horde_Mime_Part();
$ob->setType(Horde_String::lower($data->type) . '/' . Horde_String::lower($data->subType));
// Optional for multipart-parts, required for all others
if (isset($data->parameters)) {
$params = array();
foreach ($data->parameters as $key => $value) {
$params[Horde_String::lower($key)] = $value;
}
$params = Horde_Mime::decodeParam('content-type', $params);
foreach ($params['params'] as $key => $value) {
$ob->setContentTypeParameter($key, $value);
}
}
// Optional entries. 'location' and 'language' not supported
if (isset($data->disposition)) {
$ob->setDisposition($data->disposition);
if (isset($data->dparameters)) {
$dparams = array();
foreach ($data->dparameters as $key => $value) {
$dparams[Horde_String::lower($key)] = $value;
}
$dparams = Horde_Mime::decodeParam('content-disposition', $dparams);
foreach ($dparams['params'] as $key => $value) {
$ob->setDispositionParameter($key, $value);
}
}
}
if ($ob->getPrimaryType() == 'multipart') {
// multipart/* specific entries
foreach ($data->subParts as $val) {
$ob->addPart($this->_parseStructure($val));
}
} else {
// Required options
if (isset($data->partID)) {
$ob->setContentId($data->partID);
}
$ob->setTransferEncoding(Horde_String::lower($data->encoding));
$ob->setBytes($data->bytes);
if ($ob->getType() == 'message/rfc822') {
$ob->addPart($this->_parseStructure(reset($data->subParts)));
}
}
return $ob;
}
示例12: _writeAddress
/**
*/
protected function _writeAddress($opts)
{
$addr = $this->addresses->writeAddress($opts);
$groupname = $this->groupname;
if (!empty($opts['encode'])) {
$groupname = Horde_Mime::encode($groupname, $opts['encode']);
}
$rfc822 = new Horde_Mail_Rfc822();
return $rfc822->encode($groupname, 'personal') . ':' . (strlen($addr) ? ' ' . $addr : '') . ';';
}
示例13: _writeAddress
/**
*/
protected function _writeAddress($opts)
{
$rfc822 = new Horde_Mail_Rfc822();
$address = $rfc822->encode($this->mailbox, 'address');
$host = empty($opts['idn']) ? $this->host : $this->host_idn;
if (strlen($host)) {
$address .= '@' . $host;
}
$personal = $this->personal;
if (strlen($personal)) {
if (!empty($opts['encode'])) {
$personal = Horde_Mime::encode($this->personal, $opts['encode']);
}
if (empty($opts['noquote'])) {
$personal = $rfc822->encode($personal, 'personal');
}
}
if (!empty($opts['comment']) && !empty($this->comment)) {
foreach ($this->comment as $val) {
$personal .= ' (' . $rfc822->encode($val, 'comment') . ')';
}
}
return strlen($personal) && $personal != $address ? ltrim($personal) . ' <' . $address . '>' : $address;
}
示例14: _parseStructureParams
/**
* Helper function to parse a parameters-like tokenized array.
*
* @param mixed $data Message data. Either a Horde_Imap_Client_Tokenize
* object or null.
* @param string $type The header name.
*
* @return array The parameter array.
*/
protected function _parseStructureParams($data, $type)
{
$params = array();
if (is_null($data)) {
return $params;
}
while (($name = $data->next()) !== false) {
$params[strtolower($name)] = $data->next();
}
$ret = Horde_Mime::decodeParam($type, $params);
return $ret['params'];
}
示例15: _perform
//.........这里部分代码省略.........
case Ingo_Rule_User::COMBINE_ALL:
$query->andSearch(array($ob));
break;
case Ingo_Rule_User::COMBINE_ANY:
$query->orSearch(array($ob));
break;
}
}
$base_query->andSearch(array($query));
$indices = $api->search($base_query);
if ($indices = array_diff($indices, $ignore_ids)) {
if ($rule->stop) {
/* If the stop action is set, add these
* indices to the list of ids that will be
* ignored by subsequent rules. */
$ignore_ids = array_unique($indices + $ignore_ids);
}
/* Set the flags. */
if ($class !== 'Ingo_Rule_User_Discard') {
$flags = array();
if ($rule->flags & Ingo_Rule_User::FLAG_ANSWERED) {
$flags[] = '\\answered';
}
if ($rule->flags & Ingo_Rule_User::FLAG_DELETED) {
$flags[] = '\\deleted';
}
if ($rule->flags & Ingo_Rule_User::FLAG_FLAGGED) {
$flags[] = '\\flagged';
}
if ($rule->flags & Ingo_Rule_User::FLAG_SEEN) {
$flags[] = '\\seen';
}
if (!empty($flags)) {
$api->setMessageFlags($indices, $flags);
}
}
switch ($class) {
case 'Ingo_Rule_User_Keep':
/* Add these indices to the ignore list. */
$ignore_ids = array_unique($indices + $ignore_ids);
break;
case 'Ingo_Rule_User_Move':
/* We need to grab the envelope first. */
if ($this->_params['show_filter_msg'] && !($fetch = $api->fetchEnvelope($indices))) {
continue 2;
}
$mbox = new Horde_Imap_Client_Mailbox($rule->value);
/* Move the messages to the requested mailbox. */
$api->moveMessages($indices, strval($mbox));
/* Display notification message(s). */
if ($this->_params['show_filter_msg']) {
foreach ($fetch as $msg) {
$envelope = $msg->getEnvelope();
$notification->push(sprintf(_("Filter activity: The message \"%s\" from \"%s\" has been moved to the folder \"%s\"."), !empty($envelope->subject) ? Horde_Mime::decode($envelope->subject) : _("[No Subject]"), !empty($envelope->from) ? strval($envelope->from) : _("[No Sender]"), $mbox), 'horde.message');
}
} else {
$notification->push(sprintf(_("Filter activity: %s message(s) have been moved to the folder \"%s\"."), count($indices), $mbox), 'horde.message');
}
break;
case 'Ingo_Rule_User_Discard':
/* We need to grab the envelope first. */
if ($this->_params['show_filter_msg'] && !($fetch = $api->fetchEnvelope($indices))) {
continue;
}
/* Delete the messages now. */
$api->deleteMessages($indices);
/* Display notification message(s). */
if ($this->_params['show_filter_msg']) {
foreach ($fetch as $msg) {
$envelope = $msg->getEnvelope();
$notification->push(sprintf(_("Filter activity: The message \"%s\" from \"%s\" has been deleted."), !empty($envelope->subject) ? Horde_Mime::decode($envelope->subject) : _("[No Subject]"), !empty($envelope->from) ? strval($envelope->from) : _("[No Sender]")), 'horde.message');
}
} else {
$notification->push(sprintf(_("Filter activity: %s message(s) have been deleted."), count($indices)), 'horde.message');
}
break;
case 'Ingo_Rule_User_MoveKeep':
$mbox = new Horde_Imap_Client_Mailbox($rule->value);
/* Copy the messages to the requested mailbox. */
$api->copyMessages($indices, strval($mbox));
/* Display notification message(s). */
if ($this->_params['show_filter_msg']) {
if (!($fetch = $api->fetchEnvelope($indices))) {
continue;
}
foreach ($fetch as $msg) {
$envelope = $msg->getEnvelope();
$notification->push(sprintf(_("Filter activity: The message \"%s\" from \"%s\" has been copied to the folder \"%s\"."), !empty($envelope->subject) ? Horde_Mime::decode($envelope->subject) : _("[No Subject]"), !empty($envelope->from) ? strval($envelope->from) : _("[No Sender]"), $mbox), 'horde.message');
}
} else {
$notification->push(sprintf(_("Filter activity: %s message(s) have been copied to the folder \"%s\"."), count($indices), $mbox), 'horde.message');
}
}
}
break;
}
}
/* Set cache flag. */
$api->storeCache($change);
}