Mail control panel
==================

First some initial setup code:

    >>> from Products.CMFCore.utils import getToolByName
    >>> from zope.component import getUtility
    >>> from Products.MailHost.interfaces import IMailHost
    >>> ctool = getToolByName(self.portal, 'portal_calendar')
    >>> mailhost = getUtility(IMailHost)
    >>> self.loginAsManager()

Viewing the mail control panel
--------------------------------

    >>> self.browser.open('http://nohost/plone/@@mail-controlpanel')
    >>> self.browser.url.endswith('mail-controlpanel')
    True

Click the cancel button:

    >>> self.browser.getControl(name="form.actions.cancel").click()
    >>> self.browser.url.endswith('plone_control_panel')
    True

There should be still no changes:

    >>> 'Changes canceled.' in self.browser.contents
    True

Make some changes
-----------------

    >>> self.browser.open('http://nohost/plone/@@mail-controlpanel')
    >>> self.browser.url.endswith('mail-controlpanel')
    True

    >>> self.browser.getControl(name='form.smtp_host').value = 'localhost2'
    >>> self.browser.getControl(name='form.smtp_port').value = '2525'
    >>> self.browser.getControl(name='form.smtp_userid').value = 'admin'
    >>> self.browser.getControl(name='form.smtp_pass').value = 'secret'
    >>> self.browser.getControl(name='form.email_from_name').value = 'Spambot'
    >>> self.browser.getControl(name='form.email_from_address').value = 'spam@localhost'

Click the save button:

    >>> self.browser.getControl(name="form.actions.save").click()
    >>> self.browser.url.endswith('mail-controlpanel')
    True

We should be informed that something has changed:

    >>> 'Changes saved.' in self.browser.contents
    True

Make sure the changes have been applied correctly to the mailhost:

    >>> mailhost.smtp_host
    u'localhost2'

    >>> mailhost.smtp_port
    2525

    >>> getattr(mailhost, 'smtp_userid', mailhost.smtp_uid)
    u'admin'

    >>> getattr(mailhost, 'smtp_pass', mailhost.smtp_pwd)
    u'secret'

    >>> self.site_props.email_from_name
    u'Spambot'

    >>> self.site_props.email_from_address
    'spam@localhost'

Dealing with non-ascii
------------------------

There is no problem if we use the control panel to fill in the values:

    >>> self.browser.open('http://nohost/plone/@@mail-controlpanel')

    >>> self.browser.getControl(name='form.email_from_name').value = '\xc3\x89\xc3\xa7 \xc3\xb6\xc5\x93 \xc3\xb2'

    >>> self.browser.getControl(name="form.actions.save").click()
    >>> self.browser.url.endswith('mail-controlpanel')
    True

    >>> 'Changes saved.' in self.browser.contents
    True

    >>> self.site_props.email_from_name
    u'\xc9\xe7 \xf6\u0153 \xf2'

But we must deal with encoding if we someone set this info via ZMI:

    >>> self.browser.open('http://nohost/plone/manage_propertiesForm')
    >>> self.browser.getControl(name='email_from_name:string').value = '\xc3\x89\xc3\xa7 \xc3\xb6\xc5\x93 \xc3\xb2'
    >>> self.browser.getControl(name="manage_editProperties:method").click()

And the control panel should not break:
    
    >>> self.browser.open('http://nohost/plone/@@mail-controlpanel')

Even though data is stored as string:

    >>> self.site_props.email_from_name
    '\xc3\x89\xc3\xa7 \xc3\xb6\xc5\x93 \xc3\xb2'
