summaryrefslogtreecommitdiff
path: root/lib/feed2imap/itemtomail.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-01-10 05:24:04 -0800
committerLucas Nussbaum <lucas@lucas-nussbaum.net>2011-02-18 17:13:25 +0100
commit7579f7326ae3b8c8f441ef8b42be915cb400dc6d (patch)
treec13834a437f1be2435bb4e50cd2fc9b061ad8804 /lib/feed2imap/itemtomail.rb
parente36e42b740d9fd8b31e0d6129812501f4b787a34 (diff)
downloadfeed2imap-7579f7326ae3b8c8f441ef8b42be915cb400dc6d.tar.gz
feed2imap-7579f7326ae3b8c8f441ef8b42be915cb400dc6d.tar.bz2
feed2imap-7579f7326ae3b8c8f441ef8b42be915cb400dc6d.zip
add "parts" config option
This allows disabling either HTML or text parts to save bandwidth/disk space on the IMAP server.
Diffstat (limited to 'lib/feed2imap/itemtomail.rb')
-rw-r--r--lib/feed2imap/itemtomail.rb24
1 files changed, 15 insertions, 9 deletions
diff --git a/lib/feed2imap/itemtomail.rb b/lib/feed2imap/itemtomail.rb
index 6c70cbd..fcf8f8b 100644
--- a/lib/feed2imap/itemtomail.rb
+++ b/lib/feed2imap/itemtomail.rb
@@ -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)