From c21c27a6ddfd1c8bae18a694d0854dbeea2c7a21 Mon Sep 17 00:00:00 2001 From: SJ Date: Tue, 2 Apr 2013 22:22:30 +0200 Subject: [PATCH] added imap restore to inbox feature --- webui/controller/message/bulkrestore.php | 27 ++++++++++++++++++++++-- webui/controller/message/restore.php | 20 +++++++++++++++++- webui/model/mail/mail.php | 17 +++++++++++++++ webui/model/user/auth.php | 2 ++ 4 files changed, 63 insertions(+), 3 deletions(-) diff --git a/webui/controller/message/bulkrestore.php b/webui/controller/message/bulkrestore.php index beef75dd..c3e12508 100644 --- a/webui/controller/message/bulkrestore.php +++ b/webui/controller/message/bulkrestore.php @@ -12,6 +12,8 @@ class ControllerMessageBulkrestore extends Controller { $request = Registry::get('request'); $db = Registry::get('db'); + $imap_ok = 0; + $this->load->model('search/search'); $this->load->model('search/message'); $this->load->model('message/restore'); @@ -19,6 +21,7 @@ class ControllerMessageBulkrestore extends Controller { $this->load->model('user/user'); $this->load->model('mail/mail'); + $this->document->title = $this->data['text_message']; if(!isset($this->request->post['idlist']) || $this->request->post['idlist'] == '') { die("no idlist parameter given"); } @@ -40,6 +43,14 @@ class ControllerMessageBulkrestore extends Controller { $this->data['restored'] = 0; + if(ENABLE_IMAP_AUTH == 1) { + require_once 'Zend/Mail/Protocol/Imap.php'; + require_once 'Zend/Mail/Storage/Imap.php'; + + $imap_ok = $this->model_mail_mail->connect_imap(); + } + + foreach($idlist as $id) { AUDIT(ACTION_RESTORE_MESSAGE, '', '', $id, ''); @@ -61,14 +72,26 @@ class ControllerMessageBulkrestore extends Controller { $msg = $this->model_search_message->get_raw_message($piler_id); $this->model_search_message->remove_journal($msg); - $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 ); + if(ENABLE_IMAP_AUTH == 1) { + if($imap_ok) { + $x = $this->imap->append('INBOX', $msg); + } + else { $x = 0; } + } + 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 ); + } if($x == 1) { $this->data['restored']++; } } } + if(ENABLE_IMAP_AUTH == 1) { $this->model_mail_mail->disconnect_imap(); } + + $this->render(); } diff --git a/webui/controller/message/restore.php b/webui/controller/message/restore.php index 30e8588b..d6f8f732 100644 --- a/webui/controller/message/restore.php +++ b/webui/controller/message/restore.php @@ -24,6 +24,12 @@ class ControllerMessageRestore extends Controller { $rcpt = array(); + if(ENABLE_IMAP_AUTH == 1) { + 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']; $rcpt = preg_split("/\s/", $this->request->post['rcpt']); @@ -61,8 +67,20 @@ class ControllerMessageRestore extends Controller { $msg = $this->model_search_message->get_raw_message($this->data['piler_id']); $this->model_search_message->remove_journal($msg); - $x = $this->model_mail_mail->send_smtp_email(SMARTHOST, SMARTHOST_PORT, SMTP_DOMAIN, SMTP_FROMADDR, $rcpt, + if(ENABLE_IMAP_AUTH == 1) { + if($this->model_mail_mail->connect_imap()) { + $x = $this->imap->append('INBOX', $msg); + $this->model_mail_mail->disconnect_imap(); + } + else { + $x = 0; + } + } + 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 ); + } if($x == 1) { $this->data['data'] = $this->data['text_restored']; } } diff --git a/webui/model/mail/mail.php b/webui/model/mail/mail.php index 5f2aa672..7612f6e4 100644 --- a/webui/model/mail/mail.php +++ b/webui/model/mail/mail.php @@ -50,6 +50,23 @@ class ModelMailMail extends Model { return $ok; } + + public function connect_imap() { + $this->imap = new Zend_Mail_Protocol_Imap(IMAP_HOST, IMAP_PORT, IMAP_SSL); + + if($this->imap) { + if($this->imap->login($_SESSION['username'], $_SESSION['password'])) { return 1; } + } + + return 0; + } + + + public function disconnect_imap() { + $this->imap->logout; + } + + } ?> diff --git a/webui/model/user/auth.php b/webui/model/user/auth.php index ffae8ff1..74fb86e6 100644 --- a/webui/model/user/auth.php +++ b/webui/model/user/auth.php @@ -178,6 +178,8 @@ class ModelUserAuth extends Model { $this->add_session_vars($username, $username, array($username)); + $_SESSION['password'] = $password; + return 1; }