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 "source #{source} is done? #{source.done?} (cur_offset #{source.cur_offset} >= #{source.end_offset})"
47 yield "Loading from #{source}... " unless source.done? || source.broken?
50 add_new_messages_from source do |m, offset, entry|
51 ## always preserve the labels on disk.
52 m.labels = entry[:label].split(/\s+/).map { |x| x.intern } if entry
53 yield "Found message at #{offset} with labels #{m.labels * ', '}"
55 numi += 1 if m.labels.include? :inbox
58 yield "Found #{num} messages, #{numi} to inbox" unless num == 0
63 yield "Done polling; loaded #{total_num} new messages total"
67 [total_num, total_numi]
70 ## this is the main mechanism for adding new messages to the
71 ## index. it's called both by sup-import and by PollMode.
73 ## for each new message in the source, this yields the message, the
74 ## source offset, and the index entry on disk (if any). it expects
75 ## the yield to return the message (possibly altered in some way),
76 ## and then adds it (if new) or updates it (if previously seen).
78 ## the labels of the yielded message are the source labels. it is
79 ## likely that callers will want to replace these with the index
80 ## labels, if they exist, so that state is not lost when e.g. a new
81 ## version of a message from a mailing list comes in.
82 def add_new_messages_from source
84 return if source.done? || source.broken?
86 source.each do |offset, labels|
88 Redwood::log "error loading messages from #{source}: #{source.broken_msg}"
92 labels.each { |l| LabelManager << l }
95 m = Message.new :source => source, :source_info => offset, :labels => labels
97 Redwood::log "skipping duplicate message #{m.id}"
103 if m.source_marked_read?
104 m.remove_label :unread
105 labels.delete :unread
108 docid, entry = Index.load_entry_for_id m.id
109 m = yield m, offset, entry
112 Index.update_message m, docid, entry
115 UpdateManager.relay :add, m
117 rescue MessageFormatError, SourceError => e
118 Redwood::log "ignoring erroneous message at #{source}##{offset}: #{e.message}"