1
1
mirror of https://github.com/go-gitea/gitea synced 2025-07-22 18:28:37 +00:00

Email option to embed images as base64 instead of link (#32061)

ref: #15081
ref: #14037

Documentation: https://gitea.com/gitea/docs/pulls/69

# Example
Content:

![image](https://github.com/user-attachments/assets/e73ebfbe-e329-40f6-9c4a-f73832bbb181)
Result in Email:

![image](https://github.com/user-attachments/assets/55b7019f-e17a-46c3-a374-3b4769d5c2d6)
Result with source code:
(first image is external image, 2nd is now embedded)

![image](https://github.com/user-attachments/assets/8e2804a1-580f-4a69-adcb-cc5d16f7da81)

---------

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
sommerf-lf
2025-03-05 17:29:29 +01:00
committed by GitHub
parent f0f10413ae
commit 7cdde20c73
7 changed files with 328 additions and 28 deletions

View File

@@ -25,6 +25,10 @@ import (
"code.gitea.io/gitea/services/mailer/token"
)
// maxEmailBodySize is the approximate maximum size of an email body in bytes
// Many e-mail service providers have limitations on the size of the email body, it's usually from 10MB to 25MB
const maxEmailBodySize = 9_000_000
func fallbackMailSubject(issue *issues_model.Issue) string {
return fmt.Sprintf("[%s] %s (#%d)", issue.Repo.FullName(), issue.Title, issue.Index)
}
@@ -64,12 +68,20 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
// This is the body of the new issue or comment, not the mail body
rctx := renderhelper.NewRenderContextRepoComment(ctx.Context, ctx.Issue.Repo).WithUseAbsoluteLink(true)
body, err := markdown.RenderString(rctx,
ctx.Content)
body, err := markdown.RenderString(rctx, ctx.Content)
if err != nil {
return nil, err
}
if setting.MailService.EmbedAttachmentImages {
attEmbedder := newMailAttachmentBase64Embedder(ctx.Doer, ctx.Issue.Repo, maxEmailBodySize)
bodyAfterEmbedding, err := attEmbedder.Base64InlineImages(ctx, body)
if err != nil {
log.Error("Failed to embed images in mail body: %v", err)
} else {
body = bodyAfterEmbedding
}
}
actType, actName, tplName := actionToTemplate(ctx.Issue, ctx.ActionType, commentType, reviewType)
if actName != "new" {