本文整理汇总了Golang中net/mail.Header.AddressList方法的典型用法代码示例。如果您正苦于以下问题:Golang Header.AddressList方法的具体用法?Golang Header.AddressList怎么用?Golang Header.AddressList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net/mail.Header
的用法示例。
在下文中一共展示了Header.AddressList方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: headToAddy
// headToAddy parses a header containing email addresses
func headToAddy(h mail.Header, header string) (addys []string) {
_, exists := h[header]
if !exists {
return
}
addyList, err := h.AddressList(header)
if err != nil {
Warn.Printf("Failed to parse header: %s", header)
}
for _, addy := range addyList {
addys = append(addys, addy.Address)
}
return
}
示例2: parseFrom
// parseFrom takes a mail address of the format Name <[email protected]> and validates
// it. If custom From headers are not allowed, it will be tweaked to conform
// with the Remailer's configuration.
func parseFrom(h mail.Header) []string {
from, err := h.AddressList("From")
if err != nil {
// The supplied address is invalid. Use defaults instead.
return []string{fmt.Sprintf(
"%s <%s>",
cfg.Mail.OutboundName,
cfg.Mail.OutboundAddy,
)}
}
if len(from) == 0 {
// The address list is empty so return defaults
return []string{fmt.Sprintf(
"%s <%s>",
cfg.Mail.OutboundName,
cfg.Mail.OutboundAddy,
)}
}
if cfg.Mail.CustomFrom {
// Accept whatever was provided (it's already been validated by
// AddressList).
return []string{fmt.Sprintf(
"%s <%s>",
from[0].Name,
from[0].Address,
)}
}
if len(from[0].Name) == 0 {
return []string{fmt.Sprintf(
"%s <%s>",
cfg.Mail.OutboundName,
cfg.Mail.OutboundAddy,
)}
}
return []string{fmt.Sprintf(
"%s <%s>",
from[0].Name,
cfg.Mail.OutboundAddy,
)}
}