-
Notifications
You must be signed in to change notification settings - Fork 941
remove duplicate field stripping #766
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,30 @@ | ||
# encoding: utf-8 | ||
# | ||
# | ||
# = Mail Envelope | ||
# | ||
# | ||
# The Envelope class provides a field for the first line in an | ||
# mbox file, that looks like "From mikel@test.lindsaar.net DATETIME" | ||
# | ||
# | ||
# This envelope class reads that line, and turns it into an | ||
# Envelope.from and Envelope.date for your use. | ||
module Mail | ||
class Envelope < StructuredField | ||
|
||
def initialize(*args) | ||
super(FIELD_NAME, strip_field(FIELD_NAME, args.last)) | ||
super(FIELD_NAME, args.last.to_s) | ||
end | ||
|
||
def element | ||
@element ||= Mail::EnvelopeFromElement.new(value) | ||
end | ||
|
||
def date | ||
::DateTime.parse("#{element.date_time}") | ||
end | ||
|
||
def from | ||
element.address | ||
end | ||
|
||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,54 @@ | ||
# encoding: utf-8 | ||
# | ||
# | ||
# = Carbon Copy Field | ||
# | ||
# | ||
# The Cc field inherits from StructuredField and handles the Cc: header | ||
# field in the email. | ||
# | ||
# | ||
# Sending cc to a mail message will instantiate a Mail::Field object that | ||
# has a CcField as its field type. This includes all Mail::CommonAddress | ||
# module instance metods. | ||
# | ||
# | ||
# Only one Cc field can appear in a header, though it can have multiple | ||
# addresses and groups of addresses. | ||
# | ||
# | ||
# == Examples: | ||
# | ||
# | ||
# mail = Mail.new | ||
# mail.cc = 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net' | ||
# mail.cc #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net'] | ||
# mail[:cc] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CcField:0x180e1c4 | ||
# mail['cc'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CcField:0x180e1c4 | ||
# mail['Cc'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CcField:0x180e1c4 | ||
# | ||
# | ||
# mail[:cc].encoded #=> 'Cc: Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net\r\n' | ||
# mail[:cc].decoded #=> 'Mikel Lindsaar <mikel@test.lindsaar.net>, ada@test.lindsaar.net' | ||
# mail[:cc].addresses #=> ['mikel@test.lindsaar.net', 'ada@test.lindsaar.net'] | ||
# mail[:cc].formatted #=> ['Mikel Lindsaar <mikel@test.lindsaar.net>', 'ada@test.lindsaar.net'] | ||
# | ||
# | ||
require 'mail/fields/common/common_address' | ||
|
||
module Mail | ||
class CcField < StructuredField | ||
|
||
include Mail::CommonAddress | ||
|
||
FIELD_NAME = 'cc' | ||
CAPITALIZED_FIELD = 'Cc' | ||
|
||
def initialize(value = nil, charset = 'utf-8') | ||
self.charset = charset | ||
super(CAPITALIZED_FIELD, strip_field(FIELD_NAME, value), charset) | ||
super(CAPITALIZED_FIELD, value || "", charset) | ||
self | ||
end | ||
|
||
def encoded | ||
do_encode(CAPITALIZED_FIELD) | ||
end | ||
|
||
def decoded | ||
do_decode | ||
end | ||
|
||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,41 @@ | ||
# encoding: utf-8 | ||
# | ||
# | ||
# = Comments Field | ||
# | ||
# | ||
# The Comments field inherits from UnstructuredField and handles the Comments: | ||
# header field in the email. | ||
# | ||
# | ||
# Sending comments to a mail message will instantiate a Mail::Field object that | ||
# has a CommentsField as its field type. | ||
# | ||
# | ||
# An email header can have as many comments fields as it wants. There is no upper | ||
# limit, the comments field is also optional (that is, no comment is needed) | ||
# | ||
# | ||
# == Examples: | ||
# | ||
# | ||
# mail = Mail.new | ||
# mail.comments = 'This is a comment' | ||
# mail.comments #=> 'This is a comment' | ||
# mail[:comments] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CommentsField:0x180e1c4 | ||
# mail['comments'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CommentsField:0x180e1c4 | ||
# mail['comments'] #=> '#<Mail::Field:0x180e5e8 @field=#<Mail::CommentsField:0x180e1c4 | ||
# | ||
# | ||
# mail.comments = "This is another comment" | ||
# mail[:comments].map { |c| c.to_s } | ||
# mail[:comments].map { |c| c.to_s } | ||
# #=> ['This is a comment', "This is another comment"] | ||
# | ||
module Mail | ||
class CommentsField < UnstructuredField | ||
|
||
FIELD_NAME = 'comments' | ||
CAPITALIZED_FIELD = 'Comments' | ||
|
||
def initialize(value = nil, charset = 'utf-8') | ||
@charset = charset | ||
super(CAPITALIZED_FIELD, strip_field(FIELD_NAME, value)) | ||
super(CAPITALIZED_FIELD, value || "") | ||
self.parse | ||
self | ||
end | ||
|
||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,19 @@ | ||
# encoding: utf-8 | ||
# | ||
# | ||
# | ||
# | ||
# | ||
# | ||
module Mail | ||
class ContentDescriptionField < UnstructuredField | ||
|
||
FIELD_NAME = 'content-description' | ||
CAPITALIZED_FIELD = 'Content-Description' | ||
|
||
def initialize(value = nil, charset = 'utf-8') | ||
self.charset = charset | ||
super(CAPITALIZED_FIELD, strip_field(FIELD_NAME, value), charset) | ||
super(CAPITALIZED_FIELD, value || "", charset) | ||
self.parse | ||
self | ||
end | ||
|
||
end | ||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,62 +1,62 @@ | ||
# encoding: utf-8 | ||
# | ||
# | ||
# | ||
# | ||
# | ||
# | ||
module Mail | ||
class ContentIdField < StructuredField | ||
|
||
FIELD_NAME = 'content-id' | ||
CAPITALIZED_FIELD = "Content-ID" | ||
|
||
def initialize(value = nil, charset = 'utf-8') | ||
self.charset = charset | ||
@uniq = 1 | ||
if value.blank? | ||
value = generate_content_id | ||
else | ||
value = strip_field(FIELD_NAME, value) | ||
value = value.to_s | ||
end | ||
super(CAPITALIZED_FIELD, strip_field(FIELD_NAME, value), charset) | ||
super(CAPITALIZED_FIELD, value || "", charset) | ||
self.parse | ||
self | ||
end | ||
|
||
def parse(val = value) | ||
unless val.blank? | ||
@element = Mail::MessageIdsElement.new(val) | ||
end | ||
end | ||
|
||
def element | ||
@element ||= Mail::MessageIdsElement.new(value) | ||
end | ||
|
||
def name | ||
'Content-ID' | ||
end | ||
|
||
def content_id | ||
element.message_id | ||
end | ||
|
||
def to_s | ||
"<#{content_id}>" | ||
end | ||
|
||
# TODO: Fix this up | ||
def encoded | ||
"#{CAPITALIZED_FIELD}: #{to_s}\r\n" | ||
end | ||
|
||
def decoded | ||
"#{to_s}" | ||
end | ||
|
||
private | ||
|
||
def generate_content_id | ||
"<#{Mail.random_tag}@#{::Socket.gethostname}.mail>" | ||
end | ||
|
||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Example (where you probably saw some failing specs, I assume) of expecting a string
value
.