I noticed that the module was not able to delete the email after they are retrieved into my drupal.
In order to solve this issue I had to do the following changes in mailhandler.retrieve.inc
This approach should be done for users who has pop3 account and not imap since it should delete normally.
if ($mailbox['delete_after_read']) {
if( !imap_delete($result, $i, FT_UID))
watchdog('mailhandler', 'Failed to delete messages from the inbox account', 0, WATCHDOG_NOTICE);
else
imap_expunge($result);
}
Why to do this??
after checking the php manual i noticed the following note for the function IMAP_DELETE()
Note: POP3 mailboxes do not have their message flags saved between connections, so imap_expunge() must be called during the
same connection in order for messages marked for deletion to actually be purged.
good luck
Comments
Comment #1
Jean-Philippe Fleury commentedI have this bug too with Drupal 6.13 and Mailhandler 6.x-1.8.
Comment #2
neochief commentedFix for 6.x
Comment #3
awolfey commentedWorks for me.
Comment #4
chrisfromredfinI independently came to the exact conclusion of this patch, and THEN found this issue.
Comment #5
Ian Ward commentedIn 6.x-1.8 this should work without the patch (it seems to be working for me using a pop3 account). When run from cron, one connection is open, messages are processed, and then the connection is closed using imap_close($result, CL_EXPUNGE); (http://www.php.net/manual/en/function.imap-close.php "If set to CL_EXPUNGE, the function will silently expunge the mailbox before closing, removing all messages marked for deletion. You can achieve the same thing by using imap_expunge()")
I have a few questions for anyone w/ this problem to make sure the corner cases are covered:
1) Are any of you using a gmail account for your mailhandler mailbox? I ask because there is a separate issue whereby gmail has a custom method for deleting messages from their mailboxes which should be handled in a future version of mailhandler
2) When you say messages are not getting deleted, are they remaining in your inbox, or getting moved to trash/bin, and just not getting emptied from trash/bin?
3) Can you test and see if you notice this problem when retrieving via cron as well as when retrieving using the UI?
Thanks,
Ian
Comment #7
awolfey commentedI was testing with a gmail account and a private server account. I'll double check when I come back to this.
Comment #8
tsaker commentedI'm experiencing the same issue as initially reported. I'm using a Gmail POP3 account and the messages don't get deleted nor marked as read. I double-checked the Mailhandler settings to verify the 'Delete messages after they are processed?' flag is enabled.
Configuration:
- Drupal 6.14
- Mailhandler 6.x-1.8
- OG Mailhandler 6.x-1.x-dev
Comment #9
Jean-Philippe Fleury commentedHi Ian,
Here are my answers to your questions:
No, I don't.
The messages are remaining in the inbox. They're marked as read, but each time Mailhandler retrieves messages, it retrieves all those (read or not) found in the inbox, so it creates duplicate content.
It seems that the problem occurs only when I'm using the UI. Via cron, the messages are well deleted.
Comment #10
chrisfromredfinI would mostly mimic #9:
- not using GMail (using Dovecot)
- remaining in the inbox
- not sure, but cron seems overall more reliable than "retrieve"
We were able to get IMAP running on Dovecot and so we've moved away from this issue a litte.
Comment #11
sheldon rampton commentedI'm having the same experience as #9 and #10. I'm not using GMail, and messages are not getting deleted when I use "retrieve," thus creating duplicate content. However, cron does delete the messages. I've tried this and gotten the same result with two different POP3 accounts using different internet service providers.
I'm not sure I understand all of the code in the mailhandler module, but it looks to me like the mailhandler_cron_retrieve() function is working as expected, while the mailhandler_admin_retrieve() function is not. I would guess that the problem is probably with the following lines of code (lines 717-721 at the end of the mailhandler_retrieve_message() function):
It looks to me like this code is testing to see whether mailhandler_retrieve_message() was called using the batch API. If the answer is yes, it is supposed to run imap_close. However, the batch API does pass arguments to the mailhandler_retrieve_message() function, so wouldn't that test fail?
Comment #12
Ian Ward commentedThank you everyone for the additional information. During UI retrieval:
was indeed not getting reached. I committed a change to check a different way whether UI retrieval is being used. A small additional change was then needed to fix the message number when using POP and using UI retrieval.
This is now fixed in HEAD and should be available in the dev version soon.
Comment #13
sheldon rampton commentedIncidentally, the fact that messages are NOT deleted during UI retrieval is actually coming in handy for me right now while I'm building and testing a module that uses hook_mailhandler. It lets me develop my code without having to send a new email every time I want to test an iteration.
Maybe it's worth developing this bug into a feature, such as a check box that people can use to disable message deletion. :-)