actionmailer 2.0.5 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of actionmailer might be problematic. Click here for more details.

Files changed (73) hide show
  1. data/CHANGELOG +2 -5
  2. data/MIT-LICENSE +1 -1
  3. data/README +14 -10
  4. data/Rakefile +3 -4
  5. data/lib/action_mailer.rb +1 -1
  6. data/lib/action_mailer/adv_attr_accessor.rb +1 -1
  7. data/lib/action_mailer/base.rb +140 -100
  8. data/lib/action_mailer/helpers.rb +7 -7
  9. data/lib/action_mailer/part.rb +2 -2
  10. data/lib/action_mailer/quoting.rb +3 -1
  11. data/lib/action_mailer/test_case.rb +14 -22
  12. data/lib/action_mailer/vendor.rb +2 -2
  13. data/lib/action_mailer/vendor/text-format-0.6.3/text/format.rb +0 -0
  14. data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail.rb +1 -0
  15. data/lib/action_mailer/vendor/tmail-1.2.3/tmail/address.rb +426 -0
  16. data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/attachments.rb +2 -3
  17. data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/base64.rb +4 -10
  18. data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/compat.rb +8 -6
  19. data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/config.rb +2 -6
  20. data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/core_extensions.rb +14 -18
  21. data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/encode.rb +77 -19
  22. data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/header.rb +7 -10
  23. data/lib/action_mailer/vendor/tmail-1.2.3/tmail/index.rb +9 -0
  24. data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/interface.rb +20 -13
  25. data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/loader.rb +2 -0
  26. data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/mail.rb +97 -26
  27. data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/mailbox.rb +70 -10
  28. data/lib/action_mailer/vendor/tmail-1.2.3/tmail/main.rb +6 -0
  29. data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/mbox.rb +2 -0
  30. data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/net.rb +16 -15
  31. data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/obsolete.rb +7 -12
  32. data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/parser.rb +1 -0
  33. data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/port.rb +0 -0
  34. data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/quoting.rb +0 -0
  35. data/lib/action_mailer/vendor/tmail-1.2.3/tmail/require_arch.rb +58 -0
  36. data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/scanner.rb +3 -1
  37. data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/scanner_r.rb +15 -15
  38. data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/stringio.rb +1 -0
  39. data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/utils.rb +89 -32
  40. data/lib/action_mailer/vendor/{tmail-1.2.1 → tmail-1.2.3}/tmail/version.rb +4 -3
  41. data/lib/action_mailer/version.rb +2 -2
  42. data/test/delivery_method_test.rb +1 -1
  43. data/test/mail_helper_test.rb +1 -1
  44. data/test/mail_render_test.rb +1 -1
  45. data/test/mail_service_test.rb +48 -9
  46. data/test/quoting_test.rb +19 -32
  47. data/test/test_helper_test.rb +3 -9
  48. data/test/tmail_test.rb +1 -1
  49. data/test/url_test.rb +2 -2
  50. metadata +33 -53
  51. data/lib/action_mailer/vendor/tmail-1.2.1/tmail/Makefile +0 -19
  52. data/lib/action_mailer/vendor/tmail-1.2.1/tmail/address.rb +0 -245
  53. data/lib/action_mailer/vendor/tmail-1.2.1/tmail/facade.rb +0 -552
  54. data/lib/action_mailer/vendor/tmail-1.2.1/tmail/info.rb +0 -35
  55. data/lib/action_mailer/vendor/tmail-1.2.1/tmail/parser.y +0 -381
  56. data/lib/action_mailer/vendor/tmail-1.2.1/tmail/tmail.rb +0 -1
  57. data/test/fixtures/first_mailer/share.rhtml +0 -0
  58. data/test/fixtures/helper_mailer/use_example_helper.rhtml +0 -0
  59. data/test/fixtures/helper_mailer/use_helper.rhtml +0 -0
  60. data/test/fixtures/helper_mailer/use_helper_method.rhtml +0 -0
  61. data/test/fixtures/helper_mailer/use_mail_helper.rhtml +0 -0
  62. data/test/fixtures/path.with.dots/funky_path_mailer/multipart_with_template_path_with_dots.rhtml +0 -0
  63. data/test/fixtures/path.with.dots/multipart_with_template_path_with_dots.rhtml +0 -0
  64. data/test/fixtures/raw_base64_decoded_string +0 -0
  65. data/test/fixtures/raw_base64_encoded_string +0 -1
  66. data/test/fixtures/second_mailer/share.rhtml +0 -0
  67. data/test/fixtures/templates/signed_up.rhtml +0 -0
  68. data/test/fixtures/test_mailer/implicitly_multipart_example.ignored.rhtml +0 -0
  69. data/test/fixtures/test_mailer/implicitly_multipart_example.text.html.rhtml +0 -0
  70. data/test/fixtures/test_mailer/implicitly_multipart_example.text.plain.rhtml +0 -0
  71. data/test/fixtures/test_mailer/implicitly_multipart_example.text.yaml.rhtml +0 -0
  72. data/test/fixtures/test_mailer/signed_up.rhtml +0 -0
  73. data/test/fixtures/test_mailer/signed_up_with_url.rhtml +0 -0
@@ -1 +1,3 @@
1
+ #:stopdoc:
1
2
  require 'tmail/mailbox'
3
+ #:startdoc:
@@ -28,22 +28,7 @@
28
28
  # Note: Originally licensed under LGPL v2+. Using MIT license for Rails
29
29
  # with permission of Minero Aoki.
30
30
  #++
31
- # == TMail::Mail
32
- # === Class Methods
33
- #
34
- #
35
- #
36
- #
37
- #
38
- #
39
- #
40
- #
41
- #
42
- #
43
- #
44
- #
45
- #
46
- #
31
+
47
32
 
48
33
 
49
34
  require 'tmail/interface'
@@ -58,23 +43,89 @@ require 'socket'
58
43
 
59
44
  module TMail
60
45
 
46
+ # == Mail Class
47
+ #
48
+ # Accessing a TMail object done via the TMail::Mail class. As email can be fairly complex
49
+ # creatures, you will find a large amount of accessor and setter methods in this class!
50
+ #
51
+ # Most of the below methods handle the header, in fact, what TMail does best is handle the
52
+ # header of the email object. There are only a few methods that deal directly with the body
53
+ # of the email, such as base64_encode and base64_decode.
54
+ #
55
+ # === Using TMail inside your code
56
+ #
57
+ # The usual way is to install the gem (see the {README}[link:/README] on how to do this) and
58
+ # then put at the top of your class:
59
+ #
60
+ # require 'tmail'
61
+ #
62
+ # You can then create a new TMail object in your code with:
63
+ #
64
+ # @email = TMail::Mail.new
65
+ #
66
+ # Or if you have an email as a string, you can initialize a new TMail::Mail object and get it
67
+ # to parse that string for you like so:
68
+ #
69
+ # @email = TMail::Mail.parse(email_text)
70
+ #
71
+ # You can also read a single email off the disk, for example:
72
+ #
73
+ # @email = TMail::Mail.load('filename.txt')
74
+ #
75
+ # Also, you can read a mailbox (usual unix mbox format) and end up with an array of TMail
76
+ # objects by doing something like this:
77
+ #
78
+ # # Note, we pass true as the last variable to open the mailbox read only
79
+ # mailbox = TMail::UNIXMbox.new("mailbox", nil, true)
80
+ # @emails = []
81
+ # mailbox.each_port { |m| @emails << TMail::Mail.new(m) }
82
+ #
61
83
  class Mail
62
84
 
63
85
  class << self
86
+
87
+ # Opens an email that has been saved out as a file by itself.
88
+ #
89
+ # This function will read a file non-destructively and then parse
90
+ # the contents and return a TMail::Mail object.
91
+ #
92
+ # Does not handle multiple email mailboxes (like a unix mbox) for that
93
+ # use the TMail::UNIXMbox class.
94
+ #
95
+ # Example:
96
+ # mail = TMail::Mail.load('filename')
97
+ #
64
98
  def load( fname )
65
99
  new(FilePort.new(fname))
66
100
  end
67
101
 
68
102
  alias load_from load
69
103
  alias loadfrom load
70
-
104
+
105
+ # Parses an email from the supplied string and returns a TMail::Mail
106
+ # object.
107
+ #
108
+ # Example:
109
+ # require 'rubygems'; require 'tmail'
110
+ # email_string =<<HEREDOC
111
+ # To: mikel@lindsaar.net
112
+ # From: mikel@me.com
113
+ # Subject: This is a short Email
114
+ #
115
+ # Hello there Mikel!
116
+ #
117
+ # HEREDOC
118
+ # mail = TMail::Mail.parse(email_string)
119
+ # #=> #<TMail::Mail port=#<TMail::StringPort:id=0xa30ac0> bodyport=nil>
120
+ # mail.body
121
+ # #=> "Hello there Mikel!\n\n"
71
122
  def parse( str )
72
123
  new(StringPort.new(str))
73
124
  end
74
125
 
75
126
  end
76
127
 
77
- def initialize( port = nil, conf = DEFAULT_CONFIG )
128
+ def initialize( port = nil, conf = DEFAULT_CONFIG ) #:nodoc:
78
129
  @port = port || StringPort.new
79
130
  @config = Config.to_config(conf)
80
131
 
@@ -90,6 +141,12 @@ module TMail
90
141
  }
91
142
  end
92
143
 
144
+ # Provides access to the port this email is using to hold it's data
145
+ #
146
+ # Example:
147
+ # mail = TMail::Mail.parse(email_string)
148
+ # mail.port
149
+ # #=> #<TMail::StringPort:id=0xa2c952>
93
150
  attr_reader :port
94
151
 
95
152
  def inspect
@@ -351,8 +408,8 @@ module TMail
351
408
  when /\AFrom (\S+)/
352
409
  unixfrom = $1
353
410
 
354
- when /^charset=.*/
355
-
411
+ when /^charset=.*/
412
+
356
413
  else
357
414
  raise SyntaxError, "wrong mail header: '#{line.inspect}'"
358
415
  end
@@ -395,10 +452,12 @@ module TMail
395
452
  end
396
453
 
397
454
  def quoted_body
398
- parse_body
399
- @body_port.ropen {|f|
400
- return f.read
401
- }
455
+ body_port.ropen {|f| return f.read }
456
+ end
457
+
458
+ def quoted_body= str
459
+ body_port.wopen { |f| f.write str }
460
+ str
402
461
  end
403
462
 
404
463
  def body=( str )
@@ -420,8 +479,8 @@ module TMail
420
479
  str
421
480
  end
422
481
 
423
- alias preamble body
424
- alias preamble= body=
482
+ alias preamble quoted_body
483
+ alias preamble= quoted_body=
425
484
 
426
485
  def epilogue
427
486
  parse_body
@@ -442,6 +501,18 @@ module TMail
442
501
  def each_part( &block )
443
502
  parts().each(&block)
444
503
  end
504
+
505
+ # Returns true if the content type of this part of the email is
506
+ # a disposition attachment
507
+ def disposition_is_attachment?
508
+ (self['content-disposition'] && self['content-disposition'].disposition == "attachment")
509
+ end
510
+
511
+ # Returns true if this part's content main type is text, else returns false.
512
+ # By main type is meant "text/plain" is text. "text/html" is text
513
+ def content_type_is_text?
514
+ self.header['content-type'] && (self.header['content-type'].main_type != "text")
515
+ end
445
516
 
446
517
  private
447
518
 
@@ -150,9 +150,78 @@ module TMail
150
150
 
151
151
  class UNIXMbox
152
152
 
153
+ class << self
154
+ alias newobj new
155
+ end
156
+
157
+ # Creates a new mailbox object that you can iterate through to collect the
158
+ # emails from with "each_port".
159
+ #
160
+ # You need to pass it a filename of a unix mailbox format file, the format of this
161
+ # file can be researched at this page at {wikipedia}[link:http://en.wikipedia.org/wiki/Mbox]
162
+ #
163
+ # ==== Parameters
164
+ #
165
+ # +filename+: The filename of the mailbox you want to open
166
+ #
167
+ # +tmpdir+: Can be set to override TMail using the system environment's temp dir. TMail will first
168
+ # use the temp dir specified by you (if any) or then the temp dir specified in the Environment's TEMP
169
+ # value then the value in the Environment's TMP value or failing all of the above, '/tmp'
170
+ #
171
+ # +readonly+: If set to false, each email you take from the mail box will be removed from the mailbox.
172
+ # default is *false* - ie, it *WILL* truncate your mailbox file to ZERO once it has read the emails out.
173
+ #
174
+ # ==== Options:
175
+ #
176
+ # None
177
+ #
178
+ # ==== Examples:
179
+ #
180
+ # # First show using readonly true:
181
+ #
182
+ # require 'ftools'
183
+ # File.size("../test/fixtures/mailbox")
184
+ # #=> 20426
185
+ #
186
+ # mailbox = TMail::UNIXMbox.new("../test/fixtures/mailbox", nil, true)
187
+ # #=> #<TMail::UNIXMbox:0x14a2aa8 @readonly=true.....>
188
+ #
189
+ # mailbox.each_port do |port|
190
+ # mail = TMail::Mail.new(port)
191
+ # puts mail.subject
192
+ # end
193
+ # #Testing mailbox 1
194
+ # #Testing mailbox 2
195
+ # #Testing mailbox 3
196
+ # #Testing mailbox 4
197
+ # require 'ftools'
198
+ # File.size?("../test/fixtures/mailbox")
199
+ # #=> 20426
200
+ #
201
+ # # Now show with readonly set to the default false
202
+ #
203
+ # mailbox = TMail::UNIXMbox.new("../test/fixtures/mailbox")
204
+ # #=> #<TMail::UNIXMbox:0x14a2aa8 @readonly=false.....>
205
+ #
206
+ # mailbox.each_port do |port|
207
+ # mail = TMail::Mail.new(port)
208
+ # puts mail.subject
209
+ # end
210
+ # #Testing mailbox 1
211
+ # #Testing mailbox 2
212
+ # #Testing mailbox 3
213
+ # #Testing mailbox 4
214
+ #
215
+ # File.size?("../test/fixtures/mailbox")
216
+ # #=> nil
217
+ def UNIXMbox.new( filename, tmpdir = nil, readonly = false )
218
+ tmpdir = ENV['TEMP'] || ENV['TMP'] || '/tmp'
219
+ newobj(filename, "#{tmpdir}/ruby_tmail_#{$$}_#{rand()}", readonly, false)
220
+ end
221
+
153
222
  def UNIXMbox.lock( fname )
154
223
  begin
155
- f = File.open(fname)
224
+ f = File.open(fname, 'r+')
156
225
  f.flock File::LOCK_EX
157
226
  yield f
158
227
  ensure
@@ -161,15 +230,6 @@ module TMail
161
230
  end
162
231
  end
163
232
 
164
- class << self
165
- alias newobj new
166
- end
167
-
168
- def UNIXMbox.new( fname, tmpdir = nil, readonly = false )
169
- tmpdir = ENV['TEMP'] || ENV['TMP'] || '/tmp'
170
- newobj(fname, "#{tmpdir}/ruby_tmail_#{$$}_#{rand()}", readonly, false)
171
- end
172
-
173
233
  def UNIXMbox.static_new( fname, dir, readonly = false )
174
234
  newobj(fname, dir, readonly, true)
175
235
  end
@@ -0,0 +1,6 @@
1
+ #:stopdoc:
2
+ require 'tmail/version'
3
+ require 'tmail/mail'
4
+ require 'tmail/mailbox'
5
+ require 'tmail/core_extensions'
6
+ #:startdoc:
@@ -1 +1,3 @@
1
+ #:stopdoc:
1
2
  require 'tmail/mailbox'
3
+ #:startdoc:
@@ -1,8 +1,3 @@
1
- =begin rdoc
2
-
3
- = Net provides SMTP wrapping
4
-
5
- =end
6
1
  #--
7
2
  # Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net>
8
3
  #
@@ -29,13 +24,14 @@
29
24
  # with permission of Minero Aoki.
30
25
  #++
31
26
 
27
+ #:stopdoc:
32
28
  require 'nkf'
33
-
29
+ #:startdoc:
34
30
 
35
31
  module TMail
36
32
 
37
33
  class Mail
38
-
34
+
39
35
  def send_to( smtp )
40
36
  do_send_to(smtp) do
41
37
  ready_to_send
@@ -131,7 +127,7 @@ module TMail
131
127
 
132
128
  end
133
129
 
134
-
130
+ #:stopdoc:
135
131
  class DeleteFields
136
132
 
137
133
  NOSEND_FIELDS = %w(
@@ -155,8 +151,9 @@ module TMail
155
151
  end
156
152
 
157
153
  end
154
+ #:startdoc:
158
155
 
159
-
156
+ #:stopdoc:
160
157
  class AddMessageId
161
158
 
162
159
  def initialize( fqdn = nil )
@@ -170,8 +167,9 @@ module TMail
170
167
  end
171
168
 
172
169
  end
170
+ #:startdoc:
173
171
 
174
-
172
+ #:stopdoc:
175
173
  class AddDate
176
174
 
177
175
  def exec( mail )
@@ -179,8 +177,9 @@ module TMail
179
177
  end
180
178
 
181
179
  end
180
+ #:startdoc:
182
181
 
183
-
182
+ #:stopdoc:
184
183
  class MimeEncodeAuto
185
184
 
186
185
  def initialize( s = nil, m = nil )
@@ -198,8 +197,9 @@ module TMail
198
197
  end
199
198
 
200
199
  end
201
-
200
+ #:startdoc:
202
201
 
202
+ #:stopdoc:
203
203
  class MimeEncodeSingle
204
204
 
205
205
  def exec( mail )
@@ -225,8 +225,9 @@ module TMail
225
225
  end
226
226
 
227
227
  end
228
-
229
-
228
+ #:startdoc:
229
+
230
+ #:stopdoc:
230
231
  class MimeEncodeMulti
231
232
 
232
233
  def exec( mail, top = true )
@@ -243,5 +244,5 @@ module TMail
243
244
  end
244
245
 
245
246
  end
246
-
247
+ #:startdoc:
247
248
  end # module TMail
@@ -2,6 +2,9 @@
2
2
 
3
3
  = Obsolete methods that are depriciated
4
4
 
5
+ If you really want to see them, go to lib/tmail/obsolete.rb and view to your
6
+ heart's content.
7
+
5
8
  =end
6
9
  #--
7
10
  # Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net>
@@ -28,10 +31,9 @@
28
31
  # Note: Originally licensed under LGPL v2+. Using MIT license for Rails
29
32
  # with permission of Minero Aoki.
30
33
  #++
34
+ #:stopdoc:
35
+ module TMail #:nodoc:
31
36
 
32
- module TMail
33
-
34
- # mail.rb
35
37
  class Mail
36
38
  alias include? key?
37
39
  alias has_key? key?
@@ -51,8 +53,6 @@ module TMail
51
53
  alias has_value? value?
52
54
  end
53
55
 
54
-
55
- # facade.rb
56
56
  class Mail
57
57
  def from_addr( default = nil )
58
58
  addr, = from_addrs(nil)
@@ -83,13 +83,11 @@ module TMail
83
83
  alias each_dest each_destination
84
84
  end
85
85
 
86
-
87
- # address.rb
88
86
  class Address
89
87
  alias route routes
90
88
  alias addr spec
91
89
 
92
- def spec=( str )
90
+ def spec=( str )
93
91
  @local, @domain = str.split(/@/,2).map {|s| s.split(/\./) }
94
92
  end
95
93
 
@@ -97,8 +95,6 @@ module TMail
97
95
  alias address= spec=
98
96
  end
99
97
 
100
-
101
- # mbox.rb
102
98
  class MhMailbox
103
99
  alias new_mail new_port
104
100
  alias each_mail each_port
@@ -115,8 +111,6 @@ module TMail
115
111
  alias each_newmail each_new_port
116
112
  end
117
113
 
118
-
119
- # utils.rb
120
114
  extend TextUtils
121
115
 
122
116
  class << self
@@ -135,3 +129,4 @@ module TMail
135
129
  end
136
130
 
137
131
  end # module TMail
132
+ #:startdoc: