On Wed, Jul 26, 2017 at 02:52:05PM +0800, jesse junsay wrote: > > Check out github.com/tgulacsi/agostle - it walks the tree of mime parts > > of mail and converts everything to PDF, but you need the walk part only - > > which uses mime/multipart reader basically. > Thank you Tamas... I am already done with identifying each part using the > mime multipart... My main issue now is decoding it back to its binary form > and save it to disk... each attachment to its own data format. jpg > attachment to file.jpg, pdf attachment to file.pdf and txt attachment to > file.txt...
You should study a bit of theory behind this. As the first step, you can take any of your sample e-mail messages and ask your mail reading program to show you the "raw" message's view. You can also save the message as a file to your filesystem and then use any "advanced" text viewer program (say, Notepad++ would do) to view its "raw" content. (If asked, save as "mbox" format or "EML" format.) You can then see that each MIME part of your message has individual header block followed by an empty line (sole CR+LF sequence) followed by the body of that part. This header contains several standard fields defining what's the encoding of the following body, and what's the format of the source data which was encoded. Say, typically, the encoding is Base64, and the format depends on the data -- it may be, say, text/json or image/jpeg and so on. Your task is to try and parse these fields as you iterate over the MIME parts of your message and act accordingly. The standard library has all the bits you need to carry out this task -- see [1, 2]. 1. https://golang.org/pkg/mime/ 2. https://golang.org/pkg/mime/multipart/ -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.