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
## 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?
docid, entry = Index.load_entry_for_id m.id
HookManager.run "before-add-message", :message => m
- m = yield(m, offset, entry) or next
- Index.sync_message m, docid, entry
+ m = yield(m, offset, entry) or next if block_given?
+ 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}"