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
44 Index.usual_sources.each do |source|
45 # yield "source #{source} is done? #{source.done?} (cur_offset #{source.cur_offset} >= #{source.end_offset})"
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 * ', '}}"
55 numi += 1 if m.labels.include? :inbox
59 yield "Found #{num} messages, #{numi} to inbox" unless num == 0
64 yield "Done polling; loaded #{total_num} new messages total"
68 [total_num, total_numi]
71 ## this is the main mechanism for adding new messages to the
72 ## index. it's called both by sup-import and by PollMode.
74 ## for each new message in the source, this yields the message, the
75 ## source offset, and the index entry on disk (if any). it expects
76 ## the yield to return the message (possibly altered in some way),
77 ## and then adds it (if new) or updates it (if previously seen).
79 ## the labels of the yielded message are the source labels. it is
80 ## likely that callers will want to replace these with the index
81 ## labels, if they exist, so that state is not lost when e.g. a new
82 ## version of a message from a mailing list comes in.
83 def add_new_messages_from source
84 return if source.done? || source.broken?
87 source.each do |offset, labels|
89 Redwood::log "error loading messages from #{source}: #{source.broken_msg}"
93 labels.each { |l| LabelManager << l }
96 m = Message.new :source => source, :source_info => offset, :labels => labels
97 if m.source_marked_read?
98 m.remove_label :unread
102 docid, entry = Index.load_entry_for_id m.id
103 m = yield m, offset, entry
106 Index.update_message m, docid, entry
109 UpdateManager.relay self, :add, m
111 rescue MessageFormatError, SourceError => e
112 Redwood::log "ignoring erroneous message at #{source}##{offset}: #{e.message}"
115 rescue SourceError => e
116 Redwood::log "problem getting messages from #{source}: #{e.message}"