現在它是一個Gmail郵箱,但遲早我希望它可以擴展。獲取電子郵件未讀內容,而不影響未讀狀態
我想在其他地方同步個人郵箱(收件箱和發件箱)的副本,但我不想影響任何未讀郵件的unread
狀態。
什麼類型的訪問會使這個最簡單?如果IMAP會影響讀取狀態,我找不到任何信息,但看起來我可以手動重置消息以使其未讀。按定義流行不影響未讀狀態,但似乎沒有人使用彈出來訪問他們的Gmail,爲什麼?
現在它是一個Gmail郵箱,但遲早我希望它可以擴展。獲取電子郵件未讀內容,而不影響未讀狀態
我想在其他地方同步個人郵箱(收件箱和發件箱)的副本,但我不想影響任何未讀郵件的unread
狀態。
什麼類型的訪問會使這個最簡單?如果IMAP會影響讀取狀態,我找不到任何信息,但看起來我可以手動重置消息以使其未讀。按定義流行不影響未讀狀態,但似乎沒有人使用彈出來訪問他們的Gmail,爲什麼?
如果它幫助任何人,GAE允許你receive email as an HTTP request,所以現在我只是在那裏轉發電子郵件。
沒有人使用POP,因爲通常他們想要 IMAP的額外功能,例如跟蹤消息狀態。當這個功能只是在你的方式和需要解決方法,我認爲使用POP是你最好的選擇! - )
在IMAP世界裏,每條消息都有標誌。您可以在每條消息上設置單獨的標誌。當您提取郵件時,實際上可以閱讀該郵件,而不應用\ Seen標誌。
大多數郵件客戶端將在讀取郵件時應用\ Seen標誌。所以,如果消息已被讀取,在您的應用程序之外,那麼您將需要刪除\ Seen標誌。
正如僅供參考...這裏是有關國旗的有關部分從RFC文檔:
一個系統標誌是一個標誌名稱是在這個 規範預先定義。所有系統標誌都以「\」開頭。某些系統 標誌(\ Deleted和\ Seen)在其他地方具有描述爲 的特殊語義。當前定義的系統標誌是:
\Seen
Message has been read
\Answered
Message has been answered
\Flagged
Message is "flagged" for urgent/special attention
\Deleted
Message is "deleted" for removal by later EXPUNGE
\Draft
Message has not completed composition (marked as a draft).
\Recent
Message is "recently" arrived in this mailbox. This session
is the first session to have been notified about this
message; if the session is read-write, subsequent sessions
will not see \Recent set for this message. This flag can not
be altered by the client.
If it is not possible to determine whether or not this
session is the first session to be notified about a message,
then that message SHOULD be considered recent.
If multiple connections have the same mailbox selected
simultaneously, it is undefined which of these connections
will see newly-arrived messages with \Recent set and which
will see it without \Recent set.
使用'PEEK'不需要直接操作標誌。 – tripleee 2016-06-22 08:16:15
有一個在IMAP的FETCH命令.PEEK選項,將明確不設置/ Seen標記。
看the FETCH command in RFC 3501並向下滾動一下到第57頁或搜索「BODY.PEEK」。
要在Dan Goldstein's answer above跟進,在Python中使用「.PEEK」選項將調用IMAP4.fetch並通過它的語法‘BODY.PEEK’
要在python docs應用此的例子:
import getpass, imaplib
M = imaplib.IMAP4()
M.login(getpass.getuser(), getpass.getpass())
M.select()
typ, data = M.search(None, 'ALL')
for num in data[0].split():
typ, data = M.fetch(num, '(BODY.PEEK)')
print 'Message %s\n%s\n' % (num, data[0][5])
M.close()
M.logout()
當您使用BODY.PEEK時,您需要指定節。節是IMAP Fetch Command單證下BODY [<部分>] < <部分> >
import getpass, imaplib
M = imaplib.IMAP4()
M.login(getpass.getuser(), getpass.getpass())
M.select()
typ, data = M.search(None, 'ALL')
for num in data[0].split():
typ, data = M.fetch(num, '(BODY.PEEK[])')
print 'Message %s\n%s\n' % (num, data[0][5])
M.close()
M.logout()
PS解釋說:我想解決給定Gene Wood的答案,但不允許因爲編輯是小於6個字符(BODY.PEEK - > BODY。PEEK [])
如果您需要文件夾或併發訪問,POP是完全不合適的 - 當您的常規交互式客戶端已連接時,您的程序無法連接,反之亦然;或者,在最糟糕的情況下,您可以,但服務器不知道該如何處理您,並且做了一些比您想要的和預期的更多的事情。 – tripleee 2016-02-12 10:17:28