Last active
January 23, 2023 14:43
-
-
Save lechup/06d96b49501c59844a51c6b6571c46e7 to your computer and use it in GitHub Desktop.
Piler mailpiler.org - adding aliases on the fly
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<? | |
// based on: | |
// https://www.mailpiler.org/wiki/current:custom-authentication | |
$config['CUSTOM_EMAIL_QUERY_FUNCTION'] = 'set_email_aliases'; | |
function set_email_aliases($username = '') { | |
$session = Registry::get('session'); | |
$data = $session->get("auth_data"); | |
// array of aliases per email login | |
$aliases = [ | |
'[email protected]' => [ | |
'alias1', | |
'alias2', | |
], | |
'[email protected]' => [ | |
'alias3', | |
'alias4', | |
], | |
]; | |
// list of domains for aliases | |
$domains = [ | |
'example1.com', | |
'example2.com', | |
'example3.com' | |
]; | |
// results | |
// [email protected] -> [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected] | |
// [email protected] -> [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected] | |
if($data) { | |
$current_email = is_array($data['emails']) ? $data['emails'][0] : $data['emails']; | |
$current_aliases = in_array($current_email, array_keys($aliases)) ? $aliases[$current_email] : []; | |
$current_emails = array(); | |
foreach($current_aliases as $alias) { | |
foreach($domains as $domain) { | |
array_push($current_emails, $alias.'@'.$domain); | |
} | |
} | |
$data['emails'] = array_merge([$current_email], $current_emails); | |
$session->set("auth_data", $data); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment