lib/sup/maildir.rb in sup-0.19.0 vs lib/sup/maildir.rb in sup-0.20.0
- old
+ new
@@ -10,21 +10,29 @@
## remind me never to use inheritance again.
yaml_properties :uri, :usual, :archived, :sync_back, :id, :labels
def initialize uri, usual=true, archived=false, sync_back=true, id=nil, labels=[]
super uri, usual, archived, id
@expanded_uri = Source.expand_filesystem_uri(uri)
- uri = URI(@expanded_uri)
+ parts = @expanded_uri.match /^([a-zA-Z0-9]*:(\/\/)?)(.*)/
+ if parts
+ prefix = parts[1]
+ @path = parts[3]
+ uri = URI(prefix + URI.encode(@path, URI_ENCODE_CHARS))
+ else
+ uri = URI(URI.encode @expanded_uri, URI_ENCODE_CHARS)
+ @path = uri.path
+ end
raise ArgumentError, "not a maildir URI" unless uri.scheme == "maildir"
raise ArgumentError, "maildir URI cannot have a host: #{uri.host}" if uri.host
raise ArgumentError, "maildir URI must have a path component" unless uri.path
@sync_back = sync_back
# sync by default if not specified
@sync_back = true if @sync_back.nil?
- @dir = uri.path
+ @dir = URI.decode uri.path
@labels = Set.new(labels || [])
@mutex = Mutex.new
@ctimes = { 'cur' => Time.at(0), 'new' => Time.at(0) }
end
@@ -118,10 +126,13 @@
ctime = File.ctime subdir
next if prev_ctime >= ctime
@ctimes[d] = ctime
old_ids = benchmark(:maildir_read_index) { Index.instance.enum_for(:each_source_info, self.id, "#{d}/").to_a }
- new_ids = benchmark(:maildir_read_dir) { Dir.glob("#{subdir}/*").map { |x| File.join(d,File.basename(x)) }.sort }
+ new_ids = benchmark(:maildir_read_dir) {
+ Dir.open(subdir).select {
+ |f| !File.directory? f}.map {
+ |x| File.join(d,File.basename(x)) }.sort }
added += new_ids - old_ids
deleted += old_ids - new_ids
debug "#{old_ids.size} in index, #{new_ids.size} in filesystem"
end