// parse smtp line
771335
func parseLine(line string) (cmd string, args string) {
  if idx := strings.Index(line, " "); idx > 0 {
    cmd = strings.ToUpper(line[:idx])
    args = strings.TrimSpace(line[idx+1:])
  } else {
    cmd = strings.ToUpper(line)
  }
  return
}
38507
func (e *Envelope) Parse(fields []interface{}) error {
	if len(fields) < 10 {
		return errors.New("ENVELOPE doesn't contain 10 fields")
	}

	if date, ok := fields[0].(string); ok {
		e.Date, _ = parseMessageDateTime(date)
	}
	if subject, err := ParseString(fields[1]); err == nil {
		e.Subject, _ = decodeHeader(subject)
	}
	if from, ok := fields[2].([]interface{}); ok {
		e.From = ParseAddressList(from)
	}
	if sender, ok := fields[3].([]interface{}); ok {
		e.Sender = ParseAddressList(sender)
	}
	if replyTo, ok := fields[4].([]interface{}); ok {
		e.ReplyTo = ParseAddressList(replyTo)
	}
	if to, ok := fields[5].([]interface{}); ok {
		e.To = ParseAddressList(to)
	}
	if cc, ok := fields[6].([]interface{}); ok {
		e.Cc = ParseAddressList(cc)
	}
	if bcc, ok := fields[7].([]interface{}); ok {
		e.Bcc = ParseAddressList(bcc)
	}
	if inReplyTo, ok := fields[8].(string); ok {
		e.InReplyTo = inReplyTo
	}
	if msgId, ok := fields[9].(string); ok {
		e.MessageId = msgId
	}

	return nil
}
361996
func ParseRequestLine(line []byte) (r RequestLine, ok bool) {
	var i int
	for i = 0; i < len(line); i++ {
		c := line[i]
		if !OctetTypes[c].IsToken() {
			if i > 0 && c == ' ' {
				break
			}
			return
		}
	}
	if i == len(line) {
		return
	}

	var proto []byte
	r.Method = line[:i]
	r.URI, proto = split2(line[i+1:], ' ')
	if len(r.URI) == 0 {
		return
	}
	if major, minor, ok := ParseVersion(proto); ok {
		r.Version.Major = major
		r.Version.Minor = minor
		return r, true
	}

	return r, false
}
591989
func parseTorReply(reply string) map[string]string {
	params := make(map[string]string)

	// Replies can either span single or multiple lines, so we'll default
	// to stripping whitespace and newlines in order to retrieve the
	// individual contents of it. The -1 indicates that we want this to span
	// across all instances of a newline.
	contents := strings.Split(strings.Replace(reply, "\n", " ", -1), " ")
	for _, content := range contents {
		// Each parameter within the reply should be of the form
		// "KEY=VALUE". If the parameter doesn't contain "=", then we
		// can assume it does not provide any other relevant information
		// already known.
		keyValue := strings.SplitN(content, "=", 2)
		if len(keyValue) != 2 {
			continue
		}

		key := keyValue[0]
		value := keyValue[1]
		params[key] = value
	}

	return params
}
783647
func GenericEmail(name, paragraphs []string) string {
	h := "<html><body>"
	if len(name) > 0 {
		h += fmt.Sprintf("<p>Hi %s:</p>", name)
	}
	for _, p := range paragraphs {
		h += fmt.Sprintf("<p>%s</p>", p)
	}
	h += "<p>Best,</p>"
	h += "<p>-Abot</p>"
	h += "</body></html>"
	return h
}
25746
func Parse(s string) (*ACL, error) {
	cs := C.CString(s)
	cacl, _ := C.acl_from_text(cs)
	if cacl == nil {
		return nil, fmt.Errorf("unable to parse ACL")
	}
	return &ACL{cacl}, nil
}
1085525
func Parse(src []byte) (*ast.File, error) {
	// normalize all line endings
	// since the scanner and output only work with "\n" line endings, we may
	// end up with dangling "\r" characters in the parsed data.
	src = bytes.Replace(src, []byte("\r\n"), []byte("\n"), -1)

	p := newParser(src)
	return p.Parse()
}
805031
func ParseMessage(data []byte, sender net.Addr) (Message, error) {
	address, idx := ReadString(data)
	msg := Message{
		Address: address,
		Sender:  sender,
	}
	data = data[idx:]
	typetags, idx := ReadString(data)
	data = data[idx:]

	// Read all arguments.
	args, err := ReadArguments([]byte(typetags), data)
	if err != nil {
		return Message{}, errors.Wrap(err, "parse message")
	}
	msg.Arguments = args

	return msg, nil
}
397600
func (r Reply) Lines() []string {
	var lines []string

	if len(r.lines) == 0 {
		l := strconv.Itoa(r.Status)
		lines = append(lines, l+"\n")
		return lines
	}

	for i, line := range r.lines {
		l := ""
		if i == len(r.lines)-1 {
			l = strconv.Itoa(r.Status) + " " + line + "\r\n"
		} else {
			l = strconv.Itoa(r.Status) + "-" + line + "\r\n"
		}
		lines = append(lines, l)
	}

	return lines
}
45479
func (p *parserImpl) parse(
	blob json.RawMessage,
) ([]*Comment, []*Post, []*Message, error) {
	comments, posts, msgs, listingErr := parseRawListing(blob)
	if listingErr == nil {
		return comments, posts, msgs, nil
	}

	post, threadErr := parseThread(blob)
	if threadErr == nil {
		return nil, []*Post{post}, nil, nil
	}

	return nil, nil, nil, fmt.Errorf(
		"failed to parse as listing [%v] or thread [%v]",
		listingErr, threadErr,
	)
}
1183463
func parseMessage(t *thing) (*Message, error) {
	m := &Message{}
	return m, mapstructure.Decode(t.Data, m)
}
395921
func (m *SMTPMessage) Bytes() io.Reader {
	var b = new(bytes.Buffer)

	b.WriteString("HELO:<" + m.Helo + ">\r\n")
	b.WriteString("FROM:<" + m.From + ">\r\n")
	for _, t := range m.To {
		b.WriteString("TO:<" + t + ">\r\n")
	}
	b.WriteString("\r\n")
	b.WriteString(m.Data)

	return b
}
714830
func (s *Server) parsePacket(packet []byte, from net.Addr) error {
	var msg dns.Msg
	if err := msg.Unpack(packet); err != nil {
		log.Printf("[ERR] mdns: Failed to unpack packet: %v", err)
		return err
	}
	return s.handleQuery(&msg, from)
}
94126
func (fs *FlagSet) Parse(line string) error {
	var args []string
	for _, token := range lexer(line, ',').split() {
		name, value := token.split()
		args = append(args, fmt.Sprintf("-%s", name))
		if value != "" {
			args = append(args, value)
		}
	}

	return fs.F.Parse(args)
}
803646
func (p *PAM) Parse() *pam.Config {
	serviceName := p.ServiceName
	if serviceName == "" {
		serviceName = defaults.ServiceName
	}
	enabled, _ := utils.ParseBool(p.Enabled)
	return &pam.Config{
		Enabled:     enabled,
		ServiceName: serviceName,
	}
}
399098
func parsePost(t *thing) (*Post, error) {
	p := &Post{}
	if err := mapstructure.Decode(t.Data, p); err != nil {
		return nil, mapDecodeError(err, t.Data)
	}

	p.Deleted = p.SelfText == deletedKey
	return p, nil
}
161770
func parseRequestLine(line string) (method, uri, proto string, ok bool) {
	s1 := strings.Index(line, " ")
	s2 := strings.Index(line[s1+1:], " ")
	if s1 < 0 || s2 < 0 {
		return
	}
	s2 += s1 + 1
	return line[:s1], line[s1+1 : s2], line[s2+1:], true
}