def __init__(self, subject, template_name, recipients, from_address, delta=None, contents=None, diff=None, message_id=None, revno=None, notification_type=None, **kwargs): BaseMailer.__init__(self, subject, template_name, recipients, from_address, delta, message_id, notification_type) self.contents = contents self.diff = diff if diff is None: self.diff_size = 0 else: self.diff_size = self.diff.count('\n') + 1 self.revno = revno self.extra_template_params = kwargs
def _getTemplateParams(self, email, recipient): params = BaseMailer._getTemplateParams(self, email, recipient) reason, rationale = self._recipients.getReason(email) branch = reason.branch params['unique_name'] = branch.unique_name params['branch_identity'] = branch.identity params['branch_url'] = canonical_url(branch) if reason.recipient in branch.subscribers: # Give subscribers a link to unsubscribe. # XXX cjwatson 2015-04-15: Perhaps GitRef:+edit-subscription # should be made to work? if IGitRef.providedBy(branch): unsubscribe_url = canonical_url(branch.repository) else: unsubscribe_url = canonical_url(branch) params['unsubscribe'] = ("\nTo unsubscribe from this branch go to " "%s/+edit-subscription" % unsubscribe_url) else: params['unsubscribe'] = '' params['diff'] = self.contents or '' if not self._includeDiff(email): params['diff'] += self._explainNotPresentDiff(email) if self.delta_for_editors_text is not None: authz = getAdapter(branch, IAuthorization, 'launchpad.Edit') if authz.checkAuthenticated(IPersonRoles(recipient)): params['delta'] = self.delta_for_editors_text else: params['delta'] = self.delta_text or '' else: params['delta'] = self.delta_text or '' params.update(self.extra_template_params) return params
def _getHeaders(self, email): headers = BaseMailer._getHeaders(self, email) reason, rationale = self._recipients.getReason(email) headers['X-Launchpad-Branch'] = reason.branch.unique_name if reason.branch.product is not None: headers['X-Launchpad-Project'] = reason.branch.product.name if self.revno is not None: headers['X-Launchpad-Branch-Revision-Number'] = str(self.revno) return headers
def _getHeaders(self, email, recipient): headers = BaseMailer._getHeaders(self, email, recipient) reason, rationale = self._recipients.getReason(email) headers['X-Launchpad-Branch'] = reason.branch.unique_name if IGitRef.providedBy(reason.branch): if IProduct.providedBy(reason.branch.target): headers['X-Launchpad-Project'] = reason.branch.target.name elif IBranch.providedBy(reason.branch): if reason.branch.product is not None: headers['X-Launchpad-Project'] = reason.branch.product.name if self.revno is not None: headers['X-Launchpad-Branch-Revision-Number'] = str(self.revno) if self.revision_id is not None: headers['X-Launchpad-Branch-Revision-ID'] = self.revision_id return headers
def _getToAddresses(self, email, recipient): """Return the addresses to use for the to header. If the email is being sent directly to the recipient, their email address is returned. Otherwise, the merge proposal and requested reviewers are returned. """ if self.direct_email: return BaseMailer._getToAddresses(self, email, recipient) to_addrs = [self.merge_proposal.address] for vote in self.merge_proposal.votes: if vote.reviewer == vote.registrant: continue if vote.reviewer.is_team: continue if vote.reviewer.hide_email_addresses: continue to_addrs.append(format_address_for_person(vote.reviewer)) return to_addrs
def _getToAddresses(self, recipient, email): """Return the addresses to use for the to header. If the email is being sent directly to the recipient, their email address is returned. Otherwise, the merge proposal and requested reviewers are returned. """ if self.direct_email: return BaseMailer._getToAddresses(self, recipient, email) to_addrs = [self.merge_proposal.address] for vote in self.merge_proposal.votes: if vote.reviewer == vote.registrant: continue if vote.reviewer.is_team: continue if vote.reviewer.hide_email_addresses: continue to_addrs.append(self._format_user_address(vote.reviewer)) return to_addrs
def _getTemplateParams(self, email, recipient): params = BaseMailer._getTemplateParams(self, email, recipient) reason, rationale = self._recipients.getReason(email) branch = reason.branch params['unique_name'] = branch.unique_name params['branch_identity'] = branch.bzr_identity params['branch_url'] = canonical_url(branch) if reason.recipient in branch.subscribers: # Give subscribers a link to unsubscribe. params['unsubscribe'] = ("\nTo unsubscribe from this branch go to " "%s/+edit-subscription" % canonical_url(branch)) else: params['unsubscribe'] = '' params['diff'] = self.contents or '' if not self._includeDiff(email): params['diff'] += self._explainNotPresentDiff(email) params.setdefault('delta', '') params.update(self.extra_template_params) return params
def _getTemplateParams(self, email, recipient): params = BaseMailer._getTemplateParams(self, email, recipient) reason, rationale = self._recipients.getReason(email) branch = reason.branch params['unique_name'] = branch.unique_name params['branch_identity'] = branch.bzr_identity params['branch_url'] = canonical_url(branch) if reason.recipient in branch.subscribers: # Give subscribers a link to unsubscribe. params['unsubscribe'] = ( "\nTo unsubscribe from this branch go to " "%s/+edit-subscription" % canonical_url(branch)) else: params['unsubscribe'] = '' params['diff'] = self.contents or '' if not self._includeDiff(email): params['diff'] += self._explainNotPresentDiff(email) params.setdefault('delta', '') params.update(self.extra_template_params) return params
def __init__(self, subject, body_template, recipients, from_address, build): BaseMailer.__init__( self, subject, body_template, recipients, from_address, notification_type='recipe-build-status') self.build = build