Skip to content

Commit

Permalink
Mailbox Automatic Aliases 2.0 (#290)
Browse files Browse the repository at this point in the history
Refactors @mfechner's `ViMbAdminPlugin_MailboxAutomaticAliases`. The new plugin is fully backwards compatible, but adds a whole lot of flexibility.

One can now use plain usernames as default mapping (`defaultMapping.abuse = "postmaster"` creates an alias abuse@example.com -> postmaster@example.com), as well as domain wildcards (`defaultMapping.abuse = "@example.net"` creates an alias abuse@example.com -> abuse@example.net). Additionally there's a wildcard mapping to simplify configuration (`defaultMapping.* = "root@example.com"` causes all automatic aliases without explicit default mapping to redirect to root@example.com). The plugin will furthermore respect full domain aliases (@example.com -> @example.net), bypassing the need to create distinct automatic aliases, since they are caught by the domain alias anyway.

Protection rules are now fully enforced. Next to preventing domain admins to delete mailboxes that are used as goto address for an automatic alias, the plugin now enforces the same when disabling a mailbox, and when deleting or disabling another alias that is used as goto address. The plugin no longer relies on the default mappings for these checks, but actually checks the alias' goto address. As before, the actual automatic aliases are protected as well. The same now applies to domain aliases when there are no distinct automatic aliases.

Please note that protection rules aren't enforced recursively and not accross domain boundaries. These checks didn't exist before and IMHO aren't really worth the effort.

Also adds the `mailbox_toggleActive_preToggle` event and fixes the output of the `alias_toggleActive_preToggle` event.
  • Loading branch information
PhrozenByte authored Feb 23, 2023
1 parent 5836ad5 commit 91cd43d
Show file tree
Hide file tree
Showing 5 changed files with 436 additions and 227 deletions.
15 changes: 3 additions & 12 deletions application/configs/application.ini.dist
Original file line number Diff line number Diff line change
Expand Up @@ -367,13 +367,6 @@ skipVersionCheck = 0
skipInstallPingback = 0









;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Allow admins to dictate whether a user can use BOTH, IMAP ONLY,
; POP3 ONLY when creating mailboxes.
Expand All @@ -395,7 +388,6 @@ vimbadmin_plugins.AccessPermissions.type.POP3 = "POP3"
vimbadmin_plugins.AccessPermissions.type.SIEVE = "SIEVE"



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Allow admins to force that for a mailbox/domain basic aliases are existing
; If a new mailbox is created the system will check if the aliases are existing, if not they are created.
Expand All @@ -411,10 +403,9 @@ vimbadmin_plugins.MailboxAutomaticAliases.defaultAliases[] = "hostmaster"
vimbadmin_plugins.MailboxAutomaticAliases.defaultAliases[] = "webmaster"

; Define this if emails should be forwarded to a fixed address instead of the first mailbox address of the domain
;vimbadmin_plugins.MailboxAutomaticAliases.defaultMapping.postmaster = "postmaster@example.net"
;vimbadmin_plugins.MailboxAutomaticAliases.defaultMapping.abuse = "abuse@example.net"
;vimbadmin_plugins.MailboxAutomaticAliases.defaultMapping.hostmaster = "hostmaster@example.net"
;vimbadmin_plugins.MailboxAutomaticAliases.defaultMapping.webmaster = "webmaster@example.net"
;vimbadmin_plugins.MailboxAutomaticAliases.defaultMapping.postmaster = "@other.tld"
;vimbadmin_plugins.MailboxAutomaticAliases.defaultMapping.abuse = "postmaster"
;vimbadmin_plugins.MailboxAutomaticAliases.defaultMapping.* = "root@domain.tld"



Expand Down
22 changes: 14 additions & 8 deletions application/configs/application.ini.vagrant
Original file line number Diff line number Diff line change
Expand Up @@ -347,13 +347,6 @@ skipVersionCheck = 0
skipInstallPingback = 0









;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Allow admins to dictate whether a user can use BOTH, IMAP ONLY,
; POP3 ONLY when creating mailboxes.
Expand All @@ -375,11 +368,24 @@ vimbadmin_plugins.AccessPermissions.type.POP3 = "POP3"
vimbadmin_plugins.AccessPermissions.type.SIEVE = "SIEVE"


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Allow admins to force that for a mailbox/domain basic aliases are existing
; If a new mailbox is created the system will check if the aliases are existing, if not they are created.

vimbadmin_plugins.MailboxAutomaticAliases.disabled = true

; These aliases should always exist, it is not recommened to delete it
vimbadmin_plugins.MailboxAutomaticAliases.defaultAliases[] = "postmaster"
vimbadmin_plugins.MailboxAutomaticAliases.defaultAliases[] = "abuse"

; These aliases are optional, but it recommended to not remove them
vimbadmin_plugins.MailboxAutomaticAliases.defaultAliases[] = "hostmaster"
vimbadmin_plugins.MailboxAutomaticAliases.defaultAliases[] = "webmaster"


; Define this if emails should be forwarded to a fixed address instead of the first mailbox address of the domain
;vimbadmin_plugins.MailboxAutomaticAliases.defaultMapping.postmaster = "@other.tld"
;vimbadmin_plugins.MailboxAutomaticAliases.defaultMapping.abuse = "postmaster"
;vimbadmin_plugins.MailboxAutomaticAliases.defaultMapping.* = "root@domain.tld"



Expand Down
2 changes: 1 addition & 1 deletion application/controllers/AliasController.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,10 +327,10 @@ public function ajaxToggleActiveAction()
$this->notify( 'alias', 'toggleActive', 'preflush', $this, [ 'active' => $this->getAlias()->getActive() ] );
$this->getD2EM()->flush();
$this->notify( 'alias', 'toggleActive', 'postflush', $this, [ 'active' => $this->getAlias()->getActive() ] );
print 'ok';
} else {
print 'ko';
}
print 'ok';
}


Expand Down
24 changes: 14 additions & 10 deletions application/controllers/MailboxController.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,18 +408,22 @@ public function ajaxToggleActiveAction()
if( !$this->getMailbox() )
print 'ko';

$this->getMailbox()->setActive( !$this->getMailbox()->getActive() );
$this->getMailbox()->setModified( new \DateTime() );
if($this->notify( 'mailbox', 'toggleActive', 'preToggle', $this, [ 'active' => $this->getMailbox()->getActive() ]) === true) {
$this->getMailbox()->setActive( !$this->getMailbox()->getActive() );
$this->getMailbox()->setModified( new \DateTime() );

$this->log(
$this->getMailbox()->getActive() ? \Entities\Log::ACTION_MAILBOX_ACTIVATE : \Entities\Log::ACTION_MAILBOX_DEACTIVATE,
"{$this->getAdmin()->getFormattedName()} " . ( $this->getMailbox()->getActive() ? 'activated' : 'deactivated' ) . " mailbox {$this->getMailbox()->getUsername()}"
);
$this->log(
$this->getMailbox()->getActive() ? \Entities\Log::ACTION_MAILBOX_ACTIVATE : \Entities\Log::ACTION_MAILBOX_DEACTIVATE,
"{$this->getAdmin()->getFormattedName()} " . ( $this->getMailbox()->getActive() ? 'activated' : 'deactivated' ) . " mailbox {$this->getMailbox()->getUsername()}"
);

$this->notify( 'mailbox', 'toggleActive', 'postflush', $this, [ 'active' => $this->getMailbox()->getActive() ] );
$this->getD2EM()->flush();
$this->notify( 'mailbox', 'toggleActive', 'postflush', $this, [ 'active' => $this->getMailbox()->getActive() ] );
print 'ok';
$this->notify( 'mailbox', 'toggleActive', 'preflush', $this, [ 'active' => $this->getMailbox()->getActive() ] );
$this->getD2EM()->flush();
$this->notify( 'mailbox', 'toggleActive', 'postflush', $this, [ 'active' => $this->getMailbox()->getActive() ] );
print 'ok';
} else {
print 'ko';
}
}


Expand Down
Loading

0 comments on commit 91cd43d

Please sign in to comment.