mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-02-06 05:19:18 +01:00
* Mail: fix copy/move of mails between accounts
This commit is contained in:
parent
8a2a263f70
commit
106886756a
@ -3332,7 +3332,9 @@ class emailadmin_imapbase
|
|||||||
{
|
{
|
||||||
error_log(__METHOD__.__LINE__.' Error, could not flag messages in folder '.$folder.' Reason:'.$e->getMessage());
|
error_log(__METHOD__.__LINE__.' Error, could not flag messages in folder '.$folder.' Reason:'.$e->getMessage());
|
||||||
}
|
}
|
||||||
self::$folderStatusCache[$this->profileID][(!empty($_folder)?$_folder: $this->sessionData['mailbox'])]['uidValidity'] = 0;
|
if ($folder instanceof Horde_Imap_Client_Mailbox) $_folder = $folder->utf8;
|
||||||
|
//error_log(__METHOD__.__LINE__.'#'.$this->icServer->ImapServerId.'#'.array2string($_folder).'#');
|
||||||
|
self::$folderStatusCache[$this->icServer->ImapServerId][(!empty($_folder)?$_folder: $this->sessionData['mailbox'])]['uidValidity'] = 0;
|
||||||
|
|
||||||
//error_log(__METHOD__.' ('.__LINE__.') '.'->' .$_flag." ".array2string($_messageUID).",".($_folder?$_folder:$this->sessionData['mailbox']));
|
//error_log(__METHOD__.' ('.__LINE__.') '.'->' .$_flag." ".array2string($_messageUID).",".($_folder?$_folder:$this->sessionData['mailbox']));
|
||||||
return true; // as we do not catch/examine setFlags returnValue
|
return true; // as we do not catch/examine setFlags returnValue
|
||||||
@ -3347,48 +3349,54 @@ class emailadmin_imapbase
|
|||||||
* @param string $currentFolder
|
* @param string $currentFolder
|
||||||
* @param boolean $returnUIDs - control wether or not the action called should return the new uids
|
* @param boolean $returnUIDs - control wether or not the action called should return the new uids
|
||||||
* caveat: not all servers do support that
|
* caveat: not all servers do support that
|
||||||
* @param int $_targetProfileID - target profile ID, should only be handed over when target server is differen from source
|
* @param int $_sourceProfileID - source profile ID, should be handed over, if not $this->icServer->ImapServerId is used
|
||||||
|
* @param int $_targetProfileID - target profile ID, should only be handed over when target server is different from source
|
||||||
*
|
*
|
||||||
* @return mixed/bool true,false or new uid
|
* @return mixed/bool true,false or new uid
|
||||||
*/
|
*/
|
||||||
function moveMessages($_foldername, $_messageUID, $deleteAfterMove=true, $currentFolder = Null, $returnUIDs = false, $_targetProfileID = Null)
|
function moveMessages($_foldername, $_messageUID, $deleteAfterMove=true, $currentFolder = Null, $returnUIDs = false, $_sourceProfileID = Null, $_targetProfileID = Null)
|
||||||
{
|
{
|
||||||
$msglist = '';
|
$msglist = '';
|
||||||
|
$source = emailadmin_account::read(($_sourceProfileID?$_sourceProfileID:$this->icServer->ImapServerId))->imapServer();
|
||||||
$deleteOptions = $GLOBALS['egw_info']["user"]["preferences"]["mail"]["deleteOptions"];
|
$deleteOptions = $GLOBALS['egw_info']["user"]["preferences"]["mail"]["deleteOptions"];
|
||||||
if (empty($_messageUID))
|
if (empty($_messageUID))
|
||||||
{
|
{
|
||||||
if (self::$debug) error_log(__METHOD__." no messages Message(s): ".implode(',',$_messageUID));
|
if (self::$debug) error_log(__METHOD__." no Message(s): ".implode(',',$_messageUID));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
elseif ($_messageUID==='all')
|
elseif ($_messageUID==='all')
|
||||||
{
|
{
|
||||||
|
//error_log(__METHOD__." all Message(s): ".implode(',',$_messageUID));
|
||||||
$uidsToMove= null;
|
$uidsToMove= null;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
//error_log(__METHOD__." Message(s): ".implode(',',$_messageUID));
|
||||||
$uidsToMove = new Horde_Imap_Client_Ids();
|
$uidsToMove = new Horde_Imap_Client_Ids();
|
||||||
if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
|
if (!(is_object($_messageUID) || is_array($_messageUID))) $_messageUID = (array)$_messageUID;
|
||||||
$uidsToMove->add($_messageUID);
|
$uidsToMove->add($_messageUID);
|
||||||
}
|
}
|
||||||
$sourceFolder = (!empty($currentFolder)?$currentFolder: $this->sessionData['mailbox']);
|
$sourceFolder = (!empty($currentFolder)?$currentFolder: $this->sessionData['mailbox']);
|
||||||
if (!is_null($_targetProfileID) && $_targetProfileID !== $this->icServer->ImapServerId)
|
//error_log(__METHOD__.__LINE__."$_targetProfileID !== ".array2string($source->ImapServerId));
|
||||||
|
if (!is_null($_targetProfileID) && $_targetProfileID !== $source->ImapServerId)
|
||||||
{
|
{
|
||||||
$sourceFolder = $this->icServer->getMailbox($sourceFolder);
|
$sourceFolder = $source->getMailbox($sourceFolder);
|
||||||
$target = emailadmin_account::read($_targetProfileID)->imapServer();
|
$source->openMailbox($sourceFolder);
|
||||||
$foldername = $target->getMailbox($_foldername);
|
|
||||||
//error_log(__METHOD__.' ('.__LINE__.') '.' Sourceserver:'.$this->icServer->ImapServerId.' TargetServer:'.$_targetProfileID.' TargetFolderObject:'.array2string($foldername));
|
|
||||||
$this->icServer->openMailbox($sourceFolder);
|
|
||||||
$uidsToFetch = new Horde_Imap_Client_Ids();
|
$uidsToFetch = new Horde_Imap_Client_Ids();
|
||||||
$uidsToFetch->add($_messageUID);
|
$uidsToFetch->add($_messageUID);
|
||||||
|
|
||||||
$fquery = new Horde_Imap_Client_Fetch_Query();
|
$fquery = new Horde_Imap_Client_Fetch_Query();
|
||||||
$fquery->fullText(array('peek'=>true));
|
$fquery->fullText(array('peek'=>true));
|
||||||
$fquery->flags();
|
$fquery->flags();
|
||||||
$headersNew = $this->icServer->fetch($sourceFolder, $fquery, array(
|
$headersNew = $source->fetch($sourceFolder, $fquery, array(
|
||||||
'ids' => $uidsToFetch,
|
'ids' => $uidsToFetch,
|
||||||
));
|
));
|
||||||
|
//error_log(__METHOD__.' ('.__LINE__.') '.' Sourceserver:'.$source->ImapServerId.' mailheaders:'.array2string($headersNew));
|
||||||
|
|
||||||
if (is_object($headersNew)) {
|
if (is_object($headersNew)) {
|
||||||
|
$target = emailadmin_account::read($_targetProfileID)->imapServer();
|
||||||
|
$foldername = $target->getMailbox($_foldername);
|
||||||
|
//error_log(__METHOD__.' ('.__LINE__.') '.' Sourceserver:'.$source->ImapServerId.' TargetServer:'.$_targetProfileID.' TargetFolderObject:'.array2string($foldername));
|
||||||
$c=0;
|
$c=0;
|
||||||
$retUid = new Horde_Imap_Client_Ids();
|
$retUid = new Horde_Imap_Client_Ids();
|
||||||
// make sure the target folder is open and ready
|
// make sure the target folder is open and ready
|
||||||
@ -3397,9 +3405,10 @@ class emailadmin_imapbase
|
|||||||
foreach($headersNew as $id=>$_headerObject) {
|
foreach($headersNew as $id=>$_headerObject) {
|
||||||
$c++;
|
$c++;
|
||||||
$flags = $_headerObject->getFlags(); //unseen status seems to be lost when retrieving the full message
|
$flags = $_headerObject->getFlags(); //unseen status seems to be lost when retrieving the full message
|
||||||
|
//error_log(__METHOD__.' ('.__LINE__.') '.array2string($id));
|
||||||
//error_log(__METHOD__.' ('.__LINE__.') '.array2string($flags));
|
//error_log(__METHOD__.' ('.__LINE__.') '.array2string($flags));
|
||||||
$body = $_headerObject->getFullMsg();
|
$body = $_headerObject->getFullMsg();
|
||||||
$dataNflags[] = array('data'=>array(array('t'=>'text','v'=>"$body")), 'flags'=>$flags);
|
$dataNflags[] = array('data'=>$body, 'flags'=>$flags);
|
||||||
if ($c==5)
|
if ($c==5)
|
||||||
{
|
{
|
||||||
$ret = $target->append($foldername,$dataNflags);
|
$ret = $target->append($foldername,$dataNflags);
|
||||||
@ -3415,11 +3424,15 @@ class emailadmin_imapbase
|
|||||||
$retUid->add($ret);
|
$retUid->add($ret);
|
||||||
unset($dataNflags);
|
unset($dataNflags);
|
||||||
}
|
}
|
||||||
|
//error_log(__METHOD__.' ('.__LINE__.') '.array2string($retUid));
|
||||||
// make sure we are back to source
|
// make sure we are back to source
|
||||||
$this->icServer->openMailbox($sourceFolder);
|
$source->openMailbox($sourceFolder);
|
||||||
if ($deleteAfterMove)
|
if ($deleteAfterMove)
|
||||||
{
|
{
|
||||||
|
$remember = $this->icServer;
|
||||||
|
$this->icServer = $source;
|
||||||
$this->deleteMessages($_messageUID, $sourceFolder, $_forceDeleteMethod='remove_immediately');
|
$this->deleteMessages($_messageUID, $sourceFolder, $_forceDeleteMethod='remove_immediately');
|
||||||
|
$this->icServer = $remember;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3427,7 +3440,7 @@ class emailadmin_imapbase
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$retUid = $this->icServer->copy($sourceFolder, $_foldername, array('ids'=>$uidsToMove,'move'=>$deleteAfterMove));
|
$retUid = $source->copy($sourceFolder, $_foldername, array('ids'=>$uidsToMove,'move'=>$deleteAfterMove));
|
||||||
}
|
}
|
||||||
catch (exception $e)
|
catch (exception $e)
|
||||||
{
|
{
|
||||||
|
@ -4484,8 +4484,8 @@ class mail_ui
|
|||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//error_log(__METHOD__.__LINE__."->".print_r($messageList,true).' folder:'.$folder.' Method:'.$_forceDeleteMethod);
|
//error_log(__METHOD__.__LINE__."->".print_r($messageList,true).' folder:'.$folder.' Method:'.$_forceDeleteMethod.' '.$targetProfileID.'/'.$sourceProfileID);
|
||||||
$this->mail_bo->moveMessages($targetFolder,$messageList,($_copyOrMove=='copy'?false:true),$folder,false,($targetProfileID!=$sourceProfileID?$targetProfileID:null));
|
$this->mail_bo->moveMessages($targetFolder,$messageList,($_copyOrMove=='copy'?false:true),$folder,false,$sourceProfileID,($targetProfileID!=$sourceProfileID?$targetProfileID:null));
|
||||||
}
|
}
|
||||||
catch (egw_exception $e)
|
catch (egw_exception $e)
|
||||||
{
|
{
|
||||||
@ -4511,8 +4511,8 @@ class mail_ui
|
|||||||
}
|
}
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
//error_log(__METHOD__.__LINE__."->".print_r($messageList,true).' folder:'.$folder.' Method:'.$_forceDeleteMethod);
|
//error_log(__METHOD__.__LINE__."->".print_r($messageList,true).' folder:'.$folder.' Method:'.$_forceDeleteMethod.' '.$targetProfileID.'/'.$sourceProfileID);
|
||||||
$this->mail_bo->moveMessages($targetFolder,$messageList,($_copyOrMove=='copy'?false:true),$folder,false,($targetProfileID!=$sourceProfileID?$targetProfileID:null));
|
$this->mail_bo->moveMessages($targetFolder,$messageList,($_copyOrMove=='copy'?false:true),$folder,false,$sourceProfileID,($targetProfileID!=$sourceProfileID?$targetProfileID:null));
|
||||||
}
|
}
|
||||||
catch (egw_exception $e)
|
catch (egw_exception $e)
|
||||||
{
|
{
|
||||||
|
@ -2848,6 +2848,10 @@ app.classes.mail = AppJS.extend(
|
|||||||
messages['all'] = _allMessagesChecked;
|
messages['all'] = _allMessagesChecked;
|
||||||
if (messages['all']=='cancel') return false;
|
if (messages['all']=='cancel') return false;
|
||||||
if (messages['all']) messages['activeFilters'] = this.mail_getActiveFilters(_action);
|
if (messages['all']) messages['activeFilters'] = this.mail_getActiveFilters(_action);
|
||||||
|
|
||||||
|
// Make sure a default target folder is set in case of drop target is parent 0 (mail account name)
|
||||||
|
if (!target.match(/::/g)) target += '::INBOX';
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
egw.json('mail.mail_ui.ajax_copyMessages',[target, messages, 'move'], function(){self.unlock_tree();})
|
egw.json('mail.mail_ui.ajax_copyMessages',[target, messages, 'move'], function(){self.unlock_tree();})
|
||||||
.sendRequest();
|
.sendRequest();
|
||||||
|
Loading…
Reference in New Issue
Block a user