mirror of
https://github.com/EGroupware/egroupware.git
synced 2024-11-22 16:03:47 +01:00
moving async job stuff to mail app and storing mail and user account in async job
This commit is contained in:
parent
02db5d0357
commit
6c1ac892fb
@ -1,46 +0,0 @@
|
||||
<?php
|
||||
/**
|
||||
* EGroupware EMail - timed vacation
|
||||
*
|
||||
* @link http://www.stylite.de
|
||||
* @package mail
|
||||
* @author Ralf Becker <rb@stylite.de>
|
||||
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
||||
* @version $Id$
|
||||
*/
|
||||
|
||||
/**
|
||||
* Class containing callback to set/reset vacation notice in future (timed vacation)
|
||||
*
|
||||
* Rest of class is moved to emailadmin_sieve and accessible via incomming server object (IMAP).
|
||||
*/
|
||||
class mail_bosieve
|
||||
{
|
||||
/**
|
||||
* Callback for the async job to enable/disable the vacation message
|
||||
*
|
||||
* @param array $_vacation
|
||||
*/
|
||||
function async_vacation($_vacation)
|
||||
{
|
||||
if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.'('.print_r($_vacation,true).')');
|
||||
|
||||
$_restoreSession = false; // as in async, each call may be for a different user
|
||||
$icServer = emailadmin_account::search((isset($_vacation['account_id'])&&!empty($_vacation['account_id'])?$_vacation['account_id']:$GLOBALS['egw_info']['user']['account_id']),false,null,0,1)->oldImapServer();
|
||||
|
||||
if ($this->debug) error_log(__CLASS__.'::'.__METHOD__.'->LoginName:'.$icServer->loginName);
|
||||
//error_log(__METHOD__.__LINE__.array2string($_vacation));
|
||||
try
|
||||
{
|
||||
$ret = $icServer->setVacationUser($icServer->loginName,$_vacation['scriptName'],$_vacation);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
error_log(__METHOD__.'::'.__LINE__.' call for '.$icServer->loginName.','.$_vacation['scriptName'].' failed for reason:'.$e->getMessage());
|
||||
$ret = false;
|
||||
}
|
||||
if ($ret) $icServer->setAsyncJob($_vacation);
|
||||
if ($ret===false) $icServer->setAsyncJob($_vacation,null,true); //reschedule
|
||||
return $ret;
|
||||
}
|
||||
|
||||
}
|
@ -573,11 +573,7 @@ class mail_sieve
|
||||
{
|
||||
//error_log(__METHOD__. 'content:' . array2string($content));
|
||||
$newVacation = $content;
|
||||
if (!empty($newVacation['account_id']) || !empty($newVacation['acc_id']))
|
||||
{
|
||||
unset($newVacation['account_id']);
|
||||
unset($newVacation['acc_id']);
|
||||
}
|
||||
|
||||
if (empty($this->mailConfig['prefpreventforwarding']) ||
|
||||
$this->mailConfig['prefpreventforwarding'] == 0 )
|
||||
{
|
||||
@ -601,15 +597,11 @@ class mail_sieve
|
||||
$newVacation['status'] = 'off';
|
||||
}
|
||||
|
||||
$checkAddresses = (isset($content['check_mail_sent_to']) && ($content['check_mail_sent_to']) != 0) ? true: false;
|
||||
$checkAddresses = isset($content['check_mail_sent_to']) && $content['check_mail_sent_to'] != 0;
|
||||
if ($content['addresses'])
|
||||
{
|
||||
$newVacation ['addresses'] = $content['addresses'];
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
if($this->checkRule($newVacation,$checkAddresses))
|
||||
{
|
||||
@ -627,9 +619,10 @@ class mail_sieve
|
||||
$msg = lang('vacation update failed') . "\n" . lang('Vacation notice update failed') . ":" . $this->account->imapServer()->error;
|
||||
break;
|
||||
}
|
||||
else
|
||||
// schedule job to switch message on/off, if request and not already in past
|
||||
elseif ($newVacation['status'] == 'by_date' && $newVacation['end_date']+24*3600<time())
|
||||
{
|
||||
$icServer->setAsyncJob($newVacation);
|
||||
self::setAsyncJob($newVacation);
|
||||
$msg = lang('Vacation notice sucessfully updated.');
|
||||
}
|
||||
}
|
||||
@ -681,6 +674,69 @@ class mail_sieve
|
||||
$vtmpl->exec('mail.mail_sieve.editVacation',$content,$sel_options,$readonlys,$preserv,2);
|
||||
}
|
||||
|
||||
/**
|
||||
* set the asyncjob for a timed vacation
|
||||
*
|
||||
* @param array $_vacation vacation to set/unset with values for 'account_id', 'acc_id' and vacation stuff
|
||||
* @param boolean $_reschedule do nothing but reschedule the job by 3 minutes
|
||||
* @return void
|
||||
*/
|
||||
static function setAsyncJob (array $_vacation, $_reschedule=false)
|
||||
{
|
||||
if (!($_vacation['acc_id'] > 0))
|
||||
{
|
||||
throw new egw_exception_wrong_parameter('No acc_id given!');
|
||||
}
|
||||
// setting up an async job to enable/disable the vacation message
|
||||
$async = new asyncservice();
|
||||
if (empty($_vacation['account_id'])) $_vacation['account_id'] = $GLOBALS['egw_info']['user']['account_id'];
|
||||
$async_id = !empty($_vacation['id']) ? $_vacation['id'] : 'mail-vacation-'.$_vacation['account_id'];
|
||||
$async->delete($async_id);
|
||||
|
||||
$end_date = $_vacation['end_date'] + 24*3600; // end-date is inclusive, so we have to add 24h
|
||||
if ($_vacation['status'] == 'by_date' && time() < $end_date && $_reschedule===false)
|
||||
{
|
||||
$time = time() < $_vacation['start_date'] ? $_vacation['start_date'] : $end_date;
|
||||
$async->set_timer($time,$async_id, 'mail_sieve::async_vacation', $_vacation, $_vacation['account_id']);
|
||||
}
|
||||
if ($_reschedule)
|
||||
{
|
||||
$time = time() + 60*3;
|
||||
unset($_vacation['next']);
|
||||
unset($_vacation['times']);
|
||||
$async->set_timer($time, $async_id, 'mail_sieve::async_vacation', $_vacation, $_vacation['account_id']);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Callback for the async job to enable/disable the vacation message
|
||||
*
|
||||
* @param array $_vacation
|
||||
* @throws egw_exception_not_found if mail account is not found
|
||||
*/
|
||||
static function async_vacation(array $_vacation)
|
||||
{
|
||||
if ($this->debug) error_log(__METHOD__.'('.array2string($_vacation).')');
|
||||
|
||||
$account = emailadmin_account::read($_vacation['acc_id'], $_vacation['account_id']);
|
||||
$icServer = $account->imapServer($_vacation['account_id']);
|
||||
|
||||
if ($this->debug) error_log(__METHOD__.'() imap username='.$icServer->acc_imap_username);
|
||||
|
||||
try
|
||||
{
|
||||
$ret = $icServer->setVacationUser($_vacation['account_id'], null, $_vacation);
|
||||
self::setAsyncJob($_vacation);
|
||||
}
|
||||
catch (Exception $e) {
|
||||
error_log(__METHOD__.'('.array2string($_vacation).' failed '.$e->getMessage());
|
||||
self::setAsyncJob($_vacation, true); // reschedule
|
||||
$ret = false;
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checking vaction validation
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user