func (ra *RegistrationAuthorityImpl) validateContacts(ctx context.Context, contacts *[]*core.AcmeURL) error { if contacts == nil || len(*contacts) == 0 { return nil // Nothing to validate } if ra.maxContactsPerReg > 0 && len(*contacts) > ra.maxContactsPerReg { return core.MalformedRequestError(fmt.Sprintf("Too many contacts provided: %d > %d", len(*contacts), ra.maxContactsPerReg)) } for _, contact := range *contacts { if contact == nil { return core.MalformedRequestError("Invalid contact") } if contact.Scheme != "mailto" { return core.MalformedRequestError(fmt.Sprintf("Contact method %s is not supported", contact.Scheme)) } if !core.IsASCII(contact.String()) { return core.MalformedRequestError( fmt.Sprintf("Contact email [%s] contains non-ASCII characters", contact.String())) } start := ra.clk.Now() ra.stats.Inc("RA.ValidateEmail.Calls", 1, 1.0) problem := validateEmail(ctx, contact.Opaque, ra.DNSResolver) ra.stats.TimingDuration("RA.ValidateEmail.Latency", ra.clk.Now().Sub(start), 1.0) if problem != nil { ra.stats.Inc("RA.ValidateEmail.Errors", 1, 1.0) return problem } ra.stats.Inc("RA.ValidateEmail.Successes", 1, 1.0) } return nil }
func (m *MailerImpl) generateMessage(to []string, subject, body string) ([]byte, error) { mid := m.csprgSource.generate() now := m.clk.Now().UTC() addrs := []string{} for _, a := range to { if !core.IsASCII(a) { return nil, fmt.Errorf("Non-ASCII email address") } addrs = append(addrs, strconv.Quote(a)) } headers := []string{ fmt.Sprintf("To: %s", strings.Join(addrs, ", ")), fmt.Sprintf("From: %s", m.from.String()), fmt.Sprintf("Subject: %s", subject), fmt.Sprintf("Date: %s", now.Format(time.RFC822)), fmt.Sprintf("Message-Id: <%s.%s.%s>", now.Format("20060102T150405"), mid.String(), m.from.Address), "MIME-Version: 1.0", "Content-Type: text/plain; charset=UTF-8", "Content-Transfer-Encoding: quoted-printable", } for i := range headers[1:] { // strip LFs headers[i] = strings.Replace(headers[i], "\n", "", -1) } bodyBuf := new(bytes.Buffer) mimeWriter := quotedprintable.NewWriter(bodyBuf) _, err := mimeWriter.Write([]byte(body)) if err != nil { return nil, err } err = mimeWriter.Close() if err != nil { return nil, err } return []byte(fmt.Sprintf( "%s\r\n\r\n%s\r\n", strings.Join(headers, "\r\n"), bodyBuf.String(), )), nil }