Importation initiale. master
authorBenoît Pin <benoit.pin@gmail.com>
Sun, 7 Nov 2010 01:59:17 +0000 (02:59 +0100)
committerBenoît Pin <benoit.pin@gmail.com>
Sun, 7 Nov 2010 01:59:17 +0000 (02:59 +0100)
FakeMailHost.py [new file with mode: 0755]
__init__.py [new file with mode: 0755]
www/MailHost_icon.gif [new file with mode: 0644]
www/addFakeMailHost_form.dtml [new file with mode: 0755]
www/manageFakeMailHost.dtml [new file with mode: 0755]

diff --git a/FakeMailHost.py b/FakeMailHost.py
new file mode 100755 (executable)
index 0000000..fba8a66
--- /dev/null
@@ -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 (executable)
index 0000000..ef1f2e8
--- /dev/null
@@ -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 (file)
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 (executable)
index 0000000..bc0dfe2
--- /dev/null
@@ -0,0 +1,48 @@
+<dtml-var manage_page_header>
+<dtml-var "manage_form_title(this(), _, form_title='Add Fake MailHost')">
+
+<p class="form-help">
+Fake MailHost object provide a way to create File objects based on mails
+instead of sending them.
+</p>
+
+<form action="manage_addFakeMailHost" method="post">
+<table cellspacing="0" cellpadding="2" border="0">
+  <tr>
+    <td align="left" valign="top">
+    <div class="form-label">Id</div>
+    </td>
+    <td align="left" valign="top">
+    <input type="text" name="id" size="40" value="MailHost" />
+    </td>
+  </tr>
+  <tr>
+    <td align="left" valign="top">
+    <div class="form-optional">Title</div>
+    </td>
+    <td align="left" valign="top">
+    <input type="text" name="title" size="40" />
+    </td>
+  </tr>
+  <tr>
+    <td align="left" valign="top">
+    <div class="form-label">Base folder path</div>
+    </td>
+    <td align="left" valign="top">
+    <input type="text" name="folderPath" size="40" value="" />
+    </td>
+  </tr>
+  <tr>
+    <td align="left" valign="top">
+    </td>
+    <td align="left" valign="top">
+    <div class="form-element">
+    <input class="form-element" type="submit" name="submit" value=" Add " /> 
+    </div>
+    </td>
+  </tr>
+</table>
+</form>
+
+<dtml-var manage_page_footer>
+
diff --git a/www/manageFakeMailHost.dtml b/www/manageFakeMailHost.dtml
new file mode 100755 (executable)
index 0000000..85eca50
--- /dev/null
@@ -0,0 +1,45 @@
+<dtml-var manage_page_header>
+<dtml-var manage_tabs>
+
+<form action="manage_makeChanges" method="post">
+<table cellspacing="0" cellpadding="2" border="0">
+  <tr>
+    <td align="left" valign="top">
+    <div class="form-label">
+    Id
+    </div>
+    </td>
+    <td align="left" valign="top">
+    <div class="form-text">&dtml-id;</div>
+    </td>
+  </tr>
+  <tr>
+    <td align="left" valign="top">
+    <div class="form-optional">Title</div>
+    </td>
+    <td align="left" valign="top">
+    <input type="text" name="title" size="40" value="&dtml-title;"/>
+    </td>
+  </tr>
+  <tr>
+    <td align="left" valign="top">
+    <div class="form-label">Base folder path</div>
+    </td>
+    <td align="left" valign="top">
+    <input type="text" name="folderPath" size="40" value="&dtml-getFolderPath;" />
+    </td>
+  </tr>
+  <tr>
+    <td align="left" valign="top">
+    </td>
+    <td align="left" valign="top">
+    <div class="form-element">
+    <input class="form-element" type="submit" name="submit" 
+     value="Save Changes" /> 
+    </div>
+    </td>
+  </tr>
+</table>
+</form>
+
+<dtml-var manage_page_footer>