public void TestBuildExample2() { var b = new ImapUriBuilder(); b.Scheme = "imap"; b.Host = "psicorp.example.org"; b.Mailbox = "~peter/日本語/台北"; Assert.AreEqual(new Uri("imap://psicorp.example.org/~peter/%E6%97%A5%E6%9C%AC%E8%AA%9E/%E5%8F%B0%E5%8C%97"), b.Uri); }
public void TestBuildExample4() { var b = new ImapUriBuilder(); b.Scheme = "imap"; b.Host = "minbari.example.org"; b.AuthType = ImapAuthenticationMechanism.SelectAppropriate; b.Mailbox = "gray council"; b.SearchCriteria = new SearchQuery("SUBJECT shadows"); Assert.AreEqual(new Uri("imap://;AUTH=*@minbari.example.org/gray%20council?SUBJECT%20shadows"), b.Uri); }
public void TestBuildExample1() { var b = new ImapUriBuilder(); b.Scheme = "imap"; b.Host = "minbari.example.org"; b.Mailbox = "gray-council"; b.UidValidity = 385759045L; b.Uid = 20L; b.Partial = new ImapPartialRange(0L, 1024L); Assert.AreEqual(new Uri("imap://minbari.example.org/gray-council;UIDVALIDITY=385759045/;UID=20/;PARTIAL=0.1024"), b.Uri); }
public void TestBuildExample3() { var b = new ImapUriBuilder(); b.Scheme = "imap"; b.Host = "minbari.example.org"; b.AuthType = ImapAuthenticationMechanism.Gssapi; b.Mailbox = "gray-council"; b.Uid = 20; b.Section = "1.2"; Assert.AreEqual(new Uri("imap://;[email protected]/gray-council/;UID=20/;SECTION=1.2"), b.Uri); }
public void TestBuildListsOfMessagesFormUri() { var b = new ImapUriBuilder("imap://localhost/", "INBOX"); Assert.AreEqual(new Uri("imap://localhost/INBOX"), b.Uri); b.SearchCriteria = new SearchQuery("ALL"); Assert.AreEqual(new Uri("imap://localhost/INBOX?ALL"), b.Uri); b.UidValidity = 12345L; Assert.AreEqual(new Uri("imap://localhost/INBOX;UIDVALIDITY=12345?ALL"), b.Uri); b.SearchCriteria = null; Assert.AreEqual(new Uri("imap://localhost/INBOX;UIDVALIDITY=12345"), b.Uri); b.UidValidity = 0L; Assert.AreEqual(new Uri("imap://localhost/INBOX"), b.Uri); }
protected ImapWebResponse GetCopyResponse(ImapSequenceSet requestUidSet) { ImapCopiedUidSet copiedUids; ImapMailbox createdMailbox = null; var mailbox = GetDestinationMailbox(); var response = new ImapWebResponse(AllowCreateMailbox ? Session.Copy(requestUidSet, mailbox, out copiedUids, out createdMailbox) : Session.Copy(requestUidSet, mailbox, out copiedUids)); if (response.Result.Succeeded) { if (createdMailbox != null) { if (Subscription) { Session.Subscribe(createdMailbox); Session.Lsub(createdMailbox); } else { Session.List(createdMailbox); } response.Mailboxes = new[] {createdMailbox}; } if (copiedUids != null) { var builder = new ImapUriBuilder(DestinationUri); builder.UidValidity = copiedUids.UidValidity; if (copiedUids.AssignedUidSet.IsSingle) builder.Uid = copiedUids.AssignedUidSet.ToNumber(); else builder.SearchCriteria = ImapSearchCriteria.Uid(copiedUids.AssignedUidSet); response.SetResponseUri(builder.Uri); } } return response; }
public void TestBuildServerFormUri() { var b = new ImapUriBuilder(); b.Host = "imap.example.net"; Assert.AreEqual(new Uri("imap://imap.example.net/"), b.Uri); b.Port = 10143; Assert.AreEqual(new Uri("imap://imap.example.net:10143/"), b.Uri); b.UserName = "******"; Assert.AreEqual(new Uri("imap://[email protected]:10143/"), b.Uri); b.AuthType = ImapAuthenticationMechanism.CRAMMD5; Assert.AreEqual(new Uri("imap://user;[email protected]:10143/"), b.Uri); b.Scheme = "imaps"; Assert.AreEqual(new Uri("imaps://user;[email protected]:10143/"), b.Uri); b.Scheme = "IMAP"; Assert.AreEqual(new Uri("imap://user;[email protected]:10143/"), b.Uri); b.UserName = null; Assert.AreEqual(new Uri("imap://;[email protected]:10143/"), b.Uri); b.Port = 143; Assert.AreEqual(new Uri("imap://;[email protected]:143/"), b.Uri); b.Port = 0; Assert.AreEqual(new Uri("imap://;[email protected]:0/"), b.Uri); b.Port = -1; Assert.AreEqual(new Uri("imap://;[email protected]/"), b.Uri); }
public void TestConstructFromUriWithQueryParser() { var uri = "imap://localhost/INBOX?FROM {12+}\r\nfrom address"; var b = new ImapUriBuilder(uri, SearchQuery.FromUri); Assert.IsNotNull(b.SearchCriteria); Assert.IsInstanceOfType(typeof(SearchQuery), b.SearchCriteria); Assert.AreEqual(new Uri("imap://localhost/INBOX?FROM%20%7B12+%7D%0D%0Afrom%20address"), b.Uri); }
public void TestConstructFromUriWithoutQueryParser() { var uri = "imap://localhost/INBOX?FROM {12+}\r\nfrom address"; var b = new ImapUriBuilder(uri); Assert.IsNull(b.SearchCriteria); Assert.AreEqual(new Uri("imap://localhost/INBOX"), b.Uri); }
/// <summary>Infrastructure. It is not intended to be used directly from your code.</summary> void IImapUrl.SetBaseUrl(ImapUriBuilder baseUrl) { uriBuilder = baseUrl.Clone(); if (Uid == 0L) { uriBuilder.Uid = 0L; uriBuilder.SearchCriteria = GetSequenceNumberSearchCriteria(); } else if (Uid != uriBuilder.Uid) { uriBuilder.Uid = Uid; uriBuilder.SearchCriteria = null; } if (BodyStructure != null) BodyStructure.SetBaseUrl(uriBuilder); }
internal static Uri GetUrl(IImapBodyStructure bodyStructure, ImapUriBuilder baseUrl) { if (baseUrl == null) throw new NotSupportedException("The base URL is not specified."); else if (baseUrl.Uid == 0L) throw new NotSupportedException("The UID of the base URL is not specified."); if (baseUrl.Section != bodyStructure.Section) baseUrl.Section = bodyStructure.Section; return baseUrl.Uri; }
/// <summary>Infrastructure. It is not intended to be used directly from your code.</summary> void IImapUrl.SetBaseUrl(ImapUriBuilder baseUrl) { uriBuilder = baseUrl.Clone(); uriBuilder.Mailbox = name; uriBuilder.UidValidity = uidValidity; }
/// <summary>Infrastructure. It is not intended to be used directly from your code.</summary> void IImapUrl.SetBaseUrl(ImapUriBuilder baseUrl) { throw new NotSupportedException(); }
public void TestGetSearchResponseCriteriaWithLiteralNonSyncLiteralIncapable() { using (var server = new ImapPseudoServer()) { var methodResponses = new string[0]; var b = new ImapUriBuilder(new Uri(string.Format("imap://user@{0}/", server.HostPort))); b.Mailbox = "INBOX"; b.SearchCriteria = ImapSearchCriteria.From("差出人") & (ImapSearchCriteria.Seen | ImapSearchCriteria.Subject("件名")); b.Charset = Encoding.UTF8; var presetRequest = (Action<ImapWebRequest>)delegate(ImapWebRequest req) { // nothing to do }; try { Request(server, ImapWebRequestMethods.Search, new string[] {"IMAP4rev1"}, b.Uri, methodResponses, presetRequest, delegate(ImapWebRequest request, ImapWebResponse response) { Assert.Fail("ProtocolViolationException not thrown"); }); } catch (ProtocolViolationException) { } } }
public void TestBuildListsOfMessagesFormUriNonAsciiMailboxName() { var b = new ImapUriBuilder(); b.Scheme = "imap"; b.Host = "psicorp.example.org"; b.Mailbox = "~peter/日本語/台北"; Assert.AreEqual(new Uri("imap://psicorp.example.org/~peter/%E6%97%A5%E6%9C%AC%E8%AA%9E/%E5%8F%B0%E5%8C%97"), b.Uri); b.Scheme = "imaps"; b.Host = "localhost"; b.Mailbox = "INBOX.新しいメールボックス"; Assert.AreEqual(new Uri("imaps://localhost/INBOX.%E6%96%B0%E3%81%97%E3%81%84%E3%83%A1%E3%83%BC%E3%83%AB%E3%83%9C%E3%83%83%E3%82%AF%E3%82%B9"), b.Uri); }
public void TestSearchWithCriteriaFromUri() { using (var session = SelectMailbox("LITERAL+")) { var b = new ImapUriBuilder(session.SelectedMailbox.Url); b.SearchCriteria = ImapSearchCriteria.From("差出人") & (ImapSearchCriteria.Seen | ImapSearchCriteria.Subject("件名")); b.Charset = Encoding.UTF8; // SEARCH transaction server.EnqueueResponse("* SEARCH 2 84 882\r\n" + "0004 OK SEARCH completed\r\n"); ImapMatchedSequenceSet matched; Assert.IsTrue((bool)session.Search(ImapSearchCriteria.FromUri(b.Uri), out matched)); Assert.AreEqual("0004 SEARCH CHARSET utf-8 FROM {9+}\r\n" + "\x00E5\x00B7\x00AE\x00E5\x0087\x00BA\x00E4\x00BA\x00BA OR (SEEN) (SUBJECT {6+}\r\n" + "\x00E4\x00BB\x00B6\x00E5\x0090\x008D)\r\n", server.DequeueAll(NetworkTransferEncoding.Transfer8Bit)); Assert.IsNotNull(matched); Assert.IsFalse(matched.IsUidSet); Assert.IsFalse(matched.IsEmpty); CloseMailbox(session); } }
public void TestBuildMailboxStartsWithSlash() { var b = new ImapUriBuilder(); b.Scheme = "imaps"; b.Host = "localhost"; b.Mailbox = "/INBOX.child"; Assert.AreEqual(new Uri("imaps://localhost/%2fINBOX.child"), b.Uri); }
private ImapWebResponse GetAppendResponse() { if (beginAppendAsyncResult == null) throw new InvalidOperationException("GetRequestStream not called"); try { appendMessageBodyStream.UpdateLength(); ImapAppendedUidSet appendedUid; var response = new ImapWebResponse(Session.EndAppend(beginAppendAsyncResult, out appendedUid)); if (response.Result.Succeeded) { // set empty stream; WebClient.Upload*() methods call WebResponse.GetResponseStream response.SetResponseStream(Stream.Null, 0L, false); if (appendedUid != null) { var builder = new ImapUriBuilder(RequestUri); builder.UidValidity = appendedUid.UidValidity; builder.Uid = appendedUid.ToNumber(); // if appendedUid.IsSingle response.SetResponseUri(builder.Uri); } } return response; } finally { appendMessageBodyStream.InternalDispose(); appendMessageBodyStream = null; beginAppendAsyncResult = null; } }
public void TestBuildListsOfMessagesFormUriSearchCriteria() { var b = new ImapUriBuilder("imap://localhost/", "INBOX", 12345L, new SearchQuery("ALL")); Assert.AreEqual(new Uri("imap://localhost/INBOX;UIDVALIDITY=12345?ALL"), b.Uri); b.Charset = Encoding.UTF8; Assert.AreEqual(new Uri("imap://localhost/INBOX;UIDVALIDITY=12345?ALL"), b.Uri); b.SearchCriteria = null; Assert.AreEqual(new Uri("imap://localhost/INBOX;UIDVALIDITY=12345"), b.Uri); b.Charset = null; Assert.AreEqual(new Uri("imap://localhost/INBOX;UIDVALIDITY=12345"), b.Uri); }
private void TransitStateTo(ImapSessionState newState) { if (newState == state) return; switch (newState) { case ImapSessionState.NotConnected: authority = null; selectedMailbox = null; if (mailboxManager != null) { mailboxManager.DetachFromSession(); mailboxManager = null; } TraceInfo("now in non-connected state"); break; case ImapSessionState.NotAuthenticated: UpdateAuthority(null, null); if (state == ImapSessionState.Selected || state == ImapSessionState.Authenticated) { mailboxManager.DetachFromSession(); mailboxManager = null; TraceInfo("logged out"); } TraceInfo("now in non-authenticated state"); break; case ImapSessionState.Authenticated: TraceInfo("now in authenticated state"); if (state == ImapSessionState.NotAuthenticated || state == ImapSessionState.NotConnected) { mailboxManager = new ImapMailboxManager(this); TraceInfo("logged in"); } break; case ImapSessionState.Selected: TraceInfo("now in selected state (selected '{0}')", selectedMailbox.Name); break; } state = newState; }
public void TestBuildSpecificMessageOrMessagePartFormUri() { var b = new ImapUriBuilder("imap://localhost/", "INBOX"); b.Uid = 1L; Assert.AreEqual(new Uri("imap://localhost/INBOX/;UID=1"), b.Uri); b.UidValidity = 12345L; Assert.AreEqual(new Uri("imap://localhost/INBOX;UIDVALIDITY=12345/;UID=1"), b.Uri); b.Section = "1.2"; Assert.AreEqual(new Uri("imap://localhost/INBOX;UIDVALIDITY=12345/;UID=1/;SECTION=1.2"), b.Uri); b.Partial = new ImapPartialRange(0L, 1024L); Assert.AreEqual(new Uri("imap://localhost/INBOX;UIDVALIDITY=12345/;UID=1/;SECTION=1.2/;PARTIAL=0.1024"), b.Uri); b.Section = "HEADER.FIELDS (DATE FROM)"; Assert.AreEqual(new Uri("imap://localhost/INBOX;UIDVALIDITY=12345/;UID=1/;SECTION=HEADER.FIELDS%20(DATE%20FROM)/;PARTIAL=0.1024"), b.Uri); b.Partial = null; Assert.AreEqual(new Uri("imap://localhost/INBOX;UIDVALIDITY=12345/;UID=1/;SECTION=HEADER.FIELDS%20(DATE%20FROM)"), b.Uri); b.Section = "1.3.HEADER.FIELDS.NOT (DATE FROM)"; Assert.AreEqual(new Uri("imap://localhost/INBOX;UIDVALIDITY=12345/;UID=1/;SECTION=1.3.HEADER.FIELDS.NOT%20(DATE%20FROM)"), b.Uri); b.Partial = new ImapPartialRange(1024L); Assert.AreEqual(new Uri("imap://localhost/INBOX;UIDVALIDITY=12345/;UID=1/;SECTION=1.3.HEADER.FIELDS.NOT%20(DATE%20FROM)/;PARTIAL=1024"), b.Uri); b.Section = null; Assert.AreEqual(new Uri("imap://localhost/INBOX;UIDVALIDITY=12345/;UID=1/;PARTIAL=1024"), b.Uri); b.UidValidity = 0L; Assert.AreEqual(new Uri("imap://localhost/INBOX/;UID=1/;PARTIAL=1024"), b.Uri); b.Partial = null; Assert.AreEqual(new Uri("imap://localhost/INBOX/;UID=1"), b.Uri); }
public void TestClone() { var origin = new ImapUriBuilder("imaps://user;auth=cram-md5@localhost:10143/INBOX;uidvalidity=12345/;uid=1/;section=1.2/;partial=0.1024/"); var cloned = origin.Clone(); Assert.AreEqual(cloned, origin); Assert.AreEqual("imaps", cloned.Scheme); Assert.AreEqual("user", cloned.UserName); Assert.AreEqual(ImapAuthenticationMechanism.CRAMMD5, cloned.AuthType); Assert.AreEqual("localhost", cloned.Host); Assert.AreEqual(10143, cloned.Port); Assert.AreEqual("INBOX", cloned.Mailbox); Assert.AreEqual(12345L, cloned.UidValidity); Assert.AreEqual(1L, cloned.Uid); Assert.AreEqual("1.2", cloned.Section); Assert.AreEqual(new ImapPartialRange(0L, 1024L), cloned.Partial); Assert.IsNull(cloned.SearchCriteria); }
public void TestGetSearchResponseCriteriaWithLiteral() { using (var server = new ImapPseudoServer()) { var methodResponses = new[] { // UID SEARCH "* SEARCH 3 4 5\r\n" + "0003 OK done\r\n", // UID FETCH "* 1 FETCH (UID 3)\r\n" + "* 2 FETCH (UID 4)\r\n" + "* 3 FETCH (UID 5)\r\n" + "0004 OK done\r\n" }; var b = new ImapUriBuilder(new Uri(string.Format("imap://user@{0}/", server.HostPort))); b.Mailbox = "INBOX"; b.SearchCriteria = ImapSearchCriteria.From("差出人") & (ImapSearchCriteria.Seen | ImapSearchCriteria.Subject("件名")); b.Charset = Encoding.UTF8; var presetRequest = (Action<ImapWebRequest>)delegate(ImapWebRequest req) { req.FetchDataItem = ImapFetchDataItemMacro.Full; }; Request(server, ImapWebRequestMethods.Search, new string[] {"IMAP4rev1", "LITERAL+"}, b.Uri, methodResponses, presetRequest, delegate(ImapWebRequest request, ImapWebResponse response) { Assert.AreEqual(request.RequestUri, response.ResponseUri); Assert.IsNotNull(response); Assert.IsNotNull(response.Result); Assert.IsTrue(response.Result.Succeeded); Assert.IsNotNull(response.MessageAttributes); Assert.AreEqual(3, response.MessageAttributes.Length); b.SearchCriteria = null; b.Uid = 3L; Assert.AreEqual(b.Uri, response.MessageAttributes[0].Url); b.Uid = 4L; Assert.AreEqual(b.Uri, response.MessageAttributes[1].Url); b.Uid = 5L; Assert.AreEqual(b.Uri, response.MessageAttributes[2].Url); }); StringAssert.EndsWith("UID SEARCH CHARSET utf-8 FROM {9+}\r\n", server.DequeueRequest(NetworkTransferEncoding.Transfer8Bit)); Assert.AreEqual("\x00E5\x00B7\x00AE\x00E5\x0087\x00BA\x00E4\x00BA\x00BA OR (SEEN) (SUBJECT {6+}\r\n", server.DequeueRequest(NetworkTransferEncoding.Transfer8Bit)); Assert.AreEqual("\x00E4\x00BB\x00B6\x00E5\x0090\x008D)\r\n", server.DequeueRequest(NetworkTransferEncoding.Transfer8Bit)); StringAssert.EndsWith("UID FETCH 3,4,5 FULL\r\n", server.DequeueRequest()); } }
public void TestCloneShallowCopy() { var origin = new ImapUriBuilder("imap://localhost/", "INBOX", 12345L, new SearchQuery("ALL")); origin.Charset = Encoding.UTF8; var cloned = origin.Clone(); Assert.AreSame(cloned.SearchCriteria, origin.SearchCriteria); Assert.AreSame(cloned.Charset, origin.Charset); }
/// <summary>Infrastructure. It is not intended to be used directly from your code.</summary> void IImapUrl.SetBaseUrl(ImapUriBuilder baseUrl) { (staticAttrs as IImapUrl).SetBaseUrl(baseUrl); }
public void TestConstructDefault() { var b = new ImapUriBuilder(); Assert.AreEqual(new Uri("imap://localhost/"), b.Uri); }
/// <summary>Infrastructure. It is not intended to be used directly from your code.</summary> void IImapUrl.SetBaseUrl(ImapUriBuilder baseUrl) { uriBuilder = baseUrl.Clone(); foreach (var nested in this) { nested.SetBaseUrl(baseUrl); } }
public void TestConstructFromUri() { var uri = "IMAPS://user;auth=cram-md5@localhost:10143/INBOX;uidvalidity=12345/;uid=1/;section=1.2/;partial=0.1024/"; var b = new ImapUriBuilder(new Uri(uri)); Assert.AreEqual(new Uri("imaps://user;AUTH=CRAM-MD5@localhost:10143/INBOX;UIDVALIDITY=12345/;UID=1/;SECTION=1.2/;PARTIAL=0.1024"), b.Uri); Assert.AreEqual("imaps", b.Scheme); Assert.AreEqual("user", b.UserName); Assert.AreEqual(ImapAuthenticationMechanism.CRAMMD5, b.AuthType); Assert.AreEqual("localhost", b.Host); Assert.AreEqual(10143, b.Port); Assert.AreEqual("INBOX", b.Mailbox); Assert.AreEqual(12345L, b.UidValidity); Assert.AreEqual(1L, b.Uid); Assert.AreEqual("1.2", b.Section); Assert.AreEqual(new ImapPartialRange(0L, 1024L), b.Partial); Assert.IsNull(b.SearchCriteria); }
public ImapClientProfile(Uri authority) { this.authority = new ImapUriBuilder(authority); }
public void TestIImapUrlSearchQuery_BuildUrlListsOfMessagesFormUriSearchCriteriaContainsLiterals() { var b = new ImapUriBuilder("imap://localhost/", "INBOX", 12345L, ImapSearchCriteria.From("差出人")); try { Assert.IsNotNull(b.Uri); Assert.Fail("InvalidOperationException not thrown"); } catch (InvalidOperationException) { } b.Charset = Encoding.UTF8; Assert.AreEqual(new Uri("imap://localhost/INBOX;UIDVALIDITY=12345?CHARSET%20utf-8%20FROM%20%7B9+%7D%0D%0A%E5%B7%AE%E5%87%BA%E4%BA%BA"), b.Uri); ImapSearchCriteria.FromUri(b.Uri); // no exceptions will be thrown b.Charset = Encoding.GetEncoding("shift_jis"); Assert.AreEqual(new Uri("imap://localhost/INBOX;UIDVALIDITY=12345?CHARSET%20shift_jis%20FROM%20%7B6+%7D%0D%0A%8D%B7%8Fo%90l"), b.Uri); ImapSearchCriteria.FromUri(b.Uri); // no exceptions will be thrown b.SearchCriteria = null; Assert.AreEqual(new Uri("imap://localhost/INBOX;UIDVALIDITY=12345"), b.Uri); b.Charset = null; Assert.AreEqual(new Uri("imap://localhost/INBOX;UIDVALIDITY=12345"), b.Uri); }