- edited description
IMAP auth permission problem when IMAP uses only USERNAME
Hi
I’ve enabled IMAP auth but my IMAP server requires only USERNAME not complete e-mail.
So after auth I was able to see all messages, but if I click on any of them they return an error about “permission to read message 999”
So I find the custom authentication page on https://www.mailpiler.org/wiki/current:custom-authentication
and adapted the first sample to:
$config['CUSTOM_EMAIL_QUERY_FUNCTION'] = 'my_custom_func';
function my_custom_func($username = '') {
$session = Registry::get('session');
$data = $session->get("auth_data");
$a = array();
foreach($data['emails'] as $email) {
$s = explode("@", $email);
array_push($a, $s[0] . "@<mydomain>");
}
$data['emails'] = array_merge($data['emails'] , $a);
$session->set("auth_data", $data);
}
NOTE THE CHANGE of domain on line 11.
I think you could add this info on IMAP authentication page and this code below the IMAP part on config-site.php file with a simple explanation like “if your IMAP uses only username, add your domain on line below”.
That would allow any sysadmin to find and use it!
Regards
Jáder
(AFAIK this code allow add more than one domain by split username and domain parts, so maybe you could enhance it to just add one with little/better code!)
Comments (13)
-
reporter -
reporter I discovered a side effect of ADD domain : when searching for messages, if a FROM or TO has same info as my USERNAME , Piler show it (BAD!) but because I have no permission I can see it (good).
When logged in , in preferences I can see both names: JADER (username used to loggin) and JADER@MYDOMAIN , so because JADER is there, I can see emails from JADER@OTHERDOMAIN .
Could you patch the code to REPLACE username with username+domain if it’s not @local ? Would it be safe ?
-
reporter - changed title to IMAP auth permission problem when IMAP uses only USERNAME
-
reporter BTW: I think I broke the admin|auditor@local login! I’m getting 500 error…
-
reporter I think I need some code to deal with @local on field “email”, something like:
$s = explode("@", $email); if ($s[1] != "local" ) array_push($a, $s[0] . "@mydomain");
-
repo owner I’ve updated the documentation as you suggested, thanks.
To remove “JADER”, you need to fix the custom authentication function, I believe.
-
reporter Can you JANOS help me with the code?
option1: remove the USERNAME so JADER, JADER@mydomain became just jader@MYDOMAIN
option2: fix my function to allow @local users to work (right now I have @local or IMAP auth working, no both at same time)
-
reporter I think I solved it using SECOND example of custom-authentication page:
$config['CUSTOM_EMAIL_QUERY_FUNCTION'] = 'ignore_local'; function ignore_local($username = '') { global $session; if(strstr($username, "@local")) { error_log( "Found LOCAL, doing nothing\r\n");; } else { $session = Registry::get('session'); $data = $session->get("auth_data"); $a = array(); foreach($data['emails'] as $email) { $s = explode("@", $email); array_push($a, $s[0] . "@<mydomain.com>"); } } }
-
reporter What about somethink like:
// FROM https://www.mailpiler.org/wiki/current:custom-authentication second sample $config['CUSTOM_EMAIL_QUERY_FUNCTION'] = 'ignore_local'; function ignore_local($username = '') { global $session; if(!strstr($username, "@local")) { $session = Registry::get('session'); $data = $session->get("auth_data"); $a = array(); foreach($data['emails'] as $email) { $s = explode("@", $email); array_push($a, $s[0] . "@<mydomain.com>"); } } }
It SHOULD to have solved my problem, but it do not add @mydomain , just allow local accounts to work!
Do I miss something ?
-
repo owner If it works for you, I’m all in.
-
reporter no it do not work, and IU don’t know why! How could I find out whats happening?
-
repo owner Try the following. In the user settings menu it displays only “JADER@aaa.fu”:
$config['CUSTOM_EMAIL_QUERY_FUNCTION'] = 'my_custom_func'; function my_custom_func($username = '') { $session = Registry::get('session'); $data = $session->get("auth_data"); if(!strstr($username, '@local')) { $email = $username . '@aaa.fu'; $data['emails'] = [$email]; $session->set("auth_data", $data); } }
-
repo owner - changed status to resolved
- Log in to comment