GithubHelp home page GithubHelp logo

Need some example code about go-imap HOT 5 CLOSED

mxk avatar mxk commented on June 12, 2024
Need some example code

from go-imap.

Comments (5)

mxk avatar mxk commented on June 12, 2024

https://github.com/mxk/go-imap/tree/master/imap-demo
https://godoc.org/github.com/mxk/go-imap/imap#example-Client

from go-imap.

elgs avatar elgs commented on June 12, 2024

Thanks for the reply. I got the code run and fetched the subject from the code from your second link. However, the example in the second link does not answer the question how to get the body of the mail.

from go-imap.

mxk avatar mxk commented on June 12, 2024

You should have some understanding of the underlying protocol (RFC 3501) to use this package. The basic idea is that you would fetch "BODY[]" and then parse the response.

from go-imap.

elgs avatar elgs commented on June 12, 2024

Thanks. I finally figured out how to get it by reading RFC 3501. Here is some sample code:

cmd, _ = c.UIDFetch(set, "RFC822.HEADER", "RFC822.TEXT")

// Process responses while the command is running
fmt.Println("\nMost recent messages:")
for cmd.InProgress() {
    // Wait for the next response (no timeout)
    c.Recv(-1)

    // Process command data
    for _, rsp = range cmd.Data {
        header := imap.AsBytes(rsp.MessageInfo().Attrs["RFC822.HEADER"])
        uid := imap.AsNumber((rsp.MessageInfo().Attrs["UID"]))
        body := imap.AsBytes(rsp.MessageInfo().Attrs["RFC822.TEXT"])
        if msg, _ := mail.ReadMessage(bytes.NewReader(header)); msg != nil {
            fmt.Println("|--", msg.Header.Get("Subject"))
            fmt.Println("UID: ", uid)

            fmt.Println(string(body))
        }
    }
    cmd.Data = nil
    c.Data = nil
}

from go-imap.

ggitau avatar ggitau commented on June 12, 2024

Hi?
When I print the body as shown above it comes in parts that consist of headers and a base64 encoded string...how do I separate the two (headers and base64 encoded string) so that I can decode the contents?

from go-imap.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.