Importation initiale.
[FakeMailHost.git] / FakeMailHost.py
1 from Globals import InitializeClass, DTMLFile
2 from Products.MailHost import MailHost
3 from AccessControl import ClassSecurityInfo
4 from AccessControl.Permissions import view_management_screens, change_configuration
5 import string, re
6
7 bad_path_chars_in=re.compile('[^a-zA-Z0-9-_~\,\. \/]').search
8
9
10
11 manage_addFakeMailHostForm=DTMLFile('www/addFakeMailHost_form', globals())
12 def manage_addFakeMailHost(dispatcher, id, title='', folderPath='', REQUEST=None) :
13 ' Add Fake mail Host'
14 parent = dispatcher.Destination()
15 fmh = FakeMailHost(id, folderPath, title='title' )
16 parent._setObject(id, fmh)
17 if REQUEST is not None:
18 REQUEST['RESPONSE'].redirect(parent.absolute_url()+'/manage_main')
19
20
21 class FakeMailHost(MailHost.MailHost) :
22 """ Fake Mail Host """
23
24 meta_type = 'Fake Mail Host'
25 manage_main = DTMLFile('www/manageFakeMailHost', globals())
26 manage_main._setName('manage_main')
27 smtp_host = ''
28
29 security = ClassSecurityInfo()
30
31 def __init__(self, id, folderPath, title='', ) :
32 self.id = id
33 self.title = title
34 self.setContainerPath(path=folderPath)
35
36
37 def _send(self, mfrom, mto, messageText, immediate=False) :
38 """ Create a document based on message inside base folder """
39 folder = self._getMailContainer()
40 id = str(len(folder._objects))
41 folder.manage_addProduct['OFSP'].manage_addFile(id, file='')
42 file = getattr(folder, id)
43 file.update_data(messageText, 'text/plain')
44
45 security.declareProtected(change_configuration, 'manage_makeChanges' )
46 def manage_makeChanges(self,title,folderPath, REQUEST=None):
47 'make the changes'
48
49 title=str(title)
50 self.title=title
51 self.setContainerPath(folderPath)
52
53 if REQUEST is not None:
54 msg = 'Fake Mail Host %s updated' % self.id
55 return self.manage_main( self
56 , REQUEST
57 , manage_tabs_message=msg
58 )
59
60 security.declareProtected(view_management_screens, 'getFolderPath')
61 def getFolderPath(self) :
62 return '/'.join(self._folderPath)
63
64
65 def _getMailContainer(self) :
66 return self.unrestrictedTraverse(self._folderPath)
67
68 security.declarePrivate('setContainerPath')
69 def setContainerPath(self, path=None):
70 if not path:
71 self._folderPath = []
72 elif type(path) is type(''):
73 if bad_path_chars_in(path):
74 raise ValueError, (
75 'Path contains invalid characters in a Zope '
76 'object path'
77 )
78 self._folderPath = string.split(path, '/')
79 elif type(path) in (type([]), type(())):
80 self._folderPath = list(path) # sequence
81 else:
82 raise ValueError, ('Bad path value %s' % path)
83
84 InitializeClass(FakeMailHost)