mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-22 13:50:49 +01:00
feat: add flag smime for indicating that the part should be marked for singing with S/MIME
This commit is contained in:
parent
65b9fd07da
commit
3154649420
2 changed files with 62 additions and 0 deletions
18
part.go
18
part.go
|
@ -20,6 +20,7 @@ type Part struct {
|
|||
encoding Encoding
|
||||
isDeleted bool
|
||||
writeFunc func(io.Writer) (int64, error)
|
||||
smime bool
|
||||
}
|
||||
|
||||
// GetContent executes the WriteFunc of the Part and returns the content as byte slice
|
||||
|
@ -56,6 +57,11 @@ func (p *Part) GetDescription() string {
|
|||
return p.description
|
||||
}
|
||||
|
||||
// IsSMimeSigned returns true if the Part should be singed with S/MIME
|
||||
func (p *Part) IsSMimeSigned() bool {
|
||||
return p.smime
|
||||
}
|
||||
|
||||
// SetContent overrides the content of the Part with the given string
|
||||
func (p *Part) SetContent(content string) {
|
||||
buffer := bytes.NewBufferString(content)
|
||||
|
@ -82,6 +88,11 @@ func (p *Part) SetDescription(description string) {
|
|||
p.description = description
|
||||
}
|
||||
|
||||
// SetIsSMimeSigned sets the flag for signing the Part with S/MIME
|
||||
func (p *Part) SetIsSMimeSigned(smime bool) {
|
||||
p.smime = smime
|
||||
}
|
||||
|
||||
// SetWriteFunc overrides the WriteFunc of the Part
|
||||
func (p *Part) SetWriteFunc(writeFunc func(io.Writer) (int64, error)) {
|
||||
p.writeFunc = writeFunc
|
||||
|
@ -113,3 +124,10 @@ func WithPartContentDescription(description string) PartOption {
|
|||
p.description = description
|
||||
}
|
||||
}
|
||||
|
||||
// WithSMimeSinging overrides the flag for signing the Part with S/MIME
|
||||
func WithSMimeSinging() PartOption {
|
||||
return func(p *Part) {
|
||||
p.smime = true
|
||||
}
|
||||
}
|
||||
|
|
44
part_test.go
44
part_test.go
|
@ -102,6 +102,24 @@ func TestPart_WithPartContentDescription(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestPart_WithSMimeSinging tests the WithSMimeSinging method
|
||||
func TestPart_WithSMimeSinging(t *testing.T) {
|
||||
m := NewMsg()
|
||||
part := m.newPart(TypeTextPlain, WithSMimeSinging())
|
||||
if part == nil {
|
||||
t.Errorf("newPart() WithSMimeSinging() failed: no part returned")
|
||||
return
|
||||
}
|
||||
if part.smime != true {
|
||||
t.Errorf("newPart() WithSMimeSinging() failed: expected: %v, got: %v", true, part.smime)
|
||||
}
|
||||
part.smime = true
|
||||
part.SetIsSMimeSigned(false)
|
||||
if part.smime != false {
|
||||
t.Errorf("newPart() SetIsSMimeSigned() failed: expected: %v, got: %v", false, part.smime)
|
||||
}
|
||||
}
|
||||
|
||||
// TestPartContentType tests Part.SetContentType
|
||||
func TestPart_SetContentType(t *testing.T) {
|
||||
tests := []struct {
|
||||
|
@ -245,6 +263,32 @@ func TestPart_GetContentBroken(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
// TestPart_IsSMimeSigned tests Part.IsSMimeSigned
|
||||
func TestPart_IsSMimeSigned(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
want bool
|
||||
}{
|
||||
{"smime:", true},
|
||||
{"smime:", false},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
m := NewMsg()
|
||||
pl, err := getPartList(m)
|
||||
if err != nil {
|
||||
t.Errorf("failed: %s", err)
|
||||
return
|
||||
}
|
||||
pl[0].SetIsSMimeSigned(tt.want)
|
||||
smime := pl[0].IsSMimeSigned()
|
||||
if smime != tt.want {
|
||||
t.Errorf("SetContentType failed. Got: %v, expected: %v", smime, tt.want)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// TestPart_SetWriteFunc tests Part.SetWriteFunc
|
||||
func TestPart_SetWriteFunc(t *testing.T) {
|
||||
c := "This is a test with ümläutß"
|
||||
|
|
Loading…
Reference in a new issue