mail-portertech 2.6.2.edge

Sign up to get free protection for your applications and to get access to all the features.
Files changed (153) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.rdoc +753 -0
  3. data/CONTRIBUTING.md +60 -0
  4. data/Dependencies.txt +2 -0
  5. data/Gemfile +15 -0
  6. data/MIT-LICENSE +20 -0
  7. data/README.md +683 -0
  8. data/Rakefile +29 -0
  9. data/TODO.rdoc +9 -0
  10. data/lib/mail.rb +91 -0
  11. data/lib/mail/attachments_list.rb +104 -0
  12. data/lib/mail/body.rb +291 -0
  13. data/lib/mail/check_delivery_params.rb +20 -0
  14. data/lib/mail/configuration.rb +75 -0
  15. data/lib/mail/core_extensions/nil.rb +19 -0
  16. data/lib/mail/core_extensions/object.rb +13 -0
  17. data/lib/mail/core_extensions/smtp.rb +24 -0
  18. data/lib/mail/core_extensions/string.rb +43 -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 +270 -0
  23. data/lib/mail/elements/address_list.rb +51 -0
  24. data/lib/mail/elements/content_disposition_element.rb +26 -0
  25. data/lib/mail/elements/content_location_element.rb +21 -0
  26. data/lib/mail/elements/content_transfer_encoding_element.rb +17 -0
  27. data/lib/mail/elements/content_type_element.rb +31 -0
  28. data/lib/mail/elements/date_time_element.rb +22 -0
  29. data/lib/mail/elements/envelope_from_element.rb +39 -0
  30. data/lib/mail/elements/message_ids_element.rb +24 -0
  31. data/lib/mail/elements/mime_version_element.rb +22 -0
  32. data/lib/mail/elements/phrase_list.rb +16 -0
  33. data/lib/mail/elements/received_element.rb +26 -0
  34. data/lib/mail/encodings.rb +304 -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 +39 -0
  40. data/lib/mail/encodings/transfer_encoding.rb +58 -0
  41. data/lib/mail/envelope.rb +30 -0
  42. data/lib/mail/field.rb +247 -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 +135 -0
  50. data/lib/mail/fields/common/common_date.rb +35 -0
  51. data/lib/mail/fields/common/common_field.rb +57 -0
  52. data/lib/mail/fields/common/common_message_id.rb +48 -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 +70 -0
  56. data/lib/mail/fields/content_id_field.rb +62 -0
  57. data/lib/mail/fields/content_location_field.rb +42 -0
  58. data/lib/mail/fields/content_transfer_encoding_field.rb +44 -0
  59. data/lib/mail/fields/content_type_field.rb +201 -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 +56 -0
  63. data/lib/mail/fields/keywords_field.rb +44 -0
  64. data/lib/mail/fields/message_id_field.rb +82 -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 +56 -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 +204 -0
  83. data/lib/mail/header.rb +274 -0
  84. data/lib/mail/indifferent_hash.rb +146 -0
  85. data/lib/mail/mail.rb +267 -0
  86. data/lib/mail/matchers/has_sent_mail.rb +157 -0
  87. data/lib/mail/message.rb +2160 -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 +400 -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 +52 -0
  95. data/lib/mail/network/delivery_methods/file_delivery.rb +45 -0
  96. data/lib/mail/network/delivery_methods/sendmail.rb +89 -0
  97. data/lib/mail/network/delivery_methods/smtp.rb +142 -0
  98. data/lib/mail/network/delivery_methods/smtp_connection.rb +61 -0
  99. data/lib/mail/network/delivery_methods/test_mailer.rb +44 -0
  100. data/lib/mail/network/retriever_methods/base.rb +63 -0
  101. data/lib/mail/network/retriever_methods/imap.rb +173 -0
  102. data/lib/mail/network/retriever_methods/pop3.rb +140 -0
  103. data/lib/mail/network/retriever_methods/test_retriever.rb +43 -0
  104. data/lib/mail/parsers.rb +26 -0
  105. data/lib/mail/parsers/address_lists_parser.rb +132 -0
  106. data/lib/mail/parsers/content_disposition_parser.rb +67 -0
  107. data/lib/mail/parsers/content_location_parser.rb +35 -0
  108. data/lib/mail/parsers/content_transfer_encoding_parser.rb +33 -0
  109. data/lib/mail/parsers/content_type_parser.rb +64 -0
  110. data/lib/mail/parsers/date_time_parser.rb +36 -0
  111. data/lib/mail/parsers/envelope_from_parser.rb +45 -0
  112. data/lib/mail/parsers/message_ids_parser.rb +39 -0
  113. data/lib/mail/parsers/mime_version_parser.rb +41 -0
  114. data/lib/mail/parsers/phrase_lists_parser.rb +33 -0
  115. data/lib/mail/parsers/ragel.rb +17 -0
  116. data/lib/mail/parsers/ragel/common.rl +184 -0
  117. data/lib/mail/parsers/ragel/date_time.rl +30 -0
  118. data/lib/mail/parsers/ragel/parser_info.rb +61 -0
  119. data/lib/mail/parsers/ragel/ruby.rb +39 -0
  120. data/lib/mail/parsers/ragel/ruby/machines/address_lists_machine.rb +14864 -0
  121. data/lib/mail/parsers/ragel/ruby/machines/address_lists_machine.rb.rl +37 -0
  122. data/lib/mail/parsers/ragel/ruby/machines/content_disposition_machine.rb +751 -0
  123. data/lib/mail/parsers/ragel/ruby/machines/content_disposition_machine.rb.rl +37 -0
  124. data/lib/mail/parsers/ragel/ruby/machines/content_location_machine.rb +614 -0
  125. data/lib/mail/parsers/ragel/ruby/machines/content_location_machine.rb.rl +37 -0
  126. data/lib/mail/parsers/ragel/ruby/machines/content_transfer_encoding_machine.rb +447 -0
  127. data/lib/mail/parsers/ragel/ruby/machines/content_transfer_encoding_machine.rb.rl +37 -0
  128. data/lib/mail/parsers/ragel/ruby/machines/content_type_machine.rb +825 -0
  129. data/lib/mail/parsers/ragel/ruby/machines/content_type_machine.rb.rl +37 -0
  130. data/lib/mail/parsers/ragel/ruby/machines/date_time_machine.rb +817 -0
  131. data/lib/mail/parsers/ragel/ruby/machines/date_time_machine.rb.rl +37 -0
  132. data/lib/mail/parsers/ragel/ruby/machines/envelope_from_machine.rb +2129 -0
  133. data/lib/mail/parsers/ragel/ruby/machines/envelope_from_machine.rb.rl +37 -0
  134. data/lib/mail/parsers/ragel/ruby/machines/message_ids_machine.rb +1570 -0
  135. data/lib/mail/parsers/ragel/ruby/machines/message_ids_machine.rb.rl +37 -0
  136. data/lib/mail/parsers/ragel/ruby/machines/mime_version_machine.rb +440 -0
  137. data/lib/mail/parsers/ragel/ruby/machines/mime_version_machine.rb.rl +37 -0
  138. data/lib/mail/parsers/ragel/ruby/machines/phrase_lists_machine.rb +564 -0
  139. data/lib/mail/parsers/ragel/ruby/machines/phrase_lists_machine.rb.rl +37 -0
  140. data/lib/mail/parsers/ragel/ruby/machines/rb_actions.rl +51 -0
  141. data/lib/mail/parsers/ragel/ruby/machines/received_machine.rb +5144 -0
  142. data/lib/mail/parsers/ragel/ruby/machines/received_machine.rb.rl +37 -0
  143. data/lib/mail/parsers/ragel/ruby/parser.rb.rl.erb +37 -0
  144. data/lib/mail/parsers/received_parser.rb +47 -0
  145. data/lib/mail/part.rb +120 -0
  146. data/lib/mail/parts_list.rb +57 -0
  147. data/lib/mail/patterns.rb +37 -0
  148. data/lib/mail/utilities.rb +225 -0
  149. data/lib/mail/values/unicode_tables.dat +0 -0
  150. data/lib/mail/version.rb +4 -0
  151. data/lib/mail/version_specific/ruby_1_8.rb +119 -0
  152. data/lib/mail/version_specific/ruby_1_9.rb +159 -0
  153. metadata +276 -0
@@ -0,0 +1,57 @@
1
+ # encoding: utf-8
2
+ #
3
+ # = Date Field
4
+ #
5
+ # The Date field inherits from StructuredField and handles the Date: header
6
+ # field in the email.
7
+ #
8
+ # Sending date to a mail message will instantiate a Mail::Field object that
9
+ # has a DateField as its field type. This includes all Mail::CommonAddress
10
+ # module instance methods.
11
+ #
12
+ # There must be excatly one Date field in an RFC2822 email.
13
+ #
14
+ # == Examples:
15
+ #
16
+ # mail = Mail.new
17
+ # mail.date = 'Mon, 24 Nov 1997 14:22:01 -0800'
18
+ # mail.date #=> #<DateTime: 211747170121/86400,-1/3,2299161>
19
+ # mail.date.to_s #=> 'Mon, 24 Nov 1997 14:22:01 -0800'
20
+ # mail[:date] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::DateField:0x180e1c4
21
+ # mail['date'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::DateField:0x180e1c4
22
+ # mail['Date'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::DateField:0x180e1c4
23
+ #
24
+ require 'mail/fields/common/common_date'
25
+
26
+ module Mail
27
+ class DateField < StructuredField
28
+
29
+ include Mail::CommonDate
30
+
31
+ FIELD_NAME = 'date'
32
+ CAPITALIZED_FIELD = "Date"
33
+
34
+ def initialize(value = nil, charset = 'utf-8')
35
+ self.charset = charset
36
+ if value.blank?
37
+ value = ::DateTime.now.strftime('%a, %d %b %Y %H:%M:%S %z')
38
+ else
39
+ value = strip_field(FIELD_NAME, value)
40
+ value.to_s.gsub!(/\(.*?\)/, '')
41
+ value = ::DateTime.parse(value.to_s.squeeze(" ")).strftime('%a, %d %b %Y %H:%M:%S %z')
42
+ end
43
+ super(CAPITALIZED_FIELD, value, charset)
44
+ rescue ArgumentError => e
45
+ raise e unless "invalid date"==e.message
46
+ end
47
+
48
+ def encoded
49
+ do_encode(CAPITALIZED_FIELD)
50
+ end
51
+
52
+ def decoded
53
+ do_decode
54
+ end
55
+
56
+ end
57
+ end
@@ -0,0 +1,55 @@
1
+ # encoding: utf-8
2
+ #
3
+ # = From Field
4
+ #
5
+ # The From field inherits from StructuredField and handles the From: header
6
+ # field in the email.
7
+ #
8
+ # Sending from to a mail message will instantiate a Mail::Field object that
9
+ # has a FromField as its field type. This includes all Mail::CommonAddress
10
+ # module instance metods.
11
+ #
12
+ # Only one From 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.from = 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
19
+ # mail.from #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
20
+ # mail[:from] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::FromField:0x180e1c4
21
+ # mail['from'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::FromField:0x180e1c4
22
+ # mail['From'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::FromField:0x180e1c4
23
+ #
24
+ # mail[:from].encoded #=> 'from: Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net\r\n'
25
+ # mail[:from].decoded #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
26
+ # mail[:from].addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
27
+ # mail[:from].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 FromField < StructuredField
33
+
34
+ include Mail::CommonAddress
35
+
36
+ FIELD_NAME = 'from'
37
+ CAPITALIZED_FIELD = 'From'
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,56 @@
1
+ # encoding: utf-8
2
+ #
3
+ # = In-Reply-To Field
4
+ #
5
+ # The In-Reply-To field inherits from StructuredField and handles the
6
+ # In-Reply-To: header field in the email.
7
+ #
8
+ # Sending in_reply_to to a mail message will instantiate a Mail::Field object that
9
+ # has a InReplyToField as its field type. This includes all Mail::CommonMessageId
10
+ # module instance metods.
11
+ #
12
+ # Note that, the #message_ids method will return an array of message IDs without the
13
+ # enclosing angle brackets which per RFC are not syntactically part of the message id.
14
+ #
15
+ # Only one InReplyTo field can appear in a header, though it can have multiple
16
+ # Message IDs.
17
+ #
18
+ # == Examples:
19
+ #
20
+ # mail = Mail.new
21
+ # mail.in_reply_to = '<F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom>'
22
+ # mail.in_reply_to #=> '<F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom>'
23
+ # mail[:in_reply_to] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::InReplyToField:0x180e1c4
24
+ # mail['in_reply_to'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::InReplyToField:0x180e1c4
25
+ # mail['In-Reply-To'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::InReplyToField:0x180e1c4
26
+ #
27
+ # mail[:in_reply_to].message_ids #=> ['F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom']
28
+ #
29
+ require 'mail/fields/common/common_message_id'
30
+
31
+ module Mail
32
+ class InReplyToField < StructuredField
33
+
34
+ include Mail::CommonMessageId
35
+
36
+ FIELD_NAME = 'in-reply-to'
37
+ CAPITALIZED_FIELD = 'In-Reply-To'
38
+
39
+ def initialize(value = nil, charset = 'utf-8')
40
+ self.charset = charset
41
+ value = value.join("\r\n\s") if value.is_a?(Array)
42
+ super(CAPITALIZED_FIELD, strip_field(FIELD_NAME, value), charset)
43
+ self.parse
44
+ self
45
+ end
46
+
47
+ def encoded
48
+ do_encode(CAPITALIZED_FIELD)
49
+ end
50
+
51
+ def decoded
52
+ do_decode
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+ #
3
+ # keywords = "Keywords:" phrase *("," phrase) CRLF
4
+ module Mail
5
+ class KeywordsField < StructuredField
6
+
7
+ FIELD_NAME = 'keywords'
8
+ CAPITALIZED_FIELD = 'Keywords'
9
+
10
+ def initialize(value = nil, charset = 'utf-8')
11
+ self.charset = charset
12
+ super(CAPITALIZED_FIELD, strip_field(FIELD_NAME, value), charset)
13
+ self.parse
14
+ self
15
+ end
16
+
17
+ def parse(val = value)
18
+ unless val.blank?
19
+ @phrase_list ||= PhraseList.new(value)
20
+ end
21
+ end
22
+
23
+ def phrase_list
24
+ @phrase_list ||= PhraseList.new(value)
25
+ end
26
+
27
+ def keywords
28
+ phrase_list.phrases
29
+ end
30
+
31
+ def encoded
32
+ "#{CAPITALIZED_FIELD}: #{keywords.join(",\r\n ")}\r\n"
33
+ end
34
+
35
+ def decoded
36
+ keywords.join(', ')
37
+ end
38
+
39
+ def default
40
+ keywords
41
+ end
42
+
43
+ end
44
+ end
@@ -0,0 +1,82 @@
1
+ # encoding: utf-8
2
+ #
3
+ # = Message-ID Field
4
+ #
5
+ # The Message-ID field inherits from StructuredField and handles the
6
+ # Message-ID: header field in the email.
7
+ #
8
+ # Sending message_id to a mail message will instantiate a Mail::Field object that
9
+ # has a MessageIdField as its field type. This includes all Mail::CommonMessageId
10
+ # module instance metods.
11
+ #
12
+ # Only one MessageId field can appear in a header, and syntactically it can only have
13
+ # one Message ID. The message_ids method call has been left in however as it will only
14
+ # return the one message id, ie, an array of length 1.
15
+ #
16
+ # Note that, the #message_ids method will return an array of message IDs without the
17
+ # enclosing angle brackets which per RFC are not syntactically part of the message id.
18
+ #
19
+ # == Examples:
20
+ #
21
+ # mail = Mail.new
22
+ # mail.message_id = '<F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom>'
23
+ # mail.message_id #=> '<F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom>'
24
+ # mail[:message_id] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::MessageIdField:0x180e1c4
25
+ # mail['message_id'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::MessageIdField:0x180e1c4
26
+ # mail['Message-ID'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::MessageIdField:0x180e1c4
27
+ #
28
+ # mail[:message_id].message_id #=> 'F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom'
29
+ # mail[:message_id].message_ids #=> ['F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom']
30
+ #
31
+ require 'mail/fields/common/common_message_id'
32
+
33
+ module Mail
34
+ class MessageIdField < StructuredField
35
+
36
+ include Mail::CommonMessageId
37
+
38
+ FIELD_NAME = 'message-id'
39
+ CAPITALIZED_FIELD = 'Message-ID'
40
+
41
+ def initialize(value = nil, charset = 'utf-8')
42
+ self.charset = charset
43
+ @uniq = 1
44
+ if value.blank?
45
+ self.name = CAPITALIZED_FIELD
46
+ self.value = generate_message_id
47
+ else
48
+ super(CAPITALIZED_FIELD, strip_field(FIELD_NAME, value), charset)
49
+ end
50
+ self.parse
51
+ self
52
+
53
+ end
54
+
55
+ def name
56
+ 'Message-ID'
57
+ end
58
+
59
+ def message_ids
60
+ [message_id]
61
+ end
62
+
63
+ def to_s
64
+ "<#{message_id}>"
65
+ end
66
+
67
+ def encoded
68
+ do_encode(CAPITALIZED_FIELD)
69
+ end
70
+
71
+ def decoded
72
+ do_decode
73
+ end
74
+
75
+ private
76
+
77
+ def generate_message_id
78
+ "<#{Mail.random_tag}@#{::Socket.gethostname}.mail>"
79
+ end
80
+
81
+ end
82
+ end
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+ #
3
+ #
4
+ #
5
+ module Mail
6
+ class MimeVersionField < StructuredField
7
+
8
+ FIELD_NAME = 'mime-version'
9
+ CAPITALIZED_FIELD = 'Mime-Version'
10
+
11
+ def initialize(value = nil, charset = 'utf-8')
12
+ self.charset = charset
13
+ if value.blank?
14
+ value = '1.0'
15
+ end
16
+ super(CAPITALIZED_FIELD, strip_field(FIELD_NAME, value), charset)
17
+ self.parse
18
+ self
19
+
20
+ end
21
+
22
+ def parse(val = value)
23
+ unless val.blank?
24
+ @element = Mail::MimeVersionElement.new(val)
25
+ end
26
+ end
27
+
28
+ def element
29
+ @element ||= Mail::MimeVersionElement.new(value)
30
+ end
31
+
32
+ def version
33
+ "#{element.major}.#{element.minor}"
34
+ end
35
+
36
+ def major
37
+ element.major.to_i
38
+ end
39
+
40
+ def minor
41
+ element.minor.to_i
42
+ end
43
+
44
+ def encoded
45
+ "#{CAPITALIZED_FIELD}: #{version}\r\n"
46
+ end
47
+
48
+ def decoded
49
+ version
50
+ end
51
+
52
+ end
53
+ end
@@ -0,0 +1,13 @@
1
+ # encoding: utf-8
2
+ #
3
+ # The field names of any optional-field MUST NOT be identical to any
4
+ # field name specified elsewhere in this standard.
5
+ #
6
+ # optional-field = field-name ":" unstructured CRLF
7
+ require 'mail/fields/unstructured_field'
8
+
9
+ module Mail
10
+ class OptionalField < UnstructuredField
11
+
12
+ end
13
+ end
@@ -0,0 +1,75 @@
1
+ # encoding: utf-8
2
+ #
3
+ # trace = [return]
4
+ # 1*received
5
+ #
6
+ # return = "Return-Path:" path CRLF
7
+ #
8
+ # path = ([CFWS] "<" ([CFWS] / addr-spec) ">" [CFWS]) /
9
+ # obs-path
10
+ #
11
+ # received = "Received:" name-val-list ";" date-time CRLF
12
+ #
13
+ # name-val-list = [CFWS] [name-val-pair *(CFWS name-val-pair)]
14
+ #
15
+ # name-val-pair = item-name CFWS item-value
16
+ #
17
+ # item-name = ALPHA *(["-"] (ALPHA / DIGIT))
18
+ #
19
+ # item-value = 1*angle-addr / addr-spec /
20
+ # atom / domain / msg-id
21
+ #
22
+ module Mail
23
+ class ReceivedField < StructuredField
24
+
25
+ FIELD_NAME = 'received'
26
+ CAPITALIZED_FIELD = 'Received'
27
+
28
+ def initialize(value = nil, charset = 'utf-8')
29
+ self.charset = charset
30
+ super(CAPITALIZED_FIELD, strip_field(FIELD_NAME, value), charset)
31
+ self.parse
32
+ self
33
+
34
+ end
35
+
36
+ def parse(val = value)
37
+ unless val.blank?
38
+ @element = Mail::ReceivedElement.new(val)
39
+ end
40
+ end
41
+
42
+ def element
43
+ @element ||= Mail::ReceivedElement.new(value)
44
+ end
45
+
46
+ def date_time
47
+ @datetime ||= ::DateTime.parse("#{element.date_time}")
48
+ end
49
+
50
+ def info
51
+ element.info
52
+ end
53
+
54
+ def formatted_date
55
+ date_time.strftime("%a, %d %b %Y %H:%M:%S ") + date_time.zone.delete(':')
56
+ end
57
+
58
+ def encoded
59
+ if value.blank?
60
+ "#{CAPITALIZED_FIELD}: \r\n"
61
+ else
62
+ "#{CAPITALIZED_FIELD}: #{info}; #{formatted_date}\r\n"
63
+ end
64
+ end
65
+
66
+ def decoded
67
+ if value.blank?
68
+ ""
69
+ else
70
+ "#{info}; #{formatted_date}"
71
+ end
72
+ end
73
+
74
+ end
75
+ end
@@ -0,0 +1,56 @@
1
+ # encoding: utf-8
2
+ #
3
+ # = References Field
4
+ #
5
+ # The References field inherits references StructuredField and handles the References: header
6
+ # field in the email.
7
+ #
8
+ # Sending references to a mail message will instantiate a Mail::Field object that
9
+ # has a ReferencesField as its field type. This includes all Mail::CommonAddress
10
+ # module instance metods.
11
+ #
12
+ # Note that, the #message_ids method will return an array of message IDs without the
13
+ # enclosing angle brackets which per RFC are not syntactically part of the message id.
14
+ #
15
+ # Only one References field can appear in a header, though it can have multiple
16
+ # Message IDs.
17
+ #
18
+ # == Examples:
19
+ #
20
+ # mail = Mail.new
21
+ # mail.references = '<F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom>'
22
+ # mail.references #=> '<F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom>'
23
+ # mail[:references] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ReferencesField:0x180e1c4
24
+ # mail['references'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ReferencesField:0x180e1c4
25
+ # mail['References'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::ReferencesField:0x180e1c4
26
+ #
27
+ # mail[:references].message_ids #=> ['F6E2D0B4-CC35-4A91-BA4C-C7C712B10C13@test.me.dom']
28
+ #
29
+ require 'mail/fields/common/common_message_id'
30
+
31
+ module Mail
32
+ class ReferencesField < StructuredField
33
+
34
+ include CommonMessageId
35
+
36
+ FIELD_NAME = 'references'
37
+ CAPITALIZED_FIELD = 'References'
38
+
39
+ def initialize(value = nil, charset = 'utf-8')
40
+ self.charset = charset
41
+ value = value.join("\r\n\s") if value.is_a?(Array)
42
+ super(CAPITALIZED_FIELD, strip_field(FIELD_NAME, value), charset)
43
+ self.parse
44
+ self
45
+ end
46
+
47
+ def encoded
48
+ do_encode(CAPITALIZED_FIELD)
49
+ end
50
+
51
+ def decoded
52
+ do_decode
53
+ end
54
+
55
+ end
56
+ end