From: wmorgan Date: Sun, 10 Dec 2006 19:56:57 +0000 (+0000) Subject: tweaked broken source handling X-Git-Url: https://git.notmuchmail.org/git?a=commitdiff_plain;h=45e9a7d94bb5d4285c15e6e3453ebe0bd4ad0843;p=sup tweaked broken source handling git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@74 5c8cc53c-5e98-4d25-b20a-d8db53a31250 --- diff --git a/bin/sup-import b/bin/sup-import index 6bbab93..391be89 100644 --- a/bin/sup-import +++ b/bin/sup-import @@ -117,6 +117,10 @@ found = {} 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 diff --git a/lib/sup/imap.rb b/lib/sup/imap.rb index 86dc236..148b67f 100644 --- a/lib/sup/imap.rb +++ b/lib/sup/imap.rb @@ -48,9 +48,9 @@ class IMAP < Source @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 @@ -71,8 +71,9 @@ class IMAP < Source ## 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 @@ -80,12 +81,12 @@ class IMAP < Source 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 diff --git a/lib/sup/mbox/loader.rb b/lib/sup/mbox/loader.rb index ca85b03..31e221e 100644 --- a/lib/sup/mbox/loader.rb +++ b/lib/sup/mbox/loader.rb @@ -29,8 +29,8 @@ class Loader < Source @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 diff --git a/lib/sup/source.rb b/lib/sup/source.rb index e3ea7b5..4ce1f9b 100644 --- a/lib/sup/source.rb +++ b/lib/sup/source.rb @@ -9,7 +9,7 @@ class Source ## 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: @@ -29,10 +29,10 @@ class Source @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 @@ -56,7 +56,7 @@ protected @dirty = true end - attr_writer :broken + attr_writer :broken_msg end Redwood::register_yaml(Source, %w(uri cur_offset usual archived id))