JasonKing-inline_attachment 0.4.0 → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,26 +1,29 @@
1
- = Inline Attachment
1
+ Inline Attachment
2
+ =================
2
3
 
3
4
  This package adds full support for embedding inline images into your HTML emails
4
5
  through ActionMailer.
5
6
 
6
- == Installation
7
+ Installation
8
+ ------------
7
9
 
8
10
  To perform a system wide installation:
9
11
 
10
- <tt>gem source -a http://gems.github.com</tt>
11
- <tt>gem install JasonKing-inline_attachment</tt>
12
+ gem source -a http://gems.github.com
13
+ gem install JasonKing-inline_attachment
12
14
 
13
15
  To use inline_attachment in your project, add the following line to your project's
14
16
  config/environment.rb:
15
17
 
16
- <tt>config.gem 'inline_attachment'</tt>
18
+ config.gem 'inline_attachment'
17
19
 
18
20
 
19
- == Usage
21
+ Usage
22
+ -----
20
23
 
21
24
  I've rewritten most of Edmond's great work in this version. I now override
22
- path_to_image instead of image_tag because a big reason for all the Rails2
23
- breakages was because image_tag was basically reproduced in previous versions,
25
+ path_to_image instead of `image_tag` because a big reason for all the Rails2
26
+ breakages was because `image_tag` was basically reproduced in previous versions,
24
27
  so broke when that method changed.
25
28
 
26
29
  Now we override the very simple path_to_image, and most importantly we really
@@ -30,23 +33,23 @@ code for everything else.
30
33
  I've also integrated in with the new implicit multipart stuff. So now, there is
31
34
  so little code required!
32
35
 
33
-
34
- class Notifier < ActionMailer::Base
35
- def signup
36
+ #### notifier.rb
37
+ class Notifier < ActionMailer::Base
38
+ def signup
36
39
  recipients %q{"Testing IA" <testing@handle.it>}
37
40
  from %q{"Mr Tester" <tester@handle.it>}
38
41
  subject "Here's a funky test"
39
- end
42
+ end
40
43
  end
41
-
42
- # Oh yeah baby! Read it and weep! So how's this work? Well, you'll need
43
- # your templates named properly - see the `Multipart email` section of the
44
- # ActionMailer::Base docs.
45
-
46
- # signup.text.plain.erb
44
+
45
+ Oh yeah baby! Read it and weep! So how's this work? Well, you'll need
46
+ your templates named properly - see the `Multipart email` section of the
47
+ ActionMailer::Base docs.
48
+
49
+ #### signup.text.plain.erb
47
50
  Your username is: <%= @username %>
48
-
49
- # signup.text.html.erb
51
+
52
+ #### signup.text.html.erb
50
53
  <html><head><title>Signup Notification</title></head><body>
51
54
  <%= image_tag "logo.png" %>
52
55
  <p>Your username is: <%=h @username %>
@@ -54,9 +57,9 @@ so little code required!
54
57
 
55
58
 
56
59
  That's it! InlineAttachment will look for
57
- "#{RAILS_ROOT}/public/images/logo.png" and will do the right thing and embed it
60
+ `#{RAILS_ROOT}/public/images/logo.png` and will do the right thing and embed it
58
61
  inline into the HTML version of the email. ActionMailer will do the right thing
59
- and offer the recipient both the text/plain and text/html parts as alternatives.
62
+ and offer the recipient both the `text/plain` and `text/html` parts as alternatives.
60
63
 
61
64
 
62
65
  Note, that you should still be able to use this in the 0.3.0 way if you have
@@ -64,5 +67,11 @@ code that uses that. But there were a lot of alternatives, and the examples in
64
67
  here didn't show a crucial step of shuffling the parts around to be sure that
65
68
  the image parts came after the html.
66
69
 
67
- You can also do the old "manual" method if you want.
70
+ You can also do the old _manual_ method if you want.
71
+
68
72
 
73
+ Contributors
74
+ ------------
75
+
76
+ * Jason King (JasonKing)
77
+ * Matt Griffin (betamatt)
@@ -15,47 +15,52 @@ module ActionMailer
15
15
  end
16
16
 
17
17
  class Base
18
- alias_method :ia_original_create_mail, :create_mail
19
- def create_mail
20
- # sniff out inline html parts with inline images and wrap them up in a
21
- # multipart/related mime part
22
- got_inlines = false
23
- related_parts = []
24
- for_deletion = []
25
- @parts.each_with_index do |p,i|
26
- logger.debug "Considering #{i}"
27
- if p.content_disposition == 'inline' && p.content_type =~ %r{^image/}i && p.headers[CID_NAME]
28
- logger.debug "Just adding [#{i}] to the list\n#{p.filename}"
29
- for_deletion << i
30
- related_parts << p
31
- got_inlines = true
32
- end
18
+ private
19
+
20
+ def create_mail_with_inline_attachment
21
+ # sniff out inline html parts with inline images and wrap them up in a
22
+ # multipart/related mime part
23
+ got_inlines = false
24
+ related_parts = []
25
+ for_deletion = []
26
+ @parts.each_with_index do |p,i|
27
+ if p.content_disposition == 'inline' && p.content_type =~ %r{^image/}i && p.headers[CID_NAME]
28
+ for_deletion << i
29
+ related_parts << p
30
+ got_inlines = true
31
+ end
33
32
 
34
- if got_inlines && p.content_type =~ %r{text/html}i
35
- @parts[i] = ActionMailer::Part.new( :content_type => "multipart/related" )
36
- @parts[i].parts << p
37
- related_parts.each do |rp|
38
- @parts[i].parts << rp
33
+ if got_inlines && p.content_type =~ %r{text/html}i
34
+ @parts[i] = ActionMailer::Part.new( :content_type => "multipart/related" )
35
+ @parts[i].parts << p
36
+ related_parts.each do |rp|
37
+ @parts[i].parts << rp
38
+ end
39
+ got_inlines = false
40
+ related_parts = []
39
41
  end
40
- got_inlines = false
41
- related_parts = []
42
42
  end
43
+ for_deletion.sort{|a,b|b<=>a}.each {|i|@parts.delete_at(i)}
44
+ create_mail_without_inline_attachment
43
45
  end
44
- for_deletion.sort{|a,b|b<=>a}.each {|i|@parts.delete_at(i)}
45
- ia_original_create_mail
46
- end
46
+ alias_method_chain :create_mail, :inline_attachment
47
47
  end
48
48
  end
49
49
 
50
50
  module ActionView
51
51
  module Helpers #:nodoc:
52
52
  module AssetTagHelper
53
- alias_method :ia_original_path_to_image, :path_to_image
54
- def path_to_image(source)
53
+ def path_to_image_with_inline_attachment(source)
55
54
  @part_container ||= @controller
56
55
  if @part_container.is_a?(ActionMailer::Base) or @part_container.is_a?(ActionMailer::Part)
57
- file_path = "#{RAILS_ROOT}/public#{ia_original_path_to_image(source).split('?').first}"
58
-
56
+ if source =~ %r{file://}
57
+ # Handle attached files from the local filesystem. Should sandbox this somehow.
58
+ file_path = source.sub(%r{file://}, '')
59
+ else
60
+ # Public image files
61
+ file_path = "#{RAILS_ROOT}/public#{path_to_image_without_inline_attachment(source).split('?').first}"
62
+ end
63
+
59
64
  if File.exists?(file_path)
60
65
  basename = File.basename(file_path)
61
66
  ext = basename.split('.').last
@@ -71,8 +76,9 @@ module ActionView
71
76
  return "cid:#{cid}"
72
77
  end
73
78
  end
74
- return ia_original_path_to_image(source)
79
+ return path_to_image_without_inline_attachment(source)
75
80
  end
81
+ alias_method_chain :path_to_image, :inline_attachment
76
82
  end
77
83
  end
78
84
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: JasonKing-inline_attachment
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason King
@@ -9,11 +9,12 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-01 00:00:00 -08:00
12
+ date: 2009-02-20 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: mime-types
17
+ type: :runtime
17
18
  version_requirement:
18
19
  version_requirements: !ruby/object:Gem::Requirement
19
20
  requirements:
@@ -30,7 +31,7 @@ extensions: []
30
31
  extra_rdoc_files: []
31
32
 
32
33
  files:
33
- - README
34
+ - README.markdown
34
35
  - lib/inline_attachment.rb
35
36
  has_rdoc: true
36
37
  homepage: http://github.com/JasonKing/inline_attachment