Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BODYSTRUCTURE #17

Open
pedromorgan opened this issue Nov 14, 2015 · 1 comment
Open

BODYSTRUCTURE #17

pedromorgan opened this issue Nov 14, 2015 · 1 comment

Comments

@pedromorgan
Copy link

How do I parse BODYSTRUCTURE, as I want to find the attachments..

Using

cmd, err := imap.Wait( client.UIDFetch(uidlist, "FLAGS", "INTERNALDATE", "RFC822.SIZE", "RFC822.HEADER", "BODYSTRUCTURE") )

and then,

for _, bsv := range imap.AsList(rsp.MessageInfo().Attrs["BODYSTRUCTURE"]) {
    if  imap.TypeOf(bsv) == imap.List {
        vvv := imap.AsList(bsv)
        fmt.Println(" ==", vvv)
    }
}

Prints

 == [["text" "plain" ["charset" "UTF-8"] <nil> <nil> "7bit" 34 1 <nil> <nil> <nil> <nil>] ["text" "html" ["charset" "UTF-8"] <nil> <nil> "7bit" 55 1 <nil> <nil> <nil> <nil>] "alternative" ["boundary" "001a1145bb103402220524805d18"] <nil> <nil> <nil>]

 == ["application" "pdf" ["name" "White Paper - On-train fiber optic connectivity.pdf"] <nil> <nil> "base64" 1718302 <nil> ["attachment" ["filename" "White Paper - On-train fiber optic connectivity.pdf"]] <nil> <nil>]

 == ["application" "pdf" ["name" "Interim Report 23.11.14.pdf"] <nil> <nil> "base64" 447908 <nil> ["attachment" ["filename" "Interim Report 23.11.14.pdf"]] <nil> <nil>]

 == ["image" "jpeg" ["name" "ana.jpeg"] <nil> <nil> "base64" 882306 <nil> ["attachment" ["filename" "ana.jpeg"]] <nil> <nil>]

 == ["boundary" "001a1145bb103402290524805d1a"]
@mxk
Copy link
Owner

mxk commented Nov 15, 2015

Use the As* functions to navigate the returned structure. See https://github.com/mxk/go-imap/blob/master/imap/response.go#L266 for an example and https://tools.ietf.org/html/rfc3501#section-7.4.2 for a description of BODYSTRUCTURE. There is also a test example: https://github.com/mxk/go-imap/blob/master/imap/reader_test.go#L519.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants