1
# Copyright 2011 Canonical Ltd. This software is licensed under the
2
# GNU Affero General Public License version 3 (see the file LICENSE).
4
"""Event handlers that send email notifications."""
8
from zope.component import getUtility
10
from canonical.config import config
11
from canonical.database.sqlbase import block_implicit_flushes
12
from canonical.launchpad.helpers import get_email_template
13
from canonical.launchpad.webapp.interfaces import ILaunchpadRoot
14
from canonical.launchpad.webapp.publisher import canonical_url
15
from lp.services.mail.mailwrapper import MailWrapper
16
from lp.services.mail.sendmail import (
24
@block_implicit_flushes
25
def notify_new_ppa_subscription(subscription, event):
26
"""Notification that a new PPA subscription can be activated."""
27
non_active_subscribers = subscription.getNonActiveSubscribers()
29
archive = subscription.archive
31
# We don't send notification emails for commercial PPAs as these
32
# are purchased via software center (and do not mention Launchpad).
33
if archive.commercial:
36
registrant_name = subscription.registrant.displayname
37
ppa_displayname = archive.displayname
38
ppa_reference = "ppa:%s/%s" % (
39
archive.owner.name, archive.name)
40
ppa_description = archive.description
41
subject = 'PPA access granted for ' + ppa_displayname
43
template = get_email_template('ppa-subscription-new.txt', app='soyuz')
45
for person, preferred_email in non_active_subscribers:
46
to_address = [preferred_email.email]
47
root = getUtility(ILaunchpadRoot)
48
recipient_subscriptions_url = "%s~/+archivesubscriptions" % (
50
description_blurb = '.'
51
if ppa_description is not None and ppa_description != '':
53
' and has the following description:\n\n%s' % ppa_description)
55
'recipient_name': person.displayname,
56
'registrant_name': registrant_name,
57
'registrant_profile_url': canonical_url(subscription.registrant),
58
'ppa_displayname': ppa_displayname,
59
'ppa_reference': ppa_reference,
60
'ppa_description_blurb': description_blurb,
61
'recipient_subscriptions_url': recipient_subscriptions_url,
63
body = MailWrapper(72).format(template % replacements,
66
from_address = format_address(
67
registrant_name, config.canonical.noreply_from_address)
70
'Sender': config.canonical.bounce_address,
73
# If the registrant has a preferred email, then use it for the
75
if subscription.registrant.preferredemail:
76
headers['Reply-To'] = format_address(
78
subscription.registrant.preferredemail.email)
80
simple_sendmail(from_address, to_address, subject, body, headers)