简体   繁体   English

使用mimekit.mimemessage从硬盘加载eml文件如何只加载文本?

[英]Using mimekit.mimemessage to load eml files from hard disk how can I load only text?

This is how I'm using it today 这就是我今天使用的方式

private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
    int counter = 0;
    MimekitallLoadedMessages = new List<MimeKit.MimeMessage>();
    MimeKit.MimeMessage loadedMessage = null;
    DirectoryInfo di = new DirectoryInfo(emailsDirectory);
    FileInfo[] files = di.GetFiles();
    for (int i = 0; i < files.Length; i++)
    {
        string uid = seenUids[0];
        loadedMessage = MimeKit.MimeMessage.Load(files[i].FullName);
        MimekitallLoadedMessages.Add(loadedMessage);
        downloaded.Add(seenUids[i]);
        counter += 1;
        int nProgress = counter * 100 / files.Length;
        backgroundWorker2.ReportProgress(nProgress);
    }
}

The method Load just load the whole message. 加载方法只加载整个消息。 But i wander if i can Load for exmaple on the subject of each message and teh add it to a listView for example so the user later will be able to select a specific email to load it's all content like the html or the whole body content. 但是我徘徊在我是否可以在每条消息的主题上加载示例并将其添加到例如listView中的位置,以便用户以后可以选择特定的电子邮件来加载它的所有内容,例如html或整个正文。

So loading only the subject and make a list of all the emails in the listView will load the messages faster. 因此,仅加载主题并在listView中列出所有电子邮件的列表将更快地加载消息。 I have like 6000 eml files on hard disk. 我在硬盘上有6000个eml文件。

Loading all the files and add all the messages to the listView might take some time. 加载所有文件并将所有消息添加到listView可能需要一些时间。 Instead maybe loading/parsing only the text might be faster ? 相反,也许只加载/解析文本可能会更快?

Is it possible ? 可能吗 ? And logic ? 和逻辑? Maybe when i download the messages first time i should create a text file with all the subjects of each email and then when running my program just to read the lines from the text file, each line is a subject ? 也许当我第一次下载消息时,我应该创建一个包含每个电子邮件的所有主题的文本文件,然后在运行程序以从文本文件中读取各行时,每行都是一个主题?

UPDATE 更新

This is the dowork event now: 现在这是dowork事件:

private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
        {
            MimeKit.HeaderList loaded = new MimeKit.HeaderList();
            int counter = 0;
            MimekitallLoadedMessages = new List<MimeKit.MimeMessage>();
            MimeKit.MimeMessage loadedMessage = null;
            DirectoryInfo di = new DirectoryInfo(emailsDirectory);
            FileInfo[] files = di.GetFiles();
            for (int i = 0; i < files.Length; i++)
            {
                string uid = seenUids[0];
                loaded = MimeKit.HeaderList.Load(files[i].FullName);
                var subject = loaded[MimeKit.HeaderId.Subject];
                downloaded.Add(seenUids[i]);
                counter += 1;
                int nProgress = counter * 100 / files.Length;
                backgroundWorker2.ReportProgress(nProgress, subject);
            }
         }

And the progresschanged event how i'm updating the listView control: 和progresschanged事件,我如何更新listView控件:

private void backgroundWorker2_ProgressChanged(object sender, ProgressChangedEventArgs e)
        {
            pbt1.Value = e.ProgressPercentage;
            pbt1.Text = e.ProgressPercentage.ToString() + "%";
            pbt1.Invalidate();
            if (e.UserState != null)
            {

                ListViewCostumControl.lvnf.Items.Add(new ListViewItem(new string[]
            {
                e.UserState.ToString()
            }));
            }
         }

You can parse the headers only if you want via HeaderList.Load . 仅当需要时,才可以通过HeaderList.Load解析标头。 This will be faster than parsing the whole message. 这将比解析整个消息更快。 Here is an example: 这是一个例子:

string filename = ...

var headerList = HeaderList.Load(filename);

var subject = headerList[HeaderId.Subject];

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

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