这是indexloc提供的服务,不要输入任何密码
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions backend/backendutil/backendutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 <mitsuha.miyamizu@example.org>\r\n" +
"Reply-To: Mitsuha Miyamizu <mitsuha.miyamizu+replyto@example.org>\r\n" +
"Message-Id: 42@example.org\r\n" +
"Message-ID: 42@example.org\r\n" +
"Subject: Your Name.\r\n" +
"To: Taki Tachibana <taki.tachibana@example.org>\r\n" +
"\r\n"
Expand All @@ -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 <mitsuha.miyamizu+replyto@example.org>\r\n" +
"Message-Id: 42@example.org\r\n" +
"Message-ID: 42@example.org\r\n" +
"Subject: Your Name.\r\n" +
"\r\n"

Expand Down
2 changes: 1 addition & 1 deletion backend/backendutil/body_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func TestFetchBodySection_NonMultipart(t *testing.T) {
testMsgHdr := "From: Mitsuha Miyamizu <mitsuha.miyamizu@example.org>\r\n" +
"To: Taki Tachibana <taki.tachibana@example.org>\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
Expand Down
2 changes: 1 addition & 1 deletion backend/backendutil/bodystructure.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion backend/backendutil/envelope.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion backend/backendutil/envelope_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion backend/backendutil/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions backend/backendutil/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions backend/backendutil/search_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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)}},
},
{
Expand All @@ -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)}},
},
{
Expand All @@ -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}}},
}},
},
{
Expand All @@ -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}}},
}},
Expand Down
4 changes: 2 additions & 2 deletions backend/memory/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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)),
Expand Down
28 changes: 14 additions & 14 deletions backend/memory/mailbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -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++
Expand All @@ -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)
}
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
}
Expand All @@ -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)

Expand All @@ -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
}
Expand All @@ -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,
Expand All @@ -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)
}
Expand All @@ -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)
}
Expand All @@ -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)
}

Expand Down
8 changes: 4 additions & 4 deletions backend/memory/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
)

type Message struct {
Uid uint32
UID uint32
Date time.Time
Size uint32
Flags []string
Expand Down Expand Up @@ -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 {
Expand All @@ -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)
}
10 changes: 5 additions & 5 deletions backend/memory/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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)
Expand All @@ -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{
Expand Down
4 changes: 2 additions & 2 deletions backend/updates.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions backend/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
}
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion client/cmd_any.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading