14 self.class.i_am_the_instance self
18 BufferManager.spawn_unless_exists("<poll for new messages>", :hidden => true) { PollMode.new }
22 BufferManager.flash "Polling for new messages..."
23 num, numi = buffer.mode.poll
25 BufferManager.flash "Loaded #{num} new messages, #{numi} to inbox."
27 BufferManager.flash "No new messages."
33 Redwood::reporting_thread do
36 poll if @last_poll.nil? || (Time.now - @last_poll) >= DELAY
42 total_num = total_numi = 0
45 Index.usual_sources.each do |source|
46 yield "Loading from #{source}... " unless source.done? || source.broken?
49 add_new_messages_from source do |m, offset, entry|
50 ## always preserve the labels on disk.
51 m.labels = entry[:label].split(/\s+/).map { |x| x.intern } if entry
52 yield "Found message at #{offset} with labels #{m.labels * ', '}"
54 numi += 1 if m.labels.include? :inbox
57 yield "Found #{num} messages, #{numi} to inbox" unless num == 0
62 yield "Done polling; loaded #{total_num} new messages total"
66 [total_num, total_numi]
69 ## this is the main mechanism for adding new messages to the
70 ## index. it's called both by sup-import and by PollMode.
72 ## for each new message in the source, this yields the message, the
73 ## source offset, and the index entry on disk (if any). it expects
74 ## the yield to return the message (possibly altered in some way),
75 ## and then adds it (if new) or updates it (if previously seen).
77 ## the labels of the yielded message are the source labels. it is
78 ## likely that callers will want to replace these with the index
79 ## labels, if they exist, so that state is not lost when e.g. a new
80 ## version of a message from a mailing list comes in.
81 def add_new_messages_from source
83 return if source.done? || source.broken?
85 source.each do |offset, labels|
87 Redwood::log "error loading messages from #{source}: #{source.broken_msg}"
91 labels.each { |l| LabelManager << l }
94 m = Message.new :source => source, :source_info => offset, :labels => labels
96 Redwood::log "skipping duplicate message #{m.id}"
102 if m.source_marked_read?
103 m.remove_label :unread
104 labels.delete :unread
107 docid, entry = Index.load_entry_for_id m.id
108 m = yield m, offset, entry
111 update_message m, docid, entry
114 UpdateManager.relay :add, m
116 rescue MessageFormatError, SourceError => e
117 Redwood::log "ignoring erroneous message at #{source}##{offset}: #{e.message}"