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
7 bad_path_chars_in
=re
.compile('[^a-zA-Z0-9-_~\,\. \/]').search
11 manage_addFakeMailHostForm
=DTMLFile('www/addFakeMailHost_form', globals())
12 def manage_addFakeMailHost(dispatcher
, id, title
='', folderPath
='', REQUEST
=None) :
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')
21 class FakeMailHost(MailHost
.MailHost
) :
22 """ Fake Mail Host """
24 meta_type
= 'Fake Mail Host'
25 manage_main
= DTMLFile('www/manageFakeMailHost', globals())
26 manage_main
._setName
('manage_main')
29 security
= ClassSecurityInfo()
31 def __init__(self
, id, folderPath
, title
='', ) :
34 self
.setContainerPath(path
=folderPath
)
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')
45 security
.declareProtected(change_configuration
, 'manage_makeChanges' )
46 def manage_makeChanges(self
,title
,folderPath
, REQUEST
=None):
51 self
.setContainerPath(folderPath
)
53 if REQUEST
is not None:
54 msg
= 'Fake Mail Host %s updated' % self
.id
55 return self
.manage_main( self
57 , manage_tabs_message
=msg
60 security
.declareProtected(view_management_screens
, 'getFolderPath')
61 def getFolderPath(self
) :
62 return '/'.join(self
._folderPath
)
65 def _getMailContainer(self
) :
66 return self
.unrestrictedTraverse(self
._folderPath
)
68 security
.declarePrivate('setContainerPath')
69 def setContainerPath(self
, path
=None):
72 elif type(path
) is type(''):
73 if bad_path_chars_in(path
):
75 'Path contains invalid characters in a Zope '
78 self
._folderPath
= string
.split(path
, '/')
79 elif type(path
) in (type([]), type(())):
80 self
._folderPath
= list(path
) # sequence
82 raise ValueError, ('Bad path value %s' % path
)
84 InitializeClass(FakeMailHost
)