本文整理汇总了PHP中imap_qprint函数的典型用法代码示例。如果您正苦于以下问题:PHP imap_qprint函数的具体用法?PHP imap_qprint怎么用?PHP imap_qprint使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imap_qprint函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_messages
/**
* Get messages according to a search criteria
*
* @param string search criteria (RFC2060, sec. 6.4.4). Set to "UNSEEN" by default
* NB: Search criteria only affects IMAP mailboxes.
* @param string date format. Set to "Y-m-d H:i:s" by default
* @return mixed array containing messages
*/
public function get_messages($search_criteria = "UNSEEN", $date_format = "Y-m-d H:i:s")
{
$msgs = imap_search($this->imap_stream, $search_criteria);
$no_of_msgs = $msgs ? count($msgs) : 0;
$messages = array();
for ($i = 0; $i < $no_of_msgs; $i++) {
// Get Message Unique ID in case mail box changes
// in the middle of this operation
$message_id = imap_uid($this->imap_stream, $msgs[$i]);
$header = imap_header($this->imap_stream, $message_id);
$date = date($date_format, $header->udate);
$from = $header->from;
$fromname = "";
$fromaddress = "";
$subject = "";
foreach ($from as $id => $object) {
if (isset($object->personal)) {
$fromname = $object->personal;
}
$fromaddress = $object->mailbox . "@" . $object->host;
if ($fromname == "") {
// In case from object doesn't have Name
$fromname = $fromaddress;
}
}
if (isset($header->subject)) {
$subject = $this->_mime_decode($header->subject);
}
$structure = imap_fetchstructure($this->imap_stream, $message_id);
$body = '';
if (!empty($structure->parts)) {
for ($j = 0, $k = count($structure->parts); $j < $k; $j++) {
$part = $structure->parts[$j];
if ($part->subtype == 'PLAIN') {
$body = imap_fetchbody($this->imap_stream, $message_id, $j + 1);
}
}
} else {
$body = imap_body($this->imap_stream, $message_id);
}
// Convert quoted-printable strings (RFC2045)
$body = imap_qprint($body);
array_push($messages, array('msg_no' => $message_id, 'date' => $date, 'from' => $fromname, 'email' => $fromaddress, 'subject' => $subject, 'body' => $body));
// Mark Message As Read
imap_setflag_full($this->imap_stream, $message_id, "\\Seen");
}
return $messages;
}
示例2: get_messages
/**
* Get messages according to a search criteria
*
* @param string search criteria (RFC2060, sec. 6.4.4). Set to "UNSEEN" by default
NB: Search criteria only affects IMAP mailboxes.
* @param string date format. Set to "Y-m-d H:i:s" by default
* @return mixed array containing messages
*/
public function get_messages($search_criteria = "UNSEEN", $date_format = "Y-m-d H:i:s")
{
$msgs = imap_search($this->imap_stream, $search_criteria);
$no_of_msgs = $msgs ? count($msgs) : 0;
$messages = array();
for ($i = 0; $i < $no_of_msgs; $i++) {
$header = imap_header($this->imap_stream, $msgs[$i]);
$date = date($date_format, $header->udate);
$from = $this->_mime_decode($header->fromaddress);
$subject = $this->_mime_decode($header->subject);
$structure = imap_fetchstructure($this->imap_stream, $msgs[$i]);
if (!empty($structure->parts)) {
for ($j = 0, $k = count($structure->parts); $j < $k; $j++) {
$part = $structure->parts[$j];
if ($part->subtype == 'PLAIN') {
$body = imap_fetchbody($this->imap_stream, $msgs[$i], $j + 1);
}
}
} else {
$body = imap_body($this->imap_stream, $msgs[$i]);
}
// Convert quoted-printable strings (RFC2045)
$body = imap_qprint($body);
array_push($messages, array('msg_no' => $msgs[$i], 'date' => $date, 'from' => $from, 'subject' => $subject, 'body' => $body));
}
return $messages;
}
示例3: get_part
function get_part($stream, $msg_number, $mime_type, $structure = false, $part_number = false)
{
if (!$structure) {
$structure = imap_fetchstructure($stream, $msg_number);
}
if ($structure) {
if ($mime_type == $this->get_mime_type($structure)) {
if (!$part_number) {
$part_number = "1";
}
$text = imap_fetchbody($stream, $msg_number, $part_number);
if ($structure->encoding == 3) {
return imap_base64($text);
} else {
if ($structure->encoding == 4) {
return imap_qprint($text);
} else {
return $text;
}
}
}
if ($structure->type == 1) {
while (list($index, $sub_structure) = each($structure->parts)) {
if ($part_number) {
$prefix = $part_number . '.';
}
$data = $this->get_part($stream, $msg_number, $mime_type, $sub_structure, $prefix . ($index + 1));
if ($data) {
return $data;
}
}
}
}
return false;
}
示例4: download
function download($VAR)
{
if (empty($VAR['id'])) {
return false;
}
$id = $VAR['id'];
// get ticket id
$db =& DB();
$rs = $db->Execute(sqlSelect($db, array("ticket_attachment", "ticket"), "A.ticket_id,B.department_id,B.account_id", "A.id=::{$id}:: AND A.ticket_id=B.id"));
if (!$rs || $rs->RecordCount() == 0) {
return false;
}
// is this an admin?
global $C_auth;
if ($C_auth->auth_method_by_name("ticket", "view")) {
// get the data & type
$rs = $db->Execute(sqlSelect($db, "ticket_attachment", "*", "id=::{$id}::"));
// set the header
require_once PATH_CORE . 'file_extensions.inc.php';
$ft = new file_extensions();
$type = $ft->set_headers_ext($rs->fields['type'], $rs->fields['name']);
if (empty($type)) {
echo imap_qprint($rs->fields['content']);
} elseif (preg_match("/^text/i", $type)) {
echo imap_base64($rs->fields['content']);
} else {
echo imap_base64($rs->fields['content']);
}
exit;
}
}
示例5: _decodeMail
private function _decodeMail($encoding, $body)
{
switch ($encoding) {
case ENC7BIT:
return $body;
case ENC8BIT:
return $body;
case ENCBINARY:
return $body;
case ENCBASE64:
return imap_base64($body);
case ENCQUOTEDPRINTABLE:
return imap_qprint($body);
case ENCOTHER:
return $body;
default:
return $body;
}
}
示例6: getdecodevalue
function getdecodevalue($message,$coding) {
switch($coding) {
case 0:
case 1:
$message = imap_8bit($message);
break;
case 2:
$message = imap_binary($message);
break;
case 3:
case 5:
$message=imap_base64($message);
break;
case 4:
$message = imap_qprint($message);
break;
}
return $message;
}
示例7: get_msg
function get_msg($imap_box, $email_number, $mime_type, $structure = false, $part_number = false)
{
if (!$structure) {
// ПЕРВЫЙ запуск, получение корня структуры
$structure = imap_fetchstructure($imap_box, $email_number);
}
$message = "";
if ($structure->subtype == $mime_type) {
//"CHARSET")
if (!$part_number) {
$part_number = "1";
}
$data = imap_fetchbody($imap_box, $email_number, $part_number);
//получить конкретную часть письма
if ($structure->encoding == 3) {
$data = base64_decode($data);
}
if ($structure->encoding == 4) {
$data = imap_qprint($data);
}
if ($structure->parameters[0]->value == "windows-1251") {
$data = mb_convert_encoding($data, 'utf-8', 'windows-1251');
}
if ($structure->parameters[0]->value == "koi8-r") {
$data = mb_convert_encoding($data, 'utf-8', 'koi8-r');
}
//echo "<br> Вложенная часть: " . $part_number . "<br>";
$message .= $data;
}
// Если письмо состоит из многа частей - разбираем каждую отдельно
if ($structure->parts) {
while (list($index, $sub_structure) = each($structure->parts)) {
if ($part_number) {
$prefix = $part_number . '.';
}
$message .= get_msg($imap_box, $email_number, $mime_type, $sub_structure, $prefix . ($index + 1));
}
// end while
}
// end if
return $message;
}
示例8: decodeBody
/**
* Attempts to Decode the message body. If a valid encoding is not passed then it will attempt to detect the encoding itself.
* @param $body
* @param int|null $encoding
* @return string
*/
public function decodeBody($body, $encoding = null)
{
switch ($encoding) {
case ENCBASE64:
return imap_base64($body);
case ENCQUOTEDPRINTABLE:
return imap_qprint($body);
case ENCBINARY:
return $body;
default:
// Let's check if the message is base64
if ($decoded = base64_decode($body, true)) {
return $decoded;
}
if ($this->isQuotedPrintable($body)) {
return imap_qprint($body);
}
return $body;
}
}
示例9: get_one_mail
function get_one_mail($number)
{
$mail = imap_headerinfo($this->connection, $number);
//echo "<hr/>";
//echo "mail nummer: ".$number."<br/>";
//echo "date: ".$mail->date."<br/>";
//echo "subject: ".$mail->subject."<br/>";
//echo "from-mailbox: ".$mail->from[0]->mailbox."<br/>";
//echo "from-host: ".$mail->from[0]->host."<br/>";
$this->mails[$number]["date"]["raw"] = $mail->date;
$this->mails[$number]["date"]["timestamp"] = strtotime($mail->date);
$last_char_1 = substr($mail->subject, -1, 1);
$cleansubject = $mail->subject;
$cleansubject = utf8_encode(imap_qprint($cleansubject));
$cleansubject = ereg_replace("=\\?ISO-8859-1\\?Q\\?", "", $cleansubject);
$cleansubject = ereg_replace("\\?=", "", $cleansubject);
$cleansubject = ereg_replace("_", " ", $cleansubject);
$last_char_2 = substr($cleansubject, -1, 1);
if ($last_char_1 != $last_char_2) {
$cleansubject = substr($cleansubject, 0, strlen($cleansubject) - 1);
}
//$cleansubject = ereg_replace("?", "", $cleansubject);
$this->mails[$number]["subject"] = $cleansubject;
$this->mails[$number]["mailbox"] = $mail->from[0]->mailbox;
$this->mails[$number]["host"] = $mail->from[0]->host;
$body = utf8_encode(imap_qprint(imap_fetchbody($this->connection, $number, "1")));
if ($body != "") {
$this->mails[$number]["text"] = $body;
}
$struct = imap_fetchstructure($this->connection, $number);
//print_r($struct);
$counter = 2;
while (imap_fetchbody($this->connection, $number, $counter) != "") {
$image = imap_fetchbody($this->connection, $number, $counter);
$this->mails[$number]["image"][$counter]["data"] = $image;
$parts = $counter - 1;
$this->mails[$number]["image"][$counter]["name"] = $struct->parts[$parts]->dparameters[0]->value;
$this->email_base64_to_file($number, $counter);
$counter++;
}
}
示例10: get_part
public static function get_part($stream, $msg_number, $mime_type, $structure = false, $part_number = false)
{
if (!$structure) {
$structure = imap_fetchstructure($stream, $msg_number);
}
if ($structure) {
if ($mime_type == self::get_mime_type($structure)) {
if (!$part_number) {
$part_number = "1";
}
$text = imap_fetchbody($stream, $msg_number, $part_number);
if ($structure->encoding == 3) {
return imap_base64($text);
} else {
if ($structure->encoding == 4) {
return imap_qprint($text);
} else {
return $text;
}
}
}
if ($structure->type == 1) {
while (list($index, $sub_structure) = each($structure->parts)) {
if ($part_number) {
$prefix = $part_number . '.';
} else {
$prefix = "";
}
$data = self::get_part($stream, $msg_number, $mime_type, $sub_structure, $prefix . ($index + 1));
if ($data) {
return $data;
}
}
// END OF WHILE
}
// END OF MULTIPART
}
// END OF STRUTURE
return false;
}
示例11: get_plain_text_body
function get_plain_text_body($mbox, $msgNum, &$attachments = array())
{
$structure = imap_fetchstructure($mbox, $msgNum);
// only plain text
if ('PLAIN' == $structure->subtype) {
return trim(imap_qprint(imap_body($mbox, $msgNum)));
}
if (isset($structure->parts)) {
// get attachments
foreach ($structure->parts as $partNum => $part) {
if (in_array($part->subtype, array('JPEG', 'PNG', 'GIF'))) {
// oeh an image
$name = 'image-from-email-' . $msgNum . '.' . strtolower($part->subtype);
foreach ($part->parameters as $param) {
if ('NAME' == $param->attribute) {
$name = $param->value;
}
}
$data = imap_fetchbody($mbox, $msgNum, (string) ($partNum + 1));
file_put_contents($attachments[] = 'attachments/' . time() . '--' . $name, base64_decode($data));
}
}
// multipart (probably) -- look for plain text part
foreach ($structure->parts as $partNum => $part) {
if ('PLAIN' == $part->subtype) {
$body = imap_fetchbody($mbox, $msgNum, (string) ($partNum + 1));
return trim($body);
} else {
if ('ALTERNATIVE' == $part->subtype && isset($part->parts)) {
foreach ($part->parts as $subPartNum => $subPart) {
if ('PLAIN' == $subPart->subtype) {
$body = imap_fetchbody($mbox, $msgNum, $partNum + 1 . '.' . ($subPartNum + 1));
return trim($body);
}
}
}
}
}
}
}
示例12: fetchBody
/**
* Fetches email body
*
* @param int $msgno Message number
* @return string
*/
protected function fetchBody($msgno)
{
$body = imap_fetchbody($this->connection, $msgno, '1', FT_PEEK);
$structure = imap_fetchstructure($this->connection, $msgno);
$encoding = $structure->parts[0]->encoding;
$charset = null;
foreach ($structure->parts[0]->parameters as $param) {
if ($param->attribute == 'CHARSET') {
$charset = $param->value;
break;
}
}
if ($encoding == ENCBASE64) {
$body = imap_base64($body);
} elseif ($encoding == ENCQUOTEDPRINTABLE) {
$body = imap_qprint($body);
}
if ($charset) {
$body = iconv($charset, "UTF-8", $body);
}
return $body;
}
示例13: get_part
function get_part($imap, $uid, $mimetype, $structure = false, $partNumber = false)
{
if (!$structure) {
//$imap_uid = imap_uid ($imap, $uid);
//echo "$uid->".$uid;
$structure = imap_fetchstructure($imap, $uid, FT_UID);
}
//echo "<br/>structure-><pre>".print_r($structure)."</pre>";
if ($structure) {
if ($mimetype == get_mime_type($structure)) {
if (!$partNumber) {
$partNumber = 1;
}
$text = imap_fetchbody($imap, $uid, $partNumber, FT_UID);
switch ($structure->encoding) {
case 3:
return imap_base64($text);
case 4:
return imap_qprint($text);
default:
return $text;
}
}
// multipart
if ($structure->type == 1) {
foreach ($structure->parts as $index => $subStruct) {
$prefix = "";
if ($partNumber) {
$prefix = $partNumber . ".";
}
$data = get_part($imap, $uid, $mimetype, $subStruct, $prefix . ($index + 1));
if ($data) {
return $data;
}
}
}
}
return false;
}
示例14: __toString
public function __toString()
{
$encoding = $this->attachment->encoding;
switch ($encoding) {
case 0:
// 7BIT
// 7BIT
case 1:
// 8BIT
// 8BIT
case 2:
// BINARY
return $this->getBody();
case 3:
// BASE-64
return base64_decode($this->getBody());
case 4:
// QUOTED-PRINTABLE
return imap_qprint($this->getBody());
}
throw new Exception(sprintf('Encoding failed: Unknown encoding %s (5: OTHER).', $encoding));
}
示例15: read
private function read()
{
$allMails = imap_search($this->conn, 'ALL');
if ($allMails) {
rsort($allMails);
foreach ($allMails as $email_number) {
$overview = imap_fetch_overview($this->conn, $email_number, 0);
$structure = imap_fetchstructure($this->conn, $email_number);
$body = '';
if (isset($structure->parts) && is_array($structure->parts) && isset($structure->parts[1])) {
$part = $structure->parts[1];
$body = imap_fetchbody($this->conn, $email_number, 2);
if ($part->encoding == 3) {
$body = imap_base64($body);
} else {
if ($part->encoding == 1) {
$body = imap_8bit($body);
} else {
$body = imap_qprint($body);
}
}
}
$body = utf8_decode($body);
$fromaddress = utf8_decode(imap_utf7_encode($overview[0]->from));
$subject = mb_decode_mimeheader($overview[0]->subject);
$date = utf8_decode(imap_utf8($overview[0]->date));
$date = date('Y-m-d H:i:s', strtotime($date));
$key = md5($fromaddress . $subject . $body);
//save to MySQL
$sql = "SELECT count(*) FROM EMAIL_INFORMATION WHERE IDMAIL = " . $this->id . " AND CHECKVERS = \"" . $key . "\"";
$resul = $this->pdo->query($sql)->fetch();
if ($resul[0] == 0) {
$this->pdo->prepare("INSERT INTO EMAIL_INFORMATION (IDMAIL,FROMADDRESS,SUBJECT,DATE,BODY,CHECKVERS) VALUES (?,?,?,?,?,?)");
$this->pdo->execute(array($this->id, $fromaddress, $subject, $date, $body, $key));
}
}
}
}