internal/imapc/open.go

727e9773591679858f7e89e6a9b2942db20cc2d2
gitbay/internal/imapc/open.go

35 lines · 790 bytes

 1package imapc
 2
 3import (
 4	"time"
 5
 6	"gitbay.org/gitbay/internal/config"
 7)
 8
 9// Open connects to the configured mailbox, logs in with the password
10// file's password, and opens the mailbox: read-only (EXAMINE) or for
11// setting flags (SELECT). It returns the number of messages in it.
12func Open(in config.MailInbound, readOnly bool, timeout time.Duration) (*Client, int, error) {
13	pass, err := in.Password()
14	if err != nil {
15		return nil, 0, err
16	}
17	c, err := Dial(in.Addr(), in.TLS == "starttls", timeout)
18	if err != nil {
19		return nil, 0, err
20	}
21	if err := c.Login(in.User, pass); err != nil {
22		c.Close()
23		return nil, 0, err
24	}
25	open := c.Select
26	if readOnly {
27		open = c.Examine
28	}
29	n, err := open(in.MailboxName())
30	if err != nil {
31		c.Close()
32		return nil, 0, err
33	}
34	return c, n, nil
35}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form