2018-08-13 07:48:32 +00:00
|
|
|
package pop
|
|
|
|
|
|
|
|
import (
|
2018-08-15 07:17:18 +00:00
|
|
|
osm "git.loafle.net/overflow/service_matcher-go"
|
2018-08-13 07:48:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
COMPARE_STR = "+OK"
|
|
|
|
)
|
|
|
|
|
|
|
|
type POPMatcher struct {
|
2018-08-15 07:17:18 +00:00
|
|
|
osm.Matchers
|
2018-08-13 07:48:32 +00:00
|
|
|
}
|
|
|
|
|
2018-09-03 13:36:57 +00:00
|
|
|
func (m *POPMatcher) Key() string {
|
2018-08-13 07:48:32 +00:00
|
|
|
return "POP3"
|
|
|
|
}
|
|
|
|
|
2018-09-12 04:26:27 +00:00
|
|
|
func (m *POPMatcher) Type() string {
|
|
|
|
return "MAIL"
|
|
|
|
}
|
2018-09-13 08:31:11 +00:00
|
|
|
func (m *POPMatcher) Vendor(matchCtx *osm.MatchCtx) string {
|
|
|
|
return "UNKNOWN"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *POPMatcher) Version(matchCtx *osm.MatchCtx) string {
|
|
|
|
return "UNKNOWN"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *POPMatcher) OsType(matchCtx *osm.MatchCtx) string {
|
|
|
|
return "UNKNOWN"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (m *POPMatcher) OsVersion(matchCtx *osm.MatchCtx) string {
|
|
|
|
return "UNKNOWN"
|
|
|
|
}
|
2018-09-12 04:26:27 +00:00
|
|
|
|
2018-09-03 13:36:57 +00:00
|
|
|
func (m *POPMatcher) Name(matchCtx *osm.MatchCtx) string {
|
2018-08-13 07:48:32 +00:00
|
|
|
return "POP3"
|
|
|
|
}
|
|
|
|
|
2018-09-03 13:41:28 +00:00
|
|
|
func (m *POPMatcher) IsPrePacket() bool {
|
2018-08-13 07:48:32 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2018-09-03 13:36:57 +00:00
|
|
|
func (m *POPMatcher) HasResponse(matchCtx *osm.MatchCtx, index int) bool {
|
2018-08-13 07:48:32 +00:00
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2018-09-03 13:36:57 +00:00
|
|
|
func (m *POPMatcher) IsError(matchCtx *osm.MatchCtx, index int, packet *osm.Packet) bool {
|
2018-08-13 07:48:32 +00:00
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
2018-09-03 13:36:57 +00:00
|
|
|
func (m *POPMatcher) Match(matchCtx *osm.MatchCtx, index int, packet *osm.Packet) error {
|
2018-08-13 07:48:32 +00:00
|
|
|
|
|
|
|
switch index {
|
|
|
|
case 0:
|
|
|
|
fallthrough
|
|
|
|
case 1:
|
2018-09-03 06:42:56 +00:00
|
|
|
recvStr := string(packet.Bytes())
|
2018-08-13 07:48:32 +00:00
|
|
|
|
|
|
|
if len(recvStr) < 3 {
|
2018-09-03 06:42:56 +00:00
|
|
|
return osm.NotMatchedError()
|
2018-08-13 07:48:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
compareStr := recvStr[0:3]
|
|
|
|
|
|
|
|
if compareStr == COMPARE_STR {
|
2018-09-03 06:42:56 +00:00
|
|
|
return nil
|
2018-08-13 07:48:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2018-09-03 06:42:56 +00:00
|
|
|
return osm.NotMatchedError()
|
2018-08-13 07:48:32 +00:00
|
|
|
}
|
|
|
|
|
2018-08-15 07:17:18 +00:00
|
|
|
func NewMatcher() osm.Matcher {
|
2018-08-13 07:48:32 +00:00
|
|
|
|
|
|
|
m := &POPMatcher{}
|
|
|
|
|
|
|
|
reqStr := "QUIT\r\n"
|
|
|
|
byte := make([]byte, len(reqStr))
|
|
|
|
copy(byte[:], reqStr)
|
2018-08-15 07:17:18 +00:00
|
|
|
m.AddPacket(osm.NewPacket(byte, len(reqStr)))
|
2018-08-13 07:48:32 +00:00
|
|
|
|
|
|
|
return m
|
|
|
|
|
|
|
|
}
|