mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-26 07:25:07 +01:00
Compare commits
No commits in common. "5c143cb74c08f606452d5c33be72fa919fc6e9d9" and "68e6284e4e23d6b24a2ce267acf655e6cba66906" have entirely different histories.
5c143cb74c
...
68e6284e4e
2 changed files with 0 additions and 63 deletions
13
msg.go
13
msg.go
|
@ -117,9 +117,6 @@ type Msg struct {
|
|||
|
||||
// sendError holds the SendError in case a Msg could not be delivered during the Client.Send operation
|
||||
sendError error
|
||||
|
||||
// noDefaultUserAgent indicates whether the default User Agent will be excluded for the Msg when it's sent.
|
||||
noDefaultUserAgent bool
|
||||
}
|
||||
|
||||
// SendmailPath is the default system path to the sendmail binary
|
||||
|
@ -195,13 +192,6 @@ func WithPGPType(t PGPType) MsgOption {
|
|||
}
|
||||
}
|
||||
|
||||
// WithNoDefaultUserAgent configures the Msg to not use the default User Agent
|
||||
func WithNoDefaultUserAgent() MsgOption {
|
||||
return func(m *Msg) {
|
||||
m.noDefaultUserAgent = true
|
||||
}
|
||||
}
|
||||
|
||||
// SetCharset sets the encoding charset of the Msg
|
||||
func (m *Msg) SetCharset(c Charset) {
|
||||
m.charset = c
|
||||
|
@ -1176,9 +1166,6 @@ func (m *Msg) setEncoder() {
|
|||
// checkUserAgent checks if a useragent/x-mailer is set and if not will set a default
|
||||
// version string
|
||||
func (m *Msg) checkUserAgent() {
|
||||
if m.noDefaultUserAgent {
|
||||
return
|
||||
}
|
||||
_, uaok := m.genHeader[HeaderUserAgent]
|
||||
_, xmok := m.genHeader[HeaderXMailer]
|
||||
if !uaok && !xmok {
|
||||
|
|
50
msg_test.go
50
msg_test.go
|
@ -3161,53 +3161,3 @@ func TestMsg_BccFromString(t *testing.T) {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsg_checkUserAgent tests the checkUserAgent method of the Msg
|
||||
func TestMsg_checkUserAgent(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
noDefaultUserAgent bool
|
||||
genHeader map[Header][]string
|
||||
wantUserAgent string
|
||||
sf bool
|
||||
}{
|
||||
{
|
||||
name: "check default user agent",
|
||||
noDefaultUserAgent: false,
|
||||
wantUserAgent: "go-mail v0.4.1 // https://github.com/wneessen/go-mail",
|
||||
sf: false,
|
||||
},
|
||||
{
|
||||
name: "check no default user agent",
|
||||
noDefaultUserAgent: true,
|
||||
wantUserAgent: "",
|
||||
sf: true,
|
||||
},
|
||||
{
|
||||
name: "check if ua and xm is already set",
|
||||
noDefaultUserAgent: false,
|
||||
genHeader: map[Header][]string{
|
||||
HeaderUserAgent: {"custom UA"},
|
||||
HeaderXMailer: {"custom XM"},
|
||||
},
|
||||
wantUserAgent: "custom UA",
|
||||
sf: false,
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
msg := &Msg{
|
||||
noDefaultUserAgent: tt.noDefaultUserAgent,
|
||||
genHeader: tt.genHeader,
|
||||
}
|
||||
msg.checkUserAgent()
|
||||
gotUserAgent := ""
|
||||
if val, ok := msg.genHeader[HeaderUserAgent]; ok {
|
||||
gotUserAgent = val[0] // Assuming the first one is the needed value
|
||||
}
|
||||
if gotUserAgent != tt.wantUserAgent && !tt.sf {
|
||||
t.Errorf("UserAgent got = %v, want = %v", gotUserAgent, tt.wantUserAgent)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue