本文整理汇总了PHP中Horde_Mime_Part::setContents方法的典型用法代码示例。如果您正苦于以下问题:PHP Horde_Mime_Part::setContents方法的具体用法?PHP Horde_Mime_Part::setContents怎么用?PHP Horde_Mime_Part::setContents使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Horde_Mime_Part
的用法示例。
在下文中一共展示了Horde_Mime_Part::setContents方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: verifyIdentity
/**
* Sends a message to an email address supposed to be added to the
* identity.
*
* A message is send to this address containing a time-sensitive link to
* confirm that the address really belongs to that user.
*
* @param integer $id The identity's ID.
* @param string $old_addr The old From: address.
*
* @throws Horde_Mime_Exception
*/
public function verifyIdentity($id, $old_addr)
{
global $injector, $notification, $registry;
$hash = strval(new Horde_Support_Randomid());
$pref = $this->_confirmEmail();
$pref[$hash] = $this->get($id);
$pref[$hash][self::EXPIRE] = time() + self::EXPIRE_SECS;
$this->_confirmEmail($pref);
$new_addr = $this->getValue($this->_prefnames['from_addr'], $id);
$confirm = Horde::url($registry->getServiceLink('emailconfirm')->add('h', $hash)->setRaw(true), true);
$message = sprintf(Horde_Core_Translation::t("You have requested to add the email address \"%s\" to the list of your personal email addresses.\n\nGo to the following link to confirm that this is really your address:\n%s\n\nIf you don't know what this message means, you can delete it."), $new_addr, $confirm);
$msg_headers = new Horde_Mime_Headers();
$msg_headers->addHeaderOb(Horde_Mime_Headers_MessageId::create());
$msg_headers->addHeaderOb(Horde_Mime_Headers_UserAgent::create());
$msg_headers->addHeaderOb(Horde_Mime_Headers_Date::create());
$msg_headers->addHeader('To', $new_addr);
$msg_headers->addHeader('From', $old_addr);
$msg_headers->addHeader('Subject', Horde_Core_Translation::t("Confirm new email address"));
$body = new Horde_Mime_Part();
$body->setType('text/plain');
$body->setContents(Horde_String::wrap($message, 76));
$body->setCharset('UTF-8');
$body->send($new_addr, $msg_headers, $injector->getInstance('Horde_Mail'));
$notification->push(sprintf(Horde_Core_Translation::t("A message has been sent to \"%s\" to verify that this is really your address. The new email address is activated as soon as you confirm this message."), $new_addr), 'horde.message');
}
示例2: _getEmbeddedMimeParts
/**
* If this MIME part can contain embedded MIME part(s), and those part(s)
* exist, return a representation of that data.
*
* @return mixed A Horde_Mime_Part object representing the embedded data.
* Returns null if no embedded MIME part(s) exist.
*/
protected function _getEmbeddedMimeParts()
{
/* Get the data from the attachment. */
try {
if (!($tnef = $this->getConfigParam('tnef'))) {
$tnef = Horde_Compress::factory('Tnef');
$this->setConfigParam('tnef', $tnef);
}
$tnefData = $tnef->decompress($this->_mimepart->getContents());
} catch (Horde_Compress_Exception $e) {
$tnefData = array();
}
if (!count($tnefData)) {
return null;
}
$mixed = new Horde_Mime_Part();
$mixed->setType('multipart/mixed');
reset($tnefData);
while (list(, $data) = each($tnefData)) {
$temp_part = new Horde_Mime_Part();
$temp_part->setName($data['name']);
$temp_part->setDescription($data['name']);
$temp_part->setContents($data['stream']);
/* Short-circuit MIME-type guessing for winmail.dat parts;
* we're showing enough entries for them already. */
$type = $data['type'] . '/' . $data['subtype'];
if (in_array($type, array('application/octet-stream', 'application/base64'))) {
$type = Horde_Mime_Magic::filenameToMIME($data['name']);
}
$temp_part->setType($type);
$mixed->addPart($temp_part);
}
return $mixed;
}
示例3: getPart
/**
* Return the MIME part object.
*
* @param boolean $build If true, ensures the part contains the data.
*
* @return Horde_Mime_Part MIME part object.
* @throws IMP_Compose_Exception
*/
public function getPart($build = false)
{
if ($build && !$this->_isBuilt) {
$this->_part->setContents($this->storage->read()->stream, array('stream' => true));
$this->_isBuilt = true;
}
return $this->_part;
}
示例4: createMimePart
/**
* Generates a Horde_Mime_Part object, in accordance with RFC 3156, that
* contains a public key.
*
* @return Horde_Mime_Part Object that contains the armored public key.
*/
public function createMimePart()
{
$part = new Horde_Mime_Part();
$part->setType('application/pgp-keys');
$part->setHeaderCharset('UTF-8');
$part->setDescription(Horde_Pgp_Translation::t("PGP Public Key"));
$part->setContents(strval($this), array('encoding' => '7bit'));
return $part;
}
示例5: token
/**
* Renders a token into text matching the requested format.
*
* @param array $options The "options" portion of the token (second
* element).
*
* @return string The text rendered from the token options.
*/
public function token($options)
{
$part = new Horde_Mime_Part();
$part->setContents($options['text']);
$part->setType('application/x-extension-' . $options['attr']['type']);
$viewer = Horde_Mime_Viewer::factory('Horde_Core_Mime_Viewer_Syntaxhighlighter', $part, array('registry' => $GLOBALS['registry']));
$data = $viewer->render('inline');
$data = reset($data);
return $data['data'];
}
示例6: report
/**
*/
public function report(IMP_Contents $contents, $action)
{
global $injector, $registry;
$imp_compose = $injector->getInstance('IMP_Factory_Compose')->create();
switch ($this->_format) {
case 'redirect':
/* Send the message. */
try {
$imp_compose->redirectMessage($contents->getIndicesOb());
$imp_compose->sendRedirectMessage($this->_email, false);
return true;
} catch (IMP_Compose_Exception $e) {
$e->log();
}
break;
case 'digest':
default:
try {
$from_line = $injector->getInstance('IMP_Identity')->getFromLine();
} catch (Horde_Exception $e) {
$from_line = null;
}
/* Build the MIME structure. */
$mime = new Horde_Mime_Part();
$mime->setType('multipart/digest');
$rfc822 = new Horde_Mime_Part();
$rfc822->setType('message/rfc822');
$rfc822->setContents($contents->fullMessageText(array('stream' => true)));
$mime->addPart($rfc822);
$spam_headers = new Horde_Mime_Headers();
$spam_headers->addMessageIdHeader();
$spam_headers->addHeader('Date', date('r'));
$spam_headers->addHeader('To', $this->_email);
if (!is_null($from_line)) {
$spam_headers->addHeader('From', $from_line);
}
$spam_headers->addHeader('Subject', sprintf(_("%s report from %s"), $action == IMP_Spam::SPAM ? 'spam' : 'innocent', $registry->getAuth()));
/* Send the message. */
try {
$recip_list = $imp_compose->recipientList(array('to' => $this->_email));
$imp_compose->sendMessage($recip_list['list'], $spam_headers, $mime, 'UTF-8');
$rfc822->clearContents();
return true;
} catch (IMP_Compose_Exception $e) {
$e->log();
$rfc822->clearContents();
}
break;
}
return false;
}
示例7: load
private function load()
{
$headers = [];
$fetch_query = new \Horde_Imap_Client_Fetch_Query();
$fetch_query->bodyPart($this->attachmentId);
$fetch_query->mimeHeader($this->attachmentId);
$headers = array_merge($headers, ['importance', 'list-post', 'x-priority']);
$headers[] = 'content-type';
$fetch_query->headers('imp', $headers, ['cache' => true]);
// $list is an array of Horde_Imap_Client_Data_Fetch objects.
$ids = new \Horde_Imap_Client_Ids($this->messageId);
$headers = $this->conn->fetch($this->mailBox, $fetch_query, ['ids' => $ids]);
/** @var $fetch Horde_Imap_Client_Data_Fetch */
if (!isset($headers[$this->messageId])) {
throw new DoesNotExistException('Unable to load the attachment.');
}
$fetch = $headers[$this->messageId];
$mimeHeaders = $fetch->getMimeHeader($this->attachmentId, Horde_Imap_Client_Data_Fetch::HEADER_PARSE);
$this->mimePart = new \Horde_Mime_Part();
// To prevent potential problems with the SOP we serve all files with the
// MIME type "application/octet-stream"
$this->mimePart->setType('application/octet-stream');
// Serve all files with a content-disposition of "attachment" to prevent Cross-Site Scripting
$this->mimePart->setDisposition('attachment');
// Extract headers from part
$contentDisposition = $mimeHeaders->getValue('content-disposition', \Horde_Mime_Headers::VALUE_PARAMS);
if (!is_null($contentDisposition)) {
$vars = ['filename'];
foreach ($contentDisposition as $key => $val) {
if (in_array($key, $vars)) {
$this->mimePart->setDispositionParameter($key, $val);
}
}
} else {
$contentDisposition = $mimeHeaders->getValue('content-type', \Horde_Mime_Headers::VALUE_PARAMS);
$vars = ['name'];
foreach ($contentDisposition as $key => $val) {
if (in_array($key, $vars)) {
$this->mimePart->setContentTypeParameter($key, $val);
}
}
}
/* Content transfer encoding. */
if ($tmp = $mimeHeaders->getValue('content-transfer-encoding')) {
$this->mimePart->setTransferEncoding($tmp);
}
$body = $fetch->getBodyPart($this->attachmentId);
$this->mimePart->setContents($body);
}
示例8: testReplaceMime
public function testReplaceMime()
{
$fixture = file_get_contents(__DIR__ . '/fixtures/signed_attachment.eml');
$mime = new Horde_ActiveSync_Mime(Horde_Mime_Part::parseMessage($fixture));
foreach ($mime->contentTypeMap() as $id => $type) {
if ($mime->isAttachment($id, $type)) {
$part = new Horde_Mime_Part();
$part->setType('text/plain');
$part->setContents(sprintf('An attachment named %s was removed by Horde_ActiveSync_Test', $mime->getPart($id)->getName(true)));
$mime->removePart($id);
$mime->addPart($part);
}
}
$this->assertEquals(true, $mime->hasAttachments());
$this->assertEquals('An attachment named foxtrotjobs.png was removed by Horde_ActiveSync_Test', $mime->getPart('3')->getContents());
}
示例9: testBug10431
public function testBug10431()
{
$text = 'Das könnte zum Beispiel so aussehen, dass wir bei entsprechenden Anfragen diese an eine Kontaktperson bei Euch weiterleiten. Oder Ihr schnürt ein entsprechendes Paket, dass wir in unseren Angeboten mit anführen. Bei erfolgreicher Vermittlung bekämen wir eine Vermittlungsgebühr.
Wir ständen dann weiterhin für 3rd-Level-Support zur Verfügung, d.h. für alle Anfragen des Kunden bzgl. Horde, die nicht zum Tagesgeschäft gehören.';
$text = Horde_String::convertCharset($text, 'UTF-8', 'ISO-8859-1');
$textBody = new Horde_Mime_Part();
$textBody->setType('text/plain');
$textBody->setCharset('ISO-8859-1');
$flowed = new Horde_Text_Flowed($text, 'ISO-8859-1');
$flowed->setDelSp(true);
$textBody->setContents($flowed->toFlowed());
$flowed_txt = $textBody->toString(array('headers' => false));
$textBody2 = new Horde_Mime_Part();
$textBody2->setType('text/plain');
$textBody2->setCharset('ISO-8859-1');
$textBody2->setContents($flowed_txt, array('encoding' => 'quoted-printable'));
$flowed2 = new Horde_Text_Flowed($textBody2->getContents(), 'ISO-8859-1');
$flowed2->setMaxLength(0);
$flowed2->setDelSp(true);
$this->assertEquals($text, trim($flowed2->toFixed()));
}
示例10: getImagePart
/**
* Returns a MIME part for an image to be embedded into a HTML document.
*
* @param string $file An image file name.
*
* @return Horde_Mime_Part A MIME part representing the image.
*/
public static function getImagePart($file)
{
$background = Horde_Themes::img($file);
$image = new Horde_Mime_Part();
$image->setType('image/png');
$image->setContents(file_get_contents($background->fs));
$image->setContentId();
$image->setDisposition('attachment');
return $image;
}
示例11: process_message_part_body
/**
* Process the messagedata and part data to extract the content of this part.
*
* @param \Horde_Imap_Client_Data_Fetch $messagedata The structure and part of the message body
* @param \Horde_Mime_Part $partdata The part data
* @param string $part The part ID
* @return string
*/
private function process_message_part_body($messagedata, $partdata, $part)
{
// This is a content section for the main body.
// Get the string version of it.
$content = $messagedata->getBodyPart($part);
if (!$messagedata->getBodyPartDecode($part)) {
// Decode the content.
$partdata->setContents($content);
$content = $partdata->getContents();
}
// Convert the text from the current encoding to UTF8.
$content = \core_text::convert($content, $partdata->getCharset());
// Fix any invalid UTF8 characters.
// Note: XSS cleaning is not the responsibility of this code. It occurs immediately before display when
// format_text is called.
$content = clean_param($content, PARAM_RAW);
return $content;
}
示例12: catch
$gollem_vfs = $injector->getInstance('Gollem_Vfs');
$stream = null;
$data = '';
try {
if (is_callable(array($gollem_vfs, 'readStream'))) {
$stream = $gollem_vfs->readStream($vars->dir, $vars->file);
} else {
$data = $gollem_vfs->read($vars->dir, $vars->file);
}
} catch (Horde_Vfs_Exception $e) {
Horde::log($e, 'NOTICE');
throw $e;
}
$mime_part = new Horde_Mime_Part();
$mime_part->setType(Horde_Mime_Magic::extToMime($vars->type));
$mime_part->setContents(is_resource($stream) ? $stream : $data);
$mime_part->setName($vars->file);
// We don't know better.
$mime_part->setCharset('US-ASCII');
$ret = $injector->getInstance('Horde_Core_Factory_MimeViewer')->create($mime_part)->render('full');
reset($ret);
$key = key($ret);
try {
$size = $gollem_vfs->size($vars->dir, $vars->file);
} catch (Horde_Vfs_Exception $e) {
$size = null;
}
if (empty($ret)) {
$browser->downloadHeaders($vars->file, null, false, $size);
if (is_resource($stream)) {
fseek($stream, 0);
示例13: _buildMailMessage
//.........这里部分代码省略.........
$priority = preg_replace('/\\D+/', '', $priority);
} else {
$priority = $imap_message->getHeaders()->getValue('Importance');
}
$eas_message->importance = $this->_getEASImportance($priority);
// Get the body data.
$mbd = $imap_message->getMessageBodyDataObject($options);
if ($version == Horde_ActiveSync::VERSION_TWOFIVE) {
$eas_message->body = $mbd->plain['body']->stream;
$eas_message->bodysize = $mbd->plain['body']->length(true);
$eas_message->bodytruncated = $mbd->plain['truncated'];
$eas_message->attachments = $imap_message->getAttachments($version);
} else {
// Get the message body and determine original type.
if ($mbd->html) {
$eas_message->airsyncbasenativebodytype = Horde_ActiveSync::BODYPREF_TYPE_HTML;
} else {
$eas_message->airsyncbasenativebodytype = Horde_ActiveSync::BODYPREF_TYPE_PLAIN;
}
$airsync_body = Horde_ActiveSync::messageFactory('AirSyncBaseBody');
$body_type_pref = $mbd->getBodyTypePreference();
if ($body_type_pref == Horde_ActiveSync::BODYPREF_TYPE_MIME) {
$this->_logger->info(sprintf('[%s] Sending MIME Message.', $this->_procid));
// ActiveSync *REQUIRES* all data sent to be in UTF-8, so we
// must convert the body parts to UTF-8. Unfortunately if the
// email is signed (or encrypted for that matter) we can't
// alter the data in anyway or the signature will not be
// verified, so we fetch the entire message and hope for the best.
if (!$imap_message->isSigned() && !$imap_message->isEncrypted()) {
$mime = new Horde_Mime_Part();
if ($mbd->plain) {
$plain_mime = new Horde_Mime_Part();
$plain_mime->setType('text/plain');
$plain_mime->setContents($mbd->plain['body']->stream, array('usestream' => true));
$plain_mime->setCharset('UTF-8');
}
if ($mbd->html) {
$html_mime = new Horde_Mime_Part();
$html_mime->setType('text/html');
$html_mime->setContents($mbd->html['body']->stream, array('usestream' => true));
$html_mime->setCharset('UTF-8');
}
// Sanity check the mime type
if (!$mbd->html && !empty($plain_mime)) {
$mime = $plain_mime;
} elseif (!$mbd->plain && !empty($html_mime)) {
$mime = $html_mime;
} elseif (!empty($plain_mime) && !empty($html_mime)) {
$mime->setType('multipart/alternative');
$mime->addPart($plain_mime);
$mime->addPart($html_mime);
}
$html_mime = null;
$plain_mime = null;
// If we have attachments, create a multipart/mixed wrapper.
if ($imap_message->hasAttachments()) {
$base = new Horde_Mime_Part();
$base->setType('multipart/mixed');
$base->addPart($mime);
$atc = $imap_message->getAttachmentsMimeParts();
foreach ($atc as $atc_part) {
$base->addPart($atc_part);
}
$eas_message->airsyncbaseattachments = $imap_message->getAttachments($version);
} else {
$base = $mime;
示例14: armorToPart
/**
* Converts armored input into a Horde_Mime_Part object.
*
* @param mixed $input Armored input.
* @param array $opts Additional options:
* - charset: (string) Charset of the armored input.
*
* @return mixed Either null if no PGP data was found, or a
* Horde_Mime_Part object.
*/
public function armorToPart($input, array $opts = array())
{
$opts = array_merge(array('charset' => 'UTF-8'), $opts);
$armor = Horde_Pgp_Armor::create($input);
$new_part = new Horde_Mime_Part();
$new_part->setType('multipart/mixed');
foreach ($armor as $val) {
switch (get_class($val)) {
case 'Horde_Pgp_Element_Text':
$part = new Horde_Mime_Part();
$part->setType('text/plain');
$part->setCharset($opts['charset']);
$part->setContents($val->message[0]->data);
$new_part[] = $part;
break;
case 'Horde_Pgp_Element_PrivateKey':
case 'Horde_Pgp_Element_PublicKey':
$part = new Horde_Mime_Part();
$part->setType('application/pgp-keys');
$part->setContents(strval($val));
$new_part[] = $part;
break;
case 'Horde_Pgp_Element_Message':
// TODO: Message can also be text or signature
$part = $this->_encryptBase($val);
$part->setMetadata(self::PGP_ARMOR, true);
$part['2']->setMetadata(self::PGP_CHARSET, isset($val->headers['Charset']) ? $val->headers['Charset'] : 'UTF-8');
$new_part[] = $part;
break;
case 'Horde_Pgp_Element_SignedMessage':
$part = $this->_signPart($val->text, $val->signature);
$new_part[] = $part;
break;
}
}
return count($new_part->getParts()) ? $new_part : null;
}
示例15: _getBodyPart
/**
* Build the data needed for the BodyPart part.
*
* @param Horde_Imap_Client_Data_Fetch $data The FETCH results.
* @param Horde_Mime_Part $mime The plaintext MIME part.
* @param boolean $to_html If true, $id is assumed to be a text/plain
* part and is converted to html.
*
* @return array The BodyPart data.
* - charset: (string) The charset of the text.
* - body: (string) The body text.
* - truncated: (boolean) True if text was truncated.
* - size: (integer) The original part size, in bytes.
*/
protected function _getBodyPart(Horde_Imap_Client_Data_Fetch $data, Horde_Mime_Part $mime, $to_html)
{
$id = $mime->getMimeId();
$text = $data->getBodyPart($id);
if (!$data->getBodyPartDecode($id)) {
$mime->setContents($text);
$text = $mime->getContents();
}
if ($to_html) {
$text = Horde_Text_Filter::filter($text, 'Text2html', array('parselevel' => Horde_Text_Filter_Text2html::MICRO, 'charset' => $mime->getCharset()));
$size = strlen($text);
} else {
$size = !is_null($data->getBodyPartSize($id)) ? $data->getBodyPartSize($id) : strlen($text);
}
if (!empty($this->_options['bodypartprefs']['truncationsize'])) {
$text = Horde_String::substr($text, 0, $this->_options['bodypartprefs']['truncationsize'], $mime->getCharset());
}
return array('charset' => $mime->getCharset(), 'body' => $text, 'truncated' => $size > strlen($text), 'size' => $size);
}