Skip to content

Commit e356713

Browse files
committed
♻️ Rename response-data methods to match ABNF
Many of the methods called by `response-data` are renamed (or given an alias) according to the new naming conventions, which aims to match the ABNF name where possible, and uses double-underscore (`__`) to signify when a method is used to match only part of an ABNF production.
1 parent a82f790 commit e356713

File tree

1 file changed

+48
-29
lines changed

1 file changed

+48
-29
lines changed

lib/net/imap/response_parser.rb

Lines changed: 48 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -494,11 +494,11 @@ def response_data
494494
when "ESEARCH" then esearch_response # RFC4731, RFC9051, etc
495495
when "VANISHED" then expunged_resp # RFC7162
496496
when "UIDFETCH" then uidfetch_resp # (draft) UIDONLY
497-
when "SEARCH" then search_response # RFC3501 (obsolete)
497+
when "SEARCH" then mailbox_data__search # RFC3501 (obsolete)
498498
when "CAPABILITY" then capability_data__untagged # RFC3501, RFC9051
499-
when "FLAGS" then flags_response # RFC3501, RFC9051
500-
when "LIST" then list_response # RFC3501, RFC9051
501-
when "STATUS" then status_response # RFC3501, RFC9051
499+
when "FLAGS" then mailbox_data__flags # RFC3501, RFC9051
500+
when "LIST" then mailbox_data__list # RFC3501, RFC9051
501+
when "STATUS" then mailbox_data__status # RFC3501, RFC9051
502502
when "NAMESPACE" then namespace_response # RFC2342, RFC9051
503503
when "ENABLED" then enable_data # RFC5161, RFC9051
504504
when "BAD" then response_cond # RFC3501, RFC9051
@@ -507,25 +507,25 @@ def response_data
507507
when "BYE" then response_cond # RFC3501, RFC9051
508508
when "RECENT" then mailbox_data__recent # RFC3501 (obsolete)
509509
when "SORT" then sort_data # RFC5256, RFC7162
510-
when "THREAD" then thread_response # RFC5256
511-
when "QUOTA" then getquota_response # RFC2087, RFC9208
512-
when "QUOTAROOT" then getquotaroot_response # RFC2087, RFC9208
510+
when "THREAD" then thread_data # RFC5256
511+
when "QUOTA" then quota_response # RFC2087, RFC9208
512+
when "QUOTAROOT" then quotaroot_response # RFC2087, RFC9208
513513
when "ID" then id_response # RFC2971
514-
when "ACL" then getacl_response # RFC4314
514+
when "ACL" then acl_data # RFC4314
515515
when "LISTRIGHTS" then listrights_data # RFC4314
516516
when "MYRIGHTS" then myrights_data # RFC4314
517517
when "METADATA" then metadata_resp # RFC5464
518518
when "LANGUAGE" then language_data # RFC5255
519519
when "COMPARATOR" then comparator_data # RFC5255
520520
when "CONVERTED" then message_data__converted # RFC5259
521-
when "LSUB" then list_response # RFC3501 (obsolete)
522-
when "XLIST" then list_response # deprecated
523-
when "NOOP" then ignored_response
524-
else unparsed_response
521+
when "LSUB" then mailbox_data__lsub # RFC3501 (obsolete)
522+
when "XLIST" then mailbox_data__xlist # deprecated
523+
when "NOOP" then response_data__noop
524+
else response_data__unhandled
525525
end
526526
end
527527

528-
def unparsed_response(klass = UntaggedResponse)
528+
def response_data__unhandled(klass = UntaggedResponse)
529529
num = number?; SP?
530530
type = tagged_ext_label; SP?
531531
text = remaining_unparsed
@@ -539,17 +539,18 @@ def remaining_unparsed
539539
str&.empty? ? nil : str
540540
end
541541

542-
def ignored_response; unparsed_response(IgnoredResponse) end
542+
def response_data__ignored; response_data__unhandled(IgnoredResponse) end
543+
alias response_data__noop response_data__ignored
543544

544-
alias esearch_response unparsed_response
545-
alias expunged_resp unparsed_response
546-
alias uidfetch_resp unparsed_response
547-
alias listrights_data unparsed_response
548-
alias myrights_data unparsed_response
549-
alias metadata_resp unparsed_response
550-
alias language_data unparsed_response
551-
alias comparator_data unparsed_response
552-
alias message_data__converted unparsed_response
545+
alias esearch_response response_data__unhandled
546+
alias expunged_resp response_data__unhandled
547+
alias uidfetch_resp response_data__unhandled
548+
alias listrights_data response_data__unhandled
549+
alias myrights_data response_data__unhandled
550+
alias metadata_resp response_data__unhandled
551+
alias language_data response_data__unhandled
552+
alias comparator_data response_data__unhandled
553+
alias message_data__converted response_data__unhandled
553554

554555
# RFC3501 & RFC9051:
555556
# response-tagged = tag SP resp-cond-state CRLF
@@ -1046,19 +1047,21 @@ def modseq_data
10461047
return name, modseq
10471048
end
10481049

1049-
def flags_response
1050+
def mailbox_data__flags
10501051
token = match(T_ATOM)
10511052
name = token.value.upcase
10521053
match(T_SPACE)
10531054
return UntaggedResponse.new(name, flag_list, @str)
10541055
end
10551056

1056-
def list_response
1057+
def mailbox_data__list
10571058
token = match(T_ATOM)
10581059
name = token.value.upcase
10591060
match(T_SPACE)
10601061
return UntaggedResponse.new(name, mailbox_list, @str)
10611062
end
1063+
alias mailbox_data__lsub mailbox_data__list
1064+
alias mailbox_data__xlist mailbox_data__list
10621065

10631066
def mailbox_list
10641067
attr = flag_list
@@ -1124,7 +1127,8 @@ def getquotaroot_response
11241127
return UntaggedResponse.new(name, data, @str)
11251128
end
11261129

1127-
def getacl_response
1130+
# acl-data = "ACL" SP mailbox *(SP identifier SP rights)
1131+
def acl_data
11281132
token = match(T_ATOM)
11291133
name = token.value.upcase
11301134
match(T_SPACE)
@@ -1150,7 +1154,21 @@ def getacl_response
11501154
return UntaggedResponse.new(name, data, @str)
11511155
end
11521156

1153-
def search_response
1157+
# RFC3501:
1158+
# mailbox-data = "SEARCH" *(SP nz-number) / ...
1159+
# RFC5256: SORT
1160+
# sort-data = "SORT" *(SP nz-number)
1161+
# RFC7162: CONDSTORE, QRESYNC
1162+
# mailbox-data =/ "SEARCH" [1*(SP nz-number) SP
1163+
# search-sort-mod-seq]
1164+
# sort-data = "SORT" [1*(SP nz-number) SP
1165+
# search-sort-mod-seq]
1166+
# ; Updates the SORT response from RFC 5256.
1167+
# search-sort-mod-seq = "(" "MODSEQ" SP mod-sequence-value ")"
1168+
# RFC9051:
1169+
# mailbox-data = obsolete-search-response / ...
1170+
# obsolete-search-response = "SEARCH" *(SP nz-number)
1171+
def mailbox_data__search
11541172
token = match(T_ATOM)
11551173
name = token.value.upcase
11561174
token = lookahead
@@ -1180,8 +1198,9 @@ def search_response
11801198
end
11811199
return UntaggedResponse.new(name, data, @str)
11821200
end
1201+
alias sort_data mailbox_data__search
11831202

1184-
def thread_response
1203+
def thread_data
11851204
token = match(T_ATOM)
11861205
name = token.value.upcase
11871206
token = lookahead
@@ -1243,7 +1262,7 @@ def thread_branch(token)
12431262
return rootmember
12441263
end
12451264

1246-
def status_response
1265+
def mailbox_data__status
12471266
token = match(T_ATOM)
12481267
name = token.value.upcase
12491268
match(T_SPACE)

0 commit comments

Comments
 (0)