lib/sup/imap.rb in sup-0.0.3 vs lib/sup/imap.rb in sup-0.0.4

- old
+ new

@@ -46,11 +46,11 @@ @imap = nil @imap_ids = {} @ids = [] @labels = [:unread] @labels << :inbox unless archived? - @labels << mailbox.intern unless mailbox =~ /inbox/i || mailbox.nil? + @labels << mailbox.intern unless mailbox =~ /inbox/i @mutex = Mutex.new end def say s @say_id = BufferManager.say s, @say_id if BufferManager.instantiated? @@ -120,11 +120,14 @@ end private :make_id def host; @parsed_uri.host; end def port; @parsed_uri.port || (ssl? ? 993 : 143); end - def mailbox; @parsed_uri.path[1..-1] || 'INBOX'; end + def mailbox + x = @parsed_uri.path[1..-1] + x.nil? || x.empty? ? 'INBOX' : x + end def ssl?; @parsed_uri.scheme == 'imaps' end def load_header id MBox::read_header StringIO.new(raw_header(id)) end @@ -147,17 +150,24 @@ get_imap_field(id, 'RFC822').gsub(/\r\n/, "\n") end end def get_imap_field id, field + retries = 0 f = nil imap_id = @imap_ids[id] or raise SourceError, "Unknown message id #{id}. It is likely that messages have been deleted from this IMAP mailbox." begin f = @imap.fetch imap_id, [field, 'RFC822.SIZE', 'INTERNALDATE'] got_id = make_id f[0] raise SourceError, "IMAP message mismatch: requested #{id}, got #{got_id}. It is likely the IMAP mailbox has been modified." unless got_id == id rescue Net::IMAP::Error => e raise SourceError, e.message + rescue Errno::EPIPE + if (retries += 1) <= 3 + @imap = nil + connect + retry + end end raise SourceError, "null IMAP field '#{field}' for message with id #{id} imap id #{imap_id}" if f.nil? f[0].attr[field] end