mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-22 16:03:47 +01:00
Make spam actions available on multiple entries
This commit is contained in:
parent
e2883e2387
commit
09e9b47c9d
@ -881,19 +881,23 @@ class mail_ui
|
|||||||
* Method to execute spam actions
|
* Method to execute spam actions
|
||||||
*
|
*
|
||||||
* @param type $_action action id
|
* @param type $_action action id
|
||||||
* @param type $_params
|
* @param type $_items
|
||||||
*/
|
*/
|
||||||
public function ajax_spamAction($_action, $_params)
|
public function ajax_spamAction($_action, $_items)
|
||||||
{
|
{
|
||||||
$msg = array();
|
$msg = array();
|
||||||
$refresh = false;
|
$refresh = false;
|
||||||
$response = Api\Json\Response::get();
|
$response = Api\Json\Response::get();
|
||||||
|
// Check active profile and change it if it's neccessary
|
||||||
$id_parts = self::splitRowID($_params['row_id']);
|
if (is_array($_items[0]))
|
||||||
|
{
|
||||||
|
$id_parts = self::splitRowID($_items[0]['row_id']);
|
||||||
if ($id_parts['profileID'] && $id_parts['profileID'] != $this->mail_bo->profileID)
|
if ($id_parts['profileID'] && $id_parts['profileID'] != $this->mail_bo->profileID)
|
||||||
{
|
{
|
||||||
$this->changeProfile($id_parts['profileID']);
|
$this->changeProfile($id_parts['profileID']);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$delimiter = $this->mail_bo->getHierarchyDelimiter();
|
$delimiter = $this->mail_bo->getHierarchyDelimiter();
|
||||||
// Ham folder
|
// Ham folder
|
||||||
$ham = $this->mail_bo->profileID.self::$delimiter.$this->mail_bo->icServer->acc_folder_ham;
|
$ham = $this->mail_bo->profileID.self::$delimiter.$this->mail_bo->icServer->acc_folder_ham;
|
||||||
@ -901,49 +905,60 @@ class mail_ui
|
|||||||
$junk = $this->mail_bo->profileID.self::$delimiter.$this->mail_bo->getJunkFolder();
|
$junk = $this->mail_bo->profileID.self::$delimiter.$this->mail_bo->getJunkFolder();
|
||||||
// Inbox folder
|
// Inbox folder
|
||||||
$inbox = $this->mail_bo->profileID.self::$delimiter.'INBOX';
|
$inbox = $this->mail_bo->profileID.self::$delimiter.'INBOX';
|
||||||
|
|
||||||
|
$messages = array();
|
||||||
|
|
||||||
|
foreach ($_items as &$params)
|
||||||
|
{
|
||||||
|
$id_parts = self::splitRowID($params['row_id']);
|
||||||
// Current Mailbox
|
// Current Mailbox
|
||||||
$mailbox = $id_parts['folder'];
|
$mailbox = $id_parts['folder'];
|
||||||
|
$messages[] = $params['row_id'];
|
||||||
if ($GLOBALS['egw_info']['apps']['stylite'])
|
if ($GLOBALS['egw_info']['apps']['stylite'])
|
||||||
{
|
{
|
||||||
$_params['mailbody'] = $this->get_load_email_data($_params['uid'], null, $mailbox);
|
$params['mailbody'] = $this->get_load_email_data($params['uid'], null, $mailbox);
|
||||||
$msg[] = stylite_mail_spamtitan::execAction($_action, $_params, array(
|
}
|
||||||
'userpwd' => $this->mail_bo->icServer->acc_imap_password,
|
|
||||||
'user' => $this->mail_bo->icServer->acc_imap_username,
|
|
||||||
'api_url' => $this->mail_bo->icServer->acc_spam_api
|
|
||||||
));
|
|
||||||
}
|
}
|
||||||
switch ($_action)
|
switch ($_action)
|
||||||
{
|
{
|
||||||
case 'spam':
|
case 'spam':
|
||||||
$this->ajax_copyMessages($junk, array(
|
$msg[] = $this->ajax_copyMessages($junk, array(
|
||||||
'all' => false,
|
'all' => false,
|
||||||
'msg' => array($_params['row_id'])
|
'msg' => $messages
|
||||||
), 'move');
|
), 'move', null, true);
|
||||||
$refresh = true;
|
$refresh = true;
|
||||||
break;
|
break;
|
||||||
case 'ham':
|
case 'ham':
|
||||||
if (isset($this->mail_bo->icServer->acc_folder_ham) && !isset($this->mail_bo->icServer->acc_spam_api))
|
if (isset($this->mail_bo->icServer->acc_folder_ham) && !isset($this->mail_bo->icServer->acc_spam_api))
|
||||||
{
|
{
|
||||||
$this->ajax_copyMessages($ham, array(
|
$msg[] = $this->ajax_copyMessages($ham, array(
|
||||||
'all' => false,
|
'all' => false,
|
||||||
'msg' => array($_params['row_id'])
|
'msg' => $messages
|
||||||
), 'copy');
|
), 'copy', null, true);
|
||||||
}
|
}
|
||||||
// Move mails to Inbox if they are in Junk folder
|
// Move mails to Inbox if they are in Junk folder
|
||||||
if ($junk == $this->mail_bo->profileID.self::$delimiter.$mailbox)
|
if ($junk == $this->mail_bo->profileID.self::$delimiter.$mailbox)
|
||||||
{
|
{
|
||||||
$this->ajax_copyMessages($inbox, array(
|
$msg[] = $this->ajax_copyMessages($inbox, array(
|
||||||
'all' => false,
|
'all' => false,
|
||||||
'msg' => array($_params['row_id'])
|
'msg' => $messages
|
||||||
), 'move');
|
), 'move', null, true);
|
||||||
$refresh = true;
|
$refresh = true;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
if ($GLOBALS['egw_info']['apps']['stylite'])
|
||||||
|
{
|
||||||
|
stylite_mail_spamtitan::setActionItems($_action, $_items, array(
|
||||||
|
'userpwd' => $this->mail_bo->icServer->acc_imap_password,
|
||||||
|
'user' => $this->mail_bo->icServer->acc_imap_username,
|
||||||
|
'api_url' => $this->mail_bo->icServer->acc_spam_api
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
if ($refresh)
|
if ($refresh)
|
||||||
{
|
{
|
||||||
$response->apply('egw.refresh',[implode('\n',$msg),'mail',$_params['row_id'],'delete']);
|
$response->data([implode('\n',$msg),$messages]);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -962,20 +977,21 @@ class mail_ui
|
|||||||
'spamfilter' => array (
|
'spamfilter' => array (
|
||||||
'caption' => 'Spam',
|
'caption' => 'Spam',
|
||||||
'icon' => 'dhtmlxtree/MailFolderJunk',
|
'icon' => 'dhtmlxtree/MailFolderJunk',
|
||||||
|
'allowOnMultiple' => true,
|
||||||
'children' => array (
|
'children' => array (
|
||||||
'spam' => array (
|
'spam' => array (
|
||||||
'caption' => 'Report as Spam',
|
'caption' => 'Report as Spam',
|
||||||
'icon' => 'dhtmlxtree/MailFolderJunk',
|
'icon' => 'dhtmlxtree/MailFolderJunk',
|
||||||
'onExecute' => 'javaScript:app.mail.spam_actions',
|
'onExecute' => 'javaScript:app.mail.spam_actions',
|
||||||
'hint' => 'Report this email content as Spam - spam solutions like spamTitan will learn',
|
'hint' => 'Report this email content as Spam - spam solutions like spamTitan will learn',
|
||||||
'allowOnMultiple' => false
|
'allowOnMultiple' => true
|
||||||
),
|
),
|
||||||
'ham' => array (
|
'ham' => array (
|
||||||
'caption' => 'Report as Ham',
|
'caption' => 'Report as Ham',
|
||||||
'icon' => 'dhtmlxtree/MailFolderHam',
|
'icon' => 'dhtmlxtree/MailFolderHam',
|
||||||
'onExecute' => 'javaScript:app.mail.spam_actions',
|
'onExecute' => 'javaScript:app.mail.spam_actions',
|
||||||
'hint' => 'Report this email content as Ham (not spam) - spam solutions like spamTitan will learn',
|
'hint' => 'Report this email content as Ham (not spam) - spam solutions like spamTitan will learn',
|
||||||
'allowOnMultiple' => false
|
'allowOnMultiple' => true
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@ -5122,10 +5138,12 @@ $filter['before']= date("d-M-Y", $cutoffdate2);
|
|||||||
* @param array _messageList list of UID's
|
* @param array _messageList list of UID's
|
||||||
* @param string _copyOrMove method to use copy or move allowed
|
* @param string _copyOrMove method to use copy or move allowed
|
||||||
* @param string _move2ArchiveMarker marker to indicate if a move 2 archive was triggered
|
* @param string _move2ArchiveMarker marker to indicate if a move 2 archive was triggered
|
||||||
|
* @param boolean _return if true the function will return the result instead of
|
||||||
|
* responding to client
|
||||||
*
|
*
|
||||||
* @return xajax response
|
* @return xajax response
|
||||||
*/
|
*/
|
||||||
function ajax_copyMessages($_folderName, $_messageList, $_copyOrMove='copy', $_move2ArchiveMarker='_')
|
function ajax_copyMessages($_folderName, $_messageList, $_copyOrMove='copy', $_move2ArchiveMarker='_', $_return = false)
|
||||||
{
|
{
|
||||||
if(Mail::$debug) error_log(__METHOD__."->".$_folderName.':'.print_r($_messageList,true).' Method:'.$_copyOrMove.' ArchiveMarker:'.$_move2ArchiveMarker);
|
if(Mail::$debug) error_log(__METHOD__."->".$_folderName.':'.print_r($_messageList,true).' Method:'.$_copyOrMove.' ArchiveMarker:'.$_move2ArchiveMarker);
|
||||||
Api\Translation::add_app('mail');
|
Api\Translation::add_app('mail');
|
||||||
@ -5292,17 +5310,22 @@ $filter['before']= date("d-M-Y", $cutoffdate2);
|
|||||||
unset($lastFoldersUsedForMoveCont[$targetProfileID][$targetFolder]);
|
unset($lastFoldersUsedForMoveCont[$targetProfileID][$targetFolder]);
|
||||||
$changeFolderActions = true;
|
$changeFolderActions = true;
|
||||||
}
|
}
|
||||||
|
if ($_return) return $error;
|
||||||
$response->call('egw.message',$error,"error");
|
$response->call('egw.message',$error,"error");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if ($_copyOrMove=='copy')
|
if ($_copyOrMove=='copy')
|
||||||
{
|
{
|
||||||
$response->call('egw.message',lang('copied %1 message(s) from %2 to %3',($messageList=='all'||$_messageList['all']?($filtered?lang('all filtered'):lang('all')):count($messageList)),$folder,$targetFolder));
|
$msg = lang('copied %1 message(s) from %2 to %3',($messageList=='all'||$_messageList['all']?($filtered?lang('all filtered'):lang('all')):count($messageList)),$folder,$targetFolder);
|
||||||
|
if ($_return) return $msg;
|
||||||
|
$response->call('egw.message',$msg);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$response->call('egw.refresh',lang('moved %1 message(s) from %2 to %3',($messageList=='all'||$_messageList['all']?($filtered?lang('all filtered'):lang('all')):count($messageList)),$folder,$targetFolder),'mail',$messageListForRefresh,'delete');
|
$msg = lang('moved %1 message(s) from %2 to %3',($messageList=='all'||$_messageList['all']?($filtered?lang('all filtered'):lang('all')):count($messageList)),$folder,$targetFolder);
|
||||||
|
if ($_return) return $msg;
|
||||||
|
$response->call('egw.refresh',$msg,'mail',$messageListForRefresh,'delete');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($changeFolderActions == true)
|
if ($changeFolderActions == true)
|
||||||
|
@ -5484,31 +5484,46 @@ app.classes.mail = AppJS.extend(
|
|||||||
* @param {object} _action egw action
|
* @param {object} _action egw action
|
||||||
* @param {object} _sender nm row
|
* @param {object} _sender nm row
|
||||||
*/
|
*/
|
||||||
spam_actions: function (_action, _sender)
|
spam_actions: function (_action, _senders)
|
||||||
{
|
{
|
||||||
var id = '';
|
var id,fromaddress,domain, email = '';
|
||||||
if (_sender.length == 0)
|
var data = {};
|
||||||
|
var items = [];
|
||||||
|
|
||||||
|
// called action for a single row from toolbar
|
||||||
|
if (_senders.length == 0)
|
||||||
{
|
{
|
||||||
var nm = this.et2.getWidgetById(this.nm_index);
|
var nm = this.et2.getWidgetById(this.nm_index);
|
||||||
id = nm.getSelection().ids[0];
|
_senders[0]['id'] = nm.getSelection().ids[0];
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
for (var i in _senders)
|
||||||
id = _sender[0].id;
|
|
||||||
}
|
|
||||||
var data = egw.dataGetUIDdata(id);
|
|
||||||
var fromaddress = data.data.fromaddress.match(/<([^\'\" <>]+)>$/);
|
|
||||||
var email = (fromaddress && fromaddress[1])?fromaddress[1]:data.data.fromaddress;
|
|
||||||
var domain = '@'+email.split('@')[1];
|
|
||||||
this.egw.json('mail.mail_ui.ajax_spamAction', [
|
|
||||||
_action.id,
|
|
||||||
{
|
{
|
||||||
|
id = _senders[i].id;
|
||||||
|
data = egw.dataGetUIDdata(id);
|
||||||
|
fromaddress = data.data.fromaddress.match(/<([^\'\" <>]+)>$/);
|
||||||
|
email = (fromaddress && fromaddress[1])?fromaddress[1]:data.data.fromaddress;
|
||||||
|
domain = '@'+email.split('@')[1];
|
||||||
|
items[i] = {
|
||||||
'acc_id':id.split('::')[2],
|
'acc_id':id.split('::')[2],
|
||||||
'row_id':data.data.row_id,
|
'row_id':data.data.row_id,
|
||||||
'uid': data.data.uid,
|
'uid': data.data.uid,
|
||||||
'sender': _action.id.match(/domain/)? domain : email
|
'sender': _action.id.match(/domain/)? domain : email
|
||||||
|
};
|
||||||
}
|
}
|
||||||
]).sendRequest(true);
|
|
||||||
|
this.egw.json('mail.mail_ui.ajax_spamAction', [
|
||||||
|
_action.id,items
|
||||||
|
], function(_data){
|
||||||
|
if (_data[1] && _data[1].length > 0)
|
||||||
|
{
|
||||||
|
egw.refresh(_data[0],'mail',_data[1],'delete');
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
egw.message(_data[0]);
|
||||||
|
}
|
||||||
|
}).sendRequest(true);
|
||||||
},
|
},
|
||||||
|
|
||||||
spamTitan_setActionTitle: function (_action, _sender)
|
spamTitan_setActionTitle: function (_action, _sender)
|
||||||
@ -5516,8 +5531,8 @@ app.classes.mail = AppJS.extend(
|
|||||||
var id = _sender[0].id;
|
var id = _sender[0].id;
|
||||||
var data = egw.dataGetUIDdata(id);
|
var data = egw.dataGetUIDdata(id);
|
||||||
var fromaddress = data.data.fromaddress.match(/<([^\'\" <>]+)>$/);
|
var fromaddress = data.data.fromaddress.match(/<([^\'\" <>]+)>$/);
|
||||||
var email = (fromaddress && fromaddress[1]) ?fromaddress[1]:data.data.fromaddress;
|
var email = _sender.length>1? this.egw.lang('emails'):(fromaddress && fromaddress[1]) ?fromaddress[1]:data.data.fromaddress;
|
||||||
var domain = email.split('@')[1];
|
var domain = _sender.length>1? this.egw.lang('domains'):email.split('@')[1];
|
||||||
switch (_action.id)
|
switch (_action.id)
|
||||||
{
|
{
|
||||||
case 'whitelist_email_add':
|
case 'whitelist_email_add':
|
||||||
|
Loading…
Reference in New Issue
Block a user