Skip to content

Commit e5ab356

Browse files
committed
♻️ Extract select_internal (private) method
1 parent 079167e commit e5ab356

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

lib/net/imap.rb

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1556,6 +1556,9 @@ def login(user, password)
15561556
.tap do state_authenticated! _1 end
15571557
end
15581558

1559+
# :call-seq:
1560+
# select(mailbox, **opts) -> result
1561+
#
15591562
# Sends a {SELECT command [IMAP4rev1 §6.3.1]}[https://www.rfc-editor.org/rfc/rfc3501#section-6.3.1]
15601563
# to select a +mailbox+ so that messages in the +mailbox+ can be accessed.
15611564
#
@@ -1589,17 +1592,13 @@ def login(user, password)
15891592
# the +condstore+ keyword parameter may be used.
15901593
# imap.select("mbox", condstore: true)
15911594
# modseq = imap.responses("HIGHESTMODSEQ", &:last)
1592-
def select(mailbox, condstore: false)
1593-
args = ["SELECT", mailbox]
1594-
args << ["CONDSTORE"] if condstore
1595-
synchronize do
1596-
state_unselected! # implicitly closes current mailbox
1597-
@responses.clear
1598-
send_command(*args)
1599-
.tap do state_selected! end
1600-
end
1595+
def select(...)
1596+
select_internal("SELECT", ...)
16011597
end
16021598

1599+
# :call-seq:
1600+
# examine(mailbox, **opts) -> result
1601+
#
16031602
# Sends a {EXAMINE command [IMAP4rev1 §6.3.2]}[https://www.rfc-editor.org/rfc/rfc3501#section-6.3.2]
16041603
# to select a +mailbox+ so that messages in the +mailbox+ can be accessed.
16051604
# Behaves the same as #select, except that the selected +mailbox+ is
@@ -1609,15 +1608,8 @@ def select(mailbox, condstore: false)
16091608
# exist or is for some reason non-examinable.
16101609
#
16111610
# Related: #select
1612-
def examine(mailbox, condstore: false)
1613-
args = ["EXAMINE", mailbox]
1614-
args << ["CONDSTORE"] if condstore
1615-
synchronize do
1616-
state_unselected! # implicitly closes current mailbox
1617-
@responses.clear
1618-
send_command(*args)
1619-
.tap do state_selected! end
1620-
end
1611+
def examine(...)
1612+
select_internal("EXAMINE", ...)
16211613
end
16221614

16231615
# Sends a {CREATE command [IMAP4rev1 §6.3.3]}[https://www.rfc-editor.org/rfc/rfc3501#section-6.3.3]
@@ -3585,6 +3577,17 @@ def enforce_logindisabled?
35853577
end
35863578
end
35873579

3580+
def select_internal(command, mailbox, condstore: false)
3581+
args = [command, mailbox]
3582+
args << ["CONDSTORE"] if condstore
3583+
synchronize do
3584+
state_unselected! # implicitly closes current mailbox
3585+
@responses.clear
3586+
send_command(*args)
3587+
.tap do state_selected! end
3588+
end
3589+
end
3590+
35883591
def expunge_internal(...)
35893592
synchronize do
35903593
send_command(...)

0 commit comments

Comments
 (0)