commit 612ab3c4819ad549bbd738770763186cdfb62caf
parent dd736147ca5dd657c40041c237e89eb41bbace87
Author: wmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Date: Sun, 10 Dec 2006 19:48:42 +0000
finishing touches on broken source handling
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@72 5c8cc53c-5e98-4d25-b20a-d8db53a31250
Diffstat:
4 files changed, 15 insertions(+), 12 deletions(-)
diff --git a/lib/sup/imap.rb b/lib/sup/imap.rb
@@ -5,7 +5,7 @@ require 'stringio'
module Redwood
class IMAP < Source
- attr_reader :labels, :broken_msg
+ attr_reader :labels
def initialize uri, username, password, last_uid=nil, usual=true, archived=false, id=nil
raise ArgumentError, "username and password must be specified" unless username && password
@@ -48,10 +48,9 @@ class IMAP < Source
@imap.examine mailbox
Redwood::log "successfully connected to #{@parsed_uri}, mailbox #{mailbox}"
rescue Exception => e
- self.broken = true
+ self.broken = e.message.chomp # fucking chomp! fuck!!!
@imap = nil
- @broken_msg = e.message.chomp # fucking chomp! fuck!!!
- Redwood::log "error connecting to IMAP server: #{@broken_msg}"
+ Redwood::log "error connecting to IMAP server: #{self.broken}"
end
end.join
@@ -73,7 +72,7 @@ class IMAP < Source
## load the full header text
def raw_header uid
begin
- connect or return broken_msg
+ connect or return broken
rescue Exception => e
raise "wtf: #{e.inspect}"
end
@@ -81,12 +80,12 @@ class IMAP < Source
end
def raw_full_message uid
- connect or return broken_msg
+ connect or return broken
@imap.uid_fetch(uid, 'RFC822')[0].attr['RFC822'].gsub(/\r\n/, "\n")
end
def each
- connect or return broken_msg
+ connect or return broken
uids = @imap.uid_search ['UID', "#{cur_offset}:#{end_offset}"]
uids.each do |uid|
@last_uid = uid
diff --git a/lib/sup/index.rb b/lib/sup/index.rb
@@ -220,7 +220,7 @@ An error occurred while loading this message. It is possible that the source
has changed, or (in the case of remote sources) is down.
The error message was:
- #{source.broken_msg}
+ #{source.broken}
EOS
end
m
diff --git a/lib/sup/mbox/loader.rb b/lib/sup/mbox/loader.rb
@@ -28,7 +28,10 @@ class Loader < Source
@mutex.synchronize do
@f.seek offset
l = @f.gets
- raise SourceError, "offset mismatch in mbox file offset #{offset.inspect}: #{l.inspect}. Run 'sup-import --rebuild #{to_s}' to correct this." unless l =~ BREAK_RE
+ 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
+ end
header = MBox::read_header @f
end
header
diff --git a/lib/sup/source.rb b/lib/sup/source.rb
@@ -8,8 +8,8 @@ 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, :broken
- attr_reader :cur_offset
+ bool_reader :usual, :archived, :dirty
+ attr_reader :cur_offset, :broken
attr_accessor :id
## You should implement:
@@ -29,9 +29,10 @@ class Source
@archived = archived
@id = id
@dirty = false
- @broken = false
+ @broken = nil
end
+ def broken?; !@broken.nil?; end
def to_s; @uri; end
def seek_to! o; self.cur_offset = o; end
def reset!; seek_to! start_offset; end