Mail related functional tests
=============================

Some initial setup:

  >>> from Testing.testbrowser import Browser
  >>> browser = Browser()

We need to fake a valid mail setup:

  >>> portal.email_from_address = "mail@plone.test"
  >>> mailhost = self.portal.MailHost

Contact form
------------

Let's go to the contact form:

  >>> browser.open('http://nohost/plone/contact-info')

Now fill in the form:

  >>> form = browser.getForm(name='feedback_form')

  >>> form.getControl(name='sender_fullname').value = 'T\xc3\xa4st user'
  >>> form.getControl(name='sender_from_address').value = 'test@plone.test'
  >>> form.getControl(name='subject').value = 'Some t\xc3\xa4st subject.'
  >>> form.getControl(name='message').value = 'Another t\xc3\xa4st message.'

And submit it:

  >>> form.submit()
  
  >>> browser.url
  'http://nohost/plone/contact-info'

  >>> 'Mail sent' in browser.contents
  True
  
As part of our test setup, we replaced the original MailHost with our
own version.  Our version doesn't mail messages, it just collects them
in a list called ``messages``:

  >>> len(mailhost.messages)
  1
  >>> msg = mailhost.messages[0]

Now that we have the message, we want to look at its contents:

  >>> 'To: mail@plone.test' in msg
  True

  >>> 'From: mail@plone.test' in msg
  True

We expect the headers to be properly header encoded (7-bit):

  >>> 'Subject: =?utf-8?q?Some_t=C3=A4st_subject=2E?=' in msg
  True

The output should be encoded in a reasonable manner (in this case
quoted-printable).  There may be some small differences in where
exactly the lines are cut off, depending on whether you use five.pt or
not, so we turn the message into one line first:

  >>> msg.replace('=\n', '').replace('\n', ' ')
  '...Another t=C3=A4st message...You are receiving this mail because T=C3=A4st user test@plone.test...is sending feedback about the site you administer at...

We can also decode the string, though we should still be careful about
lines ending in different spots:

  >>> import quopri
  >>> quopri.decodestring(msg).replace('\n', ' ')
  '...Another t\xc3\xa4st message...You are receiving this mail because T\xc3\xa4st user test@plone.test...is sending feedback about the site you administer at...'
