~launchpad-pqm/launchpad/devel

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
Email Addresses
===============

In Launchpad we use email addresses to uniquely identify a person. This is why
email addresses must be unique.

    >>> from lp.services.identity.interfaces.emailaddress import (
    ...     IEmailAddress, IEmailAddressSet)
    >>> from lp.registry.interfaces.person import IPersonSet
    >>> emailset = getUtility(IEmailAddressSet)
    >>> person = factory.makePerson()

We can get an email address through IEmailAddressSet.getByEmail().

    >>> login_person(person)
    >>> email = emailset.getByEmail(person.preferredemail.email)
    >>> email == person.preferredemail
    True

Note that IEmailAddressSet.getByEmail() is not case-sensitive.

    >>> email == emailset.getByEmail(email.email.upper())
    True

Email addresses provide both IEmailAddress and IHasOwner.

    >>> from lp.registry.interfaces.role import IHasOwner
    >>> verifyObject(IEmailAddress, email)
    True
    >>> verifyObject(IHasOwner, email)
    True

Trying to register an email address that already exists will raise an
exception.

    >>> personset = getUtility(IPersonSet)
    >>> foobar = personset.getByName('name16')
    >>> emailset.new(email.email, foobar)
    Traceback (most recent call last):
    ...
    EmailAddressAlreadyTaken: The email address '...' is already registered.

The email address verification is case insensitive as well:

    >>> emailset.new(email.email.upper(), foobar)
    Traceback (most recent call last):
    ...
    EmailAddressAlreadyTaken: The email address '...' is already registered.

Registering a new email address works -- and preserves case -- though:

    >>> emailaddress = emailset.new(
    ...     'oink@Canonical.com', foobar)
    >>> emailaddress.email
    u'oink@Canonical.com'

Generating SHA1 hashes for RDF output is easy:

    >>> emailaddress.rdf_sha1
    '3738A7C5FB02B103FEF1F3CDAA9B086B6C382F6E'

There's a convenience method on IEmailAddressSet to pull preferred email
addresses for a set of people:

    >>> guadamen = personset.getByName('guadamen')
    >>> [emailaddress.email for emailaddress in
    ...  emailset.getPreferredEmailForPeople(guadamen.allmembers)]
    [u'celso.providelo@canonical.com', u'colin.watson@ubuntulinux.com',
     u'daniel.silverstone@canonical.com', u'edgar@monteparadiso.hr',
     u'foo.bar@canonical.com', u'jeff.waugh@ubuntulinux.com',
     u'limi@plone.org', u'mark@example.com',
     u'steve.alexander@ubuntulinux.com', u'support@ubuntu.com']


Deleting email addresses
------------------------

Email addresses may be deleted if they're not a person's preferred one
or the address of a team's mailing list.

    >>> login_person(foobar)
    >>> emailaddress = emailset.getByEmail('oink@canonical.com')
    >>> emailaddress.destroySelf()
    >>> print emailset.getByEmail('oink@canonical.com')
    None

Otherwise, UndeletableEmailAddress is raised.

    >>> foobar.preferredemail.destroySelf()
    Traceback (most recent call last):
    ...
    UndeletableEmailAddress: This is a person's preferred email...

    >>> from lp.registry.tests.mailinglists_helper import (
    ...     new_list_for_team)
    >>> mailing_list = new_list_for_team(guadamen)
    >>> email = emailset.getByEmail(guadamen.mailing_list.address)
    >>> email.destroySelf()
    Traceback (most recent call last):
    ...
    UndeletableEmailAddress: This is the email address of a team's mailing
    list...