func (m *MessageAsMimeTree) Read(p []byte) (int, error) { if m.rs == nil { m.rs = &readState{} var printM func(w io.Writer, depth int, m *mime.MimePart) printM = func(w io.Writer, depth int, m *mime.MimePart) { fmt.Fprintf(w, "%s%s\n", strings.Repeat("-", depth), mime.MimeTypeTxt(m.MimeType)) if m.Child != nil { printM(w, depth+1, m.Child) } for cur := m.Next; cur != nil; cur = cur.Next { printM(w, depth, cur) } } f, err := os.Open(m.path) if err != nil { m.rs = nil return 0, err } defer f.Close() mtree, err := mime.GetMimeTree(f, 10) if err != nil { m.rs = nil return 0, err } buf := &bytes.Buffer{} printM(buf, 0, mtree) m.rs.r = buf } ret, err := m.rs.r.Read(p) if err != nil { m.rs = nil } return ret, err }
func partSummary(m *mime.MimePart) *bytes.Buffer { name := "" if m.Name != "" { name = fmt.Sprintf("- %s ", m.Name) } str := fmt.Sprintf("\n\033[7m[-- %s %s- (%s) --]\n", mime.MimeTypeTxt(m.MimeType), name, util.SiteToHuman(int64(m.Buf.Len()))) return bytes.NewBufferString(str) }