本文整理汇总了C#中OpenPop.Mime.Message.FindFirstPlainTextVersion方法的典型用法代码示例。如果您正苦于以下问题:C# Message.FindFirstPlainTextVersion方法的具体用法?C# Message.FindFirstPlainTextVersion怎么用?C# Message.FindFirstPlainTextVersion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenPop.Mime.Message
的用法示例。
在下文中一共展示了Message.FindFirstPlainTextVersion方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Translate
public EmailWatcherMessage Translate(Message message)
{
if (message == null)
{
Logger.LogError(ExceptionMessageConstants.EmailMessageCannotBeNull);
throw new Exception();
}
EmailWatcherMessage toReturn = new EmailWatcherMessage
{
Subject = message.Headers.Subject,
Body = message.FindFirstPlainTextVersion().GetBodyAsText(),
Id = message.Headers.MessageId
};
return toReturn;
}
示例2: readMail
public static string readMail(Message mail)
{
StringBuilder bodyBuilder = new StringBuilder();
MessagePart plainText = mail.FindFirstPlainTextVersion();
MessagePart htmlText = mail.FindFirstHtmlVersion();
if (plainText != null)
bodyBuilder.Append(plainText.GetBodyAsText());
if (htmlText != null)
bodyBuilder.Append(htmlText.GetBodyAsText());
if (plainText == null && bodyBuilder == null)
return "Empty mail";
else
return bodyBuilder.ToString();
}
示例3: insetToDatabase
//Takes SQLCOMMAND as parameter and run the command aginst the Database.
public static void insetToDatabase( Message mail)
{
dbConnection.Open();
//SQLiteCommand command = new SQLiteCommand(SQLCOMMAND, dbConnection);
//command.ExecuteNonQuery();
//dbConnection.Close();
SQLiteCommand cmd = new SQLiteCommand(dbConnection);
SQLiteParameter param = cmd.CreateParameter();
string SQLCOMMAND = @"INSERT INTO MailList (MessageId, Receiver, Sender, Date, Subject, Message) VALUES ('" + mail.Headers.MessageId + "','" + mail.Headers.To + "','" + mail.Headers.From + "','" + mail.Headers.DateSent + "','" + mail.Headers.Subject + "', @param)";
cmd.CommandText = SQLCOMMAND;
param.ParameterName = "param";
MessagePart html = mail.FindFirstHtmlVersion();
MessagePart plainText = mail.FindFirstPlainTextVersion();
StringBuilder builder = new StringBuilder();
if (html != null)
param.Value = builder.Append(html.GetBodyAsText()).ToString();
else
param.Value = plainText.GetBodyAsText();
cmd.Parameters.Add(param);
try
{
cmd.ExecuteNonQuery();
}
catch (Exception)
{
}
//always close the connection!!
finally { dbConnection.Close(); }
}
示例4: SaveMail
private static void SaveMail(int i, Message message)
{
MessagePart plainHtmlPart = message.FindFirstHtmlVersion();
MessagePart plainTextPart = message.FindFirstPlainTextVersion();
string textMail = null;
if (plainHtmlPart == null && plainTextPart != null)
{
textMail = plainTextPart.GetBodyAsText();
}
else if (plainHtmlPart == null && plainTextPart == null)
{
List<MessagePart> textVersions = message.FindAllTextVersions();
if (textVersions.Count >= 1)
textMail = textVersions[0].GetBodyAsText();
}
else if (plainHtmlPart != null)
{
textMail = plainHtmlPart.GetBodyAsText();
}
string xamlMail = HTMLConverter.HtmlToXamlConverter.ConvertHtmlToXaml(textMail, true);
StringReader sr = new StringReader(xamlMail);
XmlReader xr = XmlReader.Create(sr);
FlowDocument fdMail = (FlowDocument)XamlReader.Load(xr);
FlowDocument fd = new FlowDocument();
DateTime dateMail = Convert.ToDateTime(message.Headers.Date);
BLL.DiaryBLL dbll = new BLL.DiaryBLL();
fd = dbll.GetDoc(dateMail.Date.ToString());
fd = CommonHelper.MergeFlowDocument(fd, fdMail);
dbll.Save(fd, dateMail.Date.ToString());
}
示例5: get_comment
public static string get_comment(Message message)
{
string commentText = null;
MessagePart comment = message.FindFirstPlainTextVersion();
if (comment != null)
{
commentText = comment.GetBodyAsText();
if (string.IsNullOrEmpty(commentText))
{
comment = message.FindFirstHtmlVersion();
if (comment != null)
{
commentText = comment.GetBodyAsText();
}
}
}
if (string.IsNullOrEmpty(commentText))
{
commentText = "NO PLAIN TEXT MESSAGE BODY FOUND";
}
return commentText;
}
示例6: insertMessageIntoSQL
//return true if msg was added
/// <summary>
/// insert the message into an sqlite database
/// </summary>
/// <param name="mess">message to insert</param>
/// <param name="connection">connection to database to insert to</param>
/// <returns>true if it succeeds with inserting to the sqlite database</returns>
private bool insertMessageIntoSQL(Message mess, SQLiteConnection connection)
{
if (!isMessageInDB(mess.Headers.MessageId, connection))//if message is not in db then add to db
{
SQLiteCommand cmd = new SQLiteCommand("INSERT INTO `mails`(`MessageID`,`Subject`,`Sender`,`Message`,`ReceivedMail`,`ReceivedTime`,`Importance`) VALUES (@msgid,@Subject,@Sender,@Message,@ReceivedMail,@ReceivedTime,@Importance);");
cmd.Parameters.Add(new SQLiteParameter("@msgid", mess.Headers.MessageId));
try
{
if (mess.Headers.UnknownHeaders["isEncrypted"] == "true")
{
string key = mess.Headers.UnknownHeaders["key"];
string iv = mess.Headers.UnknownHeaders["iv"];
if (mess.Headers.UnknownHeaders["advancedEncryption"] == "true")
{
key = advancedEncryption.RSADecrypt(key,mess.Headers.UnknownHeaders["AEString"]);
iv = advancedEncryption.RSADecrypt(iv, mess.Headers.UnknownHeaders["AEString"]);
}
string s = EncryptionHandler.decryptstring(mess.FindFirstHtmlVersion().GetBodyAsText().Replace("\r\n\r\n\r\n---\r\nDenne e-mail er fri for virus og malware fordi avast! Antivirus beskyttelse er aktiveret.\r\nhttp://www.avast.com\r\n", ""), key, iv);
cmd.Parameters.Add(new SQLiteParameter("@Message", s));
}
else
{
cmd.Parameters.Add(new SQLiteParameter("@Message", mess.FindFirstHtmlVersion().GetBodyAsText()));
}
}
catch
{
if (mess.Headers.UnknownHeaders["isEncrypted"] == "true")
{
string key = mess.Headers.UnknownHeaders["key"];
string iv = mess.Headers.UnknownHeaders["iv"];
if (mess.Headers.UnknownHeaders["advancedEncryption"] == "true")
{
key = advancedEncryption.RSADecrypt(key, mess.Headers.UnknownHeaders["AEString"]);
iv = advancedEncryption.RSADecrypt(iv, mess.Headers.UnknownHeaders["AEString"]);
}
string s = EncryptionHandler.decryptstring(mess.FindFirstPlainTextVersion().GetBodyAsText().Replace("\r\n\r\n\r\n---\r\nDenne e-mail er fri for virus og malware fordi avast! Antivirus beskyttelse er aktiveret.\r\nhttp://www.avast.com\r\n", ""), key, iv);
cmd.Parameters.Add(new SQLiteParameter("@Message", s));
}
else
{
cmd.Parameters.Add(new SQLiteParameter("@Message", mess.FindFirstPlainTextVersion().GetBodyAsText()));
}
}
cmd.Parameters.Add(new SQLiteParameter("@Subject", mess.Headers.Subject));
cmd.Parameters.Add(new SQLiteParameter("@Sender", mess.Headers.From));
cmd.Parameters.Add(new SQLiteParameter("@ReceivedMail", mess.Headers.To[0]));
cmd.Parameters.Add(new SQLiteParameter("@ReceivedTime", mess.Headers.DateSent));
cmd.Parameters.Add(new SQLiteParameter("@Importance", mess.Headers.Importance.ToString()));
cmd.Connection = connection;
cmd.ExecuteNonQuery();
return true;
}
else
{
return false;
}
}
示例7: FindPlainTextInMessage
/// <summary>
/// Example showing:
/// - how to a find plain text version in a Message
/// - how to save MessageParts to file
/// </summary>
/// <param name="message">The message to examine for plain text</param>
public static void FindPlainTextInMessage(Message message)
{
MessagePart plainText = message.FindFirstPlainTextVersion();
if(plainText != null)
{
// Save the plain text to a file, database or anything you like
plainText.Save(new FileInfo("plainText.txt"));
}
}
示例8: TestComplexMultiPartMessage
//.........这里部分代码省略.........
Assert.AreEqual("[email protected]", message.Headers.To[0].Address);
// Date
Assert.AreEqual("Fri, 07 Oct 1994 16:15:05 -0700 (PDT)", message.Headers.Date);
// -0700 is the same as adding 7 hours in the UTC DateTime
Assert.AreEqual(new DateTime(1994, 10, 7, 23, 15, 05, DateTimeKind.Utc), message.Headers.DateSent);
// Subject
Assert.AreEqual("A multipart example", message.Headers.Subject);
MessagePart part1 = message.MessagePart;
Assert.AreEqual("multipart/mixed", part1.ContentType.MediaType);
Assert.IsTrue(part1.IsMultiPart);
Assert.NotNull(part1.MessageParts);
Assert.IsNull(part1.Body);
// There is a total of 5 multiparts in the first message (unique-boundary-1)
Assert.AreEqual(5, part1.MessageParts.Count);
// Fetch out the parts, which are checked against later
System.Collections.Generic.List<MessagePart> attachments = message.FindAllAttachments();
System.Collections.Generic.List<MessagePart> textVersions = message.FindAllTextVersions();
// We are now going one level deeper into the message tree
{
MessagePart part1Part1 = part1.MessageParts[0];
Assert.NotNull(part1Part1);
Assert.IsFalse(part1Part1.IsMultiPart);
Assert.NotNull(part1Part1.Body);
Assert.AreEqual("text/plain", part1Part1.ContentType.MediaType);
Assert.AreEqual(" ... Some text appears here ...", part1Part1.GetBodyAsText());
// Check that the fetching algoritm for finding a plain-text version is working
Assert.AreEqual(part1Part1, message.FindFirstPlainTextVersion());
// Check this message is included in the text version
Assert.Contains(part1Part1, textVersions);
// But not included in the attachments
Assert.IsFalse(attachments.Contains(part1Part1));
// We are now going one level deeper into the message tree
{
MessagePart part1Part2 = part1.MessageParts[1];
Assert.NotNull(part1Part2);
Assert.IsFalse(part1Part2.IsMultiPart);
Assert.NotNull(part1Part2.Body);
Assert.AreEqual("text/plain", part1Part2.ContentType.MediaType);
Assert.AreEqual("US-ASCII", part1Part2.ContentType.CharSet);
Assert.AreEqual("This could have been part of the previous part, but\r\n" +
"illustrates explicit versus implicit typing of body\r\n" +
"parts.", part1Part2.GetBodyAsText());
// Check this message is included in the text version
Assert.Contains(part1Part2, textVersions);
// But not included in the attachments
Assert.IsFalse(attachments.Contains(part1Part2));
}
// We are now going one level deeper into the message tree
{
MessagePart part1Part3 = part1.MessageParts[2];
Assert.NotNull(part1Part3);
Assert.IsTrue(part1Part3.IsMultiPart);
Assert.IsNotNull(part1Part3.MessageParts);
示例9: TestContentTypeWithLargeCharactersCanStillBeFound
public void TestContentTypeWithLargeCharactersCanStillBeFound()
{
const string messagePartContent =
"Content-Type: TEXT/PLAIN\r\n" +
"\r\n" + // End of message headers
"foo";
Message message = new Message(Encoding.ASCII.GetBytes(messagePartContent));
// Cna be found
MessagePart textHtml = message.FindFirstPlainTextVersion();
Assert.NotNull(textHtml);
Assert.AreEqual("foo", textHtml.GetBodyAsText());
// Can still be found
System.Collections.Generic.List<MessagePart> messageParts = message.FindAllTextVersions();
Assert.IsNotEmpty(messageParts);
Assert.AreEqual(1, messageParts.Count);
Assert.AreEqual(textHtml, messageParts[0]);
}