Mailhandler attempts to open server session twice
tjsaker - October 4, 2009 - 00:30
| Project: | Mailhandler |
| Version: | 6.x-1.8 |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | postponed (maintainer needs more info) |
Jump to:
Description
In Mailhandler 6.x-1.8
I didn't see any other reports on this, so it may be related to the fact that I'm using hMailServer as my mail server in a windows development environment. Other servers may simply ignore the fact that a client is trying to open an already open session.
Nonetheless, my code review reveals that there is a flaw in Mailhandler's mail retrieval logic. mailhandler_cron_retrieve() calls mailhandler_get_unread_messages(). They are both calling mailhandler_open_mailbox(). The second call to mailhandler_open_mailbox() generates errors on my mail server and the session fails.
I've attached a patch file for mailhandler.retrieve.inc which corrects the situation.
| Attachment | Size |
|---|---|
| mailhandler.retrieve.inc-20091003.patch | 1.54 KB |

#1
@tjsaker I see what you are saying. It looks like your patch will cause mailhandler_open_mailbox to be called multiple times when running via cron. Can you try the following:
Change:
if ($result = mailhandler_open_mailbox($mailbox)) {// Find out how many messages need retrieval
$new_messages = mailhandler_get_unread_messages($mailbox);
to:
$new_messages = mailhandler_get_unread_messages($mailbox);if ($result = mailhandler_open_mailbox($mailbox)) {
// Find out how many messages need retrieval
and see if you still get the session error? mailhandler_get_unread_messages() closes the connection it opens. I'm wondering if it's called first, since it will not be opening a second connection to the mailbox, whether this will fix the problem you're seeing. I do not know how opening multiple streams to the same mailbox is handled b/t the different OS's. Please let me know how it goes.