Skip to content

📥 An IMAP library for clients and servers

License

Notifications You must be signed in to change notification settings

foxcpp/go-imap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Repository files navigation

go-imap

GoDocBuild StatusCodecovGo Report CardUnstable

An IMAP4rev1 library written in Go. It can be used to build a client and/or a server.

go get github.com/emersion/go-imap/...

Usage

Client GoDoc

package main import ( "log""github.com/emersion/go-imap/client""github.com/emersion/go-imap" ) funcmain(){log.Println("Connecting to server...") // Connect to serverc, err:=client.DialTLS("mail.example.org:993", nil) iferr!=nil{log.Fatal(err) } log.Println("Connected") // Don't forget to logoutdeferc.Logout() // Loginiferr:=c.Login("username", "password"); err!=nil{log.Fatal(err) } log.Println("Logged in") // List mailboxesmailboxes:=make(chan*imap.MailboxInfo, 10) done:=make(chanerror, 1) gofunc (){done<-c.List("", "*", mailboxes) }() log.Println("Mailboxes:") form:=rangemailboxes{log.Println("* "+m.Name) } iferr:=<-done; err!=nil{log.Fatal(err) } // Select INBOXmbox, err:=c.Select("INBOX", false) iferr!=nil{log.Fatal(err) } log.Println("Flags for INBOX:", mbox.Flags) // Get the last 4 messagesfrom:=uint32(1) to:=mbox.Messagesifmbox.Messages>3{// We're using unsigned integers here, only substract if the result is > 0from=mbox.Messages-3 } seqset:=new(imap.SeqSet) seqset.AddRange(from, to) messages:=make(chan*imap.Message, 10) done=make(chanerror, 1) gofunc(){done<-c.Fetch(seqset, []imap.FetchItem{imap.FetchEnvelope}, messages) }() log.Println("Last 4 messages:") formsg:=rangemessages{log.Println("* "+msg.Envelope.Subject) } iferr:=<-done; err!=nil{log.Fatal(err) } log.Println("Done!") }

Server GoDoc

package main import ( "log""github.com/emersion/go-imap/server""github.com/emersion/go-imap/backend/memory" ) funcmain(){// Create a memory backendbe:=memory.New() // Create a new servers:=server.New(be) s.Addr=":1143"// Since we will use this server for testing only, we can allow plain text// authentication over unencrypted connectionss.AllowInsecureAuth=truelog.Println("Starting IMAP server at localhost:1143") iferr:=s.ListenAndServe(); err!=nil{log.Fatal(err) } }

You can now use telnet localhost 1143 to manually connect to the server.

Extending go-imap

Extensions

Commands defined in IMAP extensions are available in other packages. See the wiki to learn how to use them.

Server backends

Related projects

  • go-message - parsing and formatting MIME and mail messages
  • go-pgpmail - decrypting and encrypting mails with OpenPGP
  • go-sasl - sending and receiving SASL authentications
  • go-smtp - building SMTP clients and servers
  • go-dkim - creating and verifying DKIM signatures

License

MIT

About

📥 An IMAP library for clients and servers

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Go100.0%