<?php
$eml_file = $file;
$content = file_get_contents($eml_file) or die("Could not read files");
$email = new Email($content);
//exit($email->raw);
$email->analyze();
if(!isset($_GET['attachment'])) {
?>
<html>
<head>
<style>
#container {
margin: 10px;
border: 1px solid black;
font-family:arial;
}
#downloadlink {
background-color:#ff9;
line-height:35px;
font-size:18px;
font-weight:bold;
padding-left:10px;
border-bottom: 1px solid black;
}
#info {
background-color:#eee;
padding:10px;
border-bottom:1px solid black;
}
.label {
float:left;
width:150px;
font-weight:bold;
text-align:right;
margin-right:10px;
clear:left;
line-height:20px;
}
.info {
line-height:20px;
}
#message {
padding:0px 10px;
height:400px;
overflow:auto;
}
</style>
</head>
<body>
<div id='container'>
<div id='downloadlink'>
<a href='file.php?file=<?php echo $_REQUEST['file']; ?>&download=true;'>Download email</a>
</div>
<div id='info'>
<div class='label'>From:</div>
<div class='info'> <?php echo $email->from; ?></div>
<div class='label'>To:</div>
<div class='info'> <?php echo $email->to; ?></div>
<div class='label'>Subject:</div>
<div class='info'> <?php echo $email->subject; ?></div>
<div class='label'>Date:</div>
<div class='info'><?php echo $email->date; ?></div>
<div class='label'>Attachments:</div>
<div class='info'>
<?php
$attachments=array();
foreach($email->attachments as $key=>$attachment) {
$attachments[]="<a href='?file=".$_GET['file']."&attachment=$key'>$attachment[filename]</a>";
}
echo implode("; ", $attachments);
?>
<br style='clear: left;' />
</div></div>
<div id='message'>
<?php
echo $email->plain;
?>
</div>
</div>
</body>
</html>
<?php
} else {
//This is an attempt to downlaod an attachment.. send the attachment after decoding it
$attachment = $email->attachments[$_GET['attachment']];
header("Content-Type: " . $attachment['Content-Type']);
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=\"".$attachment['filename']."\";");
if(!in_array($attachment['ext'],$not_binary)) {
header("Content-Transfer-Encoding: binary");
}
exit($attachment['body']);
}
?>