View Single Post
  #1 (permalink)  
Old 10-21-2008, 09:35 PM
durango99 durango99 is offline
Junior Member
 
Posts: 5
Default [SOLVED] qview.php - php script to handle quarantined emails

[possible repost: my previous post was flagged as spam, so i'll post with the php in the thread instead of as an attachment]

Until the RFE comes through, I created a simple php script to work with the quarantined email in a web interface. It's a first draft and I spent an hour working on it, so I won't be surprised if there might be some issues with it Not ideal but I think it's better than hunting around in the quarantine folder.

Also, currently there is not security provided at the moment. So anyone could get to this page. .htaccess or a web function to tie into the ldap system in zimbra should do the trick.

At the moment, you can view the raw email content or download the quarantine file but not release it back into the mail system to a recipient. The downloaded file will have a .eml extension so a email client should be able to render it.

Hope this helps others out!

Instructions:
  • Copy and paste the code below. Put it in a file called qview.php in /opt/zimbra/httpd/htdocs in your zimbra installation.
  • Access it http://<your zimbra server url>:7780/qview.php

Code:
PHP Code:
<?php

// Code by durango99
// 10/21/2008
// 

$getflag $_GET['getflag'];

$getfile $_GET['getfile'];
$getfile urldecode($getfile);

$dirname "/opt/zimbra/data/amavisd/quarantine/";

//download it
if ($getflag == 1){

    
header('Content-Description: File Transfer');
    
header('Content-Type: application/octet-stream');
    
header('Content-Disposition: attachment; filename='.basename($getfile).'.eml');
    
header('Content-Transfer-Encoding: binary');
    
header('Expires: 0');
    
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
    
header('Pragma: public');
    
header('Content-Length: ' filesize($getfile));
    
ob_clean();
    
flush();
    
readfile($getfile);

    die;

}


?>

<html>
<title>
Qview - Quarantine viewer
</title>

<head>
<style type="text/css">
body { 
font-family: arial;
font-size: normal;
 }

table { 
font-family: arial;
font-size: small;
 }
 
</style>
</head>

<body>
<?

echo "<p>Current Quarantine View:</p>\n";

//view it
if ($getflag == 2){


    $file = file_get_contents ($getfile); 

    echo "<pre>$file</pre>";
    
    die;
    
}


$qfiles = dirList($dirname);

echo "<table border=1>\n";

echo "<tr>
<td>#</td>
<td>From:</td>
<td>To</td>
<td>Subject</td>
<td>View</td>
<td><font color=red><b>(CAREFUL!)</font></b></td>
</tr>";

$i=1;
foreach ($qfiles as $qfile){

$YourFile = $dirname . $qfile;
$file = file_get_contents ($YourFile); 

echo "<tr><td>\n";

echo "$i";


echo "</td><td>\n";

preg_match( "/^From:(.*)$/m", $file, $fromline );
echo ($fromline[1]);

echo "</td><td>\n";

preg_match( "/^To:(.*)$/m", $file, $toline );
echo ($toline[1]);

echo "</td><td>\n";

preg_match( "/^Subject:(.*)$/m", $file, $subjline );
echo ($subjline[1]);

echo "</td><td>\n";

$ue=str_replace('+','%2B', $YourFile);
$ue=urlencode($ue);

echo "<a href=qview.php?getfile=$ue&getflag=2 target=_blank><font size=1em>$qfile</font></a>";

echo "</td><td>\n";

echo "<a href=qview.php?getfile=$ue&getflag=1 target=_blank><font color=grey>download</font></a>";

echo "</td></tr>\n";

$i++;

}

echo "</table>\n";


function dirList ($directory) 
{

    // create an array to hold directory list
    $results = array();

    // create a handler for the directory
    $handler = opendir($directory);

    // keep going until all files in directory have been read
    while ($file = readdir($handler)) {

        // if $file isn't this directory or its parent, 
        // add it to the results array
        if ($file != '.' && $file != '..')
            $results[] = $file;
    }

    // tidy up: close the handler
    closedir($handler);

    // done!
    return $results;

}

?>
</body>
</html>
Reply With Quote