While technical invalid, a large number of valid senders send email with mismatched parenthesis in the ReceivedHeader.
Throwing an error and aborting parsing is not a good solution.
A better solution is to escape all parenthesis in the received header when they are mismatched.
This allows the the regular parser to continue and pass all tests.
module TextUtils
def quote_parentheses
if @body.count("(") != @body.count(")")
@body.gsub!(/\(/, "\\(")
@body.gsub!(/\)/, "\\)")
end
end
end
class ReceivedHeader < StructuredHeader
private
def init
quote_parentheses
@from = @by = @via = @with = @id = @_for = nil
@with = []
@date = nil
end
end
|