本文整理汇总了PHP中imap_fetchstructure函数的典型用法代码示例。如果您正苦于以下问题:PHP imap_fetchstructure函数的具体用法?PHP imap_fetchstructure怎么用?PHP imap_fetchstructure使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了imap_fetchstructure函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: readEmails
public function readEmails($sentTo = null, $bodyPart = null)
{
$host = '{imap.gmail.com:993/imap/ssl}INBOX';
$spinner = new Spinner('Could not connect to Imap server.', 60, 10000);
$inbox = $spinner->assertBecomesTrue(function () use($host) {
return @imap_open($host, $this->email, $this->password);
});
$emails = imap_search($inbox, 'TO ' . ($sentTo ? $sentTo : $this->email));
if ($emails) {
$messages = [];
foreach ($emails as $n) {
$structure = imap_fetchstructure($inbox, $n);
if (!$bodyPart) {
$part = $this->findPart($structure, function ($part) {
return $part->subtype === 'HTML';
});
} elseif (is_callable($bodyPart)) {
$part = $this->findPart($structure, $bodyPart);
} else {
$part = $bodyPart;
}
$hinfo = imap_headerinfo($inbox, $n);
$subject = $hinfo->subject;
$message = ['subject' => $subject, 'body' => imap_fetchbody($inbox, $n, $part)];
$messages[] = $message;
}
return $messages;
} else {
return [];
}
}
示例2: getAttachments
function getAttachments($id, $path)
{
$parts = imap_fetchstructure($this->mailbox, $id);
$attachments = array();
//FIXME if we do an is_array() here it breaks howver if we don't
//we get foreach errors
foreach ($parts->parts as $key => $value) {
$encoding = $parts->parts[$key]->encoding;
if ($parts->parts[$key]->ifdparameters) {
$filename = $parts->parts[$key]->dparameters[0]->value;
$message = imap_fetchbody($this->mailbox, $id, $key + 1);
switch ($encoding) {
case 0:
$message = imap_8bit($message);
case 1:
$message = imap_8bit($message);
case 2:
$message = imap_binary($message);
case 3:
$message = imap_base64($message);
case 4:
$message = quoted_printable_decode($message);
case 5:
default:
$message = $message;
}
$fp = fopen($path . $filename, "w");
fwrite($fp, $message);
fclose($fp);
$attachments[] = $filename;
}
}
return $attachments;
}
示例3: 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;
}
示例4: parse_message
function parse_message($connection, $message_number, $option = null, $to_charset = 'UTF-8')
{
$result = array('messages' => array(), 'attachments' => array());
$structure = imap_fetchstructure($connection, $message_number, $option);
if (isset($structure->parts)) {
$flatten = parse_message_flatten($structure->parts);
} else {
$flatten = array(1 => $structure);
}
foreach ($flatten as $id => &$part) {
switch ($part->type) {
case TYPETEXT:
$message = parse_message_decode_text($connection, $part, $message_number, $id, $option, $to_charset);
$result['messages'][] = $message;
break;
case TYPEAPPLICATION:
case TYPEAUDIO:
case TYPEIMAGE:
case TYPEVIDEO:
case TYPEOTHER:
$attachment = parse_message_decode_attach($connection, $part, $message_number, $id, $option);
if ($attachment) {
$result['attachments'][] = $attachment;
}
break;
case TYPEMULTIPART:
case TYPEMESSAGE:
break;
}
}
return $result;
}
示例5: fetch
public function fetch($delete = false)
{
$oImap = imap_open('{' . $this->mail_server . ':993/imap/ssl/notls/novalidate-cert}', $this->username, $this->password);
$oMailboxStatus = imap_check($oImap);
$aMessages = imap_fetch_overview($oImap, "1:{$oMailboxStatus->Nmsgs}");
$validMessages = array();
foreach ($aMessages as $oMessage) {
print "Trying message '" . $oMessage->subject . "'";
$fileContent = $fileType = '';
$geocoder = factory::create('geocoder');
$postCode = $geocoder->extract_postcode($oMessage->subject);
$fromName = null;
$fromEmail = null;
if (strpos($oMessage->from, '<')) {
$split = split('<', $oMessage->from);
//name - make sure name not an email address
$fromName = trim($split[0]);
if (valid_email($fromName)) {
$fromName = null;
}
//email
$fromEmail = trim(str_replace('>', '', $split[1]));
} else {
$fromEmail = $oMessage->from;
}
$images = array();
$messageStructure = imap_fetchstructure($oImap, $oMessage->msgno);
if (isset($messageStructure->parts)) {
$partNumber = 0;
foreach ($messageStructure->parts as $oPart) {
$partNumber++;
if ($oPart->subtype == 'PLAIN' && !$postCode) {
$messageContent = imap_fetchbody($oImap, $oMessage->msgno, $partNumber);
if ($oPart->encoding == 4) {
$messageContent = quoted_printable_decode($messageContent);
}
$postCode = geocoder::extract_postcode($messageContent);
} elseif ($oPart->encoding == 3 && in_array($oPart->subtype, array('JPEG', 'PNG'))) {
$oImage = null;
$encodedBody = imap_fetchbody($oImap, $oMessage->msgno, $partNumber);
$fileContent = base64_decode($encodedBody);
$oImage = imagecreatefromstring($fileContent);
if (imagesx($oImage) > $this->min_import_size && imagesy($oImage) > $this->min_import_size) {
array_push($images, $oImage);
}
$fileType = strtolower($oPart->subtype);
}
}
}
//add to the messages array
array_push($validMessages, array('postcode' => $postCode, 'images' => $images, 'file_type' => $fileType, 'from_address' => $fromAddress, 'from_email' => $fromEmail, 'from_name' => $fromName));
if ($delete) {
imap_delete($oImap, $oMessage->msgno);
}
}
imap_close($oImap, CL_EXPUNGE);
$this->messages = $validMessages;
}
示例6: getdata
function getdata($host, $login, $password, $savedirpath)
{
$mbox = imap_open($host, $login, $password) or die("can't connect: " . imap_last_error());
$message = array();
$message["attachment"]["type"][0] = "text";
$message["attachment"]["type"][1] = "multipart";
$message["attachment"]["type"][2] = "message";
$message["attachment"]["type"][3] = "application";
$message["attachment"]["type"][4] = "audio";
$message["attachment"]["type"][5] = "image";
$message["attachment"]["type"][6] = "video";
$message["attachment"]["type"][7] = "other";
$buzon_destino = "cfdi";
echo imap_createmailbox($mbox, imap_utf7_encode("{$buzon_destino}"));
echo imap_num_msg($mbox);
for ($jk = 1; $jk <= imap_num_msg($mbox); $jk++) {
$structure = imap_fetchstructure($mbox, $jk);
$parts = $structure->parts;
$fpos = 2;
for ($i = 1; $i < count($parts); $i++) {
$message["pid"][$i] = $i;
$part = $parts[$i];
if (strtolower($part->disposition) == "attachment") {
$message["type"][$i] = $message["attachment"]["type"][$part->type] . "/" . strtolower($part->subtype);
$message["subtype"][$i] = strtolower($part->subtype);
$ext = $part->subtype;
$params = $part->dparameters;
$filename = $part->dparameters[0]->value;
if (!($ext == 'xml' or $ext == 'XML' or $ext == 'PDF' or $ext == 'pdf')) {
continue;
}
$mege = "";
$data = "";
$mege = imap_fetchbody($mbox, $jk, $fpos);
$data = $this->getdecodevalue($mege, $part->type);
$fp = fopen($filename, 'w');
fputs($fp, $data);
fclose($fp);
$fpos += 1;
/* Se mueve el archiv descargado al directorio de recibidos */
// rename($filename, $savedirpath.$filename);
// printf("\nSe movio el archivo $filename");
}
}
$result = imap_fetch_overview($mbox, $jk);
echo $result[0]->from;
// imap_mail_move($mbox, $jk, $buzon_destino);
//imap_delete tags a message for deletion
// imap_delete($mbox,$jk);
}
// imap_expunge deletes all tagged messages
// imap_expunge($mbox);
imap_close($mbox);
}
示例7: readMessage
public function readMessage($messageid)
{
$message = array();
$header = imap_header($this->mailbox, $messageid);
$structure = imap_fetchstructure($this->mailbox, $messageid);
$message['subject'] = $header->subject;
$message['fromaddress'] = $header->fromaddress;
$message['toaddress'] = $header->toaddress;
//$message['ccaddress'] = $header->ccaddress;
$message['date'] = $header->date;
$message['id'] = $messageid;
if ($this->check_type($structure)) {
$message['body'] = imap_fetchbody($this->mailbox, $messageid, "2");
## GET THE BODY OF MULTI-PART MESSAGE
if (!$message['body']) {
$message['body'] = '[NO TEXT ENTERED INTO THE MESSAGE]\\n\\n';
}
} else {
$message['body'] = imap_body($this->mailbox, $messageid);
if (!$message['body']) {
$message['body'] = '[NO TEXT ENTERED INTO THE MESSAGE]\\n\\n';
}
}
return $message;
}
示例8: 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;
}
示例9: inbox
function inbox()
{
$this->msg_cnt = imap_num_msg($this->conn);
echo "Number of emails read = " . $this->msg_cnt . "\n";
/*$in = array();
for($i = 1; $i <= $this->msg_cnt; $i++) {
$in[] = array(
'index' => $i,
'header' => imap_headerinfo($this->conn, $i),
'body' => imap_body($this->conn, $i),
'structure' => imap_fetchstructure($this->conn, $i)
); */
$output = '<table>';
$output .= '<tr><th>Subject</th><th>voucher</th><th>From</th><th>seen</th><th>type</th></tr>';
$mails = imap_search($this->conn, 'FROM "hotelpartners@goibibo.com" SUBJECT "Confirm Hotel Booking"');
//print_r($mails);
for ($i = 0; $i <= sizeof($mails); $i++) {
$header = imap_fetch_overview($this->conn, $mails[$i], 0);
$body = imap_fetchbody($this->conn, $mails[$i], 1.1);
$output .= '<tr>';
$output .= '<td><span class="subject">' . $header[0]->subject . '</span> </td>';
$output .= '<td><span class="from">' . $header[0]->from . '</span></td>';
$output .= '<td><span class="voucher">' . $mails[0]->voucher . '</span></td>';
$output .= '<td><span class="date">' . $header[0]->date . '</span></td>>';
$output .= '<td><span class="toggler">' . ($header[0]->seen ? 'read' : 'unread') . '"></span></td>';
$structure = imap_fetchstructure($this->conn, $mails[$i]);
$output .= '<td><span class="type">' . $structure->type . '</span> </td>';
$output .= '</tr>';
}
$output .= '</table>';
echo $output . "\n";
}
示例10: messages
/**
* @param string $criteria
* @return $this
*/
public function messages($criteria)
{
$this->messages = array_map(function ($messageNumber) {
return array('id' => $messageNumber, 'header' => imap_header($this->mailbox, $messageNumber), 'struct' => imap_fetchstructure($this->mailbox, $messageNumber));
}, imap_search($this->mailbox, $criteria));
return $this;
}
示例11: getBody
/**
*
* @return ImapMessagePart
*/
public function getBody() {
if ($this->body === null) {
$partsStructure = \imap_fetchstructure($this->imapResource, $this->uid, \FT_UID);
$this->body = new ImapMessagePart($this->imapResource, $this->uid, $partsStructure);
}
return $this->body;
}
示例12: fetchStructure
public function fetchStructure()
{
$structure = imap_fetchstructure($this->stream, $this->number);
if (FALSE === $structure) {
throw new Exception('FetchStructure failed: ' . imap_last_error());
}
return $structure;
}
示例13: __construct
public function __construct(IMAP $imap, $mail, $attachmentsDirectory = null)
{
$this->imap = $imap;
$this->connection = $imap->getConnection();
$this->mail = $mail;
$this->attachmentsDirectory = $attachmentsDirectory;
$this->structure = imap_fetchstructure($this->connection, $this->mail->id, FT_UID);
}
示例14: getStructure
public function getStructure()
{
$structure = @imap_fetchstructure($this->_connection->getConnection(), $this->_messageNumber);
if (!$structure) {
throw new Exception('Failed to fetch message structure.');
}
return $structure;
}
示例15: inbox
function inbox()
{
$this->msg_cnt = imap_num_msg($this->conn);
$in = array();
for ($i = 1; $i <= 20; $i++) {
$in[] = array('index' => $i, 'header' => imap_headerinfo($this->conn, $i), 'body' => imap_body($this->conn, $i), 'structure' => imap_fetchstructure($this->conn, $i));
}
$this->inbox = $in;
}