Skip to content

Instantly share code, notes, and snippets.

@lechup
Last active January 23, 2023 14:43
Show Gist options
  • Save lechup/06d96b49501c59844a51c6b6571c46e7 to your computer and use it in GitHub Desktop.
Save lechup/06d96b49501c59844a51c6b6571c46e7 to your computer and use it in GitHub Desktop.
Piler mailpiler.org - adding aliases on the fly
<?
// 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