View Single Post
  #8 (permalink)  
Old 11-04-2009, 06:17 AM
Hivos Hivos is offline
Advanced Member
 
Posts: 192
Default Added sort by date

Thanks for the script durango99. We've slightly adapted it to our needs. We've added a date column and display the array sorted by date.
PHP Code:
<?php

// Code by durango99
// 10/21/2008
// Adapted by Hivos
// 11/02/2009

$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>
Zimbra 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>
<?php

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>Date:</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"/^Date:(.*)$/m"$file$date );
    echo 
"$date[1]";

    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)
{
    
$results glob"/opt/zimbra/data/amavisd/quarantine/*" );

    
// Sort files by modified time, latest to earliest
    // Use SORT_ASC in place of SORT_DESC for earliest to latest
    
array_multisort(
    
array_map'filemtime'$results ),
    
SORT_NUMERIC,
    
SORT_DESC,
    
$results
    
);
    return 
$results;
}
?>
Reply With Quote