]> git.cworth.org Git - sup/blobdiff - lib/sup/poll.rb
bugfix: poll.rb assuming all messages have froms
[sup] / lib / sup / poll.rb
index d32c893e76771873832595ec95c67fac0780a208..5027218c49d66318b309a062c1d222d81699d3a1 100644 (file)
@@ -97,13 +97,13 @@ EOS
         numi = 0
         add_messages_from source do |m, offset, entry|
           ## always preserve the labels on disk.
-          m.labels = entry[:label].split(/\s+/).map { |x| x.intern } if entry
+          m.labels = ((m.labels - [:unread, :inbox]) + entry[:label].split(/\s+/).map { |x| x.intern }).uniq if entry
           yield "Found message at #{offset} with labels {#{m.labels * ', '}}"
           unless entry
             num += 1
-            from_and_subj << [m.from.longname, m.subj]
+            from_and_subj << [m.from && m.from.longname, m.subj]
             if m.has_label?(:inbox) && ([:spam, :deleted, :killed] & m.labels).empty?
-              from_and_subj_inbox << [m.from.longname, m.subj]
+              from_and_subj_inbox << [m.from && m.from.longname, m.subj]
               numi += 1 
             end
           end
@@ -134,7 +134,7 @@ EOS
   ## labels. it is likely that callers will want to replace these with
   ## the index labels, if they exist, so that state is not lost when
   ## e.g. a new version of a message from a mailing list comes in.
-  def add_messages_from source
+  def add_messages_from source, opts={}
     begin
       return if source.done? || source.has_errors?
       
@@ -157,7 +157,7 @@ EOS
           docid, entry = Index.load_entry_for_id m.id
           HookManager.run "before-add-message", :message => m
           m = yield(m, offset, entry) or next if block_given?
-          Index.sync_message m, docid, entry
+          Index.sync_message m, docid, entry, opts
           UpdateManager.relay self, :added, m unless entry
         rescue MessageFormatError => e
           Redwood::log "ignoring erroneous message at #{source}##{offset}: #{e.message}"