本文整理汇总了PHP中Horde_Mime_Part::setCharset方法的典型用法代码示例。如果您正苦于以下问题:PHP Horde_Mime_Part::setCharset方法的具体用法?PHP Horde_Mime_Part::setCharset怎么用?PHP Horde_Mime_Part::setCharset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Horde_Mime_Part
的用法示例。
在下文中一共展示了Horde_Mime_Part::setCharset方法的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: 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()));
}
示例3: 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;
}
示例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: _addAttachment
/**
* Adds an attachment to the outgoing compose message.
*
* @param string $atc_file Temporary file containing attachment contents.
* @param integer $bytes Size of data, in bytes.
* @param string $filename Filename of data.
* @param string $type MIME type of data.
*
* @return IMP_Compose_Attachment Attachment object.
* @throws IMP_Compose_Exception
*/
protected function _addAttachment($atc_file, $bytes, $filename, $type)
{
global $conf, $injector;
$atc = new Horde_Mime_Part();
$atc->setBytes($bytes);
/* Try to determine the MIME type from 1) the extension and
* then 2) analysis of the file (if available). */
if (strlen($filename)) {
$atc->setName($filename);
if ($type == 'application/octet-stream') {
$type = Horde_Mime_Magic::filenameToMIME($filename, false);
}
}
$atc->setType($type);
if ($atc->getType() == 'application/octet-stream' || $atc->getPrimaryType() == 'text') {
$analyze = Horde_Mime_Magic::analyzeFile($atc_file, empty($conf['mime']['magic_db']) ? null : $conf['mime']['magic_db'], array('nostrip' => true));
$atc->setCharset('UTF-8');
if ($analyze) {
$ctype = new Horde_Mime_Headers_ContentParam('Content-Type', $analyze);
$atc->setType($ctype->value);
if (isset($ctype->params['charset'])) {
$atc->setCharset($ctype->params['charset']);
}
}
} else {
$atc->setHeaderCharset('UTF-8');
}
$atc_ob = new IMP_Compose_Attachment($this, $atc, $atc_file);
/* Check for attachment size limitations. */
$size_limit = null;
if ($atc_ob->linked) {
if (!empty($conf['compose']['link_attach_size_limit'])) {
$linked = true;
$size_limit = 'link_attach_size_limit';
}
} elseif (!empty($conf['compose']['attach_size_limit'])) {
$linked = false;
$size_limit = 'attach_size_limit';
}
if (!is_null($size_limit)) {
$total_size = $conf['compose'][$size_limit] - $bytes;
foreach ($this as $val) {
if ($val->linked == $linked) {
$total_size -= $val->getPart()->getBytes();
}
}
if ($total_size < 0) {
throw new IMP_Compose_Exception(strlen($filename) ? sprintf(_("Attached file \"%s\" exceeds the attachment size limits. File NOT attached."), $filename) : _("Attached file exceeds the attachment size limits. File NOT attached."));
}
}
try {
$injector->getInstance('Horde_Core_Hooks')->callHook('compose_attachment', 'imp', array($atc_ob));
} catch (Horde_Exception_HookNotSet $e) {
}
$this->_atc[$atc_ob->id] = $atc_ob;
$this->changed = 'changed';
return $atc_ob;
}
示例6: _buildMailMessage
//.........这里部分代码省略.........
} 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;
}
示例7: 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;
}
示例8: saveObject
/**
* Save an object in this folder.
*
* @param array $object The array that holds the data of the object.
* @param int $data_version The format handler version.
* @param string $object_type The type of the kolab object.
* @param string $id The IMAP id of the old object if it
* existed before
* @param array $old_object The array that holds the current data of the
* object.
*
* @return boolean True on success.
*/
public function saveObject(&$object, $data_version, $object_type, $id = null, &$old_object = null)
{
// Select folder
$this->_driver->select($this->_path);
$new_headers = new Horde_Mime_Headers();
$new_headers->setEOL("\r\n");
$formats = $this->getFormats();
$handlers = array();
foreach ($formats as $type) {
$handlers[$type] =& Horde_Kolab_Format::factory($type, $object_type, $data_version);
if (is_a($handlers[$type], 'PEAR_Error')) {
if ($type == 'XML') {
return $handlers[$type];
}
Horde::log(sprintf('Loading format handler "%s" failed: %s', $type, $handlers[$type]->getMessage()), 'ERR');
continue;
}
}
if ($id != null) {
/** Update an existing kolab object */
if (!in_array($id, $this->_driver->getUids($this->_path))) {
return PEAR::raiseError(sprintf(Horde_Kolab_Storage_Translation::t("The message with ID %s does not exist. This probably means that the Kolab object has been modified by somebody else while you were editing it. Your edits have been lost."), $id));
}
/** Parse email and load Kolab format structure */
$result = $this->parseMessage($id, $handlers['XML']->getMimeType(), true, $formats);
if (is_a($result, 'PEAR_Error')) {
return $result;
}
list($old_message, $part_ids, $mime_message, $mime_headers) = $result;
if (is_a($old_message, 'PEAR_Error')) {
return $old_message;
}
if (isset($object['_attachments']) && isset($old_object['_attachments'])) {
$attachments = array_keys($object['_attachments']);
foreach (array_keys($old_object['_attachments']) as $attachment) {
if (!in_array($attachment, $attachments)) {
foreach ($mime_message->getParts() as $part) {
if ($part->getName() === $attachment) {
foreach (array_keys($mime_message->_parts) as $key) {
if ($mime_message->_parts[$key]->getMimeId() == $part->getMimeId()) {
unset($mime_message->_parts[$key]);
break;
}
}
$mime_message->_generateIdMap($mime_message->_parts);
}
}
}
}
}
$object = array_merge($old_object, $object);
if (isset($attachments)) {
foreach ($mime_message->getParts() as $part) {
$name = $part->getName();
foreach ($attachments as $attachment) {
if ($name === $attachment) {
$object['_attachments'][$attachment]['id'] = $part->getMimeId();
}
}
}
}
/** Copy email header */
if (!empty($mime_headers) && !$mime_headers === false) {
foreach ($mime_headers as $header => $value) {
$new_headers->addheader($header, $value);
}
}
} else {
$mime_message = $this->_prepareNewMessage($new_headers);
$mime_part_id = false;
}
if (isset($object['_attachments'])) {
$attachments = array_keys($object['_attachments']);
foreach ($attachments as $attachment) {
$data = $object['_attachments'][$attachment];
if (!isset($data['content']) && !isset($data['path'])) {
/**
* There no new content and no new path. Do not rewrite the
* attachment.
*/
continue;
}
$part = new Horde_Mime_Part();
$part->setType(isset($data['type']) ? $data['type'] : null);
$part->setContents(isset($data['content']) ? $data['content'] : file_get_contents($data['path']));
$part->setCharset('UTF-8');
$part->setTransferEncoding('quoted-printable');
//.........这里部分代码省略.........
示例9: 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;
}
示例10: createFreshKolabPart
/**
* Embed the Kolab content into a new MIME Part.
*
* @param resource $content The Kolab content.
*
* @return Horde_Mime_Part The MIME part that encapsules the Kolab content.
*/
protected function createFreshKolabPart($content)
{
$part = new Horde_Mime_Part();
$part->setCharset('utf-8');
$part->setDisposition('inline');
$part->setDispositionParameter('x-kolab-type', 'xml');
$part->setName('kolab.xml');
$part->setType(Horde_Kolab_Storage_Object_MimeType::getMimeTypeFromObjectType($this->getType()));
$part->setContents($content, array('encoding' => 'quoted-printable'));
return $part;
}
示例11: testNullCharactersNotAllowedInMimeHeaderData
public function testNullCharactersNotAllowedInMimeHeaderData()
{
$part = new Horde_Mime_Part();
$part->setType("text/plain");
$this->assertEquals('text/plain', $part->getType());
$part->setDisposition("inline");
$this->assertEquals('inline', $part->getDisposition());
$part->setDispositionParameter('size', '123' . "" . '456');
$this->assertEquals(123456, $part->getDispositionParameter('size'));
$part->setDispositionParameter('foo', "foobar");
$this->assertEquals('foobar', $part->getDispositionParameter('foo'));
$part->setCharset("utf-8");
$this->assertEquals('utf-8', $part->getCharset());
$part->setName("foobar");
$this->assertEquals('foobar', $part->getName());
$this->assertEquals('foobar', $part->getDispositionParameter('filename'));
$this->assertEquals('foobar', $part->getContentTypeParameter('name'));
$part->setLanguage("en");
$this->assertEquals(array('en'), $part->getLanguage());
$part->setLanguage(array("en", "de"));
$this->assertEquals(array('en', 'de'), $part->getLanguage());
$part->setDuration('123' . "" . '456');
$this->assertEquals(123456, $part->getDuration());
$part->setBytes('123' . "" . '456');
$this->assertEquals(123456, $part->getBytes());
$part->setDescription("foobar");
$this->assertEquals('foobar', $part->getDescription());
$part->setContentTypeParameter('foo', "foobar");
$this->assertEquals('foobar', $part->getContentTypeParameter('foo'));
$part->setContentId("foobar");
$this->assertEquals('foobar', $part->getContentId());
}
示例12: encryptMIMEPart
/**
* Encrypt a MIME part using S/MIME. This produces S/MIME Version 3.2
* compatible data (see RFC 5751 [3.3]).
*
* @param Horde_Mime_Part $mime_part The object to encrypt.
* @param array $params The parameters required for
* encryption.
*
* @return Horde_Mime_Part An encrypted MIME part object.
* @throws Horde_Crypt_Exception
*/
public function encryptMIMEPart($mime_part, $params = array())
{
/* Sign the part as a message */
$message = $this->encrypt($mime_part->toString(array('headers' => true, 'canonical' => true)), $params);
$msg = new Horde_Mime_Part();
$msg->setCharset($this->_params['email_charset']);
$msg->setHeaderCharset('UTF-8');
$msg->setDescription(Horde_Crypt_Translation::t("S/MIME Encrypted Message"));
$msg->setDisposition('inline');
$msg->setType('application/pkcs7-mime');
$msg->setContentTypeParameter('smime-type', 'enveloped-data');
$msg->setContents(substr($message, strpos($message, "\n\n") + 2), array('encoding' => 'base64'));
return $msg;
}
示例13: sendNotification
/**
* Send notification to attachment owner.
*/
public function sendNotification()
{
global $conf, $injector, $registry;
if (empty($conf['compose']['link_attachments_notify'])) {
return;
}
try {
$identity = $injector->getInstance('Horde_Core_Factory_Identity')->create($this->_user);
$address = $identity->getDefaultFromAddress();
/* Ignore missing addresses, which are returned as <>. */
if (strlen($address) < 3 || $this->_getDeleteToken()) {
return;
}
$address_full = $identity->getDefaultFromAddress(true);
/* Load user prefs to correctly translate gettext strings. */
if (!$registry->getAuth()) {
$prefs = $injector->getInstance('Horde_Core_Factory_Prefs')->create('imp', array('user' => $this->_user));
$registry->setLanguageEnvironment($prefs->getValue('language'));
}
$h = new Horde_Mime_Headers();
$h->addReceivedHeader(array('dns' => $injector->getInstance('Net_DNS2_Resolver'), 'server' => $conf['server']['name']));
$h->addMessageIdHeader();
$h->addUserAgentHeader();
$h->addHeader('Date', date('r'));
$h->addHeader('From', $address_full);
$h->addHeader('To', $address_full);
$h->addHeader('Subject', _("Notification: Linked attachment downloaded"));
$h->addHeader('Auto-Submitted', 'auto-generated');
$msg = new Horde_Mime_Part();
$msg->setType('text/plain');
$msg->setCharset('UTF-8');
$md = $this->_atc->getMetadata();
$msg->setContents(Horde_String::wrap(_("Your linked attachment has been downloaded by at least one user.") . "\n\n" . sprintf(_("Name: %s"), $md->filename) . "\n" . sprintf(_("Type: %s"), $md->type) . "\n" . sprintf(_("Sent Date: %s"), date('r', $md->time)) . "\n\n" . _("Click on the following link to permanently delete the attachment:") . "\n" . strval($this->_atc->link_url->add('d', $this->_getDeleteToken(true)))));
$msg->send($address, $h, $injector->getInstance('Horde_Mail'));
} catch (Exception $e) {
Horde::log($e, 'ERR');
}
}
示例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:
<?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;