otherinbox-mail 2.4.4
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +607 -0
- data/CONTRIBUTING.md +45 -0
- data/Dependencies.txt +3 -0
- data/Gemfile +26 -0
- data/Gemfile.lock +44 -0
- data/README.md +663 -0
- data/Rakefile +40 -0
- data/TODO.rdoc +9 -0
- data/lib/VERSION +4 -0
- data/lib/mail.rb +101 -0
- data/lib/mail/attachments_list.rb +104 -0
- data/lib/mail/body.rb +291 -0
- data/lib/mail/configuration.rb +75 -0
- data/lib/mail/core_extensions/nil.rb +17 -0
- data/lib/mail/core_extensions/object.rb +13 -0
- data/lib/mail/core_extensions/shell_escape.rb +56 -0
- data/lib/mail/core_extensions/smtp.rb +25 -0
- data/lib/mail/core_extensions/string.rb +33 -0
- data/lib/mail/core_extensions/string/access.rb +145 -0
- data/lib/mail/core_extensions/string/multibyte.rb +78 -0
- data/lib/mail/elements.rb +14 -0
- data/lib/mail/elements/address.rb +306 -0
- data/lib/mail/elements/address_list.rb +74 -0
- data/lib/mail/elements/content_disposition_element.rb +30 -0
- data/lib/mail/elements/content_location_element.rb +25 -0
- data/lib/mail/elements/content_transfer_encoding_element.rb +24 -0
- data/lib/mail/elements/content_type_element.rb +35 -0
- data/lib/mail/elements/date_time_element.rb +26 -0
- data/lib/mail/elements/envelope_from_element.rb +34 -0
- data/lib/mail/elements/message_ids_element.rb +29 -0
- data/lib/mail/elements/mime_version_element.rb +26 -0
- data/lib/mail/elements/phrase_list.rb +21 -0
- data/lib/mail/elements/received_element.rb +30 -0
- data/lib/mail/encodings.rb +274 -0
- data/lib/mail/encodings/7bit.rb +31 -0
- data/lib/mail/encodings/8bit.rb +31 -0
- data/lib/mail/encodings/base64.rb +33 -0
- data/lib/mail/encodings/binary.rb +31 -0
- data/lib/mail/encodings/quoted_printable.rb +38 -0
- data/lib/mail/encodings/transfer_encoding.rb +58 -0
- data/lib/mail/envelope.rb +35 -0
- data/lib/mail/field.rb +234 -0
- data/lib/mail/field_list.rb +33 -0
- data/lib/mail/fields.rb +35 -0
- data/lib/mail/fields/bcc_field.rb +56 -0
- data/lib/mail/fields/cc_field.rb +55 -0
- data/lib/mail/fields/comments_field.rb +41 -0
- data/lib/mail/fields/common/address_container.rb +16 -0
- data/lib/mail/fields/common/common_address.rb +125 -0
- data/lib/mail/fields/common/common_date.rb +42 -0
- data/lib/mail/fields/common/common_field.rb +51 -0
- data/lib/mail/fields/common/common_message_id.rb +44 -0
- data/lib/mail/fields/common/parameter_hash.rb +58 -0
- data/lib/mail/fields/content_description_field.rb +19 -0
- data/lib/mail/fields/content_disposition_field.rb +69 -0
- data/lib/mail/fields/content_id_field.rb +63 -0
- data/lib/mail/fields/content_location_field.rb +42 -0
- data/lib/mail/fields/content_transfer_encoding_field.rb +50 -0
- data/lib/mail/fields/content_type_field.rb +198 -0
- data/lib/mail/fields/date_field.rb +57 -0
- data/lib/mail/fields/from_field.rb +55 -0
- data/lib/mail/fields/in_reply_to_field.rb +55 -0
- data/lib/mail/fields/keywords_field.rb +44 -0
- data/lib/mail/fields/message_id_field.rb +83 -0
- data/lib/mail/fields/mime_version_field.rb +53 -0
- data/lib/mail/fields/optional_field.rb +13 -0
- data/lib/mail/fields/received_field.rb +75 -0
- data/lib/mail/fields/references_field.rb +55 -0
- data/lib/mail/fields/reply_to_field.rb +55 -0
- data/lib/mail/fields/resent_bcc_field.rb +55 -0
- data/lib/mail/fields/resent_cc_field.rb +55 -0
- data/lib/mail/fields/resent_date_field.rb +35 -0
- data/lib/mail/fields/resent_from_field.rb +55 -0
- data/lib/mail/fields/resent_message_id_field.rb +34 -0
- data/lib/mail/fields/resent_sender_field.rb +62 -0
- data/lib/mail/fields/resent_to_field.rb +55 -0
- data/lib/mail/fields/return_path_field.rb +65 -0
- data/lib/mail/fields/sender_field.rb +67 -0
- data/lib/mail/fields/structured_field.rb +51 -0
- data/lib/mail/fields/subject_field.rb +16 -0
- data/lib/mail/fields/to_field.rb +55 -0
- data/lib/mail/fields/unstructured_field.rb +191 -0
- data/lib/mail/header.rb +265 -0
- data/lib/mail/indifferent_hash.rb +146 -0
- data/lib/mail/mail.rb +255 -0
- data/lib/mail/matchers/has_sent_mail.rb +124 -0
- data/lib/mail/message.rb +2059 -0
- data/lib/mail/multibyte.rb +42 -0
- data/lib/mail/multibyte/chars.rb +474 -0
- data/lib/mail/multibyte/exceptions.rb +8 -0
- data/lib/mail/multibyte/unicode.rb +392 -0
- data/lib/mail/multibyte/utils.rb +60 -0
- data/lib/mail/network.rb +14 -0
- data/lib/mail/network/delivery_methods/exim.rb +53 -0
- data/lib/mail/network/delivery_methods/file_delivery.rb +40 -0
- data/lib/mail/network/delivery_methods/sendmail.rb +62 -0
- data/lib/mail/network/delivery_methods/smtp.rb +153 -0
- data/lib/mail/network/delivery_methods/smtp_connection.rb +74 -0
- data/lib/mail/network/delivery_methods/test_mailer.rb +40 -0
- data/lib/mail/network/retriever_methods/base.rb +63 -0
- data/lib/mail/network/retriever_methods/imap.rb +168 -0
- data/lib/mail/network/retriever_methods/pop3.rb +140 -0
- data/lib/mail/network/retriever_methods/test_retriever.rb +47 -0
- data/lib/mail/parsers/address_lists.rb +64 -0
- data/lib/mail/parsers/address_lists.treetop +19 -0
- data/lib/mail/parsers/content_disposition.rb +535 -0
- data/lib/mail/parsers/content_disposition.treetop +46 -0
- data/lib/mail/parsers/content_location.rb +139 -0
- data/lib/mail/parsers/content_location.treetop +20 -0
- data/lib/mail/parsers/content_transfer_encoding.rb +162 -0
- data/lib/mail/parsers/content_transfer_encoding.treetop +20 -0
- data/lib/mail/parsers/content_type.rb +967 -0
- data/lib/mail/parsers/content_type.treetop +68 -0
- data/lib/mail/parsers/date_time.rb +114 -0
- data/lib/mail/parsers/date_time.treetop +11 -0
- data/lib/mail/parsers/envelope_from.rb +194 -0
- data/lib/mail/parsers/envelope_from.treetop +32 -0
- data/lib/mail/parsers/message_ids.rb +45 -0
- data/lib/mail/parsers/message_ids.treetop +15 -0
- data/lib/mail/parsers/mime_version.rb +144 -0
- data/lib/mail/parsers/mime_version.treetop +19 -0
- data/lib/mail/parsers/phrase_lists.rb +45 -0
- data/lib/mail/parsers/phrase_lists.treetop +15 -0
- data/lib/mail/parsers/received.rb +71 -0
- data/lib/mail/parsers/received.treetop +11 -0
- data/lib/mail/parsers/rfc2045.rb +464 -0
- data/lib/mail/parsers/rfc2045.treetop +36 -0
- data/lib/mail/parsers/rfc2822.rb +5341 -0
- data/lib/mail/parsers/rfc2822.treetop +410 -0
- data/lib/mail/parsers/rfc2822_obsolete.rb +3768 -0
- data/lib/mail/parsers/rfc2822_obsolete.treetop +241 -0
- data/lib/mail/part.rb +116 -0
- data/lib/mail/parts_list.rb +55 -0
- data/lib/mail/patterns.rb +34 -0
- data/lib/mail/utilities.rb +215 -0
- data/lib/mail/version.rb +24 -0
- data/lib/mail/version_specific/ruby_1_8.rb +98 -0
- data/lib/mail/version_specific/ruby_1_9.rb +113 -0
- data/lib/tasks/corpus.rake +125 -0
- data/lib/tasks/treetop.rake +10 -0
- metadata +253 -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 it's 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 it's 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 Lindsaar <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,55 @@
|
|
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 it's 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
|
+
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,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"
|
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,83 @@
|
|
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 it's 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
|
+
fqdn = ::Socket.gethostname
|
79
|
+
"<#{Mail.random_tag}@#{fqdn}.mail>"
|
80
|
+
end
|
81
|
+
|
82
|
+
end
|
83
|
+
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
|