package goog

import (
	"net/mail"
	"strings"
)

// GetAddress is the From header. mail.Address does the RFC 5322 quoting and
// RFC 2047 encoding a display name needs: sprintf-ing it together emits a bare
// 8-bit name for "Renée", and silently splits the address into two recipients
// for "Doe, Jane". Both matter now that every send builds its own headers.
func (c *Client) GetAddress() string {
	return c.FromAddress("")
}

// FromAddress is GetAddress with a per-send display name; empty falls back to
// the name the client was built with.
func (c *Client) FromAddress(name string) string {
	name = strings.TrimSpace(name)
	if name == "" {
		name = strings.TrimSpace(c.FirstName + " " + c.LastName)
	}
	addr := mail.Address{Name: name, Address: c.Email}
	return addr.String()
}
