Files
proton-bridge/pkg/message/parser/handler.go
2020-09-11 11:41:02 +02:00

41 lines
692 B
Go

package parser
import "regexp"
type HandlerFunc func(*Part) error
type handler struct {
typeRegExp, dispRegExp string
fn HandlerFunc
}
func (h *handler) matchPart(p *Part) bool {
return h.matchType(p) || h.matchDisp(p)
}
func (h *handler) matchType(p *Part) bool {
if h.typeRegExp == "" {
return false
}
t, _, err := p.Header.ContentType()
if err != nil {
t = ""
}
return regexp.MustCompile(h.typeRegExp).MatchString(t)
}
func (h *handler) matchDisp(p *Part) bool {
if h.dispRegExp == "" {
return false
}
disp, _, err := p.Header.ContentDisposition()
if err != nil {
disp = ""
}
return regexp.MustCompile(h.dispRegExp).MatchString(disp)
}