本文整理汇总了PHP中imap_uid函数的典型用法代码示例。如果您正苦于以下问题:PHP imap_uid函数的具体用法?PHP imap_uid怎么用?PHP imap_uid使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imap_uid函数的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: __construct
/**
* Constructor which gets the Mail details from the server
* @param String $mBox - Mail Box Connection string
* @param Integer $msgno - Mail Message Number
* @param Boolean $fetchbody - Used to save the mail information to DB
*/
function __construct($mBox = false, $msgno = false, $fetchbody = false)
{
if ($mBox && $msgno) {
$this->mBox = $mBox;
$this->mMsgNo = $msgno;
$loaded = false;
// Unique ID based on sequence number
$this->mUid = imap_uid($mBox, $msgno);
if ($fetchbody) {
// Lookup if there was previous cached message
$loaded = $this->readFromDB($this->mUid);
}
if (!$loaded) {
parent::__construct($mBox, $msgno, $fetchbody);
if ($fetchbody) {
// Save for further use
$loaded = $this->saveToDB($this->mUid);
}
}
if ($loaded) {
$this->setRead(true);
$this->setMsgNo(intval($msgno));
}
}
}
示例3: get_part
public function get_part($imap, $uid, $mimetype, $structure = false, $partNumber = false)
{
if (!$structure) {
$uid = imap_uid($imap, $uid);
//echo "uid->".$uid."<br>";
//echo "ft_uid=>".FT_UID;
// die;
//error_reporting(0);
$structure = imap_fetchstructure($imap, $uid, FT_UID);
}
//echo "<br/>structure-><pre>".print_r($structure)."</pre>";
if ($structure) {
if ($mimetype == $this->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 = $this->get_part($imap, $uid, $mimetype, $subStruct, $prefix . ($index + 1));
if ($data) {
return $data;
}
}
}
}
return false;
}
示例4: getHeaders
function getHeaders($mid)
{
if (!$this->marubox) {
return false;
}
$mail_header = @imap_fetchheader($this->marubox, $mid);
if ($mail_header == false) {
return false;
}
$mail_header = imap_rfc822_parse_headers($mail_header);
$sender = isset($mail_header->from[0]) ? $mail_header->from[0] : '';
$sender_replyto = isset($mail_header->reply_to[0]) ? $mail_header->reply_to[0] : '';
if (strtolower($sender->mailbox) != 'mailer-daemon' && strtolower($sender->mailbox) != 'postmaster') {
$newvalue['personal'] = $this->email_Decode($sender->personal);
$newvalue['sender_personal'] = $this->email_Decode($sender_replyto->personal);
$newvalue['subject'] = $this->email_Decode($mail_header->subject);
$newvalue['toaddress'] = isset($mail_header->toaddress) ? $this->email_Decode($mail_header->toaddress) : '';
$mail_header = (array) $mail_header;
$sender = (array) $sender;
$mail_details = array('feid' => imap_uid($this->marubox, $mid), 'from' => strtolower($sender['mailbox']) . '@' . $sender['host'], 'from_name' => $newvalue['personal'], 'to_other' => strtolower($sender_replyto->mailbox) . '@' . $sender_replyto->host, 'toname_other' => $newvalue['sender_personal'], 'subjects' => $newvalue['subject'], 'to' => $newvalue['toaddress'], 'time' => strtotime($mail_header['Date']));
}
return $mail_details;
}
示例5: temp
public function temp()
{
set_time_limit(4000);
// Connect to gmail
$imapPath = '{imap.gmail.com:993/imap/ssl}INBOX';
$username = 'prageethkalhara17@gmail.com';
$password = 'prageethkalhara33';
$imap = imap_open($imapPath, $username, $password) or die('Cannot connect to Gmail: ' . imap_last_error());
$numMessages = imap_num_msg($imap);
for ($i = $numMessages; $i > $numMessages - 1; $i--) {
$header = imap_header($imap, $i);
$fromInfo = $header->from[0];
$replyInfo = $header->reply_to[0];
$details = array("fromAddr" => isset($fromInfo->mailbox) && isset($fromInfo->host) ? $fromInfo->mailbox . "@" . $fromInfo->host : "", "fromName" => isset($fromInfo->personal) ? $fromInfo->personal : "", "replyAddr" => isset($replyInfo->mailbox) && isset($replyInfo->host) ? $replyInfo->mailbox . "@" . $replyInfo->host : "", "subject" => isset($header->subject) ? $header->subject : "", "udate" => isset($header->udate) ? $header->udate : "");
$uid = imap_uid($imap, $i);
}
$body = get_part($imap, $uid, "TEXT/HTML");
// if HTML body is empty, try getting text body
/* if ($body == "") {
$body = get_part($imap, $uid, "TEXT/PLAIN");
}
return $body;*/
// return view('messages.che')->with('body',$body);
}
示例6: get_mail_detail
public static function get_mail_detail($mbox, $id, $msgno = false)
{
$return = array();
if (!$msgno) {
$msgno = imap_msgno($mbox, $id);
}
if (!$id) {
$id = imap_uid($mbox, $msgno);
}
if (!$msgno) {
return false;
}
$header = imap_header($mbox, $msgno);
$structure = self::_get_body_attach($mbox, $id, $msgno);
$return['id'] = $id;
$return['Msgno'] = $header->Msgno;
$return['message_id'] = $header->message_id;
$return['toaddress'] = self::get_only_email($header->to);
$return['fromaddress'] = self::get_only_email($header->from);
$return['reply_toaddress'] = self::get_only_email($header->reply_to);
$return['ccaddress'] = self::get_only_email($header->cc);
$return['bccaddress'] = self::get_only_email($header->bcc);
$return['senderaddress'] = self::get_only_email($header->sender);
$return['subject'] = self::_decode_text($header->subject);
$return['MailDate'] = $header->MailDate;
$return['date'] = $header->date;
$return['udate'] = $header->udate;
$return['udate_formated'] = date("Y-m-d H:i:s", $header->udate);
$return['Recent'] = $header->Recent;
$return['Unseen'] = $header->Unseen;
$return['Flagged'] = $header->Flagged;
$return['Answered'] = $header->Answered;
$return['Deleted'] = $header->Deleted;
$return['Draft'] = $header->Draft;
$return['Size'] = $header->Size;
$return['body'] = $structure['body'];
$return['attachments'] = $structure['attachment'];
$return['clean'] = '';
$msgs = imap_fetch_overview($mbox, $msgno);
foreach ($msgs as $msg) {
$return['clean'] .= imap_fetchheader($mbox, $msg->msgno);
}
return $return;
}
示例7: _getFormattedMail
/**
* get the basic details like sender and reciver with flags like attatchments etc
*
* @param int $uid the number of the message
* @return array empty on error/nothing or array of formatted details
*/
protected function _getFormattedMail($Model, $uid, $fetchAttachments = false)
{
// Translate uid to msg_no. Has no decent fail
$msg_number = imap_msgno($this->Stream, $uid);
// A hack to detect if imap_msgno failed, and we're in fact looking at the wrong mail
if ($uid != ($mailuid = imap_uid($this->Stream, $msg_number))) {
pr(compact('Mail'));
return $this->err($Model, 'Mail id mismatch. parameter id: %s vs mail id: %s', $uid, $mailuid);
}
// Get Mail with a property: 'date' or fail
if (!($Mail = imap_headerinfo($this->Stream, $msg_number)) || !property_exists($Mail, 'date')) {
pr(compact('Mail'));
return $this->err($Model, 'Unable to find mail date property in Mail corresponding with uid: %s. Something must be wrong', $uid);
}
// Get Mail with a property: 'type' or fail
if (!($flatStructure = $this->_flatStructure($Model, $uid))) {
return $this->err($Model, 'Unable to find structure type property in Mail corresponding with uid: %s. Something must be wrong', $uid);
}
$plain = $this->_fetchFirstByMime($flatStructure, 'text/plain');
$html = $this->_fetchFirstByMime($flatStructure, 'text/html');
$return[$Model->alias] = array('id' => $this->_toId($uid), 'message_id' => $Mail->message_id, 'email_number' => $Mail->Msgno, 'to' => $this->_personId($Mail, 'to', 'address'), 'to_name' => $this->_personId($Mail, 'to', 'name'), 'from' => $this->_personId($Mail, 'from', 'address'), 'from_name' => $this->_personId($Mail, 'from', 'name'), 'reply_to' => $this->_personId($Mail, 'reply_to', 'address'), 'reply_to_name' => $this->_personId($Mail, 'reply_to', 'name'), 'sender' => $this->_personId($Mail, 'sender', 'address'), 'sender_name' => $this->_personId($Mail, 'sender', 'name'), 'subject' => htmlspecialchars(@$Mail->subject), 'slug' => Inflector::slug(@$Mail->subject, '-'), 'header' => @imap_fetchheader($this->Stream, $uid, FT_UID), 'body' => $html, 'plainmsg' => $plain ? $plain : $html, 'size' => @$Mail->Size, 'recent' => @$Mail->Recent === 'R' ? 1 : 0, 'seen' => @$Mail->Unseen === 'U' ? 0 : 1, 'flagged' => @$Mail->Flagged === 'F' ? 1 : 0, 'answered' => @$Mail->Answered === 'A' ? 1 : 0, 'draft' => @$Mail->Draft === 'X' ? 1 : 0, 'deleted' => @$Mail->Deleted === 'D' ? 1 : 0, 'thread_count' => $this->_getThreadCount($Mail), 'in_reply_to' => @$Mail->in_reply_to, 'reference' => @$Mail->references, 'new' => (int) @$Mail->in_reply_to, 'created' => date('Y-m-d H:i:s', strtotime($Mail->date)));
if ($fetchAttachments) {
$return['Attachment'] = $this->_fetchAttachments($flatStructure, $Model);
}
// Auto mark after read
if (!empty($this->config['auto_mark_as'])) {
$marks = '\\' . join(' \\', $this->config['auto_mark_as']);
if (!imap_setflag_full($this->Stream, $uid, $marks, ST_UID)) {
$this->err($Model, 'Unable to mark email %s as %s', $uid, $marks);
}
}
return $return;
}
示例8: pollMonitoredInboxes
/**
* Job 1
*/
function pollMonitoredInboxes()
{
$_bck_up = array('team_id' => $GLOBALS['current_user']->team_id, 'team_set_id' => $GLOBALS['current_user']->team_set_id);
Log::info('----->Scheduler fired job of type pollMonitoredInboxes()');
global $dictionary;
global $app_strings;
require_once 'modules/Emails/EmailUI.php';
$ie = new InboundEmail();
$emailUI = new EmailUI();
$r = $ie->db->query('SELECT id, name FROM inbound_email WHERE is_personal = 0 AND deleted=0 AND status=\'Active\' AND mailbox_type != \'bounce\'');
Log::debug('Just got Result from get all Inbounds of Inbound Emails');
while ($a = $ie->db->fetchByAssoc($r)) {
Log::debug('In while loop of Inbound Emails');
$ieX = new InboundEmail();
$ieX->retrieve($a['id']);
$GLOBALS['current_user']->team_id = $ieX->team_id;
$GLOBALS['current_user']->team_set_id = $ieX->team_set_id;
$mailboxes = $ieX->mailboxarray;
foreach ($mailboxes as $mbox) {
$ieX->mailbox = $mbox;
$newMsgs = array();
$msgNoToUIDL = array();
$connectToMailServer = false;
if ($ieX->isPop3Protocol()) {
$msgNoToUIDL = $ieX->getPop3NewMessagesToDownloadForCron();
// get all the keys which are msgnos;
$newMsgs = array_keys($msgNoToUIDL);
}
if ($ieX->connectMailserver() == 'true') {
$connectToMailServer = true;
}
// if
Log::debug('Trying to connect to mailserver for [ ' . $a['name'] . ' ]');
if ($connectToMailServer) {
Log::debug('Connected to mailserver');
if (!$ieX->isPop3Protocol()) {
$newMsgs = $ieX->getNewMessageIds();
}
if (is_array($newMsgs)) {
$current = 1;
$total = count($newMsgs);
require_once "include/SugarFolders/SugarFolders.php";
$sugarFolder = new SugarFolder();
$groupFolderId = $ieX->groupfolder_id;
$isGroupFolderExists = false;
$users = array();
if ($groupFolderId != null && $groupFolderId != "") {
$sugarFolder->retrieve($groupFolderId);
$isGroupFolderExists = true;
}
// if
$messagesToDelete = array();
if ($ieX->isMailBoxTypeCreateCase()) {
$users[] = $sugarFolder->assign_to_id;
$distributionMethod = $ieX->get_stored_options("distrib_method", "");
if ($distributionMethod != 'roundRobin') {
$counts = $emailUI->getAssignedEmailsCountForUsers($users);
} else {
$lastRobin = $emailUI->getLastRobin($ieX);
}
Log::debug('distribution method id [ ' . $distributionMethod . ' ]');
}
foreach ($newMsgs as $k => $msgNo) {
$uid = $msgNo;
if ($ieX->isPop3Protocol()) {
$uid = $msgNoToUIDL[$msgNo];
} else {
$uid = imap_uid($ieX->conn, $msgNo);
}
// else
if ($isGroupFolderExists) {
if ($ieX->importOneEmail($msgNo, $uid)) {
// add to folder
$sugarFolder->addBean($ieX->email);
if ($ieX->isPop3Protocol()) {
$messagesToDelete[] = $msgNo;
} else {
$messagesToDelete[] = $uid;
}
if ($ieX->isMailBoxTypeCreateCase()) {
$userId = "";
if ($distributionMethod == 'roundRobin') {
if (sizeof($users) == 1) {
$userId = $users[0];
$lastRobin = $users[0];
} else {
$userIdsKeys = array_flip($users);
// now keys are values
$thisRobinKey = $userIdsKeys[$lastRobin] + 1;
if (!empty($users[$thisRobinKey])) {
$userId = $users[$thisRobinKey];
$lastRobin = $users[$thisRobinKey];
} else {
$userId = $users[0];
$lastRobin = $users[0];
}
}
//.........这里部分代码省略.........
示例9: KLogger
<?php
// read mails from internal bounce mailbox and set invalidEmail=1 for these email addresses
require '/var/www/yoursite/http/variables.php';
require '/var/www/yoursite/http/variablesdb.php';
require_once '/var/www/yoursite/http/functions.php';
require '/var/www/yoursite/http/log/KLogger.php';
$log = new KLogger('/var/www/yoursite/http/log/bounces/', KLogger::INFO);
$mailbox = imap_open('{localhost:993/ssl/novalidate-cert}', 'bounce', 'bounce01$');
$mailbox_info = imap_check($mailbox);
for ($i = 1; $i <= $mailbox_info->Nmsgs; $i++) {
$msg = imap_fetch_overview($mailbox, $i);
$rcpt = $msg[0]->to;
if (substr($rcpt, 0, 6) == 'bounce') {
$target = substr($rcpt, 7);
// exclude 'bounce='
$target = substr($target, 0, -9);
// exclude '@yoursite'
$target = str_replace('=', '@', $target);
// revert '=' to '@'
if ($msg[0]->answered == 0) {
$sql = "UPDATE {$playerstable} SET invalidEmail=1 WHERE invalidEmail=0 AND mail='" . $target . "'";
mysql_query($sql);
$affected = mysql_affected_rows();
$uid = imap_uid($mailbox, $i);
$status = imap_setflag_full($mailbox, $uid, '\\Answered \\Seen', ST_UID);
$log->logInfo('sql=[' . $sql . '] affected=[' . $affected . '] status=[' . $status . ']');
}
}
}
imap_close($mailbox);
// close the mailbox
示例10: pollMonitoredInboxesForBouncedCampaignEmails
function pollMonitoredInboxesForBouncedCampaignEmails()
{
$GLOBALS['log']->info('----->Scheduler job of type pollMonitoredInboxesForBouncedCampaignEmails()');
global $dictionary;
$ie = new InboundEmail();
$r = $ie->db->query('SELECT id FROM inbound_email WHERE deleted=0 AND status=\'Active\' AND mailbox_type=\'bounce\'');
while ($a = $ie->db->fetchByAssoc($r)) {
$ieX = new InboundEmail();
$ieX->retrieve($a['id']);
$ieX->connectMailserver();
$GLOBALS['log']->info("Bounced campaign scheduler connected to mail server id: {$a['id']} ");
$newMsgs = array();
if ($ieX->isPop3Protocol()) {
$newMsgs = $ieX->getPop3NewMessagesToDownload();
} else {
$newMsgs = $ieX->getNewMessageIds();
}
//$newMsgs = $ieX->getNewMessageIds();
if (is_array($newMsgs)) {
foreach ($newMsgs as $k => $msgNo) {
$uid = $msgNo;
if ($ieX->isPop3Protocol()) {
$uid = $ieX->getUIDLForMessage($msgNo);
} else {
$uid = imap_uid($ieX->conn, $msgNo);
}
// else
$GLOBALS['log']->info("Bounced campaign scheduler will import message no: {$msgNo}");
$ieX->importOneEmail($msgNo, $uid, false, false);
}
}
imap_expunge($ieX->conn);
imap_close($ieX->conn);
}
return true;
}
示例11: mail_Scan
public static function mail_Scan($mbox, $account, $folder, $scan_id)
{
$return = [];
$last_user_uid = self::getUidFolder($account['user_id'], $folder);
$msgno = imap_msgno($mbox, $last_user_uid);
$num_msg = imap_num_msg($mbox);
$get_emails = false;
if ($msgno == 0 && $num_msg != 0) {
$last_email_uid = imap_uid($mbox, $num_msg);
if ($last_user_uid == 1) {
$get_emails = true;
$msgno = 1;
} elseif ($last_email_uid > $last_user_uid) {
$exit = true;
while ($exit) {
$last_user_uid++;
$last_scaned_num = imap_msgno($mbox, $last_user_uid);
if ($last_scaned_num != 0) {
$exit = false;
$msgno = $last_scaned_num;
} elseif ($last_user_uid == $last_email_uid) {
$exit = false;
$msgno = $num_msg;
}
}
$get_emails = true;
}
} else {
if ($msgno < $num_msg) {
$get_emails = true;
}
}
if ($get_emails) {
$return['count'] = 0;
for ($i = $msgno; $i <= $num_msg; $i++) {
$OSSMailModel = Vtiger_Record_Model::getCleanInstance('OSSMail');
self::checkFolderUid($account['user_id'], $folder);
$uid = imap_uid($mbox, $i);
$mail_detail = $OSSMailModel->get_mail_detail($mbox, $uid, $i);
$mail_detail['Account_username'] = $account['username'];
$mail_detail['Account_user_id'] = $account['user_id'];
self::executeActions($account, $mail_detail, $folder);
$adb = PearDatabase::getInstance();
$adb->pquery("update vtiger_ossmailscanner_folders_uid set uid=? where user_id=? AND folder = ?", array($uid, $account['user_id'], $folder));
self::update_scan_history($scan_id, array('status' => '1', 'count' => $return['count'], 'action' => 'Action_CronMailScanner'));
$return['count']++;
}
}
return $return;
}
示例12: appendMessage
public function appendMessage($message, $box = 'IMAP.Sent', $flags = null, $messageId = null)
{
$mailbox = $this->imap->reopen($box);
$date = null;
if ($messageId) {
//var_dump($messageId);
$messageId = imap_uid($this->connection, $messageId);
//var_dump($messageId);
$headerinfo = imap_headerinfo($this->connection, $messageId);
$date = date('d-M-Y H:i:s O', $headerinfo->udate);
}
$result = imap_append($this->connection, $mailbox, $message, $flags);
$this->fullName = $this->imap->reopen($this->name);
return $result;
}
示例13: getMessageUId
/**
* Get a sequenced message id
*
* @param string $msgNo in the format <.*@.*> from the email
*
* @return mixed on imap its the unique id (int) and for others its a base64_encoded string
*/
protected function getMessageUId($msgNo)
{
if ($this->imapStream == null) {
return false;
}
return imap_uid($this->imapStream, $msgNo);
}
示例14: getHeader
/**
* Read the header of the message
*
* @param string $msgCount//(邮件ID)
* @return array
*/
public function getHeader($msgCount)
{
$mailHeader = array();
$header = imap_headerinfo($this->_connect, $msgCount);
$sender = $header->from[0];
$replyTo = $header->reply_to[0];
$reciever = $header->to[0];
if (strtolower($sender->mailbox) != 'mailer-daemon' && strtolower($sender->mailbox) != 'postmaster') {
$subject = $this->subjectDecode($header->subject);
$mailHeader = array('from' => strtolower($sender->mailbox) . '@' . $sender->host, 'fromName' => $this->subjectDecode($sender->personal), 'toOther' => strtolower($replyTo->mailbox) . '@' . $replyTo->host, 'toOtherName' => $replyTo->personal, 'subject' => $subject, 'to' => strtolower($reciever->mailbox) . '@' . $reciever->host, 'toName' => $this->subjectDecode($reciever->personal), 'date' => $header->date, 'id' => $header->Msgno, 'seen' => $header->Unseen, 'msg_id' => imap_uid($this->_connect, $header->Msgno), 'answered' => $header->Answered, 'flagged' => $header->Flagged);
}
return $mailHeader;
}
示例15: getMessageHeader
/**
* fetch message by id
*
* @return header
* @param $id of the message
*/
private function getMessageHeader($id)
{
$count = $this->countMessages();
for ($i = 1; $i <= $count; $i++) {
$uid = imap_uid($this->imap, $i);
if ($uid == $id) {
$header = imap_headerinfo($this->imap, $i);
return $header;
}
}
return false;
}