Replace reply with a forked version to fix the cut-off of the incoming mail text (#3747)
replace reply with forgejos forked version
If plain text is selected as the message format in e.g. Apple Mail, the inline attachments are no longer at the end of the mail, but instead directly where they are in the mail. When parsing the mail, these inline attachments are replaced by "--". The new reply version no longer cuts the text at the first "--".
Tests for this are present in reply (7dc5750c6d
).
Fixes https://codeberg.org/forgejo/forgejo/issues/3496#issuecomment-1798416
---
Additionally, I reduced the allocations for the inline attachments.
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/3747
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Co-authored-by: Beowulf <beowulf@beocode.eu>
Co-committed-by: Beowulf <beowulf@beocode.eu>
This commit is contained in:
parent
d09a6d130c
commit
2810b9ae0a
5 changed files with 30 additions and 17 deletions
|
@ -17,7 +17,7 @@ import (
|
|||
"code.gitea.io/gitea/modules/setting"
|
||||
"code.gitea.io/gitea/services/mailer/token"
|
||||
|
||||
"github.com/dimiro1/reply"
|
||||
"code.forgejo.org/forgejo/reply"
|
||||
"github.com/emersion/go-imap"
|
||||
"github.com/emersion/go-imap/client"
|
||||
"github.com/jhillyerd/enmime"
|
||||
|
@ -377,9 +377,10 @@ func getContentFromMailReader(env *enmime.Envelope) *MailContent {
|
|||
Content: attachment.Content,
|
||||
})
|
||||
}
|
||||
inlineAttachments := make([]*Attachment, 0, len(env.Inlines))
|
||||
for _, inline := range env.Inlines {
|
||||
if inline.FileName != "" {
|
||||
attachments = append(attachments, &Attachment{
|
||||
if inline.FileName != "" && inline.ContentType != "text/plain" {
|
||||
inlineAttachments = append(inlineAttachments, &Attachment{
|
||||
Name: inline.FileName,
|
||||
Content: inline.Content,
|
||||
})
|
||||
|
@ -388,6 +389,6 @@ func getContentFromMailReader(env *enmime.Envelope) *MailContent {
|
|||
|
||||
return &MailContent{
|
||||
Content: reply.FromText(env.Text),
|
||||
Attachments: attachments,
|
||||
Attachments: append(attachments, inlineAttachments...),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue