# HG changeset patch # User Mads Kiilerich # Date 1405704121 -7200 # Node ID 0529498575ce28072933f54801947fb275530054 # Parent 2bb17f6f3044175e5b684a47f4c4784af221afe6 notifications: insert 'References' mail headers to help MUA threading gmail is however fubar. diff -r 2bb17f6f3044 -r 0529498575ce kallithea/lib/celerylib/tasks.py --- a/kallithea/lib/celerylib/tasks.py Fri Jul 18 19:22:01 2014 +0200 +++ b/kallithea/lib/celerylib/tasks.py Fri Jul 18 19:22:01 2014 +0200 @@ -257,7 +257,7 @@ @task(ignore_result=True) @dbsession -def send_email(recipients, subject, body='', html_body=''): +def send_email(recipients, subject, body='', html_body='', headers=None): """ Sends an email with defined parameters from the .ini files. @@ -304,7 +304,7 @@ try: m = SmtpMailer(mail_from, user, passwd, mail_server, smtp_auth, mail_port, ssl, tls, debug=debug) - m.send(recipients, subject, body, html_body) + m.send(recipients, subject, body, html_body, headers=headers) except: log.error('Mail sending failed') log.error(traceback.format_exc()) diff -r 2bb17f6f3044 -r 0529498575ce kallithea/lib/rcmail/smtp_mailer.py --- a/kallithea/lib/rcmail/smtp_mailer.py Fri Jul 18 19:22:01 2014 +0200 +++ b/kallithea/lib/rcmail/smtp_mailer.py Fri Jul 18 19:22:01 2014 +0200 @@ -61,13 +61,13 @@ self.auth = smtp_auth def send(self, recipients=[], subject='', body='', html='', - attachment_files=None): + attachment_files=None, headers=None): if isinstance(recipients, basestring): recipients = [recipients] - headers = { - 'Date': formatdate(time.time()) - } + if headers is None: + headers = {} + headers.setdefault('Date', formatdate(time.time())) msg = Message(subject, recipients, body, html, self.mail_from, recipients_separator=", ", extra_headers=headers) raw_msg = msg.to_message() diff -r 2bb17f6f3044 -r 0529498575ce kallithea/model/comment.py --- a/kallithea/model/comment.py Fri Jul 18 19:22:01 2014 +0200 +++ b/kallithea/model/comment.py Fri Jul 18 19:22:01 2014 +0200 @@ -82,7 +82,11 @@ cs = repo.scm_instance.get_changeset(revision) desc = "%s" % (cs.short_id) - _url = h.url('changeset_home', + revision_url = h.url('changeset_home', + repo_name=repo.repo_name, + revision=revision, + qualified=True,) + comment_url = h.url('changeset_home', repo_name=repo.repo_name, revision=revision, anchor='comment-%s' % comment.comment_id, @@ -91,7 +95,7 @@ subj = safe_unicode( h.link_to('Re changeset: %(desc)s %(line)s' % \ {'desc': desc, 'line': line}, - _url) + comment_url) ) # get the current participants of this changeset recipients = ChangesetComment.get_users(revision=revision) @@ -106,20 +110,25 @@ 'cs_comment_user': h.person(user), 'cs_target_repo': h.url('summary_home', repo_name=repo.repo_name, qualified=True), - 'cs_comment_url': _url, + 'cs_comment_url': comment_url, 'raw_id': revision, 'message': cs.message, 'repo_name': repo.repo_name, 'short_id': h.short_id(revision), 'branch': cs.branch, 'comment_username': user.username, + 'threading': [revision_url, comment_url], # TODO: url to line number } #pull request elif pull_request: notification_type = Notification.TYPE_PULL_REQUEST_COMMENT desc = comment.pull_request.title _org_ref_type, org_ref_name, _org_rev = comment.pull_request.org_ref.split(':') - _url = h.url('pullrequest_show', + pr_url = h.url('pullrequest_show', + repo_name=pull_request.other_repo.repo_name, + pull_request_id=pull_request.pull_request_id, + qualified=True,) + comment_url = h.url('pullrequest_show', repo_name=pull_request.other_repo.repo_name, pull_request_id=pull_request.pull_request_id, anchor='comment-%s' % comment.comment_id, @@ -130,7 +139,7 @@ {'desc': desc, 'pr_id': comment.pull_request.pull_request_id, 'line': line}, - _url) + comment_url) ) # get the current participants of this pull request recipients = ChangesetComment.get_users(pull_request_id= @@ -147,7 +156,7 @@ 'pr_id': pull_request.pull_request_id, 'status_change': status_change, 'closing_pr': closing_pr, - 'pr_comment_url': _url, + 'pr_comment_url': comment_url, 'pr_comment_user': h.person(user), 'pr_target_repo': h.url('summary_home', repo_name=pull_request.other_repo.repo_name, @@ -155,6 +164,7 @@ 'repo_name': pull_request.other_repo.repo_name, 'ref': org_ref_name, 'comment_username': user.username, + 'threading': [pr_url, comment_url], # TODO: url to line number } return subj, body, recipients, notification_type, email_kwargs diff -r 2bb17f6f3044 -r 0529498575ce kallithea/model/notification.py --- a/kallithea/model/notification.py Fri Jul 18 19:22:01 2014 +0200 +++ b/kallithea/model/notification.py Fri Jul 18 19:22:01 2014 +0200 @@ -114,6 +114,10 @@ #don't send email to person who created this comment rec_objs = set(recipients_objs).difference(set([created_by_obj])) + headers = None + if 'threading' in email_kwargs: + headers = {'References': ' '.join('<%s>' % x for x in email_kwargs['threading'])} + # send email with notification to all other participants for rec in rec_objs: email_body = None # we set body to none, we just send HTML emails @@ -131,7 +135,7 @@ .get_email_tmpl(type_, **kwargs) run_task(tasks.send_email, [rec.email], email_subject, email_body, - email_body_html) + email_body_html, headers) return notif diff -r 2bb17f6f3044 -r 0529498575ce kallithea/model/pull_request.py --- a/kallithea/model/pull_request.py Fri Jul 18 19:22:01 2014 +0200 +++ b/kallithea/model/pull_request.py Fri Jul 18 19:22:01 2014 +0200 @@ -144,6 +144,7 @@ 'pr_id': pr.pull_request_id, 'ref': org_ref_name, 'pr_username': pr.author.username, + 'threading': [pr_url], } NotificationModel().create(created_by=pr.author, subject=subject, body=body, recipients=reviewers,