Skip to content

Commit

Permalink
fix(IMAP) rnwood#1126 (rnwood#1142)
Browse files Browse the repository at this point in the history
* Add test to reproduce rnwood#1126

* fix(IMAP): Fix rnwood#1126 disposed object exception when marking read
  • Loading branch information
rnwood authored Oct 23, 2022
1 parent 64231f1 commit e5404b3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
22 changes: 20 additions & 2 deletions Rnwood.Smtp4dev.Tests/E2E/E2ETests_Imap.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using LumiSoft.Net.Mime;
using MailKit;
using MailKit.Net.Imap;
using MailKit.Net.Smtp;
using MailKit.Security;
Expand Down Expand Up @@ -54,10 +55,27 @@ public void MessagesAvailable()
{
imapClient.Connect("localhost", context.ImapPortNumber);
imapClient.Authenticate("user", "password");
imapClient.Inbox.Open(MailKit.FolderAccess.ReadOnly);
var imapMessage = imapClient.Inbox.FirstOrDefault();
imapClient.Inbox.Open(MailKit.FolderAccess.ReadWrite);

var imapMessageSummary = imapClient.Inbox.Fetch(0, 0, MessageSummaryItems.UniqueId|MessageSummaryItems.Full);
Assert.Equal(messageSubject, imapMessageSummary[0].NormalizedSubject);
var imapMessage = imapClient.Inbox.GetMessage(imapMessageSummary[0].UniqueId);
Assert.NotNull(imapMessage);
Assert.Equal(messageSubject, imapMessage.Subject);

imapClient.Inbox.AddFlags(imapMessageSummary[0].UniqueId, MessageFlags.Seen, true);
imapClient.Inbox.Close();
}

using (ImapClient imapClient = new ImapClient())
{
imapClient.Connect("localhost", context.ImapPortNumber);
imapClient.Authenticate("user", "password");
imapClient.Inbox.Open(MailKit.FolderAccess.ReadWrite);

var imapMessageSummary = imapClient.Inbox.Fetch(0, 0, MessageSummaryItems.All);
Assert.True(imapMessageSummary[0].Flags.Value.HasFlag(MessageFlags.Seen));
imapClient.Inbox.Close();
}

});
Expand Down
4 changes: 2 additions & 2 deletions Rnwood.Smtp4dev/Server/ImapServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,12 +168,12 @@ private void Session_Store(object sender, IMAP_e_Store e)
{
if (e.Flags.Contains("Seen", StringComparer.OrdinalIgnoreCase))
{
messagesRepository.MarkMessageRead(new Guid(e.MessageInfo.ID));
messagesRepository.MarkMessageRead(new Guid(e.MessageInfo.ID)).Wait();
}

if (e.Flags.Contains("Deleted", StringComparer.OrdinalIgnoreCase))
{
messagesRepository.DeleteMessage(new Guid(e.MessageInfo.ID));
messagesRepository.DeleteMessage(new Guid(e.MessageInfo.ID)).Wait();
}
}
}
Expand Down

0 comments on commit e5404b3

Please sign in to comment.