summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas Nussbaum <lucas@lucas-nussbaum.net>2010-12-01 13:56:33 +0100
committerLucas Nussbaum <lucas@lucas-nussbaum.net>2010-12-01 13:56:33 +0100
commit7de154f86754059317f800a82ef22d9aa00a1140 (patch)
tree7855c3c72153a1db0f07014319f660ef2d3f90ee
parent71acc1e9cee028c8357bebbe2d5ec51a01249aa5 (diff)
downloadfeed2imap-7de154f86754059317f800a82ef22d9aa00a1140.tar.gz
feed2imap-7de154f86754059317f800a82ef22d9aa00a1140.tar.bz2
feed2imap-7de154f86754059317f800a82ef22d9aa00a1140.zip
Encode the folder in UTF7
Patch from René 'Necoro' Neumann <lists@necoro.eu>, who writes: > I wanted to wrap the folder name in a call to > "Net::IMAP::encode_utf7" > to allow special characters like umlauts in the folder name (see the > attached patch). > > Problem is, that the encode_utf7 (and the decode_utf7 FWIW) uses the > 'String::force_encoding' method, which some googling shows to be in > Ruby1.9 but not 1.8.
Diffstat (limited to '')
-rw-r--r--lib/feed2imap/config.rb18
1 files changed, 17 insertions, 1 deletions
diff --git a/lib/feed2imap/config.rb b/lib/feed2imap/config.rb
index 5e339c7..6c3654b 100644
--- a/lib/feed2imap/config.rb
+++ b/lib/feed2imap/config.rb
@@ -109,7 +109,8 @@ class ConfigFeed
@name = f['name']
@url = f['url']
@url.sub!(/^feed:/, '') if @url =~ /^feed:/
- @imapaccount, @folder = imapaccount, folder
+ @imapaccount = imapaccount
+ @folder = encode_utf7 folder
@freq = f['min-frequency']
@always_new = false
@@ -136,4 +137,19 @@ class ConfigFeed
return true if @freq.nil?
return (lastcheck + @freq * 3600) < Time::now
end
+
+ def encode_utf7(s)
+ if "foo".respond_to?(:force_encoding)
+ return Net::IMAP::encode_utf7 s
+ else
+ # this is a copy of the Net::IMAP::encode_utf7 w/o the force_encoding
+ return s.gsub(/(&)|([^\x20-\x7e]+)/u) {
+ if $1
+ "&-"
+ else
+ base64 = [$&.unpack("U*").pack("n*")].pack("m")
+ "&" + base64.delete("=\n").tr("/", ",") + "-"
+ end }
+ end
+ end
end