refactor: remove dead code

This commit is contained in:
James Houlahan
2020-08-14 15:31:16 +02:00
parent 9821b5bbc2
commit 9ba08e5edb
4 changed files with 13 additions and 64 deletions

View File

@ -25,28 +25,16 @@ import (
type Writer struct {
root *Part
cond []Condition
}
type Condition func(p *Part) bool
func newWriter(root *Part) *Writer {
return &Writer{
root: root,
}
}
// WithCondition allows setting a condition when parts should be written.
// Parts are passed to each condition set and if any condition returns false,
// the part is not written.
// This initially seemed like a good idea but is now kinda useless.
func (w *Writer) WithCondition(cond Condition) *Writer {
w.cond = append(w.cond, cond)
return w
}
func (w *Writer) Write(ww io.Writer) error {
if w.shouldFilter(w.root) {
if !w.root.is7BitClean() {
w.root.Header.Add("Content-Transfer-Encoding", "base64")
}
@ -62,32 +50,6 @@ func (w *Writer) Write(ww io.Writer) error {
return msgWriter.Close()
}
func (w *Writer) shouldWrite(p *Part) bool {
for _, cond := range w.cond {
if !cond(p) {
return false
}
}
return true
}
func (w *Writer) shouldFilter(p *Part) bool {
encoding := p.Header.Get("Content-Transfer-Encoding")
if encoding != "" && encoding == "quoted-printable" || encoding == "base64" {
return false
}
for _, b := range p.Body {
if b > 1<<7 {
return true
}
}
return false
}
func (w *Writer) write(writer *message.Writer, p *Part) error {
if len(p.children) > 0 {
for _, child := range p.children {
@ -105,11 +67,7 @@ func (w *Writer) write(writer *message.Writer, p *Part) error {
}
func (w *Writer) writeAsChild(writer *message.Writer, p *Part) error {
if !w.shouldWrite(p) {
return nil
}
if w.shouldFilter(p) {
if !p.is7BitClean() {
p.Header.Add("Content-Transfer-Encoding", "base64")
}