<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>メールチェック</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<meta name="generator" content="Geany 1.23.1" />
<style type="text/css">
table {
table-layout: fixed;
word-wrap: break-word;
width:100%;
border-collapse: collapse;
}
table, td, th{
border: 1px #000000 solid;
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
</style>
</head>
<body>
<table>
<tr><th style="width:250px">送信者</th><th>タイトル</th><th style="width:200px">時刻</th><th style="width:50px">主</th><th style="width:50px">副</th></tr>
<?php
$master_mbox = imap_open('{imap.gmail.com:993/imap/ssl}[Gmail]/&MFkweTBmMG4w4TD8MOs-', 'master@example.com', 'MasterPassword', OP_READONLY) or die("接続できません: " . imap_last_error());;
$slave_mbox = imap_open('{imap.gmail.com:993/imap/ssl}[Gmail]/&MFkweTBmMG4w4TD8MOs-', 'slave@example.com', 'SlavePassword', OP_READONLY) or die("接続できません: " . imap_last_error());;
$MC = imap_check($master_mbox);
$m_max = $MC->Nmsgs;
$m_min = $MC->Nmsgs - 200;
if ($m_min < 0) {
$m_min = 1;
}
$MC = imap_check($slave_mbox);
$s_max = $MC->Nmsgs;
$s_min = $MC->Nmsgs - 200;
if ($s_min < 0) {
$s_min = 1;
}
$master_result = imap_fetch_overview($master_mbox, $m_min . ':' . $m_max);
$slave_result = imap_fetch_overview($slave_mbox, $s_min . ':' . $s_max);
$mmsg_ids = array();
$mdates = array();
foreach($master_result as $key=>$overview){
$mmsg_ids[$overview->message_id] = &$master_result[$key];
$mdates[$overview->message_id] = strtotime($overview->date);
}
$smsg_ids = array();
$sdates = array();
foreach($slave_result as $key=>$overview){
$smsg_ids[$overview->message_id] = &$slave_result[$key];
$sdates[$overview->message_id] = strtotime($overview->date);
}
$dates = array_merge($mdates, $sdates);
$msg_ids = array_merge($mmsg_ids, $smsg_ids);
array_multisort($dates, $msg_ids);
$msg_ids = array_reverse($msg_ids);
foreach ($msg_ids as $message_id=>$overview) {
$mmark = '×';
$smark = '×';
if(isset($mmsg_ids[$message_id])){
$mmark = '○';
}
if(isset($smsg_ids[$message_id])){
$smark = '○';
}
$subject = imap_utf8($overview->subject);
$date = date('Y/m/d H:i:s', strtotime($overview->date));
$from = imap_utf8($overview->from);
$subject = htmlspecialchars($subject);
$from = htmlspecialchars($from);
echo "<tr><td>{$from}</td><td>{$subject}</td><td style='text-align:center;'>{$date}</td><td style='text-align:center;'>{$mmark}</td><td style='text-align:center;'>{$smark}</td></tr>\n";
}
imap_close($master_mbox);
imap_close($slave_mbox);
?>
</table>
</body>
</html>