Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

add "parts" config option

This allows disabling either HTML or text parts to save bandwidth/disk
space on the IMAP server.
  • Loading branch information...
commit 7579f7326ae3b8c8f441ef8b42be915cb400dc6d 1 parent e36e42b
Eric Wong authored lnussbaum committed
8 lib/feed2imap/config.rb
View
@@ -23,6 +23,7 @@
require 'feed2imap/maildir'
require 'etc'
require 'socket'
+require 'set'
# Default cache file
DEFCACHE = ENV['HOME'] + '/.feed2imap.cache'
@@ -33,7 +34,7 @@
# Feed2imap configuration
class F2IConfig
- attr_reader :imap_accounts, :cache, :feeds, :dumpdir, :updateddebug, :max_failures, :include_images, :default_email, :hostname, :reupload_if_updated
+ attr_reader :imap_accounts, :cache, :feeds, :dumpdir, :updateddebug, :max_failures, :include_images, :default_email, :hostname, :reupload_if_updated, :parts
# Load the configuration from the IO stream
# TODO should do some sanity check on the data read.
@@ -48,8 +49,13 @@ def initialize(io)
@updateddebug = false
@updateddebug = @conf['debug-updated'] if @conf.has_key?('debug-updated')
+ @parts = %w(text html)
+ @parts = Array(@conf['parts']) if @conf.has_key?('parts') && !@conf['parts'].empty?
+ @parts = Set.new(@parts)
+
@include_images = true
@include_images = @conf['include-images'] if @conf.has_key?('include-images')
+ @parts << 'html' if @include_images && ! @parts.include?('html')
@reupload_if_updated = true
@reupload_if_updated = @conf['reupload-if-updated'] if @conf.has_key?('reupload-if-updated')
24 lib/feed2imap/itemtomail.rb
View
@@ -77,14 +77,20 @@ def item_to_mail(config, item, id, updated, from = 'Feed2Imap', inline_images =
message.header['Subject'] = subj
end
end
- textpart = RMail::Message::new
- textpart.header['Content-Type'] = 'text/plain; charset=utf-8; format=flowed'
- textpart.header['Content-Transfer-Encoding'] = '8bit'
- textpart.body = item.to_text(true, wrapto, false)
- htmlpart = RMail::Message::new
- htmlpart.header['Content-Type'] = 'text/html; charset=utf-8'
- htmlpart.header['Content-Transfer-Encoding'] = '8bit'
- htmlpart.body = item.to_html
+ textpart = htmlpart = nil
+ parts = config.parts
+ if parts.include?('text')
+ textpart = parts.size == 1 ? message : RMail::Message::new
+ textpart.header['Content-Type'] = 'text/plain; charset=utf-8; format=flowed'
+ textpart.header['Content-Transfer-Encoding'] = '8bit'
+ textpart.body = item.to_text(true, wrapto, false)
+ end
+ if parts.include?('html')
+ htmlpart = parts.size == 1 ? message : RMail::Message::new
+ htmlpart.header['Content-Type'] = 'text/html; charset=utf-8'
+ htmlpart.header['Content-Transfer-Encoding'] = '8bit'
+ htmlpart.body = item.to_html
+ end
# inline images as attachments
imgs = []
@@ -127,7 +133,7 @@ def item_to_mail(config, item, id, updated, from = 'Feed2Imap', inline_images =
imgs.each do |i|
message.add_part(i)
end
- else
+ elsif parts.size != 1
message.header['Content-Type'] = 'multipart/alternative'
message.add_part(textpart)
message.add_part(htmlpart)
18 test/tc_config.rb
View
@@ -34,6 +34,17 @@
url: http://something2
target: imaps://login:pasword@ezaezae/Feeds/B
EOF
+CONFPARTS = <<EOF
+parts: text
+include-images: false
+feeds:
+ - name: feed1
+ url: http://something
+ target: imap://login:pasword@ezaezae/Feeds/A
+ - name: feed2
+ url: http://something2
+ target: imap://login:pasword@ezaezae/Feeds/B
+EOF
class ConfigTest < Test::Unit::TestCase
def test_cache
@@ -61,4 +72,11 @@ def test_feedurls
assert_equal('http://something', conf.feeds[0].url)
assert_equal('http://something2', conf.feeds[1].url)
end
+
+ def test_parts
+ sio = StringIO::new CONFPARTS
+ conf = F2IConfig::new(sio)
+ assert conf.parts.include?('text')
+ assert ! conf.parts.include?('html')
+ end
end
Please sign in to comment.
Something went wrong with that request. Please try again.