commit 23d5ced228b2c82d174efa09353fd1d18cee52bf
parent fcd9314bef3d60aad039d83f2d716c5d14dd448a
Author: wmorgan <wmorgan@5c8cc53c-5e98-4d25-b20a-d8db53a31250>
Date: Tue, 26 Dec 2006 17:49:11 +0000
moved responsibility for labels out of source and back into subclasses.
minor tweaks on imap to be a little prettier.
allowed mbox::loader to take iether a filename or an IO object; the latter
will be used for mbox+ssh support
git-svn-id: svn://rubyforge.org/var/svn/sup/trunk@99 5c8cc53c-5e98-4d25-b20a-d8db53a31250
Diffstat:
3 files changed, 19 insertions(+), 11 deletions(-)
diff --git a/lib/sup/imap.rb b/lib/sup/imap.rb
@@ -9,6 +9,7 @@ class IMAP < Source
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
+ raise ArgumentError, "not an imap uri" unless uri =~ %r!imaps?://!
super uri, last_uid, usual, archived, id
@@ -17,8 +18,8 @@ class IMAP < Source
@password = password
@imap = nil
@labels = [:unread]
- @labels << mailbox.intern unless mailbox =~ /inbox/i || mailbox.nil?
@labels << :inbox unless archived?
+ @labels << mailbox.intern unless mailbox =~ /inbox/i || mailbox.nil?
connect
end
@@ -43,7 +44,7 @@ class IMAP < Source
::Thread.new do
begin
#raise Net::IMAP::ByeResponseError, "simulated imap failure"
- @imap = Net::IMAP.new @parsed_uri.host, ssl? ? 993 : 143, ssl?
+ @imap = Net::IMAP.new host, ssl? ? 993 : 143, ssl?
@imap.authenticate 'LOGIN', @username, @password
@imap.examine mailbox
Redwood::log "successfully connected to #{@parsed_uri}, mailbox #{mailbox}"
@@ -58,6 +59,7 @@ class IMAP < Source
end
private :connect
+ def host; @parsed_uri.host; end
def mailbox; @parsed_uri.path[1..-1] end ##XXXX TODO handle nil
def ssl?; @parsed_uri.scheme == 'imaps' end
diff --git a/lib/sup/mbox/loader.rb b/lib/sup/mbox/loader.rb
@@ -1,4 +1,3 @@
-require 'thread'
require 'rmail'
module Redwood
@@ -7,17 +6,25 @@ module MBox
class Loader < Source
attr_reader :labels
- def initialize uri, start_offset=nil, usual=true, archived=false, id=nil
- raise ArgumentError, "not an mbox uri" unless uri =~ %r!mbox://!
+ def initialize uri_or_fp, start_offset=nil, usual=true, archived=false, id=nil
super
@mutex = Mutex.new
- @filename = uri.sub(%r!^mbox://!, "")
- @f = File.open @filename
- ## heuristic: use the filename as a label, unless the file
- ## has a path that probably represents an inbox.
@labels = [:unread]
- @labels << File.basename(@filename).intern unless File.dirname(@filename) =~ /\b(var|usr|spool)\b/
+ @labels << :inbox unless archived?
+
+ case uri_or_fp
+ when String
+ raise ArgumentError, "not an mbox uri" unless uri_or_fp =~ %r!mbox://!
+
+ fn = uri_or_fp.sub(%r!^mbox://!, "")
+ ## heuristic: use the filename as a label, unless the file
+ ## has a path that probably represents an inbox.
+ @labels << File.basename(fn).intern unless File.dirname(fn) =~ /\b(var|usr|spool)\b/
+ @f = File.open fn
+ else
+ @f = uri_or_fp
+ end
end
def start_offset; 0; end
diff --git a/lib/sup/source.rb b/lib/sup/source.rb
@@ -44,7 +44,6 @@ class Source
until done?
n, labels = self.next
raise "no message" unless n
- labels += [:inbox] unless archived?
yield n, labels
end
end