From 2c7a9e22507ea4ac37d3a01812c277efd067725e Mon Sep 17 00:00:00 2001 From: lnu Date: Mon, 11 Apr 2005 21:10:08 +0000 Subject: finally fixed encoding issues git-svn-id: svn+ssh://svn.gna.org/svn/feed2imap/trunk/feed2imap@18 f70e237a-67f3-0310-a06c-d2b8a7116972 --- lib/feed2imap/channel.rb | 39 +++++++++++++++++++++------------------ lib/feed2imap/textconverters.rb | 11 +++++++++++ 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 += '' s += '' s += "

Channel: " - s += "" if @channel.link - s += @channel.title.toISO_8859_1('utf-8') if @channel.title + s += "" if @channel.link + s += @channel.title if @channel.title s += "" if @channel.link s += "
\nItem: " - s += "" if @link - s += @title.toISO_8859_1('utf-8') if @title + s += "" if @link + s += @title if @title s += "" if @link s += "\n" - s += "
Date: #{@date.to_s.toISO_8859_1('utf-8')}" if @date # TODO improve date rendering ? - s += "
Author: #{@creator.toISO_8859_1('utf-8')}" if @creator - s += "
Subject: #{@subject.toISO_8859_1('utf-8')}" if @subject - s += "
Category: #{@category.toISO_8859_1('utf-8')}" if @category + s += "
Date: #{@date.to_s}" if @date # TODO improve date rendering ? + s += "
Author: #{@creator}" if @creator + s += "
Subject: #{@subject}" if @subject + s += "
Category: #{@category}" if @category s += "

" - s += "

#{@content.toISO_8859_1('utf-8')}

" if @content + s += "

#{@content}

" if @content s += '' 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 -- cgit v1.2.3-54-g00ecf /commit/portato/eix/parser.py?h=0.14&id=d041a06226aec18308b846bd90ef99a744367f3e&follow=1'>Add package and category objectsRené 'Necoro' Neumann1-3/+29