本文整理汇总了PHP中Mail_mimeDecode::getBodyRecursive方法的典型用法代码示例。如果您正苦于以下问题:PHP Mail_mimeDecode::getBodyRecursive方法的具体用法?PHP Mail_mimeDecode::getBodyRecursive怎么用?PHP Mail_mimeDecode::getBodyRecursive使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mail_mimeDecode
的用法示例。
在下文中一共展示了Mail_mimeDecode::getBodyRecursive方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: testMimeDecode
function testMimeDecode($file, $new_file)
{
if (!defined('LOGLEVEL')) {
define('LOGLEVEL', LOGLEVEL_DEBUG);
}
if (!defined('LOGUSERLEVEL')) {
define('LOGUSERLEVEL', LOGLEVEL_DEVICEID);
}
printf("TEST MIME DECODE\n");
$mobj = new Mail_mimeDecode(file_get_contents($file));
$message = $mobj->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'charset' => 'utf-8'));
$handle = fopen($new_file, "w");
fwrite($handle, build_mime_message($message));
fclose($handle);
foreach ($message->headers as $k => $v) {
if (is_array($v)) {
foreach ($v as $vk => $vv) {
printf("Header <%s> <%s> <%s>\n", $k, $vk, $vv);
}
} else {
printf("Header <%s> <%s>\n", $k, $v);
}
}
$text = $html = "";
Mail_mimeDecode::getBodyRecursive($message, "plain", $text);
Mail_mimeDecode::getBodyRecursive($message, "html", $html);
printf("TEXT Body <%s>\n", $text);
printf("HTML Body <%s>\n", $html);
}
示例2: GetMessage
/**
* Returns the actual SyncXXX object type.
*
* @param string $folderid id of the parent folder
* @param string $id id of the message
* @param ContentParameters $contentparameters parameters of the requested message (truncation, mimesupport etc)
*
* @access public
* @return object/false false if the message could not be retrieved
*/
public function GetMessage($folderid, $id, $contentparameters)
{
$truncsize = Utils::GetTruncSize($contentparameters->GetTruncation());
$mimesupport = $contentparameters->GetMimeSupport();
$bodypreference = $contentparameters->GetBodyPreference();
/* fmbiete's contribution r1528, ZP-320 */
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetMessage('%s', '%s', '%s')", $folderid, $id, implode(",", $bodypreference)));
$folderImapid = $this->getImapIdFromFolderId($folderid);
// Get flags, etc
$stat = $this->StatMessage($folderid, $id);
if ($stat) {
$this->imap_reopen_folder($folderImapid);
$mail = @imap_fetchheader($this->mbox, $id, FT_UID) . @imap_body($this->mbox, $id, FT_PEEK | FT_UID);
if (empty($mail)) {
throw new StatusException(sprintf("BackendIMAP->GetMessage(): Error, message not found, maybe was moved"), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT);
}
$mobj = new Mail_mimeDecode($mail);
$message = $mobj->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'rfc_822bodies' => true, 'charset' => 'utf-8'));
$is_multipart = is_multipart($message);
$is_smime = is_smime($message);
$is_encrypted = $is_smime ? is_encrypted($message) : false;
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetMessage(): Message is multipart: %d, smime: %d, smime encrypted: %d", $is_multipart, $is_smime, $is_encrypted));
//Select body type preference
$bpReturnType = SYNC_BODYPREFERENCE_PLAIN;
if ($bodypreference !== false) {
$bpReturnType = Utils::GetBodyPreferenceBestMatch($bodypreference);
// changed by mku ZP-330
}
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetMessage(): getBodyPreferenceBestMatch: %d", $bpReturnType));
// Prefered format is MIME -OR- message is SMIME -OR- the device supports MIME (iPhone) and doesn't really understand HTML
if ($bpReturnType == SYNC_BODYPREFERENCE_MIME || $is_smime || in_array(SYNC_BODYPREFERENCE_MIME, $bodypreference)) {
$bpReturnType = SYNC_BODYPREFERENCE_MIME;
}
// We need the text body even though MIME is used, for the preview
$textBody = "";
Mail_mimeDecode::getBodyRecursive($message, "html", $textBody, true);
if (strlen($textBody) > 0) {
if ($bpReturnType != SYNC_BODYPREFERENCE_MIME) {
$bpReturnType = SYNC_BODYPREFERENCE_HTML;
}
} else {
Mail_mimeDecode::getBodyRecursive($message, "plain", $textBody, true);
if ($bpReturnType != SYNC_BODYPREFERENCE_MIME) {
$bpReturnType = SYNC_BODYPREFERENCE_PLAIN;
}
}
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetMessage(): after thinking a bit we will use: %d", $bpReturnType));
$output = new SyncMail();
if (Request::GetProtocolVersion() >= 12.0) {
$output->asbody = new SyncBaseBody();
switch ($bpReturnType) {
case SYNC_BODYPREFERENCE_PLAIN:
$output->asbody->data = $textBody;
break;
case SYNC_BODYPREFERENCE_HTML:
$output->asbody->data = $textBody;
break;
case SYNC_BODYPREFERENCE_MIME:
if ($is_smime) {
$output->asbody->data = $mail;
if ($is_encrypted) {
// #190, KD 2015-06-04 - If message body is encrypted we'd drop it as data should only be in the attachment but... there's no good way to let only headers through...
$truncsize = 500;
}
} else {
$output->asbody->data = build_mime_message($message);
}
break;
case SYNC_BODYPREFERENCE_RTF:
ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->GetMessage(): RTF Format NOT CHECKED");
$output->asbody->data = base64_encode($textBody);
break;
}
// truncate body, if requested.
// MIME should not be truncated, but encrypted messages are truncated always to a minimal fixed size
if (($bpReturnType !== SYNC_BODYPREFERENCE_MIME || $is_encrypted) && strlen($output->asbody->data) > $truncsize) {
$output->asbody->data = Utils::Utf8_truncate($output->asbody->data, $truncsize);
$output->asbody->truncated = 1;
} else {
$output->asbody->truncated = 0;
}
$output->asbody->type = $bpReturnType;
if ($bpReturnType == SYNC_BODYPREFERENCE_MIME) {
// NativeBodyType can be only (1 => PLAIN, 2 => HTML, 3 => RTF). MIME uses 1
$output->nativebodytype = SYNC_BODYPREFERENCE_PLAIN;
} else {
$output->nativebodytype = $bpReturnType;
}
$output->asbody->estimatedDataSize = strlen($output->asbody->data);
$bpo = $contentparameters->BodyPreference($output->asbody->type);
//.........这里部分代码省略.........
示例3: GetMessage
/**
* Returns the actual SyncXXX object type.
*
* @param string $folderid id of the parent folder
* @param string $id id of the message
* @param ContentParameters $contentparameters parameters of the requested message (truncation, mimesupport etc)
*
* @access public
* @return object/false false if the message could not be retrieved
*/
public function GetMessage($folderid, $id, $contentparameters)
{
$truncsize = Utils::GetTruncSize($contentparameters->GetTruncation());
$mimesupport = $contentparameters->GetMimeSupport();
$bodypreference = $contentparameters->GetBodyPreference();
/* fmbiete's contribution r1528, ZP-320 */
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetMessage('%s','%s')", $folderid, $id));
$folderImapid = $this->getImapIdFromFolderId($folderid);
// Get flags, etc
$stat = $this->StatMessage($folderid, $id);
if ($stat) {
$this->imap_reopen_folder($folderImapid);
$mail = @imap_fetchheader($this->mbox, $id, FT_UID) . @imap_body($this->mbox, $id, FT_PEEK | FT_UID);
if (empty($mail)) {
throw new StatusException(sprintf("BackendIMAP->GetMessage(): Error, message not found, maybe was moved"), SYNC_ITEMOPERATIONSSTATUS_INVALIDATT);
}
$mobj = new Mail_mimeDecode($mail);
$message = $mobj->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'charset' => 'utf-8'));
/* BEGIN fmbiete's contribution r1528, ZP-320 */
$output = new SyncMail();
//Select body type preference
$bpReturnType = SYNC_BODYPREFERENCE_PLAIN;
if ($bodypreference !== false) {
$bpReturnType = Utils::GetBodyPreferenceBestMatch($bodypreference);
// changed by mku ZP-330
}
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetMessage - getBodyPreferenceBestMatch: %d", $bpReturnType));
if (is_smime($message)) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendIMAP->GetMessage - Message is SMIME, forcing to work with MIME"));
$bpReturnType = SYNC_BODYPREFERENCE_MIME;
}
//Get body data
Mail_mimeDecode::getBodyRecursive($message, "plain", $plainBody);
Mail_mimeDecode::getBodyRecursive($message, "html", $htmlBody);
if ($plainBody == "") {
$plainBody = Utils::ConvertHtmlToText($htmlBody);
}
$htmlBody = str_replace("\n", "\r\n", str_replace("\r", "", $htmlBody));
$plainBody = str_replace("\n", "\r\n", str_replace("\r", "", $plainBody));
if (Request::GetProtocolVersion() >= 12.0) {
$output->asbody = new SyncBaseBody();
switch ($bpReturnType) {
case SYNC_BODYPREFERENCE_PLAIN:
$output->asbody->data = $plainBody;
break;
case SYNC_BODYPREFERENCE_HTML:
if ($htmlBody == "") {
$output->asbody->data = $plainBody;
$bpReturnType = SYNC_BODYPREFERENCE_PLAIN;
} else {
$output->asbody->data = $htmlBody;
}
break;
case SYNC_BODYPREFERENCE_MIME:
if (is_smime($message)) {
$output->asbody->data = $mail;
} else {
$output->asbody->data = build_mime_message($message);
}
break;
case SYNC_BODYPREFERENCE_RTF:
ZLog::Write(LOGLEVEL_DEBUG, "BackendIMAP->GetMessage RTF Format NOT CHECKED");
$output->asbody->data = base64_encode($plainBody);
break;
}
// truncate body, if requested, but never truncate MIME messages
if ($bpReturnType !== SYNC_BODYPREFERENCE_MIME && strlen($output->asbody->data) > $truncsize) {
$output->asbody->data = Utils::Utf8_truncate($output->asbody->data, $truncsize);
$output->asbody->truncated = 1;
} else {
$output->asbody->truncated = 0;
}
$output->asbody->type = $bpReturnType;
if ($bpReturnType == SYNC_BODYPREFERENCE_MIME) {
$output->nativebodytype = SYNC_BODYPREFERENCE_PLAIN;
// http://msdn.microsoft.com/en-us/library/ee220018%28v=exchg.80%29.aspx
} else {
$output->nativebodytype = $bpReturnType;
}
$output->asbody->estimatedDataSize = strlen($output->asbody->data);
$bpo = $contentparameters->BodyPreference($output->asbody->type);
if (Request::GetProtocolVersion() >= 14.0 && $bpo->GetPreview()) {
$output->asbody->preview = Utils::Utf8_truncate(Utils::ConvertHtmlToText($plainBody), $bpo->GetPreview());
}
} else {
// ASV_2.5
$output->bodytruncated = 0;
/* BEGIN fmbiete's contribution r1528, ZP-320 */
if ($bpReturnType == SYNC_BODYPREFERENCE_MIME) {
// truncate body, if requested, but never truncate MIME messages
//.........这里部分代码省略.........
示例4: getBodyRecursive
/**
* Get all parts in the message with specified type and concatenate them together, unless the
* Content-Disposition is 'attachment', in which case the text is apparently an attachment
*
* @param string $message mimedecode message(part)
* @param string $message message subtype
* @param string &$body body reference
* @param boolean $replace_nr replace \n\r with \n
*
* @return void
* @access public
*/
static function getBodyRecursive($message, $subtype, &$body, $replace_nr = false)
{
if (!isset($message->ctype_primary)) {
return;
}
if (strcasecmp($message->ctype_primary, "text") == 0 && strcasecmp($message->ctype_secondary, $subtype) == 0 && isset($message->body)) {
if ($replace_nr) {
$body .= str_replace("\n", "\r\n", str_replace("\r", "", $message->body));
} else {
$body .= $message->body;
}
}
if (strcasecmp($message->ctype_primary, "multipart") == 0 && isset($message->parts) && is_array($message->parts)) {
foreach ($message->parts as $part) {
// Check testing/samples/m1009.txt
// Content-Type: text/plain; charset=us-ascii; name="hareandtoroise.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="hareandtoroise.txt"
// We don't want to show that file text (outlook doesn't show it), so if we have content-disposition we don't apply recursivity
if (!isset($part->disposition)) {
Mail_mimeDecode::getBodyRecursive($part, $subtype, $body, $replace_nr);
}
}
}
}
示例5: define
<?php
// Test MIME preview
// This code will extract the preview text for a message
require_once 'vendor/autoload.php';
define('LOGLEVEL', LOGLEVEL_DEBUG);
define('LOGUSERLEVEL', LOGLEVEL_DEVICEID);
$file = "testing/samples/messages/zpush-html-preview-bug.txt";
$mobj = new Mail_mimeDecode(file_get_contents($file));
$message = $mobj->decode(array('decode_headers' => true, 'decode_bodies' => true, 'include_bodies' => true, 'rfc_822bodies' => true, 'charset' => 'utf-8'));
unset($mobj);
$previewText = "";
Mail_mimeDecode::getBodyRecursive($message, "plain", $previewText, true);
if (strlen($previewText) == 0) {
printf("No Plain part found\n");
Mail_mimeDecode::getBodyRecursive($message, "html", $previewText, true);
$previewText = Utils::ConvertHtmlToText($previewText);
}
printf("%s\n", Utils::Utf8_truncate($previewText, 250));