-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🔀 Merge pull request #225 from nevans/parser/better-faster-cleaner-st…
…atus ⚡ Better Faster Cleaner `STATUS` parsing
- Loading branch information
Showing
4 changed files
with
314 additions
and
26 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# frozen_string_literal: true | ||
|
||
module Net | ||
class IMAP | ||
|
||
## | ||
# An IMAP {sequence | ||
# set}[https://www.rfc-editor.org/rfc/rfc9051.html#section-4.1.1], | ||
# is a set of message sequence numbers or unique identifier numbers | ||
# ("UIDs"). It contains numbers and ranges of numbers. The numbers are all | ||
# non-zero unsigned 32-bit integers and one special value, <tt>*</tt>, that | ||
# represents the largest value in the mailbox. | ||
# | ||
# *NOTE:* This SequenceSet class is currently a placeholder for unhandled | ||
# extension data. All it does now is validate. It will be expanded to a | ||
# full API in a future release. | ||
class SequenceSet | ||
|
||
def self.[](str) new(str).freeze end | ||
|
||
def initialize(input) | ||
@atom = -String.try_convert(input) | ||
validate | ||
end | ||
|
||
# Returns the IMAP string representation. In the IMAP grammar, | ||
# +sequence-set+ is a subset of +atom+ which is a subset of +astring+. | ||
attr_accessor :atom | ||
|
||
# Returns #atom. In the IMAP grammar, +atom+ is a subset of +astring+. | ||
alias astring atom | ||
|
||
# Returns the value of #atom | ||
alias to_s atom | ||
|
||
# Hash equality requires the same encoded #atom representation. | ||
# | ||
# Net::IMAP::SequenceSet["1:3"] .eql? Net::IMAP::SequenceSet["1:3"] # => true | ||
# Net::IMAP::SequenceSet["1,2,3"].eql? Net::IMAP::SequenceSet["1:3"] # => false | ||
# Net::IMAP::SequenceSet["1,3"] .eql? Net::IMAP::SequenceSet["3,1"] # => false | ||
# Net::IMAP::SequenceSet["9,1:*"].eql? Net::IMAP::SequenceSet["1:*"] # => false | ||
# | ||
def eql?(other) self.class == other.class && atom == other.atom end | ||
alias == eql? | ||
|
||
# See #eql? | ||
def hash; [self.class. atom].hash end | ||
|
||
def inspect | ||
(frozen? ? "%s[%p]" : "#<%s %p>") % [self.class, to_s] | ||
end | ||
|
||
# Unstable API, for internal use only (Net::IMAP#validate_data) | ||
def validate # :nodoc: | ||
ResponseParser::Patterns::SEQUENCE_SET_STR.match?(@atom) or | ||
raise ArgumentError, "invalid sequence-set: %p" % [input] | ||
true | ||
end | ||
|
||
# Unstable API, for internal use only (Net::IMAP#send_data) | ||
def send_data(imap, tag) # :nodoc: | ||
imap.__send__(:put_string, atom) | ||
end | ||
|
||
end | ||
end | ||
end |
Oops, something went wrong.