当前位置: 首页>>代码示例>>C#>>正文


C# Pop3Client.GetMessageAsBytes方法代码示例

本文整理汇总了C#中OpenPop.Pop3.Pop3Client.GetMessageAsBytes方法的典型用法代码示例。如果您正苦于以下问题:C# Pop3Client.GetMessageAsBytes方法的具体用法?C# Pop3Client.GetMessageAsBytes怎么用?C# Pop3Client.GetMessageAsBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OpenPop.Pop3.Pop3Client的用法示例。


在下文中一共展示了Pop3Client.GetMessageAsBytes方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestGetMessageAsBytes

		public void TestGetMessageAsBytes()
		{
			const string welcomeMessage = "+OK";
			const string okUsername = "+OK";
			const string okPassword = "+OK";
			const string okMessageFetch = "+OK";
			const string messageHeaders = "Return-Path: <[email protected]>";
			const string messageHeaderToBodyDelimiter = "";
			const string messageBody = "\r\nTest\r\n";
			const string messageEnd = ".";

			const string message = messageHeaders + "\r\n" + messageHeaderToBodyDelimiter + "\r\n" + messageBody;

			const string serverResponses = welcomeMessage + "\r\n" + okUsername + "\r\n" + okPassword + "\r\n" + okMessageFetch + "\r\n" + message + "\r\n" + messageEnd + "\r\n";

			Stream inputStream = new MemoryStream(Encoding.ASCII.GetBytes(serverResponses));
			Stream outputStream = new MemoryStream();

			byte[] expectedBytes = Encoding.ASCII.GetBytes(message);

			Pop3Client client = new Pop3Client();
			client.Connect(new CombinedStream(inputStream, outputStream));
			client.Authenticate("something", "else");

			byte[] messageBytes = client.GetMessageAsBytes(132);

			Assert.AreEqual(expectedBytes, messageBytes);
		}
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:28,代码来源:POPClientPositiveTests.cs

示例2: TestGetMessageAsBytesWithDotDot

		public void TestGetMessageAsBytesWithDotDot()
		{
			const string welcomeMessage = "+OK";
			const string okUsername = "+OK";
			const string okPassword = "+OK";
			const string okMessageFetch = "+OK";
			const string messageEnd = ".";

			const string message		 = "Return-Path: <[email protected]>" + "\r\n" + "" + "\r\n" + "..";
			const string expectedMessage = "Return-Path: <[email protected]>" + "\r\n" + "" + "\r\n" + ".";
			
			const string serverResponses = welcomeMessage + "\r\n" + okUsername + "\r\n" + okPassword + "\r\n" + okMessageFetch + "\r\n" + message + "\r\n" + messageEnd + "\r\n";

			Stream inputStream = new MemoryStream(Encoding.ASCII.GetBytes(serverResponses));
			Stream outputStream = new MemoryStream();

			// When a .. is expected as the first character of a line, it really means that it is only a .
			byte[] expectedBytes = Encoding.ASCII.GetBytes(expectedMessage);

			Pop3Client client = new Pop3Client();
			client.Connect(new CombinedStream(inputStream, outputStream));
			client.Authenticate("something", "else");

			byte[] messageBytes = client.GetMessageAsBytes(139);

			Assert.AreEqual(expectedBytes, messageBytes);
		}
开发者ID:XiBeichuan,项目名称:hydronumerics,代码行数:27,代码来源:POPClientPositiveTests.cs

示例3: GetMails

        private void GetMails(MailboxInfo info)
        {
            try
            {
                using (var client = new Pop3Client())
                {
                    //Get Zabbix metrics
                    var stopwatch = new Stopwatch();
                    stopwatch.Start();
                    //Get mail count
                    client.Connect(info.Hostname, info.Port, false);
                    client.Authenticate(info.User, info.Password);
                    stopwatch.Stop();

                    //Send it to Zabbix
                    Functions.Zabbix.SendData(new ZabbixItem { Host = _config.HostKey, Key = info.Type + _config.TimingKey, Value = stopwatch.ElapsedMilliseconds.ToString() });
                    Functions.Log.Debug("Send [{0}] timing to Zabbix: connected to '{1}' as '{2}', timing {3}ms", info.Type, info.Hostname, info.User, stopwatch.ElapsedMilliseconds);

                    var count = client.GetMessageCount();
                    if (count == 0)
                        return;

                    Functions.Log.Debug("We've got new {0} messages in '{1}'", count, info.User);
                    //Send messages to sorting block
                    for (var i = 0; i < count; i++)
                    {
                        try
                        {
                            var mailInfo = new MessageInfo
                            {
                                IsSpam = false,
                                Mail = client.GetMessage(i + 1),
                                Type = MessageType.UNKNOWN,
                                Subtype = null,
                                Recipient = null,
                                Mailbox = info
                            };
                            Functions.Log.Debug("Download message from '{0}'. Size: {1}b", info.User, mailInfo.Mail.RawMessage.Length);
                            while (!_sortMailDataBlock.Post(mailInfo))
                                Thread.Sleep(500);

                            //Save every mail to archive
                            Functions.Log.Debug("Archive message");
                            Functions.Archive.Info(Functions.MessageToString(mailInfo.Mail));
                        }
                        catch (Exception ex)
                        {
                            Functions.Log.Error("Parse email error: {0}", ex.Message);
                            Functions.ErrorsCounters[info.Type].Increment();

                            //Archive mail anyway
                            Functions.Log.Debug("Archive message");
                            Functions.Archive.Info(Encoding.Default.GetString(client.GetMessageAsBytes(i + 1)));
                        }

                        if (_config.DeleteMail)
                            client.DeleteMessage(i + 1);

                        if (_stopPipeline)
                            break;
                    }
                    Functions.Log.Debug("Done with '{0}'", info.User);
                }
            }
            catch (Exception ex)
            {
                Functions.Log.Error("General error - type: {0}, message: {1}", ex, ex.Message);
                Functions.ErrorsCounters[info.Type].Increment();
            }
        }
开发者ID:risedphantom,项目名称:TopCrawler,代码行数:70,代码来源:Crawler.cs


注:本文中的OpenPop.Pop3.Pop3Client.GetMessageAsBytes方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。