Skip to content

Commit 06c1bba

Browse files
Include some tests to IMAP function.
1 parent 1564052 commit 06c1bba

3 files changed

Lines changed: 94 additions & 4 deletions

File tree

Class Library/ActiveUp.Net.Imap4/Imap4Client.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -862,7 +862,7 @@ public void CloseBaseTCPConnection()
862862
#region Authentication
863863

864864
/// <summary>
865-
/// Logs in to the specified account.
865+
/// Logs in to the specified account and load all account MailBox.
866866
/// </summary>
867867
/// <param name="username">Username of the account.</param>
868868
/// <param name="password">Password of the account.</param>

Class Library/ActiveUp.Net.Tests/Common/RFC2047/Rfc2047DecoderTests.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,18 @@ public void should_decode_RFC2047_encoded_words()
7676
sampleText.ShouldEqual(Rfc2047Codec.Decode(encodedText));
7777
}
7878

79+
public void should_decode_RFC2047_encoded_subject()
80+
{
81+
var sampleText = "Pacote para atualização do enContact";
82+
var expectedText = "=?UTF-8?Q?Pacote_para_atualiza=C3=A7=C3=A3o_enContact?=";
83+
var encodedText = Rfc2047Codec.Encode(sampleText, "iso-8859-1");
84+
sampleText.ShouldEqual(expectedText);
85+
86+
87+
//var formattedSubject = Codec.RFC2047Encode(Codec.ToQuotedPrintable(texto, "utf-8"), "utf-8");
88+
//Subject: =?UTF-8?Q?Pacote_para_atualiza=C3=A7=C3=A3o_enContact?=
89+
}
90+
7991
/// <summary>
8092
/// This case is forbidden by RFC2047, but some senders don't respect it
8193
/// </summary>

Class Library/ActiveUp.Net.Tests/ImapTests.cs

Lines changed: 81 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ public class ImapTests
1616
private const string _imapPassword = "[password]";
1717
private const int _imapPort = 993;
1818
private const string _imapServerAddress = "imap.gmail.com";
19-
20-
2119

2220

2321
[Test, Ignore("Manual tests")]
@@ -32,7 +30,87 @@ public void dump_emails_for_tests()
3230
}
3331
}
3432

35-
public IEnumerable<string> DumpHeadersFromImap()
33+
[Test, Ignore("Manual tests")]
34+
public void download_imap_test()
35+
{
36+
try
37+
{
38+
var _selectedMailBox = "INBOX";
39+
using (var _clientImap4 = new Imap4Client())
40+
{
41+
42+
_clientImap4.ConnectSsl(_imapServerAddress, _imapPort);
43+
//_clientImap4.Connect(_mailServer.address, _mailServer.port);
44+
45+
_clientImap4.Login(_imapLogin, _imapPassword); // Efetua login e carrega as MailBox da conta.
46+
//_clientImap4.LoginFast(_imapLogin, _imapPassword); // Efetua login e não carrega as MailBox da conta.
47+
48+
var _mailBox = _clientImap4.SelectMailbox(_selectedMailBox);
49+
50+
foreach (var messageId in _mailBox.Search("ALL").AsEnumerable())
51+
{
52+
var message = _mailBox.Fetch.Message(messageId);
53+
var _imapMessage = Parser.ParseMessage(message);
54+
}
55+
56+
_clientImap4.Disconnect();
57+
}
58+
59+
Assert.IsTrue(true);
60+
}
61+
catch(Exception e)
62+
{
63+
Assert.Fail("Don't work.", e);
64+
}
65+
}
66+
67+
[Test, Ignore("Manual tests")]
68+
public void download_imap_async_test()
69+
{
70+
try
71+
{
72+
var callBack = new AsyncCallback(ImapAsyncCallBack);
73+
74+
using (var _clientImap4 = new Imap4Client())
75+
{
76+
77+
var result = _clientImap4.BeginConnectSsl(_imapServerAddress, _imapPort, callBack);
78+
79+
while(!result.CompletedSynchronously)
80+
{
81+
Console.WriteLine("Waiting execution....");
82+
}
83+
}
84+
85+
Assert.IsTrue(true);
86+
}
87+
catch (Exception e)
88+
{
89+
Assert.Fail("Dont work.", e);
90+
}
91+
}
92+
93+
private void ImapAsyncCallBack(IAsyncResult result)
94+
{
95+
var resultStatus = result.AsyncState;
96+
using (var _clientImap4 = (Imap4Client)((System.Delegate)result.AsyncState).Target)
97+
{
98+
_clientImap4.Login(_imapLogin, _imapPassword); // Efetua login e carrega as MailBox da conta.
99+
//_clientImap4.LoginFast(_imapLogin, _imapPassword); // Efetua login e não carrega as MailBox da conta.
100+
var _selectedMailBox = "INBOX";
101+
var _mailBox = _clientImap4.SelectMailbox(_selectedMailBox);
102+
103+
foreach (var messageId in _mailBox.Search("ALL").AsEnumerable())
104+
{
105+
var message = _mailBox.Fetch.Message(messageId);
106+
var _imapMessage = Parser.ParseMessage(message);
107+
}
108+
109+
_clientImap4.Disconnect();
110+
}
111+
}
112+
113+
private IEnumerable<string> DumpHeadersFromImap()
36114
{
37115
var client = new Imap4Client();
38116
client.ConnectSsl(_imapServerAddress, _imapPort);

0 commit comments

Comments
 (0)