otherinbox-mail 2.4.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (141) hide show
  1. data/CHANGELOG.rdoc +607 -0
  2. data/CONTRIBUTING.md +45 -0
  3. data/Dependencies.txt +3 -0
  4. data/Gemfile +26 -0
  5. data/Gemfile.lock +44 -0
  6. data/README.md +663 -0
  7. data/Rakefile +40 -0
  8. data/TODO.rdoc +9 -0
  9. data/lib/VERSION +4 -0
  10. data/lib/mail.rb +101 -0
  11. data/lib/mail/attachments_list.rb +104 -0
  12. data/lib/mail/body.rb +291 -0
  13. data/lib/mail/configuration.rb +75 -0
  14. data/lib/mail/core_extensions/nil.rb +17 -0
  15. data/lib/mail/core_extensions/object.rb +13 -0
  16. data/lib/mail/core_extensions/shell_escape.rb +56 -0
  17. data/lib/mail/core_extensions/smtp.rb +25 -0
  18. data/lib/mail/core_extensions/string.rb +33 -0
  19. data/lib/mail/core_extensions/string/access.rb +145 -0
  20. data/lib/mail/core_extensions/string/multibyte.rb +78 -0
  21. data/lib/mail/elements.rb +14 -0
  22. data/lib/mail/elements/address.rb +306 -0
  23. data/lib/mail/elements/address_list.rb +74 -0
  24. data/lib/mail/elements/content_disposition_element.rb +30 -0
  25. data/lib/mail/elements/content_location_element.rb +25 -0
  26. data/lib/mail/elements/content_transfer_encoding_element.rb +24 -0
  27. data/lib/mail/elements/content_type_element.rb +35 -0
  28. data/lib/mail/elements/date_time_element.rb +26 -0
  29. data/lib/mail/elements/envelope_from_element.rb +34 -0
  30. data/lib/mail/elements/message_ids_element.rb +29 -0
  31. data/lib/mail/elements/mime_version_element.rb +26 -0
  32. data/lib/mail/elements/phrase_list.rb +21 -0
  33. data/lib/mail/elements/received_element.rb +30 -0
  34. data/lib/mail/encodings.rb +274 -0
  35. data/lib/mail/encodings/7bit.rb +31 -0
  36. data/lib/mail/encodings/8bit.rb +31 -0
  37. data/lib/mail/encodings/base64.rb +33 -0
  38. data/lib/mail/encodings/binary.rb +31 -0
  39. data/lib/mail/encodings/quoted_printable.rb +38 -0
  40. data/lib/mail/encodings/transfer_encoding.rb +58 -0
  41. data/lib/mail/envelope.rb +35 -0
  42. data/lib/mail/field.rb +234 -0
  43. data/lib/mail/field_list.rb +33 -0
  44. data/lib/mail/fields.rb +35 -0
  45. data/lib/mail/fields/bcc_field.rb +56 -0
  46. data/lib/mail/fields/cc_field.rb +55 -0
  47. data/lib/mail/fields/comments_field.rb +41 -0
  48. data/lib/mail/fields/common/address_container.rb +16 -0
  49. data/lib/mail/fields/common/common_address.rb +125 -0
  50. data/lib/mail/fields/common/common_date.rb +42 -0
  51. data/lib/mail/fields/common/common_field.rb +51 -0
  52. data/lib/mail/fields/common/common_message_id.rb +44 -0
  53. data/lib/mail/fields/common/parameter_hash.rb +58 -0
  54. data/lib/mail/fields/content_description_field.rb +19 -0
  55. data/lib/mail/fields/content_disposition_field.rb +69 -0
  56. data/lib/mail/fields/content_id_field.rb +63 -0
  57. data/lib/mail/fields/content_location_field.rb +42 -0
  58. data/lib/mail/fields/content_transfer_encoding_field.rb +50 -0
  59. data/lib/mail/fields/content_type_field.rb +198 -0
  60. data/lib/mail/fields/date_field.rb +57 -0
  61. data/lib/mail/fields/from_field.rb +55 -0
  62. data/lib/mail/fields/in_reply_to_field.rb +55 -0
  63. data/lib/mail/fields/keywords_field.rb +44 -0
  64. data/lib/mail/fields/message_id_field.rb +83 -0
  65. data/lib/mail/fields/mime_version_field.rb +53 -0
  66. data/lib/mail/fields/optional_field.rb +13 -0
  67. data/lib/mail/fields/received_field.rb +75 -0
  68. data/lib/mail/fields/references_field.rb +55 -0
  69. data/lib/mail/fields/reply_to_field.rb +55 -0
  70. data/lib/mail/fields/resent_bcc_field.rb +55 -0
  71. data/lib/mail/fields/resent_cc_field.rb +55 -0
  72. data/lib/mail/fields/resent_date_field.rb +35 -0
  73. data/lib/mail/fields/resent_from_field.rb +55 -0
  74. data/lib/mail/fields/resent_message_id_field.rb +34 -0
  75. data/lib/mail/fields/resent_sender_field.rb +62 -0
  76. data/lib/mail/fields/resent_to_field.rb +55 -0
  77. data/lib/mail/fields/return_path_field.rb +65 -0
  78. data/lib/mail/fields/sender_field.rb +67 -0
  79. data/lib/mail/fields/structured_field.rb +51 -0
  80. data/lib/mail/fields/subject_field.rb +16 -0
  81. data/lib/mail/fields/to_field.rb +55 -0
  82. data/lib/mail/fields/unstructured_field.rb +191 -0
  83. data/lib/mail/header.rb +265 -0
  84. data/lib/mail/indifferent_hash.rb +146 -0
  85. data/lib/mail/mail.rb +255 -0
  86. data/lib/mail/matchers/has_sent_mail.rb +124 -0
  87. data/lib/mail/message.rb +2059 -0
  88. data/lib/mail/multibyte.rb +42 -0
  89. data/lib/mail/multibyte/chars.rb +474 -0
  90. data/lib/mail/multibyte/exceptions.rb +8 -0
  91. data/lib/mail/multibyte/unicode.rb +392 -0
  92. data/lib/mail/multibyte/utils.rb +60 -0
  93. data/lib/mail/network.rb +14 -0
  94. data/lib/mail/network/delivery_methods/exim.rb +53 -0
  95. data/lib/mail/network/delivery_methods/file_delivery.rb +40 -0
  96. data/lib/mail/network/delivery_methods/sendmail.rb +62 -0
  97. data/lib/mail/network/delivery_methods/smtp.rb +153 -0
  98. data/lib/mail/network/delivery_methods/smtp_connection.rb +74 -0
  99. data/lib/mail/network/delivery_methods/test_mailer.rb +40 -0
  100. data/lib/mail/network/retriever_methods/base.rb +63 -0
  101. data/lib/mail/network/retriever_methods/imap.rb +168 -0
  102. data/lib/mail/network/retriever_methods/pop3.rb +140 -0
  103. data/lib/mail/network/retriever_methods/test_retriever.rb +47 -0
  104. data/lib/mail/parsers/address_lists.rb +64 -0
  105. data/lib/mail/parsers/address_lists.treetop +19 -0
  106. data/lib/mail/parsers/content_disposition.rb +535 -0
  107. data/lib/mail/parsers/content_disposition.treetop +46 -0
  108. data/lib/mail/parsers/content_location.rb +139 -0
  109. data/lib/mail/parsers/content_location.treetop +20 -0
  110. data/lib/mail/parsers/content_transfer_encoding.rb +162 -0
  111. data/lib/mail/parsers/content_transfer_encoding.treetop +20 -0
  112. data/lib/mail/parsers/content_type.rb +967 -0
  113. data/lib/mail/parsers/content_type.treetop +68 -0
  114. data/lib/mail/parsers/date_time.rb +114 -0
  115. data/lib/mail/parsers/date_time.treetop +11 -0
  116. data/lib/mail/parsers/envelope_from.rb +194 -0
  117. data/lib/mail/parsers/envelope_from.treetop +32 -0
  118. data/lib/mail/parsers/message_ids.rb +45 -0
  119. data/lib/mail/parsers/message_ids.treetop +15 -0
  120. data/lib/mail/parsers/mime_version.rb +144 -0
  121. data/lib/mail/parsers/mime_version.treetop +19 -0
  122. data/lib/mail/parsers/phrase_lists.rb +45 -0
  123. data/lib/mail/parsers/phrase_lists.treetop +15 -0
  124. data/lib/mail/parsers/received.rb +71 -0
  125. data/lib/mail/parsers/received.treetop +11 -0
  126. data/lib/mail/parsers/rfc2045.rb +464 -0
  127. data/lib/mail/parsers/rfc2045.treetop +36 -0
  128. data/lib/mail/parsers/rfc2822.rb +5341 -0
  129. data/lib/mail/parsers/rfc2822.treetop +410 -0
  130. data/lib/mail/parsers/rfc2822_obsolete.rb +3768 -0
  131. data/lib/mail/parsers/rfc2822_obsolete.treetop +241 -0
  132. data/lib/mail/part.rb +116 -0
  133. data/lib/mail/parts_list.rb +55 -0
  134. data/lib/mail/patterns.rb +34 -0
  135. data/lib/mail/utilities.rb +215 -0
  136. data/lib/mail/version.rb +24 -0
  137. data/lib/mail/version_specific/ruby_1_8.rb +98 -0
  138. data/lib/mail/version_specific/ruby_1_9.rb +113 -0
  139. data/lib/tasks/corpus.rake +125 -0
  140. data/lib/tasks/treetop.rake +10 -0
  141. metadata +253 -0
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+ module Mail
3
+
4
+ # Field List class provides an enhanced array that keeps a list of
5
+ # email fields in order. And allows you to insert new fields without
6
+ # having to worry about the order they will appear in.
7
+ class FieldList < Array
8
+
9
+ include Enumerable
10
+
11
+ def <<( new_field )
12
+ current_entry = self.rindex(new_field)
13
+ if current_entry
14
+ self.insert((current_entry + 1), new_field)
15
+ else
16
+ insert_idx = -1
17
+ self.each_with_index do |item, idx|
18
+ case item <=> new_field
19
+ when -1
20
+ next
21
+ when 0
22
+ next
23
+ when 1
24
+ insert_idx = idx
25
+ break
26
+ end
27
+ end
28
+ insert(insert_idx, new_field)
29
+ end
30
+ end
31
+
32
+ end
33
+ end
@@ -0,0 +1,35 @@
1
+ module Mail
2
+ register_autoload :UnstructuredField, 'mail/fields/unstructured_field'
3
+ register_autoload :StructuredField, 'mail/fields/structured_field'
4
+ register_autoload :OptionalField, 'mail/fields/optional_field'
5
+
6
+ register_autoload :BccField, 'mail/fields/bcc_field'
7
+ register_autoload :CcField, 'mail/fields/cc_field'
8
+ register_autoload :CommentsField, 'mail/fields/comments_field'
9
+ register_autoload :ContentDescriptionField, 'mail/fields/content_description_field'
10
+ register_autoload :ContentDispositionField, 'mail/fields/content_disposition_field'
11
+ register_autoload :ContentIdField, 'mail/fields/content_id_field'
12
+ register_autoload :ContentLocationField, 'mail/fields/content_location_field'
13
+ register_autoload :ContentTransferEncodingField, 'mail/fields/content_transfer_encoding_field'
14
+ register_autoload :ContentTypeField, 'mail/fields/content_type_field'
15
+ register_autoload :DateField, 'mail/fields/date_field'
16
+ register_autoload :FromField, 'mail/fields/from_field'
17
+ register_autoload :InReplyToField, 'mail/fields/in_reply_to_field'
18
+ register_autoload :KeywordsField, 'mail/fields/keywords_field'
19
+ register_autoload :MessageIdField, 'mail/fields/message_id_field'
20
+ register_autoload :MimeVersionField, 'mail/fields/mime_version_field'
21
+ register_autoload :ReceivedField, 'mail/fields/received_field'
22
+ register_autoload :ReferencesField, 'mail/fields/references_field'
23
+ register_autoload :ReplyToField, 'mail/fields/reply_to_field'
24
+ register_autoload :ResentBccField, 'mail/fields/resent_bcc_field'
25
+ register_autoload :ResentCcField, 'mail/fields/resent_cc_field'
26
+ register_autoload :ResentDateField, 'mail/fields/resent_date_field'
27
+ register_autoload :ResentFromField, 'mail/fields/resent_from_field'
28
+ register_autoload :ResentMessageIdField, 'mail/fields/resent_message_id_field'
29
+ register_autoload :ResentSenderField, 'mail/fields/resent_sender_field'
30
+ register_autoload :ResentToField, 'mail/fields/resent_to_field'
31
+ register_autoload :ReturnPathField, 'mail/fields/return_path_field'
32
+ register_autoload :SenderField, 'mail/fields/sender_field'
33
+ register_autoload :SubjectField, 'mail/fields/subject_field'
34
+ register_autoload :ToField, 'mail/fields/to_field'
35
+ end
@@ -0,0 +1,56 @@
1
+ # encoding: utf-8
2
+ #
3
+ # = Blind Carbon Copy Field
4
+ #
5
+ # The Bcc field inherits from StructuredField and handles the Bcc: header
6
+ # field in the email.
7
+ #
8
+ # Sending bcc to a mail message will instantiate a Mail::Field object that
9
+ # has a BccField as it's field type. This includes all Mail::CommonAddress
10
+ # module instance metods.
11
+ #
12
+ # Only one Bcc field can appear in a header, though it can have multiple
13
+ # addresses and groups of addresses.
14
+ #
15
+ # == Examples:
16
+ #
17
+ # mail = Mail.new
18
+ # mail.bcc = 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
19
+ # mail.bcc #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
20
+ # mail[:bcc] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::BccField:0x180e1c4
21
+ # mail['bcc'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::BccField:0x180e1c4
22
+ # mail['Bcc'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::BccField:0x180e1c4
23
+ #
24
+ # mail[:bcc].encoded #=> '' # Bcc field does not get output into an email
25
+ # mail[:bcc].decoded #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
26
+ # mail[:bcc].addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
27
+ # mail[:bcc].formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
28
+ #
29
+ require 'mail/fields/common/common_address'
30
+
31
+ module Mail
32
+ class BccField < StructuredField
33
+
34
+ include Mail::CommonAddress
35
+
36
+ FIELD_NAME = 'bcc'
37
+ CAPITALIZED_FIELD = 'Bcc'
38
+
39
+ def initialize(value = '', charset = 'utf-8')
40
+ @charset = charset
41
+ super(CAPITALIZED_FIELD, strip_field(FIELD_NAME, value), charset)
42
+ self.parse
43
+ self
44
+ end
45
+
46
+ # Bcc field should never be :encoded
47
+ def encoded
48
+ ''
49
+ end
50
+
51
+ def decoded
52
+ do_decode
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+ #
3
+ # = Carbon Copy Field
4
+ #
5
+ # The Cc field inherits from StructuredField and handles the Cc: header
6
+ # field in the email.
7
+ #
8
+ # Sending cc to a mail message will instantiate a Mail::Field object that
9
+ # has a CcField as it's field type. This includes all Mail::CommonAddress
10
+ # module instance metods.
11
+ #
12
+ # Only one Cc field can appear in a header, though it can have multiple
13
+ # addresses and groups of addresses.
14
+ #
15
+ # == Examples:
16
+ #
17
+ # mail = Mail.new
18
+ # mail.cc = 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
19
+ # mail.cc #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
20
+ # mail[:cc] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CcField:0x180e1c4
21
+ # mail['cc'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CcField:0x180e1c4
22
+ # mail['Cc'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CcField:0x180e1c4
23
+ #
24
+ # mail[:cc].encoded #=> 'Cc: Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net\r\n'
25
+ # mail[:cc].decoded #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
26
+ # mail[:cc].addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
27
+ # mail[:cc].formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
28
+ #
29
+ require 'mail/fields/common/common_address'
30
+
31
+ module Mail
32
+ class CcField < StructuredField
33
+
34
+ include Mail::CommonAddress
35
+
36
+ FIELD_NAME = 'cc'
37
+ CAPITALIZED_FIELD = 'Cc'
38
+
39
+ def initialize(value = nil, charset = 'utf-8')
40
+ self.charset = charset
41
+ super(CAPITALIZED_FIELD, strip_field(FIELD_NAME, value), charset)
42
+ self.parse
43
+ self
44
+ end
45
+
46
+ def encoded
47
+ do_encode(CAPITALIZED_FIELD)
48
+ end
49
+
50
+ def decoded
51
+ do_decode
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+ #
3
+ # = Comments Field
4
+ #
5
+ # The Comments field inherits from UnstructuredField and handles the Comments:
6
+ # header field in the email.
7
+ #
8
+ # Sending comments to a mail message will instantiate a Mail::Field object that
9
+ # has a CommentsField as it's field type.
10
+ #
11
+ # An email header can have as many comments fields as it wants. There is no upper
12
+ # limit, the comments field is also optional (that is, no comment is needed)
13
+ #
14
+ # == Examples:
15
+ #
16
+ # mail = Mail.new
17
+ # mail.comments = 'This is a comment'
18
+ # mail.comments #=> 'This is a comment'
19
+ # mail[:comments] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CommentsField:0x180e1c4
20
+ # mail['comments'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CommentsField:0x180e1c4
21
+ # mail['comments'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CommentsField:0x180e1c4
22
+ #
23
+ # mail.comments = "This is another comment"
24
+ # mail[:comments].map { |c| c.to_s }
25
+ # #=> ['This is a comment', "This is another comment"]
26
+ #
27
+ module Mail
28
+ class CommentsField < UnstructuredField
29
+
30
+ FIELD_NAME = 'comments'
31
+ CAPITALIZED_FIELD = 'Comments'
32
+
33
+ def initialize(value = nil, charset = 'utf-8')
34
+ @charset = charset
35
+ super(CAPITALIZED_FIELD, strip_field(FIELD_NAME, value))
36
+ self.parse
37
+ self
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,16 @@
1
+ module Mail
2
+
3
+ class AddressContainer < Array
4
+
5
+ def initialize(field, list = [])
6
+ @field = field
7
+ super(list)
8
+ end
9
+
10
+ def << (address)
11
+ @field << address
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,125 @@
1
+ # encoding: utf-8
2
+ require 'mail/fields/common/address_container'
3
+
4
+ module Mail
5
+ module CommonAddress # :nodoc:
6
+
7
+ def parse(val = value)
8
+ unless val.blank?
9
+ @tree = AddressList.new(encode_if_needed(val))
10
+ else
11
+ nil
12
+ end
13
+ end
14
+
15
+ def charset
16
+ @charset
17
+ end
18
+
19
+ def encode_if_needed(val)
20
+ Encodings.address_encode(val, charset)
21
+ end
22
+
23
+ # Allows you to iterate through each address object in the syntax tree
24
+ def each
25
+ tree.addresses.each do |address|
26
+ yield(address)
27
+ end
28
+ end
29
+
30
+ # Returns the address string of all the addresses in the address list
31
+ def addresses
32
+ list = tree.addresses.map { |a| a.address }
33
+ Mail::AddressContainer.new(self, list)
34
+ end
35
+
36
+ # Returns the formatted string of all the addresses in the address list
37
+ def formatted
38
+ list = tree.addresses.map { |a| a.format }
39
+ Mail::AddressContainer.new(self, list)
40
+ end
41
+
42
+ # Returns the display name of all the addresses in the address list
43
+ def display_names
44
+ list = tree.addresses.map { |a| a.display_name }
45
+ Mail::AddressContainer.new(self, list)
46
+ end
47
+
48
+ # Returns the actual address objects in the address list
49
+ def addrs
50
+ list = tree.addresses
51
+ Mail::AddressContainer.new(self, list)
52
+ end
53
+
54
+ # Returns a hash of group name => address strings for the address list
55
+ def groups
56
+ @groups = Hash.new
57
+ tree.group_recipients.each do |group|
58
+ @groups[group.group_name.text_value.to_str] = get_group_addresses(group.group_list)
59
+ end
60
+ @groups
61
+ end
62
+
63
+ # Returns the addresses that are part of groups
64
+ def group_addresses
65
+ groups.map { |k,v| v.map { |a| a.format } }.flatten
66
+ end
67
+
68
+ # Returns the name of all the groups in a string
69
+ def group_names # :nodoc:
70
+ tree.group_names
71
+ end
72
+
73
+ def default
74
+ addresses
75
+ end
76
+
77
+ def <<(val)
78
+ case
79
+ when val.nil?
80
+ raise ArgumentError, "Need to pass an address to <<"
81
+ when val.blank?
82
+ parse(encoded)
83
+ else
84
+ parse((formatted + [val]).join(", "))
85
+ end
86
+ end
87
+
88
+ private
89
+
90
+ def do_encode(field_name)
91
+ return '' if value.blank?
92
+ address_array = tree.addresses.reject { |a| group_addresses.include?(a.encoded) }.compact.map { |a| a.encoded }
93
+ address_text = address_array.join(", \r\n\s")
94
+ group_array = groups.map { |k,v| "#{k}: #{v.map { |a| a.encoded }.join(", \r\n\s")};" }
95
+ group_text = group_array.join(" \r\n\s")
96
+ return_array = [address_text, group_text].reject { |a| a.blank? }
97
+ "#{field_name}: #{return_array.join(", \r\n\s")}\r\n"
98
+ end
99
+
100
+ def do_decode
101
+ return nil if value.blank?
102
+ address_array = tree.addresses.reject { |a| group_addresses.include?(a.decoded) }.map { |a| a.decoded }
103
+ address_text = address_array.join(", ")
104
+ group_array = groups.map { |k,v| "#{k}: #{v.map { |a| a.decoded }.join(", ")};" }
105
+ group_text = group_array.join(" ")
106
+ return_array = [address_text, group_text].reject { |a| a.blank? }
107
+ return_array.join(", ")
108
+ end
109
+
110
+ # Returns the syntax tree of the Addresses
111
+ def tree # :nodoc:
112
+ @tree ||= AddressList.new(value)
113
+ end
114
+
115
+ def get_group_addresses(group_list)
116
+ if group_list.respond_to?(:addresses)
117
+ group_list.addresses.map do |address_tree|
118
+ Mail::Address.new(address_tree)
119
+ end
120
+ else
121
+ []
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,42 @@
1
+ # encoding: utf-8
2
+ module Mail
3
+ module CommonDate # :nodoc:
4
+ # Returns a date time object of the parsed date
5
+ def date_time
6
+ ::DateTime.parse("#{element.date_string} #{element.time_string}")
7
+ end
8
+
9
+ def default
10
+ date_time
11
+ end
12
+
13
+ def parse(val = value)
14
+ unless val.blank?
15
+ @element = Mail::DateTimeElement.new(val)
16
+ @tree = @element.tree
17
+ else
18
+ nil
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def do_encode(field_name)
25
+ "#{field_name}: #{value}\r\n"
26
+ end
27
+
28
+ def do_decode
29
+ "#{value}"
30
+ end
31
+
32
+ def element
33
+ @element ||= Mail::DateTimeElement.new(value)
34
+ end
35
+
36
+ # Returns the syntax tree of the Date
37
+ def tree
38
+ @tree ||= element.tree
39
+ end
40
+
41
+ end
42
+ end
@@ -0,0 +1,51 @@
1
+ # encoding: utf-8
2
+ module Mail
3
+ module CommonField # :nodoc:
4
+
5
+ def name=(value)
6
+ @name = value
7
+ end
8
+
9
+ def name
10
+ @name ||= nil
11
+ end
12
+
13
+ def value=(value)
14
+ @length = nil
15
+ @tree = nil
16
+ @element = nil
17
+ @value = value
18
+ end
19
+
20
+ def value
21
+ @value
22
+ end
23
+
24
+ def to_s
25
+ decoded
26
+ end
27
+
28
+ def default
29
+ decoded
30
+ end
31
+
32
+ def field_length
33
+ @length ||= "#{name}: #{encode(decoded)}".length
34
+ end
35
+
36
+ def responsible_for?( val )
37
+ name.to_s.downcase == val.to_s.downcase
38
+ end
39
+
40
+ private
41
+
42
+ def strip_field(field_name, value)
43
+ if value.is_a?(Array)
44
+ value
45
+ else
46
+ value.to_s.gsub(/#{field_name}:\s+/i, '')
47
+ end
48
+ end
49
+
50
+ end
51
+ end