8bc927cf91
This reverts commit 7e4a2f1775
104 lines
1.7 KiB
Go
104 lines
1.7 KiB
Go
package imap
|
|
|
|
import (
|
|
osm "git.loafle.net/overflow/service_matcher-go"
|
|
)
|
|
|
|
const (
|
|
PRE_COMPARE_STR = "* OK"
|
|
SEND_COMPARE_STR = "* BYE"
|
|
)
|
|
|
|
type IMAPMatcher struct {
|
|
osm.Matchers
|
|
}
|
|
|
|
func (m *IMAPMatcher) Key() string {
|
|
return "IMAP"
|
|
}
|
|
|
|
func (m *IMAPMatcher) Type() string {
|
|
return "MAIL"
|
|
}
|
|
func (m *IMAPMatcher) Vendor(matchCtx *osm.MatchCtx) string {
|
|
return "UNKNOWN"
|
|
}
|
|
|
|
func (m *IMAPMatcher) Version(matchCtx *osm.MatchCtx) string {
|
|
return "UNKNOWN"
|
|
}
|
|
|
|
func (m *IMAPMatcher) OsType(matchCtx *osm.MatchCtx) string {
|
|
return "UNKNOWN"
|
|
}
|
|
|
|
func (m *IMAPMatcher) OsVersion(matchCtx *osm.MatchCtx) string {
|
|
return "UNKNOWN"
|
|
}
|
|
|
|
func (m *IMAPMatcher) Name(matchCtx *osm.MatchCtx) string {
|
|
return "IMAP"
|
|
}
|
|
|
|
func (m *IMAPMatcher) IsPrePacket() bool {
|
|
return true
|
|
}
|
|
|
|
func (m *IMAPMatcher) HasResponse(matchCtx *osm.MatchCtx, index int) bool {
|
|
return true
|
|
}
|
|
|
|
func (m *IMAPMatcher) IsError(matchCtx *osm.MatchCtx, index int, packet *osm.Packet) bool {
|
|
return false
|
|
}
|
|
|
|
func (m *IMAPMatcher) Match(matchCtx *osm.MatchCtx, index int, packet *osm.Packet) error {
|
|
|
|
switch index {
|
|
case 0:
|
|
|
|
recvStr := string(packet.Bytes())
|
|
|
|
if len(recvStr) < 3 {
|
|
return osm.NotMatchedError()
|
|
}
|
|
|
|
compareStr := recvStr[0:4]
|
|
|
|
if compareStr == PRE_COMPARE_STR {
|
|
return nil
|
|
}
|
|
|
|
case 1:
|
|
|
|
recvStr := string(packet.Bytes())
|
|
|
|
if len(recvStr) < 5 {
|
|
return osm.NotMatchedError()
|
|
}
|
|
|
|
compareStr := recvStr[0:5]
|
|
|
|
if compareStr == SEND_COMPARE_STR {
|
|
return nil
|
|
}
|
|
|
|
}
|
|
|
|
return osm.NotMatchedError()
|
|
}
|
|
|
|
func NewMatcher() osm.Matcher {
|
|
|
|
m := &IMAPMatcher{}
|
|
|
|
reqStr := "A0001 LOGOUT\r\n"
|
|
byte := make([]byte, len(reqStr))
|
|
copy(byte[:], reqStr)
|
|
|
|
m.AddPacket(osm.NewPacket(byte, len(reqStr)))
|
|
|
|
return m
|
|
|
|
}
|