This project is read-only.

message.Seen = true isn't working properly

Topics: Issues
Jan 16, 2014 at 2:48 PM
Edited Jan 17, 2014 at 5:54 PM
Hi!
First, congrats for the lib, is really easy to use and get results very fast!,
but I'm experience some problems while marking messages as read.
I'm connecting to a zimbra mail server (version 8) with success, also i can download attachments, but the when i fetch "UNSEEN" messages and using Seen property the first time aren't marked at all, but a second time fetching the same mail it correctly marks as seen, so i'm a bit confused with this. I'm using imapx 2.0.0.15 for 4.0 .net framework

My code:
 Folder folderInbox = clienteCorreoImap.Folders.Inbox;
                    folderInbox.Messages.Download("UNSEEN", ImapX.Enums.MessageFetchMode.Tiny);
                    foreach (Message msj in folderInbox.Messages) {
foreach (Attachment adjunto in msj.Attachments)
                        {
adjunto.Download();
//saving the file, then i apply some custom processing

//finally i try to mark the message as read
msj.Seen = true;
}
}
i also tried with
msj.Seen = true;
msj.Flags.Add(ImapX.Flags.MessageFlags.Seen);
msj.Flags.Remove("UNSEEN");
With the same results: only the second time fetching and processing the UNSEEN mails they got correctly marked as seen.
I could use NEW or RECENT to fetch mails, but i need to keep track of mails which aren't correctly downloaded and processed its attachments (ie, keep them as unread/unseen), so that's why I'm using the UNSEEN tag.
If you could help me to enlight what I'm doing wrong here would be greatly appreciated

Thanks! And keep the good work!

-------------------------------EDIT------------------------------------------
As further info, i found something extra weird. If I fetch mails twice with tags "UNSEEN" and then "NEW", the second time operating over messages works as expected (mark as read/unread, move to trash or delete).
The thing i can't understand so far is WHY ???¿¿¿
Thanks again ;)
Jan 17, 2014 at 4:22 PM
I'm also seeing this behavior with a microsoft exchange server. I've tried the exact things you have hehe. It would be nice to see a fix for this, until then I'm going back to a previous version.
Coordinator
Jan 17, 2014 at 8:26 PM
Hi noivern, Phasze,

the issue seems strange to me, I don't experience any issues (tested with GMail and hMailServer). Can you provide the dollowing information:
  1. Which flags are inside the Message.Flags collection when you just requested the messages?
  2. What is the console output when client.IsDebug is set to true? (see sample)
Best regards,

Pavel
Jan 17, 2014 at 8:42 PM
Edited Jan 17, 2014 at 8:44 PM
Gmail works fine for me, it's only that exchange server that requires me to actually make two calls to get all the unseen messages and mark them seen.

on the call <messages>.Download("UNSEEN"); I see this error in the debug console. Setting IsDebug to true doesn't seem to add anything for me...

"A first chance exception of type 'System.FormatException' occurred in System.dll"


Here is the code I'm using as well:
    public static string[] getUnreadOutlook()
    {
        ImapClient imap = new ImapClient(host, 143, false, true);
        imap.IsDebug = true;
        var result = imap.Connect();
        if (!imap.Login(username, password))
        {
            Program.printInColor("Error logging into Exchange. ", ConsoleColor.Red);
            return null;
        }

        var messages = imap.Folders["INBOX"].Messages;
        messages.Download("UNSEEN");

        List<string> subjects = new List<string>();
        foreach (var mes in messages)
        {
            //mes.Flags.Add(ImapX.Flags.MessageFlags.Seen);
            mes.Seen = true;
            subjects.Add(mes.Subject);
        }

        return subjects.ToArray();
    }

Edit: the flag I see in the messages is "\Recent". Also a side note, if I mark a message unread and run this code it works fine and marks it as seen. If I email a new message in I have to run this code twice for it to be marked as seen.
Jan 17, 2014 at 9:11 PM
Hi Pavel!
As you requested, here is the output:
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\andy\documents\visual studio 2010\Projects\JugandoConIMAP\JugandoConIMAP\bin\Debug\JugandoConIMAP.vshost.exe'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'
The thread 'vshost.NotifyLoad' (0x10d8) has exited with code 0 (0x0).
The thread '<No Name>' (0x1eb4) has exited with code 0 (0x0).
The thread 'vshost.LoadReference' (0x13c4) has exited with code 0 (0x0).
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\andy\documents\visual studio 2010\Projects\JugandoConIMAP\JugandoConIMAP\bin\Debug\JugandoConIMAP.exe', Symbols loaded.
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\andy\documents\visual studio 2010\Projects\JugandoConIMAP\JugandoConIMAP\bin\Debug\ImapX.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.resources\v4.0_4.0.0.0_es_b77a5c561934e089\System.resources.dll'
A first chance exception of type 'System.FormatException' occurred in System.dll
A first chance exception of type 'System.FormatException' occurred in System.dll
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\mscorlib.resources\v4.0_4.0.0.0_es_b77a5c561934e089\mscorlib.resources.dll'
A first chance exception of type 'System.ArgumentNullException' occurred in mscorlib.dll
The thread '<No Name>' (0x1b00) has exited with code 0 (0x0).
The thread 'vshost.RunParkingWindow' (0x1d04) has exited with code 0 (0x0).
The thread '<No Name>' (0x1bd0) has exited with code 0 (0x0).
The program '[6892] JugandoConIMAP.vshost.exe: Program Trace' has exited with code 0 (0x0).
The program '[6892] JugandoConIMAP.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).
there is an exception :/


Also, as you can see, the only flag when fetching the mails for the very first time is: /Recent
Image


I have this little example project with the issue can be seen:
Playing with imap

Made with VS2010 and .net 4.0 framework.

I must remark that I'm currently connecting to a Zimbra custom own server, so maybe that could be the reason, but anyway, if you could look into it if i'm doing something wrong, it will be really nice to know.
Coordinator
Jan 18, 2014 at 11:13 AM
Hi noivern, Phasze,

guess I figured out the problem. Please try the followng code to mark your message as seen:
msg.Flags.Remove(MessageFlags.Recent);
msg.Seen = true;
If it works fine, I will provide a fix so you can ommit the removal of the recent flag in future.

Greets,

Pavel
Jan 20, 2014 at 12:48 PM
Edited Jan 20, 2014 at 12:58 PM
Hi again, Pavel:
Sorry the delay, weekend time :D, hope yours was fine too!


Sadly, I just tried your suggestion with no luck :(
msj.Flags.Remove(ImapX.Flags.MessageFlags.Recent);
msj.Seen = true;
The flag \Recent is still there even with the explicit remove. As always, this happens only the first time fetching an email.
Second time fetching it works flawless.

The output:
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Windows.Forms\v4.0_4.0.0.0__b77a5c561934e089\System.Windows.Forms.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Drawing\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Drawing.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System\v4.0_4.0.0.0__b77a5c561934e089\System.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.HostingProcess.Utilities.Sync\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.HostingProcess.Utilities.Sync.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\assembly\GAC_MSIL\Microsoft.VisualStudio.Debugger.Runtime\10.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.Debugger.Runtime.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\andy\documents\visual studio 2010\Projects\JugandoConIMAP\JugandoConIMAP\bin\Debug\JugandoConIMAP.vshost.exe'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Core\v4.0_4.0.0.0__b77a5c561934e089\System.Core.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml.Linq\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.Linq.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Data.DataSetExtensions\v4.0_4.0.0.0__b77a5c561934e089\System.Data.DataSetExtensions.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\Microsoft.CSharp\v4.0_4.0.0.0__b03f5f7f11d50a3a\Microsoft.CSharp.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Xml\v4.0_4.0.0.0__b77a5c561934e089\System.Xml.dll'
The thread 'vshost.NotifyLoad' (0x13b8) has exited with code 0 (0x0).
The thread '<No Name>' (0xf94) has exited with code 0 (0x0).
The thread 'vshost.LoadReference' (0xdec) has exited with code 0 (0x0).
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\andy\documents\visual studio 2010\Projects\JugandoConIMAP\JugandoConIMAP\bin\Debug\JugandoConIMAP.exe', Symbols loaded.
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Users\andy\documents\visual studio 2010\Projects\JugandoConIMAP\JugandoConIMAP\bin\Debug\ImapX.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.Configuration\v4.0_4.0.0.0__b03f5f7f11d50a3a\System.Configuration.dll'
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\System.resources\v4.0_4.0.0.0_es_b77a5c561934e089\System.resources.dll'
A first chance exception of type 'System.FormatException' occurred in System.dll
A first chance exception of type 'System.FormatException' occurred in System.dll
'JugandoConIMAP.vshost.exe' (Managed (v4.0.30319)): Loaded 'C:\Windows\Microsoft.Net\assembly\GAC_MSIL\mscorlib.resources\v4.0_4.0.0.0_es_b77a5c561934e089\mscorlib.resources.dll'
A first chance exception of type 'System.ArgumentNullException' occurred in mscorlib.dll
The thread 'vshost.RunParkingWindow' (0x1bc8) has exited with code 0 (0x0).
The thread '<No Name>' (0xc20) has exited with code 0 (0x0).
The program '[7876] JugandoConIMAP.vshost.exe: Program Trace' has exited with code 0 (0x0).
The program '[7876] JugandoConIMAP.vshost.exe: Managed (v4.0.30319)' has exited with code 0 (0x0).
Jan 20, 2014 at 3:56 PM
I also tried removing the Recent when I first saw it as well, but no luck.
Coordinator
Jan 23, 2014 at 10:03 AM
Sorry for the delay, I will test the issue this weekend and let you know if I can find the problem.

Greets,

Pavel
Jan 23, 2014 at 3:11 PM
Ok, don't worry.
I had to move to pop3 because of time schedules, but anyway i want to keep the imap option on the application, so I'm keeping an eye at this topic.
Keep the great job Pavel, and thanks again.
Coordinator
Jan 27, 2014 at 9:55 AM
Good day!

I mde another update of the source code, please check if marking the message as seen works fine now!

best regards,

Pavel
Jan 27, 2014 at 3:56 PM
Awesome, do you have a compiled file we could use or should we download and compile it ourselves?

~Phase
Jan 27, 2014 at 9:32 PM
When i got some time i'll try.

Thanks for the support Pavel!
Feb 25, 2014 at 4:32 PM
Noivern, have you tried this yet? I downloaded the latest source and I still have to check the emails twice to get them as seen.
Apr 16, 2014 at 10:15 PM
Working like a charm from the latest source I just pulled.