本文整理汇总了PHP中Horde_Mime_Part::addPart方法的典型用法代码示例。如果您正苦于以下问题:PHP Horde_Mime_Part::addPart方法的具体用法?PHP Horde_Mime_Part::addPart怎么用?PHP Horde_Mime_Part::addPart使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Horde_Mime_Part
的用法示例。
在下文中一共展示了Horde_Mime_Part::addPart方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _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;
}
示例2: 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;
}
示例3: append
/**
* Append the current Draft message to the IMAP server.
*
* @return array An array with the following keys:
* - uid: (integer) The new draft message's IMAP UID.
* - atchash: (array) An attachment hash of newly added attachments.
*/
public function append($folderid)
{
// Init
$atc_map = array();
$atc_hash = array();
// Create the wrapper part.
$base = new Horde_Mime_Part();
$base->setType('multipart/mixed');
// Check to see if we have any existing parts to add.
if (!empty($this->_imapMessage)) {
foreach ($this->_imapMessage->getStructure() as $part) {
if ($part->isAttachment() && !in_array($part->getMimeId(), $this->_atcDelete)) {
$base->addPart($this->_imapMessage->getMimePart($part->getMimeId()));
}
}
}
// Add body
$base->addPart($this->_textPart);
// Add Mime headers
$base->addMimeHeaders(array('headers' => $this->_headers));
foreach ($this->_atcAdd as $atc) {
$base->addPart($atc);
$atc_map[$atc->displayname] = $atc->clientid;
}
$stream = $base->toString(array('stream' => true, 'headers' => $this->_headers->toString()));
$new_uid = $this->_imap->appendMessage($folderid, $stream, array('\\draft', '\\seen'));
foreach ($base as $part) {
if ($part->isAttachment() && !empty($atc_map[$part->getName()])) {
$atc_hash['add'][$atc_map[$part->getName()]] = $folderid . ':' . $stat['id'] . ':' . $part->getMimeId();
}
}
// If we pulled down an existing Draft, delete it now since the
// new one will replace it.
if (!empty($this->_imapMessage)) {
$this->_imap->deleteMessages(array($this->_draftUid), $folderid);
}
return array('uid' => $new_uid, 'atchash' => $atc_hash);
}
示例4: sendITipNotifications
/**
* Sends out iTip task notification to the assignee.
*
* Can be used to send task invitations, updates, and cancellations.
*
* @param Nag_Task $task The task in question.
* @param Horde_Notification_Handler $notification
* A notification object used to show result status.
* @param integer $action
* The type of notification to send. One of the Nag::ITIP_* values.
* @param Horde_Date $instance
* If cancelling a single instance of a recurring task, the date of
* this instance.
* @param string $range The range parameter if this is a recurring event.
* Possible values are self::RANGE_THISANDFUTURE
*/
public static function sendITipNotifications(Nag_Task $task, Horde_Notification_Handler $notification, $action, Horde_Date $instance = null, $range = null)
{
global $injector, $registry, $nag_shares;
if (!$task->assignee) {
return;
}
$ident = $injector->getInstance('Horde_Core_Factory_Identity')->create($task->creator);
if (!$ident->getValue('from_addr')) {
$notification->push(sprintf(_("You do not have an email address configured in your Personal Information Preferences. You must set one %shere%s before event notifications can be sent."), $registry->getServiceLink('prefs', 'kronolith')->add(array('app' => 'horde', 'group' => 'identities'))->link(), '</a>'), 'horde.error', array('content.raw'));
return;
}
// Generate image mime part first and only once, because we
// need the Content-ID.
$image = self::getImagePart('big_invitation.png');
$share = $nag_shares->getShare($task->tasklist);
$view = new Horde_View(array('templatePath' => NAG_TEMPLATES . '/itip'));
new Horde_View_Helper_Text($view);
$view->identity = $ident;
$view->task = $task;
$view->imageId = $image->getContentId();
$email = Nag::getUserEmail($task->assignee);
if (strpos($email, '@') === false) {
continue;
}
/* Determine all notification-specific strings. */
$method = 'REQUEST';
switch ($action) {
case self::ITIP_CANCEL:
/* Cancellation. */
$method = 'CANCEL';
$filename = 'task-cancellation.ics';
$view->subject = sprintf(_("Cancelled: %s"), $task->name);
if (empty($instance)) {
$view->header = sprintf(_("%s has cancelled \"%s\"."), $ident->getName(), $task->name);
} else {
$view->header = sprintf(_("%s has cancelled an instance of the recurring \"%s\"."), $ident->getName(), $task->name);
}
break;
case self::ITIP_UPDATE:
if (!empty($task->organizer) && $task->organizer != Nag::getUserEmail($task->creator)) {
// Sending a progress update.
$method = 'REPLY';
} else {
$method = 'UPDATE';
}
case self::ITIP_REQUEST:
default:
if (empty($task->status) || $task->status == self::RESPONSE_NONE) {
/* Invitation. */
$filename = 'task-invitation.ics';
$view->subject = $task->name;
$view->header = sprintf(_("%s wishes to make you aware of \"%s\"."), $ident->getName(), $task->name);
} else {
$filename = 'task-update.ics';
$view->subject = sprintf(_("Updated: %s."), $task->name);
$view->header = sprintf(_("%s wants to notify you about changes of \"%s\"."), $ident->getName(), $task->name);
}
break;
}
$view->attendees = $email;
$view->organizer = empty($task->organizer) ? $registry->convertUserName($task->creator, false) : $task->organizer;
/* Build the iCalendar data */
$iCal = new Horde_Icalendar();
$iCal->setAttribute('METHOD', $method);
$vevent = $task->toiCalendar($iCal);
$iCal->addComponent($vevent);
/* text/calendar part */
$ics = new Horde_Mime_Part();
$ics->setType('text/calendar');
$ics->setContents($iCal->exportvCalendar());
$ics->setName($filename);
$ics->setContentTypeParameter('METHOD', $method);
$ics->setCharset('UTF-8');
$ics->setEOL("\r\n");
/* application/ics part */
$ics2 = clone $ics;
$ics2->setType('application/ics');
/* multipart/mixed part */
$multipart = new Horde_Mime_Part();
$multipart->setType('multipart/mixed');
$inner = self::buildMimeMessage($view, 'notification', $image);
$inner->addPart($ics);
$multipart->addPart($inner);
$multipart->addPart($ics2);
//.........这里部分代码省略.........
示例5: encryptMIMEPart
/**
* Encrypts a MIME part using PGP.
*
* @param Horde_Mime_Part $mime_part The object to encrypt.
* @param array $params The parameters required for
* encryption
* ({@see _encryptMessage()}).
*
* @return mixed A Horde_Mime_Part object that is encrypted according to
* RFC 3156.
* @throws Horde_Crypt_Exception
*/
public function encryptMIMEPart($mime_part, $params = array())
{
$params = array_merge($params, array('type' => 'message'));
$signenc_body = $mime_part->toString(array('canonical' => true, 'headers' => true));
$message_encrypt = $this->encrypt($signenc_body, $params);
/* Set up MIME Structure according to RFC 3156. */
$part = new Horde_Mime_Part();
$part->setType('multipart/encrypted');
$part->setHeaderCharset('UTF-8');
$part->setContentTypeParameter('protocol', 'application/pgp-encrypted');
$part->setDescription(Horde_Crypt_Translation::t("PGP Encrypted Data"));
$part->setContents("This message is in MIME format and has been PGP encrypted.\n");
$part1 = new Horde_Mime_Part();
$part1->setType('application/pgp-encrypted');
$part1->setCharset(null);
$part1->setContents("Version: 1\n", array('encoding' => '7bit'));
$part->addPart($part1);
$part2 = new Horde_Mime_Part();
$part2->setType('application/octet-stream');
$part2->setCharset(null);
$part2->setContents($message_encrypt, array('encoding' => '7bit'));
$part2->setDisposition('inline');
$part->addPart($part2);
return $part;
}
示例6: getMultiPartMessage
/**
* Return the response as a MIME message.
*
* @param Horde_Itip_Response_Type $type The response type.
* @param Horde_Itip_Response_Options $options The options for the response.
*
* @return array A list of two object: The mime headers and the mime
* message.
*/
public function getMultiPartMessage(Horde_Itip_Response_Type $type, Horde_Itip_Response_Options $options)
{
$message = new Horde_Mime_Part();
$message->setType('multipart/alternative');
list($headers, $ics) = $this->getMessage($type, $options);
$body = new Horde_Mime_Part();
$body->setType('text/plain');
$options->prepareMessageMimePart($body);
$body->setContents(Horde_String::wrap($type->getMessage(), 76));
$message->addPart($body);
$message->addPart($ics);
return array($headers, $message);
}
示例7:
<?php
$part1 = new Horde_Mime_Part();
$part1->setType('text/plain');
$part1->setTransferEncoding('quoted-printable');
$part1->setCharset('UTF-8');
$part1->setDisposition('inline');
$part1->setBytes(249);
$part2 = new Horde_Mime_Part();
$part2->setType('application/x-vnd.kolab.note');
$part2->setTransferEncoding('quoted-printable');
$part2->setName('kolab.xml');
$part2->setDisposition('attachment');
$part2->setBytes(704);
$message = new Horde_Mime_Part();
$message->setType('multipart/mixed');
$message->addPart($part1);
$message->addPart($part2);
$message->buildMimeIds(0);
return $message;
示例8: _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)
//.........这里部分代码省略.........
示例9: _buildMailMessage
//.........这里部分代码省略.........
} 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;
}
$mime = null;
// Populate the EAS body structure with the MIME data, but
// remove the Content-Type and Content-Transfer-Encoding
// headers since we are building this ourselves.
$headers = $imap_message->getHeaders();
$headers->removeHeader('Content-Type');
$headers->removeHeader('Content-Transfer-Encoding');
$airsync_body->data = $base->toString(array('headers' => $headers, 'stream' => true));
$airsync_body->estimateddatasize = $base->getBytes();
} else {
// Signed/Encrypted message - can't mess with it at all.
$raw = new Horde_ActiveSync_Rfc822($imap_message->getFullMsg(true), false);
$airsync_body->estimateddatasize = $raw->getBytes();
$airsync_body->data = $raw->getString();
$eas_message->airsyncbaseattachments = $imap_message->getAttachments($version);
示例10: createEnvelope
/**
* Generates a new MIME messages that will wrap a Kolab groupware object.
*
* @return Horde_Mime_Part The new MIME message.
*/
protected function createEnvelope()
{
$envelope = new Horde_Mime_Part();
$envelope->setName('Kolab Groupware Data');
$envelope->setType('multipart/mixed');
$description = new Horde_Mime_Part();
$description->setName('Kolab Groupware Information');
$description->setType('text/plain');
$description->setDisposition('inline');
$description->setCharset('utf-8');
$description->setContents(sprintf(Horde_Kolab_Storage_Translation::t("This is a Kolab Groupware object. To view this object you will need an email client that understands the Kolab Groupware format. For a list of such email clients please visit %s"), 'http://www.kolab.org/content/kolab-clients'), array('encoding' => 'quoted-printable'));
$envelope->addPart($description);
return $envelope;
}
示例11: _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;
}
示例12: _getStructure
/**
* 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' => 'application/octet-stream', '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'] && !$hdrs->getValue('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->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($opts['ctype']);
}
/* 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);
}
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->addPart(self::parseMessage($body, array('forcemime' => true)));
}
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->addPart(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;
//.........这里部分代码省略.........
示例13: signMIMEPart
/**
* Sign a MIME part using S/MIME. This produces S/MIME Version 3.2
* compatible data (see RFC 5751 [3.4]).
*
* @param Horde_Mime_Part $mime_part The object to sign.
* @param array $params The parameters required for signing.
*
* @return Horde_Mime_Part A signed MIME part object.
* @throws Horde_Crypt_Exception
*/
public function signMIMEPart($mime_part, $params)
{
/* Sign the part as a message */
$message = $this->encrypt($mime_part->toString(array('headers' => true, 'canonical' => true)), $params);
/* Break the result into its components */
$mime_message = Horde_Mime_Part::parseMessage($message, array('forcemime' => true));
$smime_sign = $mime_message->getPart('2');
$smime_sign->setDescription(Horde_Crypt_Translation::t("S/MIME Signature"));
$smime_sign->setTransferEncoding('base64', array('send' => true));
$smime_part = new Horde_Mime_Part();
$smime_part->setType('multipart/signed');
$smime_part->setContents("This is a cryptographically signed message in MIME format.\n");
$smime_part->setContentTypeParameter('protocol', 'application/pkcs7-signature');
// Per RFC 5751 [3.4.3.2], 'sha1' has been deprecated for 'sha-1'.
$smime_part->setContentTypeParameter('micalg', 'sha-1');
$smime_part->addPart($mime_part);
$smime_part->addPart($smime_sign);
return $smime_part;
}
示例14: generate
/**
* Generate the MDN according to the specifications listed in RFC
* 3798 [3].
*
* @param boolean $action Was this MDN type a result of a manual
* action on part of the user?
* @param boolean $sending Was this MDN sent as a result of a manual
* action on part of the user?
* @param string $type The type of action performed by the user.
* Per RFC 3798 [3.2.6.2] the following types are
* valid:
* - deleted
* - displayed
* @param string $name The name of the local server.
* @param Mail $mailer A Mail driver.
* @param array $opts Additional options:
* - charset: (string) Default charset.
* DEFAULT: NONE
* - from_addr: (string) From address.
* DEFAULT: NONE
* @param array $mod The list of modifications. Per RFC 3798
* [3.2.6.3] the following modifications are
* valid:
* - error
* @param array $err If $mod is 'error', the additional
* information to provide. Key is the type of
* modification, value is the text.
*
* @throws Horde_Mime_Exception
*/
public function generate($action, $sending, $type, $name, $mailer, array $opts = array(), array $mod = array(), array $err = array())
{
$opts = array_merge(array('charset' => null, 'from_addr' => null), $opts);
$to = $this->getMdnReturnAddr();
$ua = $this->_headers->getUserAgent();
$orig_recip = $this->_headers->getValue('Original-Recipient');
if (!empty($orig_recip) && is_array($orig_recip)) {
$orig_recip = $orig_recip[0];
}
$msg_id = $this->_headers->getValue('Message-ID');
/* Create the Disposition field now (RFC 3798 [3.2.6]). */
$dispo = 'Disposition: ' . ($action ? 'manual-action' : 'automatic-action') . '/' . ($sending ? 'MDN-sent-manually' : 'MDN-sent-automatically') . '; ' . $type;
if (!empty($mod)) {
$dispo .= '/' . implode(', ', $mod);
}
/* Set up the mail headers. */
$msg_headers = new Horde_Mime_Headers();
$msg_headers->addMessageIdHeader();
$msg_headers->addUserAgentHeader($ua);
$msg_headers->addHeader('Date', date('r'));
if ($opts['from_addr']) {
$msg_headers->addHeader('From', $opts['from_addr']);
}
$msg_headers->addHeader('To', $this->getMdnReturnAddr());
$msg_headers->addHeader('Subject', Horde_Mime_Translation::t("Disposition Notification"));
/* MDNs are a subtype of 'multipart/report'. */
$msg = new Horde_Mime_Part();
$msg->setType('multipart/report');
$msg->setContentTypeParameter('report-type', 'disposition-notification');
/* The first part is a human readable message. */
$part_one = new Horde_Mime_Part();
$part_one->setType('text/plain');
$part_one->setCharset($opts['charset']);
if ($type == 'displayed') {
$contents = sprintf(Horde_Mime_Translation::t("The message sent on %s to %s with subject \"%s\" has been displayed.\n\nThis is no guarantee that the message has been read or understood."), $this->_headers->getValue('Date'), $this->_headers->getValue('To'), $this->_headers->getValue('Subject'));
$flowed = new Horde_Text_Flowed($contents, $opts['charset']);
$flowed->setDelSp(true);
$part_one->setContentTypeParameter('format', 'flowed');
$part_one->setContentTypeParameter('DelSp', 'Yes');
$part_one->setContents($flowed->toFlowed());
}
// TODO: Messages for other notification types.
$msg->addPart($part_one);
/* The second part is a machine-parseable description. */
$part_two = new Horde_Mime_Part();
$part_two->setType('message/disposition-notification');
$part_two_text = array('Reporting-UA: ' . $name . '; ' . $ua . "\n");
if (!empty($orig_recip)) {
$part_two_text[] = 'Original-Recipient: rfc822;' . $orig_recip . "\n";
}
if ($opts['from_addr']) {
$part_two_text[] = 'Final-Recipient: rfc822;' . $opts['from_addr'] . "\n";
}
if (!empty($msg_id)) {
$part_two_text[] = 'Original-Message-ID: rfc822;' . $msg_id . "\n";
}
$part_two_text[] = $dispo . "\n";
if (in_array('error', $mod) && isset($err['error'])) {
$part_two_text[] = 'Error: ' . $err['error'] . "\n";
}
$part_two->setContents($part_two_text);
$msg->addPart($part_two);
/* The third part is the text of the original message. RFC 3798 [3]
* allows us to return only a portion of the entire message - this
* is left up to the user. */
$part_three = new Horde_Mime_Part();
$part_three->setType('message/rfc822');
$part_three_text = array($this->_headers->toString());
if (!empty($this->_msgtext)) {
$part_three_text[] = $part_three->getEOL() . $this->_msgtext;
//.........这里部分代码省略.........
示例15: _getStructure
/**
* 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;
}