电子邮件监控同步

发布于 2024-07-23 07:41:41 字数 317 浏览 10 评论 0原文

我正在编写一个 C# 程序,该程序使用 POP3 来监视专用 Gmail 帐户的专门命令电子邮件并做出适当的反应。

为了获得最大的可靠性,我将在全国各地的多台计算机上运行该程序。 我目前有一个竞争条件,程序的两个实例可以在其中一个实例删除同一条消息之前读取该消息,从而导致该消息被处理两次。

如何确保每个命令只处理一次?

Gmail 的 POP3 访问过去只为每封邮件提供一次(使 RETR 和 DELE 成为单个原子操作),但我无法再重现此行为。

计算机之间通信的唯一方法是 SQL Server 和 HTTP 服务器(由我控制)。

I'm writing a C# program that monitors a dedicated Gmail account using POP3 for specialized command emails and reacts appropriately.

For maximum reliability, I will run this program on several computers throughout the country.
I currently have a race condition where two instances of the program can read the same message before one of them deletes it, causing the message to be processed twice.

How can I make sure that each command is processed exactly once?

Gmail's POP3 access used to only serve each message once (making RETR and DELE a single atomic operation), but I can no longer reproduce this behavior.

The only method of communication between the computers is a SQL Server and an HTTP server (which I control).

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

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

发布评论

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

评论(2

打小就很酷 2024-07-30 07:41:41

我想到的一个选择是使用 POP3 的 UIDL 命令,并在 SQL Server 中创建一个表,其中包含已处理的 UIDL 的唯一列。

然后,在下载每条消息之前,守护进程会将 UIDL 插入表中,如果出现错误,则跳过该消息。 (我假设 SQL Server 的 INSERT 命令是原子操作)。

One option I've thought of is to use POP3's UIDL command, and have a table in SQL Server with a unique column of UIDLs that were already processed.

Then, before downloading each message, the daemon would INSERT the UIDL into the table, and, if it got an error, skip the message. (I'm assuming that SQL Server's INSERT command is an atomic operation).

極樂鬼 2024-07-30 07:41:41

首先我必须承认我不知道 POP3 支持哪些命令,但是...如果您可以执行显式“DELE”并在消息不再存在时收到错误,那么我会说:

  • RETR 消息
  • DELE 消息
  • 处理仅当 DELE 成功

编辑:

阅读 RFC1939 后,这种方法应该有效; 来自 RFC:

DELE msg

     Arguments:
         a message-number (required) which may NOT refer to a
         message marked as deleted

     Restrictions:
         may only be given in the TRANSACTION state

     Discussion:
         The POP3 server marks the message as deleted.  Any future
         reference to the message-number associated with the message
         in a POP3 command generates an error.  The POP3 server does
         not actually delete the message until the POP3 session
         enters the UPDATE state.

     Possible Responses:
         +OK message deleted
         -ERR no such message

     Examples:
         C: DELE 1
         S: +OK message 1 deleted
            ...
         C: DELE 2
         S: -ERR message 2 already deleted

这当然是假设 Gmail 实现实际上遵循 RFC。

First I must admit I do not know what commands POP3 supports, but... if you can do an explicit 'DELE' and get an error if the message no longer exists, then I'd say:

  • RETR the message
  • DELE the message
  • Process only if DELE succeeded

EDIT:

After reading RFC1939, this approach should work; from the RFC:

DELE msg

     Arguments:
         a message-number (required) which may NOT refer to a
         message marked as deleted

     Restrictions:
         may only be given in the TRANSACTION state

     Discussion:
         The POP3 server marks the message as deleted.  Any future
         reference to the message-number associated with the message
         in a POP3 command generates an error.  The POP3 server does
         not actually delete the message until the POP3 session
         enters the UPDATE state.

     Possible Responses:
         +OK message deleted
         -ERR no such message

     Examples:
         C: DELE 1
         S: +OK message 1 deleted
            ...
         C: DELE 2
         S: -ERR message 2 already deleted

This is ofcourse assuming that the Gmail implementation actually honours the RFC.

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