mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-22 05:40:50 +01:00
Add GetMessageID method to Msg
Introduced GetMessageID to retrieve the Message ID from the Msg
This commit is contained in:
parent
3bdb6f7cca
commit
69e211682c
2 changed files with 26 additions and 0 deletions
11
msg.go
11
msg.go
|
@ -476,6 +476,17 @@ func (m *Msg) SetMessageID() {
|
|||
m.SetMessageIDWithValue(messageID)
|
||||
}
|
||||
|
||||
// GetMessageID returns the message ID of the Msg as string value. If no message ID
|
||||
// is set, an empty string will be returned
|
||||
func (m *Msg) GetMessageID() string {
|
||||
if msgidheader, ok := m.genHeader[HeaderMessageID]; ok {
|
||||
if len(msgidheader) > 0 {
|
||||
return msgidheader[0]
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
// SetMessageIDWithValue sets the message id for the mail
|
||||
func (m *Msg) SetMessageIDWithValue(messageID string) {
|
||||
m.SetGenHeader(HeaderMessageID, fmt.Sprintf("<%s>", messageID))
|
||||
|
|
15
msg_test.go
15
msg_test.go
|
@ -805,6 +805,21 @@ func TestMsg_SetMessageIDRandomness(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestMsg_GetMessageID(t *testing.T) {
|
||||
expected := "this.is.a.message.id"
|
||||
msg := NewMsg()
|
||||
msg.SetMessageIDWithValue(expected)
|
||||
val := msg.GetMessageID()
|
||||
if !strings.EqualFold(val, fmt.Sprintf("<%s>", expected)) {
|
||||
t.Errorf("GetMessageID() failed. Expected: %s, got: %s", fmt.Sprintf("<%s>", expected), val)
|
||||
}
|
||||
msg.genHeader[HeaderMessageID] = nil
|
||||
val = msg.GetMessageID()
|
||||
if val != "" {
|
||||
t.Errorf("GetMessageID() failed. Expected empty string, got: %s", val)
|
||||
}
|
||||
}
|
||||
|
||||
// TestMsg_FromFormat tests the FromFormat and EnvelopeFrom methods for the Msg object
|
||||
func TestMsg_FromFormat(t *testing.T) {
|
||||
tests := []struct {
|
||||
|
|
Loading…
Reference in a new issue