<commit_before>package smtpd

import (
	"fmt"
	"strings"
)

func parseAddress(src string) (string, error) {

	if len(src) == 0 || src[0] != '<' || src[len(src)-1] != '>' {
		return "", fmt.Errorf("Ill-formatted e-mail address: %s", src)
	}

	if strings.Count(src, "@") > 1 {
		return "", fmt.Errorf("Ill-formatted e-mail address: %s", src)
	}

	return src[1 : len(src)-1], nil
}<commit_msg>Modified address parsing to use the net/mail ParseAddress function.<commit_after>package smtpd

import (
	"fmt"
	"net/mail"
	"strings"
)

func parseAddress(src string) (string, error) {

	// Mailbox specifications as per RFC5321 must have a local part and a
	// domain part separated by '@'
	if strings.Count(src, "@") != 1 {
		return "", fmt.Errorf("malformed e-mail address: %s", src)
	}

	// While a RFC5321 mailbox specification is not the same as an RFC5322
	// email address specification, it is better to accept that format and
	// parse it down to the actual address, as there are a lot of badly
	// behaving MTAs and MUAs that do it wrongly. It therefore makes sense
	// to rely on Go's built-in address parser. This does have the benefit
	// of allowing "<EMAIL>" as input as thats commonly used,
	// though not RFC compliant.
	addr, err := mail.ParseAddress(src)
	if err != nil {
		return "", fmt.Errorf("malformed e-mail address: %s", src)
	}

	return addr.Address, nil
}
{'fraction_non_alphanumeric': 0.13619810633648943, 'fraction_numerical': 0.013838310269482883, 'mean_word_length': 3.673469387755102, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5720902', 'n_tokens_mistral': 478, 'n_tokens_neox': 444, 'n_words': 167}