summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLucas Nussbaum <lucas@lucas-nussbaum.net>2008-06-17 10:46:57 +0200
committerLucas Nussbaum <lucas@lucas-nussbaum.net>2008-06-17 10:46:57 +0200
commit6bbd505f5e08635a23d3abbf4371e679d4f21c51 (patch)
tree49718004381d67854fce928c9640d4f3997ae4f8 /lib
parent37c4df0efb4528d67db42b9c49979f88e3585822 (diff)
downloadfeed2imap-6bbd505f5e08635a23d3abbf4371e679d4f21c51.tar.gz
feed2imap-6bbd505f5e08635a23d3abbf4371e679d4f21c51.tar.bz2
feed2imap-6bbd505f5e08635a23d3abbf4371e679d4f21c51.zip
generate correct messages with images
Diffstat (limited to '')
-rw-r--r--lib/feed2imap/itemtomail.rb25
1 files changed, 18 insertions, 7 deletions
diff --git a/lib/feed2imap/itemtomail.rb b/lib/feed2imap/itemtomail.rb
index 0bd7420..06efbeb 100644
--- a/lib/feed2imap/itemtomail.rb
+++ b/lib/feed2imap/itemtomail.rb
@@ -47,7 +47,7 @@ class String
end
end
-def item_to_mail(item, index, updated, from = 'Feed2Imap', include_images = false)
+def item_to_mail(item, index, updated, from = 'Feed2Imap', inline_images = false)
message = RMail::Message::new
if item.creator and item.creator != ''
if item.creator.include?('@')
@@ -87,15 +87,25 @@ def item_to_mail(item, index, updated, from = 'Feed2Imap', include_images = fals
# inline images as attachments
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)
+
htmlpart.body.gsub!(/(<img[^>]+)src="(\S+?\/([^\/]+?\.(png|gif|jpe?g)))"([^>]*>)/i) do |match|
# $2 contains url, $3 the image name, $4 the image extension
begin
- image = Base64.encode64(HTTPFetcher::fetch($2, Time.at(0)))
+ image = Base64.encode64(HTTPFetcher::fetch($2, Time.at(0)).chomp) + "\n"
cid = "#{Digest::MD5.hexdigest($2)}@feed2imap.acme.com"
imgpart = RMail::Message.new
- imgpart.header.set('Content-Type', "image/#{$4}", 'name' => $3)
- imgpart.header.set('Content-Transfer-Encoding', 'base64')
imgpart.header.set('Content-ID', "<#{cid}>")
+ type = $4
+ type = 'jpeg' if type.downcase == 'jpg' # hack hack hack
+ imgpart.header.set('Content-Type', "image/#{type}", 'name' => $3)
+ imgpart.header.set('Content-Disposition', 'attachment', 'filename' => $3)
+ imgpart.header.set('Content-Transfer-Encoding', 'base64')
imgpart.body = image
message.add_part(imgpart)
# now to specify what to replace with
@@ -107,10 +117,11 @@ def item_to_mail(item, index, updated, from = 'Feed2Imap', include_images = fals
$& # don't modify on exception
end
end
+ else
+ message.header['Content-Type'] = 'multipart/alternative'
+ message.add_part(textpart)
+ message.add_part(htmlpart)
end
-
- message.add_part(textpart)
- message.add_part(htmlpart)
return message.to_s
end