2012-05-07 09:38:47 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
class ControllerMessageBulkrestore extends Controller {
|
|
|
|
|
|
|
|
public function index(){
|
|
|
|
|
|
|
|
$this->id = "content";
|
|
|
|
$this->template = "message/bulkrestore.tpl";
|
|
|
|
$this->layout = "common/layout-empty";
|
|
|
|
|
2013-11-18 19:24:33 +01:00
|
|
|
$session = Registry::get('session');
|
2012-05-07 09:38:47 +02:00
|
|
|
$request = Registry::get('request');
|
|
|
|
$db = Registry::get('db');
|
|
|
|
|
2013-04-02 22:22:30 +02:00
|
|
|
$imap_ok = 0;
|
2013-12-19 13:23:51 +01:00
|
|
|
$email = '';
|
2013-04-02 22:22:30 +02:00
|
|
|
|
2012-05-07 09:38:47 +02:00
|
|
|
$this->load->model('search/search');
|
|
|
|
$this->load->model('search/message');
|
2012-05-11 23:42:55 +02:00
|
|
|
$this->load->model('message/restore');
|
2012-05-07 09:38:47 +02:00
|
|
|
|
|
|
|
$this->load->model('user/user');
|
|
|
|
$this->load->model('mail/mail');
|
|
|
|
|
2013-04-02 22:22:30 +02:00
|
|
|
|
2012-05-07 09:38:47 +02:00
|
|
|
$this->document->title = $this->data['text_message'];
|
|
|
|
|
|
|
|
if(!isset($this->request->post['idlist']) || $this->request->post['idlist'] == '') { die("no idlist parameter given"); }
|
|
|
|
|
2012-09-06 15:27:20 +02:00
|
|
|
$idlist = $this->model_search_search->check_your_permission_by_id_list(explode(",", $this->request->post['idlist']));
|
2012-05-07 09:38:47 +02:00
|
|
|
|
2012-05-11 23:42:55 +02:00
|
|
|
$download = $this->request->post['download'];
|
|
|
|
|
2013-12-19 13:23:51 +01:00
|
|
|
if(isset($this->request->post['email'])) { $email = $this->request->post['email']; }
|
2012-05-11 23:42:55 +02:00
|
|
|
|
|
|
|
if($download == 1) {
|
|
|
|
$this->model_message_restore->download_files_as_zip($idlist);
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
2012-05-07 09:38:47 +02:00
|
|
|
|
|
|
|
$this->data['username'] = Registry::get('username');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$this->data['restored'] = 0;
|
|
|
|
|
2017-09-23 17:13:29 +02:00
|
|
|
if(RESTORE_OVER_IMAP == 1 && Registry::get('auditor_user') == 0) {
|
2013-04-02 22:22:30 +02:00
|
|
|
require_once 'Zend/Mail/Protocol/Imap.php';
|
|
|
|
require_once 'Zend/Mail/Storage/Imap.php';
|
|
|
|
|
2016-12-24 21:19:33 +01:00
|
|
|
$emails = $session->get("emails");
|
|
|
|
|
2013-04-02 22:22:30 +02:00
|
|
|
$imap_ok = $this->model_mail_mail->connect_imap();
|
2014-06-21 21:30:51 +02:00
|
|
|
|
|
|
|
if(!$imap_ok) {
|
|
|
|
syslog(LOG_INFO, "imap connection failed for bulkrestore");
|
|
|
|
}
|
2013-04-02 22:22:30 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-05-07 09:38:47 +02:00
|
|
|
foreach($idlist as $id) {
|
|
|
|
|
|
|
|
AUDIT(ACTION_RESTORE_MESSAGE, '', '', $id, '');
|
|
|
|
|
2012-08-15 16:24:56 +02:00
|
|
|
$rcpt = array();
|
|
|
|
|
2012-12-20 14:11:17 +01:00
|
|
|
/* send the email to all the recipients of the original email if you are an auditor user */
|
2012-08-15 16:24:56 +02:00
|
|
|
|
|
|
|
if(Registry::get('auditor_user') == 1) {
|
2013-12-19 13:23:51 +01:00
|
|
|
if($email) {
|
|
|
|
$rcpt[0] = $email;
|
|
|
|
}
|
|
|
|
else {
|
2014-03-19 16:43:55 +01:00
|
|
|
$rcpt[0] = $session->get("email");
|
2013-12-19 13:23:51 +01:00
|
|
|
}
|
2012-08-15 16:24:56 +02:00
|
|
|
}
|
|
|
|
else {
|
2013-11-18 19:24:33 +01:00
|
|
|
array_push($rcpt, $session->get("email"));
|
2012-08-15 16:24:56 +02:00
|
|
|
}
|
|
|
|
|
2012-09-06 15:27:20 +02:00
|
|
|
if(count($rcpt) > 0) {
|
|
|
|
$piler_id = $this->model_search_message->get_piler_id_by_id($id);
|
2012-05-07 09:38:47 +02:00
|
|
|
|
2013-01-27 21:43:42 +01:00
|
|
|
$msg = $this->model_search_message->get_raw_message($piler_id);
|
2018-12-23 20:50:14 +01:00
|
|
|
$this->model_search_message->remove_journal($msg);
|
2013-01-27 21:43:42 +01:00
|
|
|
|
2017-09-23 17:13:29 +02:00
|
|
|
if(RESTORE_OVER_IMAP == 1 && Registry::get('auditor_user') == 0) {
|
2013-04-02 22:22:30 +02:00
|
|
|
if($imap_ok) {
|
2016-12-24 21:19:33 +01:00
|
|
|
$imap_folder = IMAP_RESTORE_FOLDER_INBOX;
|
|
|
|
|
|
|
|
$meta = $this->model_search_message->get_metadata_by_id($id);
|
|
|
|
if(in_array($meta['from'], $emails)) {
|
|
|
|
$imap_folder = IMAP_RESTORE_FOLDER_SENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
$x = $this->imap->append($imap_folder, $msg);
|
|
|
|
syslog(LOG_INFO, "imap append $id/$piler_id, to " . $imap_folder . ", rc=$x");
|
2013-04-02 22:22:30 +02:00
|
|
|
}
|
|
|
|
else { $x = 0; }
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
|
2014-01-05 22:47:47 +01:00
|
|
|
if(RESTORE_EMAILS_AS_ATTACHMENT == 1) {
|
|
|
|
$msg = $this->model_mail_mail->message_as_rfc822_attachment($piler_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 . $id . EOL . $msg );
|
|
|
|
}
|
|
|
|
|
2013-04-02 22:22:30 +02:00
|
|
|
}
|
2012-09-06 15:27:20 +02:00
|
|
|
|
|
|
|
if($x == 1) { $this->data['restored']++; }
|
|
|
|
}
|
2012-05-07 09:38:47 +02:00
|
|
|
}
|
|
|
|
|
2014-06-05 13:32:22 +02:00
|
|
|
if(RESTORE_OVER_IMAP == 1) { $this->model_mail_mail->disconnect_imap(); }
|
2013-04-02 22:22:30 +02:00
|
|
|
|
|
|
|
|
2012-05-07 09:38:47 +02:00
|
|
|
$this->render();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
?>
|