=============
IMAP accounts
=============

The `Account` class is an object-oriented representation of an IMAP account on
a server.

An account requires information about the server on which it is located and
the user credentials to allow logging in:

>>> from gocept.imapapi.account import Account
>>> account = Account('localhost', 10143, 'test', 'bsdf')

Note that the account object provides the IAccount interface:

>>> from gocept.imapapi.interfaces import IAccount
>>> IAccount.providedBy(account)
True
>>> account.host
'localhost'
>>> account.port
10143
>>> account.user
'test'
>>> account.password
'bsdf'


Retrieving folder structure
===========================

An account contains folders, but does not contain messages by itself:

>>> from pprint import pprint
>>> pprint(dict(account.folders))
{'Bar': <gocept.imapapi.folder.Folder object 'Bar' at 0x...>,
 'INBOX': <gocept.imapapi.folder.Folder object 'INBOX' at 0x...>}

>>> account.messages
Traceback (most recent call last):
AttributeError: 'Account' object has no attribute 'messages'

Individual folders can be retrieved by specifying their name:

>>> account.folders['INBOX']
<gocept.imapapi.folder.Folder object 'INBOX' at 0x...>

>>> account.folders['nofolder']
Traceback (most recent call last):
KeyError: 'nofolder'


Failing logins
==============

If the connection can not be established, the account object will not be
created:

>>> account = Account('localhost', 10143, 'test', 'foo')
Traceback (most recent call last):
error: Authentication failed.

>>> account = Account('localhost', 10144, 'test', 'bsdf')
Traceback (most recent call last):
error: (..., 'Connection refused')
