<?php

// include Imap_parser class
include_once('lib/Imap_parser.php');
// create Imap_parser Object
$email = new Imap_parser();
// data
$data = array(
	// email account
	'email' => array(
		'hostname' => '{mail.dzvisual.my:143/notls}INBOX',
		'username' => 'homestay@dzvisual.my',
		'password' => 'Farhan@88'    
	),
	// inbox pagination
	'pagination' => array(
		'sort' => 'DESC', // or ASC
		'limit' => 10,
		'offset' => (empty($_GET['offset']) ? 0 : $_GET['offset'])
	)
);

// get inbox. Array
$result = $email->inbox($data);
//echo '<pre>'; print_r($result); echo '</pre>';
foreach($result['inbox'] as $data){

	echo "ID : ".$data['id']."<br>";
	echo "SUBJECT : ".$data['subject']."<br>";
	echo "FROM : ".$data['from']."<br>";
	echo "EMAIL : ".$data['email']."<br>";
	echo "DATE : ".$data['date']."<br>";
	//echo "MESSAGE : ".str_replace("= ","",$data['message'])."<br>";
	//echo "MESSAGE : ".base64_decode($data['message'])."<br>";
	echo "MESSAGE : ".$data['message']."<br>";
	echo "STR : ".strpos($data['message'],"Airbnb")."<br>";
	
	//preg_match('/(Airbnb)/',$data['message'],$matches, PREG_OFFSET_CAPTURE);
	echo "STR MATCH : ";
	
	if(strpos($data['message'],"Airbnb")){
		echo "Airbnb, ";
		echo substr($data['message'],strpos($data['message'],"Reservation ")+12,10);}
	
	if(strpos($data['message'],"Agoda")){
		echo "Agoda, ";
		echo substr($data['message'],strpos($data['message'],"ng ID ")+6,9);}
	
	
	
	//print_r($matches);
	echo "<br>";
	
	echo "HMDBQR3Z8X FOUND? : ";
	if(strpos($data['message'],"HMDBQR3Z8X")){echo "FOUNND!! HMDBQR3Z8X, ";}else{echo "NO AVAILABLE";}
	echo "<br>";
	echo "<br>";
};

//https://github.com/bachors/Imap_parser.php
?>

