예제 #1
0
func extractCommand(reader *textproto.Reader) (command, error) {
	line, err := reader.ReadLine()
	if err != nil {
		return getStats, err
	}

	for index, commandName := range commandNames {
		if commandName == line {
			return command(index), nil
		}
	}
	return getStats, errInvalidCommand
}
예제 #2
0
func putTextprotoReader(r *textproto.Reader) {
	r.R = nil
	select {
	case textprotoReaderCache <- r:
	default:
	}
}
예제 #3
0
/**
The Email Header is expected to follow this spec:
	Mail Header: Return-Path: <*****@*****.**>
	X-Original-To: [email protected]
	Delivered-To: [email protected]
	Received: by domain.de (Postfix, from userid 0)
	id 034C710090703; Sat, 16 Mar 2013 02:05:26 +0100 (CET)
	To: [email protected], [email protected], [...]
	Subject: Test Message
	Message-Id: <*****@*****.**>
	Date: Sat, _6 Mar 2013 02:05:26 +0100 (CET)
	From: [email protected] (root)
which translates to a more generic form of:
	Key : Blank Value \newline
*/
func parseHeaderStr(header string) (*Header, error) {
	if 0 == len(header) {
		return nil, errors.New("Header string is empty")
	}
	var (
		reader  *textproto.Reader = textproto.NewReader(bufio.NewReader(bytes.NewBufferString(header)))
		mHeader textproto.MIMEHeader
		err     error
	)
	if mHeader, err = reader.ReadMIMEHeader(); err != nil && err != io.EOF {
		return nil, err
	}
	//		for key, val := range mHeader {
	//			fmt.Printf("&&&& %s -> %s\n", key, val)
	//		}
	return parseMainHeaderContent(mHeader)
}
예제 #4
0
파일: peer.go 프로젝트: postfix/libblockify
func (s *Service) reader(r *textproto.Reader) {
	for {
		str, e := r.ReadLine()
		if e != nil {
			break
		}
		req := rxreq.FindStringSubmatch(str)
		if req == nil {
			break
		}
		if req[1] == "QUIT" {
			break
		}
		switch req[1] {
		case "PULL":
			if s.Debug {
				fmt.Println("got pull", req[2])
			}
			k, e := base64.StdEncoding.DecodeString(req[2])
			if e == nil {
				s.rpull <- k
			}
		case "PUSH":
			_, e = io.ReadFull(r.R, s.rblock)
			if e == nil {
				h := sha512.New()
				h.Write(s.rblock)
				hash := h.Sum([]byte{})
				if s.acc.Accept(hash) {
					if s.Debug {
						fmt.Println("got push", base64.StdEncoding.EncodeToString(hash), "accept")
					}
					s.bck.Store(hash, s.rblock)
				} else {
					if s.Debug {
						fmt.Println("got push", base64.StdEncoding.EncodeToString(hash), "refuse")
					}
				}
			}
		}
	}
}
예제 #5
0
파일: request.go 프로젝트: arnold8/go
func putTextprotoReader(r *textproto.Reader) {
	r.R = nil
	textprotoReaderPool.Put(r)
}