From 7de154f86754059317f800a82ef22d9aa00a1140 Mon Sep 17 00:00:00 2001 From: Lucas Nussbaum Date: Wed, 1 Dec 2010 13:56:33 +0100 Subject: Encode the folder in UTF7 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch from René 'Necoro' Neumann , 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. --- lib/feed2imap/config.rb | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'lib') 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 -- cgit v1.2.3