电子邮件客户端如何处理来自 POP 服务器的邮件?

发布于 2024-12-11 08:53:01 字数 914 浏览 3 评论 0原文

当编写通过套接字连接到 POP3 协议的连接时,我可以使用 LIST 命令来获取电子邮件列表。假设我执行 LIST 命令,它会在列表中返回 3700 封邮件。我将整个响应读入缓冲区。现在,我想在我的申请中一一列出这些邮件。

LIST
1 1472
...
3696 3224
3697 5998
3698 1970
3699 1425
3700 129345
.

我心里有两个想法。首先,我可以逐行解析响应并获取消息的消息号。对于每一行,我都会得到消息编号,比如 #3700,我会执行 TOP 3700 10。因此这将读取 10 行邮件标头。起初,我认为这会很好,因为我不必只下载整个邮件的主题、姓名、发件人地址和电子邮件的一些简短内容;我可以节省交通。但问题是并非所有电子邮件都只有 10 行标题。有些电子邮件的标题非常长,而另一些则非常短。很难确定要读取多少行。不仅如此,因为电子邮件没有完全下载,当用户想要阅读完整的邮件时,我必须发送另一个 RETR 命令来获取整个电子邮件。然后假设是否有另一个到 POP 帐户的连接并删除了消息#3700。我的应用程序仍然通过这个“非唯一”消息 ID 来识别电子邮件。当我的应用程序想要下载电子邮件并发送 RETR 3700 时,它将响应 -ERR Server Unavailable。 21

我的第二个想法是使用 RETR 3700。这将读取整个邮件,只是为了在应用程序中列出一些信息。我认为这有点愚蠢,因为如果邮箱有很多邮件,我会将整个邮箱检索到应用程序的内存中!

电子邮件客户端处理来自 POP 服务器的邮件有哪些常见/巧妙的方法?

PS:我没有使用 JavaMail,因为目的是了解有关 POP 协议如何工作以及用于使用该协议的实现的更多信息。

When writing a connection to connect to the POP3 protocol through sockets, I could use the LIST command to get the list of emails. Suppose I do a LIST command, it returns 3700 mails in the list. I read the whole response into a buffer. Now, I want to list these mails one by one on my application.

LIST
1 1472
...
3696 3224
3697 5998
3698 1970
3699 1425
3700 129345
.

I had 2 ideas in mind. First, I could parse the response line by line and get the message number of the message. And for each line I get the message number, say #3700, I do a TOP 3700 10. So this would read 10 lines of the mail headers. At first, I thought this would be good because I don't have to do a download the entire mail just for the subject, name, from address and some bit of brief content of the email; I could save the traffic. But the problem is not all emails have only 10 lines of headers. Some emails have extremely long headers while others are very short. It is difficult to determine how many lines to read. Not only that, because the email is not entirely downloaded, when the user wants to read the full mail, I have to send another RETR command to get the whole email. Then suppose if there were another connection to the POP account and deleted the message #3700. My application still recognise the email by this "non-unique" message id. When my application wants to download the email and sends a RETR 3700, it will respond with a -ERR Server Unavailable. 21

The second idea I have is then to use a RETR 3700. This would read the whole mail, just for that few information to list it in the application. I thought this is kind of silly because if the mailbox has a lot of mails, I am retrieving the entire mailbox into the application's memory!

What are the common/clever ways an email client would handle the mails from the POP server?

PS: I am not using the JavaMail because the intention is to learn more about how the POP protocol works and the implementations used to work with the protocols.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

伪心 2024-12-18 08:53:01

TOP 命令的第二个参数是要下载的非负消息行数 - 不包括标题行

您可以使用 TOP 命令并将行数设置为 0 (TOP message_number 0) 以仅下载消息标头。

The 2nd argument of TOP command is a non-negative number of message lines to download - header lines are not included.

You can use TOP command with 0 as line count (TOP message_number 0) to download only message headers.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文