コード例 #1
0
ファイル: to_matcher_test.go プロジェクト: robmcl4/gost
func TestNegativeMatchNoAddressees(t *testing.T) {
	e_smtp := email.SMTPEmail{
		Contents: []byte(
			`Foo: bar
Bar: baz
The-Thing: Other-Thing

A body to the message
`),
	}
	e, err := e_smtp.Parse()
	assert.Nil(t, err)
	matcher := NewToMatcher("*****@*****.**")
	assert.False(t, matcher.Matches(e), "should match email")
}
コード例 #2
0
ファイル: to_matcher_test.go プロジェクト: robmcl4/gost
func TestPositiveMatch(t *testing.T) {
	e_smtp := email.SMTPEmail{
		Contents: []byte(
			`Foo: bar
Bar: baz
The-Thing: Other-Thing
To: The Dude <*****@*****.**>

A body to the message
`),
	}
	e, err := e_smtp.Parse()
	assert.Nil(t, err)
	matcher := NewToMatcher("*****@*****.**")
	assert.True(t, matcher.Matches(e), "should match email")
}
コード例 #3
0
ファイル: to_matcher_test.go プロジェクト: robmcl4/gost
func TestNegativeMatchMultiple(t *testing.T) {
	e_smtp := email.SMTPEmail{
		Contents: []byte(
			`Foo: bar
Bar: baz
The-Thing: Other-Thing
To: "The Dude" <*****@*****.**>, "The Other Dude" <*****@*****.**>

A body to the message
`),
	}
	e, err := e_smtp.Parse()
	assert.Nil(t, err)
	matcher := NewToMatcher("*****@*****.**")
	assert.False(t, matcher.Matches(e), "should match email")
}
コード例 #4
0
ファイル: message_handler.go プロジェクト: robmcl4/gost
func (c *Client) getEmail() (*email.SMTPEmail, error) {
	ret := new(email.SMTPEmail)
	// get the MAIL command
	verb, extra, err := c.getCommand()
	if err != nil {
		return nil, err
	}
	if verb != "MAIL" {
		c.notifyBadSequence()
		return nil, fmt.Errorf("Expected MAIL but got %s", verb)
	}
	if match := fromRegexp.FindStringSubmatch(extra); match != nil {
		ret.From = match[1]
	}
	err = c.notifyOk()
	if err != nil {
		return nil, err
	}
	// get the RCPT commands
	for {
		verb, extra, err = c.getCommand()
		if verb != "RCPT" {
			break
		}
		if err != nil {
			return nil, err
		}
		if match := toRegexp.FindStringSubmatch(extra); match != nil {
			ret.To = append(ret.To, match[1])
			err = c.notifyOk()
			if err != nil {
				return nil, err
			}
		} else {
			c.notifySyntaxError()
			return nil, fmt.Errorf("Couldn't find recipient email: %s", extra)
		}
	}
	// ok so we should have at least 1 recipient now.. if not, this is an error
	if ret.To == nil || len(ret.To) == 0 {
		c.notifyBadSequence()
		return nil, fmt.Errorf("Expected RCPT command, got %s", verb)
	}
	// this should be the DATA command
	if verb != "DATA" {
		c.notifyBadSequence()
		return nil, fmt.Errorf("Expected DATA command, got %s", verb)
	}
	err = c.notifyStartMailInput()
	if err != nil {
		return nil, err
	}
	// let's receive data...
	ret.Contents, err = c.readDataBody()
	if err != nil {
		return nil, err
	}
	err = c.notifyOk()
	if err != nil {
		return nil, err
	}
	return ret, nil
}