简体   繁体   English

使用 MailKit 的正文或消息包含方法

[英]Body or Message Contains method using MailKit

I'm using MailKit for received messages via Imap.我正在使用 MailKit 通过 Imap 接收消息。

Now I need a search-logic for the software and I got a some troubles.现在我需要软件的搜索逻辑,但遇到了一些麻烦。

For ex, I using:例如,我使用:

var query = SearchQuery.BodyContains("SomeTextfromEmail");
( or var query = SearchQuery.MessageContains("SomeTextfromEmail"); )

foreach (UniqueId uid in imapfolder.Search(query)){
  //some logic
}

So, I can't get messages with text contains on it with Search filter.因此,我无法使用搜索过滤器获取包含文本的消息。 I'm downloaded message ( message.WriteTo(string.Format(@"C:{0}.eml", uid)); ) and see the message content.我下载了消息( message.WriteTo(string.Format(@"C:{0}.eml", uid)); )并查看消息内容。 Text of message in a base-64 format. base-64 格式的消息文本。

How do it correctly?怎么做才正确? I need decode message text from base64?我需要从 base64 解码消息文本吗?

Problem are here:问题在这里:

var query = SearchQuery.BodyContains("Iphone").And(SearchQuery.All);  //this construction find messages in folder
foreach (var uid in imapfolder.Search(query))
{
    Console.WriteLine(message.From + "  :  " + uid.ToString());
}


var query = SearchQuery.BodyContains("Received from Iphone").And(SearchQuery.All); //this construction can't find message in folder
foreach (var uid in imapfolder.Search(query))
{
    Console.WriteLine(message.From + "  :  " + uid.ToString());
}

Your question is a jumbled mess of confusion (your question starts out saying you are trying to figure out how to search and then you end with asking how to base64 decode the raw message that you saved to a file) so I have no idea exactly what you want to know.你的问题是一团乱麻(你的问题开始是说你试图弄清楚如何搜索,然后你问如何对保存到文件的原始消息进行 base64 解码)所以我不知道到底是什么你要知道。

If all you want is the decoded text body, you can do this:如果你想要的只是解码后的文本正文,你可以这样做:

var message = imapfolder.GetMessage (uid);
var text = message.TextBody;

This will be the decoded text string (either base64 decoded or quoted-printable decoded if it needs to be).这将是解码后的文本字符串(如果需要,可以使用 base64 解码或带引号的可打印解码)。

The MimeKit README and FAQ are both full of useful information on the basics of how to use them. MimeKit READMEFAQ都包含有关如何使用它们的基础知识的有用信息。 I would highly recommend reading them as they may be helpful.我强烈建议阅读它们,因为它们可能会有所帮助。

Update:更新:

Based on the comment added to my answer, it sounds like what you want to do is this?根据添加到我的答案中的评论,听起来您想要做什么?

var matched = new UniqueIdSet ();
foreach (var uid in folder.Search (SearchQuery.BodyContains ("iPhone"))) {
    var message = folder.GetMessage (uid);
    var body = message.TextBody;

    if (body != null && body.Contains ("Received from iPhone"))
        matched.Add (uid);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM