IMAP connection error with users who are not allowed to use webmail.
| Project: | Basic webmail |
| Version: | 5.x-1.1 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
I discovered a tiny little bug with the basic webmail.
I have 3 roles of users. Two roles are allowed to use webmail. One role may not. The menu works just fine for only the roles allowed to use webmail see the menu item.
The problem show when a user who is not suposed to have webmail access goes into his account settings to change anything. After saving the account settings that user gets the following message:
warning: imap_open() [function.imap-open]: Couldn't open stream {mail.zooot.net:993/ssl/novalidate-cert/notls}INBOX in /home/zoooapo0/public_html/sites/all/modules/basic_webmail/basic_webmail.module on line 1960.
Now I guess that the webmail is trying to connect to the mail server. But since the user does not have any webmail access he also does not have any login data (and the mail server does not know him).
Is there a way to stop the basic webmail module from checking the server connection of users who do not have any webmail access? I would rather not hve these error messages - they tend to confuse users.
Appart from that it is a great module.
Regards,
Paul.

#1
Okay, I tried getting around this problem by inserting another condition, but that did not work.
Did I copy the code in a wrong way or am I totally of the track here?
// Make the actual connection.
if ($category == 'account' && user_access('access basic_webmail') && (($imap_resource = imap_open($mailbox, $username,
$password, 0, 1)) == FALSE) {
$error_message = t('There was an error accessing the remote server: ') . imap_last_error();
watchdog('basic_webmail', $error_message, WATCHDOG_ERROR);
return FALSE;
}
return $imap_resource;
} // End of _basic_webmail_connect_to_server().
Another solution for my problem may be to set up a default mail account and set up a default login that is used if no other specific login data is entered. But also here I do not know where to enter the default login data?
#2
Probably a better thing to check would be their roles. I'm not familiar with your site and it's operation, obviously, so this may not work for your situation, but you could try something like:
if ($category == 'account' && user_access('access basic_webmail') && in_array('your-role-here', $user->roles)) {I didn't test that, so it may need tweaking.
#3
Thank you for your suggestion.
I solved my little problem by disabling the watchdog function. This way any errors show up only on the logfiles and not in front of the user. I may try out your solution once I have my testserver running again. But for now I rather not change a running system :-)
Paul.