mail 1.1.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of mail might be problematic. Click here for more details.
- data/CHANGELOG.rdoc +14 -1
- data/README.rdoc +37 -13
- data/lib/mail/configuration.rb +4 -0
- data/lib/mail/elements/address.rb +11 -0
- data/lib/mail/encodings/base64.rb +1 -0
- data/lib/mail/encodings/encodings.rb +133 -6
- data/lib/mail/encodings/quoted_printable.rb +1 -1
- data/lib/mail/field.rb +34 -34
- data/lib/mail/fields/bcc_field.rb +10 -1
- data/lib/mail/fields/cc_field.rb +10 -1
- data/lib/mail/fields/comments_field.rb +2 -1
- data/lib/mail/fields/common/common_address.rb +25 -1
- data/lib/mail/fields/common/common_date.rb +8 -5
- data/lib/mail/fields/common/common_field.rb +2 -74
- data/lib/mail/fields/common/common_message_id.rb +10 -0
- data/lib/mail/fields/common/parameter_hash.rb +10 -0
- data/lib/mail/fields/content_description_field.rb +3 -2
- data/lib/mail/fields/content_disposition_field.rb +12 -2
- data/lib/mail/fields/content_id_field.rb +12 -2
- data/lib/mail/fields/content_location_field.rb +12 -2
- data/lib/mail/fields/content_transfer_encoding_field.rb +12 -2
- data/lib/mail/fields/content_type_field.rb +26 -5
- data/lib/mail/fields/date_field.rb +11 -2
- data/lib/mail/fields/from_field.rb +10 -1
- data/lib/mail/fields/in_reply_to_field.rb +10 -1
- data/lib/mail/fields/keywords_field.rb +10 -1
- data/lib/mail/fields/message_id_field.rb +11 -2
- data/lib/mail/fields/mime_version_field.rb +11 -2
- data/lib/mail/fields/received_field.rb +10 -1
- data/lib/mail/fields/references_field.rb +10 -1
- data/lib/mail/fields/reply_to_field.rb +10 -1
- data/lib/mail/fields/resent_bcc_field.rb +10 -1
- data/lib/mail/fields/resent_cc_field.rb +10 -1
- data/lib/mail/fields/resent_date_field.rb +10 -1
- data/lib/mail/fields/resent_from_field.rb +10 -1
- data/lib/mail/fields/resent_message_id_field.rb +10 -1
- data/lib/mail/fields/resent_sender_field.rb +10 -1
- data/lib/mail/fields/resent_to_field.rb +10 -1
- data/lib/mail/fields/return_path_field.rb +10 -1
- data/lib/mail/fields/sender_field.rb +10 -1
- data/lib/mail/fields/subject_field.rb +2 -1
- data/lib/mail/fields/to_field.rb +10 -1
- data/lib/mail/fields/unstructured_field.rb +82 -0
- data/lib/mail/header.rb +2 -2
- data/lib/mail/message.rb +25 -9
- data/lib/mail/utilities.rb +7 -1
- data/lib/mail/version.rb +2 -2
- data/lib/mail/version_specific/ruby_1_8.rb +30 -10
- data/lib/mail/version_specific/ruby_1_9.rb +30 -8
- metadata +1 -1
data/lib/mail/header.rb
CHANGED
@@ -160,7 +160,7 @@ module Mail
|
|
160
160
|
def encoded
|
161
161
|
buffer = ''
|
162
162
|
fields.each do |field|
|
163
|
-
buffer << field.encoded
|
163
|
+
buffer << field.encoded
|
164
164
|
end
|
165
165
|
buffer
|
166
166
|
end
|
@@ -221,7 +221,7 @@ module Mail
|
|
221
221
|
end
|
222
222
|
|
223
223
|
def limited_field?(name)
|
224
|
-
LIMITED_FIELDS.include?(name.downcase)
|
224
|
+
LIMITED_FIELDS.include?(name.to_s.downcase)
|
225
225
|
end
|
226
226
|
|
227
227
|
end
|
data/lib/mail/message.rb
CHANGED
@@ -200,6 +200,20 @@ module Mail
|
|
200
200
|
value ? self.from = value : header[:from]
|
201
201
|
end
|
202
202
|
|
203
|
+
# Returns the list of addresses this message should be sent to by
|
204
|
+
# collecting the addresses off the to, cc and bcc fields.
|
205
|
+
#
|
206
|
+
# Example:
|
207
|
+
#
|
208
|
+
# mail.to = 'mikel@test.lindsaar.net'
|
209
|
+
# mail.cc = 'sam@test.lindsaar.net'
|
210
|
+
# mail.bcc = 'bob@test.lindsaar.net'
|
211
|
+
# mail.destinations.length #=> 3
|
212
|
+
# mail.destinations.first #=> 'mikel@test.lindsaar.net'
|
213
|
+
def destinations
|
214
|
+
[to, cc, bcc].map { |f| f.addresses if f }.compact.flatten
|
215
|
+
end
|
216
|
+
|
203
217
|
# Sets the subject field in the message header.
|
204
218
|
#
|
205
219
|
# Example:
|
@@ -559,23 +573,21 @@ module Mail
|
|
559
573
|
|
560
574
|
# Encodes the message, calls encode on all it's parts, gets an email message
|
561
575
|
# ready to send
|
562
|
-
def
|
563
|
-
parts.each { |part| part.
|
576
|
+
def ready_to_send!
|
577
|
+
parts.each { |part| part.ready_to_send! }
|
564
578
|
add_required_fields
|
565
579
|
end
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
parts.each { |part| part.decode! }
|
571
|
-
add_required_fields
|
580
|
+
|
581
|
+
def encode!
|
582
|
+
STDERR.puts("Deprecated in 1.1.0 in favour of :ready_to_send! as it is less confusing with encoding and decoding.")
|
583
|
+
ready_to_send!
|
572
584
|
end
|
573
585
|
|
574
586
|
# Outputs an encoded string representation of the mail message including
|
575
587
|
# all headers, attachments, etc. This is an encoded email in US-ASCII,
|
576
588
|
# so it is able to be directly sent to an email server.
|
577
589
|
def encoded
|
578
|
-
|
590
|
+
ready_to_send!
|
579
591
|
buffer = header.encoded
|
580
592
|
buffer << "\r\n"
|
581
593
|
buffer << body.encoded
|
@@ -584,6 +596,10 @@ module Mail
|
|
584
596
|
|
585
597
|
alias :to_s :encoded
|
586
598
|
|
599
|
+
def decoded
|
600
|
+
raise NoMethodError, 'Can not decode an entire message, try calling #decoded on the various fields and body or parts if it is a multipart message.'
|
601
|
+
end
|
602
|
+
|
587
603
|
private
|
588
604
|
|
589
605
|
# 2.1. General Description
|
data/lib/mail/utilities.rb
CHANGED
@@ -24,7 +24,13 @@ module Mail
|
|
24
24
|
# If the string supplied has PHRASE unsafe characters in it, will return the string quoted
|
25
25
|
# in double quotes, otherwise returns the string unmodified
|
26
26
|
def quote_phrase( str )
|
27
|
-
|
27
|
+
if RUBY_VERSION >= '1.9'
|
28
|
+
string = str.dup
|
29
|
+
string.force_encoding('ASCII-8BIT')
|
30
|
+
(PHRASE_UNSAFE === string) ? dquote(str) : str
|
31
|
+
else
|
32
|
+
(PHRASE_UNSAFE === str) ? dquote(str) : str
|
33
|
+
end
|
28
34
|
end
|
29
35
|
|
30
36
|
# Returns true if the string supplied is free from characters not allowed as a TOKEN
|
data/lib/mail/version.rb
CHANGED
@@ -36,29 +36,49 @@ module Mail
|
|
36
36
|
def Ruby18.get_constant(klass, string)
|
37
37
|
klass.const_get( string )
|
38
38
|
end
|
39
|
-
|
40
|
-
def Ruby18.
|
39
|
+
|
40
|
+
def Ruby18.b_value_encode(str, encoding)
|
41
41
|
# Ruby 1.8 requires an encoding to work
|
42
42
|
raise ArgumentError, "Must supply an encoding" if encoding.nil?
|
43
|
-
return str if str.ascii_only?
|
44
43
|
encoding = encoding.to_s.upcase.gsub('_', '-')
|
45
|
-
|
46
|
-
"=?#{encoding}?B?#{string.chomp}?="
|
44
|
+
[Encodings::Base64.encode(str), encoding]
|
47
45
|
end
|
48
|
-
|
49
|
-
def Ruby18.
|
46
|
+
|
47
|
+
def Ruby18.b_value_decode(str)
|
48
|
+
match = str.match(/\=\?(.+)?\?B\?(.+)?\?\=/)
|
49
|
+
if match
|
50
|
+
encoding = match[1]
|
51
|
+
str = Ruby18.decode_base64(match[2])
|
52
|
+
end
|
53
|
+
str
|
54
|
+
end
|
55
|
+
|
56
|
+
def Ruby18.q_value_encode(str, encoding)
|
50
57
|
# Ruby 1.8 requires an encoding to work
|
51
58
|
raise ArgumentError, "Must supply an encoding" if encoding.nil?
|
52
|
-
return str if str.ascii_only?
|
53
59
|
encoding = encoding.to_s.upcase.gsub('_', '-')
|
54
|
-
|
55
|
-
|
60
|
+
[Encodings::QuotedPrintable.encode(str), encoding]
|
61
|
+
end
|
62
|
+
|
63
|
+
def Ruby18.q_value_decode(str)
|
64
|
+
match = str.match(/\=\?(.+)?\?Q\?(.+)?\?\=/)
|
65
|
+
if match
|
66
|
+
encoding = match[1]
|
67
|
+
str = Encodings::QuotedPrintable.decode(match[2])
|
68
|
+
end
|
69
|
+
str
|
56
70
|
end
|
57
71
|
|
58
72
|
def Ruby18.param_decode(str, encoding)
|
59
73
|
URI.unescape(str)
|
60
74
|
end
|
61
75
|
|
76
|
+
def Ruby18.param_encode(str)
|
77
|
+
encoding = $KCODE.to_s.downcase
|
78
|
+
language = Mail::Configuration.instance.param_encode_language
|
79
|
+
"#{encoding}'#{language}'#{URI.escape(str)}"
|
80
|
+
end
|
81
|
+
|
62
82
|
end
|
63
83
|
|
64
84
|
end
|
@@ -31,18 +31,34 @@ module Mail
|
|
31
31
|
klass.const_get( string.to_sym )
|
32
32
|
end
|
33
33
|
|
34
|
-
def Ruby19.
|
35
|
-
return str if str.ascii_only?
|
34
|
+
def Ruby19.b_value_encode(str, encoding = nil)
|
36
35
|
encoding = str.encoding.to_s
|
37
|
-
|
38
|
-
"=?#{encoding}?B?#{string.chomp}?="
|
36
|
+
[Ruby19.encode_base64(str), encoding]
|
39
37
|
end
|
40
38
|
|
41
|
-
def Ruby19.
|
42
|
-
|
39
|
+
def Ruby19.b_value_decode(str)
|
40
|
+
match = str.match(/\=\?(.+)?\?B\?(.+)?\?\=/)
|
41
|
+
if match
|
42
|
+
encoding = match[1]
|
43
|
+
str = Ruby19.decode_base64(match[2])
|
44
|
+
str.force_encoding(encoding)
|
45
|
+
end
|
46
|
+
str
|
47
|
+
end
|
48
|
+
|
49
|
+
def Ruby19.q_value_encode(str, encoding = nil)
|
43
50
|
encoding = str.encoding.to_s
|
44
|
-
|
45
|
-
|
51
|
+
[Encodings::QuotedPrintable.encode(str), encoding]
|
52
|
+
end
|
53
|
+
|
54
|
+
def Ruby19.q_value_decode(str)
|
55
|
+
match = str.match(/\=\?(.+)?\?Q\?(.+)?\?\=/)
|
56
|
+
if match
|
57
|
+
encoding = match[1]
|
58
|
+
str = Encodings::QuotedPrintable.decode(match[2])
|
59
|
+
str.force_encoding(encoding)
|
60
|
+
end
|
61
|
+
str
|
46
62
|
end
|
47
63
|
|
48
64
|
def Ruby19.param_decode(str, encoding)
|
@@ -51,5 +67,11 @@ module Mail
|
|
51
67
|
string
|
52
68
|
end
|
53
69
|
|
70
|
+
def Ruby19.param_encode(str)
|
71
|
+
encoding = str.encoding.to_s.downcase
|
72
|
+
language = Mail::Configuration.instance.param_encode_language
|
73
|
+
"#{encoding}'#{language}'#{URI.escape(str)}"
|
74
|
+
end
|
75
|
+
|
54
76
|
end
|
55
77
|
end
|