piler/webui/controller/message/restore.php

110 lines
3.4 KiB
PHP
Raw Normal View History

2012-02-08 23:14:28 +01:00
<?php
class ControllerMessageRestore extends Controller {
public function index(){
$this->id = "content";
$this->template = "message/restore.tpl";
$this->layout = "common/layout-empty";
2013-11-18 19:24:33 +01:00
$session = Registry::get('session');
2012-02-08 23:14:28 +01:00
$request = Registry::get('request');
$db = Registry::get('db');
$this->load->model('search/search');
$this->load->model('search/message');
$this->load->model('audit/audit');
2012-02-08 23:14:28 +01:00
$this->load->model('user/user');
$this->load->model('mail/mail');
$this->document->title = $this->data['text_message'];
$this->data['id'] = @$this->request->get['id'];
$rcpt = array();
2014-06-05 13:32:22 +02:00
if(RESTORE_OVER_IMAP == 1) {
2013-04-02 22:22:30 +02:00
require_once 'Zend/Mail/Protocol/Imap.php';
require_once 'Zend/Mail/Storage/Imap.php';
}
if(Registry::get('auditor_user') == 1) {
$this->data['id'] = @$this->request->post['id'];
2014-06-17 15:03:56 +02:00
$this->request->post['rcpt'] = urldecode($this->request->post['rcpt']);
$rcpt = preg_split("/\s/", $this->request->post['rcpt']);
}
if(!$this->model_audit_audit->can_restore()) {
die("cannot restore at the moment");
}
2012-02-08 23:14:28 +01:00
if(!verify_piler_id($this->data['id'])) {
AUDIT(ACTION_UNKNOWN, '', '', $this->data['id'], 'unknown piler id: ' . $this->data['id']);
die("invalid id: " . $this->data['id']);
}
2012-09-06 15:27:20 +02:00
if(!$this->model_search_search->check_your_permission_by_id($this->data['id'])) {
2012-02-08 23:14:28 +01:00
AUDIT(ACTION_UNAUTHORIZED_VIEW_MESSAGE, '', '', $this->data['id'], '');
die("no permission for " . $this->data['id']);
}
AUDIT(ACTION_RESTORE_MESSAGE, '', '', $this->data['id'], '');
$this->data['username'] = Registry::get('username');
/* send the email to all the recipients of the original email if we are admin or auditor users */
if(Registry::get('auditor_user') == 0) {
2013-11-18 19:24:33 +01:00
array_push($rcpt, $session->get("email"));
2012-02-08 23:14:28 +01:00
}
$this->data['data'] = $this->data['text_failed_to_restore'];
2012-02-08 23:14:28 +01:00
if(count($rcpt) > 0) {
2012-02-08 23:14:28 +01:00
$this->data['piler_id'] = $this->model_search_message->get_piler_id_by_id($this->data['id']);
2013-01-27 21:43:42 +01:00
$msg = $this->model_search_message->get_raw_message($this->data['piler_id']);
2013-04-09 15:02:10 +02:00
2013-01-27 21:43:42 +01:00
$this->model_search_message->remove_journal($msg);
2014-06-05 13:32:22 +02:00
if(RESTORE_OVER_IMAP == 1) {
2013-04-02 22:22:30 +02:00
if($this->model_mail_mail->connect_imap()) {
$x = $this->imap->append(IMAP_RESTORE_FOLDER, $msg);
2015-07-16 14:47:16 +02:00
syslog(LOG_INFO, "imap append " . $this->data['id'] . "/" . $this->data['piler_id'] . ", rc=$x");
2013-04-02 22:22:30 +02:00
$this->model_mail_mail->disconnect_imap();
}
else {
$x = 0;
}
}
else {
if(RESTORE_EMAILS_AS_ATTACHMENT == 1) {
$msg = $this->model_mail_mail->message_as_rfc822_attachment($this->data['id'], $msg, $rcpt[0]);
$x = $this->model_mail_mail->send_smtp_email(SMARTHOST, SMARTHOST_PORT, SMTP_DOMAIN, SMTP_FROMADDR, $rcpt, $msg);
}
else {
$x = $this->model_mail_mail->send_smtp_email(SMARTHOST, SMARTHOST_PORT, SMTP_DOMAIN, SMTP_FROMADDR, $rcpt,
"Received: by piler" . EOL . PILER_HEADER_FIELD . $this->data['id'] . EOL . $msg );
}
2013-04-02 22:22:30 +02:00
}
if($x == 1) { $this->data['data'] = $this->data['text_restored']; }
}
2012-02-08 23:14:28 +01:00
$this->render();
}
}
?>