| Welcome to the Zimbra :: Forums! | |
Welcome, if you would like to post a comment please register.
We also encourage you to explore all things Zimbra with our team and members of the community.
|  | 
10-21-2008, 09:35 PM
| | | [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> | 
10-21-2008, 10:06 PM
| | | Very nice:  | 
10-22-2008, 10:57 AM
| | | Quote:
Originally Posted by mmorse Very nice:  | Thanks Mike for the kind words and providing a screenshot of the interface. Glad it's working for you.
I'll probably add a date column and a sort feature so it's easier to read. | 
12-01-2008, 09:25 AM
| | Project Contributor | |
Posts: 108
| | Is this php ment to show daily results ? It would be nice to see feedback for more then just daily captures | 
12-01-2008, 10:01 AM
| | Advanced Member | |
Posts: 220
| | Nice script, I've checked your code now, but Is this code for each user he can mange his quarantine mails or it must be check through the admin consol?
Regards | 
12-01-2008, 10:05 AM
| | | The script is for all users ... time permitting I would like to try and write a zimlet for this, but need to see how to write the backend code.
__________________ | 
12-01-2008, 10:10 AM
| | Advanced Member | |
Posts: 220
| | I want to know how to write the backend code in order to write a zmilets, with reference to my experience with the development world, I have to many ideas to be written by the zimlet in order to utilize each user separated.
I wish studing this.. and I hope there is an document for the beginers.
Yours Sincerely, | 
11-04-2009, 06:17 AM
| | Advanced Member | |
Posts: 192
| | 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; } ?> | 
03-18-2010, 02:46 PM
| | Intermediate Member | |
Posts: 24
| | Thanx for the script.. much easier than the uudeview method we used....
Two thins got in my way of using the above modded script... I fond that subject lines that had gibberish or the like would confuse redering and cause the formatting to mess up. You will see the offending text right where the break in formatting happens, do a grep throuhg the content of the files in the direcrtory, whack it...
Also, some the the files I think were a bit big for the: $file = file_get_contents ($YourFile);
and the script would stop with only a partial listing. Changed it to: $file = file_get_contents ($YourFile, NULL, NULL, -1, 5000);
and that fixed it... I'm only quessing the 5000 characters is enough, you may have to adjust...
Thanx! | 
05-12-2010, 12:26 PM
| | Special Member | |
Posts: 103
| | This is awesome! This makes retrieving quaranteined e-mail much easier than via the CLI! If I'm bored, I may play around with making it "pretty". :-)
Thank you! | | Thread Tools | Search this Thread | | | | | Display Modes | Linear Mode | | Why Join? Registering let's you ask questions, makes it easier to search, displays any files attached to posts, and notifies you about replies.  |