Ruby와 Rails를 사용하는 IMAP 클라이언트에서 작업하고 있습니다. 메시지, 편지함 등을 성공적으로 가져올 수 있습니다. 그러나 처음 가져온 후에 마지막 동기화 이후 변경된 사항을 어떻게 검색 할 수 있습니까?Ruby IMAP이 마지막 체크 이후 "변경"되었습니다.
현재 데이터베이스에 UID 및 UID 유효성 값을 저장하고이를 비교하고 적절하게 검색하고 있습니다. 이 작동하지만 삭제 된 메시지 또는 메시지 플래그 변경 등을 감지하지 못합니다.
이러한 변경 사항을 감지 할 때마다 매번 메시지를 가져와야합니까? 다른 IMAP 클라이언트가 어떻게 그렇게 빠르게 할 수 있습니까 (예 : Apple Mail 및 Postbox). 내 스크립트는 이미 거의 이메일 주소로 계정 당 10 + 초를 취하고있다 :
# select ourself as the current mailbox
@imap_connection.examine(self.location)
# grab all new messages and update them in the database
# if the uid's are still valid, we will just fetch the newest UIDs
# otherwise, we need to search when we last synced, which is slower :(
if self.uid_validity.nil? || uid_validity == self.uid_validity
# for some IMAP servers, if a mailbox is empty, a uid_fetch will fail, so then
begin
messages = @imap_connection.uid_fetch(uid_range, ['UID', 'RFC822', 'FLAGS'])
rescue
# gmail cries if the folder is empty
uids = @imap_connection.uid_search(['ALL'])
messages = @imap_connection.uid_fetch(uids, ['UID', 'RFC822', 'FLAGS']) unless uids.empty?
end
messages.each do |imap_message|
Message.create_from_imap!(imap_message, self.id)
end unless messages.nil?
else
query = self.last_synced.nil? ? ['All'] : ['SINCE', Net::IMAP.format_datetime(self.last_synced)]
@imap_connection.search(query).each do |message_id|
imap_message = @imap_connection.fetch(message_id, ['RFC822', 'FLAGS', 'UID'])[0]
# don't mark the messages as read
#@imap_connection.store(message_id, '-FLAGS', [:Seen])
Message.create_from_imap!(imap_message, self.id)
end
end
# now assume all UIDs are valid
self.uid_validity = uid_validity
# now remember that we just fetched all those messages
self.last_synced = Time.now
self.save!
가능한가요? 관련이 있지만 속지는 아닙니다. http://stackoverflow.com/questions/1084780/getting-only-new-mail-from-an-imap-server –
이미 새 메시지를 가져 오는 방법을 알고 있습니다. 삭제되거나 "변경된"메시지를 가져 오는 방법이 필요합니다 ... – sethvargo
메시지가 휴지통 폴더에서 제거되면 (즉, 수동 또는 30 일 후) 삭제됩니다. 다른 클라이언트에 관해서는, 나는 FETCH 1 : * [UID]를 매우 빠르게 수행하고있는 것으로 추측하고 그 세트를 비교합니다. – Roman