mail 1.4.3 → 1.5.0

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

Potentially problematic release.


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

Files changed (37) hide show
  1. data/CHANGELOG.rdoc +14 -0
  2. data/README.rdoc +6 -6
  3. data/Rakefile +1 -1
  4. data/lib/mail/body.rb +2 -2
  5. data/lib/mail/field.rb +1 -1
  6. data/lib/mail/fields/bcc_field.rb +5 -6
  7. data/lib/mail/fields/cc_field.rb +5 -4
  8. data/lib/mail/fields/comments_field.rb +3 -7
  9. data/lib/mail/fields/common/common_address.rb +8 -0
  10. data/lib/mail/fields/common/common_date.rb +4 -0
  11. data/lib/mail/fields/common/common_field.rb +5 -1
  12. data/lib/mail/fields/common/common_message_id.rb +8 -0
  13. data/lib/mail/fields/content_transfer_encoding_field.rb +1 -1
  14. data/lib/mail/fields/content_type_field.rb +4 -0
  15. data/lib/mail/fields/date_field.rb +7 -7
  16. data/lib/mail/fields/from_field.rb +5 -4
  17. data/lib/mail/fields/in_reply_to_field.rb +2 -3
  18. data/lib/mail/fields/keywords_field.rb +4 -0
  19. data/lib/mail/fields/message_id_field.rb +3 -4
  20. data/lib/mail/fields/references_field.rb +2 -3
  21. data/lib/mail/fields/reply_to_field.rb +5 -4
  22. data/lib/mail/fields/resent_bcc_field.rb +5 -4
  23. data/lib/mail/fields/resent_cc_field.rb +5 -4
  24. data/lib/mail/fields/resent_date_field.rb +9 -1
  25. data/lib/mail/fields/resent_from_field.rb +6 -5
  26. data/lib/mail/fields/resent_sender_field.rb +1 -1
  27. data/lib/mail/fields/resent_to_field.rb +5 -4
  28. data/lib/mail/fields/sender_field.rb +6 -5
  29. data/lib/mail/fields/structured_field.rb +4 -0
  30. data/lib/mail/fields/to_field.rb +5 -4
  31. data/lib/mail/fields/unstructured_field.rb +4 -0
  32. data/lib/mail/header.rb +4 -3
  33. data/lib/mail/message.rb +619 -105
  34. data/lib/mail/network/delivery_methods/smtp.rb +1 -1
  35. data/lib/mail/utilities.rb +14 -3
  36. data/lib/mail/version.rb +2 -2
  37. metadata +2 -2
@@ -38,7 +38,7 @@ module Mail
38
38
  end
39
39
 
40
40
  def addresses
41
- [address]
41
+ [address.address]
42
42
  end
43
43
 
44
44
  def address
@@ -16,14 +16,15 @@
16
16
  #
17
17
  # mail = Mail.new
18
18
  # mail.resent_to = 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
19
- # mail.resent_to #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ResentToField:0x180e1c4
19
+ # mail.resent_to #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
20
20
  # mail[:resent_to] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ResentToField:0x180e1c4
21
21
  # mail['resent-to'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ResentToField:0x180e1c4
22
22
  # mail['Resent-To'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ResentToField:0x180e1c4
23
23
  #
24
- # mail.resent_to.to_s #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
25
- # mail.resent_to.addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
26
- # mail.resent_to.formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
24
+ # mail[:resent_to].encoded #=> 'Resent-To: Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net\r\n'
25
+ # mail[:resent_to].decoded #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
26
+ # mail[:resent_to].addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
27
+ # mail[:resent_to].formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
27
28
  #
28
29
  module Mail
29
30
  class ResentToField < StructuredField
@@ -16,14 +16,15 @@
16
16
  #
17
17
  # mail = Mail.new
18
18
  # mail.sender = 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
19
- # mail.sender #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::SenderField:0x180e1c4
19
+ # mail.sender #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
20
20
  # mail[:sender] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::SenderField:0x180e1c4
21
21
  # mail['sender'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::SenderField:0x180e1c4
22
22
  # mail['Sender'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::SenderField:0x180e1c4
23
23
  #
24
- # mail.sender.to_s #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
25
- # mail.sender.addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
26
- # mail.sender.formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
24
+ # mail[:sender].encoded #=> 'Sender: Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net\r\n'
25
+ # mail[:sender].decoded #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
26
+ # mail[:sender].addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
27
+ # mail[:sender].formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
27
28
  #
28
29
  module Mail
29
30
  class SenderField < StructuredField
@@ -38,7 +39,7 @@ module Mail
38
39
  end
39
40
 
40
41
  def addresses
41
- [address]
42
+ [address.address]
42
43
  end
43
44
 
44
45
  def address
@@ -28,5 +28,9 @@ module Mail
28
28
  self
29
29
  end
30
30
 
31
+ def default
32
+ decoded
33
+ end
34
+
31
35
  end
32
36
  end
@@ -16,14 +16,15 @@
16
16
  #
17
17
  # mail = Mail.new
18
18
  # mail.to = 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
19
- # mail.to #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ToField:0x180e1c4
19
+ # mail.to #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
20
20
  # mail[:to] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ToField:0x180e1c4
21
21
  # mail['to'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ToField:0x180e1c4
22
22
  # mail['To'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ToField:0x180e1c4
23
23
  #
24
- # mail.to.to_s #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
25
- # mail.to.addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
26
- # mail.to.formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
24
+ # mail[:to].encoded #=> 'To: Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net\r\n'
25
+ # mail[:to].decoded #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
26
+ # mail[:to].addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
27
+ # mail[:to].formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
27
28
  #
28
29
  module Mail
29
30
  class ToField < StructuredField
@@ -31,6 +31,10 @@ module Mail
31
31
  do_decode
32
32
  end
33
33
 
34
+ def default
35
+ decoded
36
+ end
37
+
34
38
  private
35
39
 
36
40
  def do_encode(name)
@@ -107,6 +107,7 @@ module Mail
107
107
  # h['To'] #=> 'mikel@me.com'
108
108
  # h['X-Mail-SPAM'] #=> ['15', '20']
109
109
  def [](name)
110
+ name = dasherize(name)
110
111
  selected = select_field_for(name)
111
112
  case
112
113
  when selected.length > 1
@@ -132,8 +133,9 @@ module Mail
132
133
  # h['X-Mail-SPAM'] = nil
133
134
  # h['X-Mail-SPAM'] # => nil
134
135
  def []=(name, value)
136
+ name = dasherize(name)
135
137
  selected = select_field_for(name)
136
-
138
+
137
139
  case
138
140
  # User wants to delete the field
139
141
  when !selected.blank? && value == nil
@@ -141,7 +143,6 @@ module Mail
141
143
 
142
144
  # User wants to change the field
143
145
  when !selected.blank? && limited_field?(name)
144
-
145
146
  selected.first.update(name, value)
146
147
 
147
148
  # User wants to create the field
@@ -223,7 +224,7 @@ module Mail
223
224
  end
224
225
 
225
226
  def select_field_for(name)
226
- fields.select { |f| f.responsible_for?(name) }
227
+ fields.select { |f| f.responsible_for?(name.to_s) }
227
228
  end
228
229
 
229
230
  def limited_field?(name)
@@ -152,6 +152,582 @@ module Mail
152
152
  end
153
153
  end
154
154
 
155
+ # Returns the Bcc value of the mail object, either a single string of an address
156
+ # spec or an array of strings of address specs if there is more than one address
157
+ # in the Bcc.
158
+ #
159
+ # Example:
160
+ #
161
+ # mail.bcc = 'Mikel <mikel@test.lindsaar.net>'
162
+ # mail.bcc #=> 'mikel@test.lindsaar.net'
163
+ # mail.bcc = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
164
+ # mail.bcc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
165
+ #
166
+ # Also allows you to set the value by passing a value as a parameter
167
+ #
168
+ # Example:
169
+ #
170
+ # mail.bcc 'Mikel <mikel@test.lindsaar.net>'
171
+ # mail.bcc #=> 'mikel@test.lindsaar.net'
172
+ def bcc( val = nil )
173
+ default :bcc, val
174
+ end
175
+
176
+ # Sets the Bcc value of the mail object, pass in a string of the field
177
+ #
178
+ # Example:
179
+ #
180
+ # mail.bcc = 'Mikel <mikel@test.lindsaar.net>'
181
+ # mail.bcc #=> 'mikel@test.lindsaar.net'
182
+ # mail.bcc = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
183
+ # mail.bcc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
184
+ def bcc=( val )
185
+ header[:bcc] = val
186
+ end
187
+
188
+ # Returns the Cc value of the mail object, either a single string of an address
189
+ # spec or an array of strings of address specs if there is more than one address
190
+ # in the Cc.
191
+ #
192
+ # Example:
193
+ #
194
+ # mail.cc = 'Mikel <mikel@test.lindsaar.net>'
195
+ # mail.cc #=> 'mikel@test.lindsaar.net'
196
+ # mail.cc = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
197
+ # mail.cc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
198
+ #
199
+ # Also allows you to set the value by passing a value as a parameter
200
+ #
201
+ # Example:
202
+ #
203
+ # mail.cc 'Mikel <mikel@test.lindsaar.net>'
204
+ # mail.cc #=> 'mikel@test.lindsaar.net'
205
+ def cc( val = nil )
206
+ default :cc, val
207
+ end
208
+
209
+ # Sets the Cc value of the mail object, pass in a string of the field
210
+ #
211
+ # Example:
212
+ #
213
+ # mail.cc = 'Mikel <mikel@test.lindsaar.net>'
214
+ # mail.cc #=> 'mikel@test.lindsaar.net'
215
+ # mail.cc = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
216
+ # mail.cc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
217
+ def cc=( val )
218
+ header[:cc] = val
219
+ end
220
+
221
+ def comments( val = nil )
222
+ default :comments, val
223
+ end
224
+
225
+ def comments=( val )
226
+ header[:comments] = val
227
+ end
228
+
229
+ def content_description( val = nil )
230
+ default :content_description, val
231
+ end
232
+
233
+ def content_description=( val )
234
+ header[:content_description] = val
235
+ end
236
+
237
+ def content_disposition( val = nil )
238
+ default :content_disposition, val
239
+ end
240
+
241
+ def content_disposition=( val )
242
+ header[:content_disposition] = val
243
+ end
244
+
245
+ def content_id( val = nil )
246
+ default :content_id, val
247
+ end
248
+
249
+ def content_id=( val )
250
+ header[:content_id] = val
251
+ end
252
+
253
+ def content_location( val = nil )
254
+ default :content_location, val
255
+ end
256
+
257
+ def content_location=( val )
258
+ header[:content_location] = val
259
+ end
260
+
261
+ def content_transfer_encoding( val = nil )
262
+ default :content_transfer_encoding, val
263
+ end
264
+
265
+ def content_transfer_encoding=( val )
266
+ header[:content_transfer_encoding] = val
267
+ end
268
+
269
+ def content_type( val = nil )
270
+ default :content_type, val
271
+ end
272
+
273
+ def content_type=( val )
274
+ header[:content_type] = val
275
+ end
276
+
277
+ def date( val = nil )
278
+ default :date, val
279
+ end
280
+
281
+ def date=( val )
282
+ header[:date] = val
283
+ end
284
+
285
+ # Returns the From value of the mail object, either a single string of an address
286
+ # spec or an array of strings of address specs if there is more than one address
287
+ # in the From.
288
+ #
289
+ # Example:
290
+ #
291
+ # mail.from = 'Mikel <mikel@test.lindsaar.net>'
292
+ # mail.from #=> 'mikel@test.lindsaar.net'
293
+ # mail.from = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
294
+ # mail.from #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
295
+ #
296
+ # Also allows you to set the value by passing a value as a parameter
297
+ #
298
+ # Example:
299
+ #
300
+ # mail.from 'Mikel <mikel@test.lindsaar.net>'
301
+ # mail.from #=> 'mikel@test.lindsaar.net'
302
+ def from( val = nil )
303
+ default :from, val
304
+ end
305
+
306
+ # Sets the From value of the mail object, pass in a string of the field
307
+ #
308
+ # Example:
309
+ #
310
+ # mail.from = 'Mikel <mikel@test.lindsaar.net>'
311
+ # mail.from #=> 'mikel@test.lindsaar.net'
312
+ # mail.from = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
313
+ # mail.from #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
314
+ def from=( val )
315
+ header[:from] = val
316
+ end
317
+
318
+ def in_reply_to( val = nil )
319
+ default :in_reply_to, val
320
+ end
321
+
322
+ def in_reply_to=( val )
323
+ header[:in_reply_to] = val
324
+ end
325
+
326
+ def keywords( val = nil )
327
+ default :keywords, val
328
+ end
329
+
330
+ def keywords=( val )
331
+ header[:keywords] = val
332
+ end
333
+
334
+ # Returns the Message-ID of the mail object. Note, per RFC 2822 the Message ID
335
+ # consists of what is INSIDE the < > usually seen in the mail header, so this method
336
+ # will return only what is inside.
337
+ #
338
+ # Example:
339
+ #
340
+ # mail.message_id = '<1234@message.id>'
341
+ # mail.message_id #=> '1234@message.id'
342
+ #
343
+ # Also allows you to set the Message-ID by passing a string as a parameter
344
+ #
345
+ # mail.message_id '<1234@message.id>'
346
+ # mail.message_id #=> '1234@message.id'
347
+ def message_id( val = nil )
348
+ default :message_id, val
349
+ end
350
+
351
+ # Sets the Message-ID. Note, per RFC 2822 the Message ID consists of what is INSIDE
352
+ # the < > usually seen in the mail header, so this method will return only what is inside.
353
+ #
354
+ # mail.message_id = '<1234@message.id>'
355
+ # mail.message_id #=> '1234@message.id'
356
+ def message_id=( val )
357
+ header[:message_id] = val
358
+ end
359
+
360
+ # Returns the mime version of the email as a string
361
+ #
362
+ # Example:
363
+ #
364
+ # mail.mime_version = '1.0'
365
+ # mail.mime_version #=> '1.0'
366
+ #
367
+ # Also allows you to set the mime version by passing a string as a parameter.
368
+ #
369
+ # Example:
370
+ #
371
+ # mail.mime_version '1.0'
372
+ # mail.mime_version #=> '1.0'
373
+ def mime_version( val = nil )
374
+ default :mime_version, val
375
+ end
376
+
377
+ # Sets the mime version of the email by accepting a string
378
+ #
379
+ # Example:
380
+ #
381
+ # mail.mime_version = '1.0'
382
+ # mail.mime_version #=> '1.0'
383
+ def mime_version=( val )
384
+ header[:mime_version] = val
385
+ end
386
+
387
+ def received( val = nil )
388
+ if val
389
+ header[:received] = val
390
+ else
391
+ header[:received]
392
+ end
393
+ end
394
+
395
+ def received=( val )
396
+ header[:received] = val
397
+ end
398
+
399
+ def references( val = nil )
400
+ default :references, val
401
+ end
402
+
403
+ def references=( val )
404
+ header[:references] = val
405
+ end
406
+
407
+ # Returns the Reply-To value of the mail object, either a single string of an address
408
+ # spec or an array of strings of address specs if there is more than one address
409
+ # in the Reply-To.
410
+ #
411
+ # Example:
412
+ #
413
+ # mail.reply_to = 'Mikel <mikel@test.lindsaar.net>'
414
+ # mail.reply_to #=> 'mikel@test.lindsaar.net'
415
+ # mail.reply_to = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
416
+ # mail.reply_to #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
417
+ #
418
+ # Also allows you to set the value by passing a value as a parameter
419
+ #
420
+ # Example:
421
+ #
422
+ # mail.reply_to 'Mikel <mikel@test.lindsaar.net>'
423
+ # mail.reply_to #=> 'mikel@test.lindsaar.net'
424
+ def reply_to( val = nil )
425
+ default :reply_to, val
426
+ end
427
+
428
+ # Sets the Reply-To value of the mail object, pass in a string of the field
429
+ #
430
+ # Example:
431
+ #
432
+ # mail.reply_to = 'Mikel <mikel@test.lindsaar.net>'
433
+ # mail.reply_to #=> 'mikel@test.lindsaar.net'
434
+ # mail.reply_to = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
435
+ # mail.reply_to #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
436
+ def reply_to=( val )
437
+ header[:reply_to] = val
438
+ end
439
+
440
+ # Returns the Resent-Bcc value of the mail object, either a single string of an address
441
+ # spec or an array of strings of address specs if there is more than one address
442
+ # in the Resent-Bcc.
443
+ #
444
+ # Example:
445
+ #
446
+ # mail.resent_bcc = 'Mikel <mikel@test.lindsaar.net>'
447
+ # mail.resent_bcc #=> 'mikel@test.lindsaar.net'
448
+ # mail.resent_bcc = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
449
+ # mail.resent_bcc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
450
+ #
451
+ # Also allows you to set the value by passing a value as a parameter
452
+ #
453
+ # Example:
454
+ #
455
+ # mail.resent_bcc 'Mikel <mikel@test.lindsaar.net>'
456
+ # mail.resent_bcc #=> 'mikel@test.lindsaar.net'
457
+ def resent_bcc( val = nil )
458
+ default :resent_bcc, val
459
+ end
460
+
461
+ # Sets the Resent-Bcc value of the mail object, pass in a string of the field
462
+ #
463
+ # Example:
464
+ #
465
+ # mail.resent_bcc = 'Mikel <mikel@test.lindsaar.net>'
466
+ # mail.resent_bcc #=> 'mikel@test.lindsaar.net'
467
+ # mail.resent_bcc = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
468
+ # mail.resent_bcc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
469
+ def resent_bcc=( val )
470
+ header[:resent_bcc] = val
471
+ end
472
+
473
+ # Returns the Resent-Cc value of the mail object, either a single string of an address
474
+ # spec or an array of strings of address specs if there is more than one address
475
+ # in the Resent-Cc.
476
+ #
477
+ # Example:
478
+ #
479
+ # mail.resent_cc = 'Mikel <mikel@test.lindsaar.net>'
480
+ # mail.resent_cc #=> 'mikel@test.lindsaar.net'
481
+ # mail.resent_cc = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
482
+ # mail.resent_cc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
483
+ #
484
+ # Also allows you to set the value by passing a value as a parameter
485
+ #
486
+ # Example:
487
+ #
488
+ # mail.resent_cc 'Mikel <mikel@test.lindsaar.net>'
489
+ # mail.resent_cc #=> 'mikel@test.lindsaar.net'
490
+ def resent_cc( val = nil )
491
+ default :resent_cc, val
492
+ end
493
+
494
+ # Sets the Resent-Cc value of the mail object, pass in a string of the field
495
+ #
496
+ # Example:
497
+ #
498
+ # mail.resent_cc = 'Mikel <mikel@test.lindsaar.net>'
499
+ # mail.resent_cc #=> 'mikel@test.lindsaar.net'
500
+ # mail.resent_cc = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
501
+ # mail.resent_cc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
502
+ def resent_cc=( val )
503
+ header[:resent_cc] = val
504
+ end
505
+
506
+ def resent_date( val = nil )
507
+ default :resent_date, val
508
+ end
509
+
510
+ def resent_date=( val )
511
+ header[:resent_date] = val
512
+ end
513
+
514
+ # Returns the Resent-From value of the mail object, either a single string of an address
515
+ # spec or an array of strings of address specs if there is more than one address
516
+ # in the Resent-From.
517
+ #
518
+ # Example:
519
+ #
520
+ # mail.resent_from = 'Mikel <mikel@test.lindsaar.net>'
521
+ # mail.resent_from #=> 'mikel@test.lindsaar.net'
522
+ # mail.resent_from = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
523
+ # mail.resent_from #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
524
+ #
525
+ # Also allows you to set the value by passing a value as a parameter
526
+ #
527
+ # Example:
528
+ #
529
+ # mail.resent_from 'Mikel <mikel@test.lindsaar.net>'
530
+ # mail.resent_from #=> 'mikel@test.lindsaar.net'
531
+ def resent_from( val = nil )
532
+ default :resent_from, val
533
+ end
534
+
535
+ # Sets the Resent-From value of the mail object, pass in a string of the field
536
+ #
537
+ # Example:
538
+ #
539
+ # mail.resent_from = 'Mikel <mikel@test.lindsaar.net>'
540
+ # mail.resent_from #=> 'mikel@test.lindsaar.net'
541
+ # mail.resent_from = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
542
+ # mail.resent_from #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
543
+ def resent_from=( val )
544
+ header[:resent_from] = val
545
+ end
546
+
547
+ def resent_message_id( val = nil )
548
+ default :resent_message_id, val
549
+ end
550
+
551
+ def resent_message_id=( val )
552
+ header[:resent_message_id] = val
553
+ end
554
+
555
+ # Returns the Resent-Sender value of the mail object, as a single string of an address
556
+ # spec. A sender per RFC 2822 must be a single address
557
+ #
558
+ # Example:
559
+ #
560
+ # mail.resent_sender = 'Mikel <mikel@test.lindsaar.net>'
561
+ # mail.resent_sender #=> 'mikel@test.lindsaar.net'
562
+ #
563
+ # Also allows you to set the value by passing a value as a parameter
564
+ #
565
+ # Example:
566
+ #
567
+ # mail.resent_sender 'Mikel <mikel@test.lindsaar.net>'
568
+ # mail.resent_sender #=> 'mikel@test.lindsaar.net'
569
+ def resent_sender( val = nil )
570
+ default :resent_sender, val
571
+ end
572
+
573
+ # Sets the Resent-Sender value of the mail object, pass in a string of the field
574
+ #
575
+ # Example:
576
+ #
577
+ # mail.sender = 'Mikel <mikel@test.lindsaar.net>'
578
+ # mail.sender #=> 'mikel@test.lindsaar.net'
579
+ def resent_sender=( val )
580
+ header[:resent_sender] = val
581
+ end
582
+
583
+ # Returns the Resent-To value of the mail object, either a single string of an address
584
+ # spec or an array of strings of address specs if there is more than one address
585
+ # in the Resent-To.
586
+ #
587
+ # Example:
588
+ #
589
+ # mail.resent_to = 'Mikel <mikel@test.lindsaar.net>'
590
+ # mail.resent_to #=> 'mikel@test.lindsaar.net'
591
+ # mail.resent_to = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
592
+ # mail.resent_to #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
593
+ #
594
+ # Also allows you to set the value by passing a value as a parameter
595
+ #
596
+ # Example:
597
+ #
598
+ # mail.resent_to 'Mikel <mikel@test.lindsaar.net>'
599
+ # mail.resent_to #=> 'mikel@test.lindsaar.net'
600
+ def resent_to( val = nil )
601
+ default :resent_to, val
602
+ end
603
+
604
+ # Sets the Resent-To value of the mail object, pass in a string of the field
605
+ #
606
+ # Example:
607
+ #
608
+ # mail.resent_to = 'Mikel <mikel@test.lindsaar.net>'
609
+ # mail.resent_to #=> 'mikel@test.lindsaar.net'
610
+ # mail.resent_to = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
611
+ # mail.resent_to #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
612
+ def resent_to=( val )
613
+ header[:resent_to] = val
614
+ end
615
+
616
+ # Returns the return path of the mail object, or sets it if you pass a string
617
+ def return_path( val = nil )
618
+ default :return_path, val
619
+ end
620
+
621
+ # Sets the return path of the object
622
+ def return_path=( val )
623
+ header[:return_path] = val
624
+ end
625
+
626
+ # Returns the Sender value of the mail object, as a single string of an address
627
+ # spec. A sender per RFC 2822 must be a single address
628
+ #
629
+ # Example:
630
+ #
631
+ # mail.sender = 'Mikel <mikel@test.lindsaar.net>'
632
+ # mail.sender #=> 'mikel@test.lindsaar.net'
633
+ #
634
+ # Also allows you to set the value by passing a value as a parameter
635
+ #
636
+ # Example:
637
+ #
638
+ # mail.sender 'Mikel <mikel@test.lindsaar.net>'
639
+ # mail.sender #=> 'mikel@test.lindsaar.net'
640
+ def sender( val = nil )
641
+ default :sender, val
642
+ end
643
+
644
+ # Sets the Sender value of the mail object, pass in a string of the field
645
+ #
646
+ # Example:
647
+ #
648
+ # mail.sender = 'Mikel <mikel@test.lindsaar.net>'
649
+ # mail.sender #=> 'mikel@test.lindsaar.net'
650
+ def sender=( val )
651
+ header[:sender] = val
652
+ end
653
+
654
+ # Returns the decoded value of the subject field, as a single string.
655
+ #
656
+ # Example:
657
+ #
658
+ # mail.subject = "G'Day mate"
659
+ # mail.subject #=> "G'Day mate"
660
+ # mail.subject = '=?UTF-8?Q?This_is_=E3=81=82_string?='
661
+ # mail.subject #=> "This is あ string"
662
+ #
663
+ # Also allows you to set the value by passing a value as a parameter
664
+ #
665
+ # Example:
666
+ #
667
+ # mail.subject "G'Day mate"
668
+ # mail.subject #=> "G'Day mate"
669
+ def subject( val = nil )
670
+ default :subject, val
671
+ end
672
+
673
+ # Sets the Subject value of the mail object, pass in a string of the field
674
+ #
675
+ # Example:
676
+ #
677
+ # mail.subject = '=?UTF-8?Q?This_is_=E3=81=82_string?='
678
+ # mail.subject #=> "This is あ string"
679
+ def subject=( val )
680
+ header[:subject] = val
681
+ end
682
+
683
+ # Returns the To value of the mail object, either a single string of an address
684
+ # spec or an array of strings of address specs if there is more than one address
685
+ # in the To.
686
+ #
687
+ # Example:
688
+ #
689
+ # mail.to = 'Mikel <mikel@test.lindsaar.net>'
690
+ # mail.to #=> 'mikel@test.lindsaar.net'
691
+ # mail.to = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
692
+ # mail.to #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
693
+ #
694
+ # Also allows you to set the value by passing a value as a parameter
695
+ #
696
+ # Example:
697
+ #
698
+ # mail.to 'Mikel <mikel@test.lindsaar.net>'
699
+ # mail.to #=> 'mikel@test.lindsaar.net'
700
+ def to( val = nil )
701
+ default :to, val
702
+ end
703
+
704
+ # Sets the To value of the mail object, pass in a string of the field
705
+ #
706
+ # Example:
707
+ #
708
+ # mail.to = 'Mikel <mikel@test.lindsaar.net>'
709
+ # mail.to #=> 'mikel@test.lindsaar.net'
710
+ # mail.to = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
711
+ # mail.to #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
712
+ def to=( val )
713
+ header[:to] = val
714
+ end
715
+
716
+ # Returns the default value of the field requested as a symbol.
717
+ #
718
+ # Each header field has a :default method which returns the most common use case for
719
+ # that field, for example, the date field types will return a DateTime object when
720
+ # sent :default, the subject, or unstructured fields will return a decoded string of
721
+ # their value, the address field types will return a single addr_spec or an array of
722
+ # addr_specs if there is more than one.
723
+ def default( sym, val = nil )
724
+ if val
725
+ header[sym] = val
726
+ else
727
+ header[sym].default if header[sym]
728
+ end
729
+ end
730
+
155
731
  # Sets the body object of the message object.
156
732
  #
157
733
  # Example:
@@ -207,56 +783,7 @@ module Mail
207
783
  @body
208
784
  end
209
785
  end
210
-
211
- # Sets the to filed of the message header.
212
- #
213
- # Example:
214
- #
215
- # mail.to = '"Mikel Lindsaar" <mikel@test.lindsaar.net>'
216
- # mail.to #=> '"Mikel Lindsaar" <mikel@test.lindsaar.net>'
217
- def to=(value)
218
- header[:to] = value
219
- end
220
-
221
- # Returns the to field in the message header. Or, if passed
222
- # a parameter sets the value.
223
- #
224
- # Example:
225
- #
226
- # mail.to = '"M L" <mikel@test.lindsaar.net>'
227
- # mail.to.to_s #=> '"M L" <mikel@test.lindsaar.net>'
228
- # mail.to.formatted #=> ['"M L" <mikel@test.lindsaar.net>']
229
- # mail.to.addresses #=> ['mikel@test.lindsaar.net']
230
- def to(value = nil)
231
- value ? self.to = value : header[:to]
232
- end
233
-
234
- # Sets the from field in the message header.
235
- #
236
- # Example:
237
- #
238
- # mail.from = '"Mikel Lindsaar" <mikel@test.lindsaar.net>'
239
- # mail.from.to_s #=> '"Mikel Lindsaar" <mikel@test.lindsaar.net>'
240
- def from=(value)
241
- header[:from] = value
242
- end
243
-
244
- # Returns the from field in the message header. Or, if passed
245
- # a parameter sets the value.
246
- #
247
- # Example:
248
- #
249
- # mail.from = '"Mikel Lindsaar" <mikel@test.lindsaar.net>'
250
- # mail.from.to_s #=> '"Mikel Lindsaar" <mikel@test.lindsaar.net>'
251
- #
252
- # mail.from '"M L" <mikel@test.lindsaar.net>'
253
- # mail.from.to_s #=> '"M L" <mikel@test.lindsaar.net>'
254
- # mail.from.formatted #=> ['"M L" <mikel@test.lindsaar.net>']
255
- # mail.from.addresses #=> ['mikel@test.lindsaar.net']
256
- def from(value = nil)
257
- value ? self.from = value : header[:from]
258
- end
259
-
786
+
260
787
  # Returns the list of addresses this message should be sent to by
261
788
  # collecting the addresses off the to, cc and bcc fields.
262
789
  #
@@ -268,55 +795,31 @@ module Mail
268
795
  # mail.destinations.length #=> 3
269
796
  # mail.destinations.first #=> 'mikel@test.lindsaar.net'
270
797
  def destinations
271
- [to, cc, bcc].map { |f| f.addresses if f }.compact.flatten
798
+ [to_addrs, cc_addrs, bcc_addrs].compact.flatten
272
799
  end
273
800
 
274
801
  # Returns an array of addresses (the encoded value) in the From field,
275
802
  # if no From field, returns an empty array
276
803
  def from_addrs
277
- from ? from.formatted.compact.flatten : []
804
+ from ? [from].flatten : []
278
805
  end
279
806
 
280
807
  # Returns an array of addresses (the encoded value) in the To field,
281
808
  # if no To field, returns an empty array
282
809
  def to_addrs
283
- to ? to.formatted.compact.flatten : []
810
+ to ? [to].flatten : []
284
811
  end
285
812
 
286
813
  # Returns an array of addresses (the encoded value) in the Cc field,
287
814
  # if no Cc field, returns an empty array
288
815
  def cc_addrs
289
- cc ? cc.formatted.compact.flatten : []
816
+ cc ? [cc].flatten : []
290
817
  end
291
818
 
292
819
  # Returns an array of addresses (the encoded value) in the Bcc field,
293
820
  # if no Bcc field, returns an empty array
294
821
  def bcc_addrs
295
- bcc ? bcc.formatted.compact.flatten : []
296
- end
297
-
298
- # Sets the subject field in the message header.
299
- #
300
- # Example:
301
- #
302
- # mail.subject = 'This is the subject'
303
- # mail.subject.to_s #=> 'This is the subject'
304
- def subject=(value)
305
- header[:subject] = value
306
- end
307
-
308
- # Returns the subject field in the message header. Or, if passed
309
- # a parameter sets the value.
310
- #
311
- # Example:
312
- #
313
- # mail.subject = 'This is the subject'
314
- # mail.subject.to_s #=> 'This is the subject'
315
- #
316
- # mail.subject 'This is another subject'
317
- # mail.subject.to_s #=> 'This is another subject'
318
- def subject(value = nil)
319
- value ? self.subject = value : header[:subject]
822
+ bcc ? [bcc].flatten : []
320
823
  end
321
824
 
322
825
  # Allows you to add an arbitrary header
@@ -366,10 +869,10 @@ module Mail
366
869
  # Examples:
367
870
  #
368
871
  # mail.comments = 'These are some comments'
369
- # mail.comments.to_s #=> 'These are some comments'
872
+ # mail.comments #=> 'These are some comments'
370
873
  #
371
874
  # mail.comments 'These are other comments'
372
- # mail.comments.to_s #=> 'These are other comments'
875
+ # mail.comments #=> 'These are other comments'
373
876
  #
374
877
  #
375
878
  # mail.date = 'Tue, 1 Jul 2003 10:52:37 +0200'
@@ -380,10 +883,10 @@ module Mail
380
883
  #
381
884
  #
382
885
  # mail.resent_msg_id = '<1234@resent_msg_id.lindsaar.net>'
383
- # mail.resent_msg_id.to_s #=> '<1234@resent_msg_id.lindsaar.net>'
886
+ # mail.resent_msg_id #=> '<1234@resent_msg_id.lindsaar.net>'
384
887
  #
385
888
  # mail.resent_msg_id '<4567@resent_msg_id.lindsaar.net>'
386
- # mail.resent_msg_id.to_s #=> '<4567@resent_msg_id.lindsaar.net>'
889
+ # mail.resent_msg_id #=> '<4567@resent_msg_id.lindsaar.net>'
387
890
  def method_missing(name, *args, &block)
388
891
  #:nodoc:
389
892
  # Only take the structured fields, as we could take _anything_ really
@@ -476,7 +979,7 @@ module Mail
476
979
  #
477
980
  # Otherwise raises a warning
478
981
  def add_content_type
479
- header['Content-Type'] = 'text/plain'
982
+ header[:content_type] = 'text/plain'
480
983
  end
481
984
 
482
985
  # Adds a content type and charset if the body is US-ASCII
@@ -484,11 +987,11 @@ module Mail
484
987
  # Otherwise raises a warning
485
988
  def add_charset
486
989
  if body.only_us_ascii?
487
- content_type.parameters['charset'] = 'US-ASCII'
990
+ header[:content_type].parameters['charset'] = 'US-ASCII'
488
991
  else
489
992
  warning = "Non US-ASCII detected and no charset defined.\nDefaulting to UTF-8, set your own if this is incorrect.\nCalled from:\n#{caller.join("\n")}"
490
993
  STDERR.puts(warning)
491
- content_type.parameters['charset'] = 'UTF-8'
994
+ header[:content_type].parameters['charset'] = 'UTF-8'
492
995
  end
493
996
  end
494
997
 
@@ -497,11 +1000,11 @@ module Mail
497
1000
  # Otherwise raises a warning
498
1001
  def add_content_transfer_encoding
499
1002
  if body.only_us_ascii?
500
- header['Content-Transfer-Encoding'] = '7bit'
1003
+ header[:content_transfer_encoding] = '7bit'
501
1004
  else
502
1005
  warning = "Non US-ASCII detected and no content-transfer-encoding defined.\nDefaulting to 8bit, set your own if this is incorrect.\nCalled from:\n#{caller.join("\n")}"
503
1006
  STDERR.puts(warning)
504
- header['Content-Transfer-Encoding'] = '8bit'
1007
+ header[:content_transfer_encoding] = '8bit'
505
1008
  end
506
1009
  end
507
1010
 
@@ -515,21 +1018,26 @@ module Mail
515
1018
  content_transfer_encoding
516
1019
  end
517
1020
 
518
- # Returns the content type
1021
+ # Returns the mime type of part we are on, this is taken from the content-type header
1022
+ def mime_type
1023
+ content_type ? header[:content_type].string : nil
1024
+ end
1025
+
519
1026
  def message_content_type
520
- content_type ? content_type.content_type : nil
1027
+ STDERR.puts(":message_content_type is deprecated in Mail 1.4.3. Please use mime_type\n#{caller}")
1028
+ mime_type
521
1029
  end
522
1030
 
523
1031
  # Returns the character set defined in the content type field
524
1032
  def charset
525
- content_type ? content_type.parameters['charset'] : nil
1033
+ content_type ? content_type_parameters['charset'] : nil
526
1034
  end
527
1035
 
528
1036
  # Sets the charset to the supplied value. Will set the content type to text/plain if
529
1037
  # it does not already exist
530
1038
  def charset=(value)
531
1039
  if content_type
532
- content_type.parameters['charset'] = value
1040
+ content_type_parameters['charset'] = value
533
1041
  else
534
1042
  self.content_type ['text', 'plain', {'charset' => value}]
535
1043
  end
@@ -537,17 +1045,23 @@ module Mail
537
1045
 
538
1046
  # Returns the main content type
539
1047
  def main_type
540
- has_content_type? ? content_type.main_type : nil
1048
+ has_content_type? ? header[:content_type].main_type : nil
541
1049
  end
542
1050
 
543
1051
  # Returns the sub content type
544
1052
  def sub_type
545
- has_content_type? ? content_type.sub_type : nil
1053
+ has_content_type? ? header[:content_type].sub_type : nil
546
1054
  end
547
1055
 
548
1056
  # Returns the content type parameters
549
1057
  def mime_parameters
550
- has_content_type? ? content_type.parameters : nil
1058
+ STDERR.puts(':mime_parameters is deprecated in Mail 1.4.3, please use :content_type_parameters instead')
1059
+ content_type_parameters
1060
+ end
1061
+
1062
+ # Returns the content type parameters
1063
+ def content_type_parameters
1064
+ has_content_type? ? header[:content_type].parameters : nil
551
1065
  end
552
1066
 
553
1067
  # Returns true if the message is multipart
@@ -562,7 +1076,7 @@ module Mail
562
1076
 
563
1077
  # Returns true if the message is a multipart/report; report-type=delivery-status;
564
1078
  def delivery_status_report?
565
- multipart_report? && mime_parameters['report-type'] =~ /^delivery-status$/i
1079
+ multipart_report? && content_type_parameters['report-type'] =~ /^delivery-status$/i
566
1080
  end
567
1081
 
568
1082
  # returns the part in a multipart/report email that has the content-type delivery-status
@@ -600,7 +1114,7 @@ module Mail
600
1114
 
601
1115
  # Returns the current boundary for this message part
602
1116
  def boundary
603
- mime_parameters ? mime_parameters['boundary'] : nil
1117
+ content_type_parameters ? content_type_parameters['boundary'] : nil
604
1118
  end
605
1119
 
606
1120
  # Returns an array of parts in the message
@@ -829,7 +1343,7 @@ module Mail
829
1343
 
830
1344
  def add_encoding_to_body
831
1345
  unless content_transfer_encoding.blank?
832
- body.encoding = content_transfer_encoding.decoded
1346
+ body.encoding = content_transfer_encoding
833
1347
  end
834
1348
  end
835
1349
 
@@ -907,7 +1421,7 @@ module Mail
907
1421
  parse_message
908
1422
  separate_parts if multipart?
909
1423
  if filename = attachment?
910
- encoding = content_transfer_encoding.encoding if content_transfer_encoding
1424
+ encoding = header[:content_transfer_encoding].encoding if content_transfer_encoding
911
1425
  @attachment = Mail::Attachment.new(:filename => filename,
912
1426
  :data => body.encoded,
913
1427
  :encoding => encoding)
@@ -917,12 +1431,12 @@ module Mail
917
1431
  # Returns the filename of the attachment (if it exists) or returns nil
918
1432
  def find_attachment
919
1433
  case
920
- when content_type && content_type.filename
921
- filename = content_type.filename
922
- when content_disposition && content_disposition.filename
923
- filename = content_disposition.filename
924
- when content_location && content_location.location
925
- filename = content_location.location
1434
+ when content_type && header[:content_type].filename
1435
+ filename = header[:content_type].filename
1436
+ when content_disposition && header[:content_disposition].filename
1437
+ filename = header[:content_disposition].filename
1438
+ when content_location && header[:content_location].location
1439
+ filename = header[:content_location].location
926
1440
  else
927
1441
  filename = nil
928
1442
  end