本文整理汇总了C#中OpenPop.Mime.Message类的典型用法代码示例。如果您正苦于以下问题:C# Message类的具体用法?C# Message怎么用?C# Message使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Message类属于OpenPop.Mime命名空间,在下文中一共展示了Message类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ParsingMediaTypeOctetStream
public void ParsingMediaTypeOctetStream()
{
const string base64 =
"JVBERi0xLjUNCiW1tbW1DQoxIDAgb2JqDQo8PC9UeXBlL0NhdGFsb2cvUGFnZXMgMiAwIFIv\r\n" +
"TGFuZyhkYS1ESykgL1N0cnVjdFRyZWVSb290IDE1IDAgUi9NYXJrSW5mbzw8L01hcmtlZCB0\r\n" +
"cnVlPj4+Pg0KZW5kb2JqDQoyIDAgb2JqDQo8PC9UeXBlL1BhZ2VzL0NvdW50IDEvS2lkc1sg\r\n" +
"MyAwIFJdID4+DQplbmRvYmoNCjMgMCBvYmoNCjw8L1R5cGUvUGFnZS9QYXJlbnQgMiAwIFIv\r\n" +
"UmVzb3VyY2VzPDwvRm9udDw8L0YxIDUgMCBSL0YyIDcgMCBSL0YzIDkgMCBSPj4vUHJvY1Nl\r\n" +
"dFsvUERGL1RleHQvSW1hZ2VCL0ltYWdlQy9JbWFnZUldID4+L01lZGlhQm94WyAwIDAgNTk0\r\n" +
"Ljk2IDg0Mi4wNF0gL0NvbnRlbnRzIDQgMCBSL0dyb3VwPDwvVHlwZS9Hcm91cC9TL1RyYW5z\r\n" +
"cGFyZW5jeS9DUy9EZXZpY2VSR0I+Pi9UYWJzL1MvU3RydWN0UGFyZW50cyAwPj4NCmVuZG9i";
const string partPDF =
"Content-Type: application/pdf;\r\n" +
" name=\"=?ISO-8859-1?Q?=D8nskeliste=2Epdf?=\"\r\n" +
"Content-Transfer-Encoding: base64\r\n" +
"\r\n" +
base64;
// Base 64 is only in ASCII
Message message = new Message(Encoding.ASCII.GetBytes(partPDF));
MessagePart messagePart = message.MessagePart;
// Check the headers
Assert.AreEqual("application/pdf", messagePart.ContentType.MediaType);
Assert.AreEqual(ContentTransferEncoding.Base64, messagePart.ContentTransferEncoding);
Assert.AreEqual("Ønskeliste.pdf", messagePart.ContentType.Name);
// This will fail if US-ASCII is assumed on the bytes when decoded from base64 to bytes
Assert.AreEqual(Convert.FromBase64String(base64), messagePart.Body);
}
示例2: FindPlainTextInMessage
private string FindPlainTextInMessage(Message message)
{
OpenPop.Mime.Header.MessageHeader msgheader = message.Headers;
string sender = msgheader.From.Address;
string LinkExtracted = "";
if (sender == cSender)
{
List<MessagePart> list = message.FindAllTextVersions();
string str = "";
foreach (MessagePart part in list)
{
if (part != null)
{
try
{
//string pattern = @"http://www.gutefrage.net/registrierungsbestaetigung.*(?=\042)"; linkpattern
//part.Save(new FileInfo("temp"));
//string str2 = File.ReadAllText("temp");
string str2 = part.GetBodyAsText();
int startIndex = 0;
int num2 = 0;
startIndex = str2.IndexOf(linkpattern, startIndex);
while (startIndex != -1)
{
startIndex = startIndex + ShiftBy;
char[] anyOf = new char[] { ' ', '"', '>', '<', '\r', '\n', '\\', ')' };
num2 = str2.IndexOfAny(anyOf, startIndex);
string str3 = str2.Substring(startIndex, num2 - startIndex);
if (str == str3)
{
startIndex = str2.IndexOf(linkpattern, num2);
}
else
{
// File.AppendAllText("links.txt", str3 + "\r\n");
LinkExtracted = str3;
str = str3;
startIndex = str2.IndexOf(linkpattern, num2);
}
}
return LinkExtracted;
}
catch (Exception)
{
// Console.WriteLine("Pizdets!");
return null;
}
}
}
}
if (LinkExtracted != "")
{
return LinkExtracted;
}
else
{
return null;
}
}
示例3: FindHtmlInMessage
/// <summary>
/// Example showing:
/// - how to find a html version in a Message
/// - how to save MessageParts to file
/// </summary>
/// <param name="message">The message to examine for html</param>
public static void FindHtmlInMessage(Message message)
{
MessagePart html = message.FindFirstHtmlVersion();
if (html != null)
{
// Save the plain text to a file, database or anything you like
html.Save(new FileInfo("html.txt"));
}
}
示例4: TestContentDisposition
public void TestContentDisposition()
{
const string messagePartContent =
"Content-Disposition: attachment\r\n" +
"\r\n"; // End of message headers
MessagePart messagePart = new Message(Encoding.ASCII.GetBytes(messagePartContent)).MessagePart;
Assert.IsFalse(messagePart.ContentDisposition.Inline);
}
示例5: Setup
public void Setup()
{
_stubEmailSubject = "Stub Email Subject";
_stubEmailBody = "Stub Email Body";
_stubEmail = MessageGenerator.GenerateMessage(_stubEmailSubject, _stubEmailBody);
_translator = new MessageTranslator();
}
示例6: TestIsAttachmentApplicationPdf
public void TestIsAttachmentApplicationPdf()
{
const string messagePartContent =
"Content-Type: application/pdf\r\n" +
"\r\n"; // End of message headers
MessagePart messagePart = new Message(Encoding.ASCII.GetBytes(messagePartContent)).MessagePart;
Assert.IsTrue(messagePart.IsAttachment);
}
示例7: TestContentTypeWithMissingSemicolonAndTabs
public void TestContentTypeWithMissingSemicolonAndTabs()
{
const string messagePartContent =
"Content-Type: text/plain;\r\n\tcharset=\"Windows-1252\"\r\n\tname=\"ALERTA_1.txt\"\r\n" +
"\r\n"; // End of message headers
MessagePart messagePart = new Message(Encoding.ASCII.GetBytes(messagePartContent)).MessagePart;
Assert.AreEqual(Encoding.GetEncoding(1252), messagePart.BodyEncoding);
}
示例8: TestIsTextTextPlain
public void TestIsTextTextPlain()
{
const string messagePartContent =
"Content-Type: text/plain\r\n" +
"\r\n"; // End of message headers
MessagePart messagePart = new Message(Encoding.ASCII.GetBytes(messagePartContent)).MessagePart;
Assert.IsTrue(messagePart.IsText);
}
示例9: TestIsTextMessageRfc822
public void TestIsTextMessageRfc822()
{
const string messagePartContent =
"Content-Type: message/rfc822\r\n" +
"\r\n"; // End of message headers
MessagePart messagePart = new Message(Encoding.ASCII.GetBytes(messagePartContent)).MessagePart;
Assert.IsTrue(messagePart.IsText);
}
示例10: MessageToString
public static string MessageToString(Message message)
{
using (var stream = new MemoryStream())
{
message.Save(stream);
stream.Position = 0;
var reader = new StreamReader(stream);
return reader.ReadToEnd();
}
}
示例11: TestContentTypeCharsetWithLargeFirstChar
public void TestContentTypeCharsetWithLargeFirstChar()
{
const string messagePartContent =
"Content-Type: TEXT/PLAIN; Charset=\"US-ASCII\"\r\n" +
"\r\n" + // End of message headers
"foo";
MessagePart messagePart = new Message(Encoding.ASCII.GetBytes(messagePartContent)).MessagePart;
Assert.AreEqual(Encoding.ASCII, messagePart.BodyEncoding);
Assert.AreEqual("foo", messagePart.GetBodyAsText());
}
示例12: TestContentDescriptionTwo
public void TestContentDescriptionTwo()
{
const string messagePartContent =
"Content-Description: This is some OTHER human readable text\r\n" +
"\r\n"; // End of message headers
MessagePart messagePart = new Message(Encoding.ASCII.GetBytes(messagePartContent)).MessagePart;
const string expectedDescription = "This is some OTHER human readable text";
string actualDescription = messagePart.ContentDescription;
Assert.AreEqual(expectedDescription, actualDescription);
}
示例13: get_subject
public static string get_subject(Message message)
{
string subject = message.Headers.Subject;
if (string.IsNullOrWhiteSpace(subject))
{
subject = "[No Subject]";
}
return subject;
}
示例14: TestLineEndingsNotStrippedAwayAtStart
public void TestLineEndingsNotStrippedAwayAtStart()
{
const string input =
"Content-Type: text/plain; charset=iso-8859-1\r\n" +
"Content-Transfer-Encoding: 7bit\r\n" +
"\r\n" + // Headers end
"\r\nHello"; // This is where the first \r\n should not be removed
const string expectedOutput = "\r\nHello";
string output = new Message(Encoding.ASCII.GetBytes(input)).MessagePart.GetBodyAsText();
Assert.AreEqual(expectedOutput, output);
}
示例15: ParseContentDispositionFilenameWithEncoding
public void ParseContentDispositionFilenameWithEncoding()
{
const string messageHeaders =
"Content-Disposition: attachment;\r\n" +
" filename*=ISO-8859-1\'\'%D8%6E%73%6B%65%6C%69%73%74%65%2E%70%64%66\r\n" +
"\r\n";
MessageHeader headers = new Message(Encoding.ASCII.GetBytes(messageHeaders), false).Headers;
// Tests that the ContentDisposition header correctly decoded the filename
Assert.NotNull(headers.ContentDisposition.FileName);
Assert.AreEqual("Ønskeliste.pdf", headers.ContentDisposition.FileName);
}