Beispiel #1
0
func serve(c SMTPConnection) {

	greeting := "250 email.bashman.org\r\n"

	c.state = "greeting"

	write(c, "220 email.bashman.org\r\n")
	for c.state != "goodbye" {
		input, err := c.reader.ReadString('\n')
		if err == io.EOF {
			break
		} else if err != nil {
			panic(err)
		}
		input = strings.Trim(input, "\r\n")

		fmt.Println(input)
		if input[0:1] == "." {
			break
		} else {
			cmd := input[0:4]
			switch cmd {
			case "EHLO":
				write(c, greeting)
			case "HELO":
				write(c, greeting)
			case "QUIT":
				c.state = "goodbye"
			case "MAIL":
				c = f_from(c, strings.Split(input, ":")[1])
			case "RCPT":
				c = f_to(c, strings.Split(input, ":")[1])
			case "DATA":
				c = f_data(c)
			}
		}
	}
	c.conn.Close()

	redis, err := redis.Dial("unix", "/tmp/redis.sock")
	defer redis.Close()
	if err != nil {
		panic(err)
	}

	content := ""
	content = content + "Subject:" + c.email.subject + "\n"
	content = content + "From:   " + c.email.from + "\n"
	content = content + "To:     " + c.email.to + "\n"
	content = content + "Body:   " + c.email.body

	redis.Do("SADD", c.email.to, content)
}
Beispiel #2
0
func (i *RedisIndexer) Flush(parsed_log_data []byte) (err error) {
	redis, err := redis.Dial("tcp", i.address)

	if err != nil {
		log.Fatal(err)
	}

	redis.Do("lpush", "errorz", parsed_log_data)

	log.Print("Data Pushed: ", len(parsed_log_data), " bytes")

	return
}