inline_attachment 0.4.0 → 0.4.4

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.
data/README.markdown ADDED
@@ -0,0 +1,97 @@
1
+ Inline Attachment
2
+ =================
3
+
4
+ This package adds full support for embedding inline images into your HTML emails
5
+ through ActionMailer.
6
+
7
+ Installation
8
+ ------------
9
+
10
+ ### As a Gem ###
11
+
12
+ To perform a system wide installation:
13
+
14
+ gem source -a http://gems.github.com
15
+ gem install JasonKing-inline_attachment
16
+
17
+ To use inline_attachment in your project, add the following line to your project's
18
+ config/environment.rb:
19
+
20
+ config.gem 'JasonKing-inline_attachment', :lib => 'inline_attachment'
21
+
22
+
23
+ ### As a Rails Plugin ###
24
+
25
+ Use this to install as a plugin in a Ruby on Rails app:
26
+
27
+ $ script/plugin install git://github.com/JasonKing/inline_attachment.git
28
+
29
+ ### As a Rails Plugin (using git submodules) ###
30
+
31
+ Use this if you prefer the idea of being able to easily switch between using edge or a tagged version:
32
+
33
+ $ git submodule add git://github.com/JasonKing/inline_attachment.git vendor/plugins/inline_attachment
34
+
35
+
36
+ Usage
37
+ -----
38
+
39
+ I've rewritten most of Edmond's great work in this version. I now override
40
+ path_to_image instead of `image_tag` because a big reason for all the Rails2
41
+ breakages was because `image_tag` was basically reproduced in previous versions,
42
+ so broke when that method changed.
43
+
44
+ Now we override the very simple path_to_image, and most importantly we really
45
+ just add our own stuff for ActionMailer templates, and resort to the existing
46
+ code for everything else.
47
+
48
+ I've also integrated in with the new implicit multipart stuff. So now, there is
49
+ so little code required!
50
+
51
+ #### notifier.rb
52
+ class Notifier < ActionMailer::Base
53
+ def signup
54
+ recipients %q{"Testing IA" <testing@handle.it>}
55
+ from %q{"Mr Tester" <tester@handle.it>}
56
+ subject "Here's a funky test"
57
+ end
58
+ end
59
+
60
+ Oh yeah baby! Read it and weep! So how's this work? Well, you'll need
61
+ your templates named properly - see the _Multipart email_ section of the
62
+ ActionMailer::Base docs.
63
+
64
+ #### signup.text.plain.erb
65
+ Your username is: <%= @username %>
66
+
67
+ #### signup.text.html.erb
68
+ <html><head><title>Signup Notification</title></head><body>
69
+ <%= image_tag "logo.png" %>
70
+ <p>Your username is: <%=h @username %>
71
+ </body></html>
72
+
73
+
74
+ That's it! InlineAttachment will look for
75
+ `#{RAILS_ROOT}/public/images/logo.png` and will do the right thing and embed it
76
+ inline into the HTML version of the email. ActionMailer will do the right thing
77
+ and offer the recipient both the `text/plain` and `text/html` parts as alternatives.
78
+
79
+ **Note the filenames include the (unusual) major.minor MIME type, look above at
80
+ the filenames closely.**
81
+
82
+
83
+ Note, that you should still be able to use this in the 0.3.0 way if you have
84
+ code that uses that. But there were a lot of alternatives, and the examples in
85
+ here didn't show a crucial step of shuffling the parts around to be sure that
86
+ the image parts came after the html.
87
+
88
+ You can also do the old _manual_ method if you want.
89
+
90
+
91
+ Contributors
92
+ ------------
93
+
94
+ * Jason King (JasonKing)
95
+ * Matt Griffin (betamatt) - file:// and chaining cleanup
96
+ * Logan Raarup (logandk) - pluginified
97
+ * Jeffrey Damick (jdamick) - bugfix
@@ -15,64 +15,71 @@ 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
62
67
  cid = Time.now.to_f.to_s + "#{basename}@inline_attachment"
63
- file = File.open(file_path, 'rb')
64
68
 
65
- @part_container.inline_attachment(:content_type => "image/#{ext}",
66
- :body => file.read,
67
- :filename => basename,
68
- :cid => "<#{cid}>",
69
- :disposition => "inline")
70
-
69
+ File.open(file_path, 'rb') do |file|
70
+ @part_container.inline_attachment(:content_type => "image/#{ext}",
71
+ :body => file.read,
72
+ :filename => basename,
73
+ :cid => "<#{cid}>",
74
+ :disposition => "inline")
75
+ end
76
+
71
77
  return "cid:#{cid}"
72
78
  end
73
79
  end
74
- return ia_original_path_to_image(source)
80
+ return path_to_image_without_inline_attachment(source)
75
81
  end
82
+ alias_method_chain :path_to_image, :inline_attachment
76
83
  end
77
84
  end
78
85
  end
data/rails/init.rb ADDED
@@ -0,0 +1 @@
1
+ require "inline_attachment"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inline_attachment
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason King
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-02 00:00:00 +11:00
12
+ date: 2010-02-16 00:00:00 -08:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -22,7 +22,105 @@ dependencies:
22
22
  - !ruby/object:Gem::Version
23
23
  version: "1.15"
24
24
  version:
25
- description:
25
+ description: |
26
+ Inline Attachment
27
+ =================
28
+
29
+ This package adds full support for embedding inline images into your HTML emails
30
+ through ActionMailer.
31
+
32
+ Installation
33
+ ------------
34
+
35
+ ### As a Gem ###
36
+
37
+ To perform a system wide installation:
38
+
39
+ gem source -a http://gems.github.com
40
+ gem install JasonKing-inline_attachment
41
+
42
+ To use inline_attachment in your project, add the following line to your project's
43
+ config/environment.rb:
44
+
45
+ config.gem 'JasonKing-inline_attachment', :lib => 'inline_attachment'
46
+
47
+
48
+ ### As a Rails Plugin ###
49
+
50
+ Use this to install as a plugin in a Ruby on Rails app:
51
+
52
+ $ script/plugin install git://github.com/JasonKing/inline_attachment.git
53
+
54
+ ### As a Rails Plugin (using git submodules) ###
55
+
56
+ Use this if you prefer the idea of being able to easily switch between using edge or a tagged version:
57
+
58
+ $ git submodule add git://github.com/JasonKing/inline_attachment.git vendor/plugins/inline_attachment
59
+
60
+
61
+ Usage
62
+ -----
63
+
64
+ I've rewritten most of Edmond's great work in this version. I now override
65
+ path_to_image instead of `image_tag` because a big reason for all the Rails2
66
+ breakages was because `image_tag` was basically reproduced in previous versions,
67
+ so broke when that method changed.
68
+
69
+ Now we override the very simple path_to_image, and most importantly we really
70
+ just add our own stuff for ActionMailer templates, and resort to the existing
71
+ code for everything else.
72
+
73
+ I've also integrated in with the new implicit multipart stuff. So now, there is
74
+ so little code required!
75
+
76
+ #### notifier.rb
77
+ class Notifier < ActionMailer::Base
78
+ def signup
79
+ recipients %q{"Testing IA" <testing@handle.it>}
80
+ from %q{"Mr Tester" <tester@handle.it>}
81
+ subject "Here's a funky test"
82
+ end
83
+ end
84
+
85
+ Oh yeah baby! Read it and weep! So how's this work? Well, you'll need
86
+ your templates named properly - see the _Multipart email_ section of the
87
+ ActionMailer::Base docs.
88
+
89
+ #### signup.text.plain.erb
90
+ Your username is: <%= @username %>
91
+
92
+ #### signup.text.html.erb
93
+ <html><head><title>Signup Notification</title></head><body>
94
+ <%= image_tag "logo.png" %>
95
+ <p>Your username is: <%=h @username %>
96
+ </body></html>
97
+
98
+
99
+ That's it! InlineAttachment will look for
100
+ `#{RAILS_ROOT}/public/images/logo.png` and will do the right thing and embed it
101
+ inline into the HTML version of the email. ActionMailer will do the right thing
102
+ and offer the recipient both the `text/plain` and `text/html` parts as alternatives.
103
+
104
+ **Note the filenames include the (unusual) major.minor MIME type, look above at
105
+ the filenames closely.**
106
+
107
+
108
+ Note, that you should still be able to use this in the 0.3.0 way if you have
109
+ code that uses that. But there were a lot of alternatives, and the examples in
110
+ here didn't show a crucial step of shuffling the parts around to be sure that
111
+ the image parts came after the html.
112
+
113
+ You can also do the old _manual_ method if you want.
114
+
115
+
116
+ Contributors
117
+ ------------
118
+
119
+ * Jason King (JasonKing)
120
+ * Matt Griffin (betamatt) - file:// and chaining cleanup
121
+ * Logan Raarup (logandk) - pluginified
122
+ * Jeffrey Damick (jdamick) - bugfix
123
+
26
124
  email: jk@handle.it
27
125
  executables: []
28
126
 
@@ -31,10 +129,13 @@ extensions: []
31
129
  extra_rdoc_files: []
32
130
 
33
131
  files:
34
- - README
132
+ - rails/init.rb
133
+ - README.markdown
35
134
  - lib/inline_attachment.rb
36
135
  has_rdoc: true
37
136
  homepage: http://github.com/JasonKing/inline_attachment
137
+ licenses: []
138
+
38
139
  post_install_message:
39
140
  rdoc_options:
40
141
  - --inline-source
@@ -56,7 +157,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
157
  requirements: []
57
158
 
58
159
  rubyforge_project: InlineAttachment
59
- rubygems_version: 1.3.1
160
+ rubygems_version: 1.3.5
60
161
  signing_key:
61
162
  specification_version: 2
62
163
  summary: Makes image_tag in an ActionMailer template embed the images in the emails
data/README DELETED
@@ -1,68 +0,0 @@
1
- = Inline Attachment
2
-
3
- This package adds full support for embedding inline images into your HTML emails
4
- through ActionMailer.
5
-
6
- == Installation
7
-
8
- To perform a system wide installation:
9
-
10
- <tt>gem source -a http://gems.github.com</tt>
11
- <tt>gem install JasonKing-inline_attachment</tt>
12
-
13
- To use inline_attachment in your project, add the following line to your project's
14
- config/environment.rb:
15
-
16
- <tt>config.gem 'inline_attachment'</tt>
17
-
18
-
19
- == Usage
20
-
21
- 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,
24
- so broke when that method changed.
25
-
26
- Now we override the very simple path_to_image, and most importantly we really
27
- just add our own stuff for ActionMailer templates, and resort to the existing
28
- code for everything else.
29
-
30
- I've also integrated in with the new implicit multipart stuff. So now, there is
31
- so little code required!
32
-
33
-
34
- class Notifier < ActionMailer::Base
35
- def signup
36
- recipients %q{"Testing IA" <testing@handle.it>}
37
- from %q{"Mr Tester" <tester@handle.it>}
38
- subject "Here's a funky test"
39
- end
40
- 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
47
- Your username is: <%= @username %>
48
-
49
- # signup.text.html.erb
50
- <html><head><title>Signup Notification</title></head><body>
51
- <%= image_tag "logo.png" %>
52
- <p>Your username is: <%=h @username %>
53
- </body></html>
54
-
55
-
56
- That's it! InlineAttachment will look for
57
- "#{RAILS_ROOT}/public/images/logo.png" and will do the right thing and embed it
58
- 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.
60
-
61
-
62
- Note, that you should still be able to use this in the 0.3.0 way if you have
63
- code that uses that. But there were a lot of alternatives, and the examples in
64
- here didn't show a crucial step of shuffling the parts around to be sure that
65
- the image parts came after the html.
66
-
67
- You can also do the old "manual" method if you want.
68
-