0 votes

When trying to delete messages from an outlook.com account I'm getting the following message when I try to delete. Doesn't matter if with single UID, collection of UIDS, Junk folders nor Inbox. Not finding any kind of setting that blocks it on the account. Any input would be appreciated, thanks

Command received in Invalid state.
at Limilabs.Client.IMAP.Imap.  (ImapCommand command, Boolean throwException)
at Limilabs.Client.IMAP.Imap.  ​(SequenceSet sequence, Boolean silent, Flag flag)
at Limilabs.Client.IMAP.Imap.   (List1 uids, Boolean silent, Flag flag) at Limilabs.Client.IMAP.Imap.DeleteMessageByUID(List1 uids)
at MW.GoodWords.Win.EmailDownloader.Engines.AccountProcessor.ProcessUids(Imap imap, List`1 uids, Boolean isJunk)

by (410 points)
How does your code look like?
Connection:

imap.Connect(_ctx.Host, _ctx.Port, true);
imap.UseBestLogin(_account.UserName, _account.Password);

Move to folder:

imap.ExamineInbox();

Enumerate UIDs:

var uids = imap.Search().Where(Expression.SentSince(_ctx.LastMessageDate))

Get all flags and envelopes:

var allFlags = imap.GetFlagsByUID(uids);
var allEnvelopes = imap.GetEnvelopeByUID(uids);

Based on specific rules I delete some:

imap.DeleteMessageByUID(uid);

1 Answer

+1 vote
 
Best answer

You need to use Imap.Select or Imap.SelectInbox.

Imap.Examine and Imap.ExaminInbox use EXAMINE IMAP command which selects the folder in read-only mode - thus server forbids the client email deletion.

2nd most likely reason is that this account is being throttled:
https://blogs.msdn.microsoft.com/exchangedev/2011/06/23/exchange-online-throttling-and-limits-faq/

by (297k points)
selected by
Doesn't look like thats the case. Have tried with 3 different accounts all with the same issue. 1 of them hasn't been accessed in days by any means.
See modified answer after you posted the code.
Examine() was my problem. D'Oh!

Thanks
...