1
2
3 """TurboMail extension API."""
4
5
6 import logging
7 import warnings
8
9 from turbomail.control import interface
10 from turbomail.exceptions import ManagerException
11
12
13 __all__ = ['Extension', 'TransportFactory', 'Transport', 'Manager']
14
15
16
18 """Basic extension API that allows for startup and shutdown hooks."""
19
23
25 self.ready = True
26 return True
27
29 if not self.ready:
30 return False
31
32 self.ready = False
33 return True
34
35
37 """An extension that creates new Transport instances.
38
39 This is useful to perform configuration or startup tasks outside the Transport's initializer.
40 """
41
42 transport = None
43
46
48 if not self.ready: return None
49 return self.transport()
50
51
53 """Message delivery subsystem API.
54
55 A Transport can deliver messages towards their recipients with a specific
56 method, e.g. SMTP. They don't care about delivery strategies like queing or
57 batch submission."""
58
61
63 raise NotImplementedError, "Transport plugin must override this method without inheritance."
64
65 - def config_get(self, key, default=None, tm2_key=None):
66 """Returns the value for the given key from the configuration. If the
67 value was not found, this method looks if old configuration option
68 (specified in tm2_key) is used. If tm2_key was ommitted, it tries to
69 calculate the old key from the new one by cutting out the 'smtp.' in the
70 middle. If an old configuration key is used, a DeprecationWarning is
71 issued.
72 As a final fallback, the default value (default None) is
73 returned."""
74
75
76
77 value = interface.config.get(key, None)
78 if value == None:
79 if tm2_key != None and not tm2_key.startswith('mail.'):
80 tm2_key = 'mail.' + tm2_key
81 elif tm2_key == None:
82 tm2_key = key.replace('.smtp.', '.')
83 value = interface.config.get(tm2_key, None)
84 if value is not None:
85 basemsg = 'Configuration key "%s" is deprecated, please use "%s" instead'
86 warn_text = basemsg % (tm2_key, key)
87 warnings.warn(warn_text, category=DeprecationWarning)
88 if value == None:
89 value = default
90 return value
91
93 """Called by the manager before the transport instance is destroyed. The
94 transport can do some final cleanups (like releasing external resources)
95 here."""
96 pass
97
98
100 """Manager instances orchestrate the delivery of messages."""
101
105
113
116