diff --git a/backend/backend.go b/backend/backend.go index 1ce72784..85a8ee1d 100644 --- a/backend/backend.go +++ b/backend/backend.go @@ -9,7 +9,7 @@ import ( // ErrInvalidCredentials is returned by Backend.Login when a username or a // password is incorrect. -var ErrInvalidCredentials = errors.New("Invalid credentials") +var ErrInvalidCredentials = errors.New("invalid credentials") // Backend is an IMAP server backend. A backend operation always deals with // users. diff --git a/backend/backendutil/backendutil_test.go b/backend/backendutil/backendutil_test.go index 79633308..c8c46476 100644 --- a/backend/backendutil/backendutil_test.go +++ b/backend/backendutil/backendutil_test.go @@ -11,7 +11,7 @@ const testHeaderString = "Content-Type: multipart/mixed; boundary=message-bounda "Date: Sat, 19 Jun 2016 12:00:00 +0900\r\n" + "From: Mitsuha Miyamizu \r\n" + "Reply-To: Mitsuha Miyamizu \r\n" + - "Message-Id: 42@example.org\r\n" + + "Message-ID: 42@example.org\r\n" + "Subject: Your Name.\r\n" + "To: Taki Tachibana \r\n" + "\r\n" @@ -28,7 +28,7 @@ const testHeaderNoFromToString = "Content-Type: multipart/mixed; boundary=messag "Date: Sat, 18 Jun 2016 12:00:00 +0900\r\n" + "Date: Sat, 19 Jun 2016 12:00:00 +0900\r\n" + "Reply-To: Mitsuha Miyamizu \r\n" + - "Message-Id: 42@example.org\r\n" + + "Message-ID: 42@example.org\r\n" + "Subject: Your Name.\r\n" + "\r\n" diff --git a/backend/backendutil/body_test.go b/backend/backendutil/body_test.go index 252a0845..9acd12bc 100644 --- a/backend/backendutil/body_test.go +++ b/backend/backendutil/body_test.go @@ -144,7 +144,7 @@ func TestFetchBodySection_NonMultipart(t *testing.T) { testMsgHdr := "From: Mitsuha Miyamizu \r\n" + "To: Taki Tachibana \r\n" + "Subject: Your Name.\r\n" + - "Message-Id: 42@example.org\r\n" + + "Message-ID: 42@example.org\r\n" + "\r\n" testMsgBody := "That's not multipart message. Thought it should be possible to get this text using BODY[1]." testMsg := testMsgHdr + testMsgBody diff --git a/backend/backendutil/bodystructure.go b/backend/backendutil/bodystructure.go index 101f16f3..2cbf700a 100644 --- a/backend/backendutil/bodystructure.go +++ b/backend/backendutil/bodystructure.go @@ -26,7 +26,7 @@ func FetchBodyStructure(header textproto.Header, body io.Reader, extended bool) bs.MIMESubType = "plain" } - bs.Id = header.Get("Content-Id") + bs.ID = header.Get("Content-ID") bs.Description = header.Get("Content-Description") bs.Encoding = header.Get("Content-Transfer-Encoding") // TODO: bs.Size diff --git a/backend/backendutil/envelope.go b/backend/backendutil/envelope.go index 584620d1..f5e1f905 100644 --- a/backend/backendutil/envelope.go +++ b/backend/backendutil/envelope.go @@ -52,7 +52,7 @@ func FetchEnvelope(h textproto.Header) (*imap.Envelope, error) { env.Cc, _ = headerAddressList(h.Get("Cc")) env.Bcc, _ = headerAddressList(h.Get("Bcc")) env.InReplyTo = h.Get("In-Reply-To") - env.MessageId = h.Get("Message-Id") + env.MessageID = h.Get("Message-ID") return env, nil } diff --git a/backend/backendutil/envelope_test.go b/backend/backendutil/envelope_test.go index a708c060..c62cb3ad 100644 --- a/backend/backendutil/envelope_test.go +++ b/backend/backendutil/envelope_test.go @@ -20,7 +20,7 @@ var testEnvelope = &imap.Envelope{ Cc: []*imap.Address{}, Bcc: []*imap.Address{}, InReplyTo: "", - MessageId: "42@example.org", + MessageID: "42@example.org", } func TestFetchEnvelope(t *testing.T) { diff --git a/backend/backendutil/flags_test.go b/backend/backendutil/flags_test.go index 26c5d9d3..6c27f7f2 100644 --- a/backend/backendutil/flags_test.go +++ b/backend/backendutil/flags_test.go @@ -37,7 +37,7 @@ var updateFlagsTests = []struct { func TestUpdateFlags(t *testing.T) { current := []string{"a", "b", "c"} for _, test := range updateFlagsTests { - got := UpdateFlags(current[:], test.op, test.flags) + got := UpdateFlags(current, test.op, test.flags) if !reflect.DeepEqual(got, test.res) { t.Errorf("Expected result to be \n%v\n but got \n%v", test.res, got) diff --git a/backend/backendutil/search.go b/backend/backendutil/search.go index 8aaa62b0..07ec12fe 100644 --- a/backend/backendutil/search.go +++ b/backend/backendutil/search.go @@ -136,8 +136,8 @@ func Match(e *message.Entity, seqNum, uid uint32, date time.Time, flags []string } } - if c.SeqNum != nil || c.Uid != nil { - if !matchSeqNumAndUid(seqNum, uid, c) { + if c.SeqNum != nil || c.UID != nil { + if !matchSeqNumAndUID(seqNum, uid, c) { return false, nil } } @@ -183,11 +183,11 @@ func matchFlags(flags []string, c *imap.SearchCriteria) bool { return true } -func matchSeqNumAndUid(seqNum uint32, uid uint32, c *imap.SearchCriteria) bool { +func matchSeqNumAndUID(seqNum uint32, uid uint32, c *imap.SearchCriteria) bool { if c.SeqNum != nil && !c.SeqNum.Contains(seqNum) { return false } - if c.Uid != nil && !c.Uid.Contains(uid) { + if c.UID != nil && !c.UID.Contains(uid) { return false } return true diff --git a/backend/backendutil/search_test.go b/backend/backendutil/search_test.go index 15639b44..c0dae4e0 100644 --- a/backend/backendutil/search_test.go +++ b/backend/backendutil/search_test.go @@ -65,19 +65,19 @@ var matchTests = []struct { }, { criteria: &imap.SearchCriteria{ - Header: textproto.MIMEHeader{"Message-Id": {"42@example.org"}}, + Header: textproto.MIMEHeader{"Message-ID": {"42@example.org"}}, }, res: true, }, { criteria: &imap.SearchCriteria{ - Header: textproto.MIMEHeader{"Message-Id": {"43@example.org"}}, + Header: textproto.MIMEHeader{"Message-ID": {"43@example.org"}}, }, res: false, }, { criteria: &imap.SearchCriteria{ - Header: textproto.MIMEHeader{"Message-Id": {""}}, + Header: textproto.MIMEHeader{"Message-ID": {""}}, }, res: true, }, @@ -160,7 +160,7 @@ var matchTests = []struct { criteria: &imap.SearchCriteria{ Or: [][2]*imap.SearchCriteria{{ { - Uid: new(imap.SeqSet), + UID: new(imap.SeqSet), Not: []*imap.SearchCriteria{{SeqNum: new(imap.SeqSet)}}, }, { @@ -176,7 +176,7 @@ var matchTests = []struct { criteria: &imap.SearchCriteria{ Or: [][2]*imap.SearchCriteria{{ { - Uid: &imap.SeqSet{Set: []imap.Seq{{69, 69}}}, + UID: &imap.SeqSet{Set: []imap.Seq{{69, 69}}}, Not: []*imap.SearchCriteria{{SeqNum: new(imap.SeqSet)}}, }, { @@ -192,9 +192,9 @@ var matchTests = []struct { criteria: &imap.SearchCriteria{ Or: [][2]*imap.SearchCriteria{{ { - Uid: &imap.SeqSet{Set: []imap.Seq{{69, 69}}}, + UID: &imap.SeqSet{Set: []imap.Seq{{69, 69}}}, Not: []*imap.SearchCriteria{{ - SeqNum: &imap.SeqSet{Set: []imap.Seq{imap.Seq{42, 42}}}, + SeqNum: &imap.SeqSet{Set: []imap.Seq{{42, 42}}}, }}, }, { @@ -210,7 +210,7 @@ var matchTests = []struct { criteria: &imap.SearchCriteria{ Or: [][2]*imap.SearchCriteria{{ { - Uid: &imap.SeqSet{Set: []imap.Seq{{69, 69}}}, + UID: &imap.SeqSet{Set: []imap.Seq{{69, 69}}}, Not: []*imap.SearchCriteria{{ SeqNum: &imap.SeqSet{Set: []imap.Seq{{42, 42}}}, }}, diff --git a/backend/memory/backend.go b/backend/memory/backend.go index 25c65ab8..d4981cc3 100644 --- a/backend/memory/backend.go +++ b/backend/memory/backend.go @@ -19,7 +19,7 @@ func (be *Backend) Login(_ *imap.ConnInfo, username, password string) (backend.U return user, nil } - return nil, errors.New("Bad username or password") + return nil, errors.New("bad username or password") } func New() *Backend { @@ -40,7 +40,7 @@ func New() *Backend { user: user, Messages: []*Message{ { - Uid: 6, + UID: 6, Date: time.Now(), Flags: []string{"\\Seen"}, Size: uint32(len(body)), diff --git a/backend/memory/mailbox.go b/backend/memory/mailbox.go index 2d0fa9f0..8ffd4ad8 100644 --- a/backend/memory/mailbox.go +++ b/backend/memory/mailbox.go @@ -34,8 +34,8 @@ func (mbox *Mailbox) Info() (*imap.MailboxInfo, error) { func (mbox *Mailbox) uidNext() uint32 { var uid uint32 for _, msg := range mbox.Messages { - if msg.Uid > uid { - uid = msg.Uid + if msg.UID > uid { + uid = msg.UID } } uid++ @@ -52,7 +52,7 @@ func (mbox *Mailbox) flags() []string { } } - var flags []string + flags := make([]string, 0, len(flagsMap)) for f := range flagsMap { flags = append(flags, f) } @@ -88,10 +88,10 @@ func (mbox *Mailbox) Status(items []imap.StatusItem) (*imap.MailboxStatus, error switch name { case imap.StatusMessages: status.Messages = uint32(len(mbox.Messages)) - case imap.StatusUidNext: - status.UidNext = mbox.uidNext() - case imap.StatusUidValidity: - status.UidValidity = 1 + case imap.StatusUIDNext: + status.UIDNext = mbox.uidNext() + case imap.StatusUIDValidity: + status.UIDValidity = 1 case imap.StatusRecent: status.Recent = 0 // TODO case imap.StatusUnseen: @@ -119,7 +119,7 @@ func (mbox *Mailbox) ListMessages(uid bool, seqSet *imap.SeqSet, items []imap.Fe var id uint32 if uid { - id = msg.Uid + id = msg.UID } else { id = seqNum } @@ -139,7 +139,7 @@ func (mbox *Mailbox) ListMessages(uid bool, seqSet *imap.SeqSet, items []imap.Fe } func (mbox *Mailbox) SearchMessages(uid bool, criteria *imap.SearchCriteria) ([]uint32, error) { - var ids []uint32 + ids := make([]uint32, 0, len(mbox.Messages)) for i, msg := range mbox.Messages { seqNum := uint32(i + 1) @@ -150,7 +150,7 @@ func (mbox *Mailbox) SearchMessages(uid bool, criteria *imap.SearchCriteria) ([] var id uint32 if uid { - id = msg.Uid + id = msg.UID } else { id = seqNum } @@ -170,7 +170,7 @@ func (mbox *Mailbox) CreateMessage(flags []string, date time.Time, body imap.Lit } mbox.Messages = append(mbox.Messages, &Message{ - Uid: mbox.uidNext(), + UID: mbox.uidNext(), Date: date, Size: uint32(len(b)), Flags: flags, @@ -183,7 +183,7 @@ func (mbox *Mailbox) UpdateMessagesFlags(uid bool, seqset *imap.SeqSet, op imap. for i, msg := range mbox.Messages { var id uint32 if uid { - id = msg.Uid + id = msg.UID } else { id = uint32(i + 1) } @@ -206,7 +206,7 @@ func (mbox *Mailbox) CopyMessages(uid bool, seqset *imap.SeqSet, destName string for i, msg := range mbox.Messages { var id uint32 if uid { - id = msg.Uid + id = msg.UID } else { id = uint32(i + 1) } @@ -215,7 +215,7 @@ func (mbox *Mailbox) CopyMessages(uid bool, seqset *imap.SeqSet, destName string } msgCopy := *msg - msgCopy.Uid = dest.uidNext() + msgCopy.UID = dest.uidNext() dest.Messages = append(dest.Messages, &msgCopy) } diff --git a/backend/memory/message.go b/backend/memory/message.go index 58290589..02e9d8a2 100644 --- a/backend/memory/message.go +++ b/backend/memory/message.go @@ -13,7 +13,7 @@ import ( ) type Message struct { - Uid uint32 + UID uint32 Date time.Time Size uint32 Flags []string @@ -46,8 +46,8 @@ func (m *Message) Fetch(seqNum uint32, items []imap.FetchItem) (*imap.Message, e fetched.InternalDate = m.Date case imap.FetchRFC822Size: fetched.Size = m.Size - case imap.FetchUid: - fetched.Uid = m.Uid + case imap.FetchUID: + fetched.UID = m.UID default: section, err := imap.ParseBodySectionName(item) if err != nil { @@ -70,5 +70,5 @@ func (m *Message) Fetch(seqNum uint32, items []imap.FetchItem) (*imap.Message, e func (m *Message) Match(seqNum uint32, c *imap.SearchCriteria) (bool, error) { e, _ := m.entity() - return backendutil.Match(e, seqNum, m.Uid, m.Date, m.Flags, c) + return backendutil.Match(e, seqNum, m.UID, m.Date, m.Flags, c) } diff --git a/backend/memory/user.go b/backend/memory/user.go index 5a4d3761..2eef0f42 100644 --- a/backend/memory/user.go +++ b/backend/memory/user.go @@ -30,14 +30,14 @@ func (u *User) ListMailboxes(subscribed bool) (mailboxes []backend.Mailbox, err func (u *User) GetMailbox(name string) (mailbox backend.Mailbox, err error) { mailbox, ok := u.mailboxes[name] if !ok { - err = errors.New("No such mailbox") + err = errors.New("no such mailbox") } return } func (u *User) CreateMailbox(name string) error { if _, ok := u.mailboxes[name]; ok { - return errors.New("Mailbox already exists") + return errors.New("mailbox already exists") } u.mailboxes[name] = &Mailbox{name: name, user: u} @@ -46,10 +46,10 @@ func (u *User) CreateMailbox(name string) error { func (u *User) DeleteMailbox(name string) error { if name == "INBOX" { - return errors.New("Cannot delete INBOX") + return errors.New("cannot delete INBOX") } if _, ok := u.mailboxes[name]; !ok { - return errors.New("No such mailbox") + return errors.New("no such mailbox") } delete(u.mailboxes, name) @@ -59,7 +59,7 @@ func (u *User) DeleteMailbox(name string) error { func (u *User) RenameMailbox(existingName, newName string) error { mbox, ok := u.mailboxes[existingName] if !ok { - return errors.New("No such mailbox") + return errors.New("no such mailbox") } u.mailboxes[newName] = &Mailbox{ diff --git a/backend/updates.go b/backend/updates.go index 1c87573e..ba10f884 100644 --- a/backend/updates.go +++ b/backend/updates.go @@ -72,14 +72,14 @@ type ExpungeUpdate struct { SeqNum uint32 } -// BackendUpdater is a Backend that implements Updater is able to send +// Updater is a Backend that implements Updater is able to send // unilateral backend updates. Backends not implementing this interface don't // correctly send unilateral updates, for instance if a user logs in from two // connections and deletes a message from one of them, the over is not aware // that such a mesage has been deleted. More importantly, backends implementing // Updater can notify the user for external updates such as new message // notifications. -type BackendUpdater interface { +type Updater interface { // Updates returns a set of channels where updates are sent to. Updates() <-chan Update } diff --git a/backend/user.go b/backend/user.go index afcd0142..2b254589 100644 --- a/backend/user.go +++ b/backend/user.go @@ -6,10 +6,10 @@ var ( // ErrNoSuchMailbox is returned by User.GetMailbox, User.DeleteMailbox and // User.RenameMailbox when retrieving, deleting or renaming a mailbox that // doesn't exist. - ErrNoSuchMailbox = errors.New("No such mailbox") + ErrNoSuchMailbox = errors.New("no such mailbox") // ErrMailboxAlreadyExists is returned by User.CreateMailbox and // User.RenameMailbox when creating or renaming mailbox that already exists. - ErrMailboxAlreadyExists = errors.New("Mailbox already exists") + ErrMailboxAlreadyExists = errors.New("mailbox already exists") ) // User represents a user in the mail storage system. A user operation always diff --git a/client/client.go b/client/client.go index 8e53579c..46dce107 100644 --- a/client/client.go +++ b/client/client.go @@ -218,7 +218,7 @@ func (c *Client) execute(cmdr imap.Commander, h responses.Handler) (*imap.Status c.registerHandler(responses.HandlerFunc(func(resp imap.Resp) error { select { case <-unregister: - // If an error occured while sending the command, abort + // If an error occurred while sending the command, abort return errUnregisterHandler default: } @@ -566,7 +566,6 @@ func (c *Client) SetDebug(w io.Writer) { if err != nil { log.Println("SetDebug:", err) } - } // New creates a new client from an existing connection. diff --git a/client/cmd_any.go b/client/cmd_any.go index 3268052b..54e65f0a 100644 --- a/client/cmd_any.go +++ b/client/cmd_any.go @@ -9,7 +9,7 @@ import ( // ErrAlreadyLoggedOut is returned if Logout is called when the client is // already logged out. -var ErrAlreadyLoggedOut = errors.New("Already logged out") +var ErrAlreadyLoggedOut = errors.New("already logged out") // Capability requests a listing of capabilities that the server supports. // Capabilities are often returned by the server with the greeting or with the diff --git a/client/cmd_auth.go b/client/cmd_auth.go index 62e4d018..554c377c 100644 --- a/client/cmd_auth.go +++ b/client/cmd_auth.go @@ -11,7 +11,7 @@ import ( // ErrNotLoggedIn is returned if a function that requires the client to be // logged in is called then the client isn't. -var ErrNotLoggedIn = errors.New("Not logged in") +var ErrNotLoggedIn = errors.New("not logged in") func (c *Client) ensureAuthenticated() error { state := c.State() diff --git a/client/cmd_auth_test.go b/client/cmd_auth_test.go index dd9953df..f396bb3d 100644 --- a/client/cmd_auth_test.go +++ b/client/cmd_auth_test.go @@ -50,8 +50,8 @@ func TestClient_Select(t *testing.T) { UnseenSeqNum: 12, Messages: 172, Recent: 1, - UidNext: 4392, - UidValidity: 3857529045, + UIDNext: 4392, + UIDValidity: 3857529045, } mbox.Items = nil if !reflect.DeepEqual(mbox, want) { diff --git a/client/cmd_noauth.go b/client/cmd_noauth.go index f9b34d3e..c8e5c237 100644 --- a/client/cmd_noauth.go +++ b/client/cmd_noauth.go @@ -14,14 +14,14 @@ import ( var ( // ErrAlreadyLoggedIn is returned if Login or Authenticate is called when the // client is already logged in. - ErrAlreadyLoggedIn = errors.New("Already logged in") + ErrAlreadyLoggedIn = errors.New("already logged in") // ErrTLSAlreadyEnabled is returned if StartTLS is called when TLS is already // enabled. ErrTLSAlreadyEnabled = errors.New("TLS is already enabled") // ErrLoginDisabled is returned if Login or Authenticate is called when the // server has disabled authentication. Most of the time, calling enabling TLS // solves the problem. - ErrLoginDisabled = errors.New("Login is disabled in current state") + ErrLoginDisabled = errors.New("login is disabled in current state") ) // SupportStartTLS checks if the server supports STARTTLS. diff --git a/client/cmd_selected.go b/client/cmd_selected.go index 0607247e..a41439f6 100644 --- a/client/cmd_selected.go +++ b/client/cmd_selected.go @@ -10,7 +10,7 @@ import ( // ErrNoMailboxSelected is returned if a command that requires a mailbox to be // selected is called when there isn't. -var ErrNoMailboxSelected = errors.New("No mailbox selected") +var ErrNoMailboxSelected = errors.New("no mailbox selected") // Check requests a checkpoint of the currently selected mailbox. A checkpoint // refers to any implementation-dependent housekeeping associated with the @@ -93,7 +93,7 @@ func (c *Client) executeSearch(uid bool, criteria *imap.SearchCriteria, charset Criteria: criteria, } if uid { - cmd = &commands.Uid{Cmd: cmd} + cmd = &commands.UID{Cmd: cmd} } res := new(responses.Search) @@ -127,9 +127,9 @@ func (c *Client) Search(criteria *imap.SearchCriteria) (seqNums []uint32, err er return c.search(false, criteria) } -// UidSearch is identical to Search, but UIDs are returned instead of message +// UIDSearch is identical to Search, but UIDs are returned instead of message // sequence numbers. -func (c *Client) UidSearch(criteria *imap.SearchCriteria) (uids []uint32, err error) { +func (c *Client) UIDSearch(criteria *imap.SearchCriteria) (uids []uint32, err error) { return c.search(true, criteria) } @@ -145,7 +145,7 @@ func (c *Client) fetch(uid bool, seqset *imap.SeqSet, items []imap.FetchItem, ch Items: items, } if uid { - cmd = &commands.Uid{Cmd: cmd} + cmd = &commands.UID{Cmd: cmd} } res := &responses.Fetch{Messages: ch} @@ -163,9 +163,9 @@ func (c *Client) Fetch(seqset *imap.SeqSet, items []imap.FetchItem, ch chan *ima return c.fetch(false, seqset, items, ch) } -// UidFetch is identical to Fetch, but seqset is interpreted as containing +// UIDFetch is identical to Fetch, but seqset is interpreted as containing // unique identifiers instead of message sequence numbers. -func (c *Client) UidFetch(seqset *imap.SeqSet, items []imap.FetchItem, ch chan *imap.Message) error { +func (c *Client) UIDFetch(seqset *imap.SeqSet, items []imap.FetchItem, ch chan *imap.Message) error { return c.fetch(true, seqset, items, ch) } @@ -198,7 +198,7 @@ func (c *Client) store(uid bool, seqset *imap.SeqSet, item imap.StoreItem, value Value: value, } if uid { - cmd = &commands.Uid{Cmd: cmd} + cmd = &commands.UID{Cmd: cmd} } var h responses.Handler @@ -221,9 +221,9 @@ func (c *Client) Store(seqset *imap.SeqSet, item imap.StoreItem, value interface return c.store(false, seqset, item, value, ch) } -// UidStore is identical to Store, but seqset is interpreted as containing +// UIDStore is identical to Store, but seqset is interpreted as containing // unique identifiers instead of message sequence numbers. -func (c *Client) UidStore(seqset *imap.SeqSet, item imap.StoreItem, value interface{}, ch chan *imap.Message) error { +func (c *Client) UIDStore(seqset *imap.SeqSet, item imap.StoreItem, value interface{}, ch chan *imap.Message) error { return c.store(true, seqset, item, value, ch) } @@ -237,7 +237,7 @@ func (c *Client) copy(uid bool, seqset *imap.SeqSet, dest string) error { Mailbox: dest, } if uid { - cmd = &commands.Uid{Cmd: cmd} + cmd = &commands.UID{Cmd: cmd} } status, err := c.execute(cmd, nil) @@ -253,8 +253,8 @@ func (c *Client) Copy(seqset *imap.SeqSet, dest string) error { return c.copy(false, seqset, dest) } -// UidCopy is identical to Copy, but seqset is interpreted as containing unique +// UIDCopy is identical to Copy, but seqset is interpreted as containing unique // identifiers instead of message sequence numbers. -func (c *Client) UidCopy(seqset *imap.SeqSet, dest string) error { +func (c *Client) UIDCopy(seqset *imap.SeqSet, dest string) error { return c.copy(true, seqset, dest) } diff --git a/client/cmd_selected_test.go b/client/cmd_selected_test.go index 47c1f135..ade9f00c 100644 --- a/client/cmd_selected_test.go +++ b/client/cmd_selected_test.go @@ -158,7 +158,7 @@ func TestClient_Search_Uid(t *testing.T) { var results []uint32 go func() { var err error - results, err = c.UidSearch(criteria) + results, err = c.UIDSearch(criteria) done <- err }() @@ -188,7 +188,7 @@ func TestClient_Fetch(t *testing.T) { setClientState(c, imap.SelectedState, nil) seqset, _ := imap.ParseSeqSet("2:3") - fields := []imap.FetchItem{imap.FetchUid, imap.FetchItem("BODY[]")} + fields := []imap.FetchItem{imap.FetchUID, imap.FetchItem("BODY[]")} done := make(chan error, 1) messages := make(chan *imap.Message, 2) @@ -221,8 +221,8 @@ func TestClient_Fetch(t *testing.T) { if msg.SeqNum != 2 { t.Errorf("First message has bad sequence number: %v", msg.SeqNum) } - if msg.Uid != 42 { - t.Errorf("First message has bad UID: %v", msg.Uid) + if msg.UID != 42 { + t.Errorf("First message has bad UID: %v", msg.UID) } if body, _ := ioutil.ReadAll(msg.GetBody(section)); string(body) != "I love potatoes." { t.Errorf("First message has bad body: %q", body) @@ -232,8 +232,8 @@ func TestClient_Fetch(t *testing.T) { if msg.SeqNum != 3 { t.Errorf("First message has bad sequence number: %v", msg.SeqNum) } - if msg.Uid != 28 { - t.Errorf("Second message has bad UID: %v", msg.Uid) + if msg.UID != 28 { + t.Errorf("Second message has bad UID: %v", msg.UID) } if body, _ := ioutil.ReadAll(msg.GetBody(section)); string(body) != "Hello World!" { t.Errorf("Second message has bad body: %q", body) @@ -247,7 +247,7 @@ func TestClient_Fetch_ClosedState(t *testing.T) { setClientState(c, imap.AuthenticatedState, nil) seqset, _ := imap.ParseSeqSet("2:3") - fields := []imap.FetchItem{imap.FetchUid, imap.FetchItem("BODY[]")} + fields := []imap.FetchItem{imap.FetchUID, imap.FetchItem("BODY[]")} done := make(chan error, 1) messages := make(chan *imap.Message, 2) @@ -351,7 +351,7 @@ func TestClient_Fetch_Uid(t *testing.T) { done := make(chan error, 1) messages := make(chan *imap.Message, 1) go func() { - done <- c.UidFetch(seqset, fields, messages) + done <- c.UIDFetch(seqset, fields, messages) }() tag, cmd := s.ScanCmd() @@ -363,15 +363,15 @@ func TestClient_Fetch_Uid(t *testing.T) { s.WriteString(tag + " OK UID FETCH completed\r\n") if err := <-done; err != nil { - t.Fatalf("c.UidFetch() = %v", err) + t.Fatalf("c.UIDFetch() = %v", err) } msg := <-messages if msg.SeqNum != 23 { t.Errorf("First message has bad sequence number: %v", msg.SeqNum) } - if msg.Uid != 42 { - t.Errorf("Message has bad UID: %v", msg.Uid) + if msg.UID != 42 { + t.Errorf("Message has bad UID: %v", msg.UID) } if len(msg.Flags) != 1 || msg.Flags[0] != "\\Seen" { t.Errorf("Message has bad flags: %v", msg.Flags) @@ -445,7 +445,7 @@ func TestClient_Store_Uid(t *testing.T) { done := make(chan error, 1) go func() { - done <- c.UidStore(seqset, imap.AddFlags, []interface{}{imap.DeletedFlag}, nil) + done <- c.UIDStore(seqset, imap.AddFlags, []interface{}{imap.DeletedFlag}, nil) }() tag, cmd := s.ScanCmd() @@ -456,7 +456,7 @@ func TestClient_Store_Uid(t *testing.T) { s.WriteString(tag + " OK STORE completed\r\n") if err := <-done; err != nil { - t.Fatalf("c.UidStore() = %v", err) + t.Fatalf("c.UIDStore() = %v", err) } } @@ -495,7 +495,7 @@ func TestClient_Copy_Uid(t *testing.T) { done := make(chan error, 1) go func() { - done <- c.UidCopy(seqset, "Drafts") + done <- c.UIDCopy(seqset, "Drafts") }() tag, cmd := s.ScanCmd() @@ -506,6 +506,6 @@ func TestClient_Copy_Uid(t *testing.T) { s.WriteString(tag + " OK UID COPY completed\r\n") if err := <-done; err != nil { - t.Fatalf("c.UidCopy() = %v", err) + t.Fatalf("c.UIDCopy() = %v", err) } } diff --git a/client/example_test.go b/client/example_test.go index 8da6bda5..69d296f9 100644 --- a/client/example_test.go +++ b/client/example_test.go @@ -58,7 +58,7 @@ func ExampleClient() { from := uint32(1) to := mbox.Messages if mbox.Messages > 3 { - // We're using unsigned integers here, only substract if the result is > 0 + // We're using unsigned integers here, only subtract if the result is > 0 from = mbox.Messages - 3 } seqset := new(imap.SeqSet) diff --git a/commands/append.go b/commands/append.go index d70b584e..b8f2cea0 100644 --- a/commands/append.go +++ b/commands/append.go @@ -44,7 +44,7 @@ func (cmd *Append) Command() *imap.Command { func (cmd *Append) Parse(fields []interface{}) (err error) { if len(fields) < 2 { - return errors.New("No enough arguments") + return errors.New("no enough arguments") } // Parse mailbox name @@ -60,7 +60,7 @@ func (cmd *Append) Parse(fields []interface{}) (err error) { litIndex := len(fields) - 1 var ok bool if cmd.Message, ok = fields[litIndex].(imap.Literal); !ok { - return errors.New("Message must be a literal") + return errors.New("message must be a literal") } // Remaining fields a optional @@ -82,7 +82,7 @@ func (cmd *Append) Parse(fields []interface{}) (err error) { // Parse date if len(fields) > 0 { if date, ok := fields[0].(string); !ok { - return errors.New("Date must be a string") + return errors.New("date must be a string") } else if cmd.Date, err = time.Parse(imap.DateTimeLayout, date); err != nil { return err } diff --git a/commands/authenticate.go b/commands/authenticate.go index ec39a41b..64319b4e 100644 --- a/commands/authenticate.go +++ b/commands/authenticate.go @@ -48,12 +48,12 @@ func (cmd *Authenticate) Command() *imap.Command { func (cmd *Authenticate) Parse(fields []interface{}) error { if len(fields) < 1 { - return errors.New("Not enough arguments") + return errors.New("not enough arguments") } var ok bool if cmd.Mechanism, ok = fields[0].(string); !ok { - return errors.New("Mechanism must be a string") + return errors.New("mechanism must be a string") } cmd.Mechanism = strings.ToUpper(cmd.Mechanism) @@ -63,7 +63,7 @@ func (cmd *Authenticate) Parse(fields []interface{}) error { encodedResponse, ok := fields[1].(string) if !ok { - return errors.New("Initial response must be a string") + return errors.New("initial response must be a string") } if encodedResponse == "=" { cmd.InitialResponse = []byte{} @@ -82,7 +82,7 @@ func (cmd *Authenticate) Parse(fields []interface{}) error { func (cmd *Authenticate) Handle(mechanisms map[string]sasl.Server, conn AuthenticateConn) error { sasl, ok := mechanisms[cmd.Mechanism] if !ok { - return errors.New("Unsupported mechanism") + return errors.New("unsupported mechanism") } scanner := bufio.NewScanner(conn) diff --git a/commands/copy.go b/commands/copy.go index 5258f35c..df89fc96 100644 --- a/commands/copy.go +++ b/commands/copy.go @@ -24,11 +24,11 @@ func (cmd *Copy) Command() *imap.Command { func (cmd *Copy) Parse(fields []interface{}) error { if len(fields) < 2 { - return errors.New("No enough arguments") + return errors.New("not enough arguments") } if seqSet, ok := fields[0].(string); !ok { - return errors.New("Invalid sequence set") + return errors.New("invalid sequence set") } else if seqSet, err := imap.ParseSeqSet(seqSet); err != nil { return err } else { diff --git a/commands/create.go b/commands/create.go index a1e6fe22..ac6e56a4 100644 --- a/commands/create.go +++ b/commands/create.go @@ -23,7 +23,7 @@ func (cmd *Create) Command() *imap.Command { func (cmd *Create) Parse(fields []interface{}) error { if len(fields) < 1 { - return errors.New("No enough arguments") + return errors.New("not enough arguments") } if mailbox, err := imap.ParseString(fields[0]); err != nil { diff --git a/commands/delete.go b/commands/delete.go index 60f4da8a..5500b336 100644 --- a/commands/delete.go +++ b/commands/delete.go @@ -23,7 +23,7 @@ func (cmd *Delete) Command() *imap.Command { func (cmd *Delete) Parse(fields []interface{}) error { if len(fields) < 1 { - return errors.New("No enough arguments") + return errors.New("not enough arguments") } if mailbox, err := imap.ParseString(fields[0]); err != nil { diff --git a/commands/fetch.go b/commands/fetch.go index cf45f755..5ca90697 100644 --- a/commands/fetch.go +++ b/commands/fetch.go @@ -27,12 +27,12 @@ func (cmd *Fetch) Command() *imap.Command { func (cmd *Fetch) Parse(fields []interface{}) error { if len(fields) < 2 { - return errors.New("No enough arguments") + return errors.New("not enough arguments") } var err error if seqset, ok := fields[0].(string); !ok { - return errors.New("Sequence set must be an atom") + return errors.New("sequence set must be an atom") } else if cmd.SeqSet, err = imap.ParseSeqSet(seqset); err != nil { return err } @@ -48,7 +48,7 @@ func (cmd *Fetch) Parse(fields []interface{}) error { cmd.Items = append(cmd.Items, item.Expand()...) } default: - return errors.New("Items must be either a string or a list") + return errors.New("items must be either a string or a list") } return nil diff --git a/commands/list.go b/commands/list.go index 52686e9e..f2d71b20 100644 --- a/commands/list.go +++ b/commands/list.go @@ -34,7 +34,7 @@ func (cmd *List) Command() *imap.Command { func (cmd *List) Parse(fields []interface{}) error { if len(fields) < 2 { - return errors.New("No enough arguments") + return errors.New("not enough arguments") } dec := utf7.Encoding.NewDecoder() diff --git a/commands/login.go b/commands/login.go index d0af0b50..8959b611 100644 --- a/commands/login.go +++ b/commands/login.go @@ -21,7 +21,7 @@ func (cmd *Login) Command() *imap.Command { func (cmd *Login) Parse(fields []interface{}) error { if len(fields) < 2 { - return errors.New("Not enough arguments") + return errors.New("not enough arguments") } var err error diff --git a/commands/rename.go b/commands/rename.go index 37a5fa7f..9a7863c0 100644 --- a/commands/rename.go +++ b/commands/rename.go @@ -26,7 +26,7 @@ func (cmd *Rename) Command() *imap.Command { func (cmd *Rename) Parse(fields []interface{}) error { if len(fields) < 2 { - return errors.New("No enough arguments") + return errors.New("not enough arguments") } dec := utf7.Encoding.NewDecoder() diff --git a/commands/search.go b/commands/search.go index 72f026c6..3807f680 100644 --- a/commands/search.go +++ b/commands/search.go @@ -29,16 +29,16 @@ func (cmd *Search) Command() *imap.Command { func (cmd *Search) Parse(fields []interface{}) error { if len(fields) == 0 { - return errors.New("Missing search criteria") + return errors.New("missing search criteria") } // Parse charset if f, ok := fields[0].(string); ok && strings.EqualFold(f, "CHARSET") { if len(fields) < 2 { - return errors.New("Missing CHARSET value") + return errors.New("missing CHARSET value") } if cmd.Charset, ok = fields[1].(string); !ok { - return errors.New("Charset must be a string") + return errors.New("charset must be a string") } fields = fields[2:] } diff --git a/commands/select.go b/commands/select.go index e881effe..41ebbefd 100644 --- a/commands/select.go +++ b/commands/select.go @@ -30,7 +30,7 @@ func (cmd *Select) Command() *imap.Command { func (cmd *Select) Parse(fields []interface{}) error { if len(fields) < 1 { - return errors.New("No enough arguments") + return errors.New("not enough arguments") } if mailbox, err := imap.ParseString(fields[0]); err != nil { diff --git a/commands/status.go b/commands/status.go index 672dce5c..14c03c76 100644 --- a/commands/status.go +++ b/commands/status.go @@ -30,7 +30,7 @@ func (cmd *Status) Command() *imap.Command { func (cmd *Status) Parse(fields []interface{}) error { if len(fields) < 2 { - return errors.New("No enough arguments") + return errors.New("not enough arguments") } if mailbox, err := imap.ParseString(fields[0]); err != nil { @@ -48,7 +48,7 @@ func (cmd *Status) Parse(fields []interface{}) error { cmd.Items = make([]imap.StatusItem, len(items)) for i, f := range items { if s, ok := f.(string); !ok { - return errors.New("Got a non-string field in a STATUS command parameter") + return errors.New("got a non-string field in a STATUS command parameter") } else { cmd.Items[i] = imap.StatusItem(strings.ToUpper(s)) } diff --git a/commands/store.go b/commands/store.go index aeee3e62..4912e7e5 100644 --- a/commands/store.go +++ b/commands/store.go @@ -23,12 +23,12 @@ func (cmd *Store) Command() *imap.Command { func (cmd *Store) Parse(fields []interface{}) error { if len(fields) < 3 { - return errors.New("No enough arguments") + return errors.New("not enough arguments") } seqset, ok := fields[0].(string) if !ok { - return errors.New("Invalid sequence set") + return errors.New("invalid sequence set") } var err error if cmd.SeqSet, err = imap.ParseSeqSet(seqset); err != nil { @@ -36,7 +36,7 @@ func (cmd *Store) Parse(fields []interface{}) error { } if item, ok := fields[1].(string); !ok { - return errors.New("Item name must be a string") + return errors.New("item name must be a string") } else { cmd.Item = imap.StoreItem(strings.ToUpper(item)) } diff --git a/commands/subscribe.go b/commands/subscribe.go index 6540969c..53b9daef 100644 --- a/commands/subscribe.go +++ b/commands/subscribe.go @@ -23,7 +23,7 @@ func (cmd *Subscribe) Command() *imap.Command { func (cmd *Subscribe) Parse(fields []interface{}) error { if len(fields) < 0 { - return errors.New("No enough arguments") + return errors.New("not enough arguments") } if mailbox, err := imap.ParseString(fields[0]); err != nil { @@ -51,7 +51,7 @@ func (cmd *Unsubscribe) Command() *imap.Command { func (cmd *Unsubscribe) Parse(fields []interface{}) error { if len(fields) < 0 { - return errors.New("No enogh arguments") + return errors.New("not enough arguments") } if mailbox, err := imap.ParseString(fields[0]); err != nil { diff --git a/commands/uid.go b/commands/uid.go index 979af144..8b60ae3f 100644 --- a/commands/uid.go +++ b/commands/uid.go @@ -7,13 +7,13 @@ import ( "github.com/emersion/go-imap" ) -// Uid is a UID command, as defined in RFC 3501 section 6.4.8. It wraps another +// UID is a UID command, as defined in RFC 3501 section 6.4.8. It wraps another // command (e.g. wrapping a Fetch command will result in a UID FETCH). -type Uid struct { +type UID struct { Cmd imap.Commander } -func (cmd *Uid) Command() *imap.Command { +func (cmd *UID) Command() *imap.Command { inner := cmd.Cmd.Command() args := []interface{}{imap.RawString(inner.Name)} @@ -25,14 +25,14 @@ func (cmd *Uid) Command() *imap.Command { } } -func (cmd *Uid) Parse(fields []interface{}) error { +func (cmd *UID) Parse(fields []interface{}) error { if len(fields) < 0 { - return errors.New("No command name specified") + return errors.New("no command name specified") } name, ok := fields[0].(string) if !ok { - return errors.New("Command name must be a string") + return errors.New("command name must be a string") } cmd.Cmd = &imap.Command{ diff --git a/go.mod b/go.mod index 19859a28..662f702a 100644 --- a/go.mod +++ b/go.mod @@ -1,7 +1,10 @@ module github.com/emersion/go-imap require ( + github.com/alexkohler/prealloc v0.0.0-20181002111628-4fce4887dad9 // indirect github.com/emersion/go-message v0.10.4-0.20190609165112-592ace5bc1ca github.com/emersion/go-sasl v0.0.0-20190520160400-47d427600317 golang.org/x/text v0.3.2 ) + +go 1.13 diff --git a/go.sum b/go.sum index c88e801e..494f4786 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,5 @@ +github.com/alexkohler/prealloc v0.0.0-20181002111628-4fce4887dad9 h1:31kqHz4wQqRjuSSD66Nwb8QeNxA1Fr7PL7yGtCRoMhk= +github.com/alexkohler/prealloc v0.0.0-20181002111628-4fce4887dad9/go.mod h1:CmbNRwpsIT6OOr1myakD2xc96sG7MWgs2VePr8EjW58= github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/emersion/go-message v0.10.4-0.20190609165112-592ace5bc1ca h1:OYhqtJI4eOLvGtRIsUfP87VMJ1J/o6ks1tah9DlYkn4= diff --git a/imap.go b/imap.go index 37681f1d..4a24711a 100644 --- a/imap.go +++ b/imap.go @@ -14,8 +14,8 @@ type StatusItem string const ( StatusMessages StatusItem = "MESSAGES" StatusRecent StatusItem = "RECENT" - StatusUidNext StatusItem = "UIDNEXT" - StatusUidValidity StatusItem = "UIDVALIDITY" + StatusUIDNext StatusItem = "UIDNEXT" + StatusUIDValidity StatusItem = "UIDVALIDITY" StatusUnseen StatusItem = "UNSEEN" ) @@ -39,7 +39,7 @@ const ( FetchRFC822Header FetchItem = "RFC822.HEADER" FetchRFC822Size FetchItem = "RFC822.SIZE" FetchRFC822Text FetchItem = "RFC822.TEXT" - FetchUid FetchItem = "UID" + FetchUID FetchItem = "UID" ) // Expand expands the item if it's a macro. @@ -94,7 +94,7 @@ func ParseFlagsOp(item StoreItem) (op FlagsOp, silent bool, err error) { op = FlagsOp(itemStr) if op != SetFlags && op != AddFlags && op != RemoveFlags { - err = errors.New("Unsupported STORE operation") + err = errors.New("unsupported STORE operation") } return } diff --git a/mailbox.go b/mailbox.go index 2371bdcf..315086c4 100644 --- a/mailbox.go +++ b/mailbox.go @@ -51,7 +51,7 @@ type MailboxInfo struct { // Parse mailbox info from fields. func (info *MailboxInfo) Parse(fields []interface{}) error { if len(fields) < 3 { - return errors.New("Mailbox info needs at least 3 fields") + return errors.New("mailbox info needs at least 3 fields") } var err error @@ -61,7 +61,7 @@ func (info *MailboxInfo) Parse(fields []interface{}) error { var ok bool if info.Delimiter, ok = fields[1].(string); !ok { - return errors.New("Mailbox delimiter must be a string") + return errors.New("mailbox delimiter must be a string") } if name, err := ParseString(fields[2]); err != nil { @@ -169,10 +169,10 @@ type MailboxStatus struct { // The number of unread messages. Unseen uint32 // The next UID. - UidNext uint32 + UIDNext uint32 // Together with a UID, it is a unique identifier for a message. // Must be greater than or equal to 1. - UidValidity uint32 + UIDValidity uint32 } // Create a new mailbox status that will contain the specified items. @@ -211,10 +211,10 @@ func (status *MailboxStatus) Parse(fields []interface{}) error { status.Recent, err = ParseNumber(f) case StatusUnseen: status.Unseen, err = ParseNumber(f) - case StatusUidNext: - status.UidNext, err = ParseNumber(f) - case StatusUidValidity: - status.UidValidity, err = ParseNumber(f) + case StatusUIDNext: + status.UIDNext, err = ParseNumber(f) + case StatusUIDValidity: + status.UIDValidity, err = ParseNumber(f) default: status.Items[k] = f } @@ -238,10 +238,10 @@ func (status *MailboxStatus) Format() []interface{} { v = status.Recent case StatusUnseen: v = status.Unseen - case StatusUidNext: - v = status.UidNext - case StatusUidValidity: - v = status.UidValidity + case StatusUIDNext: + v = status.UIDNext + case StatusUIDValidity: + v = status.UIDValidity } fields = append(fields, RawString(k), v) diff --git a/mailbox_test.go b/mailbox_test.go index 5d5eb70d..19e67673 100644 --- a/mailbox_test.go +++ b/mailbox_test.go @@ -140,14 +140,14 @@ var mailboxStatusTests = [...]struct { imap.StatusMessages: nil, imap.StatusRecent: nil, imap.StatusUnseen: nil, - imap.StatusUidNext: nil, - imap.StatusUidValidity: nil, + imap.StatusUIDNext: nil, + imap.StatusUIDValidity: nil, }, Messages: 42, Recent: 1, Unseen: 6, - UidNext: 65536, - UidValidity: 4242, + UIDNext: 65536, + UIDValidity: 4242, }, }, } diff --git a/message.go b/message.go index 7a001415..1b6b8bc3 100644 --- a/message.go +++ b/message.go @@ -68,7 +68,7 @@ func ParseParamList(fields []interface{}) (map[string]string, error) { for i, f := range fields { p, err := ParseString(f) if err != nil { - return nil, errors.New("Parameter list contains a non-string: " + err.Error()) + return nil, errors.New("parameter list contains a non-string: " + err.Error()) } if i%2 == 0 { @@ -80,7 +80,7 @@ func ParseParamList(fields []interface{}) (map[string]string, error) { } if k != "" { - return nil, errors.New("Parameter list contains a key without a value") + return nil, errors.New("parameter list contains a key without a value") } return params, nil } @@ -154,7 +154,7 @@ type Message struct { // The message size. Size uint32 // The message unique identifier. It must be greater than or equal to 1. - Uid uint32 + UID uint32 // The message body sections. Body map[*BodySectionName]Literal @@ -238,8 +238,8 @@ func (m *Message) Parse(fields []interface{}) error { m.InternalDate, _ = time.Parse(DateTimeLayout, date) case FetchRFC822Size: m.Size, _ = ParseNumber(f) - case FetchUid: - m.Uid, _ = ParseNumber(f) + case FetchUID: + m.UID, _ = ParseNumber(f) default: // Likely to be a section of the body // First check that the section name is correct @@ -277,8 +277,8 @@ func (m *Message) formatItem(k FetchItem) []interface{} { v = m.InternalDate case FetchRFC822Size: v = m.Size - case FetchUid: - v = m.Uid + case FetchUID: + v = m.UID default: for section, literal := range m.Body { if section.value == k { @@ -357,12 +357,12 @@ func (section *BodySectionName) parse(s string) error { partStart := strings.Index(s, "[") if partStart == -1 { - return errors.New("Invalid body section name: must contain an open bracket") + return errors.New("invalid body section name: must contain an open bracket") } partEnd := strings.LastIndex(s, "]") if partEnd == -1 { - return errors.New("Invalid body section name: must contain a close bracket") + return errors.New("invalid body section name: must contain a close bracket") } name := s[:partStart] @@ -372,7 +372,7 @@ func (section *BodySectionName) parse(s string) error { if name == "BODY.PEEK" { section.Peek = true } else if name != "BODY" { - return errors.New("Invalid body section name") + return errors.New("invalid body section name") } b := bytes.NewBufferString(part + string(cr) + string(lf)) @@ -388,7 +388,7 @@ func (section *BodySectionName) parse(s string) error { if len(partial) > 0 { if !strings.HasPrefix(partial, "<") || !strings.HasSuffix(partial, ">") { - return errors.New("Invalid body section name: invalid partial") + return errors.New("invalid body section name: invalid partial") } partial = partial[1 : len(partial)-1] @@ -396,13 +396,13 @@ func (section *BodySectionName) parse(s string) error { var from, length int if from, err = strconv.Atoi(partialParts[0]); err != nil { - return errors.New("Invalid body section name: invalid partial: invalid from: " + err.Error()) + return errors.New("invalid body section name: invalid partial: invalid from: " + err.Error()) } section.Partial = []int{from} if len(partialParts) == 2 { if length, err = strconv.Atoi(partialParts[1]); err != nil { - return errors.New("Invalid body section name: invalid partial: invalid length: " + err.Error()) + return errors.New("invalid body section name: invalid partial: invalid length: " + err.Error()) } section.Partial = append(section.Partial, length) } @@ -513,7 +513,7 @@ func (part *BodyPartName) parse(fields []interface{}) error { name, ok := fields[0].(string) if !ok { - return errors.New("Invalid body section name: part name must be a string") + return errors.New("invalid body section name: part name must be a string") } args := fields[1:] @@ -535,7 +535,7 @@ loop: return errors.New("Invalid body part name: " + err.Error()) } if index <= 0 { - return errors.New("Invalid body part name: index <= 0") + return errors.New("invalid body part name: index <= 0") } part.Path = append(part.Path, index) @@ -549,7 +549,7 @@ loop: names, ok := args[0].([]interface{}) if !ok { - return errors.New("Invalid body part name: HEADER.FIELDS must have a list argument") + return errors.New("invalid body part name: HEADER.FIELDS must have a list argument") } for _, namei := range names { @@ -723,10 +723,10 @@ type Envelope struct { Cc []*Address // The Bcc header addresses. Bcc []*Address - // The In-Reply-To header. Contains the parent Message-Id. + // The In-Reply-To header. Contains the parent Message-ID. InReplyTo string - // The Message-Id header. - MessageId string + // The Message-ID header. + MessageID string } // Parse an envelope from fields. @@ -762,8 +762,8 @@ func (e *Envelope) Parse(fields []interface{}) error { if inReplyTo, ok := fields[8].(string); ok { e.InReplyTo = inReplyTo } - if msgId, ok := fields[9].(string); ok { - e.MessageId = msgId + if msgID, ok := fields[9].(string); ok { + e.MessageID = msgID } return nil @@ -781,7 +781,7 @@ func (e *Envelope) Format() (fields []interface{}) { FormatAddressList(e.Cc), FormatAddressList(e.Bcc), e.InReplyTo, - e.MessageId, + e.MessageID, } } @@ -797,8 +797,8 @@ type BodyStructure struct { // The MIME parameters. Params map[string]string - // The Content-Id header. - Id string + // The Content-ID header. + ID string // The Content-Description header. Description string // The Content-Encoding header. @@ -906,7 +906,7 @@ func (bs *BodyStructure) Parse(fields []interface{}) error { } case string: // A non-multipart body part if len(fields) < 7 { - return errors.New("Non-multipart body part doesn't have 7 fields") + return errors.New("non-multipart body part doesn't have 7 fields") } bs.MIMEType, _ = fields[0].(string) @@ -915,7 +915,7 @@ func (bs *BodyStructure) Parse(fields []interface{}) error { params, _ := fields[2].([]interface{}) bs.Params, _ = parseHeaderParamList(params) - bs.Id, _ = fields[3].(string) + bs.ID, _ = fields[3].(string) if desc, err := ParseString(fields[4]); err == nil { bs.Description, _ = decodeHeader(desc) } @@ -927,7 +927,7 @@ func (bs *BodyStructure) Parse(fields []interface{}) error { // Type-specific fields if strings.EqualFold(bs.MIMEType, "message") && strings.EqualFold(bs.MIMESubType, "rfc822") { if len(fields)-end < 3 { - return errors.New("Missing type-specific fields for message/rfc822") + return errors.New("missing type-specific fields for message/rfc822") } envelope, _ := fields[end].([]interface{}) @@ -944,7 +944,7 @@ func (bs *BodyStructure) Parse(fields []interface{}) error { } if strings.EqualFold(bs.MIMEType, "text") { if len(fields)-end < 1 { - return errors.New("Missing type-specific fields for text/*") + return errors.New("missing type-specific fields for text/*") } bs.Lines, _ = ParseNumber(fields[end]) @@ -1026,8 +1026,8 @@ func (bs *BodyStructure) Format() (fields []interface{}) { fields[1] = bs.MIMESubType fields[2] = formatHeaderParamList(bs.Params) - if bs.Id != "" { - fields[3] = bs.Id + if bs.ID != "" { + fields[3] = bs.ID } if bs.Description != "" { fields[4] = encodeHeader(bs.Description) diff --git a/message_test.go b/message_test.go index 71646e40..5e0d2f9d 100644 --- a/message_test.go +++ b/message_test.go @@ -55,15 +55,15 @@ var messageTests = []struct { FetchBody: nil, FetchFlags: nil, FetchRFC822Size: nil, - FetchUid: nil, + FetchUID: nil, }, Body: map[*BodySectionName]Literal{}, Envelope: envelopeTests[0].envelope, BodyStructure: bodyStructureTests[0].bodyStructure, Flags: []string{SeenFlag, AnsweredFlag}, Size: 4242, - Uid: 2424, - itemsOrder: []FetchItem{FetchEnvelope, FetchBody, FetchFlags, FetchRFC822Size, FetchUid}, + UID: 2424, + itemsOrder: []FetchItem{FetchEnvelope, FetchBody, FetchFlags, FetchRFC822Size, FetchUID}, }, fields: []interface{}{ RawString("ENVELOPE"), envelopeTests[0].fields, @@ -165,8 +165,8 @@ var bodySectionNameTests = []struct { parsed: &BodySectionName{BodyPartName: BodyPartName{Specifier: HeaderSpecifier, Fields: []string{"From", "To"}}}, }, { - raw: "BODY[HEADER.FIELDS.NOT (Content-Id)]", - parsed: &BodySectionName{BodyPartName: BodyPartName{Specifier: HeaderSpecifier, Fields: []string{"Content-Id"}, NotFields: true}}, + raw: "BODY[HEADER.FIELDS.NOT (Content-ID)]", + parsed: &BodySectionName{BodyPartName: BodyPartName{Specifier: HeaderSpecifier, Fields: []string{"Content-ID"}, NotFields: true}}, }, } @@ -267,7 +267,7 @@ var envelopeTests = []struct { Cc: []*Address{}, Bcc: []*Address{}, InReplyTo: "42@example.org", - MessageId: "43@example.org", + MessageID: "43@example.org", }, fields: []interface{}{ "Tue, 10 Nov 2009 23:00:00 -0600", @@ -447,7 +447,7 @@ var bodyStructureTests = []struct { MIMEType: "image", MIMESubType: "jpeg", Params: map[string]string{}, - Id: "", + ID: "", Description: "A picture of cat", Encoding: "base64", Size: 4242, diff --git a/read.go b/read.go index 135b5aaf..70d35e61 100644 --- a/read.go +++ b/read.go @@ -79,7 +79,7 @@ func ParseNumber(f interface{}) (uint32, error) { return 0, newParseError("expected a number, got a non-atom") } - nbr, err := strconv.ParseUint(string(s), 10, 32) + nbr, err := strconv.ParseUint(s, 10, 32) if err != nil { return 0, &parseError{err} } diff --git a/response.go b/response.go index 611d03e6..bd37bcc8 100644 --- a/response.go +++ b/response.go @@ -122,7 +122,7 @@ func (r *DataResp) WriteTo(w *Writer) error { tag = RawString("*") } - fields := []interface{}{RawString(tag)} + fields := []interface{}{tag} fields = append(fields, r.Fields...) return w.writeLine(fields...) } diff --git a/responses/list.go b/responses/list.go index e080fc16..f6d09855 100644 --- a/responses/list.go +++ b/responses/list.go @@ -20,9 +20,8 @@ type List struct { func (r *List) Name() string { if r.Subscribed { return lsubName - } else { - return listName } + return listName } func (r *List) Handle(resp imap.Resp) error { diff --git a/responses/select.go b/responses/select.go index e450963b..3bdf5d96 100644 --- a/responses/select.go +++ b/responses/select.go @@ -41,11 +41,11 @@ func (r *Select) Handle(resp imap.Resp) error { flags, _ := resp.Arguments[0].([]interface{}) mbox.PermanentFlags, _ = imap.ParseStringList(flags) case "UIDNEXT": - mbox.UidNext, _ = imap.ParseNumber(resp.Arguments[0]) - item = imap.StatusUidNext + mbox.UIDNext, _ = imap.ParseNumber(resp.Arguments[0]) + item = imap.StatusUIDNext case "UIDVALIDITY": - mbox.UidValidity, _ = imap.ParseNumber(resp.Arguments[0]) - item = imap.StatusUidValidity + mbox.UIDValidity, _ = imap.ParseNumber(resp.Arguments[0]) + item = imap.StatusUIDValidity default: return ErrUnhandled } @@ -115,21 +115,21 @@ func (r *Select) WriteTo(w *imap.Writer) error { if err := res.WriteTo(w); err != nil { return err } - case imap.StatusUidNext: + case imap.StatusUIDNext: statusRes := &imap.StatusResp{ Type: imap.StatusRespOk, - Code: imap.CodeUidNext, - Arguments: []interface{}{mbox.UidNext}, + Code: imap.CodeUIDNext, + Arguments: []interface{}{mbox.UIDNext}, Info: "Predicted next UID", } if err := statusRes.WriteTo(w); err != nil { return err } - case imap.StatusUidValidity: + case imap.StatusUIDValidity: statusRes := &imap.StatusResp{ Type: imap.StatusRespOk, - Code: imap.CodeUidValidity, - Arguments: []interface{}{mbox.UidValidity}, + Code: imap.CodeUIDValidity, + Arguments: []interface{}{mbox.UIDValidity}, Info: "UIDs valid", } if err := statusRes.WriteTo(w); err != nil { diff --git a/search.go b/search.go index 14d3f65b..9851f372 100644 --- a/search.go +++ b/search.go @@ -60,7 +60,7 @@ func popSearchField(fields []interface{}) (interface{}, []interface{}, error) { // only if it matches each one of its fields. type SearchCriteria struct { SeqNum *SeqSet // Sequence number is in sequence set - Uid *SeqSet // UID is in sequence set + UID *SeqSet // UID is in sequence set // Time and timezone are ignored Since time.Time // Internal date is since this date @@ -237,7 +237,7 @@ func (c *SearchCriteria) parseField(fields []interface{}, charsetReader func(io. case "UID": if f, fields, err = popSearchField(fields); err != nil { return nil, err - } else if c.Uid, err = ParseSeqSet(maybeString(f)); err != nil { + } else if c.UID, err = ParseSeqSet(maybeString(f)); err != nil { return nil, err } case "UNANSWERED", "UNDELETED", "UNDRAFT", "UNFLAGGED", "UNSEEN": @@ -278,8 +278,8 @@ func (c *SearchCriteria) Format() []interface{} { if c.SeqNum != nil { fields = append(fields, c.SeqNum) } - if c.Uid != nil { - fields = append(fields, RawString("UID"), c.Uid) + if c.UID != nil { + fields = append(fields, RawString("UID"), c.UID) } if !c.Since.IsZero() && !c.Before.IsZero() && c.Before.Sub(c.Since) == 24*time.Hour { diff --git a/search_test.go b/search_test.go index 6d1af813..bd381fcb 100644 --- a/search_test.go +++ b/search_test.go @@ -31,7 +31,7 @@ var searchCriteriaTests = []struct { `OR (ON "5-Nov-1984" DRAFT FLAGGED UNANSWERED UNDELETED OLD) (UNDRAFT UNFLAGGED UNSEEN))`, criteria: &SearchCriteria{ SeqNum: searchSeqSet1, - Uid: searchSeqSet2, + UID: searchSeqSet2, Since: searchDate2, Before: searchDate1, SentSince: searchDate2, diff --git a/seqset.go b/seqset.go index abe6afc1..f6451694 100644 --- a/seqset.go +++ b/seqset.go @@ -150,11 +150,11 @@ func (s *SeqSet) AddNum(q ...uint32) { } // AddRange inserts a new sequence range into the set. -func (s *SeqSet) AddRange(Start, Stop uint32) { - if (Stop < Start && Stop != 0) || Start == 0 { - s.insert(Seq{Stop, Start}) +func (s *SeqSet) AddRange(start, stop uint32) { + if (stop < start && stop != 0) || start == 0 { + s.insert(Seq{stop, start}) } else { - s.insert(Seq{Start, Stop}) + s.insert(Seq{start, stop}) } } @@ -252,15 +252,15 @@ func (s *SeqSet) insert(v Seq) { // insertAt inserts a new sequence value v at index i, resizing s.Set as needed. func (s *SeqSet) insertAt(i int, v Seq) { - if n := len(s.Set); i == n { + n := len(s.Set) + switch { + case i == n: // insert at the end s.Set = append(s.Set, v) - return - } else if n < cap(s.Set) { - // enough space, shift everything at and after i to the right + case n < cap(s.Set): s.Set = s.Set[:n+1] copy(s.Set[i+1:], s.Set[i:]) - } else { + default: // allocate new slice and copy everything, n is at least 1 set := make([]Seq, n+1, n*2) copy(set, s.Set[:i]) diff --git a/seqset_test.go b/seqset_test.go index 4762bb34..807e974e 100644 --- a/seqset_test.go +++ b/seqset_test.go @@ -350,13 +350,13 @@ func TestSeqMerge(T *testing.T) { T.Errorf("parseSeq(%q) unexpected error; %v", test.t, err) continue } - test_ok := test.out != "" + testOK := test.out != "" for i := 0; i < 2; i++ { - if !test_ok { + if !testOK { test.out = test.s } out, ok := s.Merge(t) - if out.String() != test.out || ok != test_ok { + if out.String() != test.out || ok != testOK { T.Errorf("%q.Merge(%q) expected %q; got %q", test.s, test.t, test.out, out) } // Swap s & t, result should be identical @@ -539,13 +539,13 @@ func TestSeqSetInfo(t *testing.T) { if str := s.String(); str != test.s { t.Errorf("%q.String() expected %q; got %q", test.s, test.s, str) } - test_empty := len(test.s) == 0 - if s.Empty() != test_empty { - t.Errorf("%q.Empty() expected %v", test.s, test_empty) + testEmpty := len(test.s) == 0 + if s.Empty() != testEmpty { + t.Errorf("%q.Empty() expected %v", test.s, testEmpty) } - test_dynamic := !test_empty && test.s[len(test.s)-1] == '*' - if s.Dynamic() != test_dynamic { - t.Errorf("%q.Dynamic() expected %v", test.s, test_dynamic) + testDynamic := !testEmpty && test.s[len(test.s)-1] == '*' + if s.Dynamic() != testDynamic { + t.Errorf("%q.Dynamic() expected %v", test.s, testDynamic) } } } diff --git a/server/cmd_auth.go b/server/cmd_auth.go index ce25f7f7..d702b741 100644 --- a/server/cmd_auth.go +++ b/server/cmd_auth.go @@ -11,7 +11,7 @@ import ( // imap errors in Authenticated state. var ( - ErrNotAuthenticated = errors.New("Not authenticated") + ErrNotAuthenticated = errors.New("not authenticated") ) type Select struct { @@ -31,7 +31,7 @@ func (cmd *Select) Handle(conn Conn) error { items := []imap.StatusItem{ imap.StatusMessages, imap.StatusRecent, imap.StatusUnseen, - imap.StatusUidNext, imap.StatusUidValidity, + imap.StatusUIDNext, imap.StatusUIDValidity, } status, err := mbox.Status(items) diff --git a/server/cmd_noauth.go b/server/cmd_noauth.go index ac221cc7..44c63f02 100644 --- a/server/cmd_noauth.go +++ b/server/cmd_noauth.go @@ -12,8 +12,8 @@ import ( // IMAP errors in Not Authenticated state. var ( - ErrAlreadyAuthenticated = errors.New("Already authenticated") - ErrAuthDisabled = errors.New("Authentication disabled") + ErrAlreadyAuthenticated = errors.New("already authenticated") + ErrAuthDisabled = errors.New("authentication disabled") ) type StartTLS struct { diff --git a/server/cmd_selected.go b/server/cmd_selected.go index f57623bd..0af3f3d5 100644 --- a/server/cmd_selected.go +++ b/server/cmd_selected.go @@ -10,16 +10,16 @@ import ( // imap errors in Selected state. var ( - ErrNoMailboxSelected = errors.New("No mailbox selected") - ErrMailboxReadOnly = errors.New("Mailbox opened in read-only mode") + ErrNoMailboxSelected = errors.New("no mailbox selected") + ErrMailboxReadOnly = errors.New("mailbox opened in read-only mode") ) // A command handler that supports UIDs. -type UidHandler interface { +type UIDHandler interface { Handler // Handle this command using UIDs for a given connection. - UidHandle(conn Conn) error + UIDhandle(conn Conn) error } type Check struct { @@ -138,7 +138,7 @@ func (cmd *Search) Handle(conn Conn) error { return cmd.handle(false, conn) } -func (cmd *Search) UidHandle(conn Conn) error { +func (cmd *Search) UIDhandle(conn Conn) error { return cmd.handle(true, conn) } @@ -172,16 +172,16 @@ func (cmd *Fetch) Handle(conn Conn) error { return cmd.handle(false, conn) } -func (cmd *Fetch) UidHandle(conn Conn) error { +func (cmd *Fetch) UIDhandle(conn Conn) error { // Append UID to the list of requested items if it isn't already present - hasUid := false + hasUID := false for _, item := range cmd.Items { if item == "UID" { - hasUid = true + hasUID = true break } } - if !hasUid { + if !hasUID { cmd.Items = append(cmd.Items, "UID") } @@ -209,7 +209,7 @@ func (cmd *Store) handle(uid bool, conn Conn) error { flagsList, ok := cmd.Value.([]interface{}) if !ok { - return errors.New("Flags must be a list") + return errors.New("flags must be a list") } flags, err := imap.ParseStringList(flagsList) if err != nil { @@ -251,7 +251,7 @@ func (cmd *Store) Handle(conn Conn) error { return cmd.handle(false, conn) } -func (cmd *Store) UidHandle(conn Conn) error { +func (cmd *Store) UIDhandle(conn Conn) error { return cmd.handle(true, conn) } @@ -272,27 +272,27 @@ func (cmd *Copy) Handle(conn Conn) error { return cmd.handle(false, conn) } -func (cmd *Copy) UidHandle(conn Conn) error { +func (cmd *Copy) UIDhandle(conn Conn) error { return cmd.handle(true, conn) } -type Uid struct { - commands.Uid +type UID struct { + commands.UID } -func (cmd *Uid) Handle(conn Conn) error { +func (cmd *UID) Handle(conn Conn) error { inner := cmd.Cmd.Command() hdlr, err := conn.commandHandler(inner) if err != nil { return err } - uidHdlr, ok := hdlr.(UidHandler) + uidHdlr, ok := hdlr.(UIDHandler) if !ok { - return errors.New("Command unsupported with UID") + return errors.New("command unsupported with UID") } - if err := uidHdlr.UidHandle(conn); err != nil { + if err := uidHdlr.UIDhandle(conn); err != nil { return err } diff --git a/server/conn.go b/server/conn.go index 7cad37b5..4456bef5 100644 --- a/server/conn.go +++ b/server/conn.go @@ -337,7 +337,6 @@ func (c *conn) serve(conn Conn) (err error) { } if res != nil { - if err := c.WriteResp(res); err != nil { c.s.ErrorLog.Println("cannot write response:", err) continue @@ -361,7 +360,7 @@ func (c *conn) WaitReady() { func (c *conn) commandHandler(cmd *imap.Command) (hdlr Handler, err error) { newHandler := c.s.Command(cmd.Name) if newHandler == nil { - err = errors.New("Unknown command") + err = errors.New("unknown command") return } diff --git a/server/server.go b/server/server.go index 25621de0..521aea20 100644 --- a/server/server.go +++ b/server/server.go @@ -136,7 +136,7 @@ func New(bkd backend.Backend) *Server { sasl.Plain: func(conn Conn) sasl.Server { return sasl.NewPlainServer(func(identity, username, password string) error { if identity != "" && identity != username { - return errors.New("Identities not supported") + return errors.New("identities not supported") } user, err := bkd.Login(conn.Info(), username, password) @@ -188,7 +188,7 @@ func New(bkd backend.Backend) *Server { "FETCH": func() Handler { return &Fetch{} }, "STORE": func() Handler { return &Store{} }, "COPY": func() Handler { return &Copy{} }, - "UID": func() Handler { return &Uid{} }, + "UID": func() Handler { return &UID{} }, } return s @@ -207,7 +207,7 @@ func (s *Server) Serve(l net.Listener) error { delete(s.listeners, l) }() - updater, ok := s.Backend.(backend.BackendUpdater) + updater, ok := s.Backend.(backend.Updater) if ok { s.Updates = updater.Updates() go s.listenUpdates() diff --git a/status.go b/status.go index 86a95b78..12fe76b3 100644 --- a/status.go +++ b/status.go @@ -51,8 +51,8 @@ const ( CodeReadOnly StatusRespCode = "READ-ONLY" CodeReadWrite StatusRespCode = "READ-WRITE" CodeTryCreate StatusRespCode = "TRYCREATE" - CodeUidNext StatusRespCode = "UIDNEXT" - CodeUidValidity StatusRespCode = "UIDVALIDITY" + CodeUIDNext StatusRespCode = "UIDNEXT" + CodeUIDValidity StatusRespCode = "UIDVALIDITY" CodeUnseen StatusRespCode = "UNSEEN" ) @@ -94,7 +94,7 @@ func (r *StatusResp) WriteTo(w *Writer) error { tag = "*" } - if err := w.writeFields([]interface{}{RawString(tag), RawString(r.Type)}); err != nil { + if err := w.writeFields([]interface{}{tag, RawString(r.Type)}); err != nil { return err } diff --git a/utf7/decoder.go b/utf7/decoder.go index 1c5f1c4f..617825ff 100644 --- a/utf7/decoder.go +++ b/utf7/decoder.go @@ -109,15 +109,17 @@ func decode(b64 []byte) []byte { // (if padding is required), UTF-16-BE bytes, and decoded UTF-8 bytes. // Since a 2-byte UTF-16 sequence may expand into a 3-byte UTF-8 sequence, // double the space allocation for UTF-8. - if n := len(b64); b64[n-1] == '=' { + n1 := len(b64) + switch { + case b64[n1-1] == '=': return nil - } else if n&3 == 0 { - b = make([]byte, b64Enc.DecodedLen(n)*3) - } else { - n += 4 - n&3 - b = make([]byte, n+b64Enc.DecodedLen(n)*3) - copy(b[copy(b, b64):n], []byte("==")) - b64, b = b[:n], b[n:] + case n1&3 == 0: + b = make([]byte, b64Enc.DecodedLen(n1)*3) + default: + n1 += 4 - n1&3 + b = make([]byte, n1+b64Enc.DecodedLen(n1)*3) + copy(b[copy(b, b64):n1], []byte("==")) + b64, b = b[:n1], b[n1:] } // Decode Base64 into the first 1/3rd of b diff --git a/write.go b/write.go index aa17deb9..e9394620 100644 --- a/write.go +++ b/write.go @@ -36,7 +36,7 @@ func FormatStringList(list []string) (fields []interface{}) { } // Check if a string is 8-bit clean. -func isAscii(s string) bool { +func isASCII(s string) bool { for _, c := range s { if c > unicode.MaxASCII || unicode.IsControl(c) { return false @@ -77,7 +77,7 @@ func (w *Writer) writeQuoted(s string) error { } func (w *Writer) writeQuotedOrLiteral(s string) error { - if !isAscii(s) { + if !isASCII(s) { // IMAP doesn't allow 8-bit data outside literals return w.writeLiteral(bytes.NewBufferString(s)) }