@@ -33,8 +33,7 @@ func fallbackMailSubject(issue *issues_model.Issue) string {
33
33
return fmt .Sprintf ("[%s] %s (#%d)" , issue .Repo .FullName (), issue .Title , issue .Index )
34
34
}
35
35
36
- type mailCommentContext struct {
37
- context.Context
36
+ type mailComment struct {
38
37
Issue * issues_model.Issue
39
38
Doer * user_model.User
40
39
ActionType activities_model.ActionType
@@ -43,7 +42,7 @@ type mailCommentContext struct {
43
42
ForceDoerNotification bool
44
43
}
45
44
46
- func composeIssueCommentMessages (ctx * mailCommentContext , lang string , recipients []* user_model.User , fromMention bool , info string ) ([]* sender_service.Message , error ) {
45
+ func composeIssueCommentMessages (ctx context. Context , comment * mailComment , lang string , recipients []* user_model.User , fromMention bool , info string ) ([]* sender_service.Message , error ) {
47
46
var (
48
47
subject string
49
48
link string
@@ -54,44 +53,44 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
54
53
)
55
54
56
55
commentType := issues_model .CommentTypeComment
57
- if ctx .Comment != nil {
58
- commentType = ctx .Comment .Type
59
- link = ctx .Issue .HTMLURL () + "#" + ctx .Comment .HashTag ()
56
+ if comment .Comment != nil {
57
+ commentType = comment .Comment .Type
58
+ link = comment .Issue .HTMLURL () + "#" + comment .Comment .HashTag ()
60
59
} else {
61
- link = ctx .Issue .HTMLURL ()
60
+ link = comment .Issue .HTMLURL ()
62
61
}
63
62
64
63
reviewType := issues_model .ReviewTypeComment
65
- if ctx .Comment != nil && ctx .Comment .Review != nil {
66
- reviewType = ctx .Comment .Review .Type
64
+ if comment .Comment != nil && comment .Comment .Review != nil {
65
+ reviewType = comment .Comment .Review .Type
67
66
}
68
67
69
68
// This is the body of the new issue or comment, not the mail body
70
- rctx := renderhelper .NewRenderContextRepoComment (ctx . Context , ctx .Issue .Repo ).WithUseAbsoluteLink (true )
71
- body , err := markdown .RenderString (rctx , ctx .Content )
69
+ rctx := renderhelper .NewRenderContextRepoComment (ctx , comment .Issue .Repo ).WithUseAbsoluteLink (true )
70
+ body , err := markdown .RenderString (rctx , comment .Content )
72
71
if err != nil {
73
72
return nil , err
74
73
}
75
74
76
75
if setting .MailService .EmbedAttachmentImages {
77
- attEmbedder := newMailAttachmentBase64Embedder (ctx .Doer , ctx .Issue .Repo , maxEmailBodySize )
76
+ attEmbedder := newMailAttachmentBase64Embedder (comment .Doer , comment .Issue .Repo , maxEmailBodySize )
78
77
bodyAfterEmbedding , err := attEmbedder .Base64InlineImages (ctx , body )
79
78
if err != nil {
80
79
log .Error ("Failed to embed images in mail body: %v" , err )
81
80
} else {
82
81
body = bodyAfterEmbedding
83
82
}
84
83
}
85
- actType , actName , tplName := actionToTemplate (ctx .Issue , ctx .ActionType , commentType , reviewType )
84
+ actType , actName , tplName := actionToTemplate (comment .Issue , comment .ActionType , commentType , reviewType )
86
85
87
86
if actName != "new" {
88
87
prefix = "Re: "
89
88
}
90
- fallback = prefix + fallbackMailSubject (ctx .Issue )
89
+ fallback = prefix + fallbackMailSubject (comment .Issue )
91
90
92
- if ctx .Comment != nil && ctx .Comment .Review != nil {
91
+ if comment .Comment != nil && comment .Comment .Review != nil {
93
92
reviewComments = make ([]* issues_model.Comment , 0 , 10 )
94
- for _ , lines := range ctx .Comment .Review .CodeComments {
93
+ for _ , lines := range comment .Comment .Review .CodeComments {
95
94
for _ , comments := range lines {
96
95
reviewComments = append (reviewComments , comments ... )
97
96
}
@@ -104,12 +103,12 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
104
103
"FallbackSubject" : fallback ,
105
104
"Body" : body ,
106
105
"Link" : link ,
107
- "Issue" : ctx .Issue ,
108
- "Comment" : ctx .Comment ,
109
- "IsPull" : ctx .Issue .IsPull ,
110
- "User" : ctx .Issue .Repo .MustOwner (ctx ),
111
- "Repo" : ctx .Issue .Repo .FullName (),
112
- "Doer" : ctx .Doer ,
106
+ "Issue" : comment .Issue ,
107
+ "Comment" : comment .Comment ,
108
+ "IsPull" : comment .Issue .IsPull ,
109
+ "User" : comment .Issue .Repo .MustOwner (ctx ),
110
+ "Repo" : comment .Issue .Repo .FullName (),
111
+ "Doer" : comment .Doer ,
113
112
"IsMention" : fromMention ,
114
113
"SubjectPrefix" : prefix ,
115
114
"ActionType" : actType ,
@@ -140,22 +139,22 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
140
139
}
141
140
142
141
// Make sure to compose independent messages to avoid leaking user emails
143
- msgID := generateMessageIDForIssue (ctx .Issue , ctx .Comment , ctx .ActionType )
144
- reference := generateMessageIDForIssue (ctx .Issue , nil , activities_model .ActionType (0 ))
142
+ msgID := generateMessageIDForIssue (comment .Issue , comment .Comment , comment .ActionType )
143
+ reference := generateMessageIDForIssue (comment .Issue , nil , activities_model .ActionType (0 ))
145
144
146
145
var replyPayload []byte
147
- if ctx .Comment != nil {
148
- if ctx .Comment .Type .HasMailReplySupport () {
149
- replyPayload , err = incoming_payload .CreateReferencePayload (ctx .Comment )
146
+ if comment .Comment != nil {
147
+ if comment .Comment .Type .HasMailReplySupport () {
148
+ replyPayload , err = incoming_payload .CreateReferencePayload (comment .Comment )
150
149
}
151
150
} else {
152
- replyPayload , err = incoming_payload .CreateReferencePayload (ctx .Issue )
151
+ replyPayload , err = incoming_payload .CreateReferencePayload (comment .Issue )
153
152
}
154
153
if err != nil {
155
154
return nil , err
156
155
}
157
156
158
- unsubscribePayload , err := incoming_payload .CreateReferencePayload (ctx .Issue )
157
+ unsubscribePayload , err := incoming_payload .CreateReferencePayload (comment .Issue )
159
158
if err != nil {
160
159
return nil , err
161
160
}
@@ -164,7 +163,7 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
164
163
for _ , recipient := range recipients {
165
164
msg := sender_service .NewMessageFrom (
166
165
recipient .Email ,
167
- fromDisplayName (ctx .Doer ),
166
+ fromDisplayName (comment .Doer ),
168
167
setting .MailService .FromEmail ,
169
168
subject ,
170
169
mailBody .String (),
@@ -175,7 +174,7 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
175
174
msg .SetHeader ("In-Reply-To" , reference )
176
175
177
176
references := []string {reference }
178
- listUnsubscribe := []string {"<" + ctx .Issue .HTMLURL () + ">" }
177
+ listUnsubscribe := []string {"<" + comment .Issue .HTMLURL () + ">" }
179
178
180
179
if setting .IncomingEmail .Enabled {
181
180
if replyPayload != nil {
@@ -203,7 +202,7 @@ func composeIssueCommentMessages(ctx *mailCommentContext, lang string, recipient
203
202
msg .SetHeader ("References" , references ... )
204
203
msg .SetHeader ("List-Unsubscribe" , listUnsubscribe ... )
205
204
206
- for key , value := range generateAdditionalHeaders (ctx , actType , recipient ) {
205
+ for key , value := range generateAdditionalHeaders (comment , actType , recipient ) {
207
206
msg .SetHeader (key , value )
208
207
}
209
208
@@ -303,7 +302,7 @@ func generateMessageIDForIssue(issue *issues_model.Issue, comment *issues_model.
303
302
return fmt .Sprintf ("<%s/%s/%d%s@%s>" , issue .Repo .FullName (), path , issue .Index , extra , setting .Domain )
304
303
}
305
304
306
- func generateAdditionalHeaders (ctx * mailCommentContext , reason string , recipient * user_model.User ) map [string ]string {
305
+ func generateAdditionalHeaders (ctx * mailComment , reason string , recipient * user_model.User ) map [string ]string {
307
306
repo := ctx .Issue .Repo
308
307
309
308
return map [string ]string {
0 commit comments