Skip to content

Commit 24884b8

Browse files
committed
stop stripping fields multiple times
1 parent 09407e1 commit 24884b8

File tree

64 files changed

+460
-470
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+460
-470
lines changed

lib/mail/elements/content_transfer_encoding_element.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ class ContentTransferEncodingElement
55
include Mail::Utilities
66

77
def initialize(string)
8-
content_transfer_encoding = Mail::Parsers::ContentTransferEncodingParser.new.parse(string)
8+
content_transfer_encoding = Mail::Parsers::ContentTransferEncodingParser.new.parse(string.to_s)
99
@encoding = content_transfer_encoding.encoding
1010
end
1111

lib/mail/envelope.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
# encoding: utf-8
2-
#
2+
#
33
# = Mail Envelope
4-
#
4+
#
55
# The Envelope class provides a field for the first line in an
66
# mbox file, that looks like "From mikel@test.lindsaar.net DATETIME"
7-
#
7+
#
88
# This envelope class reads that line, and turns it into an
99
# Envelope.from and Envelope.date for your use.
1010
module Mail
1111
class Envelope < StructuredField
12-
12+
1313
def initialize(*args)
14-
super(FIELD_NAME, strip_field(FIELD_NAME, args.last))
14+
super(FIELD_NAME, args.last.to_s)
1515
end
16-
16+
1717
def element
1818
@element ||= Mail::EnvelopeFromElement.new(value)
1919
end
20-
20+
2121
def date
2222
::DateTime.parse("#{element.date_time}")
2323
end
2424

2525
def from
2626
element.address
2727
end
28-
28+
2929
end
3030
end

lib/mail/fields/bcc_field.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
11
# encoding: utf-8
2-
#
2+
#
33
# = Blind Carbon Copy Field
4-
#
4+
#
55
# The Bcc field inherits from StructuredField and handles the Bcc: header
66
# field in the email.
7-
#
7+
#
88
# Sending bcc to a mail message will instantiate a Mail::Field object that
99
# has a BccField as its field type. This includes all Mail::CommonAddress
1010
# module instance metods.
11-
#
11+
#
1212
# Only one Bcc field can appear in a header, though it can have multiple
1313
# addresses and groups of addresses.
14-
#
14+
#
1515
# == Examples:
16-
#
16+
#
1717
# mail = Mail.new
1818
# mail.bcc = 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
1919
# mail.bcc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
2020
# mail[:bcc] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::BccField:0x180e1c4
2121
# mail['bcc'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::BccField:0x180e1c4
2222
# mail['Bcc'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::BccField:0x180e1c4
23-
#
23+
#
2424
# mail[:bcc].encoded #=> '' # Bcc field does not get output into an email
2525
# mail[:bcc].decoded #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
2626
# mail[:bcc].addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
2727
# mail[:bcc].formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
28-
#
28+
#
2929
require 'mail/fields/common/common_address'
3030

3131
module Mail
3232
class BccField < StructuredField
33-
33+
3434
include Mail::CommonAddress
35-
35+
3636
FIELD_NAME = 'bcc'
3737
CAPITALIZED_FIELD = 'Bcc'
38-
38+
3939
def initialize(value = '', charset = 'utf-8')
4040
@charset = charset
41-
super(CAPITALIZED_FIELD, strip_field(FIELD_NAME, value), charset)
41+
super(CAPITALIZED_FIELD, value || "", charset)
4242
self
4343
end
44-
44+
4545
def include_in_headers=(include_in_headers)
4646
@include_in_headers = include_in_headers
4747
end
@@ -58,10 +58,10 @@ def encoded
5858
''
5959
end
6060
end
61-
61+
6262
def decoded
6363
do_decode
6464
end
65-
65+
6666
end
6767
end

lib/mail/fields/cc_field.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,54 @@
11
# encoding: utf-8
2-
#
2+
#
33
# = Carbon Copy Field
4-
#
4+
#
55
# The Cc field inherits from StructuredField and handles the Cc: header
66
# field in the email.
7-
#
7+
#
88
# Sending cc to a mail message will instantiate a Mail::Field object that
99
# has a CcField as its field type. This includes all Mail::CommonAddress
1010
# module instance metods.
11-
#
11+
#
1212
# Only one Cc field can appear in a header, though it can have multiple
1313
# addresses and groups of addresses.
14-
#
14+
#
1515
# == Examples:
16-
#
16+
#
1717
# mail = Mail.new
1818
# mail.cc = 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
1919
# mail.cc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
2020
# mail[:cc] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CcField:0x180e1c4
2121
# mail['cc'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CcField:0x180e1c4
2222
# mail['Cc'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CcField:0x180e1c4
23-
#
23+
#
2424
# mail[:cc].encoded #=> 'Cc: Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net\r\n'
2525
# mail[:cc].decoded #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net'
2626
# mail[:cc].addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net']
2727
# mail[:cc].formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net']
28-
#
28+
#
2929
require 'mail/fields/common/common_address'
3030

3131
module Mail
3232
class CcField < StructuredField
33-
33+
3434
include Mail::CommonAddress
35-
35+
3636
FIELD_NAME = 'cc'
3737
CAPITALIZED_FIELD = 'Cc'
38-
38+
3939
def initialize(value = nil, charset = 'utf-8')
4040
self.charset = charset
41-
super(CAPITALIZED_FIELD, strip_field(FIELD_NAME, value), charset)
41+
super(CAPITALIZED_FIELD, value || "", charset)
4242
self
4343
end
44-
44+
4545
def encoded
4646
do_encode(CAPITALIZED_FIELD)
4747
end
48-
48+
4949
def decoded
5050
do_decode
5151
end
52-
52+
5353
end
5454
end

lib/mail/fields/comments_field.rb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,41 @@
11
# encoding: utf-8
2-
#
2+
#
33
# = Comments Field
4-
#
4+
#
55
# The Comments field inherits from UnstructuredField and handles the Comments:
66
# header field in the email.
7-
#
7+
#
88
# Sending comments to a mail message will instantiate a Mail::Field object that
99
# has a CommentsField as its field type.
10-
#
10+
#
1111
# An email header can have as many comments fields as it wants. There is no upper
1212
# limit, the comments field is also optional (that is, no comment is needed)
13-
#
13+
#
1414
# == Examples:
15-
#
15+
#
1616
# mail = Mail.new
1717
# mail.comments = 'This is a comment'
1818
# mail.comments #=> 'This is a comment'
1919
# mail[:comments] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CommentsField:0x180e1c4
2020
# mail['comments'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CommentsField:0x180e1c4
2121
# mail['comments'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CommentsField:0x180e1c4
22-
#
22+
#
2323
# mail.comments = "This is another comment"
24-
# mail[:comments].map { |c| c.to_s }
24+
# mail[:comments].map { |c| c.to_s }
2525
# #=> ['This is a comment', "This is another comment"]
2626
#
2727
module Mail
2828
class CommentsField < UnstructuredField
29-
29+
3030
FIELD_NAME = 'comments'
3131
CAPITALIZED_FIELD = 'Comments'
32-
32+
3333
def initialize(value = nil, charset = 'utf-8')
3434
@charset = charset
35-
super(CAPITALIZED_FIELD, strip_field(FIELD_NAME, value))
35+
super(CAPITALIZED_FIELD, value || "")
3636
self.parse
3737
self
3838
end
39-
39+
4040
end
4141
end

lib/mail/fields/common/common_field.rb

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,6 @@ def responsible_for?( val )
4040

4141
private
4242

43-
def strip_field(field_name, value)
44-
if value.is_a?(Array)
45-
value
46-
else
47-
value.to_s.sub(/\A#{field_name}:\s+/i, EMPTY)
48-
end
49-
end
50-
5143
FILENAME_RE = /\b(filename|name)=([^;"\r\n]+\s[^;"\r\n]+)/
5244
def ensure_filename_quoted(value)
5345
if value.is_a?(String)
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
# encoding: utf-8
2-
#
3-
#
4-
#
2+
#
3+
#
4+
#
55
module Mail
66
class ContentDescriptionField < UnstructuredField
7-
7+
88
FIELD_NAME = 'content-description'
99
CAPITALIZED_FIELD = 'Content-Description'
10-
10+
1111
def initialize(value = nil, charset = 'utf-8')
1212
self.charset = charset
13-
super(CAPITALIZED_FIELD, strip_field(FIELD_NAME, value), charset)
13+
super(CAPITALIZED_FIELD, value || "", charset)
1414
self.parse
1515
self
1616
end
17-
17+
1818
end
1919
end

lib/mail/fields/content_disposition_field.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ContentDispositionField < StructuredField
1010
def initialize(value = nil, charset = 'utf-8')
1111
self.charset = charset
1212
ensure_filename_quoted(value)
13-
super(CAPITALIZED_FIELD, strip_field(FIELD_NAME, value), charset)
13+
super(CAPITALIZED_FIELD, value || "", charset)
1414
self.parse
1515
self
1616
end
Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,62 @@
11
# encoding: utf-8
2-
#
3-
#
4-
#
2+
#
3+
#
4+
#
55
module Mail
66
class ContentIdField < StructuredField
7-
7+
88
FIELD_NAME = 'content-id'
99
CAPITALIZED_FIELD = "Content-ID"
10-
10+
1111
def initialize(value = nil, charset = 'utf-8')
1212
self.charset = charset
1313
@uniq = 1
1414
if value.blank?
1515
value = generate_content_id
1616
else
17-
value = strip_field(FIELD_NAME, value)
17+
value = value.to_s
1818
end
19-
super(CAPITALIZED_FIELD, strip_field(FIELD_NAME, value), charset)
19+
super(CAPITALIZED_FIELD, value || "", charset)
2020
self.parse
2121
self
2222
end
23-
23+
2424
def parse(val = value)
2525
unless val.blank?
2626
@element = Mail::MessageIdsElement.new(val)
2727
end
2828
end
29-
29+
3030
def element
3131
@element ||= Mail::MessageIdsElement.new(value)
3232
end
33-
33+
3434
def name
3535
'Content-ID'
3636
end
37-
37+
3838
def content_id
3939
element.message_id
4040
end
41-
41+
4242
def to_s
4343
"<#{content_id}>"
4444
end
45-
45+
4646
# TODO: Fix this up
4747
def encoded
4848
"#{CAPITALIZED_FIELD}: #{to_s}\r\n"
4949
end
50-
50+
5151
def decoded
5252
"#{to_s}"
5353
end
54-
54+
5555
private
56-
56+
5757
def generate_content_id
5858
"<#{Mail.random_tag}@#{::Socket.gethostname}.mail>"
5959
end
60-
60+
6161
end
6262
end

0 commit comments

Comments
 (0)