lib/email_parser.rb in email_parser-0.1.0 vs lib/email_parser.rb in email_parser-0.1.1

- old
+ new

@@ -19,24 +19,25 @@ "|" \ "\\\\[#{Regexp.escape(LETTER_AND_DIGIT + QUOTE_NOT_REQUIRED_SYMBOLS + QUOTE_REQUIRED_SYMBOLS + ESCAPE_REQUIRED_SYMBOLS)}]" \ ")+", ) - attr_reader :allow_address_literal, :allow_dot_sequence_in_local, :allow_local_begin_with_dot, :allow_local_end_with_dot + attr_reader :allow_address_literal, :allow_domain_label_begin_with_number, :allow_dot_sequence_in_local, :allow_local_begin_with_dot, :allow_local_end_with_dot def self.parse(src, **options) new(**options).parse(src) end def self.valid?(src, **options) new(**options).valid?(src) end - def initialize(allow_address_literal: false, allow_dot_sequence_in_local: false, allow_local_begin_with_dot: false, allow_local_end_with_dot: false) + def initialize(allow_address_literal: false, allow_domain_label_begin_with_number: false, allow_dot_sequence_in_local: false, allow_local_begin_with_dot: false, allow_local_end_with_dot: false) @allow_address_literal = allow_address_literal raise NotImplementedError("Sorry, `allow_address_literal == true` is not supported yet") if allow_address_literal + @allow_domain_label_begin_with_number = allow_domain_label_begin_with_number @allow_dot_sequence_in_local = allow_dot_sequence_in_local @allow_local_begin_with_dot = allow_local_begin_with_dot @allow_local_end_with_dot = allow_local_end_with_dot end @@ -168,13 +169,16 @@ se end def label(s) buffer = "" - return unless push!(buffer, s.scan(/[a-zA-Z]/)) + unless allow_domain_label_begin_with_number + return unless push!(buffer, s.scan(/[a-zA-Z]/)) + end + push!(buffer, s.scan(/[a-zA-Z0-9]+/)) - push!(buffer, s.scan(/(-[a-zA-Z0-9])+/)) + push!(buffer, s.scan(/(-[a-zA-Z0-9]+)+/)) [:label, buffer] end end