##// END OF EJS Templates
notifications: insert 'References' mail headers to help MUA threading...
Mads Kiilerich -
r4384:05294985 default
parent child Browse files
Show More
@@ -257,7 +257,7 b' def get_commits_stats(repo_name, ts_min_'
257
257
258 @task(ignore_result=True)
258 @task(ignore_result=True)
259 @dbsession
259 @dbsession
260 def send_email(recipients, subject, body='', html_body=''):
260 def send_email(recipients, subject, body='', html_body='', headers=None):
261 """
261 """
262 Sends an email with defined parameters from the .ini files.
262 Sends an email with defined parameters from the .ini files.
263
263
@@ -304,7 +304,7 b' def send_email(recipients, subject, body'
304 try:
304 try:
305 m = SmtpMailer(mail_from, user, passwd, mail_server, smtp_auth,
305 m = SmtpMailer(mail_from, user, passwd, mail_server, smtp_auth,
306 mail_port, ssl, tls, debug=debug)
306 mail_port, ssl, tls, debug=debug)
307 m.send(recipients, subject, body, html_body)
307 m.send(recipients, subject, body, html_body, headers=headers)
308 except:
308 except:
309 log.error('Mail sending failed')
309 log.error('Mail sending failed')
310 log.error(traceback.format_exc())
310 log.error(traceback.format_exc())
@@ -61,13 +61,13 b' class SmtpMailer(object):'
61 self.auth = smtp_auth
61 self.auth = smtp_auth
62
62
63 def send(self, recipients=[], subject='', body='', html='',
63 def send(self, recipients=[], subject='', body='', html='',
64 attachment_files=None):
64 attachment_files=None, headers=None):
65
65
66 if isinstance(recipients, basestring):
66 if isinstance(recipients, basestring):
67 recipients = [recipients]
67 recipients = [recipients]
68 headers = {
68 if headers is None:
69 'Date': formatdate(time.time())
69 headers = {}
70 }
70 headers.setdefault('Date', formatdate(time.time()))
71 msg = Message(subject, recipients, body, html, self.mail_from,
71 msg = Message(subject, recipients, body, html, self.mail_from,
72 recipients_separator=", ", extra_headers=headers)
72 recipients_separator=", ", extra_headers=headers)
73 raw_msg = msg.to_message()
73 raw_msg = msg.to_message()
@@ -82,7 +82,11 b' class ChangesetCommentsModel(BaseModel):'
82 cs = repo.scm_instance.get_changeset(revision)
82 cs = repo.scm_instance.get_changeset(revision)
83 desc = "%s" % (cs.short_id)
83 desc = "%s" % (cs.short_id)
84
84
85 _url = h.url('changeset_home',
85 revision_url = h.url('changeset_home',
86 repo_name=repo.repo_name,
87 revision=revision,
88 qualified=True,)
89 comment_url = h.url('changeset_home',
86 repo_name=repo.repo_name,
90 repo_name=repo.repo_name,
87 revision=revision,
91 revision=revision,
88 anchor='comment-%s' % comment.comment_id,
92 anchor='comment-%s' % comment.comment_id,
@@ -91,7 +95,7 b' class ChangesetCommentsModel(BaseModel):'
91 subj = safe_unicode(
95 subj = safe_unicode(
92 h.link_to('Re changeset: %(desc)s %(line)s' % \
96 h.link_to('Re changeset: %(desc)s %(line)s' % \
93 {'desc': desc, 'line': line},
97 {'desc': desc, 'line': line},
94 _url)
98 comment_url)
95 )
99 )
96 # get the current participants of this changeset
100 # get the current participants of this changeset
97 recipients = ChangesetComment.get_users(revision=revision)
101 recipients = ChangesetComment.get_users(revision=revision)
@@ -106,20 +110,25 b' class ChangesetCommentsModel(BaseModel):'
106 'cs_comment_user': h.person(user),
110 'cs_comment_user': h.person(user),
107 'cs_target_repo': h.url('summary_home', repo_name=repo.repo_name,
111 'cs_target_repo': h.url('summary_home', repo_name=repo.repo_name,
108 qualified=True),
112 qualified=True),
109 'cs_comment_url': _url,
113 'cs_comment_url': comment_url,
110 'raw_id': revision,
114 'raw_id': revision,
111 'message': cs.message,
115 'message': cs.message,
112 'repo_name': repo.repo_name,
116 'repo_name': repo.repo_name,
113 'short_id': h.short_id(revision),
117 'short_id': h.short_id(revision),
114 'branch': cs.branch,
118 'branch': cs.branch,
115 'comment_username': user.username,
119 'comment_username': user.username,
120 'threading': [revision_url, comment_url], # TODO: url to line number
116 }
121 }
117 #pull request
122 #pull request
118 elif pull_request:
123 elif pull_request:
119 notification_type = Notification.TYPE_PULL_REQUEST_COMMENT
124 notification_type = Notification.TYPE_PULL_REQUEST_COMMENT
120 desc = comment.pull_request.title
125 desc = comment.pull_request.title
121 _org_ref_type, org_ref_name, _org_rev = comment.pull_request.org_ref.split(':')
126 _org_ref_type, org_ref_name, _org_rev = comment.pull_request.org_ref.split(':')
122 _url = h.url('pullrequest_show',
127 pr_url = h.url('pullrequest_show',
128 repo_name=pull_request.other_repo.repo_name,
129 pull_request_id=pull_request.pull_request_id,
130 qualified=True,)
131 comment_url = h.url('pullrequest_show',
123 repo_name=pull_request.other_repo.repo_name,
132 repo_name=pull_request.other_repo.repo_name,
124 pull_request_id=pull_request.pull_request_id,
133 pull_request_id=pull_request.pull_request_id,
125 anchor='comment-%s' % comment.comment_id,
134 anchor='comment-%s' % comment.comment_id,
@@ -130,7 +139,7 b' class ChangesetCommentsModel(BaseModel):'
130 {'desc': desc,
139 {'desc': desc,
131 'pr_id': comment.pull_request.pull_request_id,
140 'pr_id': comment.pull_request.pull_request_id,
132 'line': line},
141 'line': line},
133 _url)
142 comment_url)
134 )
143 )
135 # get the current participants of this pull request
144 # get the current participants of this pull request
136 recipients = ChangesetComment.get_users(pull_request_id=
145 recipients = ChangesetComment.get_users(pull_request_id=
@@ -147,7 +156,7 b' class ChangesetCommentsModel(BaseModel):'
147 'pr_id': pull_request.pull_request_id,
156 'pr_id': pull_request.pull_request_id,
148 'status_change': status_change,
157 'status_change': status_change,
149 'closing_pr': closing_pr,
158 'closing_pr': closing_pr,
150 'pr_comment_url': _url,
159 'pr_comment_url': comment_url,
151 'pr_comment_user': h.person(user),
160 'pr_comment_user': h.person(user),
152 'pr_target_repo': h.url('summary_home',
161 'pr_target_repo': h.url('summary_home',
153 repo_name=pull_request.other_repo.repo_name,
162 repo_name=pull_request.other_repo.repo_name,
@@ -155,6 +164,7 b' class ChangesetCommentsModel(BaseModel):'
155 'repo_name': pull_request.other_repo.repo_name,
164 'repo_name': pull_request.other_repo.repo_name,
156 'ref': org_ref_name,
165 'ref': org_ref_name,
157 'comment_username': user.username,
166 'comment_username': user.username,
167 'threading': [pr_url, comment_url], # TODO: url to line number
158 }
168 }
159
169
160 return subj, body, recipients, notification_type, email_kwargs
170 return subj, body, recipients, notification_type, email_kwargs
@@ -114,6 +114,10 b' class NotificationModel(BaseModel):'
114 #don't send email to person who created this comment
114 #don't send email to person who created this comment
115 rec_objs = set(recipients_objs).difference(set([created_by_obj]))
115 rec_objs = set(recipients_objs).difference(set([created_by_obj]))
116
116
117 headers = None
118 if 'threading' in email_kwargs:
119 headers = {'References': ' '.join('<%s>' % x for x in email_kwargs['threading'])}
120
117 # send email with notification to all other participants
121 # send email with notification to all other participants
118 for rec in rec_objs:
122 for rec in rec_objs:
119 email_body = None # we set body to none, we just send HTML emails
123 email_body = None # we set body to none, we just send HTML emails
@@ -131,7 +135,7 b' class NotificationModel(BaseModel):'
131 .get_email_tmpl(type_, **kwargs)
135 .get_email_tmpl(type_, **kwargs)
132
136
133 run_task(tasks.send_email, [rec.email], email_subject, email_body,
137 run_task(tasks.send_email, [rec.email], email_subject, email_body,
134 email_body_html)
138 email_body_html, headers)
135
139
136 return notif
140 return notif
137
141
@@ -144,6 +144,7 b' class PullRequestModel(BaseModel):'
144 'pr_id': pr.pull_request_id,
144 'pr_id': pr.pull_request_id,
145 'ref': org_ref_name,
145 'ref': org_ref_name,
146 'pr_username': pr.author.username,
146 'pr_username': pr.author.username,
147 'threading': [pr_url],
147 }
148 }
148 NotificationModel().create(created_by=pr.author, subject=subject, body=body,
149 NotificationModel().create(created_by=pr.author, subject=subject, body=body,
149 recipients=reviewers,
150 recipients=reviewers,
General Comments 0
You need to be logged in to leave comments. Login now