Verified Commit 6bccac69 authored by Côme Chilliet's avatar Côme Chilliet
Browse files

🚑 fix(cyrus) Move cyrus autocreate folders option to cyrus service

issue #6042
parent b040756b
...@@ -38,9 +38,11 @@ class serviceCyrus extends simpleMailMethodService ...@@ -38,9 +38,11 @@ class serviceCyrus extends simpleMailMethodService
*/ */
static function getAttributesInfo (): array static function getAttributesInfo (): array
{ {
global $config;
return [ return [
'cyrus' => [ 'cyrus' => [
'name' => _('Cyrus settings'), 'name' => _('Connection'),
'attrs' => [ 'attrs' => [
new CompositeAttribute( new CompositeAttribute(
_('Connect URL for Cyrus server'), _('Connect URL for Cyrus server'),
...@@ -78,15 +80,10 @@ class serviceCyrus extends simpleMailMethodService ...@@ -78,15 +80,10 @@ class serviceCyrus extends simpleMailMethodService
_('Password'), _('Admin user password'), _('Password'), _('Admin user password'),
'fdCyrusPassword', TRUE 'fdCyrusPassword', TRUE
), ),
new BooleanAttribute(
_('Use UNIX style'), _('Determines if "foo/bar" or "foo.bar" should be used as namespaces in IMAP'),
'fdCyrusUseSlashes', FALSE,
($config->get_cfg_value('CyrusUseSlashes') === 'TRUE')
),
] ]
], ],
'sieve' => [ 'sieve' => [
'name' => _('Sieve settings'), 'name' => _('Sieve'),
'attrs' => [ 'attrs' => [
new CompositeAttribute( new CompositeAttribute(
_('Sieve connect URL for Cyrus server'), _('Sieve connect URL for Cyrus server'),
...@@ -110,8 +107,25 @@ class serviceCyrus extends simpleMailMethodService ...@@ -110,8 +107,25 @@ class serviceCyrus extends simpleMailMethodService
'/^{(.*):(\\d+)\\/([^\\/]+)}$/', '/^{(.*):(\\d+)\\/([^\\/]+)}$/',
'{%s:%d/%s}' '{%s:%d/%s}'
) )
] ],
] ],
'settings' => [
'name' => _('Settings'),
'attrs' => [
new BooleanAttribute(
_('Use UNIX style'), _('Determines if "foo/bar" or "foo.bar" should be used as namespaces in IMAP'),
'fdCyrusUseSlashes', FALSE,
($config->get_cfg_value('CyrusUseSlashes') === 'TRUE')
),
new SetAttribute(
new StringAttribute(
_('Autocreate folders'), _('List of personal IMAP folders that should be created along initial account creation.'),
'fdCyrusAutocreateFolders', FALSE
),
$config->get_cfg_value('CyrusAutocreateFolders', [])
),
],
],
]; ];
} }
} }
...@@ -39,4 +39,4 @@ attributetype ( 1.3.6.1.4.1.38414.14.1.6 NAME 'fdCyrusAcl' ...@@ -39,4 +39,4 @@ attributetype ( 1.3.6.1.4.1.38414.14.1.6 NAME 'fdCyrusAcl'
objectclass (1.3.6.1.4.1.38414.14.2.1 NAME 'fdCyrusServer' SUP top AUXILIARY objectclass (1.3.6.1.4.1.38414.14.2.1 NAME 'fdCyrusServer' SUP top AUXILIARY
DESC 'FusionDirectory - Cyrus server description' DESC 'FusionDirectory - Cyrus server description'
MUST ( cn $ fdCyrusConnect $ fdCyrusAdmin $ fdCyrusPassword ) MUST ( cn $ fdCyrusConnect $ fdCyrusAdmin $ fdCyrusPassword )
MAY ( fdCyrusUseSlashes $ fdCyrusSieveServer )) MAY ( fdCyrusUseSlashes $ fdCyrusAutocreateFolders $ fdCyrusSieveServer ))
...@@ -259,23 +259,19 @@ class mailMethodCyrus extends mailMethod ...@@ -259,23 +259,19 @@ class mailMethodCyrus extends mailMethod
$list = imap_listmailbox($this->imap_handle, $cfg['connect'], $this->account_id); $list = imap_listmailbox($this->imap_handle, $cfg['connect'], $this->account_id);
if ($list === FALSE) { if ($list === FALSE) {
@DEBUG(DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, $this->account_id, @DEBUG(DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, $this->account_id,
"<b>IMAP: Add account</b> on server :".$this->parent->gosaMailServer); 'IMAP: Add account on server '.$this->parent->gosaMailServer);
if (!imap_createmailbox($this->imap_handle, $cfg["connect"].$this->account_id)) { if (!imap_createmailbox($this->imap_handle, $cfg['connect'].$this->account_id)) {
$this->error = imap_last_error(); $this->error = imap_last_error();
return FALSE; return FALSE;
} }
/* Autocreate configured default folders */ /* Autocreate configured default folders */
$folders = $config->get_cfg_value('cyrusAutocreateFolders', NULL); foreach ($cfg['autocreate'] as $folder) {
if ($folders !== NULL) { @DEBUG(DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, $folder,
// Walk thru list of specified folders 'IMAP: Add account folder on server '.$this->parent->gosaMailServer);
foreach ($folders as $folder) { if (!imap_createmailbox($this->imap_handle, $cfg['connect'].$this->create_folder_id($folder))) {
@DEBUG(DEBUG_MAIL, __LINE__, __FUNCTION__, __FILE__, '<b>'.$this->account_id.'</b>', $this->error = imap_last_error();
'<b>IMAP: Add/Update account folder '.$folder.'</b> on server :'.$this->parent->gosaMailServer); return FALSE;
if (!imap_createmailbox($this->imap_handle, $cfg['connect'].$this->create_folder_id($folder))) {
$this->error = imap_last_error();
return FALSE;
}
} }
} }
} }
...@@ -627,7 +623,10 @@ class mailMethodCyrus extends mailMethod ...@@ -627,7 +623,10 @@ class mailMethodCyrus extends mailMethod
$ldap = $config->get_ldap_link(); $ldap = $config->get_ldap_link();
$ldap->cd($config->current['BASE']); $ldap->cd($config->current['BASE']);
$ldap->search('(objectClass=fdCyrusServer)', $ldap->search('(objectClass=fdCyrusServer)',
['cn','fdCyrusConnect','fdCyrusAdmin','fdCyrusPassword','fdCyrusSieveServer','fdCyrusUseSlashes']); [
'cn','fdCyrusConnect','fdCyrusAdmin','fdCyrusPassword',
'fdCyrusSieveServer','fdCyrusUseSlashes','fdCyrusAutocreateFolders'
]);
while ($attrs = $ldap->fetch()) { while ($attrs = $ldap->fetch()) {
sscanf($attrs['fdCyrusSieveServer'][0], '{%[^{}:]:%d/%[^{}]}', $sieve_server, $sieve_port, $sieve_option); sscanf($attrs['fdCyrusSieveServer'][0], '{%[^{}:]:%d/%[^{}]}', $sieve_server, $sieve_port, $sieve_option);
...@@ -637,6 +636,7 @@ class mailMethodCyrus extends mailMethod ...@@ -637,6 +636,7 @@ class mailMethodCyrus extends mailMethod
'admin' => $attrs['fdCyrusAdmin'][0], 'admin' => $attrs['fdCyrusAdmin'][0],
'password' => $attrs['fdCyrusPassword'][0], 'password' => $attrs['fdCyrusPassword'][0],
'useSlashes' => ($attrs['fdCyrusUseSlashes'][0] ?? 'FALSE'), 'useSlashes' => ($attrs['fdCyrusUseSlashes'][0] ?? 'FALSE'),
'autocreate' => ($attrs['fdCyrusAutocreateFolders'] ?? []),
'sieve_server' => $sieve_server, 'sieve_server' => $sieve_server,
'sieve_option' => $sieve_option, 'sieve_option' => $sieve_option,
'sieve_port' => $sieve_port 'sieve_port' => $sieve_port
......
...@@ -60,13 +60,6 @@ class mailPluginConfig extends simplePlugin ...@@ -60,13 +60,6 @@ class mailPluginConfig extends simplePlugin
_('Determines if the mailbox should be removed from your IMAP server after the account is deleted in LDAP.'), _('Determines if the mailbox should be removed from your IMAP server after the account is deleted in LDAP.'),
'fdCyrusDeleteMailbox' 'fdCyrusDeleteMailbox'
), ),
new SetAttribute(
new StringAttribute(
_('Cyrus autocreate folders'),
_('List of personal IMAP folders that should be created along initial account creation.'),
'fdCyrusAutocreateFolders'
)
),
new IntAttribute( new IntAttribute(
_('IMAP timeout'), _('IMAP timeout'),
_('Sets the connection timeout for imap actions.'), _('Sets the connection timeout for imap actions.'),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment