commit dbc841a41778506745eadebeb6ff759b6886cc98
parent b7c9daf12244ac464a611e778d8588c3012ea0c0
Author: Scott Bonds <scott@ggr.com>
Date: Wed, 24 Sep 2014 16:06:30 -0700
more special characters
Diffstat:
3 files changed, 21 insertions(+), 4 deletions(-)
diff --git a/lib/sup.rb b/lib/sup.rb
@@ -65,6 +65,7 @@ module Redwood
LEGACY_YAML_DOMAIN = "masanjin.net"
YAML_DATE = "2006-10-01"
MAILDIR_SYNC_CHECK_SKIPPED = 'SKIPPED'
+ URI_ENCODE_CHARS = "!*'();:@&=+$,?#[] " # see https://en.wikipedia.org/wiki/Percent-encoding
## record exceptions thrown in threads nicely
@exceptions = []
diff --git a/lib/sup/maildir.rb b/lib/sup/maildir.rb
@@ -12,7 +12,15 @@ class Maildir < Source
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
diff --git a/lib/sup/mbox.rb b/lib/sup/mbox.rb
@@ -19,16 +19,24 @@ class MBox < Source
case uri_or_fp
when String
@expanded_uri = Source.expand_filesystem_uri(uri_or_fp)
- 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 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 = nil
- @path = URI.decode uri.path
else
@f = uri_or_fp
@path = uri_or_fp.path
- @expanded_uri = "mbox://#{URI.encode @path}"
+ @expanded_uri = "mbox://#{URI.encode @path, URI_ENCODE_CHARS}"
end
super uri_or_fp, usual, archived, id