本文整理汇总了PHP中Horde_Mime_Part::setMetadata方法的典型用法代码示例。如果您正苦于以下问题:PHP Horde_Mime_Part::setMetadata方法的具体用法?PHP Horde_Mime_Part::setMetadata怎么用?PHP Horde_Mime_Part::setMetadata使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Horde_Mime_Part
的用法示例。
在下文中一共展示了Horde_Mime_Part::setMetadata方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: parseToPart
/**
* Parses an armored message into a Horde_Mime_Part object.
*
* @param mixed $text Either the text to parse or a Horde_Stream object.
*
* @return mixed Either null if no PGP data was found, or a
* Horde_Mime_Part object. For detached signature data:
* the full contents of the armored text (data + sig) is
* contained in the SIG_RAW metadata, and the charset is
* contained in the SIG_CHARSET metadata, within the
* application/pgp-signature part.
*/
public function parseToPart($text, $charset = 'UTF-8')
{
$parts = $this->parse($text);
if (empty($parts) || count($parts) == 1 && $parts[0]['type'] == self::ARMOR_TEXT) {
return null;
}
$new_part = new Horde_Mime_Part();
$new_part->setType('multipart/mixed');
foreach ($parts as $val) {
switch ($val['type']) {
case self::ARMOR_TEXT:
$part = new Horde_Mime_Part();
$part->setType('text/plain');
$part->setCharset($charset);
$part->setContents(implode("\n", $val['data']));
$new_part->addPart($part);
break;
case self::ARMOR_PUBLIC_KEY:
$part = new Horde_Mime_Part();
$part->setType('application/pgp-keys');
$part->setContents(implode("\n", $val['data']));
$new_part->addPart($part);
break;
case self::ARMOR_MESSAGE:
$part = new Horde_Mime_Part();
$part->setType('multipart/encrypted');
$part->setMetadata(self::PGP_ARMOR, true);
$part->setContentTypeParameter('protocol', 'application/pgp-encrypted');
$part1 = new Horde_Mime_Part();
$part1->setType('application/pgp-encrypted');
$part1->setContents("Version: 1\n");
$part2 = new Horde_Mime_Part();
$part2->setType('application/octet-stream');
$part2->setContents(implode("\n", $val['data']));
$part2->setDisposition('inline');
$part->addPart($part1);
$part->addPart($part2);
$new_part->addPart($part);
break;
case self::ARMOR_SIGNED_MESSAGE:
if (($sig = current($parts)) && $sig['type'] == self::ARMOR_SIGNATURE) {
$part = new Horde_Mime_Part();
$part->setType('multipart/signed');
// TODO: add micalg parameter
$part->setContentTypeParameter('protocol', 'application/pgp-signature');
$part1 = new Horde_Mime_Part();
$part1->setType('text/plain');
$part1->setCharset($charset);
$part1_data = implode("\n", $val['data']);
$part1->setContents(substr($part1_data, strpos($part1_data, "\n\n") + 2));
$part2 = new Horde_Mime_Part();
$part2->setType('application/pgp-signature');
$part2->setContents(implode("\n", $sig['data']));
$part2->setMetadata(self::SIG_CHARSET, $charset);
$part2->setMetadata(self::SIG_RAW, implode("\n", $val['data']) . "\n" . implode("\n", $sig['data']));
$part->addPart($part1);
$part->addPart($part2);
$new_part->addPart($part);
next($parts);
}
}
}
return $new_part;
}