本文整理汇总了PHP中Horde_Mime::decode方法的典型用法代码示例。如果您正苦于以下问题:PHP Horde_Mime::decode方法的具体用法?PHP Horde_Mime::decode怎么用?PHP Horde_Mime::decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Horde_Mime
的用法示例。
在下文中一共展示了Horde_Mime::decode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __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);
}
示例2: __set
/**
*/
public function __set($name, $value)
{
switch ($name) {
case 'groupname':
$this->_groupname = Horde_Mime::decode($value);
break;
}
}
示例3: _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));
}
}
示例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
/**
* @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)));
}
}
示例6: 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']);
}
示例7: _parseBodystructure
/**
* Recursively parse BODYSTRUCTURE data from a FETCH return (see
* RFC 3501 [7.4.2]).
*
* @param Horde_Imap_Client_Tokenize $data Data returned from the server.
*
* @return array The array of bodystructure information.
*/
protected function _parseBodystructure(Horde_Imap_Client_Tokenize $data)
{
$ob = new Horde_Mime_Part();
// If index 0 is an array, this is a multipart part.
if (is_object($entry = $data->rewind())) {
// Keep going through array values until we find a non-array.
do {
$ob->addPart($this->_parseBodystructure($entry));
} while (is_object($entry = $data->next()));
// The first string entry after an array entry gives us the
// subpart type.
$ob->setType('multipart/' . $entry);
// After the subtype is further extension information. This
// information MAY not appear for BODYSTRUCTURE requests.
// This is parameter information.
if (is_object($tmp = $data->next())) {
foreach ($this->_parseStructureParams($tmp, 'content-type') as $key => $val) {
$ob->setContentTypeParameter($key, $val);
}
}
} else {
$ob->setType($entry . '/' . $data->next());
if (is_object($tmp = $data->next())) {
foreach ($this->_parseStructureParams($tmp, 'content-type') as $key => $val) {
$ob->setContentTypeParameter($key, $val);
}
}
if (!is_null($tmp = $data->next())) {
$ob->setContentId($tmp);
}
if (!is_null($tmp = $data->next())) {
$ob->setDescription(Horde_Mime::decode($tmp));
}
if (!is_null($tmp = $data->next())) {
$ob->setTransferEncoding($tmp);
}
$ob->setBytes($data->next());
// If the type is 'message/rfc822' or 'text/*', several extra
// fields are included
switch ($ob->getPrimaryType()) {
case 'message':
if ($ob->getSubType() == 'rfc822') {
$data->next();
// Ignore: envelope
$ob->addPart($this->_parseBodystructure($data->next()));
$data->next();
// Ignore: lines
}
break;
case 'text':
$data->next();
// Ignore: lines
break;
}
// After the subtype is further extension information. This
// information MAY appear for BODYSTRUCTURE requests.
$data->next();
// Ignore: MD5
}
// This is disposition information
if (is_object($tmp = $data->next())) {
$ob->setDisposition($tmp->rewind());
foreach ($this->_parseStructureParams($tmp->next(), 'content-disposition') as $key => $val) {
$ob->setDispositionParameter($key, $val);
}
}
// This is language information. It is either a single value or a list
// of values.
if (($tmp = $data->next()) !== false) {
$ob->setLanguage($tmp);
}
$data->next();
// Ignore: location (RFC 2557)
return $ob;
}
示例8: __set
/**
*/
public function __set($name, $value)
{
switch ($name) {
case 'host':
try {
$value = Horde_Idna::decode($value);
} catch (Horde_Idna_Exception $e) {
}
$this->_host = Horde_String::lower($value);
break;
case 'personal':
$this->_personal = strlen($value) ? Horde_Mime::decode($value) : null;
break;
}
}
示例9: __set
/**
*/
public function __set($name, $value)
{
switch ($name) {
case 'host':
$value = ltrim($value, '@');
$this->_host = function_exists('idn_to_utf8') ? strtolower(idn_to_utf8($value)) : strtolower($value);
break;
case 'personal':
$this->_personal = strlen($value) ? Horde_Mime::decode($value) : null;
break;
}
}
示例10: addHeader
/**
* Add a header to the header array.
*
* @param string $header The header name.
* @param string $value The header value (UTF-8).
* @param array $opts Additional options:
* - params: (array) MIME parameters for Content-Type or
* Content-Disposition.
* DEFAULT: None
* - sanity_check: (boolean) Do sanity-checking on header value?
* DEFAULT: false
*/
public function addHeader($header, $value, array $opts = array())
{
$header = trim($header);
$lcHeader = Horde_String::lower($header);
if (!isset($this->_headers[$lcHeader])) {
$this->_headers[$lcHeader] = array('h' => $header);
}
$ptr =& $this->_headers[$lcHeader];
if (!empty($opts['sanity_check'])) {
$value = $this->_sanityCheck($value);
}
// Fields defined in RFC 2822 that contain address information
if (in_array($lcHeader, $this->addressFields())) {
$rfc822 = new Horde_Mail_Rfc822();
$addr_list = $rfc822->parseAddressList($value);
switch ($lcHeader) {
case 'bcc':
case 'cc':
case 'from':
case 'to':
/* Catch malformed undisclosed-recipients entries. */
if (count($addr_list) == 1 && preg_match("/^\\s*undisclosed-recipients:?\\s*\$/i", $addr_list[0]->bare_address)) {
$addr_list = new Horde_Mail_Rfc822_List('undisclosed-recipients:;');
}
break;
}
$value = strval($addr_list);
} else {
$value = Horde_Mime::decode($value);
}
if (isset($ptr['v'])) {
if (!is_array($ptr['v'])) {
$ptr['v'] = array($ptr['v']);
}
$ptr['v'][] = $value;
} else {
$ptr['v'] = $value;
}
if (!empty($opts['params'])) {
$ptr['p'] = $opts['params'];
}
}
示例11: deleteAttach
/**
* AJAX action: Delete an attachment from compose data.
*
* Variables used:
* - atc_indices: (string) [JSON array] Attachment IDs to delete.
* - imp_compose: (string) The IMP_Compose cache identifier.
* - quiet: (boolean) If true, don't output notifications.
*
* @return array The list of attchment IDs that were deleted.
*/
public function deleteAttach()
{
global $injector, $notification;
$result = array();
if (isset($this->vars->atc_indices)) {
$imp_compose = $injector->getInstance('IMP_Factory_Compose')->create($this->vars->imp_compose);
foreach (json_decode($this->vars->atc_indices) as $val) {
if (isset($imp_compose[$val])) {
if (empty($this->vars->quiet)) {
$notification->push(sprintf(_("Deleted attachment \"%s\"."), Horde_Mime::decode($imp_compose[$val]->getPart()->getName(true))), 'horde.success');
}
unset($imp_compose[$val]);
$result[] = $val;
$this->_base->queue->compose($imp_compose);
}
}
}
if (empty($result) && empty($this->vars->quiet)) {
$notification->push(_("At least one attachment could not be deleted."), 'horde.error');
}
return $result;
}
示例12: testDecode
public function testDecode()
{
$this->assertEquals(' François Xavier. XXXXXX <foo@example.com>', Horde_Mime::decode('=?utf-8?Q?_Fran=C3=A7ois_Xavier=2E_XXXXXX_?= <foo@example.com>'));
/* Not MIME encoded. */
$this->assertEquals('=? required=?', Horde_Mime::decode('=? required=?'));
}
示例13: testDecode
/**
* @dataProvider decodeProvider
*/
public function testDecode($data, $expected)
{
$this->assertEquals($expected, Horde_Mime::decode($data));
}
示例14: _parseStructure
/**
* Recursively parse BODYSTRUCTURE data from a FETCH return (see
* RFC 3501 [7.4.2]).
*
* @param array $data The tokenized information from the server.
*
* @return array The array of bodystructure information.
*/
protected function _parseStructure($data)
{
$ob = new Horde_Mime_Part();
// If index 0 is an array, this is a multipart part.
if (is_array($data[0])) {
// Keep going through array values until we find a non-array.
for ($i = 0, $cnt = count($data); $i < $cnt; ++$i) {
if (!is_array($data[$i])) {
break;
}
$ob->addPart($this->_parseStructure($data[$i]));
}
// The first string entry after an array entry gives us the
// subpart type.
$ob->setType('multipart/' . $data[$i]);
// After the subtype is further extension information. This
// information MAY not appear for BODYSTRUCTURE requests.
// This is parameter information.
if (isset($data[++$i]) && is_array($data[$i])) {
foreach ($this->_parseStructureParams($data[$i], 'content-type') as $key => $val) {
$ob->setContentTypeParameter($key, $val);
}
}
// This is disposition information.
if (isset($data[++$i]) && is_array($data[$i])) {
$ob->setDisposition($data[$i][0]);
foreach ($this->_parseStructureParams($data[$i][1], 'content-disposition') as $key => $val) {
$ob->setDispositionParameter($key, $val);
}
}
// This is language information. It is either a single value or
// a list of values.
if (isset($data[++$i])) {
$ob->setLanguage($data[$i]);
}
// Ignore: location (RFC 2557)
// There can be further information returned in the future, but
// for now we are done.
} else {
$ob->setType($data[0] . '/' . $data[1]);
foreach ($this->_parseStructureParams($data[2], 'content-type') as $key => $val) {
$ob->setContentTypeParameter($key, $val);
}
if ($data[3] !== null) {
$ob->setContentId($data[3]);
}
if ($data[4] !== null) {
$ob->setDescription(Horde_Mime::decode($data[4]));
}
if ($data[5] !== null) {
$ob->setTransferEncoding($data[5]);
}
if ($data[6] !== null) {
$ob->setBytes($data[6]);
}
// If the type is 'message/rfc822' or 'text/*', several extra
// fields are included
switch ($ob->getPrimaryType()) {
case 'message':
if ($ob->getSubType() == 'rfc822') {
// Ignore: envelope
$ob->addPart($this->_parseStructure($data[8]));
// Ignore: lines
$i = 10;
} else {
$i = 7;
}
break;
case 'text':
// Ignore: lines
$i = 8;
break;
default:
$i = 7;
break;
}
// After the subtype is further extension information. This
// information MAY appear for BODYSTRUCTURE requests.
// Ignore: MD5
// This is disposition information
if (isset($data[++$i]) && is_array($data[$i])) {
$ob->setDisposition($data[$i][0]);
foreach ($this->_parseStructureParams($data[$i][1], 'content-disposition') as $key => $val) {
$ob->setDispositionParameter($key, $val);
}
}
// This is language information. It is either a single value or
// a list of values.
if (isset($data[++$i])) {
$ob->setLanguage($data[$i]);
}
// Ignore: location (RFC 2557)
//.........这里部分代码省略.........
示例15: decode
/**
* Decodes a MIME content parameter string pursuant to RFC 2183 & 2231
* (Content-Type and Content-Disposition headers).
*
* Stores value/parameter data in the current object.
*
* @param mixed $data Parameter data. Either an array or a string.
*/
public function decode($data)
{
$add = $convert = array();
if (is_array($data)) {
$params = $data;
} else {
$parts = explode(';', $data, 2);
if (isset($parts[0]) && strpos($parts[0], '=') === false) {
$this->setContentParamValue($parts[0]);
$param = isset($parts[1]) ? $parts[1] : null;
} else {
$param = $data;
}
if (empty($param)) {
$params = array();
} else {
$decode = new Horde_Mime_ContentParam_Decode();
$params = $decode->decode($param);
}
}
$to_add = array();
foreach ($params as $name => $val) {
/* Asterisk at end indicates encoded value. */
if (substr($name, -1) == '*') {
$name = substr($name, 0, -1);
$encoded = true;
} else {
$encoded = false;
}
/* This asterisk indicates continuation parameter. */
if (($pos = strrpos($name, '*')) !== false && is_numeric($order = substr($name, $pos + 1))) {
$name = substr($name, 0, $pos);
$to_add[Horde_String::lower($name)][$order] = $val;
} else {
$to_add[$name] = array($val);
}
if ($encoded) {
$convert[$name] = true;
}
}
foreach ($to_add as $key => $val) {
ksort($val);
$add[$key] = implode('', $val);
}
foreach (array_keys($convert) as $name) {
$val = $add[$name];
$quote = strpos($val, "'");
if ($quote === false) {
$add[$name] = urldecode($val);
} else {
$orig_charset = substr($val, 0, $quote);
if (Horde_String::lower($orig_charset) == 'iso-8859-1') {
$orig_charset = 'windows-1252';
}
/* Ignore language. */
$quote = strpos($val, "'", $quote + 1);
substr($val, $quote + 1);
$add[$name] = Horde_String::convertCharset(urldecode(substr($val, $quote + 1)), $orig_charset, 'UTF-8');
}
}
/* MIME parameters are supposed to be encoded via RFC 2231, but many
* mailers do RFC 2045 encoding instead. However, if we see at least
* one RFC 2231 encoding, then assume the sending mailer knew what
* it was doing and didn't send any parameters RFC 2045 encoded. */
if (empty($convert)) {
foreach ($add as $key => $val) {
$add[$key] = Horde_Mime::decode($val);
}
}
if (count($add)) {
foreach ($add as $key => $val) {
/* When parsing a content-param string, lowercase all
* parameter names to normalize. Only maintain case of
* parameters explicitly added by calling code. */
$this[Horde_String::lower($key)] = $val;
}
} elseif (is_string($data)) {
$this->setContentParamValue($parts[0]);
}
}