func handleAlternative(msg *imap.MsgPart) (parts []*MessagePart) { parts = make([]*MessagePart, len(msg.Child)) for i, part := range msg.Child { parts[i] = &MessagePart{ID: part.ID, Name: part.Name, Type: part.Type} switch part.Type { case "text/plain": parts[i].Contents = string(part.Text()) case "text/html": parts[i].Contents, _ = redactomat.RedactString(string(part.Text())) } } return parts }
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 }