diff options
author | Lucas Nussbaum <lucas@lucas-nussbaum.net> | 2009-05-06 14:55:35 +0200 |
---|---|---|
committer | Lucas Nussbaum <lucas@lucas-nussbaum.net> | 2009-05-06 14:55:35 +0200 |
commit | 8d4be556a2d49d28506665a820ed6bc166dbdc0d (patch) | |
tree | be6fff9edc047ff5ec7b60af765d75adc7a4faca /lib/feed2imap/itemtomail.rb | |
parent | c56f9bb6f52d4bad360b5ce93e93b9a6ceb39c94 (diff) | |
download | feed2imap-8d4be556a2d49d28506665a820ed6bc166dbdc0d.tar.gz feed2imap-8d4be556a2d49d28506665a820ed6bc166dbdc0d.tar.bz2 feed2imap-8d4be556a2d49d28506665a820ed6bc166dbdc0d.zip |
use multipart/related only if there are images
... and only use multipart/alternative in the other case.
Diffstat (limited to '')
-rw-r--r-- | lib/feed2imap/itemtomail.rb | 21 |
1 files changed, 13 insertions, 8 deletions
diff --git a/lib/feed2imap/itemtomail.rb b/lib/feed2imap/itemtomail.rb index ffa6b22..0f97ac0 100644 --- a/lib/feed2imap/itemtomail.rb +++ b/lib/feed2imap/itemtomail.rb @@ -87,14 +87,8 @@ def item_to_mail(item, id, updated, from = 'Feed2Imap', inline_images = false, w htmlpart.body = item.to_html # inline images as attachments + imgs = [] if inline_images - message.header.set('Content-Type', 'multipart/related', 'type'=> 'multipart/alternative') - texthtml = RMail::Message::new - texthtml.header.set('Content-Type', 'multipart/alternative') - texthtml.add_part(textpart) - texthtml.add_part(htmlpart) - message.add_part(texthtml) - cids = [] htmlpart.body.gsub!(/(<img[^>]+)src="(\S+?\/([^\/]+?\.(png|gif|jpe?g)))"([^>]*>)/i) do |match| # $2 contains url, $3 the image name, $4 the image extension @@ -111,7 +105,7 @@ def item_to_mail(item, id, updated, from = 'Feed2Imap', inline_images = false, w imgpart.header.set('Content-Disposition', 'attachment', 'filename' => $3) imgpart.header.set('Content-Transfer-Encoding', 'base64') imgpart.body = image - message.add_part(imgpart) + imgs << imgpart end # now to specify what to replace with newtag = "#{$1}src=\"cid:#{cid}\"#{$5}" @@ -122,6 +116,17 @@ def item_to_mail(item, id, updated, from = 'Feed2Imap', inline_images = false, w $& # don't modify on exception end end + end + if imgs.length > 0 + message.header.set('Content-Type', 'multipart/related', 'type'=> 'multipart/alternative') + texthtml = RMail::Message::new + texthtml.header.set('Content-Type', 'multipart/alternative') + texthtml.add_part(textpart) + texthtml.add_part(htmlpart) + message.add_part(texthtml) + imgs.each do |i| + message.add_part(i) + end else message.header['Content-Type'] = 'multipart/alternative' message.add_part(textpart) |