1
# Copyright (C) 2006-2012 by the Free Software Foundation, Inc.
3
# This file is part of GNU Mailman.
5
# GNU Mailman is free software: you can redistribute it and/or modify it under
6
# the terms of the GNU General Public License as published by the Free
7
# Software Foundation, either version 3 of the License, or (at your option)
10
# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15
# You should have received a copy of the GNU General Public License along with
16
# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
18
"""Model for addresses."""
20
from __future__ import absolute_import, print_function, unicode_literals
28
from email.utils import formataddr
29
from storm.locals import DateTime, Int, Reference, Unicode
30
from zope.event import notify
31
from zope.interface import implementer
33
from mailman.database.model import Model
34
from mailman.interfaces.address import AddressVerificationEvent, IAddress
35
from mailman.utilities.datetime import now
39
@implementer(IAddress)
43
id = Int(primary=True)
46
display_name = Unicode()
47
_verified_on = DateTime(name='verified_on')
48
registered_on = DateTime()
51
user = Reference(user_id, 'User.id')
52
preferences_id = Int()
53
preferences = Reference(preferences_id, 'Preferences.id')
55
def __init__(self, email, display_name):
56
super(Address, self).__init__()
57
lower_case = email.lower()
58
self.email = lower_case
59
self.display_name = display_name
60
self._original = (None if lower_case == email else email)
61
self.registered_on = now()
64
addr = (self.email if self._original is None else self._original)
65
return formataddr((self.display_name, addr))
68
verified = ('verified' if self.verified_on else 'not verified')
69
address_str = str(self)
70
if self._original is None:
71
return '<Address: {0} [{1}] at {2:#x}>'.format(
72
address_str, verified, id(self))
74
return '<Address: {0} [{1}] key: {2} at {3:#x}>'.format(
75
address_str, verified, self.email, id(self))
78
def verified_on(self):
79
return self._verified_on
82
def verified_on(self, timestamp):
83
self._verified_on = timestamp
84
notify(AddressVerificationEvent(self))
87
def original_email(self):
88
return (self.email if self._original is None else self._original)