當前位置: 首頁>>代碼示例>>Golang>>正文


Golang mail.ParseAddressList函數代碼示例

本文整理匯總了Golang中net/mail.ParseAddressList函數的典型用法代碼示例。如果您正苦於以下問題:Golang ParseAddressList函數的具體用法?Golang ParseAddressList怎麽用?Golang ParseAddressList使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了ParseAddressList函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: saveHeaderFields

func (g *Gmail) saveHeaderFields(headerValue string) {

	emails, err := mail.ParseAddressList(headerValue)
	if err != nil {
		log.Println("Unable to parse:", headerValue)
	} else {

		for _, v := range emails {

			name := v.Name
			email := v.Address

			if !g.isKnownEmail(email) {

				err := errors.New("")
				err = g.db.SetContact(name, email)

				if err != nil {
					log.Println("Unable to save email:", email)
				}
			} else {
				log.Println("Known email. Ignoring:", email)
			}
		}
	}
}
開發者ID:vcollak,項目名稱:GmailContacts,代碼行數:26,代碼來源:gmailClient.go

示例2: AddressList

// AddressList returns a mail.Address slice with RFC 2047 encoded encoded names.
func (m *MIMEBody) AddressList(key string) ([]*mail.Address, error) {
	isAddrHeader := false
	for _, hkey := range AddressHeaders {
		if strings.ToLower(hkey) == strings.ToLower(key) {
			isAddrHeader = true
			break
		}
	}
	if !isAddrHeader {
		return nil, fmt.Errorf("%s is not address header", key)
	}

	str := DecodeToUTF8Base64Header(m.header.Get(key))
	if str == "" {
		return nil, mail.ErrHeaderNotPresent
	}
	// These statements are handy for debugging ParseAddressList errors
	// fmt.Println("in:  ", m.header.Get(key))
	// fmt.Println("out: ", str)
	ret, err := mail.ParseAddressList(str)
	if err != nil {
		return nil, err
	}
	return ret, nil
}
開發者ID:davrux,項目名稱:go.enmime,代碼行數:26,代碼來源:mail.go

示例3: getMultipleAddress

func getMultipleAddress(raw string) []*mail.Address {
	addr, err := mail.ParseAddressList(raw)
	if err != nil {
		return nil
	}
	return addr
}
開發者ID:johnweldon,項目名稱:go-misc,代碼行數:7,代碼來源:sendgrid.go

示例4: TestAddBccRecipients

func TestAddBccRecipients(t *testing.T) {
	m := NewMail()
	emails, _ := mail.ParseAddressList("Joe <[email protected]>, Doe <[email protected]>")
	m.AddBccRecipients(emails)
	if len(m.Bcc) != 2 {
		t.Errorf("AddBccRecipients should append to SGMail.Bcc")
	}
}
開發者ID:yudppp,項目名稱:sendgrid-go,代碼行數:8,代碼來源:mail_test.go

示例5: parseRecipients

func parseRecipients(input *string) []*mail.Address {
	recipients, err := mail.ParseAddressList(*input)
	if err != nil {
		return []*mail.Address{}
	}

	log.Println("Recipients are", recipients)
	return recipients
}
開發者ID:tianlai,項目名稱:mailcli,代碼行數:9,代碼來源:mailcli.go

示例6: buildCCs

func buildCCs(m *Message) []*mail.Address {
	cc, err := mail.ParseAddressList(m.CCs)
	if err != nil {
		cc = []*mail.Address{}
	}
	to, err := mail.ParseAddressList(m.To)
	if err != nil {
		to = []*mail.Address{}
	}
	all := append(to, cc...)
	ret := make([]*mail.Address, 0)
	for _, e := range all {
		if !isMe(e) {
			ret = append(ret, e)
		}
	}
	return ret
}
開發者ID:deweerdt,項目名稱:amua,代碼行數:18,代碼來源:message.go

示例7: String

func (m *Mailer) String() (string, error) {
	message, header := "", make(map[string]string)

	headers := map[string][]string{
		"From": []string{m.Mail.From},
		"To":   m.Mail.To,
		"Cc":   m.Mail.Cc,
		"Bcc":  m.Mail.Bcc,
	}

	for key, addresses := range headers {
		formated_addresses := []string{}
		for _, address := range addresses {
			parsed_addresses, err := mail.ParseAddressList(address)
			if err == nil {
				for _, parsed_address := range parsed_addresses {
					if len(parsed_address.Name) > 0 {
						formated_addresses = append(formated_addresses, fmt.Sprintf("%v <%v>", parsed_address.Name, parsed_address.Address))
					} else {
						formated_addresses = append(formated_addresses, fmt.Sprintf("%v", parsed_address.Address))
					}
				}
			}
		}
		header[key] = strings.Join(formated_addresses, ", ")
	}

	header["Subject"] = m.Mail.Subject
	header["MIME-Version"] = "1.0"
	header["Content-Type"] = m.contentType()
	header["Content-Transfer-Encoding"] = m.contentTransferEncoding()

	for k, v := range header {
		if len(v) > 0 {
			message += fmt.Sprintf("%s: %s\r\n", k, v)
		}
	}

	if len(m.Mail.Bodys) == 0 {
		m.Body("")
	}

	for _, body := range m.Mail.Bodys {
		message += m.crlfBoundary()
		message += body.Encode() + "\r\n"
	}

	for _, attachment := range m.Mail.Attachments {
		message += m.crlfBoundary()
		message += attachment.Encode() + "\r\n"
	}

	message += m.endBoundary()

	return message, nil
}
開發者ID:dulumao,項目名稱:mail-3,代碼行數:56,代碼來源:mailer.go

示例8: TestAddRecipients

func TestAddRecipients(t *testing.T) {
	m := NewMail()
	emails, _ := mail.ParseAddressList("Joe <[email protected]>, Doe <[email protected]>")
	m.AddRecipients(emails)
	switch {
	case len(m.To) != 2:
		t.Errorf("AddRecipients should append to SGMail.To")
	case len(m.ToName) != 2:
		t.Errorf("AddRecipients should append to SGMail.ToName if a valid email is supplied")
	}
}
開發者ID:yudppp,項目名稱:sendgrid-go,代碼行數:11,代碼來源:mail_test.go

示例9: parseMultiExpressiveEmails

// Given a string like "Cathal Garvey <[email protected]>, Stephen Barr <[email protected]>"
// return []string{"Cathal Garvey <[email protected]>", "Stephen Barr <[email protected]>"}
func parseMultiExpressiveEmails(entry string) ([]string, error) {
	out := make([]string, 0)
	parsed, err := mail.ParseAddressList(entry)
	if err != nil {
		return nil, err
	}
	for _, m := range parsed {
		out = append(out, m.String())
	}
	return out, nil
}
開發者ID:cathalgarvey,項目名稱:listless,代碼行數:13,代碼來源:email.go

示例10: ParseAddressList

// ParseAddressList splits a comma separated list of addresses
// into multiple email addresses. The returned addresses can be
// used to call Send().
func ParseAddressList(s string) ([]string, error) {
	addrs, err := mail.ParseAddressList(s)
	if err != nil {
		return nil, err
	}
	return generic.Map(addrs, func(addr *mail.Address) string {
		if addr.Name != "" {
			return fmt.Sprintf("%s <%s>", addr.Name, addr.Address)
		}
		return addr.Address
	}).([]string), nil
}
開發者ID:rainycape,項目名稱:gondola,代碼行數:15,代碼來源:mail.go

示例11: ParseAddressList

func ParseAddressList() {
	const list = `[email protected], Alice <[email protected]>, "Bob Uncle" <[email protected]>, "Yang-Tan, Eve" <[email protected]>`
	emails, err := mail.ParseAddressList(list)
	if err != nil {
		log.Fatal(err)
	}

	for _, v := range emails {
		fmt.Println(v.Name, "=>", v.Address)
	}

}
開發者ID:suntong,項目名稱:lang,代碼行數:12,代碼來源:ParseAddress.go

示例12: NewMessageDebug

// Create a new email message, returning any reasons for failure.
func NewMessageDebug(from, to, subject, body string) (*Message, error) {
	fromAddress, err := mail.ParseAddress(from)
	if err != nil {
		return nil, errors.New("Invalid from address; " + err.Error())
	}

	toAddresses, err := mail.ParseAddressList(to)
	if err != nil {
		return nil, errors.New("Invalid to address(es); " + err.Error())
	}

	return &Message{fromAddress, &AddressList{toAddresses}, subject, body}, nil
}
開發者ID:paulchiu,項目名稱:gone-lib,代碼行數:14,代碼來源:message.go

示例13: validateEmail

func validateEmail(ctx context.Context, address string, resolver bdns.DNSResolver) (prob *probs.ProblemDetails) {
	emails, err := mail.ParseAddressList(address)
	if err != nil {
		return &probs.ProblemDetails{
			Type:   probs.InvalidEmailProblem,
			Detail: unparseableEmailDetail,
		}
	}
	if len(emails) > 1 {
		return &probs.ProblemDetails{
			Type:   probs.InvalidEmailProblem,
			Detail: multipleAddressDetail,
		}
	}
	splitEmail := strings.SplitN(emails[0].Address, "@", -1)
	domain := strings.ToLower(splitEmail[len(splitEmail)-1])
	var resultMX []string
	var resultA []net.IP
	var errMX, errA error
	var wg sync.WaitGroup
	wg.Add(2)
	go func() {
		resultMX, errMX = resolver.LookupMX(ctx, domain)
		wg.Done()
	}()
	go func() {
		resultA, errA = resolver.LookupHost(ctx, domain)
		wg.Done()
	}()
	wg.Wait()

	if errMX != nil {
		prob := bdns.ProblemDetailsFromDNSError(errMX)
		prob.Type = probs.InvalidEmailProblem
		return prob
	} else if len(resultMX) > 0 {
		return nil
	}
	if errA != nil {
		prob := bdns.ProblemDetailsFromDNSError(errA)
		prob.Type = probs.InvalidEmailProblem
		return prob
	} else if len(resultA) > 0 {
		return nil
	}

	return &probs.ProblemDetails{
		Type:   probs.InvalidEmailProblem,
		Detail: emptyDNSResponseDetail,
	}
}
開發者ID:patf,項目名稱:boulder,代碼行數:51,代碼來源:registration-authority.go

示例14: Write

func (w EMailWriter) Write(rs ...models.ScanResult) (err error) {
	conf := config.Conf
	to := strings.Join(conf.EMail.To[:], ", ")
	cc := strings.Join(conf.EMail.Cc[:], ", ")
	mailAddresses := append(conf.EMail.To, conf.EMail.Cc...)
	if _, err := mail.ParseAddressList(strings.Join(mailAddresses[:], ", ")); err != nil {
		return fmt.Errorf("Failed to parse email addresses: %s", err)
	}

	for _, r := range rs {
		subject := fmt.Sprintf("%s%s %s",
			conf.EMail.SubjectPrefix,
			r.ServerInfo(),
			r.CveSummary(),
		)

		headers := make(map[string]string)
		headers["From"] = conf.EMail.From
		headers["To"] = to
		headers["Cc"] = cc
		headers["Subject"] = subject
		headers["Date"] = time.Now().Format(time.RFC1123Z)
		headers["Content-Type"] = "text/plain; charset=utf-8"

		var message string
		for k, v := range headers {
			message += fmt.Sprintf("%s: %s\r\n", k, v)
		}
		message += "\r\n" + toFullPlainText(r)

		smtpServer := net.JoinHostPort(conf.EMail.SMTPAddr, conf.EMail.SMTPPort)
		err = smtp.SendMail(
			smtpServer,
			smtp.PlainAuth(
				"",
				conf.EMail.User,
				conf.EMail.Password,
				conf.EMail.SMTPAddr,
			),
			conf.EMail.From,
			conf.EMail.To,
			[]byte(message),
		)

		if err != nil {
			return fmt.Errorf("Failed to send emails: %s", err)
		}
	}
	return nil
}
開發者ID:ymomoi,項目名稱:vuls,代碼行數:50,代碼來源:email.go

示例15: checkContactEmail

// checkContactEmail checks the specified Contact Email and sets an appropriate erorr message
// if there's something wrong with it.
// Returns true if email is acceptable (valid or empty).
func checkContactEmail(p *page.Params, email string) (ok bool) {
	if email == "" {
		return true
	}
	if len(email) > 500 {
		p.ErrorMsg = template.HTML(`<span class="code">Contact email</span> is too long! (cannot be longer than 500 characters)`)
		return false
	}

	if _, err := mail.ParseAddressList(email); err != nil {
		p.ErrorMsg = template.HTML(`Invalid <span class="code">Contact email</span>!`)
		return false
	}
	return true
}
開發者ID:icza,項目名稱:iczagps,代碼行數:18,代碼來源:common.go


注:本文中的net/mail.ParseAddressList函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。