mail 2.2.5.1 → 2.2.5.2

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.

Potentially problematic release.


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

Files changed (115) hide show
  1. data/CHANGELOG.rdoc +18 -0
  2. data/lib/VERSION +1 -1
  3. data/lib/mail.rb +2 -2
  4. data/lib/mail/body.rb +0 -1
  5. data/lib/mail/field_list.rb +1 -1
  6. data/lib/mail/fields/content_disposition_field.rb +1 -1
  7. data/lib/mail/fields/content_type_field.rb +36 -23
  8. data/lib/mail/mail.rb +55 -51
  9. data/lib/mail/message.rb +405 -375
  10. data/lib/mail/network/retriever_methods/pop3.rb +1 -1
  11. data/lib/mail/part.rb +1 -1
  12. data/lib/mail/patterns.rb +4 -0
  13. data/lib/mail/version.rb +10 -8
  14. data/lib/mail/version_specific/ruby_1_8.rb +1 -1
  15. data/lib/mail/version_specific/ruby_1_9.rb +1 -1
  16. metadata +3 -102
  17. data/lib/mail.rbc +0 -1151
  18. data/lib/mail/attachments_list.rbc +0 -1983
  19. data/lib/mail/body.rbc +0 -3809
  20. data/lib/mail/configuration.rbc +0 -1112
  21. data/lib/mail/core_extensions/nil.rbc +0 -244
  22. data/lib/mail/core_extensions/string.rbc +0 -0
  23. data/lib/mail/elements.rbc +0 -362
  24. data/lib/mail/elements/address.rbc +0 -4112
  25. data/lib/mail/elements/address_list.rbc +0 -1309
  26. data/lib/mail/elements/content_disposition_element.rbc +0 -701
  27. data/lib/mail/elements/content_location_element.rbc +0 -573
  28. data/lib/mail/elements/content_transfer_encoding_element.rbc +0 -535
  29. data/lib/mail/elements/content_type_element.rbc +0 -786
  30. data/lib/mail/elements/date_time_element.rbc +0 -583
  31. data/lib/mail/elements/envelope_from_element.rbc +0 -771
  32. data/lib/mail/elements/message_ids_element.rbc +0 -740
  33. data/lib/mail/elements/mime_version_element.rbc +0 -583
  34. data/lib/mail/elements/phrase_list.rbc +0 -562
  35. data/lib/mail/elements/received_element.rbc +0 -725
  36. data/lib/mail/encodings.rbc +0 -0
  37. data/lib/mail/encodings/7bit.rbc +0 -538
  38. data/lib/mail/encodings/8bit.rbc +0 -541
  39. data/lib/mail/encodings/base64.rbc +0 -629
  40. data/lib/mail/encodings/binary.rbc +0 -529
  41. data/lib/mail/encodings/quoted_printable.rbc +0 -766
  42. data/lib/mail/encodings/transfer_encoding.rbc +0 -1134
  43. data/lib/mail/envelope.rbc +0 -719
  44. data/lib/mail/field.rbc +0 -4708
  45. data/lib/mail/field_list.rbc +0 -518
  46. data/lib/mail/fields.rbc +0 -782
  47. data/lib/mail/fields/bcc_field.rbc +0 -564
  48. data/lib/mail/fields/cc_field.rbc +0 -579
  49. data/lib/mail/fields/comments_field.rbc +0 -383
  50. data/lib/mail/fields/common/address_container.rbc +0 -363
  51. data/lib/mail/fields/common/common_address.rbc +0 -3550
  52. data/lib/mail/fields/common/common_date.rbc +0 -908
  53. data/lib/mail/fields/common/common_field.rbc +0 -973
  54. data/lib/mail/fields/common/common_message_id.rbc +0 -1051
  55. data/lib/mail/fields/common/parameter_hash.rbc +0 -1335
  56. data/lib/mail/fields/content_description_field.rbc +0 -396
  57. data/lib/mail/fields/content_disposition_field.rbc +0 -1440
  58. data/lib/mail/fields/content_id_field.rbc +0 -1236
  59. data/lib/mail/fields/content_location_field.rbc +0 -892
  60. data/lib/mail/fields/content_transfer_encoding_field.rbc +0 -1184
  61. data/lib/mail/fields/content_type_field.rbc +0 -3958
  62. data/lib/mail/fields/date_field.rbc +0 -712
  63. data/lib/mail/fields/from_field.rbc +0 -579
  64. data/lib/mail/fields/in_reply_to_field.rbc +0 -579
  65. data/lib/mail/fields/keywords_field.rbc +0 -979
  66. data/lib/mail/fields/message_id_field.rbc +0 -1008
  67. data/lib/mail/fields/mime_version_field.rbc +0 -1107
  68. data/lib/mail/fields/optional_field.rbc +0 -153
  69. data/lib/mail/fields/received_field.rbc +0 -1137
  70. data/lib/mail/fields/references_field.rbc +0 -574
  71. data/lib/mail/fields/reply_to_field.rbc +0 -579
  72. data/lib/mail/fields/resent_bcc_field.rbc +0 -579
  73. data/lib/mail/fields/resent_cc_field.rbc +0 -579
  74. data/lib/mail/fields/resent_date_field.rbc +0 -656
  75. data/lib/mail/fields/resent_from_field.rbc +0 -579
  76. data/lib/mail/fields/resent_message_id_field.rbc +0 -639
  77. data/lib/mail/fields/resent_sender_field.rbc +0 -731
  78. data/lib/mail/fields/resent_to_field.rbc +0 -579
  79. data/lib/mail/fields/return_path_field.rbc +0 -737
  80. data/lib/mail/fields/sender_field.rbc +0 -799
  81. data/lib/mail/fields/structured_field.rbc +0 -671
  82. data/lib/mail/fields/subject_field.rbc +0 -378
  83. data/lib/mail/fields/to_field.rbc +0 -579
  84. data/lib/mail/fields/unstructured_field.rbc +0 -2292
  85. data/lib/mail/header.rbc +0 -3720
  86. data/lib/mail/mail.rbc +0 -2168
  87. data/lib/mail/message.rbc +0 -19034
  88. data/lib/mail/network.rbc +0 -236
  89. data/lib/mail/network/delivery_methods/file_delivery.rbc +0 -722
  90. data/lib/mail/network/delivery_methods/sendmail.rbc +0 -800
  91. data/lib/mail/network/delivery_methods/smtp.rbc +0 -1081
  92. data/lib/mail/network/delivery_methods/test_mailer.rbc +0 -552
  93. data/lib/mail/network/retriever_methods/pop3.rbc +0 -2447
  94. data/lib/mail/parsers/address_lists.rbc +0 -1307
  95. data/lib/mail/parsers/content_disposition.rbc +0 -5968
  96. data/lib/mail/parsers/content_location.rbc +0 -2166
  97. data/lib/mail/parsers/content_transfer_encoding.rbc +0 -2591
  98. data/lib/mail/parsers/content_type.rbc +0 -7949
  99. data/lib/mail/parsers/date_time.rbc +0 -1836
  100. data/lib/mail/parsers/envelope_from.rbc +0 -3106
  101. data/lib/mail/parsers/message_ids.rbc +0 -989
  102. data/lib/mail/parsers/mime_version.rbc +0 -2254
  103. data/lib/mail/parsers/phrase_lists.rbc +0 -989
  104. data/lib/mail/parsers/received.rbc +0 -1267
  105. data/lib/mail/parsers/rfc2045.rbc +0 -5614
  106. data/lib/mail/parsers/rfc2822.rbc +0 -74848
  107. data/lib/mail/parsers/rfc2822_obsolete.rbc +0 -55220
  108. data/lib/mail/part.rbc +0 -2314
  109. data/lib/mail/parts_list.rbc +0 -832
  110. data/lib/mail/patterns.rbc +0 -0
  111. data/lib/mail/utilities.rbc +0 -2377
  112. data/lib/mail/version.rbc +0 -450
  113. data/lib/mail/version_specific/ruby_1_8.rbc +0 -2496
  114. data/lib/tasks/corpus.rake.compiled.rbc +0 -2195
  115. data/lib/tasks/treetop.rake.compiled.rbc +0 -297
data/lib/mail/message.rb CHANGED
@@ -2,40 +2,40 @@
2
2
  module Mail
3
3
  # The Message class provides a single point of access to all things to do with an
4
4
  # email message.
5
- #
5
+ #
6
6
  # You create a new email message by calling the Mail::Message.new method, or just
7
7
  # Mail.new
8
- #
8
+ #
9
9
  # A Message object by default has the following objects inside it:
10
- #
10
+ #
11
11
  # * A Header object which contians all information and settings of the header of the email
12
12
  # * Body object which contains all parts of the email that are not part of the header, this
13
13
  # includes any attachments, body text, MIME parts etc.
14
- #
14
+ #
15
15
  # ==Per RFC2822
16
- #
16
+ #
17
17
  # 2.1. General Description
18
- #
18
+ #
19
19
  # At the most basic level, a message is a series of characters. A
20
20
  # message that is conformant with this standard is comprised of
21
21
  # characters with values in the range 1 through 127 and interpreted as
22
22
  # US-ASCII characters [ASCII]. For brevity, this document sometimes
23
23
  # refers to this range of characters as simply "US-ASCII characters".
24
- #
24
+ #
25
25
  # Note: This standard specifies that messages are made up of characters
26
26
  # in the US-ASCII range of 1 through 127. There are other documents,
27
27
  # specifically the MIME document series [RFC2045, RFC2046, RFC2047,
28
28
  # RFC2048, RFC2049], that extend this standard to allow for values
29
29
  # outside of that range. Discussion of those mechanisms is not within
30
30
  # the scope of this standard.
31
- #
31
+ #
32
32
  # Messages are divided into lines of characters. A line is a series of
33
33
  # characters that is delimited with the two characters carriage-return
34
34
  # and line-feed; that is, the carriage return (CR) character (ASCII
35
35
  # value 13) followed immediately by the line feed (LF) character (ASCII
36
36
  # value 10). (The carriage-return/line-feed pair is usually written in
37
37
  # this document as "CRLF".)
38
- #
38
+ #
39
39
  # A message consists of header fields (collectively called "the header
40
40
  # of the message") followed, optionally, by a body. The header is a
41
41
  # sequence of lines of characters with special syntax as defined in
@@ -43,74 +43,77 @@ module Mail
43
43
  # follows the header and is separated from the header by an empty line
44
44
  # (i.e., a line with nothing preceding the CRLF).
45
45
  class Message
46
-
46
+
47
47
  include Patterns
48
48
  include Utilities
49
49
 
50
50
  # ==Making an email
51
- #
51
+ #
52
52
  # You can make an new mail object via a block, passing a string, file or direct assignment.
53
- #
53
+ #
54
54
  # ===Making an email via a block
55
- #
55
+ #
56
56
  # mail = Mail.new do
57
57
  # from 'mikel@test.lindsaar.net'
58
58
  # to 'you@test.lindsaar.net'
59
59
  # subject 'This is a test email'
60
60
  # body File.read('body.txt')
61
61
  # end
62
- #
62
+ #
63
63
  # mail.to_s #=> "From: mikel@test.lindsaar.net\r\nTo: you@...
64
64
  #
65
65
  # ===Making an email via passing a string
66
- #
66
+ #
67
67
  # mail = Mail.new("To: mikel@test.lindsaar.net\r\nSubject: Hello\r\n\r\nHi there!")
68
68
  # mail.body.to_s #=> 'Hi there!'
69
69
  # mail.subject #=> 'Hello'
70
70
  # mail.to #=> 'mikel@test.lindsaar.net'
71
- #
71
+ #
72
72
  # ===Making an email from a file
73
- #
73
+ #
74
74
  # mail = Mail.read('path/to/file.eml')
75
75
  # mail.body.to_s #=> 'Hi there!'
76
76
  # mail.subject #=> 'Hello'
77
77
  # mail.to #=> 'mikel@test.lindsaar.net'
78
- #
78
+ #
79
79
  # ===Making an email via assignment
80
- #
80
+ #
81
81
  # You can assign values to a mail object via four approaches:
82
- #
82
+ #
83
83
  # * Message#field_name=(value)
84
84
  # * Message#field_name(value)
85
85
  # * Message#['field_name']=(value)
86
86
  # * Message#[:field_name]=(value)
87
- #
87
+ #
88
88
  # Examples:
89
- #
89
+ #
90
90
  # mail = Mail.new
91
91
  # mail['from'] = 'mikel@test.lindsaar.net'
92
92
  # mail[:to] = 'you@test.lindsaar.net'
93
93
  # mail.subject 'This is a test email'
94
94
  # mail.body = 'This is a body'
95
- #
95
+ #
96
96
  # mail.to_s #=> "From: mikel@test.lindsaar.net\r\nTo: you@...
97
- #
97
+ #
98
98
  def initialize(*args, &block)
99
99
  @body = nil
100
+ @body_raw = nil
101
+ @body_raw_index = nil
102
+ @separate_parts = false
100
103
  @text_part = nil
101
104
  @html_part = nil
102
105
  @errors = nil
103
106
  @header = nil
104
107
  @charset = 'UTF-8'
105
108
  @defaulted_charset = true
106
-
109
+
107
110
  @perform_deliveries = true
108
111
  @raise_delivery_errors = true
109
112
 
110
113
  @delivery_handler = nil
111
-
114
+
112
115
  @delivery_method = Mail.delivery_method.dup
113
-
116
+
114
117
  @transport_encoding = Mail::Encodings.get_encoding('7bit')
115
118
 
116
119
  if args.flatten.first.respond_to?(:each_pair)
@@ -118,7 +121,7 @@ module Mail
118
121
  else
119
122
  init_with_string(args.flatten[0].to_s.strip)
120
123
  end
121
-
124
+
122
125
  if block_given?
123
126
  instance_eval(&block)
124
127
  end
@@ -127,12 +130,12 @@ module Mail
127
130
  end
128
131
 
129
132
  # If you assign a delivery handler, mail will call :deliver_mail on the
130
- # object you assign to delivery_handler, it will pass itself as the
133
+ # object you assign to delivery_handler, it will pass itself as the
131
134
  # single argument.
132
- #
135
+ #
133
136
  # If you define a delivery_handler, then you are responsible for the
134
137
  # following actions in the delivery cycle:
135
- #
138
+ #
136
139
  # * Appending the mail object to Mail.deliveries as you see fit.
137
140
  # * Checking the mail.perform_deliveries flag to decide if you should
138
141
  # actually call :deliver! the mail object or not.
@@ -140,28 +143,28 @@ module Mail
140
143
  # should raise delivery errors if they occur.
141
144
  # * Actually calling :deliver! (with the bang) on the mail object to
142
145
  # get it to deliver itself.
143
- #
146
+ #
144
147
  # A simplest implementation of a delivery_handler would be
145
- #
148
+ #
146
149
  # class MyObject
147
150
  #
148
151
  # def initialize
149
152
  # @mail = Mail.new('To: mikel@test.lindsaar.net')
150
153
  # @mail.delivery_handler = self
151
154
  # end
152
- #
155
+ #
153
156
  # attr_accessor :mail
154
- #
157
+ #
155
158
  # def deliver_mail(mail)
156
159
  # yield
157
160
  # end
158
161
  # end
159
- #
162
+ #
160
163
  # Then doing:
161
- #
164
+ #
162
165
  # obj = MyObject.new
163
166
  # obj.mail.deliver
164
- #
167
+ #
165
168
  # Would cause Mail to call obj.deliver_mail passing itself as a parameter,
166
169
  # which then can just yield and let Mail do it's own private do_delivery
167
170
  # method.
@@ -176,24 +179,24 @@ module Mail
176
179
  # mail.perform_deliveries = false
177
180
  # mail.deliver # Mail::SMTP not called here
178
181
  # Mail.deliveries.size #=> 0
179
- #
182
+ #
180
183
  # If you want to test and query the Mail.deliveries collection to see what
181
184
  # mail you sent, you should set perform_deliveries to true and use
182
185
  # the :test mail delivery_method:
183
- #
186
+ #
184
187
  # Mail.deliveries.size #=> 0
185
188
  # mail.delivery_method :test
186
189
  # mail.perform_deliveries = true
187
190
  # mail.deliver
188
191
  # Mail.deliveries.size #=> 1
189
- #
192
+ #
190
193
  # This setting is ignored by mail (though still available as a flag) if you
191
194
  # define a delivery_handler
192
195
  attr_accessor :perform_deliveries
193
196
 
194
197
  # If set to false, mail will silently catch and ignore any exceptions
195
198
  # raised through attempting to deliver an email.
196
- #
199
+ #
197
200
  # This setting is ignored by mail (though still available as a flag) if you
198
201
  # define a delivery_handler
199
202
  attr_accessor :raise_delivery_errors
@@ -202,19 +205,19 @@ module Mail
202
205
  STDERR.puts("Message#register_for_delivery_notification is deprecated, please call Mail.register_observer instead")
203
206
  Mail.register_observer(observer)
204
207
  end
205
-
208
+
206
209
  def inform_observers
207
210
  Mail.inform_observers(self)
208
211
  end
209
-
212
+
210
213
  def inform_interceptors
211
214
  Mail.inform_interceptors(self)
212
215
  end
213
-
216
+
214
217
  # Delivers an mail object.
215
- #
218
+ #
216
219
  # Examples:
217
- #
220
+ #
218
221
  # mail = Mail.read('file.eml')
219
222
  # mail.deliver
220
223
  def deliver
@@ -228,33 +231,33 @@ module Mail
228
231
  self
229
232
  end
230
233
 
231
- # This method bypasses checking perform_deliveries and raise_delivery_errors,
234
+ # This method bypasses checking perform_deliveries and raise_delivery_errors,
232
235
  # so use with caution.
233
- #
236
+ #
234
237
  # It still however fires callbacks to the observers if they are defined.
235
- #
238
+ #
236
239
  # Returns self
237
240
  def deliver!
238
241
  delivery_method.deliver!(self)
239
242
  inform_observers
240
243
  self
241
244
  end
242
-
245
+
243
246
  def delivery_method(method = nil, settings = {})
244
247
  unless method
245
248
  @delivery_method
246
249
  else
247
- @delivery_method = Mail::Configuration.instance.lookup_delivery_method(method).new(settings)
250
+ @delivery_method = Configuration.instance.lookup_delivery_method(method).new(settings)
248
251
  end
249
252
  end
250
-
253
+
251
254
  # Provides the operator needed for sort et al.
252
- #
255
+ #
253
256
  # Compares this mail object with another mail object, this is done by date, so an
254
257
  # email that is older than another will appear first.
255
- #
258
+ #
256
259
  # Example:
257
- #
260
+ #
258
261
  # mail1 = Mail.new do
259
262
  # date(Time.now)
260
263
  # end
@@ -269,41 +272,41 @@ module Mail
269
272
  self.date <=> other.date
270
273
  end
271
274
  end
272
-
275
+
273
276
  # Two emails are the same if they have the same fields and body contents. One
274
277
  # gotcha here is that Mail will insert Message-IDs when calling encoded, so doing
275
278
  # mail1.encoded == mail2.encoded is most probably not going to return what you think
276
279
  # as the assigned Message-IDs by Mail (if not already defined as the same) will ensure
277
280
  # that the two objects are unique, and this comparison will ALWAYS return false.
278
- #
281
+ #
279
282
  # So the == operator has been defined like so: Two messages are the same if they have
280
283
  # the same content, ignoring the Message-ID field, unless BOTH emails have a defined and
281
284
  # different Message-ID value, then they are false.
282
- #
285
+ #
283
286
  # So, in practice the == operator works like this:
284
- #
287
+ #
285
288
  # m1 = Mail.new("Subject: Hello\r\n\r\nHello")
286
289
  # m2 = Mail.new("Subject: Hello\r\n\r\nHello")
287
290
  # m1 == m2 #=> true
288
- #
291
+ #
289
292
  # m1 = Mail.new("Subject: Hello\r\n\r\nHello")
290
293
  # m2 = Mail.new("Message-ID: <1234@test>\r\nSubject: Hello\r\n\r\nHello")
291
294
  # m1 == m2 #=> true
292
- #
295
+ #
293
296
  # m1 = Mail.new("Message-ID: <1234@test>\r\nSubject: Hello\r\n\r\nHello")
294
297
  # m2 = Mail.new("Subject: Hello\r\n\r\nHello")
295
298
  # m1 == m2 #=> true
296
- #
299
+ #
297
300
  # m1 = Mail.new("Message-ID: <1234@test>\r\nSubject: Hello\r\n\r\nHello")
298
301
  # m2 = Mail.new("Message-ID: <1234@test>\r\nSubject: Hello\r\n\r\nHello")
299
302
  # m1 == m2 #=> true
300
- #
303
+ #
301
304
  # m1 = Mail.new("Message-ID: <1234@test>\r\nSubject: Hello\r\n\r\nHello")
302
305
  # m2 = Mail.new("Message-ID: <DIFFERENT@test>\r\nSubject: Hello\r\n\r\nHello")
303
306
  # m1 == m2 #=> false
304
307
  def ==(other)
305
308
  return false unless other.respond_to?(:encoded)
306
-
309
+
307
310
  if self.message_id && other.message_id
308
311
  result = (self.encoded == other.encoded)
309
312
  else
@@ -315,44 +318,44 @@ module Mail
315
318
  result
316
319
  end
317
320
  end
318
-
321
+
319
322
  # Provides access to the raw source of the message as it was when it
320
323
  # was instantiated. This is set at initialization and so is untouched
321
324
  # by the parsers or decoder / encoders
322
325
  #
323
326
  # Example:
324
- #
327
+ #
325
328
  # mail = Mail.new('This is an invalid email message')
326
329
  # mail.raw_source #=> "This is an invalid email message"
327
330
  def raw_source
328
331
  @raw_source
329
332
  end
330
-
333
+
331
334
  # Sets the envelope from for the email
332
335
  def set_envelope( val )
333
336
  @raw_envelope = val
334
337
  @envelope = Mail::Envelope.new( val )
335
338
  end
336
-
339
+
337
340
  # The raw_envelope is the From mikel@test.lindsaar.net Mon May 2 16:07:05 2009
338
341
  # type field that you can see at the top of any email that has come
339
342
  # from a mailbox
340
343
  def raw_envelope
341
344
  @raw_envelope
342
345
  end
343
-
346
+
344
347
  def envelope_from
345
348
  @envelope ? @envelope.from : nil
346
349
  end
347
-
350
+
348
351
  def envelope_date
349
352
  @envelope ? @envelope.date : nil
350
353
  end
351
-
354
+
352
355
  # Sets the header of the message object.
353
- #
356
+ #
354
357
  # Example:
355
- #
358
+ #
356
359
  # mail.header = 'To: mikel@test.lindsaar.net\r\nFrom: Bob@bob.com'
357
360
  # mail.header #=> <#Mail::Header
358
361
  def header=(value)
@@ -361,80 +364,80 @@ module Mail
361
364
 
362
365
  # Returns the header object of the message object. Or, if passed
363
366
  # a parameter sets the value.
364
- #
367
+ #
365
368
  # Example:
366
- #
369
+ #
367
370
  # mail = Mail::Message.new('To: mikel\r\nFrom: you')
368
371
  # mail.header #=> #<Mail::Header:0x13ce14 @raw_source="To: mikel\r\nFr...
369
- #
372
+ #
370
373
  # mail.header #=> nil
371
374
  # mail.header 'To: mikel\r\nFrom: you'
372
375
  # mail.header #=> #<Mail::Header:0x13ce14 @raw_source="To: mikel\r\nFr...
373
376
  def header(value = nil)
374
377
  value ? self.header = value : @header
375
378
  end
376
-
379
+
377
380
  # Provides a way to set custom headers, by passing in a hash
378
381
  def headers(hash = {})
379
382
  hash.each_pair do |k,v|
380
383
  header[k] = v
381
384
  end
382
385
  end
383
-
386
+
384
387
  # Returns a list of parser errors on the header, each field that had an error
385
388
  # will be reparsed as an unstructured field to preserve the data inside, but
386
389
  # will not be used for further processing.
387
- #
390
+ #
388
391
  # It returns a nested array of [field_name, value, original_error_message]
389
392
  # per error found.
390
- #
393
+ #
391
394
  # Example:
392
- #
395
+ #
393
396
  # message = Mail.new("Content-Transfer-Encoding: weirdo\r\n")
394
397
  # message.errors.size #=> 1
395
398
  # message.errors.first[0] #=> "Content-Transfer-Encoding"
396
399
  # message.errors.first[1] #=> "weirdo"
397
400
  # message.errors.first[3] #=> <The original error message exception>
398
- #
401
+ #
399
402
  # This is a good first defence on detecting spam by the way. Some spammers send
400
403
  # invalid emails to try and get email parsers to give up parsing them.
401
404
  def errors
402
405
  header.errors
403
406
  end
404
-
405
- # Returns the Bcc value of the mail object as an array of strings of
407
+
408
+ # Returns the Bcc value of the mail object as an array of strings of
406
409
  # address specs.
407
410
  #
408
411
  # Example:
409
- #
412
+ #
410
413
  # mail.bcc = 'Mikel <mikel@test.lindsaar.net>'
411
414
  # mail.bcc #=> ['mikel@test.lindsaar.net']
412
415
  # mail.bcc = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
413
416
  # mail.bcc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
414
- #
417
+ #
415
418
  # Also allows you to set the value by passing a value as a parameter
416
419
  #
417
420
  # Example:
418
- #
421
+ #
419
422
  # mail.bcc 'Mikel <mikel@test.lindsaar.net>'
420
423
  # mail.bcc #=> ['mikel@test.lindsaar.net']
421
- #
424
+ #
422
425
  # Additionally, you can append new addresses to the returned Array like
423
426
  # object.
424
- #
427
+ #
425
428
  # Example:
426
- #
429
+ #
427
430
  # mail.bcc 'Mikel <mikel@test.lindsaar.net>'
428
431
  # mail.bcc << 'ada@test.lindsaar.net'
429
432
  # mail.bcc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
430
433
  def bcc( val = nil )
431
434
  default :bcc, val
432
435
  end
433
-
436
+
434
437
  # Sets the Bcc value of the mail object, pass in a string of the field
435
438
  #
436
439
  # Example:
437
- #
440
+ #
438
441
  # mail.bcc = 'Mikel <mikel@test.lindsaar.net>'
439
442
  # mail.bcc #=> ['mikel@test.lindsaar.net']
440
443
  # mail.bcc = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
@@ -442,40 +445,40 @@ module Mail
442
445
  def bcc=( val )
443
446
  header[:bcc] = val
444
447
  end
445
-
446
- # Returns the Cc value of the mail object as an array of strings of
448
+
449
+ # Returns the Cc value of the mail object as an array of strings of
447
450
  # address specs.
448
451
  #
449
452
  # Example:
450
- #
453
+ #
451
454
  # mail.cc = 'Mikel <mikel@test.lindsaar.net>'
452
455
  # mail.cc #=> ['mikel@test.lindsaar.net']
453
456
  # mail.cc = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
454
457
  # mail.cc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
455
- #
458
+ #
456
459
  # Also allows you to set the value by passing a value as a parameter
457
460
  #
458
461
  # Example:
459
- #
462
+ #
460
463
  # mail.cc 'Mikel <mikel@test.lindsaar.net>'
461
464
  # mail.cc #=> ['mikel@test.lindsaar.net']
462
- #
465
+ #
463
466
  # Additionally, you can append new addresses to the returned Array like
464
467
  # object.
465
- #
468
+ #
466
469
  # Example:
467
- #
470
+ #
468
471
  # mail.cc 'Mikel <mikel@test.lindsaar.net>'
469
472
  # mail.cc << 'ada@test.lindsaar.net'
470
473
  # mail.cc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
471
474
  def cc( val = nil )
472
475
  default :cc, val
473
476
  end
474
-
477
+
475
478
  # Sets the Cc value of the mail object, pass in a string of the field
476
479
  #
477
480
  # Example:
478
- #
481
+ #
479
482
  # mail.cc = 'Mikel <mikel@test.lindsaar.net>'
480
483
  # mail.cc #=> ['mikel@test.lindsaar.net']
481
484
  # mail.cc = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
@@ -483,71 +486,71 @@ module Mail
483
486
  def cc=( val )
484
487
  header[:cc] = val
485
488
  end
486
-
489
+
487
490
  def comments( val = nil )
488
491
  default :comments, val
489
492
  end
490
-
493
+
491
494
  def comments=( val )
492
495
  header[:comments] = val
493
496
  end
494
-
497
+
495
498
  def content_description( val = nil )
496
499
  default :content_description, val
497
500
  end
498
-
501
+
499
502
  def content_description=( val )
500
503
  header[:content_description] = val
501
504
  end
502
-
505
+
503
506
  def content_disposition( val = nil )
504
507
  default :content_disposition, val
505
508
  end
506
-
509
+
507
510
  def content_disposition=( val )
508
511
  header[:content_disposition] = val
509
512
  end
510
-
513
+
511
514
  def content_id( val = nil )
512
515
  default :content_id, val
513
516
  end
514
-
517
+
515
518
  def content_id=( val )
516
519
  header[:content_id] = val
517
520
  end
518
-
521
+
519
522
  def content_location( val = nil )
520
523
  default :content_location, val
521
524
  end
522
-
525
+
523
526
  def content_location=( val )
524
527
  header[:content_location] = val
525
528
  end
526
-
529
+
527
530
  def content_transfer_encoding( val = nil )
528
531
  default :content_transfer_encoding, val
529
532
  end
530
-
533
+
531
534
  def content_transfer_encoding=( val )
532
535
  header[:content_transfer_encoding] = val
533
536
  end
534
-
537
+
535
538
  def content_type( val = nil )
536
539
  default :content_type, val
537
540
  end
538
-
541
+
539
542
  def content_type=( val )
540
543
  header[:content_type] = val
541
544
  end
542
-
545
+
543
546
  def date( val = nil )
544
547
  default :date, val
545
548
  end
546
-
549
+
547
550
  def date=( val )
548
551
  header[:date] = val
549
552
  end
550
-
553
+
551
554
  def transport_encoding( val = nil)
552
555
  if val
553
556
  self.transport_encoding = val
@@ -559,40 +562,40 @@ module Mail
559
562
  def transport_encoding=( val )
560
563
  @transport_encoding = Mail::Encodings.get_encoding(val)
561
564
  end
562
-
563
- # Returns the From value of the mail object as an array of strings of
565
+
566
+ # Returns the From value of the mail object as an array of strings of
564
567
  # address specs.
565
568
  #
566
569
  # Example:
567
- #
570
+ #
568
571
  # mail.from = 'Mikel <mikel@test.lindsaar.net>'
569
572
  # mail.from #=> ['mikel@test.lindsaar.net']
570
573
  # mail.from = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
571
574
  # mail.from #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
572
- #
575
+ #
573
576
  # Also allows you to set the value by passing a value as a parameter
574
577
  #
575
578
  # Example:
576
- #
579
+ #
577
580
  # mail.from 'Mikel <mikel@test.lindsaar.net>'
578
581
  # mail.from #=> ['mikel@test.lindsaar.net']
579
- #
582
+ #
580
583
  # Additionally, you can append new addresses to the returned Array like
581
584
  # object.
582
- #
585
+ #
583
586
  # Example:
584
- #
587
+ #
585
588
  # mail.from 'Mikel <mikel@test.lindsaar.net>'
586
589
  # mail.from << 'ada@test.lindsaar.net'
587
590
  # mail.from #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
588
591
  def from( val = nil )
589
592
  default :from, val
590
593
  end
591
-
594
+
592
595
  # Sets the From value of the mail object, pass in a string of the field
593
596
  #
594
597
  # Example:
595
- #
598
+ #
596
599
  # mail.from = 'Mikel <mikel@test.lindsaar.net>'
597
600
  # mail.from #=> ['mikel@test.lindsaar.net']
598
601
  # mail.from = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
@@ -600,76 +603,76 @@ module Mail
600
603
  def from=( val )
601
604
  header[:from] = val
602
605
  end
603
-
606
+
604
607
  def in_reply_to( val = nil )
605
608
  default :in_reply_to, val
606
609
  end
607
-
610
+
608
611
  def in_reply_to=( val )
609
612
  header[:in_reply_to] = val
610
613
  end
611
-
614
+
612
615
  def keywords( val = nil )
613
616
  default :keywords, val
614
617
  end
615
-
618
+
616
619
  def keywords=( val )
617
620
  header[:keywords] = val
618
621
  end
619
-
622
+
620
623
  # Returns the Message-ID of the mail object. Note, per RFC 2822 the Message ID
621
624
  # consists of what is INSIDE the < > usually seen in the mail header, so this method
622
625
  # will return only what is inside.
623
- #
626
+ #
624
627
  # Example:
625
- #
628
+ #
626
629
  # mail.message_id = '<1234@message.id>'
627
630
  # mail.message_id #=> '1234@message.id'
628
- #
631
+ #
629
632
  # Also allows you to set the Message-ID by passing a string as a parameter
630
- #
633
+ #
631
634
  # mail.message_id '<1234@message.id>'
632
635
  # mail.message_id #=> '1234@message.id'
633
636
  def message_id( val = nil )
634
637
  default :message_id, val
635
638
  end
636
-
639
+
637
640
  # Sets the Message-ID. Note, per RFC 2822 the Message ID consists of what is INSIDE
638
641
  # the < > usually seen in the mail header, so this method will return only what is inside.
639
- #
642
+ #
640
643
  # mail.message_id = '<1234@message.id>'
641
644
  # mail.message_id #=> '1234@message.id'
642
645
  def message_id=( val )
643
646
  header[:message_id] = val
644
647
  end
645
-
648
+
646
649
  # Returns the MIME version of the email as a string
647
- #
650
+ #
648
651
  # Example:
649
- #
652
+ #
650
653
  # mail.mime_version = '1.0'
651
654
  # mail.mime_version #=> '1.0'
652
- #
655
+ #
653
656
  # Also allows you to set the MIME version by passing a string as a parameter.
654
- #
657
+ #
655
658
  # Example:
656
- #
659
+ #
657
660
  # mail.mime_version '1.0'
658
661
  # mail.mime_version #=> '1.0'
659
662
  def mime_version( val = nil )
660
663
  default :mime_version, val
661
664
  end
662
-
665
+
663
666
  # Sets the MIME version of the email by accepting a string
664
- #
667
+ #
665
668
  # Example:
666
- #
669
+ #
667
670
  # mail.mime_version = '1.0'
668
671
  # mail.mime_version #=> '1.0'
669
672
  def mime_version=( val )
670
673
  header[:mime_version] = val
671
674
  end
672
-
675
+
673
676
  def received( val = nil )
674
677
  if val
675
678
  header[:received] = val
@@ -677,52 +680,52 @@ module Mail
677
680
  header[:received]
678
681
  end
679
682
  end
680
-
683
+
681
684
  def received=( val )
682
685
  header[:received] = val
683
686
  end
684
-
687
+
685
688
  def references( val = nil )
686
689
  default :references, val
687
690
  end
688
-
691
+
689
692
  def references=( val )
690
693
  header[:references] = val
691
694
  end
692
-
693
- # Returns the Reply-To value of the mail object as an array of strings of
695
+
696
+ # Returns the Reply-To value of the mail object as an array of strings of
694
697
  # address specs.
695
698
  #
696
699
  # Example:
697
- #
700
+ #
698
701
  # mail.reply_to = 'Mikel <mikel@test.lindsaar.net>'
699
702
  # mail.reply_to #=> ['mikel@test.lindsaar.net']
700
703
  # mail.reply_to = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
701
704
  # mail.reply_to #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
702
- #
705
+ #
703
706
  # Also allows you to set the value by passing a value as a parameter
704
707
  #
705
708
  # Example:
706
- #
709
+ #
707
710
  # mail.reply_to 'Mikel <mikel@test.lindsaar.net>'
708
711
  # mail.reply_to #=> ['mikel@test.lindsaar.net']
709
- #
712
+ #
710
713
  # Additionally, you can append new addresses to the returned Array like
711
714
  # object.
712
- #
715
+ #
713
716
  # Example:
714
- #
717
+ #
715
718
  # mail.reply_to 'Mikel <mikel@test.lindsaar.net>'
716
719
  # mail.reply_to << 'ada@test.lindsaar.net'
717
720
  # mail.reply_to #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
718
721
  def reply_to( val = nil )
719
722
  default :reply_to, val
720
723
  end
721
-
724
+
722
725
  # Sets the Reply-To value of the mail object, pass in a string of the field
723
726
  #
724
727
  # Example:
725
- #
728
+ #
726
729
  # mail.reply_to = 'Mikel <mikel@test.lindsaar.net>'
727
730
  # mail.reply_to #=> ['mikel@test.lindsaar.net']
728
731
  # mail.reply_to = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
@@ -730,81 +733,81 @@ module Mail
730
733
  def reply_to=( val )
731
734
  header[:reply_to] = val
732
735
  end
733
-
734
- # Returns the Resent-Bcc value of the mail object as an array of strings of
736
+
737
+ # Returns the Resent-Bcc value of the mail object as an array of strings of
735
738
  # address specs.
736
- #
739
+ #
737
740
  # Example:
738
- #
741
+ #
739
742
  # mail.resent_bcc = 'Mikel <mikel@test.lindsaar.net>'
740
743
  # mail.resent_bcc #=> ['mikel@test.lindsaar.net']
741
744
  # mail.resent_bcc = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
742
745
  # mail.resent_bcc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
743
- #
746
+ #
744
747
  # Also allows you to set the value by passing a value as a parameter
745
748
  #
746
749
  # Example:
747
- #
750
+ #
748
751
  # mail.resent_bcc 'Mikel <mikel@test.lindsaar.net>'
749
752
  # mail.resent_bcc #=> ['mikel@test.lindsaar.net']
750
- #
753
+ #
751
754
  # Additionally, you can append new addresses to the returned Array like
752
755
  # object.
753
- #
756
+ #
754
757
  # Example:
755
- #
758
+ #
756
759
  # mail.resent_bcc 'Mikel <mikel@test.lindsaar.net>'
757
760
  # mail.resent_bcc << 'ada@test.lindsaar.net'
758
761
  # mail.resent_bcc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
759
762
  def resent_bcc( val = nil )
760
763
  default :resent_bcc, val
761
764
  end
762
-
765
+
763
766
  # Sets the Resent-Bcc value of the mail object, pass in a string of the field
764
767
  #
765
768
  # Example:
766
- #
769
+ #
767
770
  # mail.resent_bcc = 'Mikel <mikel@test.lindsaar.net>'
768
771
  # mail.resent_bcc #=> ['mikel@test.lindsaar.net']
769
772
  # mail.resent_bcc = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
770
- # mail.resent_bcc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
773
+ # mail.resent_bcc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
771
774
  def resent_bcc=( val )
772
775
  header[:resent_bcc] = val
773
776
  end
774
-
775
- # Returns the Resent-Cc value of the mail object as an array of strings of
777
+
778
+ # Returns the Resent-Cc value of the mail object as an array of strings of
776
779
  # address specs.
777
- #
780
+ #
778
781
  # Example:
779
- #
782
+ #
780
783
  # mail.resent_cc = 'Mikel <mikel@test.lindsaar.net>'
781
784
  # mail.resent_cc #=> ['mikel@test.lindsaar.net']
782
785
  # mail.resent_cc = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
783
786
  # mail.resent_cc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
784
- #
787
+ #
785
788
  # Also allows you to set the value by passing a value as a parameter
786
789
  #
787
790
  # Example:
788
- #
791
+ #
789
792
  # mail.resent_cc 'Mikel <mikel@test.lindsaar.net>'
790
793
  # mail.resent_cc #=> ['mikel@test.lindsaar.net']
791
- #
794
+ #
792
795
  # Additionally, you can append new addresses to the returned Array like
793
796
  # object.
794
- #
797
+ #
795
798
  # Example:
796
- #
799
+ #
797
800
  # mail.resent_cc 'Mikel <mikel@test.lindsaar.net>'
798
801
  # mail.resent_cc << 'ada@test.lindsaar.net'
799
802
  # mail.resent_cc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
800
803
  def resent_cc( val = nil )
801
804
  default :resent_cc, val
802
805
  end
803
-
806
+
804
807
  # Sets the Resent-Cc value of the mail object, pass in a string of the field
805
808
  #
806
809
  # Example:
807
- #
810
+ #
808
811
  # mail.resent_cc = 'Mikel <mikel@test.lindsaar.net>'
809
812
  # mail.resent_cc #=> ['mikel@test.lindsaar.net']
810
813
  # mail.resent_cc = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
@@ -812,48 +815,48 @@ module Mail
812
815
  def resent_cc=( val )
813
816
  header[:resent_cc] = val
814
817
  end
815
-
818
+
816
819
  def resent_date( val = nil )
817
820
  default :resent_date, val
818
821
  end
819
-
822
+
820
823
  def resent_date=( val )
821
824
  header[:resent_date] = val
822
825
  end
823
-
824
- # Returns the Resent-From value of the mail object as an array of strings of
826
+
827
+ # Returns the Resent-From value of the mail object as an array of strings of
825
828
  # address specs.
826
829
  #
827
830
  # Example:
828
- #
831
+ #
829
832
  # mail.resent_from = 'Mikel <mikel@test.lindsaar.net>'
830
833
  # mail.resent_from #=> ['mikel@test.lindsaar.net']
831
834
  # mail.resent_from = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
832
835
  # mail.resent_from #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
833
- #
836
+ #
834
837
  # Also allows you to set the value by passing a value as a parameter
835
838
  #
836
839
  # Example:
837
- #
840
+ #
838
841
  # mail.resent_from ['Mikel <mikel@test.lindsaar.net>']
839
842
  # mail.resent_from #=> 'mikel@test.lindsaar.net'
840
- #
843
+ #
841
844
  # Additionally, you can append new addresses to the returned Array like
842
845
  # object.
843
- #
846
+ #
844
847
  # Example:
845
- #
848
+ #
846
849
  # mail.resent_from 'Mikel <mikel@test.lindsaar.net>'
847
850
  # mail.resent_from << 'ada@test.lindsaar.net'
848
851
  # mail.resent_from #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
849
852
  def resent_from( val = nil )
850
853
  default :resent_from, val
851
854
  end
852
-
855
+
853
856
  # Sets the Resent-From value of the mail object, pass in a string of the field
854
857
  #
855
858
  # Example:
856
- #
859
+ #
857
860
  # mail.resent_from = 'Mikel <mikel@test.lindsaar.net>'
858
861
  # mail.resent_from #=> ['mikel@test.lindsaar.net']
859
862
  # mail.resent_from = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
@@ -861,28 +864,28 @@ module Mail
861
864
  def resent_from=( val )
862
865
  header[:resent_from] = val
863
866
  end
864
-
867
+
865
868
  def resent_message_id( val = nil )
866
869
  default :resent_message_id, val
867
870
  end
868
-
871
+
869
872
  def resent_message_id=( val )
870
873
  header[:resent_message_id] = val
871
874
  end
872
-
875
+
873
876
  # Returns the Resent-Sender value of the mail object, as a single string of an address
874
877
  # spec. A sender per RFC 2822 must be a single address, so you can not append to
875
878
  # this address.
876
879
  #
877
880
  # Example:
878
- #
881
+ #
879
882
  # mail.resent_sender = 'Mikel <mikel@test.lindsaar.net>'
880
883
  # mail.resent_sender #=> 'mikel@test.lindsaar.net'
881
- #
884
+ #
882
885
  # Also allows you to set the value by passing a value as a parameter
883
886
  #
884
887
  # Example:
885
- #
888
+ #
886
889
  # mail.resent_sender 'Mikel <mikel@test.lindsaar.net>'
887
890
  # mail.resent_sender #=> 'mikel@test.lindsaar.net'
888
891
  def resent_sender( val = nil )
@@ -892,46 +895,46 @@ module Mail
892
895
  # Sets the Resent-Sender value of the mail object, pass in a string of the field
893
896
  #
894
897
  # Example:
895
- #
898
+ #
896
899
  # mail.sender = 'Mikel <mikel@test.lindsaar.net>'
897
900
  # mail.sender #=> 'mikel@test.lindsaar.net'
898
901
  def resent_sender=( val )
899
902
  header[:resent_sender] = val
900
903
  end
901
-
902
- # Returns the Resent-To value of the mail object as an array of strings of
904
+
905
+ # Returns the Resent-To value of the mail object as an array of strings of
903
906
  # address specs.
904
907
  #
905
908
  # Example:
906
- #
909
+ #
907
910
  # mail.resent_to = 'Mikel <mikel@test.lindsaar.net>'
908
911
  # mail.resent_to #=> ['mikel@test.lindsaar.net']
909
912
  # mail.resent_to = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
910
913
  # mail.resent_to #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
911
- #
914
+ #
912
915
  # Also allows you to set the value by passing a value as a parameter
913
916
  #
914
917
  # Example:
915
- #
918
+ #
916
919
  # mail.resent_to 'Mikel <mikel@test.lindsaar.net>'
917
920
  # mail.resent_to #=> ['mikel@test.lindsaar.net']
918
- #
921
+ #
919
922
  # Additionally, you can append new addresses to the returned Array like
920
923
  # object.
921
- #
924
+ #
922
925
  # Example:
923
- #
926
+ #
924
927
  # mail.resent_to 'Mikel <mikel@test.lindsaar.net>'
925
928
  # mail.resent_to << 'ada@test.lindsaar.net'
926
929
  # mail.resent_to #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
927
930
  def resent_to( val = nil )
928
931
  default :resent_to, val
929
932
  end
930
-
933
+
931
934
  # Sets the Resent-To value of the mail object, pass in a string of the field
932
935
  #
933
936
  # Example:
934
- #
937
+ #
935
938
  # mail.resent_to = 'Mikel <mikel@test.lindsaar.net>'
936
939
  # mail.resent_to #=> ['mikel@test.lindsaar.net']
937
940
  # mail.resent_to = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
@@ -939,107 +942,107 @@ module Mail
939
942
  def resent_to=( val )
940
943
  header[:resent_to] = val
941
944
  end
942
-
945
+
943
946
  # Returns the return path of the mail object, or sets it if you pass a string
944
947
  def return_path( val = nil )
945
948
  default :return_path, val
946
949
  end
947
-
950
+
948
951
  # Sets the return path of the object
949
952
  def return_path=( val )
950
953
  header[:return_path] = val
951
954
  end
952
-
955
+
953
956
  # Returns the Sender value of the mail object, as a single string of an address
954
957
  # spec. A sender per RFC 2822 must be a single address.
955
958
  #
956
959
  # Example:
957
- #
960
+ #
958
961
  # mail.sender = 'Mikel <mikel@test.lindsaar.net>'
959
962
  # mail.sender #=> 'mikel@test.lindsaar.net'
960
- #
963
+ #
961
964
  # Also allows you to set the value by passing a value as a parameter
962
965
  #
963
966
  # Example:
964
- #
967
+ #
965
968
  # mail.sender 'Mikel <mikel@test.lindsaar.net>'
966
969
  # mail.sender #=> 'mikel@test.lindsaar.net'
967
970
  def sender( val = nil )
968
971
  default :sender, val
969
972
  end
970
-
973
+
971
974
  # Sets the Sender value of the mail object, pass in a string of the field
972
975
  #
973
976
  # Example:
974
- #
977
+ #
975
978
  # mail.sender = 'Mikel <mikel@test.lindsaar.net>'
976
979
  # mail.sender #=> 'mikel@test.lindsaar.net'
977
980
  def sender=( val )
978
981
  header[:sender] = val
979
982
  end
980
-
983
+
981
984
  # Returns the decoded value of the subject field, as a single string.
982
985
  #
983
986
  # Example:
984
- #
987
+ #
985
988
  # mail.subject = "G'Day mate"
986
989
  # mail.subject #=> "G'Day mate"
987
990
  # mail.subject = '=?UTF-8?Q?This_is_=E3=81=82_string?='
988
991
  # mail.subject #=> "This is あ string"
989
- #
992
+ #
990
993
  # Also allows you to set the value by passing a value as a parameter
991
994
  #
992
995
  # Example:
993
- #
996
+ #
994
997
  # mail.subject "G'Day mate"
995
998
  # mail.subject #=> "G'Day mate"
996
999
  def subject( val = nil )
997
1000
  default :subject, val
998
1001
  end
999
-
1002
+
1000
1003
  # Sets the Subject value of the mail object, pass in a string of the field
1001
1004
  #
1002
1005
  # Example:
1003
- #
1006
+ #
1004
1007
  # mail.subject = '=?UTF-8?Q?This_is_=E3=81=82_string?='
1005
1008
  # mail.subject #=> "This is あ string"
1006
1009
  def subject=( val )
1007
1010
  header[:subject] = val
1008
1011
  end
1009
-
1010
- # Returns the To value of the mail object as an array of strings of
1012
+
1013
+ # Returns the To value of the mail object as an array of strings of
1011
1014
  # address specs.
1012
1015
  #
1013
1016
  # Example:
1014
- #
1017
+ #
1015
1018
  # mail.to = 'Mikel <mikel@test.lindsaar.net>'
1016
1019
  # mail.to #=> ['mikel@test.lindsaar.net']
1017
1020
  # mail.to = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
1018
1021
  # mail.to #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
1019
- #
1022
+ #
1020
1023
  # Also allows you to set the value by passing a value as a parameter
1021
1024
  #
1022
1025
  # Example:
1023
- #
1026
+ #
1024
1027
  # mail.to 'Mikel <mikel@test.lindsaar.net>'
1025
1028
  # mail.to #=> ['mikel@test.lindsaar.net']
1026
- #
1029
+ #
1027
1030
  # Additionally, you can append new addresses to the returned Array like
1028
1031
  # object.
1029
- #
1032
+ #
1030
1033
  # Example:
1031
- #
1034
+ #
1032
1035
  # mail.to 'Mikel <mikel@test.lindsaar.net>'
1033
1036
  # mail.to << 'ada@test.lindsaar.net'
1034
1037
  # mail.to #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
1035
1038
  def to( val = nil )
1036
1039
  default :to, val
1037
1040
  end
1038
-
1041
+
1039
1042
  # Sets the To value of the mail object, pass in a string of the field
1040
1043
  #
1041
1044
  # Example:
1042
- #
1045
+ #
1043
1046
  # mail.to = 'Mikel <mikel@test.lindsaar.net>'
1044
1047
  # mail.to #=> ['mikel@test.lindsaar.net']
1045
1048
  # mail.to = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
@@ -1050,7 +1053,7 @@ module Mail
1050
1053
 
1051
1054
  # Returns the default value of the field requested as a symbol.
1052
1055
  #
1053
- # Each header field has a :default method which returns the most common use case for
1056
+ # Each header field has a :default method which returns the most common use case for
1054
1057
  # that field, for example, the date field types will return a DateTime object when
1055
1058
  # sent :default, the subject, or unstructured fields will return a decoded string of
1056
1059
  # their value, the address field types will return a single addr_spec or an array of
@@ -1062,63 +1065,56 @@ module Mail
1062
1065
  header[sym].default if header[sym]
1063
1066
  end
1064
1067
  end
1065
-
1068
+
1066
1069
  # Sets the body object of the message object.
1067
- #
1070
+ #
1068
1071
  # Example:
1069
- #
1072
+ #
1070
1073
  # mail.body = 'This is the body'
1071
1074
  # mail.body #=> #<Mail::Body:0x13919c @raw_source="This is the bo...
1072
- #
1075
+ #
1073
1076
  # You can also reset the body of an Message object by setting body to nil
1074
- #
1077
+ #
1075
1078
  # Example:
1076
- #
1079
+ #
1077
1080
  # mail.body = 'this is the body'
1078
1081
  # mail.body.encoded #=> 'this is the body'
1079
1082
  # mail.body = nil
1080
1083
  # mail.body.encoded #=> ''
1081
- #
1084
+ #
1082
1085
  # If you try and set the body of an email that is a multipart email, then instead
1083
1086
  # of deleting all the parts of your email, mail will add a text/plain part to
1084
1087
  # your email:
1085
- #
1088
+ #
1086
1089
  # mail.add_file 'somefilename.png'
1087
1090
  # mail.parts.length #=> 1
1088
1091
  # mail.body = "This is a body"
1089
1092
  # mail.parts.length #=> 2
1090
1093
  # mail.parts.last.content_type.content_type #=> 'This is a body'
1091
1094
  def body=(value)
1092
- case
1093
- when value == nil
1094
- @body = Mail::Body.new('')
1095
- when @body && @body.multipart?
1096
- @body << Mail::Part.new(value)
1097
- else
1098
- @body = Mail::Body.new(value)
1099
- end
1100
- add_encoding_to_body
1095
+ body_lazy(value, 0)
1101
1096
  end
1102
1097
 
1103
1098
  # Returns the body of the message object. Or, if passed
1104
1099
  # a parameter sets the value.
1105
- #
1100
+ #
1106
1101
  # Example:
1107
- #
1102
+ #
1108
1103
  # mail = Mail::Message.new('To: mikel\r\n\r\nThis is the body')
1109
1104
  # mail.body #=> #<Mail::Body:0x13919c @raw_source="This is the bo...
1110
- #
1105
+ #
1111
1106
  # mail.body 'This is another body'
1112
1107
  # mail.body #=> #<Mail::Body:0x13919c @raw_source="This is anothe...
1113
1108
  def body(value = nil)
1114
1109
  if value
1115
1110
  self.body = value
1116
- add_encoding_to_body
1111
+ # add_encoding_to_body
1117
1112
  else
1113
+ process_body_raw if @body_raw
1118
1114
  @body
1119
1115
  end
1120
1116
  end
1121
-
1117
+
1122
1118
  def body_encoding(value)
1123
1119
  if value.nil?
1124
1120
  body.encoding
@@ -1130,12 +1126,12 @@ module Mail
1130
1126
  def body_encoding=(value)
1131
1127
  body.encoding = value
1132
1128
  end
1133
-
1129
+
1134
1130
  # Returns the list of addresses this message should be sent to by
1135
1131
  # collecting the addresses off the to, cc and bcc fields.
1136
- #
1132
+ #
1137
1133
  # Example:
1138
- #
1134
+ #
1139
1135
  # mail.to = 'mikel@test.lindsaar.net'
1140
1136
  # mail.cc = 'sam@test.lindsaar.net'
1141
1137
  # mail.bcc = 'bob@test.lindsaar.net'
@@ -1150,27 +1146,27 @@ module Mail
1150
1146
  def from_addrs
1151
1147
  from ? [from].flatten : []
1152
1148
  end
1153
-
1149
+
1154
1150
  # Returns an array of addresses (the encoded value) in the To field,
1155
1151
  # if no To field, returns an empty array
1156
1152
  def to_addrs
1157
1153
  to ? [to].flatten : []
1158
1154
  end
1159
-
1155
+
1160
1156
  # Returns an array of addresses (the encoded value) in the Cc field,
1161
1157
  # if no Cc field, returns an empty array
1162
1158
  def cc_addrs
1163
1159
  cc ? [cc].flatten : []
1164
1160
  end
1165
-
1161
+
1166
1162
  # Returns an array of addresses (the encoded value) in the Bcc field,
1167
1163
  # if no Bcc field, returns an empty array
1168
1164
  def bcc_addrs
1169
1165
  bcc ? [bcc].flatten : []
1170
1166
  end
1171
-
1167
+
1172
1168
  # Allows you to add an arbitrary header
1173
- #
1169
+ #
1174
1170
  # Example:
1175
1171
  #
1176
1172
  # mail['foo'] = '1234'
@@ -1188,7 +1184,7 @@ module Mail
1188
1184
  end
1189
1185
 
1190
1186
  # Allows you to read an arbitrary header
1191
- #
1187
+ #
1192
1188
  # Example:
1193
1189
  #
1194
1190
  # mail['foo'] = '1234'
@@ -1196,14 +1192,14 @@ module Mail
1196
1192
  def [](name)
1197
1193
  header[underscoreize(name)]
1198
1194
  end
1199
-
1195
+
1200
1196
  # Method Missing in this implementation allows you to set any of the
1201
1197
  # standard fields directly as you would the "to", "subject" etc.
1202
- #
1198
+ #
1203
1199
  # Those fields used most often (to, subject et al) are given their
1204
- # own method for ease of documentation and also to avoid the hook
1200
+ # own method for ease of documentation and also to avoid the hook
1205
1201
  # call to method missing.
1206
- #
1202
+ #
1207
1203
  # This will only catch the known fields listed in:
1208
1204
  #
1209
1205
  # Mail::Field::KNOWN_FIELDS
@@ -1211,29 +1207,29 @@ module Mail
1211
1207
  # as per RFC 2822, any ruby string or method name could pretty much
1212
1208
  # be a field name, so we don't want to just catch ANYTHING sent to
1213
1209
  # a message object and interpret it as a header.
1214
- #
1210
+ #
1215
1211
  # This method provides all three types of header call to set, read
1216
1212
  # and explicitly set with the = operator
1217
- #
1213
+ #
1218
1214
  # Examples:
1219
- #
1215
+ #
1220
1216
  # mail.comments = 'These are some comments'
1221
1217
  # mail.comments #=> 'These are some comments'
1222
- #
1218
+ #
1223
1219
  # mail.comments 'These are other comments'
1224
1220
  # mail.comments #=> 'These are other comments'
1225
- #
1226
- #
1221
+ #
1222
+ #
1227
1223
  # mail.date = 'Tue, 1 Jul 2003 10:52:37 +0200'
1228
1224
  # mail.date.to_s #=> 'Tue, 1 Jul 2003 10:52:37 +0200'
1229
- #
1225
+ #
1230
1226
  # mail.date 'Tue, 1 Jul 2003 10:52:37 +0200'
1231
1227
  # mail.date.to_s #=> 'Tue, 1 Jul 2003 10:52:37 +0200'
1232
- #
1228
+ #
1233
1229
  #
1234
1230
  # mail.resent_msg_id = '<1234@resent_msg_id.lindsaar.net>'
1235
1231
  # mail.resent_msg_id #=> '<1234@resent_msg_id.lindsaar.net>'
1236
- #
1232
+ #
1237
1233
  # mail.resent_msg_id '<4567@resent_msg_id.lindsaar.net>'
1238
1234
  # mail.resent_msg_id #=> '<4567@resent_msg_id.lindsaar.net>'
1239
1235
  def method_missing(name, *args, &block)
@@ -1248,10 +1244,10 @@ module Mail
1248
1244
  header[field_name] = args.first
1249
1245
  end
1250
1246
  else
1251
- super # otherwise pass it on
1252
- end
1247
+ super # otherwise pass it on
1248
+ end
1253
1249
  #:startdoc:
1254
- end
1250
+ end
1255
1251
 
1256
1252
  # Returns an FieldList of all the fields in the header in the order that
1257
1253
  # they appear in the header
@@ -1276,19 +1272,19 @@ module Mail
1276
1272
  def has_mime_version?
1277
1273
  header.has_mime_version?
1278
1274
  end
1279
-
1275
+
1280
1276
  def has_content_type?
1281
1277
  !!header[:content_type]
1282
1278
  end
1283
-
1279
+
1284
1280
  def has_charset?
1285
- !!(header[:content_type] && header[:content_type].parameters['charset'])
1281
+ !!(has_content_type? && header[:content_type].parameters['charset'])
1286
1282
  end
1287
-
1283
+
1288
1284
  def has_content_transfer_encoding?
1289
1285
  header[:content_transfer_encoding] && header[:content_transfer_encoding].errors.blank?
1290
1286
  end
1291
-
1287
+
1292
1288
  def has_transfer_encoding? # :nodoc:
1293
1289
  STDERR.puts(":has_transfer_encoding? is deprecated in Mail 1.4.3. Please use has_content_transfer_encoding?\n#{caller}")
1294
1290
  has_content_transfer_encoding?
@@ -1298,41 +1294,41 @@ module Mail
1298
1294
  # into the Header. The MessageIdField object will automatically generate
1299
1295
  # a unique message ID if you try and encode it or output it to_s without
1300
1296
  # specifying a message id.
1301
- #
1297
+ #
1302
1298
  # It will preserve the message ID you specify if you do.
1303
1299
  def add_message_id(msg_id_val = '')
1304
1300
  header['message-id'] = msg_id_val
1305
1301
  end
1306
-
1302
+
1307
1303
  # Creates a new empty Date field and inserts it in the correct order
1308
1304
  # into the Header. The DateField object will automatically generate
1309
1305
  # DateTime.now's date if you try and encode it or output it to_s without
1310
1306
  # specifying a date yourself.
1311
- #
1307
+ #
1312
1308
  # It will preserve any date you specify if you do.
1313
1309
  def add_date(date_val = '')
1314
1310
  header['date'] = date_val
1315
1311
  end
1316
-
1312
+
1317
1313
  # Creates a new empty Mime Version field and inserts it in the correct order
1318
1314
  # into the Header. The MimeVersion object will automatically generate
1319
1315
  # set itself to '1.0' if you try and encode it or output it to_s without
1320
1316
  # specifying a version yourself.
1321
- #
1317
+ #
1322
1318
  # It will preserve any date you specify if you do.
1323
1319
  def add_mime_version(ver_val = '')
1324
1320
  header['mime-version'] = ver_val
1325
1321
  end
1326
-
1322
+
1327
1323
  # Adds a content type and charset if the body is US-ASCII
1328
- #
1324
+ #
1329
1325
  # Otherwise raises a warning
1330
1326
  def add_content_type
1331
1327
  header[:content_type] = 'text/plain'
1332
1328
  end
1333
1329
 
1334
1330
  # Adds a content type and charset if the body is US-ASCII
1335
- #
1331
+ #
1336
1332
  # Otherwise raises a warning
1337
1333
  def add_charset
1338
1334
  if !body.empty?
@@ -1345,9 +1341,9 @@ module Mail
1345
1341
  header[:content_type].parameters['charset'] = @charset
1346
1342
  end
1347
1343
  end
1348
-
1344
+
1349
1345
  # Adds a content transfer encoding
1350
- #
1346
+ #
1351
1347
  # Otherwise raises a warning
1352
1348
  def add_content_transfer_encoding
1353
1349
  if body.only_us_ascii?
@@ -1358,27 +1354,27 @@ module Mail
1358
1354
  header[:content_transfer_encoding] = '8bit'
1359
1355
  end
1360
1356
  end
1361
-
1357
+
1362
1358
  def add_transfer_encoding # :nodoc:
1363
1359
  STDERR.puts(":add_transfer_encoding is deprecated in Mail 1.4.3. Please use add_content_transfer_encoding\n#{caller}")
1364
1360
  add_content_transfer_encoding
1365
1361
  end
1366
-
1362
+
1367
1363
  def transfer_encoding # :nodoc:
1368
1364
  STDERR.puts(":transfer_encoding is deprecated in Mail 1.4.3. Please use content_transfer_encoding\n#{caller}")
1369
1365
  content_transfer_encoding
1370
1366
  end
1371
-
1367
+
1372
1368
  # Returns the MIME media type of part we are on, this is taken from the content-type header
1373
1369
  def mime_type
1374
1370
  content_type ? header[:content_type].string : nil
1375
1371
  end
1376
-
1372
+
1377
1373
  def message_content_type
1378
1374
  STDERR.puts(":message_content_type is deprecated in Mail 1.4.3. Please use mime_type\n#{caller}")
1379
1375
  mime_type
1380
1376
  end
1381
-
1377
+
1382
1378
  # Returns the character set defined in the content type field
1383
1379
  def charset
1384
1380
  if @header
@@ -1394,60 +1390,60 @@ module Mail
1394
1390
  @charset = value
1395
1391
  @header.charset = value
1396
1392
  end
1397
-
1393
+
1398
1394
  # Returns the main content type
1399
1395
  def main_type
1400
1396
  has_content_type? ? header[:content_type].main_type : nil
1401
1397
  end
1402
-
1398
+
1403
1399
  # Returns the sub content type
1404
1400
  def sub_type
1405
1401
  has_content_type? ? header[:content_type].sub_type : nil
1406
1402
  end
1407
-
1403
+
1408
1404
  # Returns the content type parameters
1409
1405
  def mime_parameters
1410
1406
  STDERR.puts(':mime_parameters is deprecated in Mail 1.4.3, please use :content_type_parameters instead')
1411
1407
  content_type_parameters
1412
1408
  end
1413
-
1409
+
1414
1410
  # Returns the content type parameters
1415
1411
  def content_type_parameters
1416
1412
  has_content_type? ? header[:content_type].parameters : nil
1417
1413
  end
1418
-
1414
+
1419
1415
  # Returns true if the message is multipart
1420
1416
  def multipart?
1421
1417
  has_content_type? ? !!(main_type =~ /^multipart$/i) : false
1422
1418
  end
1423
-
1419
+
1424
1420
  # Returns true if the message is a multipart/report
1425
1421
  def multipart_report?
1426
1422
  multipart? && sub_type =~ /^report$/i
1427
1423
  end
1428
-
1424
+
1429
1425
  # Returns true if the message is a multipart/report; report-type=delivery-status;
1430
1426
  def delivery_status_report?
1431
1427
  multipart_report? && content_type_parameters['report-type'] =~ /^delivery-status$/i
1432
1428
  end
1433
-
1429
+
1434
1430
  # returns the part in a multipart/report email that has the content-type delivery-status
1435
1431
  def delivery_status_part
1436
1432
  @delivery_stats_part ||= parts.select { |p| p.delivery_status_report_part? }.first
1437
1433
  end
1438
-
1434
+
1439
1435
  def bounced?
1440
1436
  delivery_status_part and delivery_status_part.bounced?
1441
1437
  end
1442
-
1438
+
1443
1439
  def action
1444
1440
  delivery_status_part and delivery_status_part.action
1445
1441
  end
1446
-
1442
+
1447
1443
  def final_recipient
1448
1444
  delivery_status_part and delivery_status_part.final_recipient
1449
1445
  end
1450
-
1446
+
1451
1447
  def error_status
1452
1448
  delivery_status_part and delivery_status_part.error_status
1453
1449
  end
@@ -1455,59 +1451,59 @@ module Mail
1455
1451
  def diagnostic_code
1456
1452
  delivery_status_part and delivery_status_part.diagnostic_code
1457
1453
  end
1458
-
1454
+
1459
1455
  def remote_mta
1460
1456
  delivery_status_part and delivery_status_part.remote_mta
1461
1457
  end
1462
-
1458
+
1463
1459
  def retryable?
1464
1460
  delivery_status_part and delivery_status_part.retryable?
1465
1461
  end
1466
-
1462
+
1467
1463
  # Returns the current boundary for this message part
1468
1464
  def boundary
1469
1465
  content_type_parameters ? content_type_parameters['boundary'] : nil
1470
1466
  end
1471
-
1467
+
1472
1468
  # Returns a parts list object of all the parts in the message
1473
1469
  def parts
1474
1470
  body.parts
1475
1471
  end
1476
-
1472
+
1477
1473
  # Returns an AttachmentsList object, which holds all of the attachments in
1478
1474
  # the receiver object (either the entier email or a part within) and all
1479
1475
  # of it's descendants.
1480
- #
1476
+ #
1481
1477
  # It also allows you to add attachments to the mail object directly, like so:
1482
- #
1478
+ #
1483
1479
  # mail.attachments['filename.jpg'] = File.read('/path/to/filename.jpg')
1484
- #
1480
+ #
1485
1481
  # If you do this, then Mail will take the file name and work out the MIME media type
1486
- # set the Content-Type, Content-Disposition, Content-Transfer-Encoding and
1482
+ # set the Content-Type, Content-Disposition, Content-Transfer-Encoding and
1487
1483
  # base64 encode the contents of the attachment all for you.
1488
- #
1484
+ #
1489
1485
  # You can also specify overrides if you want by passing a hash instead of a string:
1490
- #
1486
+ #
1491
1487
  # mail.attachments['filename.jpg'] = {:mime_type => 'application/x-gzip',
1492
1488
  # :content => File.read('/path/to/filename.jpg')}
1493
- #
1489
+ #
1494
1490
  # If you want to use a different encoding than Base64, you can pass an encoding in,
1495
1491
  # but then it is up to you to pass in the content pre-encoded, and don't expect
1496
1492
  # Mail to know how to decode this data:
1497
- #
1493
+ #
1498
1494
  # file_content = SpecialEncode(File.read('/path/to/filename.jpg'))
1499
1495
  # mail.attachments['filename.jpg'] = {:mime_type => 'application/x-gzip',
1500
1496
  # :encoding => 'SpecialEncoding',
1501
1497
  # :content => file_content }
1502
- #
1498
+ #
1503
1499
  # You can also search for specific attachments:
1504
- #
1500
+ #
1505
1501
  # # By Filename
1506
1502
  # mail.attachments['filename.jpg'] #=> Mail::Part object or nil
1507
- #
1503
+ #
1508
1504
  # # or by index
1509
1505
  # mail.attachments[0] #=> Mail::Part (first attachment)
1510
- #
1506
+ #
1511
1507
  def attachments
1512
1508
  parts.attachments
1513
1509
  end
@@ -1515,7 +1511,7 @@ module Mail
1515
1511
  def has_attachments?
1516
1512
  !attachments.empty?
1517
1513
  end
1518
-
1514
+
1519
1515
  # Accessor for html_part
1520
1516
  def html_part(&block)
1521
1517
  if block_given?
@@ -1526,7 +1522,7 @@ module Mail
1526
1522
  @html_part || find_first_mime_type('text/html')
1527
1523
  end
1528
1524
  end
1529
-
1525
+
1530
1526
  # Accessor for text_part
1531
1527
  def text_part(&block)
1532
1528
  if block_given?
@@ -1537,7 +1533,7 @@ module Mail
1537
1533
  @text_part || find_first_mime_type('text/plain')
1538
1534
  end
1539
1535
  end
1540
-
1536
+
1541
1537
  # Helper to add a html part to a multipart/alternative email. If this and
1542
1538
  # text_part are both defined in a message, then it will be a multipart/alternative
1543
1539
  # message and set itself that way.
@@ -1550,7 +1546,7 @@ module Mail
1550
1546
  add_multipart_alternate_header unless text_part.blank?
1551
1547
  add_part(@html_part)
1552
1548
  end
1553
-
1549
+
1554
1550
  # Helper to add a text part to a multipart/alternative email. If this and
1555
1551
  # html_part are both defined in a message, then it will be a multipart/alternative
1556
1552
  # message and set itself that way.
@@ -1577,9 +1573,9 @@ module Mail
1577
1573
  end
1578
1574
 
1579
1575
  # Allows you to add a part in block form to an existing mail message object
1580
- #
1576
+ #
1581
1577
  # Example:
1582
- #
1578
+ #
1583
1579
  # mail = Mail.new do
1584
1580
  # part :content_type => "multipart/alternative", :content_disposition => "inline" do |p|
1585
1581
  # p.part :content_type => "text/plain", :body => "test text\nline #2"
@@ -1591,26 +1587,26 @@ module Mail
1591
1587
  yield new_part if block_given?
1592
1588
  add_part(new_part)
1593
1589
  end
1594
-
1590
+
1595
1591
  # Adds a file to the message. You have two options with this method, you can
1596
1592
  # just pass in the absolute path to the file you want and Mail will read the file,
1597
1593
  # get the filename from the path you pass in and guess the MIME media type, or you
1598
1594
  # can pass in the filename as a string, and pass in the file content as a blob.
1599
- #
1595
+ #
1600
1596
  # Example:
1601
- #
1597
+ #
1602
1598
  # m = Mail.new
1603
1599
  # m.add_file('/path/to/filename.png')
1604
- #
1600
+ #
1605
1601
  # m = Mail.new
1606
1602
  # m.add_file(:filename => 'filename.png', :content => File.read('/path/to/file.jpg'))
1607
1603
  #
1608
1604
  # Note also that if you add a file to an existing message, Mail will convert that message
1609
1605
  # to a MIME multipart email, moving whatever plain text body you had into it's own text
1610
1606
  # plain part.
1611
- #
1607
+ #
1612
1608
  # Example:
1613
- #
1609
+ #
1614
1610
  # m = Mail.new do
1615
1611
  # body 'this is some text'
1616
1612
  # end
@@ -1619,7 +1615,7 @@ module Mail
1619
1615
  # m.multipart? #=> true
1620
1616
  # m.parts.first.content_type.content_type #=> 'text/plain'
1621
1617
  # m.parts.last.content_type.content_type #=> 'image/png'
1622
- #
1618
+ #
1623
1619
  # See also #attachments
1624
1620
  def add_file(values)
1625
1621
  convert_to_multipart unless self.multipart? || self.body.decoded.blank?
@@ -1635,7 +1631,7 @@ module Mail
1635
1631
  end
1636
1632
 
1637
1633
  def convert_to_multipart
1638
- text = @body.decoded
1634
+ text = body.decoded
1639
1635
  self.body = ''
1640
1636
  text_part = Mail::Part.new({:content_type => 'text/plain;',
1641
1637
  :body => text})
@@ -1647,7 +1643,7 @@ module Mail
1647
1643
  def ready_to_send!
1648
1644
  identify_and_set_transfer_encoding
1649
1645
  parts.sort!([ "text/plain", "text/enriched", "text/html", "multipart/alternative" ])
1650
- parts.each do |part|
1646
+ parts.each do |part|
1651
1647
  part.transport_encoding = transport_encoding
1652
1648
  part.ready_to_send!
1653
1649
  end
@@ -1658,7 +1654,7 @@ module Mail
1658
1654
  STDERR.puts("Deprecated in 1.1.0 in favour of :ready_to_send! as it is less confusing with encoding and decoding.")
1659
1655
  ready_to_send!
1660
1656
  end
1661
-
1657
+
1662
1658
  # Outputs an encoded string representation of the mail message including
1663
1659
  # all headers, attachments, etc. This is an encoded email in US-ASCII,
1664
1660
  # so it is able to be directly sent to an email server.
@@ -1669,7 +1665,7 @@ module Mail
1669
1665
  buffer << body.encoded(content_transfer_encoding)
1670
1666
  buffer
1671
1667
  end
1672
-
1668
+
1673
1669
  def to_s
1674
1670
  encoded
1675
1671
  end
@@ -1700,17 +1696,18 @@ module Mail
1700
1696
  def decode_body
1701
1697
  body.decoded
1702
1698
  end
1703
-
1704
- # Returns true if this part is an attachment
1699
+
1700
+ # Returns true if this part is an attachment,
1701
+ # false otherwise.
1705
1702
  def attachment?
1706
- find_attachment
1703
+ !!find_attachment
1707
1704
  end
1708
-
1705
+
1709
1706
  # Returns the attachment data if there is any
1710
1707
  def attachment
1711
1708
  @attachment
1712
1709
  end
1713
-
1710
+
1714
1711
  # Returns the filename of the attachment
1715
1712
  def filename
1716
1713
  find_attachment
@@ -1723,7 +1720,7 @@ module Mail
1723
1720
  def find_first_mime_type(mt)
1724
1721
  all_parts.detect { |p| p.mime_type == mt }
1725
1722
  end
1726
-
1723
+
1727
1724
  private
1728
1725
 
1729
1726
  # 2.1. General Description
@@ -1733,19 +1730,51 @@ module Mail
1733
1730
  # this standard. The body is simply a sequence of characters that
1734
1731
  # follows the header and is separated from the header by an empty line
1735
1732
  # (i.e., a line with nothing preceding the CRLF).
1736
- #
1733
+ #
1737
1734
  # Additionally, I allow for the case where someone might have put whitespace
1738
1735
  # on the "gap line"
1739
1736
  def parse_message
1740
1737
  header_part, body_part = raw_source.split(/#{CRLF}#{WSP}*#{CRLF}/m, 2)
1738
+ # index = raw_source.index(/#{CRLF}#{WSP}*#{CRLF}/m, 2)
1739
+ # self.header = (index) ? header_part[0,index] : nil
1740
+ # lazy_body ( [raw_source, index+1])
1741
1741
  self.header = header_part
1742
1742
  self.body = body_part
1743
1743
  end
1744
-
1744
+
1745
1745
  def raw_source=(value)
1746
1746
  @raw_source = value.to_crlf
1747
1747
  end
1748
-
1748
+
1749
+ # see comments to body=. We take data starting from index and process it lazily
1750
+ def body_lazy(value, index)
1751
+ process_body_raw if @body_raw && value
1752
+ case
1753
+ when value == nil || value.length<=index
1754
+ @body = Mail::Body.new('')
1755
+ @body_raw = nil
1756
+ @body_raw_index = nil
1757
+ add_encoding_to_body
1758
+ when @body && @body.multipart?
1759
+ @body << Mail::Part.new(value[index, value.length-index])
1760
+ add_encoding_to_body
1761
+ else
1762
+ @body_raw = value
1763
+ @body_raw_index = index
1764
+ # process_body_raw
1765
+ end
1766
+ end
1767
+
1768
+
1769
+ def process_body_raw
1770
+ @body = Mail::Body.new(@body_raw[@body_raw_index, @body_raw.length-@body_raw_index])
1771
+ @body_raw = nil
1772
+ @body_raw_index = nil
1773
+ separate_parts if @separate_parts
1774
+
1775
+ add_encoding_to_body
1776
+ end
1777
+
1749
1778
  def set_envelope_header
1750
1779
  if match_data = raw_source.to_s.match(/\AFrom\s(#{TEXT}+)#{CRLF}(.*)/m)
1751
1780
  set_envelope(match_data[1])
@@ -1756,10 +1785,10 @@ module Mail
1756
1785
  def separate_parts
1757
1786
  body.split!(boundary)
1758
1787
  end
1759
-
1788
+
1760
1789
  def add_encoding_to_body
1761
1790
  if has_content_transfer_encoding?
1762
- body.encoding = content_transfer_encoding
1791
+ @body.encoding = content_transfer_encoding
1763
1792
  end
1764
1793
  end
1765
1794
 
@@ -1770,10 +1799,10 @@ module Mail
1770
1799
  self.content_transfer_encoding = body.get_best_encoding(@transport_encoding)
1771
1800
  end
1772
1801
  end
1773
-
1802
+
1774
1803
  def add_required_fields
1775
1804
  add_multipart_mixed_header unless !body.multipart?
1776
- @body = Mail::Body.new('') if body.nil?
1805
+ body = nil if body.nil?
1777
1806
  add_message_id unless (has_message_id? || self.class == Mail::Part)
1778
1807
  add_date unless has_date?
1779
1808
  add_mime_version unless has_mime_version?
@@ -1781,13 +1810,13 @@ module Mail
1781
1810
  add_charset unless has_charset?
1782
1811
  add_content_transfer_encoding unless has_content_transfer_encoding?
1783
1812
  end
1784
-
1813
+
1785
1814
  def add_multipart_alternate_header
1786
1815
  header['content-type'] = ContentTypeField.with_boundary('multipart/alternative').value
1787
1816
  header['content_type'].parameters[:charset] = @charset
1788
1817
  body.boundary = boundary
1789
1818
  end
1790
-
1819
+
1791
1820
  def add_boundary
1792
1821
  unless body.boundary && boundary
1793
1822
  header['content-type'] = 'multipart/mixed' unless header['content-type']
@@ -1796,7 +1825,7 @@ module Mail
1796
1825
  body.boundary = boundary
1797
1826
  end
1798
1827
  end
1799
-
1828
+
1800
1829
  def add_multipart_mixed_header
1801
1830
  unless header['content-type']
1802
1831
  header['content-type'] = ContentTypeField.with_boundary('multipart/mixed').value
@@ -1804,13 +1833,14 @@ module Mail
1804
1833
  body.boundary = boundary
1805
1834
  end
1806
1835
  end
1807
-
1836
+
1808
1837
  def init_with_hash(hash)
1809
1838
  passed_in_options = hash.with_indifferent_access
1810
1839
  self.raw_source = ''
1811
1840
 
1812
1841
  @header = Mail::Header.new
1813
1842
  @body = Mail::Body.new
1843
+ @body_raw = nil
1814
1844
 
1815
1845
  # We need to store the body until last, as we need all headers added first
1816
1846
  body_content = nil
@@ -1833,14 +1863,14 @@ module Mail
1833
1863
  end
1834
1864
  end
1835
1865
  end
1836
-
1866
+
1837
1867
  def init_with_string(string)
1838
1868
  self.raw_source = string
1839
1869
  set_envelope_header
1840
1870
  parse_message
1841
- separate_parts if multipart?
1871
+ @separate_parts = multipart?
1842
1872
  end
1843
-
1873
+
1844
1874
  # Returns the filename of the attachment (if it exists) or returns nil
1845
1875
  def find_attachment
1846
1876
  case
@@ -1865,6 +1895,6 @@ module Mail
1865
1895
  raise e if raise_delivery_errors
1866
1896
  end
1867
1897
  end
1868
-
1898
+
1869
1899
  end
1870
1900
  end