You've already forked openaccounting-server
mirror of
https://github.com/openaccounting/oa-server.git
synced 2025-12-09 09:00:42 +13:00
mailgun dep
This commit is contained in:
42
vendor/github.com/mailgun/mailgun-go/v4/recipients.go
generated
vendored
Normal file
42
vendor/github.com/mailgun/mailgun-go/v4/recipients.go
generated
vendored
Normal file
@@ -0,0 +1,42 @@
|
||||
package mailgun
|
||||
|
||||
import "fmt"
|
||||
import "strings"
|
||||
|
||||
type Recipient struct {
|
||||
Name string `json:"-"`
|
||||
Email string `json:"-"`
|
||||
}
|
||||
|
||||
func (r Recipient) String() string {
|
||||
if r.Name != "" {
|
||||
return fmt.Sprintf("%s <%s>", r.Name, r.Email)
|
||||
}
|
||||
return r.Email
|
||||
}
|
||||
|
||||
// MarshalText satisfies TextMarshaler
|
||||
func (r Recipient) MarshalText() ([]byte, error) {
|
||||
return []byte(r.String()), nil
|
||||
}
|
||||
|
||||
// UnmarshalText satisfies TextUnmarshaler
|
||||
func (r *Recipient) UnmarshalText(text []byte) error {
|
||||
s := string(text)
|
||||
if s[len(s)-1:] != ">" {
|
||||
*r = Recipient{Email: s}
|
||||
return nil
|
||||
}
|
||||
|
||||
i := strings.Index(s, "<")
|
||||
// at least 1 char followed by a space
|
||||
if i < 2 {
|
||||
return fmt.Errorf("malformed recipient string '%s'", s)
|
||||
}
|
||||
*r = Recipient{
|
||||
Name: strings.TrimSpace(s[:i]),
|
||||
Email: s[i+1 : len(s)-1],
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user