本文整理汇总了PHP中imap_utf8函数的典型用法代码示例。如果您正苦于以下问题:PHP imap_utf8函数的具体用法?PHP imap_utf8怎么用?PHP imap_utf8使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imap_utf8函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: decode
protected function decode($value)
{
$decoded = '';
$parts = imap_mime_header_decode($value);
try {
foreach ($parts as $part) {
$charset = 'default' == $part->charset ? 'auto' : $part->charset;
//Ajout COGIVEA fix encoding :
$charset = $this->charset != '' && $charset == 'auto' ? $this->charset : $charset;
//print $part->text."#".$this->charset."/".$charset."#"."\n";
// imap_utf8 doesn't seem to work properly, so use Transcoder instead
// Got from: https://github.com/Sawered/imap/commit/e739b7221c6e57521b38f7b56f78ba399acda888 and changed to UndetectableEncodingException
try {
$decoded .= Transcoder::create()->transcode($part->text, $charset);
} catch (IllegalCharacterException $e) {
//no warn, itis reality
//FIX COGIVEA
} catch (UndetectableEncodingException $e) {
//no warn, it is reality, handle it somehow
$decoded = imap_utf8($part->text);
}
}
} catch (Exception $e) {
}
return $decoded;
}
示例2: fetchOverview
/**
* @return stdClass
* @throws Exception
*/
public function fetchOverview()
{
$result = imap_fetch_overview($this->stream, $this->number);
if (FALSE === $result) {
throw new Exception('FetchOverview failed: ' . imap_last_error());
}
list($result) = $result;
foreach ($result as &$prop) {
$prop = imap_utf8($prop);
}
return $result;
}
示例3: mimedecode
function mimedecode($text, $encoding = 'UTF-8')
{
if (function_exists('imap_mime_header_decode') && ($parts = imap_mime_header_decode($text))) {
$str = '';
foreach ($parts as $part) {
$str .= Charset::transcode($part->text, $part->charset, $encoding);
}
$text = $str;
} elseif ($text[0] == '=' && function_exists('iconv_mime_decode')) {
$text = iconv_mime_decode($text, 0, $encoding);
} elseif (!strcasecmp($encoding, 'utf-8') && function_exists('imap_utf8')) {
$text = imap_utf8($text);
}
return $text;
}
示例4: getNewMessages
/**
* @return bool
*/
public function getNewMessages()
{
$query = imap_search(self::__connect(), 'UNSEEN');
$data = false;
$messages = [];
if (is_array($query)) {
foreach ($query as $number) {
$messages[] = imap_fetch_overview(self::__connect(), $number)[0];
}
for ($i = 0; $i < count($messages); $i++) {
$data[$i]['msgno'] = $messages[$i]->msgno;
$data[$i]['subject'] = imap_mime_header_decode(imap_utf8(mb_convert_encoding($messages[$i]->subject, 'UTF8', 'KOI8-R')))[0]->text;
}
}
return $data;
}
示例5: decode
function decode($what, $errors = false)
{
if (function_exists('imap_mime_header_decode') && ($parts = imap_mime_header_decode($text))) {
$str = '';
foreach ($parts as $part) {
$str .= Format::encode($part->text, $part->charset, $encoding);
}
return $str;
} elseif ($text[0] == '=' && function_exists('iconv_mime_decode')) {
return iconv_mime_decode($text, 0, $encoding);
// TODO: Use a pure-PHP version to perform the decoding
} elseif (!strcasecmp($encoding, 'utf-8') && function_exists('imap_utf8')) {
return imap_utf8($text);
}
return $text;
}
示例6: __construct
public function __construct(stdClass $headers)
{
// Store all headers as lowercase
$this->array = array_change_key_case((array) $headers);
// Decode subject, as it may be UTF-8 encoded
if (isset($headers->subject)) {
$subject = '';
foreach (imap_mime_header_decode($headers->subject) as $part) {
// $part->charset can also be 'default', i.e. plain US-ASCII
if (function_exists('iconv')) {
$charset = $part->charset == 'default' ? 'UTF-8' : $part->charset;
$subject .= iconv($charset, 'UTF-8', $part->text);
} else {
$charset = $part->charset == 'default' ? 'auto' : $part->charset;
$subject .= mb_convert_encoding($part->text, 'UTF-8', $charset);
}
}
$this->array['subject'] = $subject;
}
$this->array['msgno'] = (int) $this->array['msgno'];
foreach (array('answered', 'deleted', 'draft') as $flag) {
$this->array[$flag] = (bool) trim($this->array[$flag]);
}
if (isset($this->array['date'])) {
$this->array['date'] = preg_replace('/(.*)\\(.*\\)/', '$1', $this->array['date']);
// $this->array['date'] = new DateTime($this->array['date']);
}
if (isset($this->array['from'])) {
$from = current($this->array['from']);
$this->array['from'] = new Mirasvit_Ddeboer_Imap_Message_EmailAddress($from->mailbox, $from->host, isset($from->personal) ? imap_utf8($from->personal) : null);
}
if (isset($this->array['to'])) {
$recipients = array();
foreach ($this->array['to'] as $to) {
$recipients[] = new Mirasvit_Ddeboer_Imap_Message_EmailAddress(str_replace('\'', '', $to->mailbox), str_replace('\'', '', $to->host), isset($to->personal) ? imap_utf8($to->personal) : null);
}
$this->array['to'] = $recipients;
} else {
$this->array['to'] = array();
}
if (isset($this->array['reply_to'])) {
$from = current($this->array['reply_to']);
$this->array['reply_to'] = new Mirasvit_Ddeboer_Imap_Message_EmailAddress($from->mailbox, $from->host, isset($from->personal) ? imap_utf8($from->personal) : null);
}
}
示例7: showEmails
public function showEmails()
{
$connect_to = '{imap.gmail.com:993/imap/ssl/novalidate-cert}INBOX';
$user = 'a.majik7@gmail.com';
$password = '77andy77';
$inbox = imap_open($connect_to, $user, $password) or die("Can't connect to '{$connect_to}': " . imap_last_error());
$folders = imap_list($inbox, "{imap.gmail.com:993/imap/ssl}", "*");
//return dd($folders);
//return $message_count = imap_num_msg($inbox);
$emails = imap_search($inbox, 'SINCE ' . date('d-M-Y', strtotime("-2 week")));
$output = [];
$emailCount = imap_num_msg($inbox);
rsort($emails);
$i = 0;
foreach ($emails as $mail) {
$headerInfo = imap_headerinfo($inbox, $mail);
//return var_dump(dd($headerInfo));
$message = "";
$output[$i]['subject'] = isset($headerInfo->Subject) ? imap_utf8($headerInfo->Subject) : "0";
$output[$i]['from'] = imap_utf8($headerInfo->from[0]->personal);
$output[$i]['toaddress'] = $headerInfo->toaddress;
$output[$i]['to'] = array_shift($headerInfo->to);
$output[$i]['date'] = $headerInfo->date[0];
$output[$i]['fromaddress'] = $headerInfo->fromaddress[0];
$output[$i]['reply_toaddress'] = $headerInfo->reply_toaddress[0];
$output[$i]['date'] = date('d-m-Y ' . '[' . 'H:i' . ']', strtotime($headerInfo->date) + 3600);
$output[$i]['unseen'] = $headerInfo->Unseen;
$output[$i]['flagged'] = $headerInfo->Flagged;
$message = imap_fetchbody($inbox, $mail, 2);
if (base64_decode($message, true)) {
//message body if base64 encoded
$message = base64_decode($message);
} else {
//message body is not base64 encoded
$message = imap_fetchbody($inbox, $mail, 1);
}
$output[$i]['body'] = $message;
$i++;
}
return dd($output);
//return view('aßdministration.email.showEmails')->with('output', $output);
}
示例8: getMessages
public function getMessages($email)
{
$messages = [];
foreach ($this->query(['to' => $email, 'on' => date('d F Y'), 'unseen' => false]) as $messageId) {
$structure = imap_fetchstructure($this->connections[$email], $messageId);
$encoding = isset($structure->parts) ? reset($structure->parts) : $structure;
$message = imap_fetch_overview($this->connections[$email], $messageId);
$message = reset($message);
$processFunction = $this->detectProcessFunction($encoding->encoding);
$message->subject = $processFunction($message->subject);
$message->body = $this->getMessageBody($email, $messageId, $processFunction, reset($structure->parameters));
foreach (['from', 'to'] as $direction) {
$address = imap_rfc822_parse_adrlist(imap_utf8($message->{$direction}), '');
$address = reset($address);
$message->{$direction} = "{$address->mailbox}@{$address->host}";
}
$messages[] = (array) $message;
imap_delete($this->connections[$email], $messageId);
}
return $messages;
}
示例9: 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));
}
}
}
}
示例10: mime_decode
/**
* Mime header value decoder. Usually unicode characters are encoded
* according to RFC-2047. This function will decode RFC-2047 encoded
* header values as well as detect headers which are not encoded.
*
* Caveats:
* If headers contain non-ascii characters the result of this function
* is completely undefined. If osTicket is corrupting your email
* headers, your mail software is not encoding the header text
* correctly.
*
* Returns:
* Header value, transocded to UTF-8
*/
function mime_decode($text, $encoding = 'utf-8')
{
// Handle poorly or completely un-encoded header values (
if (function_exists('mb_detect_encoding')) {
if (($src_enc = mb_detect_encoding($text)) && strcasecmp($src_enc, 'ASCII') !== 0) {
return Charset::transcode($text, $src_enc, $encoding);
}
}
// Handle ASCII text and RFC-2047 encoding
$str = '';
$parts = imap_mime_header_decode($text);
foreach ($parts as $part) {
$str .= $this->mime_encode($part->text, $part->charset, $encoding);
}
return $str ? $str : imap_utf8($text);
}
示例11: initMailPart
protected function initMailPart(IncomingMail $mail, $partStructure, $partNum, $markAsSeen = true)
{
$options = FT_UID;
if (!$markAsSeen) {
$options |= FT_PEEK;
}
$data = $partNum ? imap_fetchbody($this->getImapStream(), $mail->id, $partNum, $options) : imap_body($this->getImapStream(), $mail->id, $options);
if ($partStructure->encoding == 1) {
$data = imap_utf8($data);
} elseif ($partStructure->encoding == 2) {
$data = imap_binary($data);
} elseif ($partStructure->encoding == 3) {
$data = preg_replace('~[^a-zA-Z0-9+=/]+~s', '', $data);
// https://github.com/barbushin/php-imap/issues/88
$data = imap_base64($data);
} elseif ($partStructure->encoding == 4) {
$data = quoted_printable_decode($data);
}
$params = array();
if (!empty($partStructure->parameters)) {
foreach ($partStructure->parameters as $param) {
$params[strtolower($param->attribute)] = $param->value;
}
}
if (!empty($partStructure->dparameters)) {
foreach ($partStructure->dparameters as $param) {
$paramName = strtolower(preg_match('~^(.*?)\\*~', $param->attribute, $matches) ? $matches[1] : $param->attribute);
if (isset($params[$paramName])) {
$params[$paramName] .= $param->value;
} else {
$params[$paramName] = $param->value;
}
}
}
// attachments
$attachmentId = $partStructure->ifid ? trim($partStructure->id, " <>") : (isset($params['filename']) || isset($params['name']) ? mt_rand() . mt_rand() : null);
if ($attachmentId) {
if (empty($params['filename']) && empty($params['name'])) {
$fileName = $attachmentId . '.' . strtolower($partStructure->subtype);
} else {
$fileName = !empty($params['filename']) ? $params['filename'] : $params['name'];
$fileName = $this->decodeMimeStr($fileName, $this->serverEncoding);
$fileName = $this->decodeRFC2231($fileName, $this->serverEncoding);
}
$attachment = new IncomingMailAttachment();
$attachment->id = $attachmentId;
$attachment->name = $fileName;
$attachment->disposition = isset($partStructure->disposition) ? $partStructure->disposition : null;
if ($this->attachmentsDir) {
$replace = array('/\\s/' => '_', '/[^0-9a-zа-яіїє_\\.]/iu' => '', '/_+/' => '_', '/(^_)|(_$)/' => '');
$fileSysName = preg_replace('~[\\\\/]~', '', $mail->id . '_' . $attachmentId . '_' . preg_replace(array_keys($replace), $replace, $fileName));
$attachment->filePath = $this->attachmentsDir . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'public' . DIRECTORY_SEPARATOR . $fileSysName;
file_put_contents($attachment->filePath, $data);
}
$mail->addAttachment($attachment);
} else {
if (!empty($params['charset'])) {
$data = $this->convertStringEncoding($data, $params['charset'], $this->serverEncoding);
}
if ($partStructure->type == 0 && $data) {
if (strtolower($partStructure->subtype) == 'plain') {
$mail->textPlain .= $data;
} else {
$mail->textHtml .= $data;
}
} elseif ($partStructure->type == 2 && $data) {
$mail->textPlain .= trim($data);
}
}
if (!empty($partStructure->parts)) {
foreach ($partStructure->parts as $subPartNum => $subPartStructure) {
if ($partStructure->type == 2 && $partStructure->subtype == 'RFC822') {
$this->initMailPart($mail, $subPartStructure, $partNum, $markAsSeen);
} else {
$this->initMailPart($mail, $subPartStructure, $partNum . '.' . ($subPartNum + 1), $markAsSeen);
}
}
}
}
示例12: imap_num_msg
// reads messages number
$totalMessages = imap_num_msg($inbox);
echo "<b>Total messages:</b> {$totalMessages}<br/><br/>";
if ($totalMessages > 0) {
// browses all messages
for ($m = $totalMessages; $m > 0; $m--) {
print "Processing message " . $m . " ----------------------------------<br>";
$headers = imap_headerinfo($inbox, $m);
$sender = $headers->from[0]->mailbox . "@" . $headers->from[0]->host;
// checks if sender is allowed to forward messages
if (checkAllowedSender($sender)) {
//printf("mittente: %s<br><br>", $mittente);
/*foreach($headers as $key) {
printf("key: %s<br>", $key);
}*/
$subject = utf8_decode(imap_utf8($headers->subject));
// extracts recipients rule from subject
$ruleEndPos = strpos($subject, "]");
$rule = "";
if ($ruleEndPos !== false && $ruleEndPos > 1) {
$rule = substr($subject, 0, $ruleEndPos + 1);
// trims white spaces
$rule = trim($rule);
// trims white spaces
$rule = trim($rule, "[]");
//
// trims rule prefix
$subject = substr($subject, $ruleEndPos + 1);
// trims white spaces
$subject = trim($subject);
}
示例13: parseAddresses
private function parseAddresses($list)
{
$addresses = [];
foreach ($list as $item) {
$address = (object) $item;
if (!property_exists($address, 'mailbox')) {
$address->mailbox = false;
}
if (!property_exists($address, 'host')) {
$address->host = false;
}
if (!property_exists($address, 'personal')) {
$address->personal = false;
}
$address->personal = imap_utf8($address->personal);
$address->mail = $address->mailbox && $address->host ? $address->mailbox . '@' . $address->host : false;
$address->full = $address->personal ? $address->personal . ' <' . $address->mail . '>' : $address->mail;
$addresses[] = $address;
}
return $addresses;
}
示例14: getMessageHeaders
/**
* get message headers
*
* @param string|Expressomail_Model_Message $_messageId
* @param boolean $_readOnly
* @return array
* @throws Expressomail_Exception_IMAPMessageNotFound
*/
public function getMessageHeaders($_messageId, $_partId = null, $_readOnly = false)
{
if (!$_messageId instanceof Expressomail_Model_Message) {
$message = $this->_backend->get($_messageId);
} else {
$message = $_messageId;
}
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Fetching headers for message uid ' . $message->messageuid . ' (part:' . $_partId . ')');
}
try {
$imapBackend = $this->_getBackendAndSelectFolder($message->folder_id);
} catch (Zend_Mail_Storage_Exception $zmse) {
if (Tinebase_Core::isLogLevel(Zend_Log::WARN)) {
Tinebase_Core::getLogger()->warn(__METHOD__ . '::' . __LINE__ . ' ' . $zmse->getMessage());
}
if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $zmse->getTraceAsString());
}
throw new Expressomail_Exception_IMAPMessageNotFound('Folder not found');
}
if ($imapBackend === null) {
throw new Expressomail_Exception('Failed to get imap backend');
}
$section = $_partId === null ? 'HEADER' : $_partId . '.HEADER';
try {
$rawHeaders = $imapBackend->getRawContent($message->messageuid, $section, $_readOnly);
if (strtolower(mb_detect_encoding($rawHeaders)) == 'utf-8') {
$rawHeaders = utf8_decode(imap_utf8($rawHeaders));
}
} catch (Expressomail_Exception_IMAPMessageNotFound $feimnf) {
$this->_backend->delete($message->getId());
throw $feimnf;
}
if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' Fetched Headers: ' . $rawHeaders);
}
Zend_Mime_Decode::splitMessage($rawHeaders, $headers, $null);
return $headers;
}
示例15: initMailPart
protected function initMailPart(IncomingMail $mail, $partStructure, $partNum)
{
$data = $partNum ? imap_fetchbody($this->getImapStream(), $mail->id, $partNum, FT_UID) : imap_body($this->getImapStream(), $mail->id, FT_UID);
if ($partStructure->encoding == 1) {
$data = imap_utf8($data);
} elseif ($partStructure->encoding == 2) {
$data = imap_binary($data);
} elseif ($partStructure->encoding == 3) {
$data = imap_base64($data);
} elseif ($partStructure->encoding == 4) {
$data = imap_qprint($data);
}
$params = array();
if (!empty($partStructure->parameters)) {
foreach ($partStructure->parameters as $param) {
$params[strtolower($param->attribute)] = $param->value;
}
}
if (!empty($partStructure->dparameters)) {
foreach ($partStructure->dparameters as $param) {
$paramName = strtolower(preg_match('~^(.*?)\\*~', $param->attribute, $matches) ? $matches[1] : $param->attribute);
if (isset($params[$paramName])) {
$params[$paramName] .= $param->value;
} else {
$params[$paramName] = $param->value;
}
}
}
if (!empty($params['charset'])) {
$data = iconv(strtoupper($params['charset']), $this->serverEncoding . '//IGNORE', $data);
}
// attachments
$attachmentId = $partStructure->ifid ? trim($partStructure->id, " <>") : (isset($params['filename']) || isset($params['name']) ? mt_rand() . mt_rand() : null);
if ($attachmentId) {
if (empty($params['filename']) && empty($params['name'])) {
$fileName = $attachmentId . '.' . strtolower($partStructure->subtype);
} else {
$fileName = !empty($params['filename']) ? $params['filename'] : $params['name'];
$fileName = $this->decodeMimeStr($fileName, $this->serverEncoding);
$fileName = $this->decodeRFC2231($fileName, $this->serverEncoding);
}
$attachment = new IncomingMailAttachment();
$attachment->id = $attachmentId;
$attachment->name = $fileName;
if ($this->attachmentsDir) {
$replace = array('/\\s/' => '_', '/[^0-9a-zA-Z_\\.]/' => '', '/_+/' => '_', '/(^_)|(_$)/' => '');
$fileSysName = preg_replace('~[\\\\/]~', '', $mail->id . '_' . $attachmentId . '_' . preg_replace(array_keys($replace), $replace, $fileName));
$attachment->filePath = $this->attachmentsDir . DIRECTORY_SEPARATOR . $fileSysName;
file_put_contents($attachment->filePath, $data);
}
$mail->addAttachment($attachment);
} elseif ($partStructure->type == 0 && $data) {
if (strtolower($partStructure->subtype) == 'plain') {
$mail->textPlain .= $data;
} else {
$mail->textHtml .= $data;
}
} elseif ($partStructure->type == 2 && $data) {
$mail->textPlain .= trim($data);
}
if (!empty($partStructure->parts)) {
foreach ($partStructure->parts as $subPartNum => $subPartStructure) {
if ($partStructure->type == 2 && $partStructure->subtype == 'RFC822') {
$this->initMailPart($mail, $subPartStructure, $partNum);
} else {
$this->initMailPart($mail, $subPartStructure, $partNum . '.' . ($subPartNum + 1));
}
}
}
}