From 1803db6aabfe7db587fe7729a86c6b74dcd32849 Mon Sep 17 00:00:00 2001 From: vAugagneur Date: Thu, 22 Sep 2011 15:46:42 +0000 Subject: [PATCH] // --- admin-dev/ajax.php | 43 ++++++++++++++++--------- admin-dev/tabs/AdminCustomerThreads.php | 17 ++++++---- translations/fr/admin.php | 8 ++--- 3 files changed, 43 insertions(+), 25 deletions(-) diff --git a/admin-dev/ajax.php b/admin-dev/ajax.php index b2ac42f51..ee25cf7b3 100644 --- a/admin-dev/ajax.php +++ b/admin-dev/ajax.php @@ -729,23 +729,34 @@ if (Tools::isSubmit('syncImapMail')) OR !$port = Configuration::get('PS_SAV_IMAP_PORT') OR !$user = Configuration::get('PS_SAV_IMAP_USER') OR !$password = Configuration::get('PS_SAV_IMAP_PWD')) - die('{"hasError" : true, "errors" : "Configuration is not correct"}'); - + die('{"hasError" : true, "errors" : ["Configuration is not correct"]}'); + + if (!function_exists('imap_open')) + die('{"hasError" : true, "errors" : ["imap is not installed on this server"]}'); + $mbox = @imap_open('{'.$url.':'.$port.'}', $user, $password); - + + //checks if there is no error when connecting imap server $errors = imap_errors(); + $str_errors = ''; + $str_error_delete = ''; if (sizeof($errors)) { $str_errors = '["'; foreach($errors as $error) - $str_errors .= $error.','; - $str_errors = rtrim($str_errors, ',').'"]'; + $str_errors .= '"'.$error.'",'; + $str_errors = rtrim($str_errors, ',').''; } + + //checks if imap connexion is active if (!$mbox) - die('{"hasError" : true, "errors" : ["Can not connect to the mailbox"]}'); - + die('{"hasError" : true, "errors" : ["Cannot connect to the mailbox"]}'); + + //Returns information about the current mailbox. Returns FALSE on failure. $check = imap_check($mbox); - + if ($check) + die('{"hasError" : true, "errors" : ["Fail to get information about the current mailbox"]}'); + if ($check->Nmsgs == 0) die('{"hasError" : true, "errors" : ["NO message to sync"]}'); @@ -757,16 +768,18 @@ if (Tools::isSubmit('syncImapMail')) $subject = $overview->subject; else $subject = ''; - - $md5 = md5($overview->date.$overview->from.$subject); + + //Creating an md5 to check if message has been allready processed + $md5 = md5($overview->date.$overview->from.$subject.$overview->msgno); $exist = Db::getInstance()->getValue( - 'SELECT md5_header + 'SELECT `md5_header` FROM `'._DB_PREFIX_.'customer_message_sync_imap` - WHERE md5_header = \''.pSQL($md5).'\''); + WHERE `md5_header` = \''.pSQL($md5).'\''); if ($exist) { if (Configuration::get('PS_SAV_IMAP_DELETE_MSG')) - imap_delete($mbox, $overview->msgno); + if (!imap_delete($mbox, $overview->msgno)) + $str_error_delete = ', "Fail to delete message"'; } else { @@ -787,12 +800,12 @@ if (Tools::isSubmit('syncImapMail')) $cm->add(); } } - Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'customer_message_sync_imap` VALUES (\''.pSQL($md5).'\')'); + Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'customer_message_sync_imap` (`md5_header`) VALUES (\''.pSQL($md5).'\')'); } } imap_expunge($mbox); imap_close($mbox); - die('{"hasError" : false, "errors" : '.$str_errors.'}'); + die('{"hasError" : false, "errors" : '.$str_errors.$str_errors_delete.'"]}'); } /* Modify attribute position */ diff --git a/admin-dev/tabs/AdminCustomerThreads.php b/admin-dev/tabs/AdminCustomerThreads.php index 8ef4282d1..7b2646206 100644 --- a/admin-dev/tabs/AdminCustomerThreads.php +++ b/admin-dev/tabs/AdminCustomerThreads.php @@ -94,7 +94,7 @@ class AdminCustomerThreads extends AdminTab 'PS_SAV_IMAP_PORT' => array('title' => $this->l('Imap port'), 'desc' => $this->l('Port to use to connect imap server'), 'type' => 'text', 'defaultValue' => 143, 'visibility' => Shop::CONTEXT_ALL), 'PS_SAV_IMAP_USER' => array('title' => $this->l('Imap user'), 'desc' => $this->l('User to use to connect imap server'), 'type' => 'text', 'size' => 40, 'visibility' => Shop::CONTEXT_ALL), 'PS_SAV_IMAP_PWD' => array('title' => $this->l('Imap password'), 'desc' => $this->l('Password to use to connect imap server'), 'type' => 'text', 'size' => 40, 'visibility' => Shop::CONTEXT_ALL), - 'PS_SAV_IMAP_DELETE_MSG' => array('title' => $this->l('Delete messages'), 'desc' => $this->l('Deletes message after sync. If you do not active this option, the sync will be longer'), 'cast' => 'intval', 'type' => 'select', 'identifier' => 'value', 'list' => array( + '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'), 'cast' => 'intval', 'type' => 'select', 'identifier' => 'value', 'list' => array( '0' => array('value' => 0, 'name' => $this->l('No')), '1' => array('value' => 1, 'name' => $this->l('Yes')) ), 'visibility' => Shop::CONTEXT_ALL) @@ -196,6 +196,7 @@ class AdminCustomerThreads extends AdminTab '{reply}' => Tools::nl2br(Tools::getValue('reply_message')), '{link}' => Tools::url($this->context->link->getPageLink('contact', true), 'id_customer_thread='.(int)($ct->id).'&token='.$ct->token), ); + //#ct == id_customer_thread #tc == token of thread <== used in the synchronization imap if (Mail::Send($ct->id_lang, 'reply_msg', Mail::l('An answer to your message is available').' #ct'.$ct->id.'#tc'.$ct->token, $params, Tools::getValue('msg_email'), NULL, NULL, NULL, $fileAttachment, NULL, _PS_MAIL_DIR_, true)) @@ -644,14 +645,17 @@ class AdminCustomerThreads extends AdminTab
'; diff --git a/translations/fr/admin.php b/translations/fr/admin.php index 823f49b03..bc0e50159 100644 --- a/translations/fr/admin.php +++ b/translations/fr/admin.php @@ -560,11 +560,11 @@ $_LANGADM['AdminCustomerThreadsa81b40d671a82de3bc3550b878234dd6'] = 'Url pour le $_LANGADM['AdminCustomerThreadscd16a15c486d2e183732556f779968c9'] = 'Port IMAP'; $_LANGADM['AdminCustomerThreads8a29ff48f49ffe61e4e886a04cff2eb6'] = 'Port à utiliser pour se connecter le serveur imap'; $_LANGADM['AdminCustomerThreads678b57a794c6976ac961df8a32394def'] = 'Utilisateur IMAP'; -$_LANGADM['AdminCustomerThreads0882db19e4fce8cbaff75c9dc2fb1166'] = 'L\'utilisateur à utiliser pour se connecter le serveur IMAP'; +$_LANGADM['AdminCustomerThreads0882db19e4fce8cbaff75c9dc2fb1166'] = 'Utilisateur pour se connecter le serveur IMAP'; $_LANGADM['AdminCustomerThreads22e38bd8ea7e850765045720e0b9cf5d'] = 'Mot de passe IMAP'; $_LANGADM['AdminCustomerThreadsa5bf021c18a4c0891b491c07d3555b86'] = 'Mot de passe à utiliser pour se connecter le serveur IMAP'; -$_LANGADM['AdminCustomerThreadsca7e64e3f55ef8e0f50818d8117d26cc'] = 'Supprimer des messages'; -$_LANGADM['AdminCustomerThreadsbbd8156a324aee57b7186991acf82d0d'] = 'Supprime le message après la synchronisation. Si vous n\'avez pas active cette option, la synchronisation sera plus long'; +$_LANGADM['AdminCustomerThreadsfaa07c5eadea7dd34bfc379d7bfd7c67'] = 'Supprime les messages'; +$_LANGADM['AdminCustomerThreadsbbd8156a324aee57b7186991acf82d0d'] = 'Supprime le message après la synchronisation. Si vous n\'avez pas activée cette option, la synchronisation sera plus longue'; $_LANGADM['AdminCustomerThreadsbafd7322c6e97d25b6299b5d6fe8920b'] = 'Non'; $_LANGADM['AdminCustomerThreads93cba07454f06a4a960172bbd6e2a435'] = 'Oui'; $_LANGADM['AdminCustomerThreadsd21b5a78517318e6d35414d4217950ce'] = 'Message transmis à'; @@ -628,7 +628,7 @@ $_LANGADM['AdminCustomerThreads694e8d1f2ee056f98ee488bdc4982d73'] = 'Quantité'; $_LANGADM['AdminCustomerThreadsd8e87c0927539672f54462c837be0b7f'] = 'Synchroniser'; $_LANGADM['AdminCustomerThreadsa19330a6fc36ebae6683cc023e295687'] = 'Exécutez la synchronisation'; $_LANGADM['AdminCustomerThreads22009610f18142abea939bc2f1836a81'] = 'Cliquez pour synchroniser les mails automatiquement'; -$_LANGADM['AdminCustomerThreads1e65b02f3464a517e0946a46d496327c'] = 'Synchronisation avec succès'; +$_LANGADM['AdminCustomerThreads1e65b02f3464a517e0946a46d496327c'] = 'Synchronisation effectué avec succès'; $_LANGADM['AdminCustomersd1457b72c3fb323a2671125aef3eab5d'] = '?'; $_LANGADM['AdminCustomersb718adec73e04ce3ec720dd11a06a308'] = 'ID'; $_LANGADM['AdminCustomers019ec3132cdf8ee0f2e2a75cf5d3e459'] = 'Sexe';