diff --git a/webui/config.php b/webui/config.php index 5dfc300..e81f51a 100644 --- a/webui/config.php +++ b/webui/config.php @@ -107,7 +107,8 @@ $config['ENABLE_IMAP_AUTH'] = 0; $config['RESTORE_OVER_IMAP'] = 0; -$config['IMAP_RESTORE_FOLDER'] = 'INBOX'; +$config['IMAP_RESTORE_FOLDER_INBOX'] = 'INBOX'; +$config['IMAP_RESTORE_FOLDER_SENT'] = 'Sent'; $config['IMAP_HOST'] = 'mail.yourdomain.com'; $config['IMAP_PORT'] = 993; $config['IMAP_SSL'] = true; diff --git a/webui/controller/message/bulkrestore.php b/webui/controller/message/bulkrestore.php index 6a24540..0cd51ce 100644 --- a/webui/controller/message/bulkrestore.php +++ b/webui/controller/message/bulkrestore.php @@ -50,6 +50,8 @@ require_once 'Zend/Mail/Protocol/Imap.php'; require_once 'Zend/Mail/Storage/Imap.php'; + $emails = $session->get("emails"); + $imap_ok = $this->model_mail_mail->connect_imap(); if(!$imap_ok) { @@ -86,8 +88,15 @@ if(RESTORE_OVER_IMAP == 1) { if($imap_ok) { - $x = $this->imap->append(IMAP_RESTORE_FOLDER, $msg); - syslog(LOG_INFO, "imap append $id/$piler_id, rc=$x"); + $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"); } else { $x = 0; } } diff --git a/webui/controller/message/restore.php b/webui/controller/message/restore.php index d33e2db..4bcdc97 100644 --- a/webui/controller/message/restore.php +++ b/webui/controller/message/restore.php @@ -67,8 +67,8 @@ $this->data['data'] = $this->data['text_failed_to_restore']; if(count($rcpt) > 0) { - - $this->data['piler_id'] = $this->model_search_message->get_piler_id_by_id($this->data['id']); + $this->data['meta'] = $this->model_search_message->get_metadata_by_id($this->data['id']); + $this->data['piler_id'] = $this->data['meta']['piler_id']; $msg = $this->model_search_message->get_raw_message($this->data['piler_id']); @@ -76,8 +76,16 @@ if(RESTORE_OVER_IMAP == 1) { if($this->model_mail_mail->connect_imap()) { - $x = $this->imap->append(IMAP_RESTORE_FOLDER, $msg); - syslog(LOG_INFO, "imap append " . $this->data['id'] . "/" . $this->data['piler_id'] . ", rc=$x"); + + $imap_folder = IMAP_RESTORE_FOLDER_INBOX; + + $emails = $session->get("emails"); + if(in_array($this->data['meta']['from'], $emails)) { + $imap_folder = IMAP_RESTORE_FOLDER_SENT; + } + + $x = $this->imap->append($imap_folder, $msg); + syslog(LOG_INFO, "imap append " . $this->data['id'] . "/" . $this->data['piler_id'] . " to " . $imap_folder . ", rc=$x"); $this->model_mail_mail->disconnect_imap(); } else { diff --git a/webui/model/search/message.php b/webui/model/search/message.php index 56c9659..5d570b6 100644 --- a/webui/model/search/message.php +++ b/webui/model/search/message.php @@ -443,6 +443,13 @@ } + public function get_metadata_by_id($id = 0) { + $query = $this->db->query("SELECT * FROM `" . TABLE_META . "` WHERE id=?", array($id)); + if(isset($query->row['piler_id'])) { return $query->row; } + return ''; + } + + public function fix_subject($s = '') { if($s == '') { $s = 'nosubject'; } return preg_replace("/^\-{1,}/", "", preg_replace("/\W{1,}/", "-", $s));