本文整理汇总了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);
}
示例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);
}
示例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();
}
}