3 class SourceError < StandardError; end
6 ## dirty? described whether cur_offset has changed, which means the
7 ## source needs to be re-saved to disk.
9 ## broken? means no message can be loaded, e.g. IMAP server is
10 ## down, mbox file is corrupt and needs to be rescanned.
12 ## When writing a new source, you should implement:
16 ## load_header(offset)
17 ## load_message(offset)
19 ## raw_full_message(offset)
20 ## next (or each, if you prefer)
22 ## you can throw SourceErrors from any of those, but we don't catch
23 ## anything else, so make sure you catch all non-fatal errors and
24 ## reraise them as source errors.
26 bool_reader :usual, :archived, :dirty
27 attr_reader :cur_offset, :broken_msg
30 def initialize uri, initial_offset=nil, usual=true, archived=false, id=nil
32 @cur_offset = initial_offset
40 def broken?; !@broken_msg.nil?; end
42 def seek_to! o; self.cur_offset = o; end
50 def == o; o.to_s == to_s; end
52 return true if broken?
54 (self.cur_offset ||= start_offset) >= end_offset
55 rescue SourceError => e
59 def is_source_for? s; to_s == s; end
63 self.cur_offset ||= start_offset
64 until done? || broken? # just like life!
66 raise "no message" unless n
83 Redwood::log "#{to_s}: #{m}"
87 Redwood::register_yaml(Source, %w(uri cur_offset usual archived id))