func Pcmd(c *Cmd, dot *imap.MsgPart) *imap.MsgPart { if dot == nil { return nil } if dot == &dot.Msg.Root { fmt.Fprintf(bout, "From %s %s\n", unixfrom(dot.Msg.Hdr), unixtime(dot.Msg)) } bout.Write(dot.Raw()) return dot }
func printMIME(w io.Writer, p *imap.MsgPart, top bool) { switch { case top && strings.HasPrefix(p.Type, "text/"): text := p.ShortText() if p.Type == "text/html" { cmd := exec.Command("htmlfmt") cmd.Stdin = bytes.NewBuffer(text) if w == bout { bout.Flush() cmd.Stdout = os.Stdout } else { cmd.Stdout = w } if err := cmd.Run(); err != nil { fmt.Fprintf(w, "%d.%s !%s\n", msgNum[p.Msg]+1, p.ID, err) } return } w.Write(text) case p.Type == "text/plain": if top { panic("printMIME loop") } printMIME(w, p, true) case p.Type == "multipart/alternative": for _, pp := range p.Child { if pp.Type == "text/plain" { printMIME(w, pp, false) return } } if len(p.Child) > 0 { printMIME(w, p.Child[0], false) } case strings.HasPrefix(p.Type, "multipart/"): for _, pp := range p.Child { printMIME(w, pp, false) } default: fmt.Fprintf(w, "%d.%s !%s %s %s\n", msgNum[p.Msg]+1, p.ID, p.Type, p.Desc, p.Name) } }