Enough-Software / enough_mail

IMAP, POP3 and SMTP clients for Dart developers. Contains both low level as well as a high level API.
Mozilla Public License 2.0
100 stars 56 forks source link

cannot delete message with high level API #228

Closed filly82 closed 7 months ago

filly82 commented 7 months ago

I am not able to delete messages with the high level API

await client.deleteMessage(message);

but nothing happens. with logging enabled this is the output i receive:

flutter: C: a15 UID MOVE 426 Trash
flutter: S: a15 OK No messages found (0.001 + 0.000 secs).

when trying with expunge: true

await client.deleteMessage(message, expunge: true);

i get at least an exception, but it's just null

flutter: C: a15 STORE 426 +FLAGS.SILENT (\Deleted)
flutter: S: a15 BAD Error in IMAP command STORE: Invalid messageset (0.001 + 0.000 secs).

flutter: High level API failed with MailException: null:  null
flutter: #0      _IncomingImapClient.deleteMessages (package:enough_mail/src/mail/mail_client.dart:2374:9)
<asynchronous suspension>

it seems that in both cases that the message with the UID 426 is not found, right? but why? looking a bit in the log output i can see that the message with the UID 426 is there

.....
flutter: S: * 8 FETCH (UID 426 FLAGS (\Seen) RFC822.SIZE 472 BODY[] {472}
<472 bytes data>
)
.....

does anyone have any idea?

robert-virkus commented 7 months ago

That's interesting. Can you share the used IMAP server?

filly82 commented 7 months ago

sure, whatever you need. it is "Dovecot", here are the first lines from the logging output

flutter: A: connecting to server xxx.xxxxx.xx:993 - secure: true, timeout: 0:00:10.000000
flutter: S: * OK [CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE LITERAL+ AUTH=PLAIN AUTH=LOGIN] Dovecot (Ubuntu) ready.

flutter: C: a0 LOGIN "xxxx@xxxx.xx" "(password scrambled)"
flutter: S: a0 OK [CAPABILITY IMAP4rev1 SASL-IR LOGIN-REFERRALS ID ENABLE IDLE SORT SORT=DISPLAY THREAD=REFERENCES THREAD=REFS THREAD=ORDEREDSUBJECT MULTIAPPEND URL-PARTIAL CATENATE UNSELECT CHILDREN NAMESPACE UIDPLUS LIST-EXTENDED I18NLEVEL=1 CONDSTORE QRESYNC ESEARCH ESORT SEARCHRES WITHIN CONTEXT=SEARCH LIST-STATUS BINARY MOVE SNIPPET=FUZZY PREVIEW=FUZZY PREVIEW STATUS=SIZE SAVEDATE LITERAL+ NOTIFY SPECIAL-USE] Logged in

flutter: C: a1 ID NIL
flutter: S: * ID ("name" "Dovecot")

flutter: S: a1 OK ID completed (0.001 + 0.000 secs).

flutter: C: a2 ENABLE QRESYNC
flutter: S: * ENABLED QRESYNC

flutter: S: a2 OK Enabled (0.001 + 0.000 secs).
robert-virkus commented 7 months ago

Thanks, with Dovecot we can rule out any strange-behaving mail server. Have you selected a different mailbox while issuing the above commands?

filly82 commented 7 months ago

now that you mention it, i have already assumed that it has something to do with the folder because it is not in INBOX but next to it. just forgot to test it, now i did and it works when it is within INBOX

Hopefully this can be fixed, because i only need to delete mails in that one special folder called 'Notes'

does not work here:

flutter: C: a4 SELECT "Notes"

works here

flutter: C: a4 SELECT "INBOX.FTagged.Wohnung"
robert-virkus commented 7 months ago

Thanks. Can you rule out that you have selected a different folder while issuing these commands? Despite it's name, a UID is only a mailbox-specific ID, so the corresponding folder needs to be selected. The "only" benefit of a UID is that the UID stays the same, even after messages before have been deleted - in contrast to sequence IDs, which do change in that case.

robert-virkus commented 7 months ago

If you can rule that out, what is the server response when selecting the Notes mailbox?

filly82 commented 7 months ago

there you said it.

I did not explicitly select the folder/mailbox because I specified mailbox here client.fetchMessages(mailbox: mailbox); and the doc says Optionally specify the mailbox in case none has been selected before or if another mailbox/folder should be queried.

but now that I did, it works. THANK YOU

await client.selectMailboxByPath(folder); // <-- this did the trick
await client.deleteMessage(messageEntry.key, expunge: false);
filly82 commented 7 months ago

still don't know why it worked when I just replaced folder 'Notes' with 'INBOX.FTagged.Wohnung'

robert-virkus commented 7 months ago

Thanks, this seems very much to be a bug in the API, because fetchMessages should then select the corresponding mailbox. I will check this and report back within the next days. Glad that you found a workaround!

robert-virkus commented 7 months ago

Hi again, I did not find a problem with mailbox selection when fetching messages. The used mailbox should have been selected correctly after issuing the fetchMessages call. However, I simplified the code and released v2.1.4, which also adds some more fixes and improvements. Can you test your deletion again with that version?

If you still run into the problem, I guess I need to learn more details about your code, specifically: what happens between fetching the messages and then requesting to delete a non-inbox message?

filly82 commented 7 months ago

sorry for the inconvenience. I was not able to reproduce the problem with minimal code. everything worked as expected. so the problem have to be on my side even although I am not seeing it on first sight. I guess I will also have to simplify my code in order to understand what I did wrong. again sorry and thanks for the help.