示例#1
0
// Send the contents of the message to the client
func (ses *Session) sendMessage(msg smtpd.Message) {
	reader, err := msg.RawReader()
	if err != nil {
		ses.logError("Failed to read message for RETR command")
		ses.send("-ERR Failed to RETR that message, internal error")
		return
	}
	defer reader.Close()
	scanner := bufio.NewScanner(reader)
	for scanner.Scan() {
		line := scanner.Text()
		// Lines starting with . must be prefixed with another .
		if strings.HasPrefix(line, ".") {
			line = "." + line
		}
		ses.send(line)
	}

	if err = scanner.Err(); err != nil {
		ses.logError("Failed to read message for RETR command")
		ses.send(".")
		ses.send("-ERR Failed to RETR that message, internal error")
		return
	}
	ses.send(".")
}
示例#2
0
// Send the headers plus the top N lines to the client
func (ses *Session) sendMessageTop(msg smtpd.Message, lineCount int) {
	reader, err := msg.RawReader()
	if err != nil {
		ses.logError("Failed to read message for RETR command")
		ses.send("-ERR Failed to RETR that message, internal error")
		return
	}
	defer reader.Close()
	scanner := bufio.NewScanner(reader)
	inBody := false
	for scanner.Scan() {
		line := scanner.Text()
		// Lines starting with . must be prefixed with another .
		if strings.HasPrefix(line, ".") {
			line = "." + line
		}
		if inBody {
			// Check if we need to send anymore lines
			if lineCount < 1 {
				break
			} else {
				lineCount -= 1
			}
		} else {
			if line == "" {
				// We've hit the end of the header
				inBody = true
			}
		}
		ses.send(line)
	}

	if err = scanner.Err(); err != nil {
		ses.logError("Failed to read message for RETR command")
		ses.send(".")
		ses.send("-ERR Failed to RETR that message, internal error")
		return
	}
	ses.send(".")
}