added detach support for the gui

This commit is contained in:
SJ 2013-04-09 15:02:10 +02:00
parent 2a94804586
commit 8cf4a1b759
10 changed files with 149 additions and 16 deletions

View File

@ -91,7 +91,7 @@ struct _parse_rule config_parse_rules[] =
{ "pidfile", "string", (void*) string_parser, offsetof(struct __config, pidfile), PIDFILE, MAXVAL-1},
{ "piler_header_field", "string", (void*) string_parser, offsetof(struct __config, piler_header_field), "", MAXVAL-1},
{ "pilergetd_listen_addr", "string", (void*) string_parser, offsetof(struct __config, pilergetd_listen_addr), "127.0.0.1", MAXVAL-1},
{ "pilergetd_listen_port", "integer", (void*) int_parser, offsetof(struct __config, pilergetd_listen_port), "10026", sizeof(int)},
{ "pilergetd_listen_port", "integer", (void*) int_parser, offsetof(struct __config, pilergetd_listen_port), "10091", sizeof(int)},
{ "pilergetd_pidfile", "string", (void*) string_parser, offsetof(struct __config, pilergetd_pidfile), PILERGETD_PIDFILE, MAXVAL-1},
{ "queuedir", "string", (void*) string_parser, offsetof(struct __config, queuedir), QUEUE_DIR, MAXVAL-1},
{ "server_id", "integer", (void*) int_parser, offsetof(struct __config, server_id), "0", sizeof(int)},

View File

@ -8,6 +8,10 @@ $config = array();
* variable to be overridden in config-site.php
*/
$config['PILERGETD_HOST'] = '';
$config['PILERGETD_PORT'] = 10091;
$config['PILERGETD_READ_LENGTH'] = 8192;
$config['PILERGETD_TIMEOUT'] = 5;
$config['BRANDING_TEXT'] = '';
$config['BRANDING_URL'] = '';

View File

@ -51,6 +51,8 @@ class ControllerMessageBulkrestore extends Controller {
}
$this->model_search_message->connect_to_pilergetd();
foreach($idlist as $id) {
AUDIT(ACTION_RESTORE_MESSAGE, '', '', $id, '');
@ -88,6 +90,7 @@ class ControllerMessageBulkrestore extends Controller {
}
}
$this->model_search_message->disconnect_from_pilergetd();
if(ENABLE_IMAP_AUTH == 1) { $this->model_mail_mail->disconnect_imap(); }

View File

@ -40,8 +40,10 @@ class ControllerMessageDownload extends Controller {
header("Content-Disposition: attachment; filename=" . $this->data['piler_id'] . ".eml");
header("Content-Transfer-Encoding: binary\n");
$this->model_search_message->connect_to_pilergetd();
$msg = $this->model_search_message->get_raw_message($this->data['piler_id']);
$this->model_search_message->disconnect_from_pilergetd();
$this->model_search_message->remove_journal($msg);
print $msg;
}

View File

@ -64,7 +64,10 @@ class ControllerMessageRestore extends Controller {
$this->data['piler_id'] = $this->model_search_message->get_piler_id_by_id($this->data['id']);
$this->model_search_message->connect_to_pilergetd();
$msg = $this->model_search_message->get_raw_message($this->data['piler_id']);
$this->model_search_message->disconnect_from_pilergetd();
$this->model_search_message->remove_journal($msg);
if(ENABLE_IMAP_AUTH == 1) {

View File

@ -23,6 +23,9 @@ Registry::set("request", $request);
Registry::set('document', new Document());
$start = NULL;
$loader = new Loader();
Registry::set('load', $loader);

View File

@ -13,15 +13,20 @@ class ModelMessageRestore extends Model {
if($zip->open($filename, ZIPARCHIVE::CREATE) != true) { exit("cannot open <$filename>\n"); }
$this->model_search_message->connect_to_pilergetd();
foreach($idlist as $id) {
$piler_id = $this->model_search_message->get_piler_id_by_id($id);
$rawemail = $this->model_search_message->get_raw_message($piler_id);
$zip->addFromString($piler_id . ".eml", $rawemail);
AUDIT(ACTION_DOWNLOAD_MESSAGE, '', '', $id, '');
}
$this->model_search_message->disconnect_from_pilergetd();
$zip->close();

View File

@ -27,35 +27,131 @@ class ModelSearchMessage extends Model {
}
public function get_raw_message($id = '') {
$data = '';
public function get_file_size($sd, $id = '') {
fputs($sd, "STAT $id\r\n");
$s = fgets($sd, 8192);
if($id == '' || !preg_match("/^([0-9a-f]+)$/", $id)) { return $data; }
$a = explode(" ", $s);
if(isset($a[2]) && $a[2] > 0) { return $a[2]; }
$handle = popen(DECRYPT_BINARY . " $id", "r");
while(($buf = fread($handle, DECRYPT_BUFFER_LENGTH))){
$data .= $buf;
return 0;
}
pclose($handle);
return $data;
public function read_file($sd, $f = '', $size = 0) {
global $start;
$s = '';
$len = 0;
if($size <= 0) { return $s; }
fputs($sd, "RETR $f\r\n");
while(!safe_feof($sd, $start) && (microtime(true) - $start) < PILERGETD_TIMEOUT) {
$s .= fread($sd, PILERGETD_READ_LENGTH);
$len += PILERGETD_READ_LENGTH;
if($len >= $size) break;
}
return $s;
}
public function connect_to_pilergetd() {
if(PILERGETD_HOST) {
$sd = fsockopen(PILERGETD_HOST, PILERGETD_PORT);
if(!$sd) { return FALSE; }
$l = fgets($sd, 4096);
Registry::set('sd', $sd);
}
}
public function disconnect_from_pilergetd() {
if(PILERGETD_HOST) {
$sd = Registry::get('sd');
fputs($sd, "QUIT\r\n");
fclose($sd);
}
}
public function get_raw_message($id = '') {
$s = '';
if($id == '' || !preg_match("/^([0-9a-f]+)$/", $id)) { return $s; }
if(PILERGETD_HOST) {
$sd = Registry::get('sd');
fputs($sd, "MESSAGE $id\r\n");
$l = fgets($sd, 8192);
$message = explode(" ", rtrim($l));
while(list($k, $v) = each($message)) {
if($k == 0) {
$size = $this->get_file_size($sd, $v);
$s = $this->read_file($sd, $v, $size);
$s = gzuncompress($s);
}
else {
$size = $this->get_file_size($sd, $v);
$a = $this->read_file($sd, $v, $size);
$a = gzuncompress($a);
$repl = "ATTACHMENT_POINTER_" . $id . ".a" . $k . "_XXX_PILER";
$s = preg_replace("/$repl/", $a, $s);
$a = '';
}
}
}
else {
$handle = popen(DECRYPT_BINARY . " $id", "r");
while(($buf = fread($handle, DECRYPT_BUFFER_LENGTH))){
$s .= $buf;
}
pclose($handle);
}
return $s;
}
public function get_attachment($piler_id = '', $attachment_id = '') {
$data = '';
if($piler_id == '' || $attachment_id == '' || !preg_match("/^([0-9a-f]+)$/", $piler_id) || !preg_match("/^([0-9]+)$/", $attachment_id)) { return $data; }
if($piler_id == '' || $attachment_id == '' || !preg_match("/^([0-9a-f]+)$/", $piler_id) || !preg_match("/^([0-9m]+)$/", $attachment_id)) { return $data; }
$handle = popen(DECRYPT_ATTACHMENT_BINARY . " $piler_id $attachment_id", "r");
if(PILERGETD_HOST) {
$sd = fsockopen(PILERGETD_HOST, PILERGETD_PORT);
if(!$sd) { return $data; }
$l = fgets($sd, 4096);
$size = $this->get_file_size($sd, $piler_id . ".a" . $attachment_id);
$data = $this->read_file($sd, $piler_id . ".a" . $attachment_id, $size);
$data = gzuncompress($data);
fclose($sd);
}
else {
$handle = popen(DECRYPT_BINARY . " $id", "r");
while(($buf = fread($handle, DECRYPT_BUFFER_LENGTH))){
$data .= $buf;
}
pclose($handle);
}
/* check if it's a base64 encoded stuff */
@ -73,7 +169,9 @@ class ModelSearchMessage extends Model {
public function get_message_headers($id = '') {
$data = '';
$this->connect_to_pilergetd();
$msg = $this->get_raw_message($id);
$this->disconnect_from_pilergetd();
$this->remove_journal($msg);
@ -143,7 +241,9 @@ class ModelSearchMessage extends Model {
$from = $to = $subject = $date = $message = "";
$this->connect_to_pilergetd();
$msg = $this->get_raw_message($id);
$this->disconnect_from_pilergetd();
$this->remove_journal($msg);

View File

@ -493,6 +493,9 @@ class ModelSearchSearch extends Model {
$lang = Registry::get('language');
$this->model_search_message->connect_to_pilergetd();
foreach($query->rows as $m) {
$m['shortfrom'] = make_short_string($m['from'], MAX_CGI_FROM_SUBJ_LEN);
$m['from'] = escape_gt_lt_quote_symbols($m['from']);
@ -526,6 +529,9 @@ class ModelSearchSearch extends Model {
array_push($messages, $m);
}
$this->model_search_message->disconnect_from_pilergetd();
}
if(MEMCACHED_ENABLED) {

View File

@ -484,4 +484,11 @@ function fix_evolution_mime_name_crap($s = '') {
}
function safe_feof($fp, &$start = NULL) {
$start = microtime(true);
return feof($fp);
}
?>