Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log ClientExceptions to logfile #705

Closed
cm-schl opened this issue Nov 24, 2022 · 5 comments
Closed

Log ClientExceptions to logfile #705

cm-schl opened this issue Nov 24, 2022 · 5 comments

Comments

@cm-schl
Copy link

cm-schl commented Nov 24, 2022

I'm actually writing a plugin for SnappyMail to add additional mailboxes by a ldap query. There I had a problem with the domain check that is done in

public static function NewInstanceFromCredentials(\RainLoop\Actions $oActions,

If the domain found in ldap does not exist in the domain configuration of SnappyMail in theory this function would throw a ClientException to inform the user that the domain is not allowed / unknown.
As this interaction is not possible when a plugin is trying to register a new mail address to SnappyMail the user (and developer) of the plugin can't get informed about this problem.

Describe the solution you'd like
I would like to propose a change to snappymail/v/0.0.0/app/libraries/RainLoop/Exceptions/ClientException.php so that a thrown error is also logged in the log file.
This way the admin / developer is informed what happened and why a login is not possible.

@the-djmaze
Copy link
Owner

Would this help?

public function DoAdminDomainMatch() : array
{
$sEmail = $this->GetActionParam('username');
$sPassword = '********';
$sLogin = '';
$this->resolveLoginCredentials($sEmail, $sPassword, $sLogin);
$oDomain = \str_contains($sEmail, '@')
? $this->DomainProvider()->Load(\MailSo\Base\Utils::GetDomainFromEmail($sEmail), true)
: null;
return $this->DefaultResponse(__FUNCTION__, array(
'email' => $sEmail,
'login' => $sLogin,
'domain' => $oDomain,
'whitelist' => $oDomain ? $oDomain->ValidateWhiteList($sEmail, $sLogin) : null
));

@cm-schl
Copy link
Author

cm-schl commented Nov 25, 2022

sorry, i don't get it... 🙂.

The idea behind my request is to give the developer / admin the possibility to see if a user (or a plugin) tries to login with a mail address that is not in the list if configured domains.
Maybe this is only a side effect how I'm trying to register a new account out of my plugin - there I use RainLoop\Model\AdditionalAccount::NewInstanceFromCredentials to add a new additional account. If the domain is not in the list of configured domains I can't see any error inside the log file of SnappyMail.

@the-djmaze
Copy link
Owner

the-djmaze commented Nov 25, 2022

What i mean is: Should your plugin check if Domain is available BEFORE trying to login with NewInstanceFromCredentials ?

My code above does three things for that:

  1. resolveLoginCredentials() tries to make $sEmail as valid as possible according to all the rules, plugins, etc.
  2. DomainProvider()->Load() loads the Domain matching the $sEmail
  3. $oDomain->ValidateWhiteList($sEmail, $sLogin) checks if $sEmail is whitelisted

Step 1 is currently a private/protected function but you get the idea to:

  1. check if $sEmail is allowed (if not, log it yourself)
  2. when allowed add it as AdditionalAccount

@cm-schl
Copy link
Author

cm-schl commented Nov 25, 2022

Ok thanks for the explanation! I will add a check to my plugin 🙂👍

@cm-schl cm-schl closed this as completed Nov 25, 2022
@the-djmaze
Copy link
Owner

If you want access to resolveLoginCredentials() i can change the scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants