start = Time.now
begin
sources.each do |source|
+ if source.broken?
+ puts "error loading messages from #{source}: #{source.broken_msg}"
+ next
+ end
next if source.done?
puts "loading from #{source}... "
num = 0
@imap.examine mailbox
Redwood::log "successfully connected to #{@parsed_uri}, mailbox #{mailbox}"
rescue Exception => e
- self.broken = e.message.chomp # fucking chomp! fuck!!!
+ self.broken_msg = e.message.chomp # fucking chomp! fuck!!!
@imap = nil
- Redwood::log "error connecting to IMAP server: #{self.broken}"
+ Redwood::log "error connecting to IMAP server: #{self.broken_msg}"
end
end.join
## load the full header text
def raw_header uid
+ connect or return broken_msg
begin
- connect or return broken
+ connect or return broken_msg
rescue Exception => e
raise "wtf: #{e.inspect}"
end
end
def raw_full_message uid
- connect or return broken
+ connect or return broken_msg
@imap.uid_fetch(uid, 'RFC822')[0].attr['RFC822'].gsub(/\r\n/, "\n")
end
def each
- connect or return broken
+ connect or return broken_msg
uids = @imap.uid_search ['UID', "#{cur_offset}:#{end_offset}"]
uids.each do |uid|
@last_uid = uid
@f.seek offset
l = @f.gets
unless l =~ BREAK_RE
- self.broken = "offset mismatch in mbox file offset #{offset.inspect}: #{l.inspect}. Run 'sup-import --rebuild #{to_s}' to correct this."
- raise SourceError, self.broken
+ self.broken_msg = "offset mismatch in mbox file offset #{offset.inspect}: #{l.inspect}. Run 'sup-import --rebuild #{to_s}' to correct this."
+ raise SourceError, self.broken_msg
end
header = MBox::read_header @f
end
## broken? means no message can be loaded (e.g. IMAP server is
## down), so don't even bother.
bool_reader :usual, :archived, :dirty
- attr_reader :cur_offset, :broken
+ attr_reader :cur_offset, :broken_msg
attr_accessor :id
## You should implement:
@archived = archived
@id = id
@dirty = false
- @broken = nil
+ @broken_msg = nil
end
- def broken?; !@broken.nil?; end
+ def broken?; !@broken_msg.nil?; end
def to_s; @uri; end
def seek_to! o; self.cur_offset = o; end
def reset!; seek_to! start_offset; end
@dirty = true
end
- attr_writer :broken
+ attr_writer :broken_msg
end
Redwood::register_yaml(Source, %w(uri cur_offset usual archived id))