From e7f7d11fca91f784c2395e49f8dfa40e481c9bf1 Mon Sep 17 00:00:00 2001 From: vAugagneur Date: Tue, 21 Feb 2012 10:19:23 +0000 Subject: [PATCH] [-] BO : Customer Service options/sync mailbox not working - #PSFV-539 --- admin-dev/ajax.php | 33 +++++++++--- .../admin/AdminCustomerThreadsController.php | 54 +++++++++++++------ 2 files changed, 63 insertions(+), 24 deletions(-) diff --git a/admin-dev/ajax.php b/admin-dev/ajax.php index acb689d18..07aadb4d4 100644 --- a/admin-dev/ajax.php +++ b/admin-dev/ajax.php @@ -637,16 +637,35 @@ if (Tools::isSubmit('updateElementEmployee') && Tools::getValue('updateElementEm if (Tools::isSubmit('syncImapMail')) { - if (!$url = Configuration::get('PS_SAV_IMAP_URL') - || !$port = Configuration::get('PS_SAV_IMAP_PORT') - || !$user = Configuration::get('PS_SAV_IMAP_USER') - || !$password = Configuration::get('PS_SAV_IMAP_PWD')) + if (!($url = Configuration::get('PS_SAV_IMAP_URL')) + || !($port = Configuration::get('PS_SAV_IMAP_PORT')) + || !($user = Configuration::get('PS_SAV_IMAP_USER')) + || !($password = Configuration::get('PS_SAV_IMAP_PWD'))) die('{"hasError" : true, "errors" : ["Configuration is not correct"]}'); + $conf = Configuration::getMultiple(array( + 'PS_SAV_IMAP_OPT_NORSH', 'PS_SAV_IMAP_OPT_SSL', + 'PS_SAV_IMAP_OPT_VALIDATE-CERT', 'PS_SAV_IMAP_OPT_NOVALIDATE-CERT', + 'PS_SAV_IMAP_OPT_TLS', 'PS_SAV_IMAP_OPT_NOTLS')); + + $conf_str = ''; + if ($conf['PS_SAV_IMAP_OPT_NORSH']) + $conf_str .= '/norsh'; + if ($conf['PS_SAV_IMAP_OPT_SSL']) + $conf_str .= '/ssl'; + if ($conf['PS_SAV_IMAP_OPT_VALIDATE-CERT']) + $conf_str .= '/validate-cert'; + if ($conf['PS_SAV_IMAP_OPT_NOVALIDATE-CERT']) + $conf_str .= '/novalidate-cert'; + if ($conf['PS_SAV_IMAP_OPT_TLS']) + $conf_str .= '/tls'; + if ($conf['PS_SAV_IMAP_OPT_NOTLS']) + $conf_str .= '/notls'; + if (!function_exists('imap_open')) die('{"hasError" : true, "errors" : ["imap is not installed on this server"]}'); - $mbox = @imap_open('{'.$url.':'.$port.(Configuration::get('PS_SAV_IMAP_OPT') ? Configuration::get('PS_SAV_IMAP_OPT') : '').'}', $user, $password); + $mbox = @imap_open('{'.$url.':'.$port.$conf_str.'}', $user, $password); //checks if there is no error when connecting imap server $errors = imap_errors(); @@ -666,7 +685,7 @@ if (Tools::isSubmit('syncImapMail')) //Returns information about the current mailbox. Returns FALSE on failure. $check = imap_check($mbox); - if ($check) + if (!$check) die('{"hasError" : true, "errors" : ["Fail to get information about the current mailbox"]}'); if ($check->Nmsgs == 0) @@ -717,7 +736,7 @@ if (Tools::isSubmit('syncImapMail')) } imap_expunge($mbox); imap_close($mbox); - die('{"hasError" : false, "errors" : '.$str_errors.$str_errors_delete.'"]}'); + die('{"hasError" : false, "errors" : ["'.$str_errors.$str_error_delete.'"]}'); } /* Modify attribute position */ diff --git a/controllers/admin/AdminCustomerThreadsController.php b/controllers/admin/AdminCustomerThreadsController.php index 53e32eee8..0f3c16e51 100644 --- a/controllers/admin/AdminCustomerThreadsController.php +++ b/controllers/admin/AdminCustomerThreadsController.php @@ -161,28 +161,48 @@ class AdminCustomerThreadsControllerCore extends AdminController 'size' => 40, 'visibility' => Shop::CONTEXT_ALL, ), - 'PS_SAV_IMAP_OPT' => array( - 'title' => $this->l('Imap option'), - 'type' => 'select', - 'select_multiple' => true, - 'size' => 6, - 'visibility' => Shop::CONTEXT_ALL, - 'identifier' => 'value', - 'list' => array( - '0' => array('value' => '/norsh', 'name' => $this->l('Do not use rsh or ssh to establish a preauthenticated IMAP session').' /norsh'), - '1' => array('value' => '/ssl', 'name' => $this->l('Use the Secure Socket Layer to encrypt the session').' /ssl '), - '2' => array('value' => '/validate-cert', 'name' => $this->l('Validate certificates from TLS/SSL server').' /validate-cert'), - '3' => array('value' => '/novalidate-cert', 'name' => $this->l('Do not validate certificates from TLS/SSL server, needed if server uses self-signed certificates').' /novalidate-cert'), - '4' => array('value' => '/tls', 'name' => $this->l('Force use of start-TLS to encrypt the session, and reject connection to servers that do not support it').' /tls'), - '5' => array('value' => '/notls', 'name' => $this->l('do not do start-TLS to encrypt the session, even with servers that support it').' /notls') - ), - ), 'PS_SAV_IMAP_DELETE_MSG' => array( 'title' => $this->l('Deletes messages'), 'desc' => $this->l('Deletes message after sync. If you do not active this option, the sync will be longer'), 'type' => 'bool', 'visibility' => Shop::CONTEXT_ALL, - ) + ), + 'PS_SAV_IMAP_OPT_NORSH' => array( + 'title' => $this->l('Imap option').' (/norsh)', + 'type' => 'bool', + 'desc' => $this->l('Do not use rsh or ssh to establish a preauthenticated IMAP session'), + 'visibility' => Shop::CONTEXT_ALL, + ), + 'PS_SAV_IMAP_OPT_SSL' => array( + 'title' => $this->l('Imap option').' (/ssl)', + 'type' => 'bool', + 'desc' => $this->l('Use the Secure Socket Layer to encrypt the session'), + 'visibility' => Shop::CONTEXT_ALL, + ), + 'PS_SAV_IMAP_OPT_VALIDATE-CERT' => array( + 'title' => $this->l('Imap option').' (/validate-cert)', + 'type' => 'bool', + 'desc' => $this->l('Validate certificates from TLS/SSL server'), + 'visibility' => Shop::CONTEXT_ALL, + ), + 'PS_SAV_IMAP_OPT_NOVALIDATE-CERT' => array( + 'title' => $this->l('Imap option').' (/novalidate-cert)', + 'type' => 'bool', + 'desc' => $this->l('Do not validate certificates from TLS/SSL server, needed if server uses self-signed certificates'), + 'visibility' => Shop::CONTEXT_ALL, + ), + 'PS_SAV_IMAP_OPT_TLS' => array( + 'title' => $this->l('Imap option').' (/tls)', + 'type' => 'bool', + 'desc' => $this->l('Force use of start-TLS to encrypt the session, and reject connection to servers that do not support it'), + 'visibility' => Shop::CONTEXT_ALL, + ), + 'PS_SAV_IMAP_OPT_NOTLS' => array( + 'title' => $this->l('Imap option').' (/notls)', + 'type' => 'bool', + 'desc' => $this->l('do not do start-TLS to encrypt the session, even with servers that support it'), + 'visibility' => Shop::CONTEXT_ALL, + ), ), 'submit' => array('title' => $this->l('Save'), 'class' => 'button'), ),