0 votes

Hello.

I'am working on a little IMAP application to allow users to manipulate the mails in several
IMAP accounts (a mini Outlook app).

The first version allows the user to manipulate one account at a time.
All was fine. Perfect. Your component is amazing!

I am working in a second version that allows the user to work with several accounts at the same time.
I have an open Imap object for each account.

All is working well except deleting and moving messages to trash.
Before deleting a message I select the folder where the message is located.
In these commands it appears a 'Permission denied' error.

To test the app I'm working with three IMAP accounts at the same time.
At start I open the applications with these sequence:

1) open connection to imap server
2) read the folders on imap server and syncrhronize with local database
3) for each folder I read the uids of all messages and syncrhonize with local database

Once initialization is complete the uses can select any folder on any account to display the messages on that folder.
I read parts of the message when is needed, using the Imap object corresponding to the folder.

All seems correct, but the problem arises at deleting.

I only can delete from the last open IMAP account.
It seems that the last account writes something on memory, is there something static on your code?

by

1 Answer

0 votes

Two Imap instances don't share any state (there are no static variables on Imap class).

I don't think this is a bug in Mail.dll:

using (Imap imap1 = new Imap())
using (Imap imap2 = new Imap())
{
    imap1.ConnectSSL("imap.gmail.com");
    imap1.UseBestLogin("a@gmail.com", "");

    imap2.ConnectSSL("imap.gmail.com");
    imap2.UseBestLogin("b@gmail.com", "");

    imap1.SelectInbox();
    imap2.Select(new CommonFolders(imap2.GetFolders()).Sent);

    Assert.AreEqual("INBOX"            , imap1.CurrentFolder?.Name);
    Assert.AreEqual("[Gmail]/Sent Mail", imap2.CurrentFolder?.Name);

    imap1.Close();
    imap2.Close();
}

My guess is that either your server changes UIDs between sessions -or- you try to delete emails from incorrect mailbox.

by (297k points)
edited by
You must be right, but its strange.

Before deleting a message, the property CurrentFolder of ther Imap object is a folder different
that the folder of the message.

I try to change the current folder (with method Select(FolderInfo), but the value of the property CurrentFolder
does not change. How must change this property?
Arggg, I know where is the problem!!!

I am working with 3 accounts stored in the same IMAP server (it is a shared email system).
I use 3 Imap objects but all 3 connects to the same imap server, with different credentials.

It seems that the Imap instances are mixing some properties internally.

On any Imap instance I see the same CurrentFolder value, the last selected folder.
As I said: there is no shared state between Imap object instances.
...