0 votes
by (180 points)

Hello, we have a problem with purge method.
We are connecting to outlook.office365.com and when we receive email, then are calling "DeleteMessage(idx)" and then Purge. The exception after Purge method is "EXPUNGE failed (NO)."
I try UnselectFolder(true) - there no exception but the inbox are not cleared.
We have Rebex version 6.0.8232.0

by (180 points)
2023-01-06 12:29:04.643 Opening log file.
2023-01-06 12:29:04.648 INFO FileLogWriter(1)[23] Info: Assembly: Rebex.Common R6.5 for .NET 4.0-4.8
2023-01-06 12:29:04.649 INFO FileLogWriter(1)[23] Info: Platform: Windows 6.2.9200 64-bit; CLR: 4.0.30319.42000
2023-01-06 12:29:04.650 DEBUG FileLogWriter(1)[23] Info: Culture: cs; windows-1250
2023-01-06 12:29:04.661 DEBUG Imap(1)[23] Info: State changed from 'Disconnected' to 'Connecting'.
2023-01-06 12:29:04.661 INFO Imap(1)[23] Info: Connecting to outlook.office365.com:993 using Imap.
2023-01-06 12:29:04.662 INFO Imap(1)[23] Info: Assembly: Rebex.Imap R6.5 for .NET 4.0-4.8
2023-01-06 12:29:04.662 INFO Imap(1)[23] Info: Platform: Windows 6.2.9200 64-bit; CLR: 4.0.30319.42000
2023-01-06 12:29:04.662 DEBUG Imap(1)[23] Info: Culture: cs; windows-1250
2023-01-06 12:29:04.693 INFO Imap(1)[23] Info: Connecting to 40.99.150.114.
2023-01-06 12:29:04.722 DEBUG Imap(1)[23] Proxy: Connecting to 40.99.150.114:993 (no proxy).
2023-01-06 12:29:04.748 DEBUG Imap(1)[23] Proxy: Connection established.
2023-01-06 12:29:04.749 DEBUG Imap(1)[23] Info: Connection succeeded.
2023-01-06 12:29:04.755 DEBUG Imap(1)[23] Info: Upgrading connection to TLS.
2023-01-06 12:29:04.876 DEBUG Imap(1)[23] TLS: Using classic TLS core.
2023-01-06 12:29:04.907 DEBUG Imap(1)[23] TLS: Enabled cipher suites: 0x000F3DF7EBE00640.
2023-01-06 12:29:05.010 DEBUG Imap(1)[23] TLS: Applicable cipher suites: 0x000F3DF7EBE00640.
2023-01-06 12:29:05.025 DEBUG Imap(1)[23] TLS: HandshakeMessage:ClientHello was sent.
2023-01-06 12:29:05.073 DEBUG Imap(1)[23] TLS: HandshakeMessage:ServerHello was received.
2023-01-06 12:29:05.074 INFO Imap(1)[23] TLS: Negotiating TLS 1.2, RSA with ephemeral ECDH, AES with 256-bit key in GCM mode, AEAD.
2023-01-06 12:29:05.078 DEBUG Imap(1)[23] TLS: The server supports secure renegotiation.
2023-01-06 12:29:05.079 DEBUG Imap(1)[23] TLS: Extended master secret is enabled.
2023-01-06 12:29:05.081 DEBUG Imap(1)[23] TLS: HandshakeMessage:Certificate was received.
2023-01-06 12:29:05.101 DEBUG Imap(1)[23] TLS: HandshakeMessage:ServerKeyExchange was received.
2023-01-06 12:29:05.101 DEBUG Imap(1)[23] TLS: HandshakeMessage:ServerHelloDone was received.
2023-01-06 12:29:05.106 DEBUG Imap(1)[23] TLS: Verifying server certificate ('CN=outlook.com, O=Microsoft Corporation, L=Redmond, S=Washington, C=US').
2023-01-06 12:29:05.164 DEBUG Imap(1)[23] TLS: Certificate verification result: Accept
2023-01-06 12:29:05.166 DEBUG Imap(1)[23] TLS: Verifying server key exchange signature.
2023-01-06 12:29:05.200 DEBUG Imap(1)[23] TLS: Using ephemeral ECDH public key exchange with NIST P-384 curve.
2023-01-06 12:29:05.207 DEBUG Imap(1)[23] TLS: HandshakeMessage:ClientKeyExchange was sent.
2023-01-06 12:29:05.224 DEBUG Imap(1)[23] TLS: CipherSpec:ChangeCipherSpec was sent.
2023-01-06 12:29:05.225 DEBUG Imap(1)[23] TLS: HandshakeMessage:Finished was sent.
2023-01-06 12:29:05.256 DEBUG Imap(1)[23] TLS: CipherSpec:ChangeCipherSpec was received.
2023-01-06 12:29:05.258 DEBUG Imap(1)[23] TLS: HandshakeMessage:Finished was received.
2023-01-06 12:29:05.259 INFO Imap(1)[23] TLS: Connection secured using cipher: TLS 1.2, RSA with ephemeral ECDH, AES with 256-bit key in GCM mode, AEAD.
2023-01-06 12:29:05.260 DEBUG Imap(1)[23] Info: Connection upgraded to TLS 1.2.
2023-01-06 12:29:05.326 DEBUG Imap(1)[23] Info: State changed from 'Connecting' to 'Reading'.
2023-01-06 12:29:05.331 INFO Imap(1)[23] Response: * OK The Microsoft Exchange IMAP4 service is ready. [RgBSADAAUAAyADgAMQBDAEEAMAAwADkAMQAuAEQARQBVAFAAMgA4ADEALgBQAFIATwBEAC4ATwBVAFQATABPAE8ASwAuAEMATwBNAA==]
2023-01-06 12:29:05.341 DEBUG Imap(1)[23] Info: State changed from 'Reading' to 'Ready'.
2023-01-06 12:29:05.365 DEBUG Imap(1)[23] Info: State changed from 'Ready' to 'Sending'.
2023-01-06 12:29:05.369 INFO Imap(1)[23] Command: R00001 CAPABILITY
2023-01-06 12:29:05.370 DEBUG Imap(1)[23] Info: State changed from 'Sending' to 'Reading'.
2023-01-06 12:29:05.391 INFO Imap(1)[23] Response: * CAPABILITY IMAP4 IMAP4rev1 AUTH=PLAIN AUTH=XOAUTH2 SASL-IR UIDPLUS ID UNSELECT CHILDREN IDLE NAMESPACE LITERAL+
2023-01-06 12:29:05.391 INFO Imap(1)[23] Response: R00001 OK CAPABILITY completed.
2023-01-06 12:29:05.391 DEBUG Imap(1)[23] Info: State changed from 'Reading' to 'Ready'.
2023-01-06 12:29:17.322 DEBUG Imap(1)[23] Info: State changed from 'Ready' to 'Sending'.
2023-01-06 12:29:17.322 INFO Imap(1)[23] Command: R00002 AUTHENTICATE XOAUTH2 XXX
2023-01-06 12:29:17.322 DEBUG Imap(1)[23] Info: State changed from 'Sending' to 'Reading'.
2023-01-06 12:29:18.098 INFO Imap(1)[23] Response: R00002 OK AUTHENTICATE completed.
2023-01-06 12:29:18.098 DEBUG Imap(1)[23] Info: State changed from 'Reading' to 'Ready'.
2023-01-06 12:29:22.999 DEBUG Imap(1)[23] Info: State changed from 'Ready' to 'Sending'.
2023-01-06 12:29:22.999 INFO Imap(1)[23] Command: R00003 LIST "" inbox
2023-01-06 12:29:22.999 DEBUG Imap(1)[23] Info: State changed from 'Sending' to 'Reading'.
2023-01-06 12:29:23.056 INFO Imap(1)[23] Response: * LIST (\Marked \HasChildren) "/" INBOX
2023-01-06 12:29:23.056 INFO Imap(1)[23] Response: R00003 OK LIST completed.
2023-01-06 12:29:23.056 DEBUG Imap(1)[23] Info: State changed from 'Reading' to 'Ready'.
2023-01-06 12:29:23.278 DEBUG Imap(1)[23] Info: State changed from 'Ready' to 'Sending'.
2023-01-06 12:29:23.278 INFO Imap(1)[23] Command: R00004 STATUS inbox (UNSEEN)
2023-01-06 12:29:23.278 DEBUG Imap(1)[23] Info: State changed from 'Sending' to 'Reading'.
2023-01-06 12:29:23.318 INFO Imap(1)[23] Response: * STATUS INBOX (UNSEEN 8)
2023-01-06 12:29:23.318 INFO Imap(1)[23] Response: R00004 OK STATUS completed.
2023-01-06 12:29:23.318 DEBUG Imap(1)[23] Info: State changed from 'Reading' to 'Ready'.
2023-01-06 12:29:23.325 DEBUG Imap(1)[23] Info: State changed from 'Ready' to 'Sending'.
2023-01-06 12:29:23.325 INFO Imap(1)[23] Command: R00005 SELECT inbox
2023-01-06 12:29:23.325 DEBUG Imap(1)[23] Info: State changed from 'Sending' to 'Reading'.
2023-01-06 12:29:23.411 INFO Imap(1)[23] Response: * 927 EXISTS
2023-01-06 12:29:23.411 INFO Imap(1)[23] Response: * 0 RECENT
2023-01-06 12:29:23.411 INFO Imap(1)[23] Response: * FLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)
2023-01-06 12:29:23.411 INFO Imap(1)[23] Response: * OK [PERMANENTFLAGS (\Seen \Answered \Flagged \Deleted \Draft $MDNSent)] Permanent flags
2023-01-06 12:29:23.411 INFO Imap(1)[23] Response: * OK [UNSEEN 920] Is the first unseen message
2023-01-06 12:29:23.411 INFO Imap(1)[23] Response: * OK [UIDVALIDITY 14] UIDVALIDITY value
2023-01-06 12:29:23.411 INFO Imap(1)[23] Response: * OK [UIDNEXT 848407] The next unique identifier value
2023-01-06 12:29:23.411 INFO Imap(1)[23] Response: R00005 OK [READ-WRITE] SELECT completed.
2023-01-06 12:29:23.411 DEBUG Imap(1)[23] Info: State changed from 'Reading' to 'Ready'.
2023-01-06 12:29:23.463 DEBUG Imap(1)[23] Info: State changed from 'Ready' to 'Sending'.
2023-01-06 12:29:23.463 INFO Imap(1)[23] Command: R00006 FETCH 1:* (UID RFC822.SIZE FLAGS INTERNALDATE ENVELOPE)
2023-01-06 12:29:23.463 DEBUG Imap(1)[23] Info: State changed from 'Sending' to 'Reading'.
2023-01-06 12:29:23.957 INFO Imap(1)[23] Response: * 1 FETCH (UID 844959 RFC822.SIZE 1756536 FLAGS (\Seen \Deleted) INTERNALDATE "05-Jan-2023 13:49:04 +0100" ENVELOPE ("Thu, 5 Jan 2023 12:48:53 +0000" "=?UTF-8?Q?Foto_m=C4=9B=C5=99idla_27ZG600Z0628705F?=" ((NIL NIL "stanislav" "istvanek.name")) NIL NIL ((NIL NIL "mnd" "mnd.cz")) NIL NIL NIL "<63b6c7356253f_6f6b3ff9f14f00301743c@c8c8e181a16a.mail>"))
....
2023-01-06 12:29:39.560 INFO Imap(1)[23] Response: R00006 OK FETCH completed.
2023-01-06 12:29:39.560 DEBUG Imap(1)[23] Info: State changed from 'Reading' to 'Ready'.
2023-01-06 12:29:48.571 DEBUG Imap(1)[23] Info: State changed from 'Ready' to 'Sending'.
2023-01-06 12:29:48.571 INFO Imap(1)[23] Command: R00007 FETCH 927 (BODY[])
2023-01-06 12:29:48.571 DEBUG Imap(1)[23] Info: State changed from 'Sending' to 'Reading'.
2023-01-06 12:29:48.761 INFO Imap(1)[23] Response: * 927 FETCH (BODY[] {3910270}
2023-01-06 12:29:49.792 INFO Imap(1)[23] Response: ...3910270 bytes...
2023-01-06 12:29:49.792 INFO Imap(1)[23] Response:  FLAGS (\Seen))
2023-01-06 12:29:49.792 INFO Imap(1)[23] Response: * 1 RECENT
2023-01-06 12:29:49.792 INFO Imap(1)[23] Response: R00007 OK FETCH completed.
2023-01-06 12:29:49.792 DEBUG Imap(1)[23] Info: State changed from 'Reading' to 'Ready'.
2023-01-06 12:29:54.028 DEBUG Imap(1)[23] Info: State changed from 'Ready' to 'Sending'.
2023-01-06 12:29:54.029 INFO Imap(1)[23] Command: R00008 FETCH 927 (UID)
2023-01-06 12:29:54.029 DEBUG Imap(1)[23] Info: State changed from 'Sending' to 'Reading'.
2023-01-06 12:29:54.063 INFO Imap(1)[23] Response: * 927 FETCH (UID 848404)
2023-01-06 12:29:54.127 INFO Imap(1)[23] Response: R00008 OK FETCH completed.
2023-01-06 12:29:54.127 DEBUG Imap(1)[23] Info: State changed from 'Reading' to 'Ready'.
2023-01-06 12:30:26.640 DEBUG Imap(1)[23] Info: State changed from 'Ready' to 'Sending'.
2023-01-06 12:30:26.640 INFO Imap(1)[23] Command: R00009 STORE 927 +FLAGS (\Deleted)
2023-01-06 12:30:26.640 DEBUG Imap(1)[23] Info: State changed from 'Sending' to 'Reading'.
2023-01-06 12:30:26.719 INFO Imap(1)[23] Response: * 2 RECENT
2023-01-06 12:30:26.719 INFO Imap(1)[23] Response: * 927 FETCH (FLAGS (\Seen \Deleted))
2023-01-06 12:30:26.719 INFO Imap(1)[23] Response: R00009 OK STORE completed.
2023-01-06 12:30:26.720 DEBUG Imap(1)[23] Info: State changed from 'Reading' to 'Ready'.
2023-01-06 12:30:32.667 DEBUG Imap(1)[23] Info: State changed from 'Ready' to 'Sending'.
2023-01-06 12:30:32.667 INFO Imap(1)[23] Command: R0000A FETCH 927 (UID)
2023-01-06 12:30:32.667 DEBUG Imap(1)[23] Info: State changed from 'Sending' to 'Reading'.
2023-01-06 12:30:32.703 INFO Imap(1)[23] Response: * 927 FETCH (UID 848404)
2023-01-06 12:30:32.777 INFO Imap(1)[23] Response: R0000A OK FETCH completed.
2023-01-06 12:30:32.777 DEBUG Imap(1)[23] Info: State changed from 'Reading' to 'Ready'.
2023-01-06 12:30:33.974 DEBUG Imap(1)[23] Info: State changed from 'Ready' to 'Sending'.
2023-01-06 12:30:33.974 INFO Imap(1)[23] Command: R0000B UID EXPUNGE 848404
2023-01-06 12:30:33.974 DEBUG Imap(1)[23] Info: State changed from 'Sending' to 'Reading'.
2023-01-06 12:30:34.067 INFO Imap(1)[23] Response: * 928 EXISTS
2023-01-06 12:30:34.140 INFO Imap(1)[23] Response: * 928 EXISTS
2023-01-06 12:30:34.140 INFO Imap(1)[23] Response: R0000B NO EXPUNGE failed.
2023-01-06 12:30:34.140 DEBUG Imap(1)[23] Info: State changed from 'Reading' to 'Ready'.
2023-01-06 12:30:34.157 ERROR Imap(1)[23] Info: Rebex.Net.ImapException: EXPUNGE failed (NO).
   v Rebex.Net.Imap.fzsmv(String p0, ImapResponse p1, Boolean p2)
   v Rebex.Net.Imap.bldkc(String p0, Object[] p1)
   v Rebex.Net.Imap.ptycq(ImapMessageSet p0)
2023-01-06 12:31:09.232 DEBUG Imap(1)[23] Info: State changed from 'Ready' to 'Sending'.
2023-01-06 12:31:09.232 INFO Imap(1)[23] Command: R0000C CLOSE
2023-01-06 12:31:09.232 DEBUG Imap(1)[23] Info: State changed from 'Sending' to 'Reading'.
2023-01-06 12:31:12.152 INFO Imap(1)[23] Response: R0000C OK CLOSE completed.
2023-01-06 12:31:12.152 DEBUG Imap(1)[23] Info: State changed from 'Reading' to 'Ready'.

1 Answer

0 votes
by (73.5k points)

From the client's side of view, the command is correct, see RFC 9051 (UID command).

I have also tried the UID EXPUNGE on our testing Exchange 2019 and it works fine:

Command: R00007 FETCH 1:3 (UID FLAGS)
Response: * 1 FETCH (UID 307533 FLAGS ())
Response: * 2 FETCH (UID 307544 FLAGS (\Deleted))
Response: * 3 FETCH (UID 307545 FLAGS ())
Response: R00007 OK FETCH completed.

Command: R00008 UID EXPUNGE 307544
Response: * 2 EXPUNGE
Response: * 5 EXISTS
Response: R00008 OK EXPUNGE completed.

Is it possible that the connected user has no permission to delete messages or modify the mailbox?

Can you please try to call the Imap.Purge() method with no arguments - this should remove all messages marked with \Delete flag from the mailbox. If this does not work as well, I would suggest you to search for a permission setting or similar configuration specific cause of the issue. You can also contact Microsoft's support to get more details why the server rejects to remove messages.

One more idea: you can also try to delete the message from OWA (Outlook Web Access/App) - it does not use IMAP - if you are not able to delete the message there (using the same user), it is definitely a permission-like issue.

...