IMAP Library for Go
Go
Switch branches/tags
Nothing to show
Clone or download
Googol Lee
Googol Lee update readme
Latest commit b48b8fe Jan 25, 2013
Permalink
Failed to load latest commit information.
README.markdown update readme Jan 25, 2013
getbody.go add support multipart/mix and multipart/related Jul 2, 2012
imap.go use conn to create client Jan 25, 2013
imap_test.go update testcase Sep 10, 2012
response.go fix test Jul 16, 2012

README.markdown

goimap

IMAP Client for go

ATTENTION

  • Not fully implemented.
  • Only tested with GMail.

Usage

package main

import (
    "fmt"
    "io/ioutil"
    "imap"
    "net"
)

func get1st(a, b interface{}) interface{} {
    return a
}

func main() {
    conn, _ := net.Dial("tcp", "imap.gmail.com:993")
    client, _ := imap.NewClient(conn, "imap.gmail.com")
    defer client.Close()

    _ = client.Login("mail@gmail.com", "password")
    client.Select(imap.Inbox)
    ids, _ := client.Search("unseen")
    fmt.Println(ids)

    for _, id := range ids {
        client.StoreFlag(id, imap.Seen)

        msg, _ := client.GetMessage(id)

        fmt.Println("To:", get1st(msg.Header.AddressList("To")))
        fmt.Println("From:", get1st(msg.Header.AddressList("From")))
        from, _ := msg.Header.AddressList("To")
        fmt.Println("From:", from[0].Name)
        fmt.Println("Subject:", msg.Header["Subject"])
        fmt.Println("Date:", get1st(msg.Header.Date()))
        body, _ := ioutil.ReadAll(msg.Body)
        fmt.Println("body:\n", string(body))
    }
    client.Logout()
}