Skip to content

Commit 7a44de3

Browse files
committed
✨ Add STATUS MAILBOXID (RFC8474, OBJECTID)
Previously, any number-type status values worked—which is most of them. This adds support for `MAILBOXID` (needed for the `OBJECTID` extension).
1 parent 36f1381 commit 7a44de3

File tree

3 files changed

+52
-11
lines changed

3 files changed

+52
-11
lines changed

lib/net/imap.rb

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -509,8 +509,7 @@ module Net
509509
# - Adds +MAILBOXID+ ResponseCode to #select and #examine untagged response.
510510
# - Updates #fetch and #uid_fetch with the +EMAILID+ and +THREADID+ items.
511511
# See FetchData#emailid and FetchData#emailid.
512-
# >>>
513-
# *NOTE: The +MAILBOXID+ attribute for #status is not supported yet.
512+
# - Updates #status with support for the +MAILBOXID+ status attribute.
514513
#
515514
# == References
516515
#
@@ -1691,21 +1690,52 @@ def lsub(refname, mailbox)
16911690

16921691
# Sends a {STATUS commands [IMAP4rev1 §6.3.10]}[https://www.rfc-editor.org/rfc/rfc3501#section-6.3.10]
16931692
# and returns the status of the indicated +mailbox+. +attr+ is a list of one
1694-
# or more attributes whose statuses are to be requested. Supported
1695-
# attributes include:
1693+
# or more attributes whose statuses are to be requested.
1694+
#
1695+
# The return value is a hash of attributes.
1696+
#
1697+
# A Net::IMAP::NoResponseError is raised if status values
1698+
# for +mailbox+ cannot be returned; for instance, because it
1699+
# does not exist.
1700+
#
1701+
# ===== Supported attributes:
1702+
#
1703+
# +MESSAGES+:: The number of messages in the mailbox.
1704+
#
1705+
# +UIDNEXT+:: The next unique identifier value of the mailbox.
1706+
#
1707+
# +UIDVALIDITY+:: The unique identifier validity value of the mailbox.
1708+
#
1709+
# +UNSEEN+:: The number of messages without the <tt>\Seen</tt> flag.
16961710
#
1697-
# MESSAGES:: the number of messages in the mailbox.
1698-
# RECENT:: the number of recent messages in the mailbox.
1699-
# UNSEEN:: the number of unseen messages in the mailbox.
1711+
# +DELETED+:: The number of messages with the <tt>\Deleted</tt> flag.
17001712
#
1701-
# The return value is a hash of attributes. For example:
1713+
# +SIZE+::
1714+
# The approximate size of the mailbox---must be greater than or equal to
1715+
# the sum of all messages' +RFC822.SIZE+ fetch item values.
1716+
#
1717+
# +MAILBOXID+::
1718+
# A server-allocated unique identifier for the mailbox.
1719+
# See +OBJECTID+
1720+
# {[RFC8474]}[https://www.rfc-editor.org/rfc/rfc8474.html#section-4].
1721+
#
1722+
# +RECENT+::
1723+
# The number of messages with the <tt>\Recent</tt> flag.
1724+
# _NOTE:_ +RECENT+ was removed from IMAP4rev2.
1725+
#
1726+
# ===== For example:
17021727
#
17031728
# p imap.status("inbox", ["MESSAGES", "RECENT"])
17041729
# #=> {"RECENT"=>0, "MESSAGES"=>44}
17051730
#
1706-
# A Net::IMAP::NoResponseError is raised if status values
1707-
# for +mailbox+ cannot be returned; for instance, because it
1708-
# does not exist.
1731+
# ===== Capabilities
1732+
#
1733+
# +SIZE+ requires the server's capabilities to include either +IMAP4rev2+ or
1734+
# <tt>STATUS=SIZE</tt>
1735+
# {[RFC8483]}[https://www.rfc-editor.org/rfc/rfc8483.html].
1736+
#
1737+
# +MAILBOXID+ requires the server's capabilities to include +OBJECTID+
1738+
# {[RFC8474]}[https://www.rfc-editor.org/rfc/rfc8474.html].
17091739
def status(mailbox, attr)
17101740
synchronize do
17111741
send_command("STATUS", mailbox, attr)

lib/net/imap/response_parser.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,6 +1589,7 @@ def status_att_val
15891589
when "UIDVALIDITY" then nz_number # RFC3501, RFC9051
15901590
when "RECENT" then number # RFC3501 (obsolete)
15911591
when "SIZE" then number64 # RFC8483, RFC9051
1592+
when "MAILBOXID" then parens__objectid # RFC8474
15921593
else
15931594
number? || ExtensionData.new(tagged_ext_val)
15941595
end

test/net/imap/fixtures/response_parser/rfc8474_objectid_responses.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@
2323
text: Ok
2424
raw_data: "* OK [MAILBOXID (F2212ea87-6097-4256-9d51-71338625)] Ok\r\n"
2525

26+
rfc8474_example_4.3_MAILBOXID_attribute_for_STATUS:
27+
:response: "* STATUS foo (MAILBOXID (F2212ea87-6097-4256-9d51-71338625))\r\n"
28+
:expected: !ruby/struct:Net::IMAP::UntaggedResponse
29+
name: STATUS
30+
data: !ruby/struct:Net::IMAP::StatusData
31+
mailbox: foo
32+
attr:
33+
MAILBOXID: F2212ea87-6097-4256-9d51-71338625
34+
raw_data: "* STATUS foo (MAILBOXID (F2212ea87-6097-4256-9d51-71338625))\r\n"
35+
2636
rfc8474_example_5.3_EMAILID_and_THREADID:
2737
:response: "* 3 FETCH (EMAILID (M5fdc09b49ea703) THREADID (T11863d02dd95b5))\r\n"
2838
:expected: !ruby/struct:Net::IMAP::UntaggedResponse

0 commit comments

Comments
 (0)