本文整理汇总了C#中OpenPop.Mime.Message.FindFirstHtmlVersion方法的典型用法代码示例。如果您正苦于以下问题:C# Message.FindFirstHtmlVersion方法的具体用法?C# Message.FindFirstHtmlVersion怎么用?C# Message.FindFirstHtmlVersion使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenPop.Mime.Message
的用法示例。
在下文中一共展示了Message.FindFirstHtmlVersion方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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"));
}
}
示例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: TestGetFirstHTMLVersion
public void TestGetFirstHTMLVersion()
{
const string rfcExample =
"Content-type: text/html; charset=us-ascii\r\n" +
"\r\n" +
"HTML here";
Message message = new Message(Encoding.ASCII.GetBytes(rfcExample));
MessagePart part = message.FindFirstHtmlVersion();
Assert.NotNull(part);
Assert.AreEqual("text/html", part.ContentType.MediaType);
Assert.AreEqual("HTML here", part.GetBodyAsText());
}
示例8: PushToIssueTracker
private static bool PushToIssueTracker(Message message)
{
Console.WriteLine("\t\tPushing message '{0}' to IssueTracker ...", message.Headers.Subject);
try
{
var messageBody = message.FindFirstHtmlVersion().GetBodyAsText();
var creator = GetMatch(messageBody, "Creator: (.*?)<br");
var text = GetMatch(messageBody, "Text:<pre>(.*?)</pre>");
var stackTrace = GetMatch(messageBody, "Stack Trace:<pre>(.*?)</pre>");
var serverVariables = GetMatch(messageBody, "Server Variables:<pre>(.*?)</pre>");
if (text.StartsWith("IssueTracker unreachable - "))
text = text.Substring("IssueTracker unreachable - ".Length);
creator = HttpUtility.HtmlDecode(creator);
text = HttpUtility.HtmlDecode(text);
stackTrace = HttpUtility.HtmlDecode(stackTrace);
serverVariables = HttpUtility.HtmlDecode(serverVariables);
if (creator.IsNoE() && text.IsNoE() && stackTrace.IsNoE() && serverVariables.IsNoE())
return false;
if (message.Headers.Sender != null && message.Headers.Sender.Address.HasValue())
creator += " (" + message.Headers.Sender.Address + ")";
else if (message.Headers.ReplyTo != null && message.Headers.ReplyTo.Address.HasValue())
creator += " (" + message.Headers.ReplyTo.Address + ")";
try
{
var issueTracker = new Client.IssueTracker();
issueTracker.Post(new Issue
{
Text = text,
ServerVariables = serverVariables,
Source = creator,
StackTrace = stackTrace,
Version = ""
});
Console.WriteLine("\t\tMessage pushed.");
}
catch (Exception ex)
{
Console.WriteLine("\t\tUnable to push message: " + ex);
LogOwnError(new ApplicationException("Unable to push message: " + ex.Message, ex));
}
return true;
}
catch
{
Console.WriteLine("\t\tMessage seems not to be an issue report.");
return false;
}
}