lib/sup/mbox/loader.rb in sup-0.9.1 vs lib/sup/mbox/loader.rb in sup-0.10
- old
+ new
@@ -10,27 +10,28 @@
yaml_properties :uri, :cur_offset, :usual, :archived, :id, :labels
attr_reader :labels
## uri_or_fp is horrific. need to refactor.
- def initialize uri_or_fp, start_offset=0, usual=true, archived=false, id=nil, labels=nil
+ def initialize uri_or_fp, start_offset=nil, usual=true, archived=false, id=nil, labels=nil
@mutex = Mutex.new
@labels = Set.new((labels || []) - LabelManager::RESERVED_LABELS)
case uri_or_fp
when String
uri = URI(Source.expand_filesystem_uri(uri_or_fp))
raise ArgumentError, "not an mbox uri" unless uri.scheme == "mbox"
raise ArgumentError, "mbox URI ('#{uri}') cannot have a host: #{uri.host}" if uri.host
raise ArgumentError, "mbox URI must have a path component" unless uri.path
- @f = File.open uri.path
+ @f = File.open uri.path, 'rb'
@path = uri.path
else
@f = uri_or_fp
@path = uri_or_fp.path
end
+ start_offset ||= 0
super uri_or_fp, start_offset, usual, archived, id
end
def file_path; @path end
def is_source_for? uri; super || (self.uri.is_a?(String) && (URI(Source.expand_filesystem_uri(uri)) == URI(Source.expand_filesystem_uri(self.uri)))) end
@@ -112,10 +113,10 @@
ret
end
def store_message date, from_email, &block
need_blank = File.exists?(@filename) && !File.zero?(@filename)
- File.open(@filename, "a") do |f|
+ File.open(@filename, "ab") do |f|
f.puts if need_blank
f.puts "From #{from_email} #{date.rfc2822}"
yield f
end
end