Module: Net::IMAP::ResponseParser::Patterns
Defined Under Namespace
Modules: CharClassSubtraction, RFC3629, RFC5234
Constant Summary collapse
- CHAR8 =
CHAR8 = %x01-ff
; any OCTET except NUL, %x00
/[\x01-\xff]/n
- LIST_WILDCARDS =
list-wildcards = “%” / “*”
/[%*]/n
- QUOTED_SPECIALS =
quoted-specials = DQUOTE / “"
/["\\]/n
- RESP_SPECIALS =
resp-specials = “]”
/[\]]/n
- ATOM_SPECIALS =
atomish = 1*<any ATOM-CHAR except “[”>
; We use "atomish" for msg-att and section, in order ; to simplify "BODY[HEADER.FIELDS (foo bar)]".
atom-specials = “(” / “)” / “{” / SP / CTL / list-wildcards /
quoted-specials / resp-specials
ATOM-CHAR = <any CHAR except atom-specials> atom = 1*ATOM-CHAR ASTRING-CHAR = ATOM-CHAR / resp-specials tag = 1*<any ASTRING-CHAR except “+”>
/[(){ \x00-\x1f\x7f%*"\\\]]/n
- ASTRING_SPECIALS =
/[(){ \x00-\x1f\x7f%*"\\]/n
- ASTRING_CHAR =
CHAR - ASTRING_SPECIALS
- ATOM_CHAR =
CHAR - ATOM_SPECIALS
- ATOM =
/#{ATOM_CHAR}+/n
- ASTRING_CHARS =
/#{ASTRING_CHAR}+/n
- ATOMISH =
/#{ATOM_CHAR - /[\[]/ }+/
- TAG =
/#{ASTRING_CHAR - /[+]/ }+/
- TEXT_CHAR =
TEXT-CHAR = <any CHAR except CR and LF>
CHAR - /[\r\n]/
- CODE_TEXT_CHAR =
resp-text-code = … / atom [SP 1*<any TEXT-CHAR except “]”>]
TEXT_CHAR - RESP_SPECIALS
- CODE_TEXT =
/#{CODE_TEXT_CHAR}+/n
- FLAG =
flag = “Answered” / “Flagged” / “Deleted” /
"\Seen" / "\Draft" / flag-keyword / flag-extension ; Does not include "\Recent"
flag-extension = “" atom
; Future expansion. Client implementations ; MUST accept flag-extension flags. Server ; implementations MUST NOT generate ; flag-extension flags except as defined by ; a future Standard or Standards Track ; revisions of this specification.
flag-keyword = “$MDNSent” / “$Forwarded” / “$Junk” /
"$NotJunk" / "$Phishing" / atom
flag-perm = flag / “*”
Not checking for max one mbx-list-sflag in the parser.
mbx-list-oflag = “Noinferiors” / child-mbox-flag /
"\Subscribed" / "\Remote" / flag-extension ; Other flags; multiple from this list are ; possible per LIST response, but each flag ; can only appear once per LIST response
mbx-list-sflag = “NonExistent” / “Noselect” / “Marked” /
"\Unmarked" ; Selectability flags; only one per LIST response
child-mbox-flag = “HasChildren” / “HasNoChildren”
; attributes for the CHILDREN return option, at most ; one possible per LIST response
/\\?#{ATOM}/n
- FLAG_EXTENSION =
/\\#{ATOM}/n
- FLAG_KEYWORD =
ATOM
- FLAG_PERM =
Regexp.union(FLAG, "\\*")
- MBX_FLAG =
FLAG_EXTENSION
- FLAG_LIST =
flag-list = “(” [flag *(SP flag)] “)” resp-text-code =/ “PERMANENTFLAGS” SP
"(" [flag-perm *(SP flag-perm)] ")"
mbx-list-flags = *(mbx-list-oflag SP) mbx-list-sflag
*(SP mbx-list-oflag) / mbx-list-oflag *(SP mbx-list-oflag)
(Not checking for max one mbx-list-sflag in the parser.)
/\G\((#{FLAG }(?:#{SP}#{FLAG })*|)\)/ni
- FLAG_PERM_LIST =
/\G\((#{FLAG_PERM}(?:#{SP}#{FLAG_PERM})*|)\)/ni
- MBX_LIST_FLAGS =
/\G (#{MBX_FLAG }(?:#{SP}#{MBX_FLAG })*) /nix
- QUIRKY_FLAG =
Gmail allows SP and “]” in flags.……
Regexp.union(/\\?#{ASTRING_CHARS}/n, "\\*")
- QUIRKY_FLAGS_LIST =
/\G\(( [^)]* )\)/nx
- QUOTED_CHAR_safe =
RFC3501:
QUOTED-CHAR = <any TEXT-CHAR except quoted-specials> / "\" quoted-specials
RFC9051:
QUOTED-CHAR = <any TEXT-CHAR except quoted-specials> / "\" quoted-specials / UTF8-2 / UTF8-3 / UTF8-4
RFC3501 & RFC9051:
quoted = DQUOTE *QUOTED-CHAR DQUOTE
TEXT_CHAR - QUOTED_SPECIALS
- QUOTED_CHAR_esc =
/\\#{QUOTED_SPECIALS}/n
- QUOTED_CHAR_rev1 =
Regexp.union(QUOTED_CHAR_safe, QUOTED_CHAR_esc)
- QUOTED_CHAR_rev2 =
Regexp.union(QUOTED_CHAR_rev1, UTF8_2, UTF8_3, UTF8_4)
- QUOTED_rev1 =
/"(#{QUOTED_CHAR_rev1}*)"/n
- QUOTED_rev2 =
/"(#{QUOTED_CHAR_rev2}*)"/n
- TEXT_rev1 =
RFC3501:
text = 1*TEXT-CHAR
RFC9051:
text = 1*(TEXT-CHAR / UTF8-2 / UTF8-3 / UTF8-4) ; Non-ASCII text can only be returned ; after ENABLE IMAP4rev2 command
/#{TEXT_CHAR}+/
- TEXT_rev2 =
/#{Regexp.union TEXT_CHAR, UTF8_2, UTF8_3, UTF8_4}+/
- TAGGED_LABEL_FCHAR =
tagged-label-fchar = ALPHA / “-” / “_” / “.”
/[a-zA-Z\-_.]/n
- TAGGED_LABEL_CHAR =
tagged-label-char = tagged-label-fchar / DIGIT / “:”
/[a-zA-Z\-_.0-9:]*/n
- TAGGED_EXT_LABEL =
tagged-ext-label = tagged-label-fchar *tagged-label-char
; Is a valid RFC 3501 "atom".
/#{TAGGED_LABEL_FCHAR}#{TAGGED_LABEL_CHAR}*/n
- NZ_NUMBER =
nz-number = digit-nz *DIGIT
; Non-zero unsigned 32-bit integer ; (0 < n < 4,294,967,296)
/[1-9]\d*/n
- SEQ_NUMBER =
seq-number = nz-number / “*”
; message sequence number (COPY, FETCH, STORE ; commands) or unique identifier (UID COPY, ; UID FETCH, UID STORE commands). ; * represents the largest number in use. In ; the case of message sequence numbers, it is ; the number of messages in a non-empty mailbox. ; In the case of unique identifiers, it is the ; unique identifier of the last message in the ; mailbox or, if the mailbox is empty, the ; mailbox's current UIDNEXT value. ; The server should respond with a tagged BAD ; response to a command that uses a message ; sequence number greater than the number of ; messages in the selected mailbox. This ; includes "*" if the selected mailbox is empty.
/#{NZ_NUMBER}|\*/n
- SEQ_RANGE =
seq-range = seq-number “:” seq-number
; two seq-number values and all values between ; these two regardless of order. ; Example: 2:4 and 4:2 are equivalent and ; indicate values 2, 3, and 4. ; Example: a unique identifier sequence range of ; 3291:* includes the UID of the last message in ; the mailbox, even if that value is less than ; 3291.
/#{SEQ_NUMBER}:#{SEQ_NUMBER}/n
- SEQUENCE_SET_ITEM =
sequence-set = (seq-number / seq-range) [“,” sequence-set]
; set of seq-number values, regardless of order. ; Servers MAY coalesce overlaps and/or execute ; the sequence in any order. ; Example: a message sequence number set of ; 2,4:7,9,12:* for a mailbox with 15 messages is ; equivalent to 2,4,5,6,7,9,12,13,14,15 ; Example: a message sequence number set of ; *:4,5:7 for a mailbox with 10 messages is ; equivalent to 10,9,8,7,6,5,4,5,6,7 and MAY ; be reordered and overlap coalesced to be ; 4,5,6,7,8,9,10.
/#{SEQ_NUMBER}|#{SEQ_RANGE}/n
- SEQUENCE_SET =
/#{SEQUENCE_SET_ITEM}(?:,#{SEQUENCE_SET_ITEM})*/n
- SEQUENCE_SET_STR =
/\A#{SEQUENCE_SET}\z/n
- LITERAL =
RFC3501:
literal = "{" number "}" CRLF *CHAR8 ; Number represents the number of CHAR8s
RFC9051:
literal = "{" number64 ["+"] "}" CRLF *CHAR8 ; <number64> represents the number of CHAR8s. ; A non-synchronizing literal is distinguished ; from a synchronizing literal by the presence of ; "+" before the closing "}". ; Non-synchronizing literals are not allowed when ; sent from server to the client.
/\{(\d+)\}\r\n/n
- LITERAL8 =
RFC3516 (BINARY):
literal8 = "~{" number "}" CRLF *OCTET ; <number> represents the number of OCTETs ; in the response string.
RFC9051:
literal8 = "~{" number64 "}" CRLF *OCTET ; <number64> represents the number of OCTETs ; in the response string.
/~\{(\d+)\}\r\n/n
Constants included from RFC3629
RFC3629::UTF8_1, RFC3629::UTF8_2, RFC3629::UTF8_3, RFC3629::UTF8_4, RFC3629::UTF8_CHAR, RFC3629::UTF8_OCTETS, RFC3629::UTF8_TAIL
Constants included from RFC5234
RFC5234::ALPHA, RFC5234::CHAR, RFC5234::CRLF, RFC5234::CTL, RFC5234::DIGIT, RFC5234::DQUOTE, RFC5234::HEXDIG, RFC5234::OCTET, RFC5234::SP
Class Method Summary collapse
Class Method Details
.unescape_quoted(quoted) ⇒ Object
352 353 354 355 356 |
# File 'lib/net/imap/response_parser.rb', line 352 def unescape_quoted(quoted) quoted &.gsub(/\\(#{QUOTED_SPECIALS})/n, "\\1") &.force_encoding("UTF-8") end |
.unescape_quoted!(quoted) ⇒ Object
346 347 348 349 350 |
# File 'lib/net/imap/response_parser.rb', line 346 def unescape_quoted!(quoted) quoted &.gsub!(/\\(#{QUOTED_SPECIALS})/n, "\\1") &.force_encoding("UTF-8") end |