mail 2.2.5 → 2.2.19

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.
Files changed (152) hide show
  1. data/CHANGELOG.rdoc +163 -7
  2. data/README.rdoc +56 -65
  3. data/Rakefile +31 -6
  4. data/lib/VERSION +2 -2
  5. data/lib/mail/attachments_list.rb +4 -4
  6. data/lib/mail/body.rb +6 -2
  7. data/lib/mail/configuration.rb +7 -1
  8. data/lib/mail/core_extensions/shellwords.rb +55 -0
  9. data/lib/mail/core_extensions/smtp.rb +24 -0
  10. data/lib/mail/elements/address.rb +6 -6
  11. data/lib/mail/elements/content_disposition_element.rb +1 -1
  12. data/lib/mail/elements/content_type_element.rb +2 -2
  13. data/lib/mail/encodings.rb +55 -57
  14. data/lib/mail/field.rb +2 -1
  15. data/lib/mail/field_list.rb +1 -1
  16. data/lib/mail/fields/common/common_field.rb +10 -9
  17. data/lib/mail/fields/common/common_message_id.rb +6 -5
  18. data/lib/mail/fields/common/parameter_hash.rb +14 -4
  19. data/lib/mail/fields/content_disposition_field.rb +1 -1
  20. data/lib/mail/fields/content_type_field.rb +41 -28
  21. data/lib/mail/fields/date_field.rb +3 -1
  22. data/lib/mail/fields/received_field.rb +11 -3
  23. data/lib/mail/fields/resent_date_field.rb +1 -1
  24. data/lib/mail/fields/return_path_field.rb +1 -0
  25. data/lib/mail/fields/unstructured_field.rb +4 -1
  26. data/lib/mail/header.rb +8 -5
  27. data/lib/mail/mail.rb +71 -57
  28. data/lib/mail/message.rb +518 -391
  29. data/lib/mail/network/delivery_methods/sendmail.rb +15 -15
  30. data/lib/mail/network/delivery_methods/smtp.rb +33 -6
  31. data/lib/mail/network/delivery_methods/smtp_connection.rb +74 -0
  32. data/lib/mail/network/retriever_methods/base.rb +63 -0
  33. data/lib/mail/network/retriever_methods/imap.rb +147 -7
  34. data/lib/mail/network/retriever_methods/pop3.rb +25 -44
  35. data/lib/mail/network/retriever_methods/test_retriever.rb +40 -0
  36. data/lib/mail/network.rb +4 -0
  37. data/lib/mail/parsers/address_lists.rb +2 -2
  38. data/lib/mail/parsers/address_lists.treetop +2 -2
  39. data/lib/mail/parsers/content_disposition.rb +166 -18
  40. data/lib/mail/parsers/content_disposition.treetop +1 -1
  41. data/lib/mail/parsers/content_type.rb +477 -49
  42. data/lib/mail/parsers/content_type.treetop +12 -2
  43. data/lib/mail/parsers/rfc2822.rb +58 -35
  44. data/lib/mail/parsers/rfc2822.treetop +2 -2
  45. data/lib/mail/part.rb +2 -2
  46. data/lib/mail/parts_list.rb +16 -8
  47. data/lib/mail/patterns.rb +7 -2
  48. data/lib/mail/utilities.rb +31 -1
  49. data/lib/mail/version.rb +10 -8
  50. data/lib/mail/version_specific/ruby_1_8.rb +2 -2
  51. data/lib/mail/version_specific/ruby_1_9.rb +29 -8
  52. data/lib/mail.rb +8 -4
  53. metadata +44 -110
  54. data/lib/mail/attachments_list.rbc +0 -1983
  55. data/lib/mail/body.rbc +0 -3809
  56. data/lib/mail/configuration.rbc +0 -1112
  57. data/lib/mail/core_extensions/nil.rbc +0 -244
  58. data/lib/mail/core_extensions/string.rbc +0 -0
  59. data/lib/mail/elements/address.rbc +0 -4112
  60. data/lib/mail/elements/address_list.rbc +0 -1309
  61. data/lib/mail/elements/content_disposition_element.rbc +0 -701
  62. data/lib/mail/elements/content_location_element.rbc +0 -573
  63. data/lib/mail/elements/content_transfer_encoding_element.rbc +0 -535
  64. data/lib/mail/elements/content_type_element.rbc +0 -786
  65. data/lib/mail/elements/date_time_element.rbc +0 -583
  66. data/lib/mail/elements/envelope_from_element.rbc +0 -771
  67. data/lib/mail/elements/message_ids_element.rbc +0 -740
  68. data/lib/mail/elements/mime_version_element.rbc +0 -583
  69. data/lib/mail/elements/phrase_list.rbc +0 -562
  70. data/lib/mail/elements/received_element.rbc +0 -725
  71. data/lib/mail/elements.rbc +0 -362
  72. data/lib/mail/encodings/7bit.rbc +0 -538
  73. data/lib/mail/encodings/8bit.rbc +0 -541
  74. data/lib/mail/encodings/base64.rbc +0 -629
  75. data/lib/mail/encodings/binary.rbc +0 -529
  76. data/lib/mail/encodings/quoted_printable.rbc +0 -766
  77. data/lib/mail/encodings/transfer_encoding.rbc +0 -1134
  78. data/lib/mail/encodings.rbc +0 -0
  79. data/lib/mail/envelope.rbc +0 -719
  80. data/lib/mail/field.rbc +0 -4708
  81. data/lib/mail/field_list.rbc +0 -518
  82. data/lib/mail/fields/bcc_field.rbc +0 -564
  83. data/lib/mail/fields/cc_field.rbc +0 -579
  84. data/lib/mail/fields/comments_field.rbc +0 -383
  85. data/lib/mail/fields/common/address_container.rbc +0 -363
  86. data/lib/mail/fields/common/common_address.rbc +0 -3550
  87. data/lib/mail/fields/common/common_date.rbc +0 -908
  88. data/lib/mail/fields/common/common_field.rbc +0 -973
  89. data/lib/mail/fields/common/common_message_id.rbc +0 -1051
  90. data/lib/mail/fields/common/parameter_hash.rbc +0 -1335
  91. data/lib/mail/fields/content_description_field.rbc +0 -396
  92. data/lib/mail/fields/content_disposition_field.rbc +0 -1440
  93. data/lib/mail/fields/content_id_field.rbc +0 -1236
  94. data/lib/mail/fields/content_location_field.rbc +0 -892
  95. data/lib/mail/fields/content_transfer_encoding_field.rbc +0 -1184
  96. data/lib/mail/fields/content_type_field.rbc +0 -3958
  97. data/lib/mail/fields/date_field.rbc +0 -712
  98. data/lib/mail/fields/from_field.rbc +0 -579
  99. data/lib/mail/fields/in_reply_to_field.rbc +0 -579
  100. data/lib/mail/fields/keywords_field.rbc +0 -979
  101. data/lib/mail/fields/message_id_field.rbc +0 -1008
  102. data/lib/mail/fields/mime_version_field.rbc +0 -1107
  103. data/lib/mail/fields/optional_field.rbc +0 -153
  104. data/lib/mail/fields/received_field.rbc +0 -1137
  105. data/lib/mail/fields/references_field.rbc +0 -574
  106. data/lib/mail/fields/reply_to_field.rbc +0 -579
  107. data/lib/mail/fields/resent_bcc_field.rbc +0 -579
  108. data/lib/mail/fields/resent_cc_field.rbc +0 -579
  109. data/lib/mail/fields/resent_date_field.rbc +0 -656
  110. data/lib/mail/fields/resent_from_field.rbc +0 -579
  111. data/lib/mail/fields/resent_message_id_field.rbc +0 -639
  112. data/lib/mail/fields/resent_sender_field.rbc +0 -731
  113. data/lib/mail/fields/resent_to_field.rbc +0 -579
  114. data/lib/mail/fields/return_path_field.rbc +0 -737
  115. data/lib/mail/fields/sender_field.rbc +0 -799
  116. data/lib/mail/fields/structured_field.rbc +0 -671
  117. data/lib/mail/fields/subject_field.rbc +0 -378
  118. data/lib/mail/fields/to_field.rbc +0 -579
  119. data/lib/mail/fields/unstructured_field.rbc +0 -2292
  120. data/lib/mail/fields.rbc +0 -782
  121. data/lib/mail/header.rbc +0 -3720
  122. data/lib/mail/mail.rbc +0 -2168
  123. data/lib/mail/message.rbc +0 -19034
  124. data/lib/mail/network/delivery_methods/file_delivery.rbc +0 -722
  125. data/lib/mail/network/delivery_methods/sendmail.rbc +0 -800
  126. data/lib/mail/network/delivery_methods/smtp.rbc +0 -1081
  127. data/lib/mail/network/delivery_methods/test_mailer.rbc +0 -552
  128. data/lib/mail/network/retriever_methods/pop3.rbc +0 -2447
  129. data/lib/mail/network.rbc +0 -236
  130. data/lib/mail/parsers/address_lists.rbc +0 -1307
  131. data/lib/mail/parsers/content_disposition.rbc +0 -5968
  132. data/lib/mail/parsers/content_location.rbc +0 -2166
  133. data/lib/mail/parsers/content_transfer_encoding.rbc +0 -2591
  134. data/lib/mail/parsers/content_type.rbc +0 -7949
  135. data/lib/mail/parsers/date_time.rbc +0 -1836
  136. data/lib/mail/parsers/envelope_from.rbc +0 -3106
  137. data/lib/mail/parsers/message_ids.rbc +0 -989
  138. data/lib/mail/parsers/mime_version.rbc +0 -2254
  139. data/lib/mail/parsers/phrase_lists.rbc +0 -989
  140. data/lib/mail/parsers/received.rbc +0 -1267
  141. data/lib/mail/parsers/rfc2045.rbc +0 -5614
  142. data/lib/mail/parsers/rfc2822.rbc +0 -74848
  143. data/lib/mail/parsers/rfc2822_obsolete.rbc +0 -55220
  144. data/lib/mail/part.rbc +0 -2314
  145. data/lib/mail/parts_list.rbc +0 -832
  146. data/lib/mail/patterns.rbc +0 -0
  147. data/lib/mail/utilities.rbc +0 -2377
  148. data/lib/mail/version.rbc +0 -450
  149. data/lib/mail/version_specific/ruby_1_8.rbc +0 -2496
  150. data/lib/mail.rbc +0 -1151
  151. data/lib/tasks/corpus.rake.compiled.rbc +0 -2195
  152. data/lib/tasks/treetop.rake.compiled.rbc +0 -297
@@ -3,10 +3,10 @@ require 'mail/fields/common/parameter_hash'
3
3
 
4
4
  module Mail
5
5
  class ContentTypeField < StructuredField
6
-
6
+
7
7
  FIELD_NAME = 'content-type'
8
8
  CAPITALIZED_FIELD = 'Content-Type'
9
-
9
+
10
10
  def initialize(value = nil, charset = 'utf-8')
11
11
  self.charset = charset
12
12
  if value.class == Array
@@ -23,15 +23,15 @@ module Mail
23
23
  self.parse
24
24
  self
25
25
  end
26
-
26
+
27
27
  def parse(val = value)
28
28
  unless val.blank?
29
- self.value = val
29
+ self.value = val
30
30
  @element = nil
31
31
  element
32
32
  end
33
33
  end
34
-
34
+
35
35
  def element
36
36
  begin
37
37
  @element ||= Mail::ContentTypeElement.new(value)
@@ -39,7 +39,7 @@ module Mail
39
39
  attempt_to_clean
40
40
  end
41
41
  end
42
-
42
+
43
43
  def attempt_to_clean
44
44
  # Sanitize the value, handle special cases
45
45
  @element ||= Mail::ContentTypeElement.new(sanatize(value))
@@ -47,7 +47,7 @@ module Mail
47
47
  # All else fails, just get the MIME media type
48
48
  @element ||= Mail::ContentTypeElement.new(get_mime_type(value))
49
49
  end
50
-
50
+
51
51
  def main_type
52
52
  @main_type ||= element.main_type
53
53
  end
@@ -55,17 +55,17 @@ module Mail
55
55
  def sub_type
56
56
  @sub_type ||= element.sub_type
57
57
  end
58
-
58
+
59
59
  def string
60
60
  "#{main_type}/#{sub_type}"
61
61
  end
62
-
62
+
63
63
  def default
64
64
  decoded
65
65
  end
66
-
66
+
67
67
  alias :content_type :string
68
-
68
+
69
69
  def parameters
70
70
  unless @parameters
71
71
  @parameters = ParameterHash.new
@@ -77,7 +77,7 @@ module Mail
77
77
  def ContentTypeField.with_boundary(type)
78
78
  new("#{type}; boundary=#{generate_boundary}")
79
79
  end
80
-
80
+
81
81
  def ContentTypeField.generate_boundary
82
82
  "--==_mimepart_#{Mail.random_tag}"
83
83
  end
@@ -89,7 +89,7 @@ module Mail
89
89
  @value
90
90
  end
91
91
  end
92
-
92
+
93
93
  def stringify(params)
94
94
  params.map { |k,v| "#{k}=#{Encodings.param_encode(v)}" }.join("; ")
95
95
  end
@@ -100,22 +100,22 @@ module Mail
100
100
  @filename = parameters['filename']
101
101
  when parameters['name']
102
102
  @filename = parameters['name']
103
- else
103
+ else
104
104
  @filename = nil
105
105
  end
106
106
  @filename
107
107
  end
108
-
108
+
109
109
  # TODO: Fix this up
110
110
  def encoded
111
111
  if parameters.length > 0
112
- p = ";\r\n\s#{parameters.encoded}\r\n"
112
+ p = ";\r\n\s#{parameters.encoded}"
113
113
  else
114
114
  p = ""
115
115
  end
116
- "#{CAPITALIZED_FIELD}: #{content_type}" + p
116
+ "#{CAPITALIZED_FIELD}: #{content_type}#{p}\r\n"
117
117
  end
118
-
118
+
119
119
  def decoded
120
120
  if parameters.length > 0
121
121
  p = "; #{parameters.decoded}"
@@ -126,24 +126,37 @@ module Mail
126
126
  end
127
127
 
128
128
  private
129
-
129
+
130
130
  def method_missing(name, *args, &block)
131
- if name.to_s =~ /([\w_]+)=/
131
+ if name.to_s =~ /(\w+)=/
132
132
  self.parameters[$1] = args.first
133
133
  @value = "#{content_type}; #{stringify(parameters)}"
134
134
  else
135
135
  super
136
136
  end
137
137
  end
138
-
138
+
139
139
  # Various special cases from random emails found that I am not going to change
140
140
  # the parser for
141
141
  def sanatize( val )
142
+
143
+ # TODO: check if there are cases where whitespace is not a separator
144
+ val = val.tr(' ',';').
145
+ squeeze(';').
146
+ gsub(';', '; '). #use '; ' as a separator (or EOL)
147
+ gsub(/;\s*$/,'') #remove trailing to keep examples below
148
+
149
+ if val =~ /(boundary=(\S*))/i
150
+ val = "#{$`.downcase}boundary=#{$2}#{$'.downcase}"
151
+ else
152
+ val.downcase!
153
+ end
154
+
142
155
  case
143
- when val.chomp =~ /^\s*([\w\d\-_]+)\/([\w\d\-_]+)\s*;;+(.*)$/i
156
+ when val.chomp =~ /^\s*([\w\-]+)\/([\w\-]+)\s*;;+(.*)$/i
144
157
  # Handles 'text/plain;; format="flowed"' (double semi colon)
145
158
  "#{$1}/#{$2}; #{$3}"
146
- when val.chomp =~ /^\s*([\w\d\-_]+)\/([\w\d\-_]+)\s*;(ISO[\w\d\-_]+)$/i
159
+ when val.chomp =~ /^\s*([\w\-]+)\/([\w\-]+)\s*;\s?(ISO[\w\-]+)$/i
147
160
  # Microsoft helper:
148
161
  # Handles 'type/subtype;ISO-8559-1'
149
162
  "#{$1}/#{$2}; charset=#{quote_atom($3)}"
@@ -153,10 +166,10 @@ module Mail
153
166
  when val.chomp =~ /^(\w+);\s(.*)$/i
154
167
  # Handles 'text; <parameters>'
155
168
  "text/plain; #{$2}"
156
- when val =~ /([\w\d\-_]+\/[\w\d\-_]+);\scharset="charset="(\w+)""/i
169
+ when val =~ /([\w\-]+\/[\w\-]+);\scharset="charset="(\w+)""/i
157
170
  # Handles text/html; charset="charset="GB2312""
158
171
  "#{$1}; charset=#{quote_atom($2)}"
159
- when val =~ /([\w\d\-_]+\/[\w\d\-_]+);\s+(.*)/i
172
+ when val =~ /([\w\-]+\/[\w\-]+);\s+(.*)/i
160
173
  type = $1
161
174
  # Handles misquoted param values
162
175
  # e.g: application/octet-stream; name=archiveshelp1[1].htm
@@ -172,12 +185,12 @@ module Mail
172
185
  ''
173
186
  end
174
187
  end
175
-
188
+
176
189
  def get_mime_type( val )
177
190
  case
178
- when val =~ /^([\w\d\-_]+)\/([\w\d\-_]+);.+$/i
191
+ when val =~ /^([\w\-]+)\/([\w\-]+);.+$/i
179
192
  "#{$1}/#{$2}"
180
- else
193
+ else
181
194
  'text/plain'
182
195
  end
183
196
  end
@@ -34,13 +34,15 @@ module Mail
34
34
  def initialize(value = nil, charset = 'utf-8')
35
35
  self.charset = charset
36
36
  if value.blank?
37
- value = Time.now.strftime('%a, %d %b %Y %H:%M:%S %z')
37
+ value = ::DateTime.now.strftime('%a, %d %b %Y %H:%M:%S %z')
38
38
  else
39
39
  value = strip_field(FIELD_NAME, value)
40
40
  value.to_s.gsub!(/\(.*?\)/, '')
41
41
  value = ::DateTime.parse(value.to_s.squeeze(" ")).strftime('%a, %d %b %Y %H:%M:%S %z')
42
42
  end
43
43
  super(CAPITALIZED_FIELD, value, charset)
44
+ rescue ArgumentError => e
45
+ raise e unless "invalid date"==e.message
44
46
  end
45
47
 
46
48
  def encoded
@@ -52,15 +52,23 @@ module Mail
52
52
  end
53
53
 
54
54
  def formatted_date
55
- date_time.strftime("%a, %d %b %Y %H:%M:%S ") + date_time.zone.delete(':')
55
+ date_time.strftime("%a, %d %b %Y %H:%M:%S ") + date_time.zone.delete(':')
56
56
  end
57
57
 
58
58
  def encoded
59
- "#{CAPITALIZED_FIELD}: #{info}; #{formatted_date}\r\n"
59
+ if value.blank?
60
+ "#{CAPITALIZED_FIELD}: \r\n"
61
+ else
62
+ "#{CAPITALIZED_FIELD}: #{info}; #{formatted_date}\r\n"
63
+ end
60
64
  end
61
65
 
62
66
  def decoded
63
- "#{info}; #{formatted_date}"
67
+ if value.blank?
68
+ ""
69
+ else
70
+ "#{info}; #{formatted_date}"
71
+ end
64
72
  end
65
73
 
66
74
  end
@@ -14,7 +14,7 @@ module Mail
14
14
  def initialize(value = nil, charset = 'utf-8')
15
15
  self.charset = charset
16
16
  if value.blank?
17
- value = Time.now.strftime('%a, %d %b %Y %H:%M:%S %z')
17
+ value = ::DateTime.now.strftime('%a, %d %b %Y %H:%M:%S %z')
18
18
  else
19
19
  value = strip_field(FIELD_NAME, value)
20
20
  value = ::DateTime.parse(value.to_s).strftime('%a, %d %b %Y %H:%M:%S %z')
@@ -38,6 +38,7 @@ module Mail
38
38
  CAPITALIZED_FIELD = 'Return-Path'
39
39
 
40
40
  def initialize(value = nil, charset = 'utf-8')
41
+ value = nil if value == '<>'
41
42
  self.charset = charset
42
43
  super(CAPITALIZED_FIELD, strip_field(FIELD_NAME, value), charset)
43
44
  self.parse
@@ -71,7 +71,9 @@ module Mail
71
71
  end
72
72
 
73
73
  def do_decode
74
- value.blank? ? nil : Encodings.decode_encode(value, :decode)
74
+ result = value.blank? ? nil : Encodings.decode_encode(value, :decode)
75
+ result.encode!(value.encoding || "UTF-8") if RUBY_VERSION >= '1.9' && !result.blank?
76
+ result
75
77
  end
76
78
 
77
79
  # 2.2.3. Long Header Fields
@@ -164,6 +166,7 @@ module Mail
164
166
  end
165
167
 
166
168
  def encode(value)
169
+ value.encode!(charset) if defined?(Encoding) && charset
167
170
  (value.not_ascii_only? ? [value].pack("M").gsub("=\n", '') : value).gsub("\r", "=0D").gsub("\n", "=0A")
168
171
  end
169
172
 
data/lib/mail/header.rb CHANGED
@@ -73,7 +73,8 @@ module Mail
73
73
  # h.fields = ['From: mikel@me.com', 'To: bob@you.com']
74
74
  def fields=(unfolded_fields)
75
75
  @fields = Mail::FieldList.new
76
- unfolded_fields.each do |field|
76
+ warn "Warning: more than 1000 header fields only using the first 1000" if unfolded_fields.length > 1000
77
+ unfolded_fields[0..1000].each do |field|
77
78
 
78
79
  field = Field.new(field, nil, charset)
79
80
  field.errors.each { |error| self.errors << error }
@@ -161,16 +162,18 @@ module Mail
161
162
  end
162
163
 
163
164
  def charset
164
- if self[:content_type] && self[:content_type].parameters
165
- self[:content_type].parameters[:charset]
165
+ params = self[:content_type].parameters rescue nil
166
+ if params
167
+ params[:charset]
166
168
  else
167
169
  @charset
168
170
  end
169
171
  end
170
172
 
171
173
  def charset=(val)
172
- if self[:content_type]
173
- self[:content_type].parameters[:charset] = val
174
+ params = self[:content_type].parameters rescue nil
175
+ if params
176
+ params[:charset] = val
174
177
  end
175
178
  @charset = val
176
179
  end
data/lib/mail/mail.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
  module Mail
3
-
3
+
4
4
  # Allows you to create a new Mail::Message object.
5
5
  #
6
6
  # You can make an email via passing a string or passing a block.
@@ -10,11 +10,11 @@ module Mail
10
10
  #
11
11
  # Creating via a string:
12
12
  #
13
- # string = 'To: mikel@test.lindsaar.net\r\n'
14
- # string << 'From: bob@test.lindsaar.net\r\n\r\n'
15
- # string << 'Subject: This is an email\r\n'
16
- # string << '\r\n'
17
- # string << 'This is the body'
13
+ # string = "To: mikel@test.lindsaar.net\r\n"
14
+ # string << "From: bob@test.lindsaar.net\r\n"
15
+ # string << "Subject: This is an email\r\n"
16
+ # string << "\r\n"
17
+ # string << "This is the body"
18
18
  # Mail.new(string)
19
19
  #
20
20
  # Or creating via a block:
@@ -30,8 +30,8 @@ module Mail
30
30
  #
31
31
  # message = Mail.new({:to => 'mikel@test.lindsaar.net',
32
32
  # 'from' => 'bob@test.lindsaar.net',
33
- # :subject 'This is an email',
34
- # :body 'This is the body' })
33
+ # :subject => 'This is an email',
34
+ # :body => 'This is the body' })
35
35
  #
36
36
  # Note, the hash keys can be strings or symbols, the passed in object
37
37
  # does not need to be a hash, it just needs to respond to :each_pair
@@ -46,8 +46,8 @@ module Mail
46
46
  # mail[:from] = 'bob@test.lindsaar.net'
47
47
  # mail['subject'] = 'This is an email'
48
48
  # mail.body = 'This is the body'
49
- def Mail.new(*args, &block)
50
- Mail::Message.new(args, &block)
49
+ def self.new(*args, &block)
50
+ Message.new(args, &block)
51
51
  end
52
52
 
53
53
  # Sets the default delivery method and retriever method for all new Mail objects.
@@ -102,22 +102,22 @@ module Mail
102
102
  # The passed in hash is just merged against the defaults with +merge!+ and the result
103
103
  # assigned the mail object. So the above example will change only the :address value
104
104
  # of the global smtp_settings to be 'some.host', keeping all other values
105
- def Mail.defaults(&block)
106
- Mail::Configuration.instance.instance_eval(&block)
105
+ def self.defaults(&block)
106
+ Configuration.instance.instance_eval(&block)
107
107
  end
108
-
108
+
109
109
  # Returns the delivery method selected, defaults to an instance of Mail::SMTP
110
- def Mail.delivery_method
111
- Mail::Configuration.instance.delivery_method
110
+ def self.delivery_method
111
+ Configuration.instance.delivery_method
112
112
  end
113
113
 
114
114
  # Returns the retriever method selected, defaults to an instance of Mail::POP3
115
- def Mail.retriever_method
116
- Mail::Configuration.instance.retriever_method
115
+ def self.retriever_method
116
+ Configuration.instance.retriever_method
117
117
  end
118
118
 
119
119
  # Send an email using the default configuration. You do need to set a default
120
- # configuration first before you use Mail.deliver, if you don't, an appropriate
120
+ # configuration first before you use self.deliver, if you don't, an appropriate
121
121
  # error will be raised telling you to.
122
122
  #
123
123
  # If you do not specify a delivery type, SMTP will be used.
@@ -135,58 +135,72 @@ module Mail
135
135
  # mail.deliver!
136
136
  #
137
137
  # And your email object will be created and sent.
138
- def Mail.deliver(*args, &block)
139
- mail = Mail.new(args, &block)
138
+ def self.deliver(*args, &block)
139
+ mail = self.new(args, &block)
140
140
  mail.deliver
141
141
  mail
142
142
  end
143
143
 
144
- # Find emails in a POP3 server.
145
- # See Mail::POP3 for a complete documentation.
146
- def Mail.find(*args, &block)
144
+ # Find emails from the default retriever
145
+ # See Mail::Retriever for a complete documentation.
146
+ def self.find(*args, &block)
147
147
  retriever_method.find(*args, &block)
148
148
  end
149
149
 
150
- # Receive the first email(s) from a Pop3 server.
151
- # See Mail::POP3 for a complete documentation.
152
- def Mail.first(*args, &block)
150
+ # Finds and then deletes retrieved emails from the default retriever
151
+ # See Mail::Retriever for a complete documentation.
152
+ def self.find_and_delete(*args, &block)
153
+ retriever_method.find_and_delete(*args, &block)
154
+ end
155
+
156
+ # Receive the first email(s) from the default retriever
157
+ # See Mail::Retriever for a complete documentation.
158
+ def self.first(*args, &block)
153
159
  retriever_method.first(*args, &block)
154
160
  end
155
161
 
156
- # Receive the first email(s) from a Pop3 server.
157
- # See Mail::POP3 for a complete documentation.
158
- def Mail.last(*args, &block)
162
+ # Receive the first email(s) from the default retriever
163
+ # See Mail::Retriever for a complete documentation.
164
+ def self.last(*args, &block)
159
165
  retriever_method.last(*args, &block)
160
166
  end
161
167
 
162
- # Receive all emails from a POP3 server.
163
- # See Mail::POP3 for a complete documentation.
164
- def Mail.all(*args, &block)
168
+ # Receive all emails from the default retriever
169
+ # See Mail::Retriever for a complete documentation.
170
+ def self.all(*args, &block)
165
171
  retriever_method.all(*args, &block)
166
172
  end
167
173
 
168
174
  # Reads in an email message from a path and instantiates it as a new Mail::Message
169
- def Mail.read(filename)
170
- Mail.new(File.read(filename))
175
+ def self.read(filename)
176
+ self.new(File.open(filename, 'rb') { |f| f.read })
171
177
  end
172
-
173
- # Delete all emails from a POP3 server.
174
- # See Mail::POP3 for a complete documentation.
175
- def Mail.delete_all(*args, &block)
178
+
179
+ # Delete all emails from the default retriever
180
+ # See Mail::Retriever for a complete documentation.
181
+ def self.delete_all(*args, &block)
176
182
  retriever_method.delete_all(*args, &block)
177
183
  end
178
-
179
-
184
+
185
+ # Instantiates a new Mail::Message using a string
186
+ def Mail.read_from_string(mail_as_string)
187
+ Mail.new(mail_as_string)
188
+ end
189
+
190
+ def Mail.connection(&block)
191
+ retriever_method.connection(&block)
192
+ end
193
+
180
194
  # Initialize the observers and interceptors arrays
181
195
  @@delivery_notification_observers = []
182
196
  @@delivery_interceptors = []
183
-
197
+
184
198
  # You can register an object to be informed of every email that is sent through
185
199
  # this method.
186
200
  #
187
201
  # Your object needs to respond to a single method #delivered_email(mail)
188
202
  # which receives the email that is sent.
189
- def Mail.register_observer(observer)
203
+ def self.register_observer(observer)
190
204
  unless @@delivery_notification_observers.include?(observer)
191
205
  @@delivery_notification_observers << observer
192
206
  end
@@ -199,43 +213,43 @@ module Mail
199
213
  # Your object needs to respond to a single method #delivering_email(mail)
200
214
  # which receives the email that is about to be sent. Make your modifications
201
215
  # directly to this object.
202
- def Mail.register_interceptor(interceptor)
216
+ def self.register_interceptor(interceptor)
203
217
  unless @@delivery_interceptors.include?(interceptor)
204
218
  @@delivery_interceptors << interceptor
205
219
  end
206
220
  end
207
-
208
- def Mail.inform_observers(mail)
221
+
222
+ def self.inform_observers(mail)
209
223
  @@delivery_notification_observers.each do |observer|
210
224
  observer.delivered_email(mail)
211
225
  end
212
226
  end
213
-
214
- def Mail.inform_interceptors(mail)
227
+
228
+ def self.inform_interceptors(mail)
215
229
  @@delivery_interceptors.each do |interceptor|
216
230
  interceptor.delivering_email(mail)
217
231
  end
218
232
  end
219
233
 
220
234
  protected
221
-
222
- def Mail.random_tag
235
+
236
+ def self.random_tag
223
237
  t = Time.now
224
238
  sprintf('%x%x_%x%x%d%x',
225
239
  t.to_i, t.tv_usec,
226
- $$, Thread.current.object_id.abs, Mail.uniq, rand(255))
240
+ $$, Thread.current.object_id.abs, self.uniq, rand(255))
227
241
  end
228
-
242
+
229
243
  private
230
244
 
231
- def Mail.something_random
245
+ def self.something_random
232
246
  (Thread.current.object_id * rand(255) / Time.now.to_f).to_s.slice(-3..-1).to_i
233
247
  end
234
-
235
- def Mail.uniq
248
+
249
+ def self.uniq
236
250
  @@uniq += 1
237
251
  end
238
-
239
- @@uniq = Mail.something_random
240
-
252
+
253
+ @@uniq = self.something_random
254
+
241
255
  end