Skip to content

Commit

Permalink
feat: remove unused content disposition
Browse files Browse the repository at this point in the history
  • Loading branch information
theexiile1305 committed Sep 26, 2024
1 parent 8949360 commit 65b9fd0
Show file tree
Hide file tree
Showing 5 changed files with 0 additions and 107 deletions.
13 changes: 0 additions & 13 deletions encoding.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ type MIMEVersion string
// MIMEType represents the MIME type for the mail
type MIMEType string

// Disposition represents a content disposition for the Msg
type Disposition string

// List of supported encodings
const (
// EncodingB64 represents the Base64 encoding as specified in RFC 2045.
Expand Down Expand Up @@ -163,11 +160,6 @@ const (
MIMESMime MIMEType = `signed; protocol="application/pkcs7-signature"; micalg=sha256`
)

// List of common content disposition
const (
DispositionSMime Disposition = `attachment; filename="smime.p7s"`
)

// String is a standard method to convert an Charset into a printable format
func (c Charset) String() string {
return string(c)
Expand All @@ -182,8 +174,3 @@ func (c ContentType) String() string {
func (e Encoding) String() string {
return string(e)
}

// String is a standard method to convert an Disposition into a printable format
func (d Disposition) String() string {
return string(d)
}
19 changes: 0 additions & 19 deletions encoding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,22 +126,3 @@ func TestCharset_String(t *testing.T) {
})
}
}

// TestDisposition_String tests the string method of the Disposition object
func TestDisposition_String(t *testing.T) {
tests := []struct {
name string
d Disposition
want string
}{
{"Disposition: S/Mime", DispositionSMime, `attachment; filename="smime.p7s"`},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if tt.d.String() != tt.want {
t.Errorf("wrong string for Disposition returned. Expected: %s, got: %s",
tt.want, tt.d.String())
}
})
}
}
3 changes: 0 additions & 3 deletions msgwriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,9 +269,6 @@ func (mw *msgWriter) writePart(part *Part, charset Charset) {
if part.description != "" {
mimeHeader.Add(string(HeaderContentDescription), part.description)
}
if part.disposition != "" {
mimeHeader.Add(string(HeaderContentDisposition), part.disposition.String())
}
mimeHeader.Add(string(HeaderContentType), contentType)
mimeHeader.Add(string(HeaderContentTransferEnc), contentTransferEnc)
mw.newPart(mimeHeader)
Expand Down
18 changes: 0 additions & 18 deletions part.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ type Part struct {
contentType ContentType
charset Charset
description string
disposition Disposition
encoding Encoding
isDeleted bool
writeFunc func(io.Writer) (int64, error)
Expand Down Expand Up @@ -57,11 +56,6 @@ func (p *Part) GetDescription() string {
return p.description
}

// GetDisposition returns the currently set Content-Disposition of the Part
func (p *Part) GetDisposition() Disposition {
return p.disposition
}

// SetContent overrides the content of the Part with the given string
func (p *Part) SetContent(content string) {
buffer := bytes.NewBufferString(content)
Expand All @@ -88,11 +82,6 @@ func (p *Part) SetDescription(description string) {
p.description = description
}

// SetDisposition overrides the Content-Disposition of the Part
func (p *Part) SetDisposition(disposition Disposition) {
p.disposition = disposition
}

// SetWriteFunc overrides the WriteFunc of the Part
func (p *Part) SetWriteFunc(writeFunc func(io.Writer) (int64, error)) {
p.writeFunc = writeFunc
Expand Down Expand Up @@ -124,10 +113,3 @@ func WithPartContentDescription(description string) PartOption {
p.description = description
}
}

// WithContentDisposition overrides the default Part Content-Disposition
func WithContentDisposition(disposition Disposition) PartOption {
return func(p *Part) {
p.disposition = disposition
}
}
54 changes: 0 additions & 54 deletions part_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,35 +102,6 @@ func TestPart_WithPartContentDescription(t *testing.T) {
}
}

// TestPart_withContentDisposition tests the WithContentDisposition method
func TestPart_withContentDisposition(t *testing.T) {
tests := []struct {
name string
disposition Disposition
}{
{"Part disposition: test", "test"},
{"Part disposition: empty", ""},
}
for _, tt := range tests {
m := NewMsg()
t.Run(tt.name, func(t *testing.T) {
part := m.newPart(TypeTextPlain, WithContentDisposition(tt.disposition), nil)
if part == nil {
t.Errorf("newPart() WithPartContentDescription() failed: no part returned")
return
}
if part.disposition != tt.disposition {
t.Errorf("newPart() WithContentDisposition() failed: expected: %s, got: %s", tt.disposition, part.description)
}
part.disposition = ""
part.SetDisposition(tt.disposition)
if part.disposition != tt.disposition {
t.Errorf("newPart() SetDisposition() failed: expected: %s, got: %s", tt.disposition, part.description)
}
})
}
}

// TestPartContentType tests Part.SetContentType
func TestPart_SetContentType(t *testing.T) {
tests := []struct {
Expand Down Expand Up @@ -352,31 +323,6 @@ func TestPart_SetDescription(t *testing.T) {
}
}

// TestPart_SetDisposition tests Part.SetDisposition
func TestPart_SetDisposition(t *testing.T) {
c := "This is a test"
d := Disposition("test-disposition")
m := NewMsg()
m.SetBodyString(TypeTextPlain, c)
pl, err := getPartList(m)
if err != nil {
t.Errorf("failed: %s", err)
return
}
pd := pl[0].GetDisposition()
if pd != "" {
t.Errorf("Part.GetDisposition failed. Expected empty description but got: %s", pd)
}
pl[0].SetDisposition(d)
if pl[0].disposition != d {
t.Errorf("Part.SetDisposition failed. Expected description to be: %s, got: %s", d, pd)
}
pd = pl[0].GetDisposition()
if pd != d {
t.Errorf("Part.GetDisposition failed. Expected: %s, got: %s", d, pd)
}
}

// TestPart_Delete tests Part.Delete
func TestPart_Delete(t *testing.T) {
c := "This is a test with ümläutß"
Expand Down

0 comments on commit 65b9fd0

Please sign in to comment.