本文整理汇总了PHP中imap_bodystruct函数的典型用法代码示例。如果您正苦于以下问题:PHP imap_bodystruct函数的具体用法?PHP imap_bodystruct怎么用?PHP imap_bodystruct使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imap_bodystruct函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getAttachments
function getAttachments($imap, $mailNum, $part, $partNum)
{
$attachments = array();
if (isset($part->parts)) {
foreach ($part->parts as $key => $subpart) {
if ($partNum != "") {
$newPartNum = $partNum . "." . ($key + 1);
} else {
$newPartNum = $key + 1;
}
$result = getAttachments($imap, $mailNum, $subpart, $newPartNum);
if (count($result) != 0) {
array_push($attachments, $result);
}
}
} else {
if (isset($part->disposition)) {
if ($part->disposition == "ATTACHMENT") {
$partStruct = imap_bodystruct($imap, $mailNum, $partNum);
$attachmentDetails = array("name" => $part->dparameters[0]->value, "partNum" => $partNum, "enc" => $partStruct->encoding);
return $attachmentDetails;
}
}
}
return $attachments;
}
示例2: getMessageBodyStruct
/**
* Get body structure
*
* @return mixed
*/
public function getMessageBodyStruct($pos, $no, $uid = 0)
{
return imap_bodystruct($this->_mailbox_link, $pos, $no, $uid);
}
示例3: getBodystruct
public function getBodystruct($uid, $part)
{
return $this->bodystruct = imap_bodystruct($this->mbox, $this->getMsgno($uid), $part);
}
示例4: setRawBody
/**
* This function returns an object containing the raw headers of the message.
*
* @param string $partIdentifier
* @return string
*/
protected function setRawBody($partIdentifier = null)
{
if (isset($partIdentifier)) {
$body = imap_fetchbody($this->imapStream, $this->uid, $partIdentifier, FT_UID | FT_PEEK);
$this->rawBody[$partIdentifier] = ['structure' => imap_bodystruct($this->imapStream, imap_msgno($this->imapStream, $this->uid), $partIdentifier), 'body' => $body];
} else {
$this->rawBody = $body = imap_body($this->imapStream, $this->uid, FT_UID | FT_PEEK);
}
return $body;
}
示例5: Exception
throw new Exception($err);
}
$emails = imap_search($inbox, 'ALL UNSEEN');
if (!$emails) {
return;
}
foreach ($emails as $msg_number) {
$header = imap_headerinfo($inbox, $msg_number);
$structure = imap_fetchstructure($inbox, $msg_number);
$text = "";
$attachments = array();
// Use text from non-multipart messages directly
if (empty($structure->parts)) {
// Get message body
$text = imap_fetchbody($inbox, $msg_number, 1);
$part = imap_bodystruct($inbox, $msg_number, 1);
// Decode body
if ($part->encoding == 4) {
$text = imap_qprint($text);
} elseif ($part->encoding == 3) {
$text = imap_base64($text);
}
}
// Load message parts for multipart messages
if (!empty($structure->parts)) {
foreach ($structure->parts as $part_number => $part) {
// Handle plaintext
if ($part->type === 0 && !trim($text)) {
$text = imap_fetchbody($inbox, $msg_number, $part_number + 1);
// Decode body
if ($part->encoding == 4) {
示例6: saveAttachment
function saveAttachment($uid, $partNum, $encoding)
{
$partStruct = imap_bodystruct($this->stream, imap_msgno($this->stream, $uid), $partNum);
$message = imap_fetchbody($this->stream, $uid, $partNum, FT_UID);
switch ($encoding) {
case 0:
case 1:
$message = imap_8bit($message);
break;
case 2:
$message = imap_binary($message);
break;
case 3:
$message = imap_base64($message);
break;
case 4:
$message = quoted_printable_decode($message);
break;
}
return $message;
}
示例7: imap_fetchstructure
} else {
if ($headrs->deleted) {
$delstyle = " text-decoration:line-through;opacity:.35; ";
} else {
$delstyle = "";
}
}
$mail_headerinfo = @imap_headerinfo($mbox, $headrs->msgno);
$mail_senddate = $mail_headerinfo->MailDate;
$mailstruct = imap_fetchstructure($mbox, $headrs->msgno);
$selectBoxDisplay = "";
$att = "";
$contentParts = count($mailstruct->parts);
if ($contentParts >= 2) {
for ($i = 2; $i <= $contentParts; $i++) {
$att[$i - 2] = imap_bodystruct($mbox, $headrs->msgno, $i);
}
for ($k = 0; $k < sizeof($att); $k++) {
$p = $att[$k];
if (count($p->dparameters) > 0) {
foreach ($p->dparameters as $dparam) {
if (strtoupper($dparam->attribute) == 'NAME' || strtoupper($dparam->attribute) == 'FILENAME') {
$selectBoxDisplay[$k] = $dparam->value;
}
}
}
//if no filename found
if ($filename == '') {
// if there are any parameters present in this part
if (count($p->parameters) > 0) {
foreach ($p->parameters as $param) {
示例8: str_replace
{$body}
</div></li>
END;
} else {
$body = str_replace('<a ', "<a target=\"_blank\" ", $body);
$body = str_replace('<A ', "<a target=\"_blank\" ", $body);
echo $body;
}
$struct = imap_fetchstructure($mbox, $msgno);
$contentParts = count($struct->parts);
if ($contentParts >= 2) {
for ($i = 2; $i <= $contentParts; $i++) {
$att[$i - 2] = imap_bodystruct($mbox, $msgno, $i);
}
for ($k = 0; $k < sizeof($att); $k++) {
/*if ($att[$k]->parameters[0]->value == "us-ascii" || $att[$k]->parameters[0]->value == "US-ASCII") {
if ($att[$k]->parameters[1]->value != "") {
$selectBoxDisplay[$k] = imap_utf8_workaround($att[$k]->parameters[1]->value);
}
} elseif ($att[$k]->parameters[0]->value != "iso-8859-1" && $att[$k]->parameters[0]->value != "ISO-8859-1") {
$selectBoxDisplay[$k] = imap_utf8_workaround($att[$k]->parameters[0]->value);
}*/
$p = $att[$k];
if (count($p->dparameters) > 0) {
foreach ($p->dparameters as $dparam) {
if (strtoupper($dparam->attribute) == 'NAME' || strtoupper($dparam->attribute) == 'FILENAME') {
$selectBoxDisplay[$k] = $dparam->value;
}
示例9: getBodyPart
/**
* Retrieve body part, and if it's file write it to filesystem
*
* @param integer $message_id
* @param string $body_part
* @param string $file_path
* @return mixed
*/
function getBodyPart($message_id, $body_part, $encoding, $file_path = false)
{
if ($file_path) {
if (!MM_CAN_DOWNLOAD_LARGE_ATTACHMENTS) {
$structure = imap_bodystruct($this->getConnection(), $message_id, $body_part);
if (!instance_of($structure, 'stdClass')) {
return false;
}
// if
// if attachment is larger than FAIL_SAFE_IMAP_ATTACHMENT_SIZE_MAX, don't download it
if ($structure->bytes > FAIL_SAFE_IMAP_ATTACHMENT_SIZE_MAX) {
return false;
}
// if
}
// if
$savebody_result = imap_savebody_alt($this->getConnection(), $file_path, $message_id, $body_part);
if (!$savebody_result) {
return false;
}
// if
$temporary_file = $file_path . '_temp';
switch ($encoding) {
case 'base64':
$decoding_result = base64_decode_file($file_path, $temporary_file);
if ($decoding_result) {
@unlink($file_path);
rename($temporary_file, $file_path);
return true;
} else {
@unlink($file_path);
@unlink($temporary_file);
return false;
}
break;
case 'quoted-printable':
$decoding_result = quoted_printable_decode_file($file_path, $temporary_file);
if ($decoding_result) {
@unlink($file_path);
rename($temporary_file, $file_path);
return true;
} else {
@unlink($file_path);
@unlink($temporary_file);
return false;
}
break;
}
// switch
return true;
} else {
$result = imap_fetchbody($this->getConnection(), $message_id, $body_part);
switch ($encoding) {
case 'base64':
return imap_base64($result);
break;
case 'quoted-printable':
return imap_qprint($result);
break;
default:
return $result;
break;
}
// switch
}
// if
}
示例10: getInlineAttach
function getInlineAttach($partNum, $encoding)
{
$this->structure = @imap_bodystruct($this->paloImap, @imap_msgno($this->paloImap, $this->uid), $partNum);
$filename = $this->structure->dparameters[0]->value;
$message = @imap_fetchbody($this->paloImap, $this->uid, $partNum, FT_UID);
$message = $this->decodeAttachData($encoding, $message);
header("Content-Type: application/octet-stream");
header("Content-Disposition: inline; filename=" . $filename);
echo $message;
}
示例11: processBounce
function processBounce($pos, $type, $header = null)
{
if (!empty($header)) {
$md5header = md5($header);
} else {
$md5header = null;
}
if ($type == 'DSN') {
// first part of DSN (Delivery Status Notification), human-readable explanation
$dsn_msg = imap_fetchbody($this->_mailbox_link, $pos, "1");
$dsn_msg_structure = imap_bodystruct($this->_mailbox_link, $pos, "1");
if ($dsn_msg_structure->encoding == 3) {
$dsn_msg = base64_decode($dsn_msg);
}
// second part of DSN (Delivery Status Notification), delivery-status
$dsn_report = imap_fetchbody($this->_mailbox_link, $pos, "2");
// process bounces by rules
$result = bmhDSNRules($dsn_msg, $dsn_report, $this->debug_dsn_rule);
} elseif ($type == 'BODY') {
$structure = imap_fetchstructure($this->_mailbox_link, $pos);
switch ($structure->type) {
case 0:
// Content-type = text
// Content-type = text
case 2:
// Content-type = message
$body = imap_body($this->_mailbox_link, $pos);
if ($structure->encoding == 3) {
$body = base64_decode($body);
}
$body = substr($body, 0, 1000);
$result = bmhBodyRules($body, $structure, $this->debug_body_rule);
break;
case 1:
// Content-type = multipart
$body = imap_fetchbody($this->_mailbox_link, $pos, "1");
// TRICKY : detect encoding and decode
// only handle base64 right now
if ($structure->parts[0]->encoding == 3) {
$body = base64_decode($body);
}
$body = substr($body, 0, 1000);
$result = bmhBodyRules($body, $structure, $this->debug_body_rule);
break;
default:
// unsupport Content-type
$this->output("The No. {$pos} is unsupport Content-Type:{$structure->type}", VERBOSE_REPORT);
return false;
}
} else {
// internal error
$this->error_msg = 'Internal Error: unknown type';
return false;
}
$result['rule_type'] = $type;
if (!empty($header)) {
if (preg_match("/Subject:((?:[^\n]|\n[\t ])+)(?:\n[^\t ]|\$)/is", $header, $match)) {
$result['subject'] = trim($match[1]);
}
if (preg_match("/Date:[\t ]*(.*)/i", $header, $match)) {
$result['date'] = trim($match[1]);
}
if (preg_match("/From:((?:[^\n]|\n[\t ])+)(?:\n[^\t ]|\$)/is", $header, $match)) {
$addresses = imap_rfc822_parse_adrlist($match[1], '???');
if (!empty($addresses) && is_array($addresses)) {
$result['from'] = $addresses[0]->mailbox . '@' . $addresses[0]->host;
}
}
}
// last chance for unmatched rules
if ($result['rule_no'] == '0000') {
$result = bmhOtherRules($result);
}
$result['md5header'] = $md5header;
// log the result if wanted
if (!empty($this->log_function) && function_exists($this->log_function)) {
call_user_func($this->log_function, $result);
$this->c_log++;
}
// call user function for unmatched rules
if ($result['rule_no'] == '0000') {
if (!empty($this->unmatched_function) && function_exists($this->unmatched_function)) {
return call_user_func($this->unmatched_function, $result);
}
return false;
}
if ($this->testmode) {
$this->output(print_r($result, true));
return false;
}
// match a rule, take bounce action
if (!empty($this->action_function) && function_exists($this->action_function)) {
return call_user_func($this->action_function, $result);
}
return true;
}
示例12: getMessagePart
public function getMessagePart($msgno, $partObj, $partno = 0)
{
echo "<br /><hr /><br />getMessagePart({$msgno},part,{$partno})<br />";
// If partno is 0 then fetch body as a single part message
//echo " imap_fetchbody($this->hconnection, $msgno, $partno, FT_PEEK); ";
// echo "<hr /> partno=";//.(int)$partno." ";
// var_dump($partno);
// echo "<br /> msgno=".(int)$msgno." ";
// var_dump($msgno);
if ($partno) {
$data = imap_fetchbody($this->hconnection, $msgno, $partno, FT_PEEK);
} else {
$data = imap_body($this->hconnection, $msgno, FT_PEEK);
}
// $data = ($partno) ? imap_fetchbody($conn, $messageId, $partno) : imap_body($conn, $messageId);
// Any part may be encoded, even plain text messages, so decoding it
echo " encoding " . $partObj->encoding . "\n";
if ($partObj->encoding == 4) {
$data = quoted_printable_decode($data);
} elseif ($partObj->encoding == 3) {
$data = base64_decode($data);
}
// Collection all parameters, like name, filenames of attachments, etc.
$params = array();
if ($partObj->parameters) {
foreach ((array) $partObj->parameters as $x) {
echo " attribute " . $x->attribute . "\n";
$params[strtolower($x->attribute)] = $x->value;
if ($x->attribute == 'charset' || $x->attribute == 'CHARSET') {
echo " charset " . $x->value . "\n";
if (in_array(strtolower($x->value), array('windows-1250', 'iso-8859-2'))) {
echo '[BODY : ENCODING] presented: ' . $x->value . ' => encoding to utf-8' . "\n";
$data = iconv($x->value, 'UTF-8', $data);
}
if (in_array(strtolower($x->value), array('us-ascii', 'default'))) {
require_once LIB_PATH . 'mail/Mail_Encoding.php';
$detected = Mail_Encoding::detect($data);
if ($detected != 'utf-8') {
echo '[BODY : ENCODING] presented: ' . $x->value . ' , detected: ' . $detected . ' => encoding to utf-8' . "\n";
$data = iconv($detected, 'UTF-8', $data);
}
}
}
}
}
if ($partObj->dparameters) {
foreach ((array) $partObj->dparameters as $x) {
$params[strtolower($x->attribute)] = $x->value;
}
}
if ($partObj->id) {
if ($partObj->type == 5) {
// IMAGE
$extension = strtolower($partObj->subtype);
$params['filename'] = md5($partObj->id) . '.' . $extension;
}
}
// Any part with a filename is an attachment,
if ($params['filename'] || $params['name']) {
// Filename may be given as 'Filename' or 'Name' or both
$filename = $params['filename'] ? $params['filename'] : $params['name'];
if (empty($this->attachments[$filename])) {
$this->attachments[$filename] = $data;
}
}
// Processing plain text message
if ($partObj->type == 0 && $data) {
// Messages may be split in different parts because of inline attachments,
// so append parts together with blank row.
if (strtolower($partObj->subtype) == 'plain' || strtolower($partObj->subtype) == 'text/plain') {
$this->plainBody = trim($data);
// echo "<br /><br /><br /><hr /><br />PLAINBODY<br />$data<br />ENDPLAINBODY<hr /><br />";
} else {
$this->htmlBody = $data;
// echo "<br /><br /><br /><hr /><br />HTMLBODY<br />$data<br />ENDHTMLBODY<hr /><br />";
}
} elseif ($partObj->type == 2 && $data) {
$this->plainBody .= $data;
}
// Here is recursive call for subpart of the message
if ($partObj->parts) {
foreach ((array) $partObj->parts as $partno2 => $part2) {
$this->getMessagePart($msgno, $part2, $partno . '.' . ($partno2 + 1));
}
if ($partObj->subtype == 'RFC822') {
echo '[RFC PART] detected: ' . $partno . "\n";
for ($i = sizeof($partObj->parts) + 1;; $i++) {
$partObj2 = imap_bodystruct($this->hconnection, $msgno, $partno . '.' . $i);
if (!empty($partObj2)) {
$this->getMessagePart($msgno, $partObj2, $partno . '.' . $i);
} else {
break;
}
}
}
}
}
示例13: returnBodyStructureObj
/**
* returnMessageBodyStructureObj
* @see http://www.php.net/manual/en/function.imap-bodystruct.php
* @param $messageNumber(int),part(int)
* @return object
*/
private function returnBodyStructureObj($messageNumber, $part)
{
return imap_bodystruct($this->stream, $messageNumber, $part);
}
示例14: exit
exit("TEST FAILED: Unable to create test mailbox\n");
}
echo "\nGet and validate structure of body part 1\n";
$m = imap_bodystruct($imap_stream, 1, "1");
$mandatoryFields = array('ifsubtype', 'ifdescription', 'ifid', 'ifdisposition', 'ifdparameters', 'ifparameters');
foreach ($mandatoryFields as $mf) {
if (isValid($m->{$mf})) {
echo "{$mf} is 0 or 1\n";
} else {
echo "{$mf} FAIL\n";
}
}
if (is_array($m->parameters)) {
echo "parameters is an array\n";
}
echo "\nTry to get part 4!\n";
var_dump(imap_bodystruct($imap_stream, 1, "4"));
imap_close($imap_stream);
function isValid($param)
{
if ($param == 0 || $param == 1) {
$result = true;
} else {
$result = false;
}
return $result;
}
?>
===Done===
<?php
require_once 'clean.inc';
示例15: GetAttachments
/**
* Returns an array containing all files attached to message
*
* @param int $msgno The index of the message to retrieve
* @param bool $include_raw_data The raw data is the actual contents of the attachment file. Setting this to FALSE will allow you to display the name, size, type, etc of all attachments without actually downloading the contents of the files. Use GetAttachmentRawData to retrieve the raw data for an individual attachment.
* @return array An array of attachments
*
*/
function GetAttachments($msgno, $include_raw_data = true)
{
$struct = imap_fetchstructure($this->mbox, $msgno);
$contentParts = count($struct->parts);
$attachments = array();
if ($contentParts >= 2) {
for ($i = 2; $i <= $contentParts; $i++) {
$att[$i - 2] = imap_bodystruct($this->mbox, $msgno, $i);
// these extra bits help us later...
$att[$i - 2]->x_msg_id = $msgno;
$att[$i - 2]->x_part_id = $i;
}
for ($k = 0; $k < sizeof($att); $k++) {
if (strtolower($att[$k]->parameters[0]->value) == "us-ascii" && $att[$k]->parameters[1]->value != "") {
$attachments[$k] = $this->_getPartFromStruct($att[$k], $include_raw_data);
} elseif (strtolower($att[$k]->parameters[0]->value) != "iso-8859-1") {
$attachments[$k] = $this->_getPartFromStruct($att[$k], $include_raw_data);
}
}
}
return $attachments;
}