Skip to content

Instantly share code, notes, and snippets.

@lucasburlingham
Created August 3, 2021 18:56
Show Gist options
  • Save lucasburlingham/30324041e453eda03eac6b03b340f924 to your computer and use it in GitHub Desktop.
Save lucasburlingham/30324041e453eda03eac6b03b340f924 to your computer and use it in GitHub Desktop.
Get headers from all the mail in your inbox - currently has settings for Office 365
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<link rel="stylesheet" href="assets/css/style.css">
<title>Email Spoof Detection</title>
</head>
<body>
<?php
// $mbox = imap_open("{<imap domain>:<port number>/imap/ssl/novalidate-cert}", "<user@domain.com>", "<your password>");
$mbox = imap_open("{outlook.office365.com:993/imap/ssl/novalidate-cert}", "<user@domain.com>", "<your password>");
$headers = imap_headers($mbox);
array_unshift($headers, " ");
$headers_count = count($headers) - 1;
$mailboxes = imap_listmailbox($mbox, "{outlook.office365.com:993/imap/ssl/novalidate-cert}", "*");
$mailboxes_count = count($mailboxes);
$status = imap_status($mbox, "{outlook.office365.com:993/imap/ssl/novalidate-cert}", SA_ALL);
if ($headers == false) {
echo "Call failed<br />\n";
} else {
echo <<<EOL
<div class="jumbotron">
<h1>Headers in INBOX</h1>
<div class="font-weight-bold">
There are $headers_count Messages in the Inbox.
</div>
<hr>
</div>
EOL;
for ($i = count($headers) - 1; $i >= 1; $i--) {
settype($i, "int");
echo <<<EOL
<p class="card">
<a class="card-body font-weight-bold text-dark" onclick="$('#$i').collapse('toggle')" role="button" aria-expanded="false">
$headers[$i]
</a>
</p>
EOL;
$full_headers = str_replace(";", ";<br>\n", imap_fetchheader($mbox, $i));
echo <<<EOL
<div class="collapse" id="$i">
<div class="card card-body">
$i full_headers
</div>
</div>
EOL;
}
}
echo <<<EOL
<div class="jumbotron">
<h1>Mailboxes</h1>
<div class="font-weight-bold">
$mailboxes_count mailboxes can be found.
</div>
<hr>
</div>
EOL;
if ($mailboxes == false) {
echo "Call failed<br />\n";
} else {
echo <<<EOL
<p class="card">
<a class="card-body font-weight-bold text-dark" onclick="$('#mailboxes').collapse('toggle')" role="button" aria-expanded="false">
Mailboxes
</a>
</p>
<div class="collapse" id="mailboxes">
<div class="card card-body">
EOL;
foreach ($mailboxes as $val) {
echo $val . "<br>\n";
}
echo <<<EOL
</div>
</div>
EOL;
}
imap_close($mbox);
?>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.6.0/js/bootstrap.min.js"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment