当前位置: 首页>>代码示例>>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;未经允许,请勿转载。