本文整理匯總了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,
)}
}