mirror of
https://github.com/EGroupware/egroupware.git
synced 2025-06-24 11:51:43 +02:00
add more validation and defaults for the vacation
This commit is contained in:
parent
bed1e43200
commit
a8dade0083
@ -176,9 +176,13 @@ class ApiHandler extends Api\CalDAV\Handler
|
|||||||
// Sieve class stores them as comma-separated string
|
// Sieve class stores them as comma-separated string
|
||||||
if (array_key_exists('forwards', $update))
|
if (array_key_exists('forwards', $update))
|
||||||
{
|
{
|
||||||
$vacation['forwards'] = implode(',', $update['forwards'] ?? []);
|
$vacation['forwards'] = implode(',', self::parseAddressList($update['forwards'] ?? [], 'forwards'));
|
||||||
unset($update['forwards']);
|
unset($update['forwards']);
|
||||||
}
|
}
|
||||||
|
if (array_key_exists('addresses', $update))
|
||||||
|
{
|
||||||
|
$update['addresses'] = self::parseAddressList($update['addresses'] ?? [], 'addresses');
|
||||||
|
}
|
||||||
static $modi = ['notice+store', 'notice', 'store'];
|
static $modi = ['notice+store', 'notice', 'store'];
|
||||||
if (isset($update['modus']) && !in_array($update['modus'], $modi))
|
if (isset($update['modus']) && !in_array($update['modus'], $modi))
|
||||||
{
|
{
|
||||||
@ -190,7 +194,11 @@ class ApiHandler extends Api\CalDAV\Handler
|
|||||||
}
|
}
|
||||||
$vacation_rule = null;
|
$vacation_rule = null;
|
||||||
$sieve = new Api\Mail\Sieve($account->imapServer());
|
$sieve = new Api\Mail\Sieve($account->imapServer());
|
||||||
$sieve->setVacation(array_merge(['days' => 3], $vacation, $update), null, $vacation_rule, true);
|
$sieve->setVacation(array_merge([ // some defaults
|
||||||
|
'status' => 'on',
|
||||||
|
'addresses' => [Api\Accounts::id2name($user, 'account_email')],
|
||||||
|
'days' => 3,
|
||||||
|
], $vacation, $update), null, $vacation_rule, true);
|
||||||
echo json_encode([
|
echo json_encode([
|
||||||
'status' => 200,
|
'status' => 200,
|
||||||
'message' => 'Vacation handling updated',
|
'message' => 'Vacation handling updated',
|
||||||
@ -200,6 +208,32 @@ class ApiHandler extends Api\CalDAV\Handler
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Parse array of email addresses
|
||||||
|
*
|
||||||
|
* @param string[] $_addresses
|
||||||
|
* @param string $name attribute name for exception
|
||||||
|
* @return string[]
|
||||||
|
* @throws \Exception if there is an invalid email address
|
||||||
|
*/
|
||||||
|
protected static function parseAddressList(array $_addresses, $name=null)
|
||||||
|
{
|
||||||
|
$parsed = iterator_to_array(Api\Mail::parseAddressList($_addresses));
|
||||||
|
|
||||||
|
if (count($parsed) !== count($_addresses) ||
|
||||||
|
array_filter($parsed, static function ($addr)
|
||||||
|
{
|
||||||
|
return !$addr->valid;
|
||||||
|
}))
|
||||||
|
{
|
||||||
|
throw new \Exception("Error parsing email-addresses in attribute $name: ".json_encode($_addresses));
|
||||||
|
}
|
||||||
|
return array_map(static function($addr)
|
||||||
|
{
|
||||||
|
return $addr->mailbox.'@'.$addr->host;
|
||||||
|
}, $parsed);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Store uploaded attachment and return token
|
* Store uploaded attachment and return token
|
||||||
*
|
*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user