Index: /quintagroup.plonecomments/trunk/quintagroup/plonecomments/tests/helperNotify.py
===================================================================
--- /quintagroup.plonecomments/trunk/quintagroup/plonecomments/tests/helperNotify.py	(revision 1632)
+++ /quintagroup.plonecomments/trunk/quintagroup/plonecomments/tests/helperNotify.py	(revision 1633)
@@ -2,10 +2,4 @@
 ##      Helper methods for testing Mail sending        ##
 #########################################################
-
-import sys
-import os, os.path
-from Products.SecureMailHost.SecureMailHost import SecureMailBase
-
-PREFIX = os.path.abspath(os.path.dirname(__file__))
 
 ALL_PROPS = ['enable_approve_user_notification', 'enable_reply_user_notification',
@@ -14,66 +8,11 @@
              'enable_published_notification', 'enable_approve_notification']
 
-def sample_file_path(file):
-    return os.path.join(PREFIX, 'sample', file)
-
-def output_file_path(file):
-    return os.path.join(PREFIX, 'output', file)
-
-def getFileContent(f_path):
-    result_f = open(f_path,"r")
-    result = result_f.read()
-    result_f.close()
-    return result
-
-def writeToFile(f_path, text):
-    result_f = open(f_path,'w')
-    result_f.write(text.as_string()+'\n')
-    result_f.close()
-
-def clearFile(f_path):
-    result_f = open(f_path,"w")
-    result_f.write('')
-    result_f.close()
-
-def _send_MH( self, mfrom, mto, messageText ):
-    files = [f for f in os.listdir(output_file_path("")) if f.startswith('mail')]
-    files.sort()
-    fn = files and (files[-1]+ '1') or 'mail'
-    writeToFile(output_file_path(fn), messageText)
-
-def _send_SMH(self, mfrom, mto, messageText, debug=False):
-    files = [f for f in os.listdir(output_file_path("")) if f.startswith('mail')]
-    files.sort()
-    fn = files and (files[-1]+ '1') or 'mail'
-    writeToFile(output_file_path(fn), messageText)
-
-def send_SMH(self, message, mto=None, mfrom=None, subject=None, encode=None):
-    files = [f for f in os.listdir(output_file_path("")) if f.startswith('mail')]
-    files.sort()
-    fn = files and (files[-1]+ '1') or 'mail'
-    writeToFile(output_file_path(fn), message)
-
-def prepareMailSendTest():
-    # patch SecureMailHost
-    SecureMailBase.send = send_SMH
-    SecureMailBase._send = _send_SMH
-
 def setProperties(prop_sheet, *props):
     for p in ALL_PROPS:
         prop_sheet._updateProperty(p, p in props)
 
-def testMailExistance():
-    for f in os.listdir(output_file_path("")):
-        if f.startswith('mail'):
-            return True
+def testMailExistance(sel):
+    mailhost = sel.portal.MailHost
+    if mailhost.messages: 
+        return True
     return False
-
-def getMails():
-    return [file(output_file_path(f),'r').read()
-            for f in os.listdir(output_file_path(""))
-            if f.startswith('mail')]
-
-def cleanOutputDir():
-    for f in os.listdir(output_file_path("")):
-        if f.startswith('mail'):
-            os.remove(output_file_path(f))
Index: /quintagroup.plonecomments/trunk/quintagroup/plonecomments/tests/testQPloneCommentsNotification.py
===================================================================
--- /quintagroup.plonecomments/trunk/quintagroup/plonecomments/tests/testQPloneCommentsNotification.py	(revision 1632)
+++ /quintagroup.plonecomments/trunk/quintagroup/plonecomments/tests/testQPloneCommentsNotification.py	(revision 1633)
@@ -13,4 +13,9 @@
 from config import *
 
+from Products.CMFPlone.tests.utils import MockMailHost
+
+REXP_TO = re.compile("To:\s*(.*?)$",re.M)
+REXP_SUBJ = re.compile("Subject:\s*(.*?)$",re.M)
+
 
 class TestNotification(FunctionalTestCase):
@@ -20,5 +25,11 @@
         self.prefs._updateProperty('enable_published_notification', swithP)
 
+    def beforeTearDown(self):
+        self.portal.MailHost = self.portal._original_MailHost
+
     def afterSetUp(self):
+        self.portal._original_MailHost = self.portal.MailHost
+        self.portal.MailHost = mailhost = MockMailHost('MailHost')
+
         self.loginAsPortalOwner()
 
@@ -64,5 +75,5 @@
         self.request.form['body_text'] = "text of reply"
 
-        prepareMailSendTest()
+        #prepareMailSendTest()
 
     def test_bug_parent_reply(self):
@@ -93,48 +104,48 @@
 
     def test_notificafion_disabled(self):
-        cleanOutputDir()
+        self.portal.MailHost.reset()
         setProperties(self.prefs)
         self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc')
-        self.failIf(testMailExistance(), 'Mail was sended when all notification was disabled.')
+        self.failIf(testMailExistance(self), 'Mail was sended when all notification was disabled.')
 
     def test_published_comment_notification(self):
-        cleanOutputDir()
+        self.portal.MailHost.reset()
         setProperties(self.prefs, 'enable_published_notification')
         self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc')
-        self.failUnless(testMailExistance(), 'Mail was not sended when enable_published_notification.')
+        self.failUnless(testMailExistance(self), 'Mail was not sended when enable_published_notification.')
 
     def test_approve_comment_notification(self):
-        cleanOutputDir()
+        self.portal.MailHost.reset()
         setProperties(self.prefs, 'enable_approve_notification')
         self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc')
-        self.failUnless(testMailExistance(), 'Mail was not sended when enable_approve_notification.')
+        self.failUnless(testMailExistance(self), 'Mail was not sended when enable_approve_notification.')
 
     def test_reply_comment_user_notification(self):
-        cleanOutputDir()
+        self.portal.MailHost.reset()
         setProperties(self.prefs, 'enable_reply_user_notification')
         self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc')
-        self.failIf(testMailExistance(), 'Mail was sended for simple reply when enable_reply_user_notification.')
+        self.failIf(testMailExistance(self), 'Mail was sended for simple reply when enable_reply_user_notification.')
 
         reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0]
         reply.discussion_reply('A Reply for comment' ,'text of reply for comment')
         reply_for_comment = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0]
-        self.failUnless(testMailExistance(), 'Mail was not sended when enable_reply_user_notification.')
+        self.failUnless(testMailExistance(self), 'Mail was not sended when enable_reply_user_notification.')
 
     def test_rejected_comment_notification(self):
-        cleanOutputDir()
+        self.portal.MailHost.reset()
         setProperties(self.prefs, 'enable_rejected_user_notification', 'enable_moderation')
         self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc')
-        self.failIf(testMailExistance(), 'Mail was sended when enable_rejected_user_notification was enabled.')
+        self.failIf(testMailExistance(self), 'Mail was sended when enable_rejected_user_notification was enabled.')
 
         reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0]
         self.portal.REQUEST.set('ids', [reply.getId()])
         self.portal.prefs_recent_comments_delete()
-        self.failUnless(testMailExistance(), 'Mail was not sended when enable_rejected_user_notification.')
+        self.failUnless(testMailExistance(self), 'Mail was not sended when enable_rejected_user_notification.')
 
     def test_approve_comment_user__notification(self):
-        cleanOutputDir()
+        self.portal.MailHost.reset()
         setProperties(self.prefs, 'enable_approve_user_notification')
         self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc')
-        self.failUnless(testMailExistance(), 'Mail was not sended when enable_approve_user_notification.')
+        self.failUnless(testMailExistance(self), 'Mail was not sended when enable_approve_user_notification.')
 
     def test_bug_notification_on_single_reply_publish(self):
@@ -153,12 +164,12 @@
         reply2 = self.discussion.getDiscussionFor(reply).getReplies()[0]
 
-        cleanOutputDir()
+        self.portal.MailHost.reset()
         reply2.discussion_publish_comment()
-        mails = getMails()
-        self.failUnless([1 for m in mails if re.search('^Subject:.*(replied).*$', m, re.I|re.M)],
+        mails = [str(m) for m in self.portal.MailHost.messages]
+        self.failUnless([1 for m in mails if REXP_SUBJ.search(m) and 'replied' in REXP_SUBJ.search(m).group(1)],
             'No notification for reply.' % properties)
-        self.failUnless([1 for m in mails if re.search('^Subject:.*(added).*$', m, re.I|re.M)],
+        self.failUnless([1 for m in mails if REXP_SUBJ.search(m) and 'added' in REXP_SUBJ.search(m).group(1)],
             'No notification for adding comment.' % properties)
-        self.failUnless([1 for m in mails if re.search('^Subject:.*(published).*$', m, re.I|re.M)],
+        self.failUnless([1 for m in mails if REXP_SUBJ.search(m) and 'published' in REXP_SUBJ.search(m).group(1)],
             'No notification for publishing comment.' % properties)
 
@@ -173,10 +184,9 @@
         reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0]
 
-        cleanOutputDir()
+        self.portal.MailHost.reset()
         reply.deleteDiscussion()
-        mails = getMails()
+        mails = [str(m) for m in self.portal.MailHost.messages]
         subject = str(Header('Your comment on Doc was not approved', 'utf-8'))
-        subjs = [message_from_string(m)['Subject'] for m in mails]
-        self.failUnless([1 for m in subjs if m == subject],
+        self.failUnless([1 for m in mails if REXP_SUBJ.search(m) and REXP_SUBJ.search(m).group(1)==subject],
             'No notification for rejecting comment.' % properties)
 
Index: /quintagroup.plonecomments/trunk/quintagroup/plonecomments/tests/testQPloneCommentsNotificationRecipients.py
===================================================================
--- /quintagroup.plonecomments/trunk/quintagroup/plonecomments/tests/testQPloneCommentsNotificationRecipients.py	(revision 1632)
+++ /quintagroup.plonecomments/trunk/quintagroup/plonecomments/tests/testQPloneCommentsNotificationRecipients.py	(revision 1633)
@@ -9,8 +9,11 @@
 import re
 from helperNotify import *
+from email import message_from_string
 from email.Header import Header
 from base import getToolByName, FunctionalTestCase
 from common import *
 from config import *
+
+from Products.CMFPlone.tests.utils import MockMailHost
 
 USERS = {# Common Members
@@ -38,5 +41,11 @@
         self.request.form['body_text'] = "text of reply"
 
+    def beforeTearDown(self):
+        self.portal.MailHost = self.portal._original_MailHost
+
     def afterSetUp(self):
+        self.portal._original_MailHost = self.portal.MailHost
+        self.portal.MailHost = mailhost = MockMailHost('MailHost')
+
         self.loginAsPortalOwner()
 
@@ -79,8 +88,8 @@
         # Create talkback for document and Prepare REQUEST
         self.discussion.getDiscussionFor(self.my_doc)
-        prepareMailSendTest()
+        #prepareMailSendTest()
 
     def checkToANDSubj(self, mails, to, subj):
-        messages = [m for m in mails if REXP_TO.search(m) and REXP_TO.search(m).group(1)==to]
+        messages = [str(m) for m in mails if REXP_TO.search(str(m)) and REXP_TO.search(str(m)).group(1)==to]
         self.failUnless(len(messages) > 0, "No message sent to '%s' recipient" % to)
         mangled = str(Header(subj, 'utf-8'))
@@ -89,9 +98,10 @@
 
     def test_Reply(self):
-        cleanOutputDir()
+        self.portal.MailHost.reset()
+        
         self.prepareRequest4Reply('replier1')
         self.my_doc.discussion_reply('A Reply for my_doc' ,'text of reply for my_doc')
 
-        mails = getMails()
+        mails = self.portal.MailHost.messages
         self.assertEqual(len(mails), 1)
         self.checkToANDSubj(mails, to="discussion.manager@test.com",
@@ -103,8 +113,9 @@
         self.login('dm_admin')
         reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0]
-        cleanOutputDir()
+        self.portal.MailHost.reset()
+        
 
         reply.discussion_publish_comment()
-        mails = getMails()
+        mails = self.portal.MailHost.messages
         self.assertEqual(len(mails), 2)
         self.checkToANDSubj(mails, to="owner@test.com", subj="[PREFIX] New comment added")
@@ -121,8 +132,9 @@
         self.login('dm_admin')
         reply2 = self.discussion.getDiscussionFor(reply).getReplies()[0]
-        cleanOutputDir()
+        self.portal.MailHost.reset()
+        
 
         reply2.discussion_publish_comment()
-        mails = getMails()
+        mails = self.portal.MailHost.messages
         self.assertEqual(len(mails), 3)
         self.checkToANDSubj(mails, to="owner@test.com", subj="[PREFIX] New comment added")
@@ -135,8 +147,9 @@
         self.login('dm_admin')
         reply = self.discussion.getDiscussionFor(self.my_doc).getReplies()[0]
-        cleanOutputDir()
+        self.portal.MailHost.reset()
+        
 
         reply.deleteDiscussion()
-        mails = getMails()
+        mails = self.portal.MailHost.messages
         self.assertEqual(len(mails), 1)
         self.checkToANDSubj(mails, to="replier1@test.com", subj='Your comment on Test document was not approved')
Index: /quintagroup.plonecomments/trunk/quintagroup/plonecomments/tests/testQPloneCommentsUninstall.py
===================================================================
--- /quintagroup.plonecomments/trunk/quintagroup/plonecomments/tests/testQPloneCommentsUninstall.py	(revision 1632)
+++ /quintagroup.plonecomments/trunk/quintagroup/plonecomments/tests/testQPloneCommentsUninstall.py	(revision 1633)
@@ -14,4 +14,6 @@
         self.loginAsPortalOwner()
         self.qi = self.portal.portal_quickinstaller
+        self.qi.installProduct(PRODUCT)
+        self.qi.uninstallProducts([PRODUCT])
 
     def test_package_uninstall(self):
