This commit is contained in:
vAugagneur
2011-09-22 15:46:42 +00:00
parent 2180359342
commit 1803db6aab
3 changed files with 43 additions and 25 deletions
+28 -15
View File
@@ -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 */
+11 -6
View File
@@ -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
</div>
</fieldset><br/>
<script type="text/javascript">
var ajaxQueries = new Array();
function run_sync () {
$(\'#ajax_error\').html(\'\');
$(\'#ajax_error\').hide();
$(\'#ajax_conf\').html(\'\');
$(\'#ajax_conf\').hide();
for(i = 0; i < ajaxQueries.length; i++)
ajaxQueries[i].abort();
ajaxQueries = new Array();
$(\'#ajax_loader\').html(\'<img src="'._PS_ADMIN_IMG_.'ajax-loader.gif">\');
$.ajax({
ajaxQuery = $.ajax({
type: "POST",
url: "ajax.php",
data: "syncImapMail=1",
@@ -660,7 +664,7 @@ class AdminCustomerThreads extends AdminTab
jsonError = \'\';
if (jsonData.hasError)
{
for (i=0;i<jsonData.errors.length;i++)
for (i=0;i < jsonData.errors.length;i++)
jsonError = jsonError+\'<li>\'+jsonData.errors[i]+\'</li>\';
$(\'#ajax_error\').html(\'<ul>\'+jsonError+\'</ul>\');
$(\'#ajax_error\').fadeIn();
@@ -668,7 +672,7 @@ class AdminCustomerThreads extends AdminTab
else
{
jsonError = \'<li>'.$this->l('Sync success').'</li>\';
for (i=0;i<jsonData.errors.length;i++)
for (i=0;i < jsonData.errors.length;i++)
jsonError = jsonError+\'<li>\'+jsonData.errors[i]+\'</li>\';
$(\'#ajax_conf\').html(\'<ul>\'+jsonError+\'</ul>\');
$(\'#ajax_conf\').fadeIn();
@@ -677,9 +681,10 @@ class AdminCustomerThreads extends AdminTab
$(\'#ajax_loader\').html(\'\');
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
alert("TECHNICAL ERROR: unable to refresh the cart.\n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + \'Text status: \' + textStatus);
alert("TECHNICAL ERROR: unable to sync.\n\nDetails:\nError thrown: " + XMLHttpRequest + "\n" + \'Text status: \' + textStatus);
}
});
ajaxQueries.push(ajaxQuery);
};
</script>';