Skip to content
Browse files

Version bump to 1.5.0 - API change on Message#field_name

  • Loading branch information...
1 parent 85e8112 commit e6de07ce35b4adc9d2ccfc3f9e9364279481de36 @mikel committed Jan 3, 2010
Showing with 1,114 additions and 517 deletions.
  1. +14 −0 CHANGELOG.rdoc
  2. +6 −6 README.rdoc
  3. +1 −1 Rakefile
  4. +2 −2 lib/mail/body.rb
  5. +1 −1 lib/mail/field.rb
  6. +5 −6 lib/mail/fields/bcc_field.rb
  7. +5 −4 lib/mail/fields/cc_field.rb
  8. +3 −7 lib/mail/fields/comments_field.rb
  9. +8 −0 lib/mail/fields/common/common_address.rb
  10. +4 −0 lib/mail/fields/common/common_date.rb
  11. +5 −1 lib/mail/fields/common/common_field.rb
  12. +8 −0 lib/mail/fields/common/common_message_id.rb
  13. +1 −1 lib/mail/fields/content_transfer_encoding_field.rb
  14. +4 −0 lib/mail/fields/content_type_field.rb
  15. +7 −7 lib/mail/fields/date_field.rb
  16. +5 −4 lib/mail/fields/from_field.rb
  17. +2 −3 lib/mail/fields/in_reply_to_field.rb
  18. +4 −0 lib/mail/fields/keywords_field.rb
  19. +3 −4 lib/mail/fields/message_id_field.rb
  20. +2 −3 lib/mail/fields/references_field.rb
  21. +5 −4 lib/mail/fields/reply_to_field.rb
  22. +5 −4 lib/mail/fields/resent_bcc_field.rb
  23. +5 −4 lib/mail/fields/resent_cc_field.rb
  24. +9 −1 lib/mail/fields/resent_date_field.rb
  25. +6 −5 lib/mail/fields/resent_from_field.rb
  26. +1 −1 lib/mail/fields/resent_sender_field.rb
  27. +5 −4 lib/mail/fields/resent_to_field.rb
  28. +6 −5 lib/mail/fields/sender_field.rb
  29. +4 −0 lib/mail/fields/structured_field.rb
  30. +5 −4 lib/mail/fields/to_field.rb
  31. +4 −0 lib/mail/fields/unstructured_field.rb
  32. +4 −3 lib/mail/header.rb
  33. +619 −105 lib/mail/message.rb
  34. +1 −1 lib/mail/network/delivery_methods/smtp.rb
  35. +14 −3 lib/mail/utilities.rb
  36. +2 −2 lib/mail/version.rb
  37. +17 −17 spec/mail/body_spec.rb
  38. +73 −73 spec/mail/example_emails_spec.rb
  39. +2 −2 spec/mail/field_spec.rb
  40. +3 −3 spec/mail/fields/common/common_date_spec.rb
  41. +5 −5 spec/mail/fields/date_field_spec.rb
  42. +11 −3 spec/mail/fields/resent_date_field_spec.rb
  43. +4 −4 spec/mail/mail_spec.rb
  44. +207 −207 spec/mail/message_spec.rb
  45. +2 −2 spec/mail/network/deliverable_spec.rb
  46. +3 −3 spec/mail/part_spec.rb
  47. +2 −2 spec/mail/round_tripping_spec.rb
View
14 CHANGELOG.rdoc
@@ -1,3 +1,17 @@
+== Sun Jan 3 00:08:06 UTC 2010 Mikel Lindsaar <raasdnil@gmail.com>
+
+* Version bump to 1.5.0
+
+* Major API change in Message#field_name. This WILL break your applications that use Mail. Message#field_name now returns good, intelligent, default values. You can still access the field object by calling Message#[:field_name] or Message#['field_name'].
+
+== Sat Jan 2 04:12:53 UTC 2010 Mikel Lindsaar <raasdnil@gmail.com>
+
+* Message-ID, Content-ID, References et al, now return the default value of the message ID without the angle brackets, as per RFC 2822, "Semantically, the angle bracket characters are not part of the msg-id; the msg-id is what is contained between the two angle bracket characters."
+
+* Message class now has getter and setter methods for all the supported field types explicitly. This allows us to return a "default" value for all fields.
+
+* All address fields, when called from Message#to or Message#from or the like, return either a string of the address spec (mikel@test.lindsaar.net) if it is a single entry, or an array of address specs if there is more than one ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+
== Mon 28 Dec 2009 01:21:52 UTC Mikel Lindsaar <raasdnil@gmail.com>
* Added sorting of parts, default is text/plain, then text/enriched and text/html. Access through Body#set_sort_order and Body#sort_parts! (called from Body#encode automatically)
View
12 README.rdoc
@@ -290,12 +290,12 @@ Or even all emails:
mail.envelope.from #=> 'mikel@test.lindsaar.net'
mail.from.addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
mail.sender.address #=> 'mikel@test.lindsaar.net'
- mail.to.addresses #=> ['bob@test.lindsaar.net']
- mail.cc.addresses #=> ['sam@test.lindsaar.net']
- mail.subject.to_s #=> "This is the subject"
+ mail.to #=> 'bob@test.lindsaar.net'
+ mail.cc #=> 'sam@test.lindsaar.net'
+ mail.subject #=> "This is the subject"
mail.date.to_s #=> '21 Nov 1997 09:55:06 -0600'
mail.message_id #=> '<4D6AA7EB.6490534@xxx.xxx>'
- mail.body #=> 'This is the body of the email...
+ mail.body.decoded #=> 'This is the body of the email...
Many more methods available.
@@ -311,8 +311,8 @@ Many more methods available.
mail.epilogue #=> "Text after the last part"
mail.parts.map { |p| p.content_type } #=> ['text/plain', 'application/pdf']
mail.parts.map { |p| p.class } #=> [Mail::Message, Mail::Message]
- mail.parts[0].mime_parameters #=> {'charset' => 'ISO-8859-1'}
- mail.parts[1].mime_parameters #=> {'name' => 'my.pdf'}
+ mail.parts[0].content_type_parameters #=> {'charset' => 'ISO-8859-1'}
+ mail.parts[1].content_type_parameters #=> {'name' => 'my.pdf'}
Mail generates a tree of parts. Each message has many or no parts. Each part
is another message which can have many or no parts.
View
2 Rakefile
@@ -12,7 +12,7 @@ require 'bundler'
spec = Gem::Specification.new do |s|
s.name = "mail"
- s.version = "1.4.3"
+ s.version = "1.5.0"
s.author = "Mike Lindsaar"
s.email = "raasdnil@gmail.com"
s.homepage = "http://github.com/mikel/mail"
View
4 lib/mail/body.rb
@@ -108,8 +108,8 @@ def sort_parts!
# OK, 10000 is arbitrary... if anyone actually wants to explicitly sort 10000 parts of a
# single email message... please show me a use case and I'll put more work into this method,
# in the meantime, it works :)
- a_order = order.index(a.content_type.string.downcase) || 10000
- b_order = order.index(b.content_type.string.downcase) || 10000
+ a_order = order.index(a[:content_type].string.downcase) || 10000
+ b_order = order.index(b[:content_type].string.downcase) || 10000
a_order <=> b_order
end
end
View
2 lib/mail/field.rb
@@ -69,7 +69,7 @@ def initialize(name, value = nil)
case
when name =~ /:/ && value.blank? # Field.new("field-name: field data")
name, value = split(name)
- create_field(name, value.to_s)
+ create_field(name, value)
when name !~ /:/ && value.blank? # Field.new("field-name")
create_field(name, nil)
else # Field.new("field-name", "value")
View
11 lib/mail/fields/bcc_field.rb
@@ -16,16 +16,15 @@
#
# mail = Mail.new
# mail.bcc = 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
-# mail.bcc #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::BccField:0x180e1c4
+# mail.bcc #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
# mail[:bcc] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::BccField:0x180e1c4
# mail['bcc'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::BccField:0x180e1c4
# mail['Bcc'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::BccField:0x180e1c4
#
-# mail.bcc.to_s #=> '' # Bcc field does not get output into an email
-# mail.bcc.encoded #=> '' # Bcc field does not get output into an email
-# mail.bcc.decoded #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
-# mail.bcc.addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
-# mail.bcc.formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
+# mail[:bcc].encoded #=> '' # Bcc field does not get output into an email
+# mail[:bcc].decoded #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+# mail[:bcc].addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+# mail[:bcc].formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
#
module Mail
class BccField < StructuredField
View
9 lib/mail/fields/cc_field.rb
@@ -16,14 +16,15 @@
#
# mail = Mail.new
# mail.cc = 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
-# mail.cc #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CcField:0x180e1c4
+# mail.cc #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
# mail[:cc] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CcField:0x180e1c4
# mail['cc'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CcField:0x180e1c4
# mail['Cc'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CcField:0x180e1c4
#
-# mail.cc.to_s #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
-# mail.cc.addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
-# mail.cc.formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
+# mail[:cc].encoded #=> 'Cc: Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net\r\n'
+# mail[:cc].decoded #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+# mail[:cc].addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+# mail[:cc].formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
#
module Mail
class CcField < StructuredField
View
10 lib/mail/fields/comments_field.rb
@@ -15,19 +15,15 @@
#
# mail = Mail.new
# mail.comments = 'This is a comment'
-# mail.comments #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CommentsField:0x180e1c4
+# mail.comments #=> 'This is a comment'
# mail[:comments] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CommentsField:0x180e1c4
# mail['comments'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CommentsField:0x180e1c4
# mail['comments'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CommentsField:0x180e1c4
#
-# mail.comments.to_s #=> 'This is a comment'
-#
# mail.comments = "This is another comment"
-# mail.comments.map { |c| c.to_s }
+# mail[:comments].map { |c| c.to_s }
# #=> ['This is a comment', "This is another comment"]
-# mail.comments.to_s # Probably not what you want to do in this case
-# #=> "This is a commentThis is another comment"
-#
+#
module Mail
class CommentsField < UnstructuredField
View
8 lib/mail/fields/common/common_address.rb
@@ -44,6 +44,14 @@ def group_names # :nodoc:
tree.group_names
end
+ def default
+ if addresses.length == 1
+ addresses[0]
+ else
+ addresses
+ end
+ end
+
private
def do_encode(field_name)
View
4 lib/mail/fields/common/common_date.rb
@@ -9,6 +9,10 @@ def date_time
::DateTime.parse("#{element.date_string} #{element.time_string}")
end
+ def default
+ date_time
+ end
+
private
def do_encode(field_name)
View
6 lib/mail/fields/common/common_field.rb
@@ -31,6 +31,10 @@ def to_s
decoded
end
+ def default
+ decoded
+ end
+
def field_length
@length ||= name.length + value.length + ': '.length
end
@@ -41,7 +45,7 @@ def responsible_for?( val )
private
- def strip_field(field_name, string)
+ def strip_field(field_name, string)
string.to_s.gsub(/#{field_name}:\s+/i, '')
end
View
8 lib/mail/fields/common/common_message_id.rb
@@ -24,6 +24,14 @@ def message_ids
element.message_ids
end
+ def default
+ if message_ids.length == 1
+ message_ids[0]
+ else
+ message_ids
+ end
+ end
+
private
def do_encode(field_name)
View
2 lib/mail/fields/content_transfer_encoding_field.rb
@@ -33,6 +33,6 @@ def encoded
def decoded
value
end
-
+
end
end
View
4 lib/mail/fields/content_type_field.rb
@@ -45,6 +45,10 @@ def string
"#{main_type}/#{sub_type}"
end
+ def default
+ decoded
+ end
+
alias :content_type :string
def parameters
View
14 lib/mail/fields/date_field.rb
@@ -15,13 +15,11 @@
#
# mail = Mail.new
# mail.date = 'Mon, 24 Nov 1997 14:22:01 -0800'
-# mail.date #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::DateField:0x180e1c4
-# mail[:date] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::DateField:0x180e1c4
-# mail['date'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::DateField:0x180e1c4
-# mail['Date'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::DateField:0x180e1c4
-#
+# mail.date #=> #<DateTime: 211747170121/86400,-1/3,2299161>
# mail.date.to_s #=> 'Mon, 24 Nov 1997 14:22:01 -0800'
-# mail.date.date_time #=> #<DateTime: 211747170121/86400,-1/3,2299161>
+# mail[:date] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::DateField:0x180e1c4
+# mail['date'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::DateField:0x180e1c4
+# mail['Date'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::DateField:0x180e1c4
#
module Mail
class DateField < StructuredField
@@ -37,7 +35,9 @@ def initialize(*args)
self.value = Time.now.strftime('%a, %d %b %Y %H:%M:%S %z')
self
else
- super(CAPITALIZED_FIELD, strip_field(FIELD_NAME, args.last))
+ value = strip_field(FIELD_NAME, args.last)
+ value = ::DateTime.parse(value.to_s).strftime('%a, %d %b %Y %H:%M:%S %z')
+ super(CAPITALIZED_FIELD, value)
end
end
View
9 lib/mail/fields/from_field.rb
@@ -16,14 +16,15 @@
#
# mail = Mail.new
# mail.from = 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
-# mail.from #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::FromField:0x180e1c4
+# mail.from #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
# mail[:from] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::FromField:0x180e1c4
# mail['from'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::FromField:0x180e1c4
# mail['From'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::FromField:0x180e1c4
#
-# mail.from.to_s #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
-# mail.from.addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
-# mail.from.formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
+# mail[:from].encoded #=> 'from: Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net\r\n'
+# mail[:from].decoded #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+# mail[:from].addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+# mail[:from].formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
#
module Mail
class FromField < StructuredField
View
5 lib/mail/fields/in_reply_to_field.rb
@@ -19,13 +19,12 @@
#
# mail = Mail.new
# mail.in_reply_to = '<F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom>'
-# mail.in_reply_to #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::InReplyToField:0x180e1c4
+# mail.in_reply_to #=> '<F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom>'
# mail[:in_reply_to] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::InReplyToField:0x180e1c4
# mail['in_reply_to'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::InReplyToField:0x180e1c4
# mail['In-Reply-To'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::InReplyToField:0x180e1c4
#
-# mail.in_reply_to.to_s #=> '<F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom>'
-# mail.in_reply_to.message_ids #=> ['F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom']
+# mail[:in_reply_to].message_ids #=> ['F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom']
#
module Mail
class InReplyToField < StructuredField
View
4 lib/mail/fields/keywords_field.rb
@@ -26,6 +26,10 @@ def encoded
def decoded
keywords.join(', ')
end
+
+ def default
+ keywords
+ end
end
end
View
7 lib/mail/fields/message_id_field.rb
@@ -20,14 +20,13 @@
#
# mail = Mail.new
# mail.message_id = '<F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom>'
-# mail.message_id #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::MessageIdField:0x180e1c4
+# mail.message_id #=> '<F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom>'
# mail[:message_id] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::MessageIdField:0x180e1c4
# mail['message_id'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::MessageIdField:0x180e1c4
# mail['Message-ID'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::MessageIdField:0x180e1c4
#
-# mail.message_id.to_s #=> '<F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom>'
-# mail.message_id.message_id #=> 'F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom'
-# mail.message_id.message_ids #=> ['F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom']
+# mail[:message_id].message_id #=> 'F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom'
+# mail[:message_id].message_ids #=> ['F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom']
#
module Mail
class MessageIdField < StructuredField
View
5 lib/mail/fields/references_field.rb
@@ -19,13 +19,12 @@
#
# mail = Mail.new
# mail.references = '<F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom>'
-# mail.references #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ReferencesField:0x180e1c4
+# mail.references #=> '<F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom>'
# mail[:references] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ReferencesField:0x180e1c4
# mail['references'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ReferencesField:0x180e1c4
# mail['References'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ReferencesField:0x180e1c4
#
-# mail.references.to_s #=> '<F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom>'
-# mail.references.message_ids #=> ['F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom']
+# mail[:references].message_ids #=> ['F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom']
#
module Mail
class ReferencesField < StructuredField
View
9 lib/mail/fields/reply_to_field.rb
@@ -16,14 +16,15 @@
#
# mail = Mail.new
# mail.reply_to = 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
-# mail.reply_to #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ReplyToField:0x180e1c4
+# mail.reply_to #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
# mail[:reply_to] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ReplyToField:0x180e1c4
# mail['reply-to'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ReplyToField:0x180e1c4
# mail['Reply-To'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ReplyToField:0x180e1c4
#
-# mail.reply_to.to_s #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
-# mail.reply_to.addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
-# mail.reply_to.formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
+# mail[:reply_to].encoded #=> 'Reply-To: Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net\r\n'
+# mail[:reply_to].decoded #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+# mail[:reply_to].addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+# mail[:reply_to].formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
#
module Mail
class ReplyToField < StructuredField
View
9 lib/mail/fields/resent_bcc_field.rb
@@ -16,14 +16,15 @@
#
# mail = Mail.new
# mail.resent_bcc = 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
-# mail.resent_bcc #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ResentBccField:0x180e1c4
+# mail.resent_bcc #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
# mail[:resent_bcc] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ResentBccField:0x180e1c4
# mail['resent-bcc'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ResentBccField:0x180e1c4
# mail['Resent-Bcc'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ResentBccField:0x180e1c4
#
-# mail.resent_bcc.to_s #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
-# mail.resent_bcc.addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
-# mail.resent_bcc.formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
+# mail[:resent_bcc].encoded #=> 'Resent-Bcc: Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net\r\n'
+# mail[:resent_bcc].decoded #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+# mail[:resent_bcc].addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+# mail[:resent_bcc].formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
#
module Mail
class ResentBccField < StructuredField
View
9 lib/mail/fields/resent_cc_field.rb
@@ -16,14 +16,15 @@
#
# mail = Mail.new
# mail.resent_cc = 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
-# mail.resent_cc #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ResentCcField:0x180e1c4
+# mail.resent_cc #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
# mail[:resent_cc] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ResentCcField:0x180e1c4
# mail['resent-cc'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ResentCcField:0x180e1c4
# mail['Resent-Cc'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ResentCcField:0x180e1c4
#
-# mail.resent_cc.to_s #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
-# mail.resent_cc.addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
-# mail.resent_cc.formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
+# mail[:resent_cc].encoded #=> 'Resent-Cc: Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net\r\n'
+# mail[:resent_cc].decoded #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+# mail[:resent_cc].addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+# mail[:resent_cc].formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
#
module Mail
class ResentCcField < StructuredField
View
10 lib/mail/fields/resent_date_field.rb
@@ -10,7 +10,15 @@ class ResentDateField < StructuredField
CAPITALIZED_FIELD = 'Resent-Date'
def initialize(*args)
- super(CAPITALIZED_FIELD, strip_field(FIELD_NAME, args.last))
+ if args.last.blank?
+ self.name = CAPITALIZED_FIELD
+ self.value = Time.now.strftime('%a, %d %b %Y %H:%M:%S %z')
+ self
+ else
+ value = strip_field(FIELD_NAME, args.last)
+ value = ::DateTime.parse(value.to_s).strftime('%a, %d %b %Y %H:%M:%S %z')
+ super(CAPITALIZED_FIELD, value)
+ end
end
def encoded
View
11 lib/mail/fields/resent_from_field.rb
@@ -13,17 +13,18 @@
# addresses and groups of addresses.
#
# == Examples:
-#
+#
# mail = Mail.new
# mail.resent_from = 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
-# mail.resent_from #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ResentFromField:0x180e1c4
+# mail.resent_from #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
# mail[:resent_from] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ResentFromField:0x180e1c4
# mail['resent-from'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ResentFromField:0x180e1c4
# mail['Resent-From'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ResentFromField:0x180e1c4
#
-# mail.resent_from.to_s #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
-# mail.resent_from.addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
-# mail.resent_from.formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
+# mail[:resent_from].encoded #=> 'Resent-From: Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net\r\n'
+# mail[:resent_from].decoded #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+# mail[:resent_from].addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+# mail[:resent_from].formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
#
module Mail
class ResentFromField < StructuredField
View
2 lib/mail/fields/resent_sender_field.rb
@@ -38,7 +38,7 @@ def initialize(*args)
end
def addresses
- [address]
+ [address.address]
end
def address
View
9 lib/mail/fields/resent_to_field.rb
@@ -16,14 +16,15 @@
#
# mail = Mail.new
# mail.resent_to = 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
-# mail.resent_to #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ResentToField:0x180e1c4
+# mail.resent_to #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
# mail[:resent_to] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ResentToField:0x180e1c4
# mail['resent-to'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ResentToField:0x180e1c4
# mail['Resent-To'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ResentToField:0x180e1c4
#
-# mail.resent_to.to_s #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
-# mail.resent_to.addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
-# mail.resent_to.formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
+# mail[:resent_to].encoded #=> 'Resent-To: Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net\r\n'
+# mail[:resent_to].decoded #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+# mail[:resent_to].addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+# mail[:resent_to].formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
#
module Mail
class ResentToField < StructuredField
View
11 lib/mail/fields/sender_field.rb
@@ -16,14 +16,15 @@
#
# mail = Mail.new
# mail.sender = 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
-# mail.sender #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::SenderField:0x180e1c4
+# mail.sender #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
# mail[:sender] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::SenderField:0x180e1c4
# mail['sender'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::SenderField:0x180e1c4
# mail['Sender'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::SenderField:0x180e1c4
#
-# mail.sender.to_s #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
-# mail.sender.addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
-# mail.sender.formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
+# mail[:sender].encoded #=> 'Sender: Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net\r\n'
+# mail[:sender].decoded #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+# mail[:sender].addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+# mail[:sender].formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
#
module Mail
class SenderField < StructuredField
@@ -38,7 +39,7 @@ def initialize(*args)
end
def addresses
- [address]
+ [address.address]
end
def address
View
4 lib/mail/fields/structured_field.rb
@@ -28,5 +28,9 @@ def initialize(*args)
self
end
+ def default
+ decoded
+ end
+
end
end
View
9 lib/mail/fields/to_field.rb
@@ -16,14 +16,15 @@
#
# mail = Mail.new
# mail.to = 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
-# mail.to #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ToField:0x180e1c4
+# mail.to #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
# mail[:to] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ToField:0x180e1c4
# mail['to'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ToField:0x180e1c4
# mail['To'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ToField:0x180e1c4
#
-# mail.to.to_s #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
-# mail.to.addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
-# mail.to.formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
+# mail[:to].encoded #=> 'To: Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net\r\n'
+# mail[:to].decoded #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+# mail[:to].addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+# mail[:to].formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
#
module Mail
class ToField < StructuredField
View
4 lib/mail/fields/unstructured_field.rb
@@ -31,6 +31,10 @@ def decoded
do_decode
end
+ def default
+ decoded
+ end
+
private
def do_encode(name)
View
7 lib/mail/header.rb
@@ -107,6 +107,7 @@ def fields=(unfolded_fields)
# h['To'] #=> 'mikel@me.com'
# h['X-Mail-SPAM'] #=> ['15', '20']
def [](name)
+ name = dasherize(name)
selected = select_field_for(name)
case
when selected.length > 1
@@ -132,16 +133,16 @@ def [](name)
# h['X-Mail-SPAM'] = nil
# h['X-Mail-SPAM'] # => nil
def []=(name, value)
+ name = dasherize(name)
selected = select_field_for(name)
-
+
case
# User wants to delete the field
when !selected.blank? && value == nil
fields.delete_if { |f| selected.include?(f) }
# User wants to change the field
when !selected.blank? && limited_field?(name)
-
selected.first.update(name, value)
# User wants to create the field
@@ -223,7 +224,7 @@ def split_header
end
def select_field_for(name)
- fields.select { |f| f.responsible_for?(name) }
+ fields.select { |f| f.responsible_for?(name.to_s) }
end
def limited_field?(name)
View
724 lib/mail/message.rb
@@ -152,6 +152,582 @@ def headers(hash = {})
end
end
+ # Returns the Bcc value of the mail object, either a single string of an address
+ # spec or an array of strings of address specs if there is more than one address
+ # in the Bcc.
+ #
+ # Example:
+ #
+ # mail.bcc = 'Mikel <mikel@test.lindsaar.net>'
+ # mail.bcc #=> 'mikel@test.lindsaar.net'
+ # mail.bcc = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+ # mail.bcc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+ #
+ # Also allows you to set the value by passing a value as a parameter
+ #
+ # Example:
+ #
+ # mail.bcc 'Mikel <mikel@test.lindsaar.net>'
+ # mail.bcc #=> 'mikel@test.lindsaar.net'
+ def bcc( val = nil )
+ default :bcc, val
+ end
+
+ # Sets the Bcc value of the mail object, pass in a string of the field
+ #
+ # Example:
+ #
+ # mail.bcc = 'Mikel <mikel@test.lindsaar.net>'
+ # mail.bcc #=> 'mikel@test.lindsaar.net'
+ # mail.bcc = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+ # mail.bcc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+ def bcc=( val )
+ header[:bcc] = val
+ end
+
+ # Returns the Cc value of the mail object, either a single string of an address
+ # spec or an array of strings of address specs if there is more than one address
+ # in the Cc.
+ #
+ # Example:
+ #
+ # mail.cc = 'Mikel <mikel@test.lindsaar.net>'
+ # mail.cc #=> 'mikel@test.lindsaar.net'
+ # mail.cc = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+ # mail.cc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+ #
+ # Also allows you to set the value by passing a value as a parameter
+ #
+ # Example:
+ #
+ # mail.cc 'Mikel <mikel@test.lindsaar.net>'
+ # mail.cc #=> 'mikel@test.lindsaar.net'
+ def cc( val = nil )
+ default :cc, val
+ end
+
+ # Sets the Cc value of the mail object, pass in a string of the field
+ #
+ # Example:
+ #
+ # mail.cc = 'Mikel <mikel@test.lindsaar.net>'
+ # mail.cc #=> 'mikel@test.lindsaar.net'
+ # mail.cc = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+ # mail.cc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+ def cc=( val )
+ header[:cc] = val
+ end
+
+ def comments( val = nil )
+ default :comments, val
+ end
+
+ def comments=( val )
+ header[:comments] = val
+ end
+
+ def content_description( val = nil )
+ default :content_description, val
+ end
+
+ def content_description=( val )
+ header[:content_description] = val
+ end
+
+ def content_disposition( val = nil )
+ default :content_disposition, val
+ end
+
+ def content_disposition=( val )
+ header[:content_disposition] = val
+ end
+
+ def content_id( val = nil )
+ default :content_id, val
+ end
+
+ def content_id=( val )
+ header[:content_id] = val
+ end
+
+ def content_location( val = nil )
+ default :content_location, val
+ end
+
+ def content_location=( val )
+ header[:content_location] = val
+ end
+
+ def content_transfer_encoding( val = nil )
+ default :content_transfer_encoding, val
+ end
+
+ def content_transfer_encoding=( val )
+ header[:content_transfer_encoding] = val
+ end
+
+ def content_type( val = nil )
+ default :content_type, val
+ end
+
+ def content_type=( val )
+ header[:content_type] = val
+ end
+
+ def date( val = nil )
+ default :date, val
+ end
+
+ def date=( val )
+ header[:date] = val
+ end
+
+ # Returns the From value of the mail object, either a single string of an address
+ # spec or an array of strings of address specs if there is more than one address
+ # in the From.
+ #
+ # Example:
+ #
+ # mail.from = 'Mikel <mikel@test.lindsaar.net>'
+ # mail.from #=> 'mikel@test.lindsaar.net'
+ # mail.from = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+ # mail.from #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+ #
+ # Also allows you to set the value by passing a value as a parameter
+ #
+ # Example:
+ #
+ # mail.from 'Mikel <mikel@test.lindsaar.net>'
+ # mail.from #=> 'mikel@test.lindsaar.net'
+ def from( val = nil )
+ default :from, val
+ end
+
+ # Sets the From value of the mail object, pass in a string of the field
+ #
+ # Example:
+ #
+ # mail.from = 'Mikel <mikel@test.lindsaar.net>'
+ # mail.from #=> 'mikel@test.lindsaar.net'
+ # mail.from = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+ # mail.from #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+ def from=( val )
+ header[:from] = val
+ end
+
+ def in_reply_to( val = nil )
+ default :in_reply_to, val
+ end
+
+ def in_reply_to=( val )
+ header[:in_reply_to] = val
+ end
+
+ def keywords( val = nil )
+ default :keywords, val
+ end
+
+ def keywords=( val )
+ header[:keywords] = val
+ end
+
+ # Returns the Message-ID of the mail object. Note, per RFC 2822 the Message ID
+ # consists of what is INSIDE the < > usually seen in the mail header, so this method
+ # will return only what is inside.
+ #
+ # Example:
+ #
+ # mail.message_id = '<1234@message.id>'
+ # mail.message_id #=> '1234@message.id'
+ #
+ # Also allows you to set the Message-ID by passing a string as a parameter
+ #
+ # mail.message_id '<1234@message.id>'
+ # mail.message_id #=> '1234@message.id'
+ def message_id( val = nil )
+ default :message_id, val
+ end
+
+ # Sets the Message-ID. Note, per RFC 2822 the Message ID consists of what is INSIDE
+ # the < > usually seen in the mail header, so this method will return only what is inside.
+ #
+ # mail.message_id = '<1234@message.id>'
+ # mail.message_id #=> '1234@message.id'
+ def message_id=( val )
+ header[:message_id] = val
+ end
+
+ # Returns the mime version of the email as a string
+ #
+ # Example:
+ #
+ # mail.mime_version = '1.0'
+ # mail.mime_version #=> '1.0'
+ #
+ # Also allows you to set the mime version by passing a string as a parameter.
+ #
+ # Example:
+ #
+ # mail.mime_version '1.0'
+ # mail.mime_version #=> '1.0'
+ def mime_version( val = nil )
+ default :mime_version, val
+ end
+
+ # Sets the mime version of the email by accepting a string
+ #
+ # Example:
+ #
+ # mail.mime_version = '1.0'
+ # mail.mime_version #=> '1.0'
+ def mime_version=( val )
+ header[:mime_version] = val
+ end
+
+ def received( val = nil )
+ if val
+ header[:received] = val
+ else
+ header[:received]
+ end
+ end
+
+ def received=( val )
+ header[:received] = val
+ end
+
+ def references( val = nil )
+ default :references, val
+ end
+
+ def references=( val )
+ header[:references] = val
+ end
+
+ # Returns the Reply-To value of the mail object, either a single string of an address
+ # spec or an array of strings of address specs if there is more than one address
+ # in the Reply-To.
+ #
+ # Example:
+ #
+ # mail.reply_to = 'Mikel <mikel@test.lindsaar.net>'
+ # mail.reply_to #=> 'mikel@test.lindsaar.net'
+ # mail.reply_to = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+ # mail.reply_to #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+ #
+ # Also allows you to set the value by passing a value as a parameter
+ #
+ # Example:
+ #
+ # mail.reply_to 'Mikel <mikel@test.lindsaar.net>'
+ # mail.reply_to #=> 'mikel@test.lindsaar.net'
+ def reply_to( val = nil )
+ default :reply_to, val
+ end
+
+ # Sets the Reply-To value of the mail object, pass in a string of the field
+ #
+ # Example:
+ #
+ # mail.reply_to = 'Mikel <mikel@test.lindsaar.net>'
+ # mail.reply_to #=> 'mikel@test.lindsaar.net'
+ # mail.reply_to = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+ # mail.reply_to #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+ def reply_to=( val )
+ header[:reply_to] = val
+ end
+
+ # Returns the Resent-Bcc value of the mail object, either a single string of an address
+ # spec or an array of strings of address specs if there is more than one address
+ # in the Resent-Bcc.
+ #
+ # Example:
+ #
+ # mail.resent_bcc = 'Mikel <mikel@test.lindsaar.net>'
+ # mail.resent_bcc #=> 'mikel@test.lindsaar.net'
+ # mail.resent_bcc = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+ # mail.resent_bcc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+ #
+ # Also allows you to set the value by passing a value as a parameter
+ #
+ # Example:
+ #
+ # mail.resent_bcc 'Mikel <mikel@test.lindsaar.net>'
+ # mail.resent_bcc #=> 'mikel@test.lindsaar.net'
+ def resent_bcc( val = nil )
+ default :resent_bcc, val
+ end
+
+ # Sets the Resent-Bcc value of the mail object, pass in a string of the field
+ #
+ # Example:
+ #
+ # mail.resent_bcc = 'Mikel <mikel@test.lindsaar.net>'
+ # mail.resent_bcc #=> 'mikel@test.lindsaar.net'
+ # mail.resent_bcc = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+ # mail.resent_bcc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+ def resent_bcc=( val )
+ header[:resent_bcc] = val
+ end
+
+ # Returns the Resent-Cc value of the mail object, either a single string of an address
+ # spec or an array of strings of address specs if there is more than one address
+ # in the Resent-Cc.
+ #
+ # Example:
+ #
+ # mail.resent_cc = 'Mikel <mikel@test.lindsaar.net>'
+ # mail.resent_cc #=> 'mikel@test.lindsaar.net'
+ # mail.resent_cc = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+ # mail.resent_cc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+ #
+ # Also allows you to set the value by passing a value as a parameter
+ #
+ # Example:
+ #
+ # mail.resent_cc 'Mikel <mikel@test.lindsaar.net>'
+ # mail.resent_cc #=> 'mikel@test.lindsaar.net'
+ def resent_cc( val = nil )
+ default :resent_cc, val
+ end
+
+ # Sets the Resent-Cc value of the mail object, pass in a string of the field
+ #
+ # Example:
+ #
+ # mail.resent_cc = 'Mikel <mikel@test.lindsaar.net>'
+ # mail.resent_cc #=> 'mikel@test.lindsaar.net'
+ # mail.resent_cc = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+ # mail.resent_cc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+ def resent_cc=( val )
+ header[:resent_cc] = val
+ end
+
+ def resent_date( val = nil )
+ default :resent_date, val
+ end
+
+ def resent_date=( val )
+ header[:resent_date] = val
+ end
+
+ # Returns the Resent-From value of the mail object, either a single string of an address
+ # spec or an array of strings of address specs if there is more than one address
+ # in the Resent-From.
+ #
+ # Example:
+ #
+ # mail.resent_from = 'Mikel <mikel@test.lindsaar.net>'
+ # mail.resent_from #=> 'mikel@test.lindsaar.net'
+ # mail.resent_from = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+ # mail.resent_from #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+ #
+ # Also allows you to set the value by passing a value as a parameter
+ #
+ # Example:
+ #
+ # mail.resent_from 'Mikel <mikel@test.lindsaar.net>'
+ # mail.resent_from #=> 'mikel@test.lindsaar.net'
+ def resent_from( val = nil )
+ default :resent_from, val
+ end
+
+ # Sets the Resent-From value of the mail object, pass in a string of the field
+ #
+ # Example:
+ #
+ # mail.resent_from = 'Mikel <mikel@test.lindsaar.net>'
+ # mail.resent_from #=> 'mikel@test.lindsaar.net'
+ # mail.resent_from = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+ # mail.resent_from #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+ def resent_from=( val )
+ header[:resent_from] = val
+ end
+
+ def resent_message_id( val = nil )
+ default :resent_message_id, val
+ end
+
+ def resent_message_id=( val )
+ header[:resent_message_id] = val
+ end
+
+ # Returns the Resent-Sender value of the mail object, as a single string of an address
+ # spec. A sender per RFC 2822 must be a single address
+ #
+ # Example:
+ #
+ # mail.resent_sender = 'Mikel <mikel@test.lindsaar.net>'
+ # mail.resent_sender #=> 'mikel@test.lindsaar.net'
+ #
+ # Also allows you to set the value by passing a value as a parameter
+ #
+ # Example:
+ #
+ # mail.resent_sender 'Mikel <mikel@test.lindsaar.net>'
+ # mail.resent_sender #=> 'mikel@test.lindsaar.net'
+ def resent_sender( val = nil )
+ default :resent_sender, val
+ end
+
+ # Sets the Resent-Sender value of the mail object, pass in a string of the field
+ #
+ # Example:
+ #
+ # mail.sender = 'Mikel <mikel@test.lindsaar.net>'
+ # mail.sender #=> 'mikel@test.lindsaar.net'
+ def resent_sender=( val )
+ header[:resent_sender] = val
+ end
+
+ # Returns the Resent-To value of the mail object, either a single string of an address
+ # spec or an array of strings of address specs if there is more than one address
+ # in the Resent-To.
+ #
+ # Example:
+ #
+ # mail.resent_to = 'Mikel <mikel@test.lindsaar.net>'
+ # mail.resent_to #=> 'mikel@test.lindsaar.net'
+ # mail.resent_to = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+ # mail.resent_to #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+ #
+ # Also allows you to set the value by passing a value as a parameter
+ #
+ # Example:
+ #
+ # mail.resent_to 'Mikel <mikel@test.lindsaar.net>'
+ # mail.resent_to #=> 'mikel@test.lindsaar.net'
+ def resent_to( val = nil )
+ default :resent_to, val
+ end
+
+ # Sets the Resent-To value of the mail object, pass in a string of the field
+ #
+ # Example:
+ #
+ # mail.resent_to = 'Mikel <mikel@test.lindsaar.net>'
+ # mail.resent_to #=> 'mikel@test.lindsaar.net'
+ # mail.resent_to = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+ # mail.resent_to #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+ def resent_to=( val )
+ header[:resent_to] = val
+ end
+
+ # Returns the return path of the mail object, or sets it if you pass a string
+ def return_path( val = nil )
+ default :return_path, val
+ end
+
+ # Sets the return path of the object
+ def return_path=( val )
+ header[:return_path] = val
+ end
+
+ # Returns the Sender value of the mail object, as a single string of an address
+ # spec. A sender per RFC 2822 must be a single address
+ #
+ # Example:
+ #
+ # mail.sender = 'Mikel <mikel@test.lindsaar.net>'
+ # mail.sender #=> 'mikel@test.lindsaar.net'
+ #
+ # Also allows you to set the value by passing a value as a parameter
+ #
+ # Example:
+ #
+ # mail.sender 'Mikel <mikel@test.lindsaar.net>'
+ # mail.sender #=> 'mikel@test.lindsaar.net'
+ def sender( val = nil )
+ default :sender, val
+ end
+
+ # Sets the Sender value of the mail object, pass in a string of the field
+ #
+ # Example:
+ #
+ # mail.sender = 'Mikel <mikel@test.lindsaar.net>'
+ # mail.sender #=> 'mikel@test.lindsaar.net'
+ def sender=( val )
+ header[:sender] = val
+ end
+
+ # Returns the decoded value of the subject field, as a single string.
+ #
+ # Example:
+ #
+ # mail.subject = "G'Day mate"
+ # mail.subject #=> "G'Day mate"
+ # mail.subject = '=?UTF-8?Q?This_is_=E3=81=82_string?='
+ # mail.subject #=> "This is あ string"
+ #
+ # Also allows you to set the value by passing a value as a parameter
+ #
+ # Example:
+ #
+ # mail.subject "G'Day mate"
+ # mail.subject #=> "G'Day mate"
+ def subject( val = nil )
+ default :subject, val
+ end
+
+ # Sets the Subject value of the mail object, pass in a string of the field
+ #
+ # Example:
+ #
+ # mail.subject = '=?UTF-8?Q?This_is_=E3=81=82_string?='
+ # mail.subject #=> "This is あ string"
+ def subject=( val )
+ header[:subject] = val
+ end
+
+ # Returns the To value of the mail object, either a single string of an address
+ # spec or an array of strings of address specs if there is more than one address
+ # in the To.
+ #
+ # Example:
+ #
+ # mail.to = 'Mikel <mikel@test.lindsaar.net>'
+ # mail.to #=> 'mikel@test.lindsaar.net'
+ # mail.to = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+ # mail.to #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+ #
+ # Also allows you to set the value by passing a value as a parameter
+ #
+ # Example:
+ #
+ # mail.to 'Mikel <mikel@test.lindsaar.net>'
+ # mail.to #=> 'mikel@test.lindsaar.net'
+ def to( val = nil )
+ default :to, val
+ end
+
+ # Sets the To value of the mail object, pass in a string of the field
+ #
+ # Example:
+ #
+ # mail.to = 'Mikel <mikel@test.lindsaar.net>'
+ # mail.to #=> 'mikel@test.lindsaar.net'
+ # mail.to = 'Mikel <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
+ # mail.to #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
+ def to=( val )
+ header[:to] = val
+ end
+
+ # Returns the default value of the field requested as a symbol.
+ #
+ # Each header field has a :default method which returns the most common use case for
+ # that field, for example, the date field types will return a DateTime object when
+ # sent :default, the subject, or unstructured fields will return a decoded string of
+ # their value, the address field types will return a single addr_spec or an array of
+ # addr_specs if there is more than one.
+ def default( sym, val = nil )
+ if val
+ header[sym] = val
+ else
+ header[sym].default if header[sym]
+ end
+ end
+
# Sets the body object of the message object.
#
# Example:
@@ -207,56 +783,7 @@ def body(value = nil)
@body
end
end
-
- # Sets the to filed of the message header.
- #
- # Example:
- #
- # mail.to = '"Mikel Lindsaar" <mikel@test.lindsaar.net>'
- # mail.to #=> '"Mikel Lindsaar" <mikel@test.lindsaar.net>'
- def to=(value)
- header[:to] = value
- end
-
- # Returns the to field in the message header. Or, if passed
- # a parameter sets the value.
- #
- # Example:
- #
- # mail.to = '"M L" <mikel@test.lindsaar.net>'
- # mail.to.to_s #=> '"M L" <mikel@test.lindsaar.net>'
- # mail.to.formatted #=> ['"M L" <mikel@test.lindsaar.net>']
- # mail.to.addresses #=> ['mikel@test.lindsaar.net']
- def to(value = nil)
- value ? self.to = value : header[:to]
- end
-
- # Sets the from field in the message header.
- #
- # Example:
- #
- # mail.from = '"Mikel Lindsaar" <mikel@test.lindsaar.net>'
- # mail.from.to_s #=> '"Mikel Lindsaar" <mikel@test.lindsaar.net>'
- def from=(value)
- header[:from] = value
- end
-
- # Returns the from field in the message header. Or, if passed
- # a parameter sets the value.
- #
- # Example:
- #
- # mail.from = '"Mikel Lindsaar" <mikel@test.lindsaar.net>'
- # mail.from.to_s #=> '"Mikel Lindsaar" <mikel@test.lindsaar.net>'
- #
- # mail.from '"M L" <mikel@test.lindsaar.net>'
- # mail.from.to_s #=> '"M L" <mikel@test.lindsaar.net>'
- # mail.from.formatted #=> ['"M L" <mikel@test.lindsaar.net>']
- # mail.from.addresses #=> ['mikel@test.lindsaar.net']
- def from(value = nil)
- value ? self.from = value : header[:from]
- end
-
+
# Returns the list of addresses this message should be sent to by
# collecting the addresses off the to, cc and bcc fields.
#
@@ -268,55 +795,31 @@ def from(value = nil)
# mail.destinations.length #=> 3
# mail.destinations.first #=> 'mikel@test.lindsaar.net'
def destinations
- [to, cc, bcc].map { |f| f.addresses if f }.compact.flatten
+ [to_addrs, cc_addrs, bcc_addrs].compact.flatten
end
# Returns an array of addresses (the encoded value) in the From field,
# if no From field, returns an empty array
def from_addrs
- from ? from.formatted.compact.flatten : []
+ from ? [from].flatten : []
end
# Returns an array of addresses (the encoded value) in the To field,
# if no To field, returns an empty array
def to_addrs
- to ? to.formatted.compact.flatten : []
+ to ? [to].flatten : []
end
# Returns an array of addresses (the encoded value) in the Cc field,
# if no Cc field, returns an empty array
def cc_addrs
- cc ? cc.formatted.compact.flatten : []
+ cc ? [cc].flatten : []
end
# Returns an array of addresses (the encoded value) in the Bcc field,
# if no Bcc field, returns an empty array
def bcc_addrs
- bcc ? bcc.formatted.compact.flatten : []
- end
-
- # Sets the subject field in the message header.
- #
- # Example:
- #
- # mail.subject = 'This is the subject'
- # mail.subject.to_s #=> 'This is the subject'
- def subject=(value)
- header[:subject] = value
- end
-
- # Returns the subject field in the message header. Or, if passed
- # a parameter sets the value.
- #
- # Example:
- #
- # mail.subject = 'This is the subject'
- # mail.subject.to_s #=> 'This is the subject'
- #
- # mail.subject 'This is another subject'
- # mail.subject.to_s #=> 'This is another subject'
- def subject(value = nil)
- value ? self.subject = value : header[:subject]
+ bcc ? [bcc].flatten : []
end
# Allows you to add an arbitrary header
@@ -366,10 +869,10 @@ def [](name)
# Examples:
#
# mail.comments = 'These are some comments'
- # mail.comments.to_s #=> 'These are some comments'
+ # mail.comments #=> 'These are some comments'
#
# mail.comments 'These are other comments'
- # mail.comments.to_s #=> 'These are other comments'
+ # mail.comments #=> 'These are other comments'
#
#
# mail.date = 'Tue, 1 Jul 2003 10:52:37 +0200'
@@ -380,10 +883,10 @@ def [](name)
#
#
# mail.resent_msg_id = '<1234@resent_msg_id.lindsaar.net>'
- # mail.resent_msg_id.to_s #=> '<1234@resent_msg_id.lindsaar.net>'
+ # mail.resent_msg_id #=> '<1234@resent_msg_id.lindsaar.net>'
#
# mail.resent_msg_id '<4567@resent_msg_id.lindsaar.net>'
- # mail.resent_msg_id.to_s #=> '<4567@resent_msg_id.lindsaar.net>'
+ # mail.resent_msg_id #=> '<4567@resent_msg_id.lindsaar.net>'
def method_missing(name, *args, &block)
#:nodoc:
# Only take the structured fields, as we could take _anything_ really
@@ -476,19 +979,19 @@ def add_mime_version(ver_val = '')
#
# Otherwise raises a warning
def add_content_type
- header['Content-Type'] = 'text/plain'
+ header[:content_type] = 'text/plain'
end
# Adds a content type and charset if the body is US-ASCII
#
# Otherwise raises a warning
def add_charset
if body.only_us_ascii?
- content_type.parameters['charset'] = 'US-ASCII'
+ header[:content_type].parameters['charset'] = 'US-ASCII'
else
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")}"
STDERR.puts(warning)
- content_type.parameters['charset'] = 'UTF-8'
+ header[:content_type].parameters['charset'] = 'UTF-8'
end
end
@@ -497,11 +1000,11 @@ def add_charset
# Otherwise raises a warning
def add_content_transfer_encoding
if body.only_us_ascii?
- header['Content-Transfer-Encoding'] = '7bit'
+ header[:content_transfer_encoding] = '7bit'
else
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")}"
STDERR.puts(warning)
- header['Content-Transfer-Encoding'] = '8bit'
+ header[:content_transfer_encoding] = '8bit'
end
end
@@ -515,39 +1018,50 @@ def transfer_encoding # :nodoc:
content_transfer_encoding
end
- # Returns the content type
+ # Returns the mime type of part we are on, this is taken from the content-type header
+ def mime_type
+ content_type ? header[:content_type].string : nil
+ end
+
def message_content_type
- content_type ? content_type.content_type : nil
+ STDERR.puts(":message_content_type is deprecated in Mail 1.4.3. Please use mime_type\n#{caller}")
+ mime_type
end
# Returns the character set defined in the content type field
def charset
- content_type ? content_type.parameters['charset'] : nil
+ content_type ? content_type_parameters['charset'] : nil
end
# Sets the charset to the supplied value. Will set the content type to text/plain if
# it does not already exist
def charset=(value)
if content_type
- content_type.parameters['charset'] = value
+ content_type_parameters['charset'] = value
else
self.content_type ['text', 'plain', {'charset' => value}]
end
end
# Returns the main content type
def main_type
- has_content_type? ? content_type.main_type : nil
+ has_content_type? ? header[:content_type].main_type : nil
end
# Returns the sub content type
def sub_type
- has_content_type? ? content_type.sub_type : nil
+ has_content_type? ? header[:content_type].sub_type : nil
end
# Returns the content type parameters
def mime_parameters
- has_content_type? ? content_type.parameters : nil
+ STDERR.puts(':mime_parameters is deprecated in Mail 1.4.3, please use :content_type_parameters instead')
+ content_type_parameters
+ end
+
+ # Returns the content type parameters
+ def content_type_parameters
+ has_content_type? ? header[:content_type].parameters : nil
end
# Returns true if the message is multipart
@@ -562,7 +1076,7 @@ def multipart_report?
# Returns true if the message is a multipart/report; report-type=delivery-status;
def delivery_status_report?
- multipart_report? && mime_parameters['report-type'] =~ /^delivery-status$/i
+ multipart_report? && content_type_parameters['report-type'] =~ /^delivery-status$/i
end
# returns the part in a multipart/report email that has the content-type delivery-status
@@ -600,7 +1114,7 @@ def retryable?
# Returns the current boundary for this message part
def boundary
- mime_parameters ? mime_parameters['boundary'] : nil
+ content_type_parameters ? content_type_parameters['boundary'] : nil
end
# Returns an array of parts in the message
@@ -829,7 +1343,7 @@ def separate_parts
def add_encoding_to_body
unless content_transfer_encoding.blank?
- body.encoding = content_transfer_encoding.decoded
+ body.encoding = content_transfer_encoding
end
end
@@ -907,7 +1421,7 @@ def init_with_string(string)
parse_message
separate_parts if multipart?
if filename = attachment?
- encoding = content_transfer_encoding.encoding if content_transfer_encoding
+ encoding = header[:content_transfer_encoding].encoding if content_transfer_encoding
@attachment = Mail::Attachment.new(:filename => filename,
:data => body.encoded,
:encoding => encoding)
@@ -917,12 +1431,12 @@ def init_with_string(string)
# Returns the filename of the attachment (if it exists) or returns nil
def find_attachment
case
- when content_type && content_type.filename
- filename = content_type.filename
- when content_disposition && content_disposition.filename
- filename = content_disposition.filename
- when content_location && content_location.location
- filename = content_location.location
+ when content_type && header[:content_type].filename
+ filename = header[:content_type].filename
+ when content_disposition && header[:content_disposition].filename
+ filename = header[:content_disposition].filename
+ when content_location && header[:content_location].location
+ filename = header[:content_location].location
else
filename = nil
end
View
2 lib/mail/network/delivery_methods/smtp.rb
@@ -62,7 +62,7 @@ def SMTP.deliver!(mail)
config = Mail.defaults
# TODO: use the "return-path" field by default instead of the "from" field ? (see ActionMailer)
- from = mail.from.addresses.first if mail.respond_to?(:from) && mail.from
+ from = mail.from_addrs.first
raise ArgumentError.new('An author -from- is required to send a message') if from.blank?
to ||= mail.destinations if mail.respond_to?(:destinations) && mail.destinations
raise ArgumentError.new('At least one recipient -to, cc, bcc- is required to send a message') if to.blank?
View
17 lib/mail/utilities.rb
@@ -130,16 +130,27 @@ def capitalize_field( str )
def constantize( str )
str.to_s.split(/[-_]/).map { |v| v.capitalize }.to_s
end
+
+ # Swaps out all underscores (_) for hyphens (-) good for stringing from symbols
+ # a field name.
+ #
+ # Example:
+ #
+ # string = :resent_from_field
+ # dasherize ( string ) #=> 'resent_from_field'
+ def dasherize( str )
+ str.to_s.downcase.gsub('_', '-')
+ end
- # Swaps out all hyphens (-) for underscores (_) good for symbolizing
+ # Swaps out all underscores (_) for hyphens (-) good for stringing from symbols
# a field name.
#
# Example:
#
- # string = 'Resent-From-Field'
+ # string = :resent_from_field
# underscoreize ( string ) #=> 'resent_from_field'
def underscoreize( str )
- str.to_s.downcase.gsub('_', '-')
+ str.to_s.downcase.gsub('-', '_')
end
end
View
4 lib/mail/version.rb
@@ -2,8 +2,8 @@
module Mail
module VERSION
MAJOR = 1
- MINOR = 4
- TINY = 3
+ MINOR = 5
+ TINY = 0
STRING = [MAJOR, MINOR, TINY].join('.')
end
View
34 spec/mail/body_spec.rb
@@ -138,14 +138,14 @@
multipart_body = "this is some text\r\n\r\n------=_Part_2192_32400445\r\nContent-Type: text/plain; charset=ISO-8859-1\r\n\r\nThis is a plain text\r\n\r\n------=_Part_2192_32400445\r\nContent-Type: text/html\r\n\r\n<p>This is HTML</p>\r\nn------=_Part_2192_32400445--\r\n"
body = Mail::Body.new(multipart_body)
body.split!('----=_Part_2192_32400445')
- body.parts[0].content_type.content_type.should == "text/plain"
+ body.parts[0].content_type.should == "text/plain; charset=ISO-8859-1"
end
it "should return the first part as it's own message" do
multipart_body = "this is some text\r\n\r\n------=_Part_2192_32400445\r\nContent-Type: text/plain; charset=ISO-8859-1\r\n\r\nThis is a plain text\r\n\r\n------=_Part_2192_32400445\r\nContent-Type: text/html\r\n\r\n<p>This is HTML</p>\r\nn------=_Part_2192_32400445--\r\n"
body = Mail::Body.new(multipart_body)
body.split!('----=_Part_2192_32400445')
- body.parts[1].content_type.content_type.should == "text/html"
+ body.parts[1].content_type.should == "text/html"
end
it "should separate out it's parts" do
@@ -221,9 +221,9 @@
body.parts.length.should == 3
body.should be_multipart
body.sort_parts!
- body.parts[0].content_type.value.should == "text/plain"
- body.parts[1].content_type.value.should == "text/enriched"
- body.parts[2].content_type.value.should == "text/html"
+ body.parts[0].content_type.should == "text/plain"
+ body.parts[1].content_type.should == "text/enriched"
+ body.parts[2].content_type.should == "text/html"
end
it "should allow you to sort the parts with an arbitrary sort order" do
@@ -235,9 +235,9 @@
body.parts.length.should == 3
body.should be_multipart
body.sort_parts!
- body.parts[0].content_type.value.should == "text/plain"
- body.parts[1].content_type.value.should == "text/html"
- body.parts[2].content_type.value.should == "text/enriched"
+ body.parts[0].content_type.should == "text/plain"
+ body.parts[1].content_type.should == "text/html"
+ body.parts[2].content_type.should == "text/enriched"
end
it "should allow you to sort the parts with an arbitrary sort order" do
@@ -249,9 +249,9 @@
body.parts.length.should == 3
body.should be_multipart
body.sort_parts!
- body.parts[0].content_type.value.should == "application/x-yaml"
- body.parts[1].content_type.value.should == "text/plain"
- body.parts[2].content_type.value.should == "text/html"
+ body.parts[0].content_type.should == "application/x-yaml"
+ body.parts[1].content_type.should == "text/plain"
+ body.parts[2].content_type.should == "text/html"
end
it "should sort the parts on encode" do
@@ -262,9 +262,9 @@
body.parts.length.should == 3
body.should be_multipart
body.encoded
- body.parts[0].content_type.value.should == "text/plain"
- body.parts[1].content_type.value.should == "text/enriched"
- body.parts[2].content_type.value.should == "text/html"
+ body.parts[0].content_type.should == "text/plain"
+ body.parts[1].content_type.should == "text/enriched"
+ body.parts[2].content_type.should == "text/html"
end
it "should put the part types it doesn't know about at the end" do
@@ -275,9 +275,9 @@
body.parts.length.should == 3
body.should be_multipart
body.encoded
- body.parts[0].content_type.value.should == "text/plain"
- body.parts[1].content_type.value.should == "text/html"
- body.parts[2].content_type.value.should == "image/jpeg"
+ body.parts[0].content_type.should == "text/plain"
+ body.parts[1].content_type.should == "text/html"
+ body.parts[2].content_type.should == "image/jpeg"
end
end
View
146 spec/mail/example_emails_spec.rb
@@ -11,11 +11,11 @@
# message identifier, and a textual message in the body.
it "should handle the basic test email" do
mail = Mail.read(fixture('emails', 'rfc2822', 'example01.eml'))
- mail.from.formatted.should == ['John Doe <jdoe@machine.example>']
- mail.to.formatted.should == ['Mary Smith <mary@example.net>']
- mail.message_id.value.should == '<1234@local.machine.example>'
- mail.date.date_time.should == ::DateTime.parse('21 Nov 1997 09:55:06 -0600')
- mail.subject.value.should == 'Saying Hello'
+ mail.from.should == "jdoe@machine.example"
+ mail.to.should == 'mary@example.net'
+ mail.message_id.should == '1234@local.machine.example'
+ mail.date.should == ::DateTime.parse('21 Nov 1997 09:55:06 -0600')
+ mail.subject.should == 'Saying Hello'
end
# From RFC 2822:
@@ -24,12 +24,12 @@
# sender field would be used:
it "should handle the sender test email" do
mail = Mail.read(fixture('emails', 'rfc2822', 'example02.eml'))
- mail.from.formatted.should == ['John Doe <jdoe@machine.example>']
- mail.sender.formatted.should == ['Michael Jones <mjones@machine.example>']
- mail.to.formatted.should == ['Mary Smith <mary@example.net>']
- mail.message_id.value.should == '<1234@local.machine.example>'
- mail.date.date_time.should == ::DateTime.parse('21 Nov 1997 09:55:06 -0600')
- mail.subject.value.should == 'Saying Hello'
+ mail.from.should == 'jdoe@machine.example'
+ mail.sender.should == 'mjones@machine.example'
+ mail.to.should == 'mary@example.net'
+ mail.message_id.should == '1234@local.machine.example'
+ mail.date.should == ::DateTime.parse('21 Nov 1997 09:55:06 -0600')
+ mail.subject.should == 'Saying Hello'
end
# From RFC 2822:
@@ -49,11 +49,11 @@
# "Giant; \"Big\" Box" <sysservices@example.net>
it "should handle multiple recipients test email" do
mail = Mail.read(fixture('emails', 'rfc2822', 'example03.eml'))
- mail.from.formatted.should == ['"Joe Q. Public" <john.q.public@example.com>']
- mail.to.formatted.should == ['Mary Smith <mary@x.test>', 'jdoe@example.org', 'Who? <one@y.test>']
- mail.cc.formatted.should == ['boss@nil.test', "\"Giant; \\\"Big\\\" Box\" <sysservices@example.net>"]
- mail.message_id.value.should == '<5678.21-Nov-1997@example.com>'
- mail.date.date_time.should == ::DateTime.parse('1 Jul 2003 10:52:37 +0200')
+ mail.from.should == 'john.q.public@example.com'
+ mail.to.should == ['mary@x.test', 'jdoe@example.org', 'one@y.test']
+ mail.cc.should == ['boss@nil.test', "sysservices@example.net"]
+ mail.message_id.should == '5678.21-Nov-1997@example.com'
+ mail.date.should == ::DateTime.parse('1 Jul 2003 10:52:37 +0200')
end
# From RFC 2822:
@@ -63,11 +63,11 @@
# group recipient named Undisclosed recipients.
it "should handle group address email test" do
mail = Mail.read(fixture('emails', 'rfc2822', 'example04.eml'))
- mail.from.formatted.should == ['Pete <pete@silly.example>']
- mail.to.formatted.should == ['Chris Jones <c@a.test>', 'joe@where.test', 'John <jdoe@one.test>']
- mail.cc.group_names.should == ['Undisclosed recipients']
- mail.message_id.value.should == '<testabcd.1234@silly.example>'
- mail.date.date_time.should == ::DateTime.parse('Thu, 13 Feb 1969 23:32:54 -0330')
+ mail.from.should == 'pete@silly.example'
+ mail.to.should == ['c@a.test', 'joe@where.test', 'jdoe@one.test']
+ mail[:cc].group_names.should == ['Undisclosed recipients']
+ mail.message_id.should == 'testabcd.1234@silly.example'
+ mail.date.should == ::DateTime.parse('Thu, 13 Feb 1969 23:32:54 -0330')
end
@@ -82,11 +82,11 @@
# fields in each message.
it "should handle reply messages" do
mail = Mail.read(fixture('emails', 'rfc2822', 'example05.eml'))
- mail.from.addresses.should == ['jdoe@machine.example']
- mail.to.addresses.should == ['mary@example.net']
- mail.subject.value.should == 'Saying Hello'
- mail.message_id.value.should == '<1234@local.machine.example>'
- mail.date.date_time.should == ::DateTime.parse('Fri, 21 Nov 1997 09:55:06 -0600')
+ mail.from.should == "jdoe@machine.example"
+ mail.to.should == 'mary@example.net'
+ mail.subject.should == 'Saying Hello'
+ mail.message_id.should == '1234@local.machine.example'
+ mail.date.should == ::DateTime.parse('Fri, 21 Nov 1997 09:55:06 -0600')
end
# From RFC 2822:
@@ -97,27 +97,27 @@
# "Reply-To:" field instead of the address in the "From:" field.
it "should handle reply message 2" do
mail = Mail.read(fixture('emails', 'rfc2822', 'example06.eml'))
- mail.from.addresses.should == ['mary@example.net']
- mail.to.addresses.should == ['jdoe@machine.example']
- mail.reply_to.addresses.should == ['smith@home.example']
- mail.subject.value.should == 'Re: Saying Hello'
- mail.message_id.value.should == '<3456@example.net>'
- mail.in_reply_to.message_ids.should == ['1234@local.machine.example']
- mail.references.message_ids.should == ['1234@local.machine.example']
- mail.date.date_time.should == ::DateTime.parse('Fri, 21 Nov 1997 10:01:10 -0600')
+ mail.from.should == 'mary@example.net'
+ mail.to.should == 'jdoe@machine.example'
+ mail.reply_to.should == 'smith@home.example'
+ mail.subject.should == 'Re: Saying Hello'
+ mail.message_id.should == '3456@example.net'
+ mail[:in_reply_to].message_ids.should == ['1234@local.machine.example']
+ mail[:references].message_ids.should == ['1234@local.machine.example']
+ mail.date.should == ::DateTime.parse('Fri, 21 Nov 1997 10:01:10 -0600')
end
# From RFC 2822:
# Final reply message
it "should handle the final reply message" do
mail = Mail.read(fixture('emails', 'rfc2822', 'example07.eml'))
- mail.to.addresses.should == ['smith@home.example']
- mail.from.addresses.should == ['jdoe@machine.example']
- mail.subject.value.should == 'Re: Saying Hello'
- mail.date.date_time.should == ::DateTime.parse('Fri, 21 Nov 1997 11:00:00 -0600')
- mail.message_id.value.should == '<abcd.1234@local.machine.tld>'
- mail.in_reply_to.value.should == '<3456@example.net>'
- mail.references.message_ids.should == ['1234@local.machine.example', '3456@example.net']
+ mail.to.should == 'smith@home.example'
+ mail.from.should == 'jdoe@machine.example'
+ mail.subject.should == 'Re: Saying Hello'
+ mail.date.should == ::DateTime.parse('Fri, 21 Nov 1997 11:00:00 -0600')
+ mail.message_id.should == 'abcd.1234@local.machine.tld'
+ mail.in_reply_to.should == '3456@example.net'
+ mail[:references].message_ids.should == ['1234@local.machine.example', '3456@example.net']
end
# From RFC2822
@@ -135,15 +135,15 @@
# and send that.
it "should handle the rfc resent example email" do
mail = Mail.read(fixture('emails', 'rfc2822', 'example08.eml'))
- mail.resent_from.addresses.should == ['mary@example.net']
- mail.resent_to.addresses.should == ['j-brown@other.example']
- mail.resent_date.date_time.should == ::DateTime.parse('Mon, 24 Nov 1997 14:22:01 -0800')
- mail.resent_message_id.value.should == '<78910@example.net>'
- mail.from.addresses.should == ['jdoe@machine.example']
- mail.to.addresses.should == ['mary@example.net']
- mail.subject.value.should == 'Saying Hello'
- mail.date.date_time.should == ::DateTime.parse('Fri, 21 Nov 1997 09:55:06 -0600')
- mail.message_id.value.should == '<1234@local.machine.example>'
+ mail.resent_from.should == 'mary@example.net'
+ mail.resent_to.should == 'j-brown@other.example'
+ mail.resent_date.should == ::DateTime.parse('Mon, 24 Nov 1997 14:22:01 -0800')
+ mail.resent_message_id.should == '78910@example.net'
+ mail.from.should == 'jdoe@machine.example'
+ mail.to.should == 'mary@example.net'
+ mail.subject.should == 'Saying Hello'
+ mail.date.should == ::DateTime.parse('Fri, 21 Nov 1997 09:55:06 -0600')
+ mail.message_id.should == '1234@local.machine.example'
end
# A.4. Messages with trace fields
@@ -158,11 +158,11 @@
mail.received[0].date_time.should == ::DateTime.parse('21 Nov 1997 10:05:43 -0600')
mail.received[1].info.should == 'from machine.example by x.y.test'
mail.received[1].date_time.should == ::DateTime.parse('21 Nov 1997 10:01:22 -0600')
- mail.from.addresses.should == ['jdoe@machine.example']
- mail.to.addresses.should == ['mary@example.net']
- mail.subject.value.should == 'Saying Hello'
- mail.date.date_time.should == ::DateTime.parse('Fri, 21 Nov 1997 09:55:06 -0600')
- mail.message_id.value.should == '<1234@local.machine.example>'
+ mail.from.should == 'jdoe@machine.example'
+ mail.to.should == 'mary@example.net'
+ mail.subject.should == 'Saying Hello'
+ mail.date.should == ::DateTime.parse('Fri, 21 Nov 1997 09:55:06 -0600')
+ mail.message_id.should == '1234@local.machine.example'
end
# A.5. White space, comments, and other oddities
@@ -185,11 +185,11 @@
# (but not within) the identifier in the "Message-ID:" field.
it "should handle the rfc whitespace test email" do
mail = Mail.read(fixture('emails', 'rfc2822', 'example10.eml'))
- mail.from.addresses.should == ['pete(his account)@silly.test']
- mail.to.addresses.should == ["c@(Chris's host.)public.example", 'joe@example.org', 'jdoe@one.test']
- mail.cc.group_names.should == ['(Empty list)(start)Undisclosed recipients ']
- mail.date.date_time.should == ::DateTime.parse('Thu, 13 Feb 1969 23:32 -0330')
- mail.message_id.value.should == '<testabcd.1234@silly.test>'
+ mail.from.should == "pete(his account)@silly.test"
+ mail.to.should == ["c@(Chris's host.)public.example", "joe@example.org", "jdoe@one.test"]
+ mail[:cc].group_names.should == ['(Empty list)(start)Undisclosed recipients ']
+ mail.date.should == ::DateTime.parse('Thu, 13 Feb 1969 23:32 -0330')
+ mail.message_id.should == 'testabcd.1234@silly.test'
end
# A.6. Obsoleted forms
@@ -204,11 +204,11 @@
it "should handle the rfc obsolete addressing" do
pending
mail = Mail.read(fixture('emails', 'rfc2822', 'example11.eml'))
- mail.from.addresses.should == ['john.q.public@example.com']
- mail.from.formatted.should == ['"Joe Q. Public" <john.q.public@example.com>']
- mail.to.addresses.should == ["@machine.tld:mary@example.net", 'jdoe@test.example']
- mail.date.date_time.should == ::DateTime.parse('Tue, 1 Jul 2003 10:52:37 +0200')
- mail.message_id.value.should == '<5678.21-Nov-1997@example.com>'
+ mail[:from].addresses.should == ['john.q.public@example.com']
+ mail.from.should == '"Joe Q. Public" <john.q.public@example.com>'
+ mail.to.should == ["@machine.tld:mary@example.net", 'jdoe@test.example']
+ mail.date.should == ::DateTime.parse('Tue, 1 Jul 2003 10:52:37 +0200')
+ mail.message_id.should == '5678.21-Nov-1997@example.com'
end
# A.6.2. Obsolete dates
@@ -220,10 +220,10 @@
it "should handle the rfc obsolete dates" do
pending
mail = Mail.read(fixture('emails', 'rfc2822', 'example12.eml'))
- mail.from.addresses.should == ['jdoe@machine.example']
- mail.to.addresses.should == ['mary@example.net']
- mail.date.date_time.should == ::DateTime.parse('21 Nov 97 09:55:06 GMT')
- mail.message_id.value.should == '<1234@local.machine.example>'
+ mail.from.should == 'jdoe@machine.example'
+ mail.to.should == 'mary@example.net'
+ mail.date.should == ::DateTime.parse('21 Nov 97 09:55:06 GMT')
+ mail.message_id.should == '1234@local.machine.example'
end
# A.6.3. Obsolete white space and comments
@@ -241,10 +241,10 @@
it "should handle the rfc obsolete whitespace email" do
pending
mail = Mail.read(fixture('emails', 'rfc2822', 'example13.eml'))
- mail.from.addresses.should == ['John Doe <jdoe@machine(comment).example>']
- mail.to.addresses.should == ['Mary Smith <mary@example.net>']
- mail.date.date_time.should == ::DateTime.parse('Fri, 21 Nov 1997 09:55:06 -0600')
- mail.message_id.value.should == '<1234@local(blah).machine.example>'
+ mail.from.should == 'John Doe <jdoe@machine(comment).example>'
+ mail.to.should == 'Mary Smith <mary@example.net>'
+ mail.date.should == ::DateTime.parse('Fri, 21 Nov 1997 09:55:06 -0600')
+ mail.message_id.should == '1234@local(blah).machine.example'
doing { Mail::Message.new(email) }.should_not raise_error
end
View
4 spec/mail/field_spec.rb
@@ -30,7 +30,7 @@
structured_fields.each do |sf|
words = sf.split("-").map { |a| a.capitalize }
klass = "#{words.join}Field"
- Mail::Field.new("#{sf}: Value").field.class.should == Mail.const_get(klass)
+ Mail::Field.new("#{sf}: ").field.class.should == Mail.const_get(klass)
end
end
@@ -44,7 +44,7 @@
structured_fields.each do |sf|
words = sf.split("-").map { |a| a.capitalize }
klass = "#{words.join}Field"
- Mail::Field.new("#{sf}: Value").field.class.should == Mail.const_get(klass)
+ Mail::Field.new("#{sf}: ").field.class.should == Mail.const_get(klass)