do not add text/plain inline attachments as attachments to the comment

text/plain inline attachments are parsed into the body of the comment,
so we do not add them as an attachment to avoid duplicates

The test for the signature has been changed.
Messages are now no longer cut off after "-", "--" or "---", which may
cause some signatures to be added to the comment, but it's better to
add a little more rather than cut off important content. Everything
after more than 4 "-" are cut off.
"--" is used as a separator between inline attachments
"---" is also often used by users to separate paragraphs
This commit is contained in:
Beowulf 2024-05-13 22:25:06 +02:00
parent 3f14058a7a
commit 713eb62bc1
No known key found for this signature in database
GPG key ID: 44225F5F2792841D
2 changed files with 18 additions and 6 deletions

View file

@ -379,7 +379,7 @@ func getContentFromMailReader(env *enmime.Envelope) *MailContent {
}
inlineAttachments := make([]*Attachment, 0, len(env.Inlines))
for _, inline := range env.Inlines {
if inline.FileName != "" {
if inline.FileName != "" && inline.ContentType != "text/plain" {
inlineAttachments = append(inlineAttachments, &Attachment{
Name: inline.FileName,
Content: inline.Content,

View file

@ -125,15 +125,27 @@ func TestGetContentFromMailReader(t *testing.T) {
"Content-Disposition: inline; filename=attachment.txt\r\n" +
"\r\n" +
"attachment content\r\n" +
"--message-boundary\r\n" +
"Content-Type: text/html\r\n" +
"Content-Disposition: inline; filename=attachment.html\r\n" +
"\r\n" +
"<p>html attachment content</p>\r\n" +
"--message-boundary\r\n" +
"Content-Type: image/png\r\n" +
"Content-Disposition: inline; filename=attachment.png\r\n" +
"Content-Transfer-Encoding: base64\r\n" +
"\r\n" +
"iVBORw0KGgoAAAANSUhEUgAAAAgAAAAIAQMAAAD+wSzIAAAABlBMVEX///+/v7+jQ3Y5AAAADklEQVQI12P4AIX8EAgALgAD/aNpbtEAAAAASUVORK5CYII\r\n" +
"--message-boundary--\r\n"
env, err = enmime.ReadEnvelope(strings.NewReader(mailString))
assert.NoError(t, err)
content = getContentFromMailReader(env)
assert.Equal(t, "mail content", content.Content)
assert.Len(t, content.Attachments, 1)
assert.Equal(t, "attachment.txt", content.Attachments[0].Name)
assert.Equal(t, []byte("attachment content"), content.Attachments[0].Content)
assert.Equal(t, "mail content\n--\nattachment content", content.Content)
assert.Len(t, content.Attachments, 2)
assert.Equal(t, "attachment.html", content.Attachments[0].Name)
assert.Equal(t, []byte("<p>html attachment content</p>"), content.Attachments[0].Content)
assert.Equal(t, "attachment.png", content.Attachments[1].Name)
mailString = "Content-Type: multipart/mixed; boundary=message-boundary\r\n" +
"\r\n" +
@ -164,7 +176,7 @@ func TestGetContentFromMailReader(t *testing.T) {
"Content-Disposition: inline\r\n" +
"\r\n" +
"mail content without signature\r\n" +
"--\r\n" +
"----\r\n" +
"signature\r\n" +
"--text-boundary--\r\n" +
"--message-boundary--\r\n"