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,6 +1,6 @@
1
1
  =begin rdoc
2
2
 
3
- = Attachment handling class
3
+ = Attachment handling file
4
4
 
5
5
  =end
6
6
 
@@ -17,8 +17,7 @@ module TMail
17
17
  end
18
18
 
19
19
  def attachment?(part)
20
- (part['content-disposition'] && part['content-disposition'].disposition == "attachment") ||
21
- part.header['content-type'].main_type != "text"
20
+ part.disposition_is_attachment? || part.content_type_is_text?
22
21
  end
23
22
 
24
23
  def attachments
@@ -1,9 +1,4 @@
1
- # = TITLE:
2
- #
3
- # Base64
4
- #
5
- # = COPYRIGHT:
6
- #
1
+ #--
7
2
  # Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net>
8
3
  #
9
4
  # Permission is hereby granted, free of charge, to any person obtaining
@@ -27,10 +22,9 @@
27
22
  #
28
23
  # Note: Originally licensed under LGPL v2+. Using MIT license for Rails
29
24
  # with permission of Minero Aoki.
30
-
31
- #
25
+ #++
26
+ #:stopdoc:
32
27
  module TMail
33
-
34
28
  module Base64
35
29
 
36
30
  module_function
@@ -48,5 +42,5 @@ module TMail
48
42
  end
49
43
 
50
44
  end
51
-
52
45
  end
46
+ #:startdoc:
@@ -1,17 +1,18 @@
1
- unless Enumerable.method_defined?(:map)
2
- module Enumerable
1
+ #:stopdoc:
2
+ unless Enumerable.method_defined?(:map)
3
+ module Enumerable #:nodoc:
3
4
  alias map collect
4
5
  end
5
6
  end
6
7
 
7
8
  unless Enumerable.method_defined?(:select)
8
- module Enumerable
9
+ module Enumerable #:nodoc:
9
10
  alias select find_all
10
11
  end
11
12
  end
12
13
 
13
14
  unless Enumerable.method_defined?(:reject)
14
- module Enumerable
15
+ module Enumerable #:nodoc:
15
16
  def reject
16
17
  result = []
17
18
  each do |i|
@@ -23,7 +24,7 @@ unless Enumerable.method_defined?(:reject)
23
24
  end
24
25
 
25
26
  unless Enumerable.method_defined?(:sort_by)
26
- module Enumerable
27
+ module Enumerable #:nodoc:
27
28
  def sort_by
28
29
  map {|i| [yield(i), i] }.sort.map {|val, i| i }
29
30
  end
@@ -31,9 +32,10 @@ unless Enumerable.method_defined?(:sort_by)
31
32
  end
32
33
 
33
34
  unless File.respond_to?(:read)
34
- def File.read(fname)
35
+ def File.read(fname) #:nodoc:
35
36
  File.open(fname) {|f|
36
37
  return f.read
37
38
  }
38
39
  end
39
40
  end
41
+ #:startdoc:
@@ -1,8 +1,3 @@
1
- =begin rdoc
2
-
3
- = Configuration Class
4
-
5
- =end
6
1
  #--
7
2
  # Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net>
8
3
  #
@@ -28,7 +23,7 @@
28
23
  # Note: Originally licensed under LGPL v2+. Using MIT license for Rails
29
24
  # with permission of Minero Aoki.
30
25
  #++
31
-
26
+ #:stopdoc:
32
27
  module TMail
33
28
 
34
29
  class Config
@@ -69,3 +64,4 @@ module TMail
69
64
  end
70
65
 
71
66
  end
67
+ #:startdoc:
@@ -1,14 +1,9 @@
1
- =begin rdoc
2
-
3
- = Ruby on Rails Core Extensions
4
-
5
- provides .blank?
6
-
7
- =end
8
- unless Object.respond_to?(:blank?) #:nodoc:
9
- # Check first to see if we are in a Rails environment, no need to
10
- # define these methods if we are
1
+ #:stopdoc:
2
+ unless Object.respond_to?(:blank?)
11
3
  class Object
4
+ # Check first to see if we are in a Rails environment, no need to
5
+ # define these methods if we are
6
+
12
7
  # An object is blank if it's nil, empty, or a whitespace string.
13
8
  # For example, "", " ", nil, [], and {} are blank.
14
9
  #
@@ -27,41 +22,42 @@ unless Object.respond_to?(:blank?) #:nodoc:
27
22
  end
28
23
  end
29
24
 
30
- class NilClass #:nodoc:
25
+ class NilClass
31
26
  def blank?
32
27
  true
33
28
  end
34
29
  end
35
30
 
36
- class FalseClass #:nodoc:
31
+ class FalseClass
37
32
  def blank?
38
33
  true
39
34
  end
40
35
  end
41
36
 
42
- class TrueClass #:nodoc:
37
+ class TrueClass
43
38
  def blank?
44
39
  false
45
40
  end
46
41
  end
47
42
 
48
- class Array #:nodoc:
43
+ class Array
49
44
  alias_method :blank?, :empty?
50
45
  end
51
46
 
52
- class Hash #:nodoc:
47
+ class Hash
53
48
  alias_method :blank?, :empty?
54
49
  end
55
50
 
56
- class String #:nodoc:
51
+ class String
57
52
  def blank?
58
53
  empty? || strip.empty?
59
54
  end
60
55
  end
61
56
 
62
- class Numeric #:nodoc:
57
+ class Numeric
63
58
  def blank?
64
59
  false
65
60
  end
66
61
  end
67
- end
62
+ end
63
+ #:startdoc:
@@ -1,7 +1,4 @@
1
- # = TITLE:
2
- #
3
- # Text Encoding class
4
- #
1
+ #--
5
2
  # = COPYRIGHT:
6
3
  #
7
4
  # Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net>
@@ -27,14 +24,22 @@
27
24
  #
28
25
  # Note: Originally licensed under LGPL v2+. Using MIT license for Rails
29
26
  # with permission of Minero Aoki.
30
-
27
+ #++
28
+ #:stopdoc:
31
29
  require 'nkf'
32
30
  require 'tmail/base64'
33
31
  require 'tmail/stringio'
34
32
  require 'tmail/utils'
33
+ #:startdoc:
35
34
 
36
35
 
37
36
  module TMail
37
+
38
+ #:stopdoc:
39
+ class << self
40
+ attr_accessor :KCODE
41
+ end
42
+ self.KCODE = 'NONE'
38
43
 
39
44
  module StrategyInterface
40
45
 
@@ -52,10 +57,34 @@ module TMail
52
57
  end
53
58
  module_function :create_dest
54
59
 
60
+ #:startdoc:
61
+ # Returns the TMail object encoded and ready to be sent via SMTP etc.
62
+ # You should call this before you are packaging up your email to
63
+ # correctly escape all the values that need escaping in the email, line
64
+ # wrap the email etc.
65
+ #
66
+ # It is also a good idea to call this before you marshal or serialize
67
+ # a TMail object.
68
+ #
69
+ # For Example:
70
+ #
71
+ # email = TMail::Load(my_email_file)
72
+ # email_to_send = email.encoded
55
73
  def encoded( eol = "\r\n", charset = 'j', dest = nil )
56
74
  accept_strategy Encoder, eol, charset, dest
57
75
  end
58
76
 
77
+ # Returns the TMail object decoded and ready to be used by you, your
78
+ # program etc.
79
+ #
80
+ # You should call this before you are packaging up your email to
81
+ # correctly escape all the values that need escaping in the email, line
82
+ # wrap the email etc.
83
+ #
84
+ # For Example:
85
+ #
86
+ # email = TMail::Load(my_email_file)
87
+ # email_to_send = email.encoded
59
88
  def decoded( eol = "\n", charset = 'e', dest = nil )
60
89
  # Turn the E-Mail into a string and return it with all
61
90
  # encoded characters decoded. alias for to_s
@@ -64,7 +93,7 @@ module TMail
64
93
 
65
94
  alias to_s decoded
66
95
 
67
- def accept_strategy( klass, eol, charset, dest = nil )
96
+ def accept_strategy( klass, eol, charset, dest = nil ) #:nodoc:
68
97
  dest ||= ''
69
98
  accept klass.new( create_dest(dest), charset, eol )
70
99
  dest
@@ -72,6 +101,7 @@ module TMail
72
101
 
73
102
  end
74
103
 
104
+ #:stopdoc:
75
105
 
76
106
  ###
77
107
  ### MIME B encoding decoder
@@ -90,8 +120,8 @@ module TMail
90
120
  }
91
121
 
92
122
  def self.decode( str, encoding = nil )
93
- encoding ||= (OUTPUT_ENCODING[$KCODE] || 'j')
94
- opt = '-m' + encoding
123
+ encoding ||= (OUTPUT_ENCODING[TMail.KCODE] || 'j')
124
+ opt = '-mS' + encoding
95
125
  str.gsub(ENCODED_WORDS) {|s| NKF.nkf(opt, s) }
96
126
  end
97
127
 
@@ -193,8 +223,9 @@ module TMail
193
223
 
194
224
  def initialize( dest = nil, encoding = nil, eol = "\r\n", limit = nil )
195
225
  @f = StrategyInterface.create_dest(dest)
196
- @opt = OPTIONS[$KCODE]
226
+ @opt = OPTIONS[TMail.KCODE]
197
227
  @eol = eol
228
+ @folded = false
198
229
  @preserve_quotes = true
199
230
  reset
200
231
  end
@@ -308,22 +339,36 @@ module TMail
308
339
  def scanadd( str, force = false )
309
340
  types = ''
310
341
  strs = []
311
-
342
+ if str.respond_to?(:encoding)
343
+ enc = str.encoding
344
+ str.force_encoding(Encoding::ASCII_8BIT)
345
+ end
312
346
  until str.empty?
313
347
  if m = /\A[^\e\t\r\n ]+/.match(str)
314
348
  types << (force ? 'j' : 'a')
315
- strs.push m[0]
316
-
349
+ if str.respond_to?(:encoding)
350
+ strs.push m[0].force_encoding(enc)
351
+ else
352
+ strs.push m[0]
353
+ end
317
354
  elsif m = /\A[\t\r\n ]+/.match(str)
318
355
  types << 's'
319
- strs.push m[0]
356
+ if str.respond_to?(:encoding)
357
+ strs.push m[0].force_encoding(enc)
358
+ else
359
+ strs.push m[0]
360
+ end
320
361
 
321
362
  elsif m = /\A\e../.match(str)
322
363
  esc = m[0]
323
364
  str = m.post_match
324
365
  if esc != "\e(B" and m = /\A[^\e]+/.match(str)
325
366
  types << 'j'
326
- strs.push m[0]
367
+ if str.respond_to?(:encoding)
368
+ strs.push m[0].force_encoding(enc)
369
+ else
370
+ strs.push m[0]
371
+ end
327
372
  end
328
373
 
329
374
  else
@@ -367,11 +412,16 @@ module TMail
367
412
  end
368
413
 
369
414
  def concat_A_S( types, strs )
415
+ if RUBY_VERSION < '1.9'
416
+ a = ?a; s = ?s
417
+ else
418
+ a = 'a'.ord; s = 's'.ord
419
+ end
370
420
  i = 0
371
421
  types.each_byte do |t|
372
422
  case t
373
- when ?a then add_text strs[i]
374
- when ?s then add_lwsp strs[i]
423
+ when a then add_text strs[i]
424
+ when s then add_lwsp strs[i]
375
425
  else
376
426
  raise "TMail FATAL: unknown flag: #{t.chr}"
377
427
  end
@@ -417,7 +467,13 @@ module TMail
417
467
  size = max_bytes(chunksize, str.size) - 6
418
468
  size = (size % 2 == 0) ? (size) : (size - 1)
419
469
  return nil if size <= 0
420
- "\e$B#{str.slice!(0, size)}\e(B"
470
+ if str.respond_to?(:encoding)
471
+ enc = str.encoding
472
+ str.force_encoding(Encoding::ASCII_8BIT)
473
+ "\e$B#{str.slice!(0, size)}\e(B".force_encoding(enc)
474
+ else
475
+ "\e$B#{str.slice!(0, size)}\e(B"
476
+ end
421
477
  end
422
478
 
423
479
  def extract_A( chunksize, str )
@@ -490,7 +546,7 @@ module TMail
490
546
 
491
547
  # Check the text to see if there is whitespace, or if not
492
548
  @wrapped_text = []
493
- until @text == ''
549
+ until @text.blank?
494
550
  fold_the_string
495
551
  end
496
552
  @text = @wrapped_text.join("#{@eol}#{SPACER}")
@@ -501,10 +557,12 @@ module TMail
501
557
  # Is the location of the whitespace shorter than the RCF_2822_MAX_LENGTH?
502
558
  # if there is no whitespace in the string, then this
503
559
  unless mazsize(whitespace_location) <= 0
560
+ @text.strip!
504
561
  @wrapped_text << @text.slice!(0...whitespace_location)
505
562
  # If it is not less, we have to wrap it destructively
506
563
  else
507
564
  slice_point = RFC_2822_MAX_LENGTH - @curlen - @lwsp.length
565
+ @text.strip!
508
566
  @wrapped_text << @text.slice!(0...slice_point)
509
567
  end
510
568
  end
@@ -519,5 +577,5 @@ module TMail
519
577
  end
520
578
 
521
579
  end
522
-
580
+ #:startdoc:
523
581
  end # module TMail
@@ -1,11 +1,3 @@
1
- =begin rdoc
2
-
3
- = Header handling class
4
-
5
- =end
6
- # RFC #822 ftp://ftp.isi.edu/in-notes/rfc822.txt
7
- #
8
- #
9
1
  #--
10
2
  # Copyright (c) 1998-2003 Minero Aoki <aamine@loveruby.net>
11
3
  #
@@ -38,9 +30,10 @@ require 'tmail/parser'
38
30
  require 'tmail/config'
39
31
  require 'tmail/utils'
40
32
 
41
-
33
+ #:startdoc:
42
34
  module TMail
43
35
 
36
+ # Provides methods to handle and manipulate headers in the email
44
37
  class HeaderField
45
38
 
46
39
  include TextUtils
@@ -214,7 +207,11 @@ module TMail
214
207
 
215
208
  def comments
216
209
  ensure_parsed
217
- @comments
210
+ if @comments[0]
211
+ [Decoder.decode(@comments[0])]
212
+ else
213
+ @comments
214
+ end
218
215
  end
219
216
 
220
217
  private
@@ -0,0 +1,9 @@
1
+ #:stopdoc:
2
+ # This is here for Rolls.
3
+ # Rolls uses this instead of lib/tmail.rb.
4
+
5
+ require 'tmail/version'
6
+ require 'tmail/mail'
7
+ require 'tmail/mailbox'
8
+ require 'tmail/core_extensions'
9
+ #:startdoc:
@@ -591,12 +591,17 @@ module TMail
591
591
  end
592
592
 
593
593
  # Destructively sets the message ID of the mail object instance to the passed in string
594
+ #
595
+ # Invalid message IDs are ignored (silently, unless configured otherwise) and result in
596
+ # a nil message ID. Left and right angle brackets are required.
594
597
  #
595
598
  # Example:
596
599
  #
597
600
  # mail = TMail::Mail.new
601
+ # mail.message_id = "<348F04F142D69C21-291E56D292BC@xxxx.net>"
602
+ # mail.message_id #=> "<348F04F142D69C21-291E56D292BC@xxxx.net>"
598
603
  # mail.message_id = "this_is_my_badly_formatted_message_id"
599
- # mail.message_id #=> "this_is_my_badly_formatted_message_id"
604
+ # mail.message_id #=> nil
600
605
  def message_id=( str )
601
606
  set_string_attr 'Message-Id', str
602
607
  end
@@ -966,31 +971,33 @@ module TMail
966
971
  end
967
972
  end
968
973
 
969
- # Destructively convert the Mail object's body into a Base64 encoded email
974
+ # Convert the Mail object's body into a Base64 encoded email
970
975
  # returning the modified Mail object
971
976
  def base64_encode!
972
977
  store 'Content-Transfer-Encoding', 'Base64'
973
- self.body = Base64.folding_encode(self.body)
978
+ self.body = base64_encode
974
979
  end
975
980
 
976
- # ==Depreciation warning
977
- # base64_encode will return the body encoded, not modify the message body in
978
- # future versions of TMail
979
- alias :base64_encode :base64_encode!
981
+ # Return the result of encoding the TMail::Mail object body
982
+ # without altering the current body
983
+ def base64_encode
984
+ Base64.folding_encode(self.body)
985
+ end
980
986
 
981
- # Destructively convert the Mail object's body into a Base64 decoded email
987
+ # Convert the Mail object's body into a Base64 decoded email
982
988
  # returning the modified Mail object
983
989
  def base64_decode!
984
990
  if /base64/i === self.transfer_encoding('')
985
991
  store 'Content-Transfer-Encoding', '8bit'
986
- self.body = Base64.decode(self.body, @config.strict_base64decode?)
992
+ self.body = base64_decode
987
993
  end
988
994
  end
989
995
 
990
- # ==Depreciation warning
991
- # base64_decode will return the body decoded, not modify the message body in
992
- # future versions of TMail
993
- alias :base64_decode :base64_decode!
996
+ # Returns the result of decoding the TMail::Mail object body
997
+ # without altering the current body
998
+ def base64_decode
999
+ Base64.decode(self.body, @config.strict_base64decode?)
1000
+ end
994
1001
 
995
1002
  # Returns an array of each destination in the email message including to: cc: or bcc:
996
1003
  #