[英]Mailkit - Get HTML and Text parts without having full mime message
I want to download text and html parts from mime message and store it in the database and later if needed to download attachments. 我想从mime消息中下载文本和html部分,并将其存储在数据库中,如果需要下载附件,可以稍后再存储。 I need this because I don't want to store the attachments in my database to save disk space and bandwidth.
我需要这样做是因为我不想将附件存储在数据库中以节省磁盘空间和带宽。 They will be downloaded on demand later.
它们将在以后按需下载。 I am not sure if I can do that and still be able to use MimeParser from MimeKit
我不确定是否可以这样做,但仍然可以使用MimeKit中的MimeParser
I am planning to do that: 我打算这样做:
Later I want to show the message in the UI but I want to delay parsing until the mail message needs to be shown in the UI. 稍后,我想在UI中显示消息,但是我想延迟解析,直到需要在UI中显示邮件消息为止。
This is my progress so far 到目前为止,这是我的进步
var msgSummaries = remoteFolder.Fetch(new int[] { remoteMessage.Index }, MessageSummaryItems.BodyStructure);
var stream = remoteFolder.GetStream(remoteMessage.Index, msgSummaries[0].HtmlBody.PartSpecifier);
//at this point i am saving the stream to the database and later i am trying to convert it to mime entity like that
var parser = new MimeParser(ParserOptions.Default, stream, true);
var mimeEntity = parser.ParseEntity(cancellationToken);
Unfortunatelly the stream doesn't contain mime part headers and cannot be parsed and I don't see an option to request headers inside GetStream method like this 不幸的是,流不包含mime部件标头,也无法解析,并且我看不到这样的选项来请求GetStream方法内的标头
FETCH 1 (BODY.PEEK[2.MIME] BODY.PEEK[2]) FETCH 1(BODY.PEEK [2.MIME] BODY.PEEK [2])
Any suggestions? 有什么建议么?
Well, first of all, have you tried: 好吧,首先,您是否尝试过:
var mimeEntity = remoteFolder.GetBodyPart (remoteMessage.Index, msgSummaries[0].HtmlBody);
or, if you really want to use streams: 或者,如果您确实要使用流:
var headerStream = remoteFolder.GetStream (remoteMessage.Index, msgSummaries[0].HtmlBody.PartSpecifier + ".MIME");
var contentStream = remoteFolder.GetStream (remoteMessage.Index, msgSummaries[0].HtmlBody.PartSpecifier);
var stream = new MemoryStream ();
headerStream.CopyTo (stream);
headerStream.Dispose ();
contentStream.CopyTo (stream);
contentStream.Dispose ();
stream.Position = 0;
//at this point i am saving the stream to the database and later i am trying to convert it to mime entity like that
var parser = new MimeParser(ParserOptions.Default, stream, true);
var mimeEntity = parser.ParseEntity(cancellationToken);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.