From: BenoƮt Pin Date: Sun, 7 Nov 2010 01:59:17 +0000 (+0100) Subject: Importation initiale. X-Git-Url: https://scm.cri.ensmp.fr/git/FakeMailHost.git/commitdiff_plain/877050bf69ae69eab272021ab648578599d2aaab Importation initiale. --- 877050bf69ae69eab272021ab648578599d2aaab diff --git a/FakeMailHost.py b/FakeMailHost.py new file mode 100755 index 0000000..fba8a66 --- /dev/null +++ b/FakeMailHost.py @@ -0,0 +1,84 @@ +from Globals import InitializeClass, DTMLFile +from Products.MailHost import MailHost +from AccessControl import ClassSecurityInfo +from AccessControl.Permissions import view_management_screens, change_configuration +import string, re + +bad_path_chars_in=re.compile('[^a-zA-Z0-9-_~\,\. \/]').search + + + +manage_addFakeMailHostForm=DTMLFile('www/addFakeMailHost_form', globals()) +def manage_addFakeMailHost(dispatcher, id, title='', folderPath='', REQUEST=None) : + ' Add Fake mail Host' + parent = dispatcher.Destination() + fmh = FakeMailHost(id, folderPath, title='title' ) + parent._setObject(id, fmh) + if REQUEST is not None: + REQUEST['RESPONSE'].redirect(parent.absolute_url()+'/manage_main') + + +class FakeMailHost(MailHost.MailHost) : + """ Fake Mail Host """ + + meta_type = 'Fake Mail Host' + manage_main = DTMLFile('www/manageFakeMailHost', globals()) + manage_main._setName('manage_main') + smtp_host = '' + + security = ClassSecurityInfo() + + def __init__(self, id, folderPath, title='', ) : + self.id = id + self.title = title + self.setContainerPath(path=folderPath) + + + def _send(self, mfrom, mto, messageText, immediate=False) : + """ Create a document based on message inside base folder """ + folder = self._getMailContainer() + id = str(len(folder._objects)) + folder.manage_addProduct['OFSP'].manage_addFile(id, file='') + file = getattr(folder, id) + file.update_data(messageText, 'text/plain') + + security.declareProtected(change_configuration, 'manage_makeChanges' ) + def manage_makeChanges(self,title,folderPath, REQUEST=None): + 'make the changes' + + title=str(title) + self.title=title + self.setContainerPath(folderPath) + + if REQUEST is not None: + msg = 'Fake Mail Host %s updated' % self.id + return self.manage_main( self + , REQUEST + , manage_tabs_message=msg + ) + + security.declareProtected(view_management_screens, 'getFolderPath') + def getFolderPath(self) : + return '/'.join(self._folderPath) + + + def _getMailContainer(self) : + return self.unrestrictedTraverse(self._folderPath) + + security.declarePrivate('setContainerPath') + def setContainerPath(self, path=None): + if not path: + self._folderPath = [] + elif type(path) is type(''): + if bad_path_chars_in(path): + raise ValueError, ( + 'Path contains invalid characters in a Zope ' + 'object path' + ) + self._folderPath = string.split(path, '/') + elif type(path) in (type([]), type(())): + self._folderPath = list(path) # sequence + else: + raise ValueError, ('Bad path value %s' % path) + +InitializeClass(FakeMailHost) \ No newline at end of file diff --git a/__init__.py b/__init__.py new file mode 100755 index 0000000..ef1f2e8 --- /dev/null +++ b/__init__.py @@ -0,0 +1,10 @@ +import FakeMailHost + +def initialize(context) : + context.registerClass( + FakeMailHost.FakeMailHost, + permission='Add MailHost objects', + constructors=(FakeMailHost.manage_addFakeMailHostForm, + FakeMailHost.manage_addFakeMailHost), + icon='www/MailHost_icon.gif', + ) \ No newline at end of file diff --git a/www/MailHost_icon.gif b/www/MailHost_icon.gif new file mode 100644 index 0000000..f931228 Binary files /dev/null and b/www/MailHost_icon.gif differ diff --git a/www/addFakeMailHost_form.dtml b/www/addFakeMailHost_form.dtml new file mode 100755 index 0000000..bc0dfe2 --- /dev/null +++ b/www/addFakeMailHost_form.dtml @@ -0,0 +1,48 @@ + + + +

+Fake MailHost object provide a way to create File objects based on mails +instead of sending them. +

+ +
+ + + + + + + + + + + + + + + + + +
+
Id
+
+ +
+
Title
+
+ +
+
Base folder path
+
+ +
+ +
+ +
+
+
+ + + diff --git a/www/manageFakeMailHost.dtml b/www/manageFakeMailHost.dtml new file mode 100755 index 0000000..85eca50 --- /dev/null +++ b/www/manageFakeMailHost.dtml @@ -0,0 +1,45 @@ + + + +
+ + + + + + + + + + + + + + + + + +
+
+ Id +
+
+
&dtml-id;
+
+
Title
+
+ +
+
Base folder path
+
+ +
+ +
+ +
+
+
+ +