Пример #1
0
func PostArticle(conn *client.Conn, tok []string) {
	if tok[1] == "<*****@*****.**>" {
		conn.Send("435 Already have article.")
		return
	}
	if tok[1] == "<*****@*****.**>" {
		conn.Send("436 Early failed.")
		return
	}
	conn.Send("335 Send article to be transferred.")

	b := new(bytes.Buffer)
	br := bufio.NewReader(conn.GetReader())
	r := textproto.NewReader(br)

	fmt.Println("PostArticle head.")
	m, e := r.ReadMIMEHeader()
	if e != nil {
		conn.Send("437 Failed reading header")
		return
	}

	fmt.Println("PostArticle body.")
	if _, e := io.Copy(b, dotreader.New(br)); e != nil {
		conn.Send("437 Failed reading body")
		return
	}

	if val := m.Get("X-Accept"); val == "DENY" {
		conn.Send("437 Deny test.")
		return
	}
	if val := m.Get("X-Accept"); val == "BROKEN" {
		conn.Send("500 Server is broken.")
		return
	}
	if val := m.Get("X-Accept"); val == "FAILED" {
		conn.Send("436 Transfer failed test.")
		return
	}

	if tok[1] == "<*****@*****.**>" {
		conn.Send("437 Duplicate")
		return
	}

	if conn.User == "refeed" {
		config.RequeMsgids = append(config.RequeMsgids, tok[1])
		conn.Send("235 Transferred.")
		return
	}

	if b.String() != "\r\nBody.\r\nBody1\r\nBody2 ohyeay?\r\n.\r\n" {
		conn.Send("500 Body does not match hardcoded compare value.")
		return
	}
	conn.Send("235 Transferred.")
}
Пример #2
0
func req(conn *client.Conn) {
	conn.Send("200 StoreD")
	for {
		tok, e := conn.ReadLine()
		if e != nil {
			fmt.Println(fmt.Sprintf("WARN: C(%s): %s", conn.RemoteAddr(), e.Error()))
			break
		}

		cmd := strings.ToUpper(tok[0])
		if cmd == "QUIT" {
			Quit(conn, tok)
			break
		} else if cmd == "ARTICLE" {
			Article(conn, tok)
		} else if cmd == "HEAD" {
			Head(conn, tok)
		} else if cmd == "BODY" {
			Body(conn, tok)
		} else if cmd == "STAT" {
			Stat(conn, tok)
		} else if cmd == "AUTHINFO" {
			sub := strings.ToUpper(tok[1])
			if sub == "USER" {
				conn.User = tok[2]
				conn.Send("381 Need more.")
			} else if sub == "PASS" {
				if tok[2] == "test" {
					conn.Send("281 Authentication accepted.")
				}
			}
		} else if cmd == "GROUP" {
			Group(conn, tok)
		} else if cmd == "NOOP" {
			conn.Send("500 Unsupported.")
		} else if cmd == "IHAVE" {
			PostArticle(conn, tok)
		} else if cmd == "POST" {
			if e := conn.Send("340 Start posting."); e != nil {
				conn.Send("437 Start failed.")
			}
			br := bufio.NewReader(conn.GetReader())
			if _, e := io.Copy(ioutil.Discard, dotreader.New(br)); e != nil {
				conn.Send("437 Failed reading body")
				return
			}
			if e := conn.Send("240 Posted "); e != nil {
				conn.Send("437 Failed storing.")
			}
		} else if cmd == "XOVER" {
			Xover(conn, tok)
		} else if cmd == "XHDR" {
			Xhdr(conn, tok)
		} else if cmd == "LIST" {
			List(conn, tok)
		} else if cmd == "DATE" {
			Date(conn, tok)
		} else {
			Unsupported(conn, tok)
			break
		}
	}

	conn.Close()
	if config.Verbose {
		fmt.Println(fmt.Sprintf("C(%s) Closed", conn.RemoteAddr()))
	}
}