mail 2.2.15 → 2.2.16
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 +16 -0
- data/lib/VERSION +1 -1
- data/lib/mail/body.rb +6 -1
- data/lib/mail/configuration.rb +2 -0
- data/lib/mail/encodings.rb +43 -43
- data/lib/mail/fields/received_field.rb +11 -3
- data/lib/mail/fields/return_path_field.rb +1 -0
- data/lib/mail/fields/unstructured_field.rb +1 -0
- data/lib/mail/header.rb +2 -1
- data/lib/mail/message.rb +24 -3
- data/lib/mail/network.rb +1 -0
- data/lib/mail/network/delivery_methods/smtp.rb +4 -3
- data/lib/mail/network/delivery_methods/smtp_connection.rb +74 -0
- data/lib/mail/part.rb +1 -1
- data/lib/mail/parts_list.rb +16 -8
- data/lib/mail/version_specific/ruby_1_9.rb +9 -7
- metadata +13 -5
data/CHANGELOG.rdoc
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
== Sat Apr 16 12:57:27 UTC 2011 Mikel Lindsaar <mikel@rubyx.com>
|
2
|
+
|
3
|
+
* Added support for open SMTP connections and returning the Mail server's response - https://github.com/spiegela
|
4
|
+
* RE: not appended to subject when replying to a reply - https://github.com/prateekdayal
|
5
|
+
* Support not ascii compatible charset mail send - https://github.com/yalab
|
6
|
+
* Fix for issue 208 "mail.body after mail.add_file truncates message body" - https://github.com/glongman
|
7
|
+
* Handle bad subject encoding (or ":invalid => :replace" is ineffective for utf-8 to utf-8 encoding) - https://github.com/choonkeat
|
8
|
+
* Handle blank Received header field - https://github.com/bcantin
|
9
|
+
* Handle part with missing content type - https://github.com/bcantin
|
10
|
+
* Handle a "<>" Return field - https://github.com/bcantin
|
11
|
+
* Performance improvements for 1.9 - https://github.com/nobu
|
12
|
+
* Fix heavy CPU issues when messages are missing a space - https://github.com/scsmith
|
13
|
+
* Tighten up allowed encodings - https://github.com/scsmith
|
14
|
+
* Added to_yaml & from_yaml (as well as to_hash & from_hash) - https://github.com/srushti
|
15
|
+
* Fix up some comments - https://github.com/takahashim
|
16
|
+
|
1
17
|
== Wed 26 Jan 2011 02:23:09 UTC Mikel Lindsaar <mikel@rubyx.com>
|
2
18
|
|
3
19
|
* Update addresses passed into sendmail to escape them (Andy Lindeman)
|
data/lib/VERSION
CHANGED
data/lib/mail/body.rb
CHANGED
@@ -162,7 +162,12 @@ module Mail
|
|
162
162
|
else
|
163
163
|
# Decode then encode to normalize and allow transforming
|
164
164
|
# from base64 to Q-P and vice versa
|
165
|
-
|
165
|
+
decoded = dec.decode(raw_source)
|
166
|
+
if defined?(Encoding) && charset && charset != "US-ASCII"
|
167
|
+
decoded.encode!(charset)
|
168
|
+
decoded.force_encoding('BINARY') unless Encoding.find(charset).ascii_compatible?
|
169
|
+
end
|
170
|
+
enc.encode(decoded)
|
166
171
|
end
|
167
172
|
end
|
168
173
|
end
|
data/lib/mail/configuration.rb
CHANGED
data/lib/mail/encodings.rb
CHANGED
@@ -6,12 +6,12 @@ module Mail
|
|
6
6
|
end
|
7
7
|
|
8
8
|
module Encodings
|
9
|
-
|
9
|
+
|
10
10
|
include Mail::Patterns
|
11
11
|
extend Mail::Utilities
|
12
12
|
|
13
13
|
@transfer_encodings = {}
|
14
|
-
|
14
|
+
|
15
15
|
# Register transfer encoding
|
16
16
|
#
|
17
17
|
# Example
|
@@ -20,23 +20,23 @@ module Mail
|
|
20
20
|
def Encodings.register(name, cls)
|
21
21
|
@transfer_encodings[get_name(name)] = cls
|
22
22
|
end
|
23
|
-
|
23
|
+
|
24
24
|
# Is the encoding we want defined?
|
25
|
-
#
|
25
|
+
#
|
26
26
|
# Example:
|
27
|
-
#
|
27
|
+
#
|
28
28
|
# Encodings.defined?(:base64) #=> true
|
29
29
|
def Encodings.defined?( str )
|
30
30
|
@transfer_encodings.include? get_name(str)
|
31
31
|
end
|
32
|
-
|
32
|
+
|
33
33
|
# Gets a defined encoding type, QuotedPrintable or Base64 for now.
|
34
|
-
#
|
35
|
-
# Each encoding needs to be defined as a Mail::Encodings::ClassName for
|
34
|
+
#
|
35
|
+
# Each encoding needs to be defined as a Mail::Encodings::ClassName for
|
36
36
|
# this to work, allows us to add other encodings in the future.
|
37
|
-
#
|
37
|
+
#
|
38
38
|
# Example:
|
39
|
-
#
|
39
|
+
#
|
40
40
|
# Encodings.get_encoding(:base64) #=> Mail::Encodings::Base64
|
41
41
|
def Encodings.get_encoding( str )
|
42
42
|
@transfer_encodings[get_name(str)]
|
@@ -52,16 +52,16 @@ module Mail
|
|
52
52
|
|
53
53
|
# Encodes a parameter value using URI Escaping, note the language field 'en' can
|
54
54
|
# be set using Mail::Configuration, like so:
|
55
|
-
#
|
55
|
+
#
|
56
56
|
# Mail.defaults.do
|
57
57
|
# param_encode_language 'jp'
|
58
58
|
# end
|
59
59
|
#
|
60
|
-
# The character set used for encoding will either be the value of $KCODE for
|
60
|
+
# The character set used for encoding will either be the value of $KCODE for
|
61
61
|
# Ruby < 1.9 or the encoding on the string passed in.
|
62
|
-
#
|
62
|
+
#
|
63
63
|
# Example:
|
64
|
-
#
|
64
|
+
#
|
65
65
|
# Mail::Encodings.param_encode("This is fun") #=> "us-ascii'en'This%20is%20fun"
|
66
66
|
def Encodings.param_encode(str)
|
67
67
|
case
|
@@ -75,9 +75,9 @@ module Mail
|
|
75
75
|
end
|
76
76
|
|
77
77
|
# Decodes a parameter value using URI Escaping.
|
78
|
-
#
|
78
|
+
#
|
79
79
|
# Example:
|
80
|
-
#
|
80
|
+
#
|
81
81
|
# Mail::Encodings.param_decode("This%20is%20fun", 'us-ascii') #=> "This is fun"
|
82
82
|
#
|
83
83
|
# str = Mail::Encodings.param_decode("This%20is%20fun", 'iso-8559-1')
|
@@ -86,14 +86,14 @@ module Mail
|
|
86
86
|
def Encodings.param_decode(str, encoding)
|
87
87
|
RubyVer.param_decode(str, encoding)
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
# Decodes or encodes a string as needed for either Base64 or QP encoding types in
|
91
91
|
# the =?<encoding>?[QB]?<string>?=" format.
|
92
|
-
#
|
92
|
+
#
|
93
93
|
# The output type needs to be :decode to decode the input string or :encode to
|
94
94
|
# encode the input string. The character set used for encoding will either be
|
95
95
|
# the value of $KCODE for Ruby < 1.9 or the encoding on the string passed in.
|
96
|
-
#
|
96
|
+
#
|
97
97
|
# On encoding, will only send out Base64 encoded strings.
|
98
98
|
def Encodings.decode_encode(str, output_type)
|
99
99
|
case
|
@@ -110,12 +110,12 @@ module Mail
|
|
110
110
|
|
111
111
|
# Decodes a given string as Base64 or Quoted Printable, depending on what
|
112
112
|
# type it is.
|
113
|
-
#
|
113
|
+
#
|
114
114
|
# String has to be of the format =?<encoding>?[QB]?<string>?=
|
115
115
|
def Encodings.value_decode(str)
|
116
116
|
# Optimization: If there's no encoded-words in the string, just return it
|
117
117
|
return str unless str.index("=?")
|
118
|
-
|
118
|
+
|
119
119
|
str = str.gsub(/\?=(\s*)=\?/, '?==?') # Remove whitespaces between 'encoded-word's
|
120
120
|
|
121
121
|
# Split on white-space boundaries with capture, so we capture the white-space as well
|
@@ -125,18 +125,18 @@ module Mail
|
|
125
125
|
else
|
126
126
|
# Join QP encoded-words that are adjacent to avoid decoding partial chars
|
127
127
|
text.gsub!(/\?\=\=\?.+?\?[Qq]\?/m, '') if text =~ /\?==\?/
|
128
|
-
|
128
|
+
|
129
129
|
# Separate encoded-words with a space, so we can treat them one by one
|
130
130
|
text.gsub!(/\?\=\=\?/, '?= =?')
|
131
131
|
text.split(/ /).map do |word|
|
132
132
|
word.to_str.
|
133
|
-
gsub(/=\?.+\?[Bb]\?.+\?=/m) {|substr| b_value_decode(substr)}.
|
134
|
-
gsub(/=\?.+\?[Qq]\?.+\?=/m) {|substr| q_value_decode(substr)}
|
133
|
+
gsub( /=\?.+\?[Bb]\?.+\?=/m ) { |substr| b_value_decode(substr) }.
|
134
|
+
gsub( /=\?.+\?[Qq]\?.+\?=/m ) { |substr| q_value_decode(substr) }
|
135
135
|
end
|
136
136
|
end
|
137
137
|
end.join("")
|
138
138
|
end
|
139
|
-
|
139
|
+
|
140
140
|
# Takes an encoded string of the format =?<encoding>?[QB]?<string>?=
|
141
141
|
def Encodings.unquote_and_convert_to(str, to_encoding)
|
142
142
|
original_encoding, string = split_encoding_from_string( str )
|
@@ -166,7 +166,7 @@ module Mail
|
|
166
166
|
output
|
167
167
|
end
|
168
168
|
end
|
169
|
-
|
169
|
+
|
170
170
|
def Encodings.address_encode(address, charset = 'utf-8')
|
171
171
|
if address.is_a?(Array)
|
172
172
|
# loop back through for each element
|
@@ -196,13 +196,13 @@ module Mail
|
|
196
196
|
end
|
197
197
|
end.join(' ')
|
198
198
|
end
|
199
|
-
|
199
|
+
|
200
200
|
# Encode a string with Base64 Encoding and returns it ready to be inserted
|
201
201
|
# as a value for a field, that is, in the =?<charset>?B?<string>?= format
|
202
202
|
#
|
203
203
|
# Example:
|
204
|
-
#
|
205
|
-
# Encodings.b_value_encode('This is あ string', 'UTF-8')
|
204
|
+
#
|
205
|
+
# Encodings.b_value_encode('This is あ string', 'UTF-8')
|
206
206
|
# #=> "=?UTF-8?B?VGhpcyBpcyDjgYIgc3RyaW5n?="
|
207
207
|
def Encodings.b_value_encode(str, encoding = nil)
|
208
208
|
return str if str.to_s.ascii_only?
|
@@ -211,13 +211,13 @@ module Mail
|
|
211
211
|
"=?#{encoding}?B?#{str.chomp}?="
|
212
212
|
end.join(" ")
|
213
213
|
end
|
214
|
-
|
214
|
+
|
215
215
|
# Encode a string with Quoted-Printable Encoding and returns it ready to be inserted
|
216
216
|
# as a value for a field, that is, in the =?<charset>?Q?<string>?= format
|
217
217
|
#
|
218
218
|
# Example:
|
219
|
-
#
|
220
|
-
# Encodings.q_value_encode('This is あ string', 'UTF-8')
|
219
|
+
#
|
220
|
+
# Encodings.q_value_encode('This is あ string', 'UTF-8')
|
221
221
|
# #=> "=?UTF-8?Q?This_is_=E3=81=82_string?="
|
222
222
|
def Encodings.q_value_encode(str, encoding = nil)
|
223
223
|
return str if str.to_s.ascii_only?
|
@@ -227,29 +227,29 @@ module Mail
|
|
227
227
|
"=?#{encoding}?Q?#{str.chomp.gsub(/ /, '_')}?="
|
228
228
|
end.join(" ")
|
229
229
|
end
|
230
|
-
|
230
|
+
|
231
231
|
private
|
232
|
-
|
232
|
+
|
233
233
|
# Decodes a Base64 string from the "=?UTF-8?B?VGhpcyBpcyDjgYIgc3RyaW5n?=" format
|
234
|
-
#
|
234
|
+
#
|
235
235
|
# Example:
|
236
|
-
#
|
237
|
-
# Encodings.
|
236
|
+
#
|
237
|
+
# Encodings.b_value_decode("=?UTF-8?B?VGhpcyBpcyDjgYIgc3RyaW5n?=")
|
238
238
|
# #=> 'This is あ string'
|
239
239
|
def Encodings.b_value_decode(str)
|
240
240
|
RubyVer.b_value_decode(str)
|
241
241
|
end
|
242
|
-
|
242
|
+
|
243
243
|
# Decodes a Quoted-Printable string from the "=?UTF-8?Q?This_is_=E3=81=82_string?=" format
|
244
|
-
#
|
244
|
+
#
|
245
245
|
# Example:
|
246
|
-
#
|
247
|
-
# Encodings.
|
246
|
+
#
|
247
|
+
# Encodings.q_value_decode("=?UTF-8?Q?This_is_=E3=81=82_string?=")
|
248
248
|
# #=> 'This is あ string'
|
249
249
|
def Encodings.q_value_decode(str)
|
250
250
|
RubyVer.q_value_decode(str).gsub(/_/, ' ')
|
251
251
|
end
|
252
|
-
|
252
|
+
|
253
253
|
def Encodings.split_encoding_from_string( str )
|
254
254
|
match = str.match(/\=\?([^?]+)?\?[QB]\?(.+)?\?\=/mi)
|
255
255
|
if match
|
@@ -258,7 +258,7 @@ module Mail
|
|
258
258
|
nil
|
259
259
|
end
|
260
260
|
end
|
261
|
-
|
261
|
+
|
262
262
|
def Encodings.find_encoding(str)
|
263
263
|
RUBY_VERSION >= '1.9' ? str.encoding : $KCODE
|
264
264
|
end
|
@@ -52,15 +52,23 @@ module Mail
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def formatted_date
|
55
|
-
|
55
|
+
date_time.strftime("%a, %d %b %Y %H:%M:%S ") + date_time.zone.delete(':')
|
56
56
|
end
|
57
57
|
|
58
58
|
def encoded
|
59
|
-
|
59
|
+
if value.blank?
|
60
|
+
"#{CAPITALIZED_FIELD}: \r\n"
|
61
|
+
else
|
62
|
+
"#{CAPITALIZED_FIELD}: #{info}; #{formatted_date}\r\n"
|
63
|
+
end
|
60
64
|
end
|
61
65
|
|
62
66
|
def decoded
|
63
|
-
|
67
|
+
if value.blank?
|
68
|
+
""
|
69
|
+
else
|
70
|
+
"#{info}; #{formatted_date}"
|
71
|
+
end
|
64
72
|
end
|
65
73
|
|
66
74
|
end
|
data/lib/mail/header.rb
CHANGED
@@ -73,7 +73,8 @@ module Mail
|
|
73
73
|
# h.fields = ['From: mikel@me.com', 'To: bob@you.com']
|
74
74
|
def fields=(unfolded_fields)
|
75
75
|
@fields = Mail::FieldList.new
|
76
|
-
unfolded_fields.
|
76
|
+
warn "Warning: more than 1000 header fields only using the first 1000" if unfolded_fields.length > 1000
|
77
|
+
unfolded_fields[0..1000].each do |field|
|
77
78
|
|
78
79
|
field = Field.new(field, nil, charset)
|
79
80
|
field.errors.each { |error| self.errors << error }
|
data/lib/mail/message.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
|
+
require "yaml"
|
3
|
+
|
2
4
|
module Mail
|
3
5
|
# The Message class provides a single point of access to all things to do with an
|
4
6
|
# email message.
|
@@ -240,9 +242,9 @@ module Mail
|
|
240
242
|
#
|
241
243
|
# Returns self
|
242
244
|
def deliver!
|
243
|
-
delivery_method.deliver!(self)
|
245
|
+
response = delivery_method.deliver!(self)
|
244
246
|
inform_observers
|
245
|
-
self
|
247
|
+
delivery_method.settings[:return_response] ? response : self
|
246
248
|
end
|
247
249
|
|
248
250
|
def delivery_method(method = nil, settings = {})
|
@@ -268,7 +270,7 @@ module Mail
|
|
268
270
|
reply.references ||= bracketed_message_id
|
269
271
|
end
|
270
272
|
if subject
|
271
|
-
reply.subject = "RE: #{subject}"
|
273
|
+
reply.subject = subject =~ /^Re:/i ? subject : "RE: #{subject}"
|
272
274
|
end
|
273
275
|
if reply_to || from
|
274
276
|
reply.to = self[reply_to ? :reply_to : :from].to_s
|
@@ -1708,6 +1710,25 @@ module Mail
|
|
1708
1710
|
buffer
|
1709
1711
|
end
|
1710
1712
|
|
1713
|
+
def to_yaml
|
1714
|
+
ready_to_send!
|
1715
|
+
hash = {}
|
1716
|
+
header.fields.each do |field|
|
1717
|
+
hash[field.name] = field.value
|
1718
|
+
end
|
1719
|
+
hash['subject'] = subject
|
1720
|
+
hash['body'] = body.encoded(content_transfer_encoding)
|
1721
|
+
hash.to_yaml
|
1722
|
+
end
|
1723
|
+
|
1724
|
+
def self.from_yaml(str)
|
1725
|
+
from_hash(YAML::load(str))
|
1726
|
+
end
|
1727
|
+
|
1728
|
+
def self.from_hash(hash)
|
1729
|
+
Mail::Message.new(hash)
|
1730
|
+
end
|
1731
|
+
|
1711
1732
|
def to_s
|
1712
1733
|
encoded
|
1713
1734
|
end
|
data/lib/mail/network.rb
CHANGED
@@ -4,6 +4,7 @@ module Mail
|
|
4
4
|
autoload :SMTP, 'mail/network/delivery_methods/smtp'
|
5
5
|
autoload :FileDelivery, 'mail/network/delivery_methods/file_delivery'
|
6
6
|
autoload :Sendmail, 'mail/network/delivery_methods/sendmail'
|
7
|
+
autoload :SMTPConnection, 'mail/network/delivery_methods/smtp_connection'
|
7
8
|
autoload :TestMailer, 'mail/network/delivery_methods/test_mailer'
|
8
9
|
|
9
10
|
autoload :POP3, 'mail/network/retriever_methods/pop3'
|
@@ -124,11 +124,12 @@ module Mail
|
|
124
124
|
end
|
125
125
|
end
|
126
126
|
|
127
|
+
response = nil
|
127
128
|
smtp.start(settings[:domain], settings[:user_name], settings[:password], settings[:authentication]) do |smtp|
|
128
|
-
smtp.sendmail(message, envelope_from, destinations)
|
129
|
+
response = smtp.sendmail(message, envelope_from, destinations)
|
129
130
|
end
|
130
|
-
|
131
|
-
self
|
131
|
+
|
132
|
+
return settings[:return_response] ? response : self
|
132
133
|
end
|
133
134
|
|
134
135
|
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Mail
|
2
|
+
# == Sending Email with SMTP
|
3
|
+
#
|
4
|
+
# Mail allows you to send emails using an open SMTP connection. This is done by
|
5
|
+
# passing a created Net::SMTP object. This way we can get better performance to
|
6
|
+
# our local mail server by reducing the number of connections at any one time.
|
7
|
+
#
|
8
|
+
# === Sending via SMTP server on Localhost
|
9
|
+
#
|
10
|
+
# To send mail open a connection with Net::Smtp using any options you like
|
11
|
+
# === Delivering the email
|
12
|
+
#
|
13
|
+
# Once you have the settings right, sending the email is done by:
|
14
|
+
#
|
15
|
+
# smtp_conn = Net::SMTP.start(settings[:address], settings[:port])
|
16
|
+
# Mail.defaults do
|
17
|
+
# delivery_method :smtp_connection, { :connection => smtp_conn }
|
18
|
+
# end
|
19
|
+
#
|
20
|
+
# Mail.deliver do
|
21
|
+
# to 'mikel@test.lindsaar.net'
|
22
|
+
# from 'ada@test.lindsaar.net'
|
23
|
+
# subject 'testing sendmail'
|
24
|
+
# body 'testing sendmail'
|
25
|
+
# end
|
26
|
+
#
|
27
|
+
# Or by calling deliver on a Mail message
|
28
|
+
#
|
29
|
+
# mail = Mail.new do
|
30
|
+
# to 'mikel@test.lindsaar.net'
|
31
|
+
# from 'ada@test.lindsaar.net'
|
32
|
+
# subject 'testing sendmail'
|
33
|
+
# body 'testing sendmail'
|
34
|
+
# end
|
35
|
+
#
|
36
|
+
# mail.deliver!
|
37
|
+
class SMTPConnection
|
38
|
+
|
39
|
+
def initialize(values)
|
40
|
+
raise ArgumentError.new('A Net::SMTP object is required for this delivery method') if values[:connection].nil?
|
41
|
+
self.smtp = values[:connection]
|
42
|
+
self.settings = values
|
43
|
+
end
|
44
|
+
|
45
|
+
attr_accessor :smtp
|
46
|
+
attr_accessor :settings
|
47
|
+
|
48
|
+
# Send the message via SMTP.
|
49
|
+
# The from and to attributes are optional. If not set, they are retrieve from the Message.
|
50
|
+
def deliver!(mail)
|
51
|
+
|
52
|
+
# Set the envelope from to be either the return-path, the sender or the first from address
|
53
|
+
envelope_from = mail.return_path || mail.sender || mail.from_addrs.first
|
54
|
+
if envelope_from.blank?
|
55
|
+
raise ArgumentError.new('A sender (Return-Path, Sender or From) required to send a message')
|
56
|
+
end
|
57
|
+
|
58
|
+
destinations ||= mail.destinations if mail.respond_to?(:destinations) && mail.destinations
|
59
|
+
if destinations.blank?
|
60
|
+
raise ArgumentError.new('At least one recipient (To, Cc or Bcc) is required to send a message')
|
61
|
+
end
|
62
|
+
|
63
|
+
message ||= mail.encoded if mail.respond_to?(:encoded)
|
64
|
+
if message.blank?
|
65
|
+
raise ArgumentError.new('A encoded content is required to send a message')
|
66
|
+
end
|
67
|
+
|
68
|
+
response = smtp.sendmail(message, envelope_from, destinations)
|
69
|
+
|
70
|
+
settings[:return_response] ? response : self
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
end
|
data/lib/mail/part.rb
CHANGED
data/lib/mail/parts_list.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Mail
|
2
2
|
class PartsList < Array
|
3
|
-
|
3
|
+
|
4
4
|
def attachments
|
5
5
|
Mail::AttachmentsList.new(self)
|
6
6
|
end
|
@@ -14,30 +14,38 @@ module Mail
|
|
14
14
|
to_a
|
15
15
|
end
|
16
16
|
end
|
17
|
-
|
17
|
+
|
18
18
|
undef :map
|
19
19
|
alias_method :map, :collect
|
20
20
|
|
21
21
|
def map!
|
22
22
|
raise NoMethodError, "#map! is not defined, please call #collect and create a new PartsList"
|
23
23
|
end
|
24
|
-
|
24
|
+
|
25
25
|
def collect!
|
26
26
|
raise NoMethodError, "#collect! is not defined, please call #collect and create a new PartsList"
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def sort!(order)
|
30
30
|
sorted = self.sort do |a, b|
|
31
31
|
# OK, 10000 is arbitrary... if anyone actually wants to explicitly sort 10000 parts of a
|
32
32
|
# single email message... please show me a use case and I'll put more work into this method,
|
33
33
|
# in the meantime, it works :)
|
34
|
-
|
35
|
-
b_order = order.index(b[:content_type].string.downcase) || 10000
|
36
|
-
a_order <=> b_order
|
34
|
+
get_order_value(a, order) <=> get_order_value(b, order)
|
37
35
|
end
|
38
36
|
self.clear
|
39
37
|
sorted.each { |p| self << p }
|
40
38
|
end
|
41
|
-
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def get_order_value(part, order)
|
43
|
+
if part.respond_to?(:content_type)
|
44
|
+
order.index(part[:content_type].string.downcase) || 10000
|
45
|
+
else
|
46
|
+
10000
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
42
50
|
end
|
43
51
|
end
|
@@ -27,7 +27,7 @@ module Mail
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def Ruby19.decode_base64(str)
|
30
|
-
str.unpack( 'm' ).first
|
30
|
+
str.unpack( 'm' ).first
|
31
31
|
end
|
32
32
|
|
33
33
|
def Ruby19.encode_base64(str)
|
@@ -35,11 +35,11 @@ module Mail
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def Ruby19.has_constant?(klass, string)
|
38
|
-
klass.
|
38
|
+
klass.const_defined?( string, false )
|
39
39
|
end
|
40
40
|
|
41
41
|
def Ruby19.get_constant(klass, string)
|
42
|
-
klass.const_get( string
|
42
|
+
klass.const_get( string )
|
43
43
|
end
|
44
44
|
|
45
45
|
def Ruby19.b_value_encode(str, encoding = nil)
|
@@ -54,7 +54,8 @@ module Mail
|
|
54
54
|
str = Ruby19.decode_base64(match[2])
|
55
55
|
str.force_encoding(fix_encoding(encoding))
|
56
56
|
end
|
57
|
-
str.encode("utf-8", :invalid => :replace, :replace => "")
|
57
|
+
decoded = str.encode("utf-8", :invalid => :replace, :replace => "")
|
58
|
+
decoded.valid_encoding? ? decoded : decoded.encode("utf-16le", :invalid => :replace, :replace => "").encode("utf-8")
|
58
59
|
end
|
59
60
|
|
60
61
|
def Ruby19.q_value_encode(str, encoding = nil)
|
@@ -69,7 +70,8 @@ module Mail
|
|
69
70
|
str = Encodings::QuotedPrintable.decode(match[2])
|
70
71
|
str.force_encoding(fix_encoding(encoding))
|
71
72
|
end
|
72
|
-
str.encode("utf-8", :invalid => :replace, :replace => "")
|
73
|
+
decoded = str.encode("utf-8", :invalid => :replace, :replace => "")
|
74
|
+
decoded.valid_encoding? ? decoded : decoded.encode("utf-16le", :invalid => :replace, :replace => "").encode("utf-8")
|
73
75
|
end
|
74
76
|
|
75
77
|
def Ruby19.param_decode(str, encoding)
|
@@ -94,8 +96,8 @@ module Mail
|
|
94
96
|
when /iso-?(\d{4})-?(\w{1,2})/i then return "ISO-#{$1}-#{$2}"
|
95
97
|
# "ISO-2022-JP-KDDI" and alike
|
96
98
|
when /iso-?(\d{4})-?(\w{1,2})-?(\w*)/i then return "ISO-#{$1}-#{$2}-#{$3}"
|
97
|
-
#
|
98
|
-
when /utf-?(
|
99
|
+
# UTF-8, UTF-32BE and alike
|
100
|
+
when /utf-?(\d{1,2})?(\w{1,2})/i then return "UTF-#{$1}#{$2}"
|
99
101
|
# Windows-1252 and alike
|
100
102
|
when /Windows-?(.*)/i then return "Windows-#{$1}"
|
101
103
|
#more aliases to be added if needed
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mail
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
hash: 39
|
5
|
+
prerelease:
|
5
6
|
segments:
|
6
7
|
- 2
|
7
8
|
- 2
|
8
|
-
-
|
9
|
-
version: 2.2.
|
9
|
+
- 16
|
10
|
+
version: 2.2.16
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Mikel Lindsaar
|
@@ -14,7 +15,7 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2011-
|
18
|
+
date: 2011-04-16 00:00:00 +10:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
@@ -25,6 +26,7 @@ dependencies:
|
|
25
26
|
requirements:
|
26
27
|
- - ">="
|
27
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 15
|
28
30
|
segments:
|
29
31
|
- 2
|
30
32
|
- 3
|
@@ -40,6 +42,7 @@ dependencies:
|
|
40
42
|
requirements:
|
41
43
|
- - ~>
|
42
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 47
|
43
46
|
segments:
|
44
47
|
- 1
|
45
48
|
- 16
|
@@ -54,6 +57,7 @@ dependencies:
|
|
54
57
|
requirements:
|
55
58
|
- - ~>
|
56
59
|
- !ruby/object:Gem::Version
|
60
|
+
hash: 23
|
57
61
|
segments:
|
58
62
|
- 1
|
59
63
|
- 4
|
@@ -69,6 +73,7 @@ dependencies:
|
|
69
73
|
requirements:
|
70
74
|
- - ">="
|
71
75
|
- !ruby/object:Gem::Version
|
76
|
+
hash: 15
|
72
77
|
segments:
|
73
78
|
- 0
|
74
79
|
- 4
|
@@ -165,6 +170,7 @@ files:
|
|
165
170
|
- lib/mail/network/delivery_methods/file_delivery.rb
|
166
171
|
- lib/mail/network/delivery_methods/sendmail.rb
|
167
172
|
- lib/mail/network/delivery_methods/smtp.rb
|
173
|
+
- lib/mail/network/delivery_methods/smtp_connection.rb
|
168
174
|
- lib/mail/network/delivery_methods/test_mailer.rb
|
169
175
|
- lib/mail/network/retriever_methods/base.rb
|
170
176
|
- lib/mail/network/retriever_methods/imap.rb
|
@@ -225,6 +231,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
225
231
|
requirements:
|
226
232
|
- - ">="
|
227
233
|
- !ruby/object:Gem::Version
|
234
|
+
hash: 3
|
228
235
|
segments:
|
229
236
|
- 0
|
230
237
|
version: "0"
|
@@ -233,13 +240,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
233
240
|
requirements:
|
234
241
|
- - ">="
|
235
242
|
- !ruby/object:Gem::Version
|
243
|
+
hash: 3
|
236
244
|
segments:
|
237
245
|
- 0
|
238
246
|
version: "0"
|
239
247
|
requirements: []
|
240
248
|
|
241
249
|
rubyforge_project:
|
242
|
-
rubygems_version: 1.
|
250
|
+
rubygems_version: 1.6.1
|
243
251
|
signing_key:
|
244
252
|
specification_version: 3
|
245
253
|
summary: Mail provides a nice Ruby DSL for making, sending and reading emails.
|