Esempio n. 1
0
def migrateMailHost(context):
    portal = getToolByName(context, 'portal_url').getPortalObject()
    mh = getToolByName(portal, 'MailHost', None)
    if mh is None:
        return

    # Migrate secure mail host and broken mail host objects
    meta_type = getattr(mh, 'meta_type', None)
    if meta_type in ('Secure Mail Host', 'Broken Because Product is Gone'):
        if meta_type == 'Secure Mail Host':
            new_mh = MailHost(
                id=mh.id,
                title=mh.title,
                smtp_host=mh.smtp_host,
                smtp_port=mh.smtp_port,
                smtp_uid=mh.smtp_userid or '',
                smtp_pwd=mh.smtp_pass or '',
                force_tls=False,
            )
        else:
            new_mh = MailHost(id='MailHost', smtp_host='')
            logger.info('Replaced a broken MailHost object.')
        portal._delObject('MailHost')
        portal._setObject('MailHost', new_mh)
        sm = getSiteManager(context=portal)
        sm.unregisterUtility(provided=IMailHost)
        sm.registerUtility(new_mh, provided=IMailHost)
Esempio n. 2
0
    def _send(self, mfrom, mto, messageText, immediate=False):
        """ Send the message """

        # Send it immediately. We don't want to store mails that doesn't get
        # sent, mail shoud be delivered directly, always.
        MailHost._send(self, mfrom, mto, messageText, immediate=True)
        # I'm not sure you always get list here, so I handle both:
        if isinstance(mto, (str, unicode)):
            recipients = mto
            mto = mto.split(',')
        else:
            recipients = ','.join(mto)

        message = message_from_string(messageText)
        email = {
            'from': mfrom,
            'to': recipients,
            'date': DateTime(),  # DateTime beacause timezones.
            'subject': getheader(message['subject']),
            'message': message.get_payload()
        }

        try:
            key = self._emails.maxKey() + 1
        except ValueError:
            key = 0

        store = False
        current_user = user.get_current()
        current_email = current_user.getProperty('email')

        # Don't store anonymous password resets, or emails from the admin
        if current_user.getId(
        ) is None or current_email is None or current_email == self.email_from_address:
            return

        sender_id = current_user.getId()
        if sender_id not in self._outboxes:
            self._outboxes[sender_id] = IITreeSet()
        self._outboxes[sender_id].add(key)
        store = True

        acl_users = getToolByName(self, 'acl_users')
        recipients = []
        for mail in mto:
            recipients.extend(acl_users.searchUsers(email=mail.strip()))
        for recipient in recipients:
            recipient_id = recipient['userid']
            if recipient_id not in self._inboxes:
                self._inboxes[recipient_id] = IITreeSet()
            self._inboxes[recipient_id].add(key)
            store = True

        if store:
            self._emails[key] = email
Esempio n. 3
0
    def _send(self, mfrom, mto, messageText, immediate=False):
        """ Send the message """

        # Send it immediately. We don't want to store mails that doesn't get
        # sent, mail shoud be delivered directly, always.
        MailHost._send(self, mfrom, mto, messageText, immediate=True)
        # I'm not sure you always get list here, so I handle both:
        if isinstance(mto, (str, unicode)):
            recipients = mto
            mto = mto.split(',')
        else:
            recipients = ','.join(mto)

        message = message_from_string(messageText)
        email = {'from': mfrom,
                 'to': recipients,
                 'date': DateTime(), # DateTime beacause timezones.
                 'subject': getheader(message['subject']),
                 'message': message.get_payload()}

        try:
            key = self._emails.maxKey() + 1
        except ValueError:
            key = 0
        
        store = False
        current_user = user.get_current()
        current_email = current_user.getProperty('email')
        
        # Don't store anonymous password resets, or emails from the admin
        if current_user.getId() is None or current_email is None or current_email == self.email_from_address:
            return
        
        sender_id = current_user.getId()
        if sender_id not in self._outboxes:
            self._outboxes[sender_id] = IITreeSet()
        self._outboxes[sender_id].add(key)
        store = True
        
        acl_users = getToolByName(self, 'acl_users')
        recipients = []
        for mail in mto:
            recipients.extend(acl_users.searchUsers(email=mail.strip()))
        for recipient in recipients:
            recipient_id = recipient['userid']
            if recipient_id not in self._inboxes:
                self._inboxes[recipient_id] = IITreeSet()
            self._inboxes[recipient_id].add(key)
            store = True
        
        if store:
            self._emails[key] = email
Esempio n. 4
0
    def _initSite(self, use_changed=False):
        from Products.MailHost.MailHost import MailHost

        site = Folder(id='site').__of__(self.app)
        mh = MailHost('MailHost')
        getSiteManager().registerUtility(mh, IMailHost)

        if use_changed:
            mh.smtp_port = '1'
            mh.smtp_pwd = "value1"
            mh.smtp_host = "value2"
            mh.smtp_uid = "value3"

        return site, mh
Esempio n. 5
0
    def setUp(self):
        from Products.MailHost.MailHost import MailHost

        mh = self._obj = MailHost('foo_mailhost')
        del mh.smtp_queue
        del mh.smtp_queue_directory
        self._BODY = _MAILHOST_BODY
Esempio n. 6
0
 def setUp(self):
     SecurityTest.setUp(self)
     self.site = PropertiedDummySite('site')
     sm = getSiteManager()
     sm.registerUtility(self.site, ISiteRoot)
     self.site._setObject('portal_properties', self._makeOne())
     sm.registerUtility(self.site.portal_properties, IPropertiesTool)
     self.site._setObject('MailHost', MailHost('MailHost'))
     sm.registerUtility(self.site.MailHost, IMailHost)
Esempio n. 7
0
 def __init__(self,
              id='',
              title='',
              smtp_host='localhost',
              smtp_port=25,
              force_tls=False,
              smtp_uid='',
              smtp_pwd='',
              smtp_queue=False,
              smtp_queue_directory='/tmp',
             ):
     """Initialize a new MailHost instance.
     """
     MailHost.__init__(self, id, title, smtp_host, smtp_port, force_tls,
                       smtp_uid, smtp_pwd, smtp_queue, smtp_queue_directory)
     self._emails = IOBTree()
     self._outboxes = OOBTree()
     self._inboxes = OOBTree()
    def setUp(self):
        from Products.CMFCore.interfaces import IPropertiesTool

        SecurityTest.setUp(self)
        self.site = PropertiedDummySite('site')
        sm = getSiteManager()
        sm.registerUtility(MailHost('MailHost'), IMailHost)
        sm.registerUtility(self._makeOne(), IPropertiesTool)
        sm.registerUtility(self.site, ISiteRoot)
Esempio n. 9
0
 def __init__(
     self,
     id='',
     title='',
     smtp_host='localhost',
     smtp_port=25,
     force_tls=False,
     smtp_uid='',
     smtp_pwd='',
     smtp_queue=False,
     smtp_queue_directory='/tmp',
 ):
     """Initialize a new MailHost instance.
     """
     MailHost.__init__(self, id, title, smtp_host, smtp_port, force_tls,
                       smtp_uid, smtp_pwd, smtp_queue, smtp_queue_directory)
     self._emails = IOBTree()
     self._outboxes = OOBTree()
     self._inboxes = OOBTree()
Esempio n. 10
0
    def _initSite(self, use_changed=False):
        self.root.site = Folder(id='site')
        site = self.root.site
        mh = site.MailHost = MailHost('MailHost')

        if use_changed:
            mh.smtp_port = '1'
            mh.smtp_pwd = "value1"
            mh.smtp_host = "value2"
            mh.smtp_uid = "value3"

        return site
Esempio n. 11
0
    def _initSite(self, use_changed=False):
        from Products.MailHost.MailHost import MailHost

        self.root.site = Folder(id='site')
        site = self.root.site
        mh = site.MailHost = MailHost('MailHost')
        sm = getSiteManager()
        sm.registerUtility(site.MailHost, IMailHost)

        if use_changed:
            mh.smtp_port = '1'
            mh.smtp_pwd = "value1"
            mh.smtp_host = "value2"
            mh.smtp_uid = "value3"

        return site
    def _initSite(self, use_changed=False):
        from Products.MailHost.MailHost import MailHost

        site = Folder(id='site').__of__(self.app)
        mh = MailHost('MailHost')
        getSiteManager().registerUtility(mh, IMailHost)

        if use_changed:
            mh.smtp_port = '1'
            mh.smtp_pwd = "value1"
            mh.smtp_host = "value2"
            mh.smtp_uid = "value3"

        return site, mh
Esempio n. 13
0
    def setUp(self):
        from Products.MailHost.MailHost import MailHost

        self._obj = MailHost('foo_mailhost')
        self._BODY = _MAILHOST_BODY
Esempio n. 14
0
 def __init__(self, id):
     MailBase.__init__(self, id)
     self.reset()
Esempio n. 15
0
 def __setstate__(self, state):
     """ load the config when we're loaded from the database """
     MailHost.__setstate__(self, state)
     self._load_config()
Esempio n. 16
0
    def setUp(self):
        from Products.MailHost.MailHost import MailHost

        BodyAdapterTestCase.setUp(self)
        self._obj = MailHost('foo_mailhost')
        self._BODY = _MAILHOST_BODY