Beispiel #1
0
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
}
Beispiel #2
0
func handleMail(msg *imap.MsgPart) (parts *MessagePart) {
	parts = &MessagePart{ID: msg.ID, Name: msg.Name, Type: msg.Type}
	switch msg.Type {
	case "text/plain":
		parts.Contents = string(msg.Text())
	case "text/html":
		parts.Contents, _ = redactomat.RedactString(string(msg.Text()))
	case "multipart/alternative":
		parts.Children = handleAlternative(msg)
	case "multipart/mixed":
		parts.Children = handleMixed(msg)
	}
	return parts
}
Beispiel #3
0
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)
	}
}