diff --git a/UnitTests/Net/Imap/ImapFolderFetchTests.cs b/UnitTests/Net/Imap/ImapFolderFetchTests.cs index 02100d299b..32f694afac 100644 --- a/UnitTests/Net/Imap/ImapFolderFetchTests.cs +++ b/UnitTests/Net/Imap/ImapFolderFetchTests.cs @@ -1259,6 +1259,108 @@ public async Task TestFetchSimulatedPreviewTextAsync () } } + static List CreateFetchSimulatedKoreanPreviewTextCommands () + { + return new List { + new ImapReplayCommand ("", "gmail.greeting.txt"), + new ImapReplayCommand ("A00000000 CAPABILITY\r\n", "gmail.capability.txt"), + new ImapReplayCommand ("A00000001 AUTHENTICATE PLAIN AHVzZXJuYW1lAHBhc3N3b3Jk\r\n", "gmail.authenticate.txt"), + new ImapReplayCommand ("A00000002 NAMESPACE\r\n", "gmail.namespace.txt"), + new ImapReplayCommand ("A00000003 LIST \"\" \"INBOX\" RETURN (SUBSCRIBED CHILDREN)\r\n", "gmail.list-inbox.txt"), + new ImapReplayCommand ("A00000004 XLIST \"\" \"*\"\r\n", "gmail.xlist.txt"), + new ImapReplayCommand ("A00000005 LIST \"\" \"%\"\r\n", "gmail.list-personal.txt"), + new ImapReplayCommand ("A00000006 EXAMINE INBOX (CONDSTORE)\r\n", "gmail.examine-inbox.txt"), + new ImapReplayCommand ("A00000007 UID FETCH 1 (UID BODYSTRUCTURE)\r\n", "gmail.fetch-korean-previewtext-bodystructure.txt"), + new ImapReplayCommand ("A00000008 UID FETCH 1 (BODY.PEEK[TEXT]<0.512>)\r\n", "gmail.fetch-korean-previewtext-peek-text-only.txt"), + }; + } + + [Test] + public void TestFetchSimulatedKoreanPreviewText () + { + const string koreanPreviewText = "내 주제는 여기 안녕하세요 여러분, 모두 괜찮기를 바랍니다. 이번 주말에 어떤 계획을 갖고 있나요? 다들 빨리 보시길 바랄게요! 여행을 계획하는 아이디어가 있습니다. 네 생각을 말해봐. 또 봐요!"; + var commands = CreateFetchSimulatedKoreanPreviewTextCommands (); + + using (var client = new ImapClient () { TagPrefix = 'A' }) { + try { + client.Connect (new ImapReplayStream (commands, false), "localhost", 143, SecureSocketOptions.None); + } catch (Exception ex) { + Assert.Fail ($"Did not expect an exception in Connect: {ex}"); + } + + // Note: Do not try XOAUTH2 + client.AuthenticationMechanisms.Remove ("XOAUTH2"); + + try { + client.Authenticate ("username", "password"); + } catch (Exception ex) { + Assert.Fail ($"Did not expect an exception in Authenticate: {ex}"); + } + + // disable LIST-EXTENDED + client.Capabilities &= ~ImapCapabilities.ListExtended; + + var personal = client.GetFolder (client.PersonalNamespaces[0]); + var folders = personal.GetSubfolders (); + Assert.That (folders[0], Is.EqualTo (client.Inbox), "Expected the first folder to be the Inbox."); + Assert.That (folders[1].FullName, Is.EqualTo ("[Gmail]"), "Expected the second folder to be [Gmail]."); + Assert.That (folders[1].Attributes, Is.EqualTo (FolderAttributes.NoSelect | FolderAttributes.HasChildren), "Expected [Gmail] folder to be \\Noselect \\HasChildren."); + + var inbox = client.Inbox; + + inbox.Open (FolderAccess.ReadOnly); + + var messages = inbox.Fetch (new[] { new UniqueId (1) }, MessageSummaryItems.PreviewText); + Assert.That (messages.Count, Is.EqualTo (1), "Expected 1 message to be fetched."); + Assert.That (messages[0].PreviewText, Is.EqualTo (koreanPreviewText)); + + client.Disconnect (false); + } + } + + [Test] + public async Task TestFetchSimulatedKoreanPreviewTextAsync () + { + const string koreanPreviewText = "내 주제는 여기 안녕하세요 여러분, 모두 괜찮기를 바랍니다. 이번 주말에 어떤 계획을 갖고 있나요? 다들 빨리 보시길 바랄게요! 여행을 계획하는 아이디어가 있습니다. 네 생각을 말해봐. 또 봐요!"; + var commands = CreateFetchSimulatedKoreanPreviewTextCommands (); + + using (var client = new ImapClient () { TagPrefix = 'A' }) { + try { + await client.ConnectAsync (new ImapReplayStream (commands, true), "localhost", 143, SecureSocketOptions.None); + } catch (Exception ex) { + Assert.Fail ($"Did not expect an exception in Connect: {ex}"); + } + + // Note: Do not try XOAUTH2 + client.AuthenticationMechanisms.Remove ("XOAUTH2"); + + try { + await client.AuthenticateAsync ("username", "password"); + } catch (Exception ex) { + Assert.Fail ($"Did not expect an exception in Authenticate: {ex}"); + } + + // disable LIST-EXTENDED + client.Capabilities &= ~ImapCapabilities.ListExtended; + + var personal = client.GetFolder (client.PersonalNamespaces[0]); + var folders = await personal.GetSubfoldersAsync (); + Assert.That (folders[0], Is.EqualTo (client.Inbox), "Expected the first folder to be the Inbox."); + Assert.That (folders[1].FullName, Is.EqualTo ("[Gmail]"), "Expected the second folder to be [Gmail]."); + Assert.That (folders[1].Attributes, Is.EqualTo (FolderAttributes.NoSelect | FolderAttributes.HasChildren), "Expected [Gmail] folder to be \\Noselect \\HasChildren."); + + var inbox = client.Inbox; + + await inbox.OpenAsync (FolderAccess.ReadOnly); + + var messages = await inbox.FetchAsync (new[] { new UniqueId (1) }, MessageSummaryItems.PreviewText); + Assert.That (messages.Count, Is.EqualTo (1), "Expected 1 message to be fetched."); + Assert.That (messages[0].PreviewText, Is.EqualTo (koreanPreviewText)); + + await client.DisconnectAsync (false); + } + } + static List CreateFetchQuotedStringCommands () { return new List { diff --git a/UnitTests/Net/Imap/Resources/gmail/fetch-korean-previewtext-bodystructure.txt b/UnitTests/Net/Imap/Resources/gmail/fetch-korean-previewtext-bodystructure.txt new file mode 100644 index 0000000000..1c56e2256e --- /dev/null +++ b/UnitTests/Net/Imap/Resources/gmail/fetch-korean-previewtext-bodystructure.txt @@ -0,0 +1,2 @@ +* 1 FETCH (UID 1 BODYSTRUCTURE ("TEXT" "PLAIN" ("CHARSET" "ks_c_5601-1987") NIL NIL "BASE64" 280 4 NIL NIL NIL)) +A######## OK Success diff --git a/UnitTests/Net/Imap/Resources/gmail/fetch-korean-previewtext-peek-text-only.txt b/UnitTests/Net/Imap/Resources/gmail/fetch-korean-previewtext-peek-text-only.txt new file mode 100644 index 0000000000..69930f94da --- /dev/null +++ b/UnitTests/Net/Imap/Resources/gmail/fetch-korean-previewtext-peek-text-only.txt @@ -0,0 +1,6 @@ +* 1 FETCH (UID 1 BODY[TEXT]<0> {278} +s7sgwdbBprTCIL+pseINCg0KDQq+yLPnx8+8vL/kIL+pt6+60CwNCg0KuPC1ziCxpsL6seK4piC5 +2bb4tM+02S4gwMy5+CDB1ri7v6Egvu62siCw6Mi5wLsgsK6w7SDA1rOqv+Q/DQq02bXpILuhuK4g +uri9w7HmILnZtvaw1L/kIQ0KDQq/qcfgwLsgsOjIucfPtMIgvsbAzLXwvu6woSDA1r3AtM+02S4g +s9cgu/2wosC7ILi7x9i6wS4NCg0KtscgusG/5CENCg== ) +A######## OK Success