问题描述
我有一个电子邮件界面客户端,并且我正在使用IMAP进行请求.我希望能够实时显示基本的电子邮件数据以显示列表视图.
I have an email interface client, and I am using IMAP for my requests. I want to be able to show, in real-time, basic email data, for a list view.
例如,在GMail列表视图中.为此,我需要执行IMAP请求以获取所有电子邮件的主题,所有电子邮件的日期等.到目前为止,此方法有效.
As in, for example, the GMail list view. For that, I need to do an IMAP request to obtain the subject of all emails, the date of all emails, etc. This works so far.
问题是,我还要显示正文的第一个字符.如果我使用BODYSTRUCTURE
调用来获取text/HTML
部分的索引,则它会花费太长时间(对于具有数千个字符的电子邮件,每封电子邮件可能要花费一秒钟的时间,而仅使用subject/date/etc调用会花费最长约0.02秒
The problem is, I want to also show the first characters of the body text. If I use the BODYSTRUCTURE
call to obtain the index of the text/HTML
part it takes too long (for emails with thousands of characters it might take well over a second per email, while using only the subject/date/etc calls takes about 0.02 seconds max.
我尝试使用BODY[INDEX]<0.XYZ>
字节,其中XYZ
是我们要获取的第一个字节的数目,但令我沮丧的是,它花费的时间与使用BODY[INDEX]
调用一样长.有时甚至更多.
I tried using the BODY[INDEX]<0.XYZ>
bytes where XYZ
is the number of the first bytes we want to obtain, but to my dismay, it takes as long as using the BODY[INDEX]
call. Sometimes even more.
是否有另一种方式来获取前几个文字字符,但又要快速?如果我想在界面上列出300封电子邮件,那么我就不能为了获得第一个文本字符而每封电子邮件花费1秒钟的时间.
Is there another way to obtain the first text characters, but in a quick manner? If I want to list 300 emails on my interface I cannot afford to spend 1 second per email just to obtain the first text characters.
我正在将Python与imaplib结合使用,即使可能不相关.
I'm using Python with imaplib for this, even though probably not relevant.
推荐答案
在 IMAP RFC .
FETCH 2 (BODY[]<0.size>)
例如,如果您要获取前100个字节的邮件,则可以将命令触发为
for example if you want to fetch first 100 bytes of mail then you can fire the command as
FETCH 2 (BODY[]<0.100>)
这篇关于获取部分IMAP文本部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!