summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorlnu <lnu@f70e237a-67f3-0310-a06c-d2b8a7116972>2005-04-11 21:10:08 +0000
committerlnu <lnu@f70e237a-67f3-0310-a06c-d2b8a7116972>2005-04-11 21:10:08 +0000
commit2c7a9e22507ea4ac37d3a01812c277efd067725e (patch)
tree8ae79f1bbacfc1790a3acda79e7fc5aee7947b2a /lib
parentb4fc05daee9e8d9703316cf736100236a2c6cb93 (diff)
downloadfeed2imap-2c7a9e22507ea4ac37d3a01812c277efd067725e.tar.gz
feed2imap-2c7a9e22507ea4ac37d3a01812c277efd067725e.tar.bz2
feed2imap-2c7a9e22507ea4ac37d3a01812c277efd067725e.zip
finally fixed encoding issues
git-svn-id: svn+ssh://svn.gna.org/svn/feed2imap/trunk/feed2imap@18 f70e237a-67f3-0310-a06c-d2b8a7116972
Diffstat (limited to 'lib')
-rw-r--r--lib/feed2imap/channel.rb39
-rw-r--r--lib/feed2imap/textconverters.rb11
2 files changed, 32 insertions, 18 deletions
diff --git a/lib/feed2imap/channel.rb b/lib/feed2imap/channel.rb
index f359f82..eda01e6 100644
--- a/lib/feed2imap/channel.rb
+++ b/lib/feed2imap/channel.rb
@@ -25,6 +25,7 @@ require 'rmail'
require 'feed2imap/textconverters'
require 'feed2imap/rubymail_patch'
require 'feed2imap/rexml_patch'
+require 'base64'
class UnknownFeedTypeException < RuntimeError
end
@@ -205,6 +206,7 @@ class Item
s += "\n"
s += "\nDate: #{@date.to_s.toISO_8859_1('utf-8')}" if @date # TODO improve date rendering ?
s += "\nAuthor: #{@creator.toISO_8859_1('utf-8')}" if @creator
+
s += "\nSubject: #{@subject.toISO_8859_1('utf-8')}" if @subject
s += "\nCategory: #{@category.toISO_8859_1('utf-8')}" if @category
s += "\n\n"
@@ -217,20 +219,20 @@ class Item
s += '<html>'
s += '<body>'
s += "<p>Channel: "
- s += "<a href=\"#{@channel.link.toISO_8859_1('utf-8')}\">" if @channel.link
- s += @channel.title.toISO_8859_1('utf-8') if @channel.title
+ s += "<a href=\"#{@channel.link}\">" if @channel.link
+ s += @channel.title if @channel.title
s += "</a>" if @channel.link
s += "<br/>\nItem: "
- s += "<a href=\"#{@link.toISO_8859_1('utf-8')}\">" if @link
- s += @title.toISO_8859_1('utf-8') if @title
+ s += "<a href=\"#{@link}\">" if @link
+ s += @title if @title
s += "</a>" if @link
s += "\n"
- s += "<br/>Date: #{@date.to_s.toISO_8859_1('utf-8')}" if @date # TODO improve date rendering ?
- s += "<br/>Author: #{@creator.toISO_8859_1('utf-8')}" if @creator
- s += "<br/>Subject: #{@subject.toISO_8859_1('utf-8')}" if @subject
- s += "<br/>Category: #{@category.toISO_8859_1('utf-8')}" if @category
+ s += "<br/>Date: #{@date.to_s}" if @date # TODO improve date rendering ?
+ s += "<br/>Author: #{@creator}" if @creator
+ s += "<br/>Subject: #{@subject}" if @subject
+ s += "<br/>Category: #{@category}" if @category
s += "</p>"
- s += "<p>#{@content.toISO_8859_1('utf-8')}</p>" if @content
+ s += "<p>#{@content}</p>" if @content
s += '</body></html>'
s
end
@@ -247,20 +249,21 @@ class Item
message.header['X-Feed2Imap-Version'] = F2I_VERSION if defined?(F2I_VERSION)
message.header['X-CacheIndex'] = "-#{@cacheditem.index}-"
message.header['X-F2IStatus'] = "Updated" if @cacheditem.updated
- # TODO encode in ISO ?
- if @title
- message.header['Subject'] = @title.toISO_8859_1('utf-8')
- elsif @date
- message.header['Subject'] = @date.to_s.toISO_8859_1('utf-8')
- elsif @link
- message.header['Subject'] = @link.toISO_8859_1('utf-8')
+ # treat subject. Might need MIME encoding.
+ subj = @title or (@date and @date.to_s) or @link
+ if subj
+ if subj.needMIME
+ message.header['Subject'] = "=?utf-8?b?#{Base64::encode64(subj).chomp}?="
+ else
+ message.header['Subject'] = subj
+ end
end
textpart = RMail::Message::new
- textpart.header['Content-Type'] = 'text/plain; charset=iso-8859-1; format=flowed'
+ textpart.header['Content-Type'] = 'text/plain; charset=iso-8859-1'
textpart.header['Content-Transfer-Encoding'] = '7bit'
textpart.body = to_text
htmlpart = RMail::Message::new
- htmlpart.header['Content-Type'] = 'text/html; charset=iso-8859-1'
+ htmlpart.header['Content-Type'] = 'text/html; charset=utf-8'
htmlpart.header['Content-Transfer-Encoding'] = '7bit'
htmlpart.body = to_html
message.add_part(textpart)
diff --git a/lib/feed2imap/textconverters.rb b/lib/feed2imap/textconverters.rb
index b28c211..be63173 100644
--- a/lib/feed2imap/textconverters.rb
+++ b/lib/feed2imap/textconverters.rb
@@ -95,4 +95,15 @@ class String
return self
end
end
+
+ def needMIME
+ utf8 = false
+ self.unpack('U*').each do |c|
+ if c > 127
+ utf8 = true
+ break
+ end
+ end
+ utf8
+ end
end