Skip to content

Commit be45b1e

Browse files
committed
Fix unselect test deadlock, move Client.Unselect to cmd_selected.go (squash me)
1 parent bd98973 commit be45b1e

File tree

4 files changed

+29
-28
lines changed

4 files changed

+29
-28
lines changed

client/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func (c *serverConn) WriteString(s string) (n int, err error) {
4949
}
5050

5151
func newTestClient(t *testing.T) (c *Client, s *serverConn) {
52-
return newTestClientWithGreeting(t, "* OK [CAPABILITY IMAP4rev1 STARTTLS AUTH=PLAIN] Server ready.\r\n")
52+
return newTestClientWithGreeting(t, "* OK [CAPABILITY IMAP4rev1 STARTTLS AUTH=PLAIN UNSELECT] Server ready.\r\n")
5353
}
5454

5555
func newTestClientWithGreeting(t *testing.T, greeting string) (c *Client, s *serverConn) {

client/cmd_any.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ func (c *Client) Support(cap string) (bool, error) {
5656
c.locker.Lock()
5757
supported := c.caps[cap]
5858
c.locker.Unlock()
59+
5960
return supported, nil
6061
}
6162

client/cmd_auth.go

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -252,30 +252,3 @@ func (c *Client) Append(mbox string, flags []string, date time.Time, msg imap.Li
252252
}
253253
return status.Err()
254254
}
255-
256-
// Unselect frees server's resources associated with the selected mailbox and
257-
// returns the server to the authenticated state. This command performs the same
258-
// actions as Close, except that no messages are permanently removed from the
259-
// currently selected mailbox.
260-
//
261-
// If client does not support the UNSELECT extension, ErrExtensionUnsupported
262-
// is returned.
263-
func (c *Client) Unselect() error {
264-
if ok, err := c.Support("UNSELECT"); !ok || err != nil {
265-
return ErrExtensionUnsupported
266-
}
267-
268-
if c.State() != imap.SelectedState {
269-
return ErrNoMailboxSelected
270-
}
271-
272-
cmd := &commands.Unselect{}
273-
if status, err := c.Execute(cmd, nil); err != nil {
274-
return err
275-
} else if err := status.Err(); err != nil {
276-
return err
277-
}
278-
279-
c.SetState(imap.AuthenticatedState, nil)
280-
return nil
281-
}

client/cmd_selected.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,3 +271,30 @@ func (c *Client) Copy(seqset *imap.SeqSet, dest string) error {
271271
func (c *Client) UidCopy(seqset *imap.SeqSet, dest string) error {
272272
return c.copy(true, seqset, dest)
273273
}
274+
275+
// Unselect frees server's resources associated with the selected mailbox and
276+
// returns the server to the authenticated state. This command performs the same
277+
// actions as Close, except that no messages are permanently removed from the
278+
// currently selected mailbox.
279+
//
280+
// If client does not support the UNSELECT extension, ErrExtensionUnsupported
281+
// is returned.
282+
func (c *Client) Unselect() error {
283+
if ok, err := c.Support("UNSELECT"); !ok || err != nil {
284+
return ErrExtensionUnsupported
285+
}
286+
287+
if c.State() != imap.SelectedState {
288+
return ErrNoMailboxSelected
289+
}
290+
291+
cmd := &commands.Unselect{}
292+
if status, err := c.Execute(cmd, nil); err != nil {
293+
return err
294+
} else if err := status.Err(); err != nil {
295+
return err
296+
}
297+
298+
c.SetState(imap.AuthenticatedState, nil)
299+
return nil
300+
}

0 commit comments

Comments
 (0)