package pop import ( osm "git.loafle.net/overflow/service_matcher-go" ) const ( COMPARE_STR = "+OK" ) type POPMatcher struct { osm.Matchers } func (p *POPMatcher) Key() string { return "POP3" } func (p *POPMatcher) Name() string { return "POP3" } func (p *POPMatcher) Meta() osm.Metadata { return nil } func (p *POPMatcher) IsPrePacket() bool { return true } func (p *POPMatcher) HasResponse(index int) bool { return true } func (p *POPMatcher) IsError(info osm.MatchInfo, index int, packet *osm.Packet) bool { return false } func (p *POPMatcher) Match(info osm.MatchInfo, index int, packet *osm.Packet) error { switch index { case 0: fallthrough case 1: recvStr := string(packet.Bytes()) if len(recvStr) < 3 { return osm.NotMatchedError() } compareStr := recvStr[0:3] if compareStr == COMPARE_STR { return nil } } return osm.NotMatchedError() } func NewMatcher() osm.Matcher { m := &POPMatcher{} reqStr := "QUIT\r\n" byte := make([]byte, len(reqStr)) copy(byte[:], reqStr) m.AddPacket(osm.NewPacket(byte, len(reqStr))) return m }