-
-
Notifications
You must be signed in to change notification settings - Fork 818
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Message is not marked as seen #153
Comments
Add a ProtocolLogger to your ImapClient constructor to get a log of the IMAP protocol transaction to see what is going on. using (var client = new ImapClient (new ProtocolLogger ("imap.log"))) {
client.Connect (...);
client.Authenticate (...);
var inbox = client.Inbox;
var sent = ...;
inbox.Open (FolderAccess.ReadWrite);
var messages = inbox.Fetch (...);
// why are you using SortableSubject here? This is only meant to be used for sorting purposes
// and is not necessarily the actual subject of the message. What you probably want is
// info.Envelope.Subject instead.
var info = messages.FirstOrDefault(item => item.SortableSubject == sentFiles[i]);
if (info != null) {
inbox.SetFlags(info.UniqueId.Value, MessageFlags.Seen, true);
inbox.MoveTo(info.UniqueId.Value, sent);
}
} My bet is that MailKit is in fact marking the message as Seen assuming it is even matching the message you expect. |
I've replaced here some info that seems confidential with underscore signs. |
What is the value of inbox.PermanentFlags? |
None |
That's the problem, then... but no idea why it is None. This works perfectly fine in my unit tests. |
Probably you can register a mailbox on mail.ru and test it on your own. I can't give you the full log or the full program :( |
I've just pasted the following snippet into my Unit Tests and it works fine:
|
I can't read Russian so there's no way I'm going to figure out how to create an account on mail.ru's website. |
Ok, i can register the test account and submit the credentials to you. |
Thanks. |
I've submitted the message to your mail address. |
Awesome, thanks. I'll see if I can debug this using the mail.ru account... |
This is very odd. I used the following test program and it worked as expected: using System;
using System.Linq;
using MailKit.Net.Imap;
using MailKit;
using MimeKit;
namespace TestClient {
class Program
{
public static void Main (string[] args)
{
var logger = new ProtocolLogger (Console.OpenStandardError ());
using (var client = new ImapClient (logger)) {
client.Connect ("imap.mail.ru", 993, true);
Console.WriteLine ("Capabilities = {0}", client.Capabilities);
client.AuthenticationMechanisms.Remove ("XOAUTH2");
client.Authenticate ("xxx", "xxx");
Console.WriteLine ("Capabilities = {0}", client.Capabilities);
var inbox = client.Inbox;
inbox.Open (FolderAccess.ReadWrite);
Console.WriteLine ("PermanentFlags = {0}", inbox.PermanentFlags);
Console.WriteLine ("AcceptedFlags = {0}", inbox.AcceptedFlags);
var items = MessageSummaryItems.Full | MessageSummaryItems.UniqueId;
var messages = inbox.Fetch (0, -1, items);
var info = messages.FirstOrDefault (x => x.Envelope.Subject == "Test 1");
if (info != null)
inbox.SetFlags (info.UniqueId.Value, MessageFlags.Seen, true);
client.Disconnect (true);
}
}
}
} The log is as follows:
I wonder if the bug you are seeing has something to do with your locale charset. I assume that it's iso-8859-5, koi8-r or windows-cp1251 or something other than UTF-8, correct? |
This program also works fine on my computer. This is very strange... |
Hmmm, not sure that would matter... ImapStream's ReadToken() logic is all ascii-based anyway (at least for flags), it just casts bytes to chars, so there's no way that this should be a charset conversion issue there unless switch statements on strings are problematic? The code to map flag strings to enum bits looks like this: string flag = (string) token.Value;
switch (flag) {
case "\\Answered": flags |= MessageFlags.Answered; break;
case "\\Deleted": flags |= MessageFlags.Deleted; break;
case "\\Draft": flags |= MessageFlags.Draft; break;
case "\\Flagged": flags |= MessageFlags.Flagged; break;
case "\\Seen": flags |= MessageFlags.Seen; break;
case "\\Recent": flags |= MessageFlags.Recent; break;
} The only thing I can think of is that the CurrentCulture has some effect on the switch statement above that is making it not work as expected. I would expect, though, that it wouldn'tmatter... at least for koi8-r since koi8-r still contains the ASCII subset which is all that is being compared ehre and afaik has no Hungarian-i-like oddities. |
I've found the problem. Before inbox folder processing I've opened 'Sent' folder and haven't closed it. I've added sent.Close() and now everything works fine. But I think a exception should be raised if such a situation leads to errors. |
Can you give me some pseudo code? I'm confused about the sent folder thing. |
This code gives the described problem. |
Okay, thanks. |
…er folder was selected Instead, set the previously selected folder's PermFlags to None. D'oh! Fixes issue #153
Thanks, that revealed the bug in ImapFolder.Open() clear as day. I've fixed my think-o in the code now, so all should be good. |
Can you publish the new version in the Nuget? |
Sure. Just published 1.0.8 to NuGet. |
I'm trying to work with mail.ru via IMAP. I've wrote the code like
to mark a message as seen and move it to the "Sent" folder, but after executing of this code the message remains unseen (through moving of the message works). Maybe is it a bug in MailKit? Please check it.
The text was updated successfully, but these errors were encountered: