<?php
//Fix by Siongjer
include('global.php');
session_start();
if (!session_is_registered("SESSION"))
{
header("Location: error.php?ec=2");
exit;
}
if (!$id || !$pid)
{
header("Location: error.php?ec=4");
exit;
}
$id = $_GET['id'];
$pid = $_GET['pid'];
// open POP connection //fixed
$inbox = imap_open("{localhost:110/pop3/notls}INBOX",$_SESSION['SESSION_USER_NAME'], $_SESSION['SESSION_USER_PASS'], OP_HALFOPEN) or header("Location: error.php?ec=1");
// parse message structure
$structure = imap_fetchstructure($inbox, $id);
$sections = parse($structure);
// look for specified part
for($x=0; $x<sizeof($sections); $x++)
{
if($sections[$x]["pid"] == $pid)
{
$type = $sections[$x]["type"];
$encoding = $sections[$x]["encoding"];
$filename = $sections[$x]["name"];
}
}
$attachment = imap_fetchbody($inbox, $id, $pid);
// send headers to browser to initiate file download
header ("Content-Type: application/octet-stream");
header ("Content-Disposition: attachment; filename=$filename");
if ($encoding == "base64")
{
// decode and send
echo imap_base64($attachment);
}
else
{
// add handlers for other encodings here
echo $attachment;
}
// clean up
imap_close($inbox);
?>