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
@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
::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}"
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
-require 'thread'
require 'rmail'
module Redwood
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