PageRenderTime 77ms CodeModel.GetById 33ms RepoModel.GetById 1ms app.codeStats 1ms

/module/ASC.MailSystem/ClassLibrary/ActiveUp.Net.Pop3/Pop3Client.cs

https://github.com/dc0d/ONLYOFFICE-Server
C# | 2155 lines | 1070 code | 190 blank | 895 comment | 70 complexity | 4016836d8ccda65ebbbc13862b8fb4fb MD5 | raw file
Possible License(s): GPL-2.0, MPL-2.0-no-copyleft-exception

Large files files are truncated, but you can click here to view the full file

  1. // Copyright 2001-2010 - Active Up SPRLU (http://www.agilecomponents.com)
  2. //
  3. // This file is part of MailSystem.NET.
  4. // MailSystem.NET is free software; you can redistribute it and/or modify
  5. // it under the terms of the GNU Lesser General Public License as published by
  6. // the Free Software Foundation; either version 2 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // MailSystem.NET is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU Lesser General Public License for more details.
  13. // You should have received a copy of the GNU Lesser General Public License
  14. // along with SharpMap; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. using System;
  17. using System.Text.RegularExpressions;
  18. using ActiveUp.Net.Security;
  19. namespace ActiveUp.Net.Mail
  20. {
  21. #region Pop3Client Object version 2
  22. /// <summary>
  23. /// POP3 Client extending a System.Net.Sockets.TcpClient to send/receive POP3 command/responses.
  24. /// </summary>
  25. #if !PocketPC
  26. [System.Serializable]
  27. #endif
  28. public class Pop3Client : ActiveUp.Net.Common.BaseProtocolClient
  29. {
  30. #region Constructors
  31. /// <summary>
  32. /// Default constructor
  33. /// </summary>
  34. public Pop3Client()
  35. {
  36. }
  37. #if PocketPC
  38. /// <summary>
  39. /// Finds PPC Encoding replacing ISO 8859-1 as standard.
  40. /// </summary>
  41. internal static System.Text.Encoding PPCEncode
  42. {
  43. get
  44. {
  45. //Since ISO 8859-1, not supported widelys (Depends on PPC region)
  46. //We are using Windows Code Page 1252 which is very much nearer to ISO
  47. //standard.
  48. return System.Text.Encoding.GetEncoding(1252);
  49. }
  50. }
  51. #endif
  52. #endregion
  53. #region Events
  54. #region Event definitions
  55. /*/// <summary>
  56. /// Event fired when a certain amount of bytes are read during message or Header retrieval.
  57. /// </summary>
  58. public event ActiveUp.Net.Mail.ProgressEventHandler Progress;*/
  59. /// <summary>
  60. /// Event fired when authentication starts.
  61. /// </summary>
  62. public event ActiveUp.Net.Mail.AuthenticatingEventHandler Authenticating;
  63. /// <summary>
  64. /// Event fired when authentication completed.
  65. /// </summary>
  66. public event ActiveUp.Net.Mail.AuthenticatedEventHandler Authenticated;
  67. /// <summary>
  68. /// Event fired when NOOP command is issued.
  69. /// </summary>
  70. public event ActiveUp.Net.Mail.NoopingEventHandler Nooping;
  71. /// <summary>
  72. /// Event fired when NOOP command completed.
  73. /// </summary>
  74. public event ActiveUp.Net.Mail.NoopedEventHandler Nooped;
  75. /// <summary>
  76. /// Event fired when a command is being written to the server.
  77. /// </summary>
  78. public event ActiveUp.Net.Mail.TcpWritingEventHandler TcpWriting;
  79. /// <summary>
  80. /// Event fired when a command has been written to the server.
  81. /// </summary>
  82. public event ActiveUp.Net.Mail.TcpWrittenEventHandler TcpWritten;
  83. /// <summary>
  84. /// Event fired when a response is being read from the server.
  85. /// </summary>
  86. public event ActiveUp.Net.Mail.TcpReadingEventHandler TcpReading;
  87. /// <summary>
  88. /// Event fired when a response has been read from the server.
  89. /// </summary>
  90. public event ActiveUp.Net.Mail.TcpReadEventHandler TcpRead;
  91. /// <summary>
  92. /// Event fired when a message is being requested using the RetrieveMessage() method.
  93. /// </summary>
  94. public event ActiveUp.Net.Mail.MessageRetrievingEventHandler MessageRetrieving;
  95. /// <summary>
  96. /// Event fired when a message is being retrieved using the RetrieveMessage() method.
  97. /// </summary>
  98. public event ActiveUp.Net.Mail.MessageRetrievedEventHandler MessageRetrieved;
  99. /// <summary>
  100. /// Event fired when a message Header is being requested using the RetrieveHeader() method.
  101. /// </summary>
  102. public event ActiveUp.Net.Mail.HeaderRetrievingEventHandler HeaderRetrieving;
  103. /// <summary>
  104. /// Event fired when a message Header has been retrieved using the RetrieveHeader() method.
  105. /// </summary>
  106. public event ActiveUp.Net.Mail.HeaderRetrievedEventHandler HeaderRetrieved;
  107. /// <summary>
  108. /// Event fired when attempting to connect to the remote server using the specified host.
  109. /// </summary>
  110. public event ActiveUp.Net.Mail.ConnectingEventHandler Connecting;
  111. /// <summary>
  112. /// Event fired when the object is connected to the remote server or when connection failed.
  113. /// </summary>
  114. public new event ActiveUp.Net.Mail.ConnectedEventHandler Connected;
  115. /// <summary>
  116. /// Event fired when attempting to disconnect from the remote server.
  117. /// </summary>
  118. public event ActiveUp.Net.Mail.DisconnectingEventHandler Disconnecting;
  119. /// <summary>
  120. /// Event fired when the object disconnected from the remote server.
  121. /// </summary>
  122. public event ActiveUp.Net.Mail.DisconnectedEventHandler Disconnected;
  123. #endregion
  124. #region Event triggers and logging
  125. /*internal void OnProgress(ActiveUp.Net.Mail.ProgressEventArgs e)
  126. {
  127. if(Progress!=null) Progress(this,e);
  128. }*/
  129. internal void OnAuthenticating(ActiveUp.Net.Mail.AuthenticatingEventArgs e)
  130. {
  131. if (Authenticating != null) Authenticating(this, e);
  132. ActiveUp.Net.Mail.Logger.AddEntry("Authenticating as " + e.Username + " on " + e.Host + "...", 2);
  133. }
  134. internal void OnAuthenticated(ActiveUp.Net.Mail.AuthenticatedEventArgs e)
  135. {
  136. if (Authenticated != null) Authenticated(this, e);
  137. ActiveUp.Net.Mail.Logger.AddEntry("Authenticated as " + e.Username + " on " + e.Host + ".", 2);
  138. }
  139. internal void OnNooping()
  140. {
  141. if (Nooping != null) Nooping(this);
  142. ActiveUp.Net.Mail.Logger.AddEntry("Nooping...", 1);
  143. }
  144. internal void OnNooped()
  145. {
  146. if (Nooped != null) Nooped(this);
  147. ActiveUp.Net.Mail.Logger.AddEntry("Nooped.", 1);
  148. }
  149. internal void OnTcpWriting(ActiveUp.Net.Mail.TcpWritingEventArgs e)
  150. {
  151. if (TcpWriting != null) TcpWriting(this, e);
  152. ActiveUp.Net.Mail.Logger.AddEntry("Sending " + e.Command + "...", 1);
  153. }
  154. internal void OnTcpWritten(ActiveUp.Net.Mail.TcpWrittenEventArgs e)
  155. {
  156. if (TcpWritten != null) TcpWritten(this, e);
  157. ActiveUp.Net.Mail.Logger.AddEntry("Sent " + e.Command + ".", 1);
  158. }
  159. internal void OnTcpReading()
  160. {
  161. if (TcpReading != null) TcpReading(this);
  162. ActiveUp.Net.Mail.Logger.AddEntry("Reading...", 1);
  163. }
  164. internal void OnTcpRead(ActiveUp.Net.Mail.TcpReadEventArgs e)
  165. {
  166. if (TcpRead != null) TcpRead(this, e);
  167. ActiveUp.Net.Mail.Logger.AddEntry("Read " + e.Response + ".", 1);
  168. }
  169. internal void OnMessageRetrieving(ActiveUp.Net.Mail.MessageRetrievingEventArgs e)
  170. {
  171. if (MessageRetrieving != null) MessageRetrieving(this, e);
  172. ActiveUp.Net.Mail.Logger.AddEntry("Retrieving message at index " + e.MessageIndex + " out of " + e.TotalCount + "...", 2);
  173. }
  174. internal void OnMessageRetrieved(ActiveUp.Net.Mail.MessageRetrievedEventArgs e)
  175. {
  176. if (MessageRetrieved != null) MessageRetrieved(this, e);
  177. ActiveUp.Net.Mail.Logger.AddEntry("Retrieved message at index " + e.MessageIndex + " out of " + e.TotalCount + ".", 2);
  178. }
  179. internal void OnHeaderRetrieving(ActiveUp.Net.Mail.HeaderRetrievingEventArgs e)
  180. {
  181. if (HeaderRetrieving != null) HeaderRetrieving(this, e);
  182. ActiveUp.Net.Mail.Logger.AddEntry("Retrieving Header at index " + e.MessageIndex + " out of " + e.TotalCount + "...", 2);
  183. }
  184. internal void OnHeaderRetrieved(ActiveUp.Net.Mail.HeaderRetrievedEventArgs e)
  185. {
  186. if (HeaderRetrieved != null) HeaderRetrieved(this, e);
  187. ActiveUp.Net.Mail.Logger.AddEntry("Retrieved Header at index " + e.MessageIndex + " out of " + e.TotalCount + ".", 2);
  188. }
  189. internal void OnDisconnecting()
  190. {
  191. if (Disconnecting != null) Disconnecting(this);
  192. ActiveUp.Net.Mail.Logger.AddEntry("Disconnecting...", 2);
  193. }
  194. internal void OnDisconnected(ActiveUp.Net.Mail.DisconnectedEventArgs e)
  195. {
  196. if (Disconnected != null) Disconnected(this, e);
  197. ActiveUp.Net.Mail.Logger.AddEntry("Disconnected.", 2);
  198. }
  199. internal void OnConnecting()
  200. {
  201. if (Connecting != null) Connecting(this);
  202. ActiveUp.Net.Mail.Logger.AddEntry("Connecting...", 2);
  203. }
  204. internal void OnConnected(ActiveUp.Net.Mail.ConnectedEventArgs e)
  205. {
  206. if (Connected != null) Connected(this, e);
  207. ActiveUp.Net.Mail.Logger.AddEntry("Connected. Server replied : " + e.ServerResponse + ".", 2);
  208. }
  209. #endregion
  210. #endregion
  211. #region Private fields
  212. int _messageCount;
  213. long _totalSize;
  214. //#if !PocketPC
  215. // System.Net.Security.SslStream _sslStream;
  216. //#endif
  217. #endregion
  218. #region Properties
  219. /// <summary>
  220. /// Number of messages on the remote POP server.
  221. /// </summary>
  222. /// <example>
  223. /// <code>
  224. /// C#
  225. ///
  226. /// Pop3Client pop = new Pop3Client();
  227. /// pop.Connect("mail.myhost.com","user","pass");
  228. /// int msgCount = pop.MessageCount;
  229. /// pop.Disconnect();
  230. ///
  231. /// VB.NET
  232. ///
  233. /// Dim pop As New Pop3Client
  234. /// pop.Connect("mail.myhost.com","user","pass")
  235. /// Dim msgCount as Integer = pop.MessageCount
  236. /// pop.Disconnect()
  237. ///
  238. /// JScript.NET
  239. ///
  240. /// var pop:Pop3Client = new Pop3Client();
  241. /// pop.Connect("mail.myhost.com","user","pass");
  242. /// var msgCount:int = pop.MessageCount;
  243. /// pop.Disconnect();
  244. /// </code>
  245. /// </example>
  246. public int MessageCount
  247. {
  248. get
  249. {
  250. return this._messageCount;
  251. }
  252. set
  253. {
  254. this._messageCount = value;
  255. }
  256. }
  257. /// <summary>
  258. /// Size of all messages on the remote POP server.
  259. /// </summary>
  260. /// <example>
  261. /// <code>
  262. /// C#
  263. ///
  264. /// Pop3Client pop = new Pop3Client();
  265. /// pop.Connect("mail.myhost.com","user","pass");
  266. /// int accountSize = pop.TotalSize;
  267. /// pop.Disconnect();
  268. ///
  269. /// VB.NET
  270. ///
  271. /// Dim pop As New Pop3Client
  272. /// pop.Connect("mail.myhost.com","user","pass")
  273. /// Dim accountSize as Integer = pop.TotalSize
  274. /// pop.Disconnect()
  275. ///
  276. /// JScript.NET
  277. ///
  278. /// var pop:Pop3Client = new Pop3Client();
  279. /// pop.Connect("mail.myhost.com","user","pass");
  280. /// var accountSize:int = pop.TotalSize;
  281. /// pop.Disconnect();
  282. /// </code>
  283. /// </example>
  284. public long TotalSize
  285. {
  286. get
  287. {
  288. return this._totalSize;
  289. }
  290. set
  291. {
  292. this._totalSize = value;
  293. }
  294. }
  295. #endregion
  296. #region Delegates and associated private fields
  297. private delegate string DelegateConnect(string host, int port);
  298. private DelegateConnect _delegateConnect;
  299. private delegate string DelegateConnectIPAddress(System.Net.IPAddress addr, int port);
  300. private DelegateConnectIPAddress _delegateConnectIPAddress;
  301. private delegate string DelegateConnectIPAddresses(System.Net.IPAddress[] addresses, int port);
  302. private DelegateConnectIPAddresses _delegateConnectIPAddresses;
  303. private delegate string DelegateConnectAuth(string host, int port, string user, string pass);
  304. private DelegateConnectAuth _delegateConnectAuth;
  305. private delegate string DelegateConnectAPOP(string host, int port, string user, string pass);
  306. private DelegateConnectAPOP _delegateConnectAPOP;
  307. #if !PocketPC
  308. private delegate string DelegateConnectSslAuth(string host, int port, string username, string password, ActiveUp.Net.Security.SslHandShake sslHandShake);
  309. private DelegateConnectSslAuth _delegateConnectSslAuth;
  310. private delegate string DelegateConnectSsl(string host, int port, ActiveUp.Net.Security.SslHandShake sslHandShake);
  311. private DelegateConnectSsl _delegateConnectSsl;
  312. private delegate string DelegateConnectSslIPAddress(System.Net.IPAddress addr, int port, ActiveUp.Net.Security.SslHandShake sslHandShake);
  313. private DelegateConnectSslIPAddress _delegateConnectSslIPAddress;
  314. private delegate string DelegateConnectSslIPAddresses(System.Net.IPAddress[] addresses, int port, ActiveUp.Net.Security.SslHandShake sslHandShake);
  315. private DelegateConnectSslIPAddresses _delegateConnectSslIPAddresses;
  316. #endif
  317. private delegate string DelegateAuthenticate(string username, string password, SaslMechanism mechanism);
  318. private DelegateAuthenticate _delegateAuthenticate;
  319. private delegate string DelegateDisconnect();
  320. private DelegateDisconnect _delegateDisconnect;
  321. private delegate string DelegateCommand(string command);
  322. private DelegateCommand _delegateCommand;
  323. private delegate byte[] DelegateRetrieveMessage(int messageIndex, bool deleteMessage);
  324. private DelegateRetrieveMessage _delegateRetrieveMessage;
  325. private delegate Message DelegateRetrieveMessageObject(int messageIndex, bool deleteMessage);
  326. private DelegateRetrieveMessageObject _delegateRetrieveMessageObject;
  327. private delegate void DelegateStoreMessage(int messageIndex, bool deleteMessage, string destinationPath);
  328. private DelegateStoreMessage _delegateStoreMessage;
  329. private delegate byte[] DelegateRetrieveHeader(int messageIndex, int numberOfBodyLines);
  330. private DelegateRetrieveHeader _delegateRetrieveHeader;
  331. private delegate Header DelegateRetrieveHeaderObject(int messageIndex);
  332. private DelegateRetrieveHeaderObject _delegateRetrieveHeaderObject;
  333. private delegate void DelegateStoreHeader(int messageIndex, string destinationPath);
  334. private DelegateStoreHeader _delegateStoreHeader;
  335. private delegate void DelegateDeleteMessage(int indexOnServer);
  336. private DelegateDeleteMessage _delegateDeleteMessage;
  337. private delegate int DelegateReset();
  338. private DelegateReset _delegateReset;
  339. private delegate string DelegateGetUniqueID(int messageIndex);
  340. private DelegateGetUniqueID _delegateGetUniqueID;
  341. private delegate System.Collections.Generic.List<PopServerUniqueId> DelegateGetUniqueIDs();
  342. private DelegateGetUniqueIDs _delegateGetUniqueIDs;
  343. private delegate int DelegateGetMessageSize(int messageIndex);
  344. private DelegateGetMessageSize _delegateGetMessageSize;
  345. private delegate void DelegateUpdateStats();
  346. private DelegateUpdateStats _delegateUpdateStats;
  347. private delegate void DelegateNoop();
  348. private DelegateNoop _delegateNoop;
  349. private delegate bool DelegateCheckAPOP(string host, int port);
  350. private static DelegateCheckAPOP _delegateCheckAPOP;
  351. private delegate bool DelegateCheckAPOPString(string host);
  352. private static DelegateCheckAPOPString _delegateCheckAPOPString;
  353. private delegate string[] DelegateGetServerCapabilities();
  354. private DelegateGetServerCapabilities _delegateGetServerCapabilities;
  355. #endregion
  356. #region Methods
  357. #region Private utility methods
  358. #if !PocketPC
  359. protected override void DoSslHandShake(ActiveUp.Net.Security.SslHandShake sslHandShake)
  360. {
  361. this._sslStream = new System.Net.Security.SslStream(base.GetStream(), false, sslHandShake.ServerCertificateValidationCallback, sslHandShake.ClientCertificateSelectionCallback);
  362. this._sslStream.AuthenticateAsClient(sslHandShake.HostName, sslHandShake.ClientCertificates, sslHandShake.SslProtocol, sslHandShake.CheckRevocation);
  363. }
  364. #endif
  365. private string _CramMd5(string username, string password)
  366. {
  367. this.OnAuthenticating(new ActiveUp.Net.Mail.AuthenticatingEventArgs(username, password));
  368. //string digest = System.Text.Encoding.ASCII.GetString(System.Convert.FromBase64String(this.Command("auth cram-md5").Split(' ')[1].Trim(new char[] { '\r', '\n' })));
  369. byte[] data = System.Convert.FromBase64String(this.Command("auth cram-md5").Split(' ')[1].Trim(new char[] { '\r', '\n' }));
  370. #if !PocketPC
  371. string digest = System.Text.Encoding.GetEncoding("iso-8859-1").GetString(data,0,data.Length);
  372. string response = this.Command(System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(username + " " + ActiveUp.Net.Mail.Crypto.HMACMD5Digest(password, digest))));
  373. #else
  374. string digest = PPCEncode.GetString(data, 0, data.Length);
  375. string response = this.Command(System.Convert.ToBase64String(PPCEncode.GetBytes(username + " " + ActiveUp.Net.Mail.Crypto.HMACMD5Digest(password, digest))));
  376. #endif
  377. //string response = this.Command(System.Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(username + " " + ActiveUp.Net.Mail.Crypto.HMACMD5Digest(password, digest))));
  378. this.OnAuthenticated(new ActiveUp.Net.Mail.AuthenticatedEventArgs(username, password, response));
  379. return response;
  380. }
  381. public override string Login(string user, string pass, string host)
  382. {
  383. this.OnAuthenticating(new ActiveUp.Net.Mail.AuthenticatingEventArgs(user, pass, host));
  384. string response = this.Command("USER " + user);
  385. string presponse = this.Command("PASS " + pass);
  386. this.OnAuthenticated(new ActiveUp.Net.Mail.AuthenticatedEventArgs(user, pass, host, response));
  387. /*response = this.Command("STAT");
  388. var splited = response.Split(' ');
  389. this._messageCount = System.Convert.ToInt32(splited[1]);
  390. this._totalSize = System.Convert.ToInt32(splited[2]);*/
  391. return presponse;
  392. }
  393. private string _Login(string username, string password)
  394. {
  395. this.OnAuthenticating(new ActiveUp.Net.Mail.AuthenticatingEventArgs(username, password));
  396. this.Command("auth login");
  397. //this.Command(System.Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(username)));
  398. //string response = this.Command(System.Convert.ToBase64String(System.Text.Encoding.ASCII.GetBytes(password)));
  399. #if !PocketPC
  400. this.Command(System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(username)));
  401. string response = this.Command(System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(password)));
  402. #else
  403. this.Command(System.Convert.ToBase64String(PPCEncode.GetBytes(username)));
  404. string response = this.Command(System.Convert.ToBase64String(PPCEncode.GetBytes(password)));
  405. #endif
  406. this.OnAuthenticated(new ActiveUp.Net.Mail.AuthenticatedEventArgs(username, password, response));
  407. return response;
  408. }
  409. private string ReadLine()
  410. {
  411. this.OnTcpReading();
  412. //System.IO.StreamReader sr = new System.IO.StreamReader(this.GetStream(), System.Text.Encoding.ASCII);
  413. #if !PocketPC
  414. System.IO.StreamReader sr = new System.IO.StreamReader(this.GetStream(), System.Text.Encoding.GetEncoding("iso-8859-1"));
  415. #else
  416. System.IO.StreamReader sr = new System.IO.StreamReader(this.GetStream(), PPCEncode);
  417. #endif
  418. string response = sr.ReadLine();
  419. this.OnTcpRead(new ActiveUp.Net.Mail.TcpReadEventArgs(response));
  420. return response;
  421. }
  422. private string StoreToFile(string path, byte[] data)
  423. {
  424. System.IO.FileStream fs = new System.IO.FileStream(path, System.IO.FileMode.Create, System.IO.FileAccess.Write);
  425. fs.Write(data, 0, data.Length);
  426. fs.Close();
  427. return path;
  428. }
  429. private System.IO.MemoryStream StoreToStream(byte[] data)
  430. {
  431. return new System.IO.MemoryStream(data, 0, data.Length, false, true);
  432. }
  433. #if PocketPC
  434. /// <summary>
  435. /// This functions Injects Sleep wherever required in PocketPC. This is required so that
  436. /// Less powerful MessagePump in PocketPC gets chance to execute other things.
  437. /// </summary>
  438. private void PPCSleep()
  439. {
  440. System.Threading.Thread.Sleep(1);
  441. }
  442. #endif
  443. #endregion
  444. #region Public methods
  445. #region Connecting, authenticating and disconnecting
  446. #region Cleartext methods
  447. /// <summary>
  448. /// Connects the object with the remote POP server using the given parameters.
  449. /// </summary>
  450. /// <param name="host">Remote POP server address.</param>
  451. /// <returns>The server's welcome greeting.</returns>
  452. /// <example>
  453. /// <code>
  454. /// C#
  455. ///
  456. /// Pop3Client pop = new Pop3Client();
  457. /// pop.Connect("mail.myhost.com");
  458. ///
  459. /// VB.NET
  460. ///
  461. /// Dim pop As New Pop3Client
  462. /// pop.Connect("mail.myhost.com")
  463. ///
  464. /// JScript.NET
  465. ///
  466. /// var pop:Pop3Client = new Pop3Client();
  467. /// pop.Connect("mail.myhost.com");
  468. /// </code>
  469. /// </example>
  470. public string Connect(string host)
  471. {
  472. return this.Connect(host, 110);
  473. }
  474. public IAsyncResult BeginConnect(string host, AsyncCallback callback)
  475. {
  476. return this.BeginConnect(host, 110, callback);
  477. }
  478. /// <summary>
  479. /// Connects the object with the remote POP server using the given parameters.
  480. /// </summary>
  481. /// <param name="host">Remote POP server address.</param>
  482. /// <param name="port">The port to be used.</param>
  483. /// <returns>The server's welcome greeting.</returns>
  484. /// <example>
  485. /// <code>
  486. /// C#
  487. ///
  488. /// Pop3Client pop = new Pop3Client();
  489. /// pop.Connect("mail.myhost.com",8503);
  490. ///
  491. /// VB.NET
  492. ///
  493. /// Dim pop As New Pop3Client
  494. /// pop.Connect("mail.myhost.com",8503)
  495. ///
  496. /// JScript.NET
  497. ///
  498. /// var pop:Pop3Client = new Pop3Client();
  499. /// pop.Connect("mail.myhost.com",8503);
  500. /// </code>
  501. /// </example>
  502. public new string Connect(string host, int port)
  503. {
  504. this.OnConnecting();
  505. base.Connect(host, port);
  506. string response = "";
  507. response = this.ReadLine();
  508. this.OnConnected(new ActiveUp.Net.Mail.ConnectedEventArgs(response));
  509. return response;
  510. }
  511. public string ConnectTLS(string host, int port)
  512. {
  513. this.Connect(host, port);
  514. return this.StartTLS(host);
  515. }
  516. public override IAsyncResult BeginConnect(string host, int port, AsyncCallback callback)
  517. {
  518. this._delegateConnect = this.Connect;
  519. return this._delegateConnect.BeginInvoke(host, port, callback, this._delegateConnect);
  520. }
  521. public IAsyncResult BeginConnectTLS(string host, int port, AsyncCallback callback)
  522. {
  523. this._delegateConnect = this.ConnectTLS;
  524. return this._delegateConnect.BeginInvoke(host, port, callback, this._delegateConnect);
  525. }
  526. public new string Connect(System.Net.IPAddress addr, int port)
  527. {
  528. this.OnConnecting();
  529. base.Connect(addr, port);
  530. string response = "";
  531. response = this.ReadLine();
  532. this.OnConnected(new ActiveUp.Net.Mail.ConnectedEventArgs(response));
  533. return response;
  534. }
  535. public IAsyncResult BeginConnect(System.Net.IPAddress addr, int port, AsyncCallback callback)
  536. {
  537. this._delegateConnectIPAddress = this.Connect;
  538. return this._delegateConnectIPAddress.BeginInvoke(addr, port, callback, this._delegateConnectIPAddress);
  539. }
  540. public new string Connect(System.Net.IPAddress[] addresses, int port)
  541. {
  542. this.OnConnecting();
  543. #if !PocketPC
  544. base.Connect(addresses, port);
  545. #else
  546. if(addresses.Length>0)
  547. base.Connect(addresses[0], port);
  548. PPCSleep();
  549. #endif
  550. string response = "";
  551. response = this.ReadLine();
  552. this.OnConnected(new ActiveUp.Net.Mail.ConnectedEventArgs(response));
  553. return response;
  554. }
  555. public IAsyncResult BeginConnect(System.Net.IPAddress[] addresses, int port, AsyncCallback callback)
  556. {
  557. this._delegateConnectIPAddresses = this.Connect;
  558. return this._delegateConnectIPAddresses.BeginInvoke(addresses, port, callback, this._delegateConnectIPAddresses);
  559. }
  560. public string Connect(string host, string username, string password)
  561. {
  562. return this.Connect(host, 110, username, password);
  563. }
  564. public IAsyncResult BeginConnect(string host, string username, string password, AsyncCallback callback)
  565. {
  566. return this.BeginConnect(host, 110, username, password, callback);
  567. }
  568. public string Connect(string host, int port, string username, string password)
  569. {
  570. this.OnConnecting();
  571. base.Connect(host, port);
  572. string response = this.ReadLine();
  573. this.OnConnected(new ActiveUp.Net.Mail.ConnectedEventArgs(response));
  574. this.OnAuthenticating(new ActiveUp.Net.Mail.AuthenticatingEventArgs(username, password, host));
  575. response = this.Command("USER " + username);
  576. string presponse = this.Command("PASS " + password);
  577. this.OnAuthenticated(new ActiveUp.Net.Mail.AuthenticatedEventArgs(username, password, host, response));
  578. /*response = this.Command("STAT");
  579. this._messageCount = System.Convert.ToInt32(response.Split(' ')[1]);
  580. this._totalSize = System.Convert.ToInt32(response.Split(' ')[2]);*/
  581. return presponse;
  582. }
  583. public IAsyncResult BeginConnect(string host, int port, string username, string password, AsyncCallback callback)
  584. {
  585. this._delegateConnectAuth = this.Connect;
  586. return this._delegateConnectAuth.BeginInvoke(host, port, username, password, callback, this._delegateConnectAuth);
  587. }
  588. public new string EndConnect(IAsyncResult result)
  589. {
  590. return (string)result.AsyncState.GetType().GetMethod("EndInvoke").Invoke(result.AsyncState, new object[] { result });
  591. }
  592. /// <summary>
  593. /// Connects the object with the remote POP server using the given parameters and APOP.
  594. /// </summary>
  595. /// <param name="user">Username on the remote POP server.</param>
  596. /// <param name="pass">Password on the remote POP server.</param>
  597. /// <param name="host">Remote POP server address.</param>
  598. /// <example>
  599. /// This will connect to the remote POP server using APOP.<br /><br />
  600. /// <code>
  601. /// C#
  602. ///
  603. /// Pop3Client pop = new Pop3Client();
  604. /// pop.APOPConnect("pop.myisp.com","username","password");
  605. ///
  606. /// VB.NET
  607. ///
  608. /// Dim pop As New Pop3Client()
  609. /// pop.APOPConnect("pop.myisp.com","username","password")
  610. ///
  611. /// JScript.NET
  612. ///
  613. /// var pop:Pop3Client = new Pop3Client();
  614. /// pop.APOPConnect("pop.myisp.com","username","password");
  615. /// </code>
  616. /// </example>
  617. public string APOPConnect(string host, string user, string pass)
  618. {
  619. return this.APOPConnect(host, 110, user, pass);
  620. }
  621. public IAsyncResult BeginAPOPConnect(string host, string user, string pass, AsyncCallback callback)
  622. {
  623. return this.BeginAPOPConnect(host, 110, user, pass, callback);
  624. }
  625. /// <summary>
  626. /// Connects the object with the remote POP server using the given parameters and APOP.
  627. /// </summary>
  628. /// <param name="user">Username on the remote POP server.</param>
  629. /// <param name="pass">Password on the remote POP server.</param>
  630. /// <param name="host">Remote POP server address.</param>
  631. /// <param name="port">Port to be used.</param>
  632. /// <example>
  633. /// This will connect to the remote POP server using APOP.<br /><br />
  634. /// <code>
  635. /// C#
  636. ///
  637. /// Pop3Client pop = new Pop3Client();
  638. /// pop.APOPConnect("pop.myisp.com","username","password",8503);
  639. ///
  640. /// VB.NET
  641. ///
  642. /// Dim pop As New Pop3Client()
  643. /// pop.APOPConnect("pop.myisp.com","username","password",8503)
  644. ///
  645. /// JScript.NET
  646. ///
  647. /// var pop:Pop3Client = new Pop3Client();
  648. /// pop.APOPConnect("pop.myisp.com","username","password",8503);
  649. /// </code>
  650. /// </example>
  651. public string APOPConnect(string host, int port, string user, string pass)
  652. {
  653. string response = this.Connect(host, port);
  654. string presponse = "";
  655. this.OnAuthenticating(new ActiveUp.Net.Mail.AuthenticatingEventArgs(user, pass, host));
  656. Match timestamp = Regex.Match(response, @"<.+@.+>");
  657. if (timestamp.Success)
  658. {
  659. string encrypted = timestamp.Value + pass;
  660. presponse = this.Command("APOP " + user + " " + ActiveUp.Net.Mail.Crypto.MD5Digest(encrypted));
  661. this.OnAuthenticated(new ActiveUp.Net.Mail.AuthenticatedEventArgs(user, pass, host, response));
  662. response = this.Command("STAT");
  663. this._messageCount = System.Convert.ToInt32(response.Split(' ')[1]);
  664. this._totalSize = System.Convert.ToInt32(response.Split(' ')[2]);
  665. }
  666. return presponse;
  667. }
  668. public IAsyncResult BeginAPOPConnect(string host, int port, string username, string password, AsyncCallback callback)
  669. {
  670. this._delegateConnectAPOP = this.APOPConnect;
  671. return this._delegateConnectAPOP.BeginInvoke(host, port, username, password, callback, this._delegateConnectAPOP);
  672. }
  673. public string EndAPOPConnect(IAsyncResult result)
  674. {
  675. return (string)result.AsyncState.GetType().GetMethod("EndInvoke").Invoke(result.AsyncState, new object[] { result });
  676. }
  677. /// <summary>
  678. /// Gets a value indicating whether this instance is connected.
  679. /// </summary>
  680. /// <value>
  681. /// <c>true</c> if this instance is connected; otherwise, <c>false</c>.
  682. /// </value>
  683. public override bool IsConnected
  684. {
  685. get
  686. {
  687. if (this.Client != null)
  688. return this.Client.Connected;
  689. else
  690. return false;
  691. }
  692. }
  693. #endregion
  694. #region SSL methods
  695. #if !PocketPC
  696. public string ConnectSsl(string host)
  697. {
  698. return this.ConnectSsl(host, 995, new ActiveUp.Net.Security.SslHandShake(host));
  699. }
  700. public IAsyncResult BeginConnectSsl(string host, AsyncCallback callback)
  701. {
  702. return this.BeginConnectSsl(host, 995, new ActiveUp.Net.Security.SslHandShake(host), callback);
  703. }
  704. public string ConnectSsl(string host, ActiveUp.Net.Security.SslHandShake sslHandShake)
  705. {
  706. return this.ConnectSsl(host, 995, sslHandShake);
  707. }
  708. public IAsyncResult BeginConnectSsl(string host, ActiveUp.Net.Security.SslHandShake sslHandShake, AsyncCallback callback)
  709. {
  710. return this.BeginConnectSsl(host, 995, sslHandShake, callback);
  711. }
  712. public string ConnectSsl(string host, int port)
  713. {
  714. return this.ConnectSsl(host, port, new ActiveUp.Net.Security.SslHandShake(host));
  715. }
  716. public override IAsyncResult BeginConnectSsl(string host, int port, AsyncCallback callback)
  717. {
  718. return this.BeginConnectSsl(host, port, new SslHandShake(host), callback);
  719. }
  720. public string ConnectSsl(string host, int port, ActiveUp.Net.Security.SslHandShake sslHandShake)
  721. {
  722. this.OnConnecting();
  723. base.Connect(host, port);
  724. this.DoSslHandShake(sslHandShake);
  725. string response = this.ReadLine();
  726. this.OnConnected(new ActiveUp.Net.Mail.ConnectedEventArgs(response));
  727. return response;
  728. }
  729. public IAsyncResult BeginConnectSsl(string host, int port, ActiveUp.Net.Security.SslHandShake sslHandShake, AsyncCallback callback)
  730. {
  731. this._delegateConnectSsl = this.ConnectSsl;
  732. return this._delegateConnectSsl.BeginInvoke(host, port, sslHandShake, callback, this._delegateConnectSsl);
  733. }
  734. public string ConnectSsl(System.Net.IPAddress addr, int port, ActiveUp.Net.Security.SslHandShake sslHandShake)
  735. {
  736. this.OnConnecting();
  737. base.Connect(addr, port);
  738. this.DoSslHandShake(sslHandShake);
  739. string response = this.ReadLine();
  740. this.OnConnected(new ActiveUp.Net.Mail.ConnectedEventArgs(response));
  741. return response;
  742. }
  743. public IAsyncResult BeginConnectSsl(System.Net.IPAddress addr, int port, ActiveUp.Net.Security.SslHandShake sslHandShake, AsyncCallback callback)
  744. {
  745. this._delegateConnectSslIPAddress = this.ConnectSsl;
  746. return this._delegateConnectSslIPAddress.BeginInvoke(addr, port, sslHandShake, callback, this._delegateConnectSslIPAddress);
  747. }
  748. public string ConnectSsl(System.Net.IPAddress[] addresses, int port, ActiveUp.Net.Security.SslHandShake sslHandShake)
  749. {
  750. this.OnConnecting();
  751. base.Connect(addresses, port);
  752. this.DoSslHandShake(sslHandShake);
  753. string response = this.ReadLine();
  754. this.OnConnected(new ActiveUp.Net.Mail.ConnectedEventArgs(response));
  755. return response;
  756. }
  757. public IAsyncResult BeginConnectSsl(System.Net.IPAddress[] addresses, int port, ActiveUp.Net.Security.SslHandShake sslHandShake, AsyncCallback callback)
  758. {
  759. this._delegateConnectSslIPAddresses = this.ConnectSsl;
  760. return this._delegateConnectSslIPAddresses.BeginInvoke(addresses, port, sslHandShake, callback, this._delegateConnectSslIPAddresses);
  761. }
  762. public string ConnectSsl(string host, string user, string pass)
  763. {
  764. return this.ConnectSsl(host, 995, user, pass, new SslHandShake(host));
  765. }
  766. public IAsyncResult BeginConnectSsl(string host, string user, string pass, AsyncCallback callback)
  767. {
  768. return this.BeginConnectSsl(host, 995, user, pass, new SslHandShake(host), callback);
  769. }
  770. public string ConnectSsl(string host, string user, string pass, SslHandShake sslHandShake)
  771. {
  772. return this.ConnectSsl(host, 995, user, pass, sslHandShake);
  773. }
  774. public IAsyncResult BeginConnectSsl(string host, string user, string pass, SslHandShake sslHandShake, AsyncCallback callback)
  775. {
  776. return this.BeginConnectSsl(host, 995, user, pass, sslHandShake, callback);
  777. }
  778. public string ConnectSsl(string host, int port, string user, string pass)
  779. {
  780. return this.ConnectSsl(host, port, user, pass, new SslHandShake(host));
  781. }
  782. public IAsyncResult BeginConnectSsl(string host, int port, string user, string pass, AsyncCallback callback)
  783. {
  784. return this.BeginConnectSsl(host, port, user, pass, new SslHandShake(host), callback);
  785. }
  786. public string ConnectSsl(string host, int port, string user, string pass, SslHandShake sslHandShake)
  787. {
  788. this.OnConnecting();
  789. base.Connect(host, port);
  790. this.DoSslHandShake(sslHandShake);
  791. string response = this.ReadLine();
  792. this.OnConnected(new ActiveUp.Net.Mail.ConnectedEventArgs(response));
  793. this.OnAuthenticating(new ActiveUp.Net.Mail.AuthenticatingEventArgs(user, pass, host));
  794. response = this.Command("USER " + user);
  795. string presponse = this.Command("PASS " + pass);
  796. this.OnAuthenticated(new ActiveUp.Net.Mail.AuthenticatedEventArgs(user, pass, host, response));
  797. /*response = this.Command("STAT");
  798. var splited = response.Split(' ');
  799. this._messageCount = System.Convert.ToInt32(splited[1]);
  800. this._totalSize = System.Convert.ToInt32(splited[2]);*/
  801. return presponse;
  802. }
  803. public IAsyncResult BeginConnectSsl(string host, int port, string user, string pass, SslHandShake sslHandShake, AsyncCallback callback)
  804. {
  805. this._delegateConnectSslAuth = this.ConnectSsl;
  806. return this._delegateConnectSslAuth.BeginInvoke(host, port, user, pass, sslHandShake, callback, this._delegateConnectSslAuth);
  807. }
  808. public override string EndConnectSsl(IAsyncResult result)
  809. {
  810. return (string)result.AsyncState.GetType().GetMethod("EndInvoke").Invoke(result.AsyncState, new object[] { result });
  811. }
  812. #endif
  813. #endregion
  814. #region SASL authentication
  815. /// <summary>
  816. /// Authenticates using the given SASL mechanism.
  817. /// </summary>
  818. /// <param name="username">Username to authenticate as.</param>
  819. /// <param name="password">Password.</param>
  820. /// <param name="mechanism">SASL mechanism to be used.</param>
  821. /// <returns>The server's response.</returns>
  822. /// <example>
  823. /// <code>
  824. /// C#
  825. ///
  826. /// Pop3Client pop = new Pop3Client();
  827. /// pop.Connect("mail.myhost.com");
  828. /// pop.Authenticate("user","pass",SASLMechanism.CramMd5);
  829. /// pop.Disconnect();
  830. ///
  831. /// VB.NET
  832. ///
  833. /// Dim pop As New Pop3Client
  834. /// pop.Connect("mail.myhost.com")
  835. /// pop.Authenticate("user","pass",SASLMechanism.CramMd5)
  836. /// pop.Disconnect()
  837. ///
  838. /// JScript.NET
  839. ///
  840. /// var pop:Pop3Client = new Pop3Client();
  841. /// pop.Connect("mail.myhost.com");
  842. /// pop.Authenticate("user","pass",SASLMechanism.CramMd5);
  843. /// pop.Disconnect();
  844. /// </code>
  845. /// </example>
  846. public string Authenticate(string username, string password, SaslMechanism mechanism)
  847. {
  848. switch (mechanism)
  849. {
  850. case ActiveUp.Net.Mail.SaslMechanism.CramMd5:
  851. return this._CramMd5(username, password);
  852. case ActiveUp.Net.Mail.SaslMechanism.Login:
  853. return this._Login(username, password);
  854. }
  855. return string.Empty;
  856. }
  857. public override IAsyncResult BeginAuthenticate(string username, string password, SaslMechanism mechanism, AsyncCallback callback)
  858. {
  859. this._delegateAuthenticate = this.Authenticate;
  860. return this._delegateAuthenticate.BeginInvoke(username, password, mechanism, callback, null);
  861. }
  862. public string EndAuthenticate(IAsyncResult result)
  863. {
  864. return this._delegateAuthenticate.EndInvoke(result);
  865. }
  866. #endregion
  867. #region Disconnect method
  868. /// <summary>
  869. /// Disconnects the client from the remote server.
  870. /// </summary>
  871. /// <example>
  872. /// <code>
  873. /// C#
  874. ///
  875. /// Pop3Client pop = new Pop3Client();
  876. /// pop.Connect("mail.myhost.com","user","pass");
  877. /// //Do some work...
  878. /// pop.Disconnect();
  879. ///
  880. /// VB.NET
  881. ///
  882. /// Dim pop As New Pop3Client
  883. /// pop.Connect("mail.myhost.com","user","pass")
  884. /// 'Do some work...
  885. /// pop.Disconnect()
  886. ///
  887. /// JScript.NET
  888. ///
  889. /// var pop:Pop3Client = new Pop3Client();
  890. /// pop.Connect("mail.myhost.com","user","pass");
  891. /// //Do some work...
  892. /// pop.Disconnect();
  893. /// </code>
  894. /// </example>
  895. public override string Disconnect()
  896. {
  897. this.OnDisconnecting();
  898. string response = this.Command("QUIT");
  899. this.Close();
  900. this.OnDisconnected(new ActiveUp.Net.Mail.DisconnectedEventArgs(response));
  901. return response;
  902. }
  903. public IAsyncResult BeginDisconnect(AsyncCallback callback)
  904. {
  905. this._delegateDisconnect = this.Disconnect;
  906. return this._delegateDisconnect.BeginInvoke(callback, null);
  907. }
  908. public string EndDisconnect(IAsyncResult result)
  909. {
  910. return this._delegateDisconnect.EndInvoke(result);
  911. }
  912. #endregion
  913. #endregion
  914. #region Command sending and receiving, stream access
  915. /// <summary>
  916. /// Sends the provided string to the server.
  917. /// </summary>
  918. /// <param name="command">The string to be sent to the server.</param>
  919. /// <returns>The server's response.</returns>
  920. /// <remarks>This method is to be used only with commands that return single-line responses.</remarks>
  921. /// <example>
  922. /// <code>
  923. /// C#
  924. ///
  925. /// Pop3Client pop = new Pop3Client();
  926. /// pop.Connect("mail.myhost.com","user","pass");
  927. /// string response = pop.Command("XANYCOMMAND anyarguments");
  928. /// pop.Disconnect();
  929. ///
  930. /// VB.NET
  931. ///
  932. /// Dim pop As New Pop3Client
  933. /// pop.Connect("mail.myhost.com","user","pass")
  934. /// Dim response As String = pop.Command("XANYCOMMAND anyarguments")
  935. /// pop.Disconnect()
  936. ///
  937. /// JScript.NET
  938. ///
  939. /// var pop:Pop3Client = new Pop3Client();
  940. /// pop.Connect("mail.myhost.com","user","pass");
  941. /// var response:string = pop.Command("XANYCOMMAND anyarguments");
  942. /// pop.Disconnect();
  943. /// </code>
  944. /// </example>
  945. public string Command(string command)
  946. {
  947. this.OnTcpWriting(new ActiveUp.Net.Mail.TcpWritingEventArgs(command));
  948. //this.GetStream().Write(System.Text.Encoding.ASCII.GetBytes(command + "\r\n"), 0, command.Length + 2);
  949. #if !PocketPC
  950. this.GetStream().Write(System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(command + "\r\n"), 0, command.Length + 2);
  951. #else
  952. this.GetStream().Write(PPCEncode.GetBytes(command + "\r\n"), 0, command.Length + 2);
  953. #endif
  954. #if !PocketPC
  955. System.IO.StreamReader sr = new System.IO.StreamReader(this.GetStream(), System.Text.Encoding.GetEncoding("iso-8859-1"));
  956. #else
  957. System.IO.StreamReader sr = new System.IO.StreamReader(this.GetStream(), PPCEncode);
  958. #endif
  959. string response = sr.ReadLine();
  960. this.OnTcpWritten(new ActiveUp.Net.Mail.TcpWrittenEventArgs(command));
  961. this.OnTcpReading();
  962. if (response == null || !response.StartsWith("+"))
  963. throw new ActiveUp.Net.Mail.Pop3Exception(command.StartsWith("PASS") ? "PASS *****" : command, response);
  964. this.OnTcpRead(new ActiveUp.Net.Mail.TcpReadEventArgs(response));
  965. return response;
  966. }
  967. public IAsyncResult BeginCommand(string command, AsyncCallback callback)
  968. {
  969. this._delegateCommand = this.Command;
  970. return this._delegateCommand.BeginInvoke(command, callback, null);
  971. }
  972. public string EndCommand(IAsyncResult result)
  973. {
  974. return this._delegateCommand.EndInvoke(result);
  975. }
  976. /// <summary>
  977. /// Sends the provided string to the server.
  978. /// </summary>
  979. /// <param name="command">The string to be sent to the server.</param>
  980. /// <returns>The server's response.</returns>
  981. /// <remarks>This method is to be used only with commands that return multi-line responses.</remarks>
  982. /// <example>
  983. /// <code>
  984. /// C#
  985. ///
  986. /// Pop3Client pop = new Pop3Client();
  987. /// pop.Connect("mail.myhost.com","user","pass");
  988. /// string response = pop.CommandMultiline("XANYCOMMAND anyarguments");
  989. /// pop.Disconnect();
  990. ///
  991. /// VB.NET
  992. ///
  993. /// Dim pop As New Pop3Client
  994. /// pop.Connect("mail.myhost.com","user","pass")
  995. /// Dim response As String = pop.CommandMultiline("XANYCOMMAND anyarguments")
  996. /// pop.Disconnect()
  997. ///
  998. /// JScript.NET
  999. ///
  1000. /// var pop:Pop3Client = new Pop3Client();
  1001. /// pop.Connect("mail.myhost.com","user","pass");
  1002. /// var response:string = pop.CommandMultiline("XANYCOMMAND anyarguments");
  1003. /// pop.Disconnect();
  1004. /// </code>
  1005. /// </example>
  1006. public string CommandMultiline(string command)
  1007. {
  1008. this.OnTcpWriting(new ActiveUp.Net.Mail.TcpWritingEventArgs(command));
  1009. #if !PocketPC
  1010. this.GetStream().Write(System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(command + "\r\n"), 0, command.Length + 2);
  1011. System.IO.StreamReader sr = new System.IO.StreamReader(this.GetStream(), System.Text.Encoding.GetEncoding("iso-8859-1"));
  1012. System.Text.StringBuilder sb = new System.Text.StringBuilder();
  1013. this.OnTcpWritten(new ActiveUp.Net.Mail.TcpWrittenEventArgs(command));
  1014. #else
  1015. this.GetStream().Write(PPCEncode.GetBytes(command + "\r\n"), 0, command.Length + 2);
  1016. this.OnTcpWritten(new ActiveUp.Net.Mail.TcpWrittenEventArgs(command));
  1017. System.Text.StringBuilder sb = new System.Text.StringBuilder();
  1018. System.IO.StreamReader sr = new System.IO.StreamReader(this.GetStream(), PPCEncode);
  1019. #endif
  1020. string str = "";
  1021. this.OnTcpReading();
  1022. str = sr.ReadLine();
  1023. if (!str.StartsWith("+")) throw new Pop3Exception(command, str);
  1024. while (true)
  1025. {
  1026. str = sr.ReadLine();
  1027. if (str != ".") sb.Append(str + "\r\n");
  1028. else break;
  1029. }
  1030. this.OnTcpRead(new ActiveUp.Net.Mail.TcpReadEventArgs("Read multiline command response."));
  1031. return sb.ToString().Replace("\r\n..\r\n", "\r\n.\r\n");
  1032. }
  1033. public IAsyncResult BeginCommandMultiline(string command, AsyncCallback callback)
  1034. {
  1035. this._delegateCommand = this.CommandMultiline;
  1036. return this._delegateCommand.BeginInvoke(command, callback, null);
  1037. }
  1038. public string EndCommandMultiline(IAsyncResult result)
  1039. {
  1040. return this._delegateCommand.EndInvoke(result);
  1041. }
  1042. /// <summary>
  1043. /// Gets the communacation stream of this object.
  1044. /// </summary>

Large files files are truncated, but you can click here to view the full file