Unable to delete or move a message via IMAP
Asked Answered
S

1

7

I am trying to move a message to another folder in a mail box using the IMAP functionality of ae.net.mail. The problem is that although the message is moved into the target folder, it is not removed from INBOX.

I'm also having a problem deleting a message. In this case I'm finding that the status of the message merely changes from unseen to seen.

Here is what I have tried:

using (ImapClient ic = new ImapClient(
    host, email, password, ImapClient.AuthMethods.Login, 993, true))
{
     ic.SelectMailbox("INBOX");
     string[] uids = ic.Search(SearchCondition.From("[email protected]"));

     MailMessage[] messages =
         ic.GetMessages(uids[0], uids[uids.Length - 1], false);

     ic.MoveMessage(uids[0], "Junk");
}   
Sain answered 11/2, 2014 at 20:8 Comment(0)
I
5

The standard IMAP protocol does not have a MOVE command (but there is an extension that adds it). So, depending on your IMAP server, the client may need to implement MOVE as a UID COPY + UID STORE +FLAGS.SILENT (\Deleted) + UID EXPUNGE, but that assumes that the server supports the UIDPLUS extension. If the server doesn't support UIDPLUS, either, then it becomes essentially impossible to implement properly. All you can do is COPY + STORE +FLAGS.SILENT (\Deleted) but cannot do the EXPUNGE because there's no way to limit the messages that will get expunged (I suppose you could unmark any other deleted messages, then EXPUNGE, then re-mark them as \Deleted, but that starts to become risky).

This would explain why the messages might still exist in the INBOX (although they should be at least marked as deleted).

Not sure why marking a message as deleted is marking it as Seen. That seems like a bug in AE.NET.Mail.

Introduce answered 11/2, 2014 at 20:23 Comment(11)
there is a reported bug on the project site, github.com/andyedinborough/aenetmail/issues/7Loren
@jstedfast. There is another interesting thing going on. i am setting the flag of message to deleted, and guess what, it changes the status from seen to unseen. Must be some real magic going on inside ae.net.mailSain
Looks like AE.NET.Mail doesn't handle untagged responses to commands it sends :-\Introduce
@THunter: yea, I might recommend using my IMAP library instead: github.com/jstedfast/MailKit it's still in development, but it's better quality than AE.NET.Mail. I plan to make the APIs async, though, so be warned.Introduce
@Introduce i'm using s22.imap using delete or move just transfers mail to the other folder but does not delete or move from inbox.Assertion
i tried mailkit but getting some errors while connecting so stayed with s22.imap for a whileAssertion
To remove it from the inbox you need to Expunge()Introduce
@Introduce i have come across a issue, where i'm moving email to other folder from inbox, but when i view in owa in retrieve email from server on deleted folder, i can view all moved emails in it tooAssertion
You need to call Expunge() like I explained above.Introduce
at times i cannot see emails in inbox they are moved to deleted on server withouht being moved or processed.. i know you have written it clearly. but can you explain what expunge() does, is it risky to implement. how would it be helpful to implementAssertion
The EXPUNGE command purges deleted messages from your Inbox. It sounds to me like you need to read tools.ietf.org/html/rfc3501 so that you can get a basic understanding of how IMAP works. Then, what you can do is pass a new ProtocolLogger ("imap.log") asn an argument to the ImapClient constructor so that you can look at a log of what is going on.Introduce

© 2022 - 2024 — McMap. All rights reserved.