summaryrefslogtreecommitdiff
path: root/lib/feed2imap
diff options
context:
space:
mode:
authorLucas Nussbaum <lucas@lucas-nussbaum.net>2009-05-06 11:07:48 +0200
committerLucas Nussbaum <lucas@lucas-nussbaum.net>2009-05-06 11:07:48 +0200
commit92b406375fa95e9111653b8139d74cebe8c65b01 (patch)
tree889c75024539129209fc7f98b658b4bda52d5ff5 /lib/feed2imap
parent31361b976200db24e704380360882a04244256a6 (diff)
downloadfeed2imap-92b406375fa95e9111653b8139d74cebe8c65b01.tar.gz
feed2imap-92b406375fa95e9111653b8139d74cebe8c65b01.tar.bz2
feed2imap-92b406375fa95e9111653b8139d74cebe8c65b01.zip
Only include images once as attachments if the image is duplicated in the item (thanks to Joachim Breitner for noticing)
Diffstat (limited to '')
-rw-r--r--lib/feed2imap/itemtomail.rb22
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/feed2imap/itemtomail.rb b/lib/feed2imap/itemtomail.rb
index ec3bbfb..00ce84f 100644
--- a/lib/feed2imap/itemtomail.rb
+++ b/lib/feed2imap/itemtomail.rb
@@ -95,20 +95,24 @@ def item_to_mail(item, index, updated, from = 'Feed2Imap', inline_images = false
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
begin
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-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)
+ if not cids.include?(cid)
+ cids << cid
+ imgpart = RMail::Message.new
+ 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)
+ end
# now to specify what to replace with
newtag = "#{$1}src=\"cid:#{cid}\"#{$5}"
#print "#{cid}: Replacing '#{$&}' with '#{newtag}'...\n"
-49/+1771 2013-06-06i3: new temporary workspaceRené Neumann2-1/+27 2013-06-06Allow 'klass' in i3.py descriptionsRené Neumann1-0/+4 2013-06-04i3: rename workspaceRené Neumann1-0/+3 2013-06-03Some more greek chars / math product and sumRené 'Necoro' Neumann1-0/+6 2013-06-02Fix rules in i3-config. Somehow 'set' expands variables twice :-/René Neumann1-14/+11 2013-06-01Overhaul xlock.shRené 'Necoro' Neumann1-4/+8 2013-06-01Better workspace chooserRené 'Necoro' Neumann3-2/+581 2013-06-01FF/TB/Pidgin stuffRené 'Necoro' Neumann1-26/+45 2013-06-01More i3René 'Necoro' Neumann1-2/+11 2013-06-01FixesRené 'Necoro' Neumann2-2/+2