diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2021-04-20 06:25:08 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-04-19 18:25:08 -0400 |
commit | 9d99f6ab19ac3f97af3ca126720e9075c127a652 (patch) | |
tree | b817b4582a871f83b91ad7977fe772fc3501c1e8 /services/mailer/mail.go | |
parent | c9cc6698d2172625854cd063301e63602204a2a1 (diff) | |
download | gitea-9d99f6ab19ac3f97af3ca126720e9075c127a652.tar.gz gitea-9d99f6ab19ac3f97af3ca126720e9075c127a652.zip |
Refactor renders (#15175)
* Refactor renders
* Some performance optimization
* Fix comment
* Transform reader
* Fix csv test
* Fix test
* Fix tests
* Improve optimaziation
* Fix test
* Fix test
* Detect file encoding with reader
* Improve optimaziation
* reduce memory usage
* improve code
* fix build
* Fix test
* Fix for go1.15
* Fix render
* Fix comment
* Fix lint
* Fix test
* Don't use NormalEOF when unnecessary
* revert change on util.go
* Apply suggestions from code review
Co-authored-by: zeripath <art27@cantab.net>
* rename function
* Take NormalEOF back
Co-authored-by: zeripath <art27@cantab.net>
Diffstat (limited to 'services/mailer/mail.go')
-rw-r--r-- | services/mailer/mail.go | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/services/mailer/mail.go b/services/mailer/mail.go index c50795968a..f22140c9f7 100644 --- a/services/mailer/mail.go +++ b/services/mailer/mail.go @@ -174,8 +174,7 @@ func SendCollaboratorMail(u, doer *models.User, repo *models.Repository) { SendAsync(msg) } -func composeIssueCommentMessages(ctx *mailCommentContext, lang string, tos []string, fromMention bool, info string) []*Message { - +func composeIssueCommentMessages(ctx *mailCommentContext, lang string, tos []string, fromMention bool, info string) ([]*Message, error) { var ( subject string link string @@ -199,7 +198,14 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, tos []str } // This is the body of the new issue or comment, not the mail body - body := string(markup.RenderByType(markdown.MarkupName, []byte(ctx.Content), ctx.Issue.Repo.HTMLURL(), ctx.Issue.Repo.ComposeMetas())) + body, err := markdown.RenderString(&markup.RenderContext{ + URLPrefix: ctx.Issue.Repo.HTMLURL(), + Metas: ctx.Issue.Repo.ComposeMetas(), + }, ctx.Content) + if err != nil { + return nil, err + } + actType, actName, tplName := actionToTemplate(ctx.Issue, ctx.ActionType, commentType, reviewType) if actName != "new" { @@ -240,14 +246,13 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, tos []str // TODO: i18n templates? if err := subjectTemplates.ExecuteTemplate(&mailSubject, string(tplName), mailMeta); err == nil { subject = sanitizeSubject(mailSubject.String()) + if subject == "" { + subject = fallback + } } else { log.Error("ExecuteTemplate [%s]: %v", tplName+"/subject", err) } - if subject == "" { - subject = fallback - } - subject = emoji.ReplaceAliases(subject) mailMeta["Subject"] = subject @@ -275,7 +280,7 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, tos []str msgs = append(msgs, msg) } - return msgs + return msgs, nil } func sanitizeSubject(subject string) string { @@ -288,21 +293,26 @@ func sanitizeSubject(subject string) string { } // SendIssueAssignedMail composes and sends issue assigned email -func SendIssueAssignedMail(issue *models.Issue, doer *models.User, content string, comment *models.Comment, recipients []*models.User) { +func SendIssueAssignedMail(issue *models.Issue, doer *models.User, content string, comment *models.Comment, recipients []*models.User) error { langMap := make(map[string][]string) for _, user := range recipients { langMap[user.Language] = append(langMap[user.Language], user.Email) } for lang, tos := range langMap { - SendAsyncs(composeIssueCommentMessages(&mailCommentContext{ + msgs, err := composeIssueCommentMessages(&mailCommentContext{ Issue: issue, Doer: doer, ActionType: models.ActionType(0), Content: content, Comment: comment, - }, lang, tos, false, "issue assigned")) + }, lang, tos, false, "issue assigned") + if err != nil { + return err + } + SendAsyncs(msgs) } + return nil } // actionToTemplate returns the type and name of the action facing the user |