'Returns the mail message with the given index.
Each message is a dictionary with date, from, subject, body, attachments entries.
The attachments entry is a list of (MIME-type, str)-tuples.'

def __getitem__(self, i, attachments=False, cached=True):

    i += 1
    id = ('mail-%s-%s-%s-%s' % (self.parent._id, self.name, i, attachments))
    if (cached and (id in cache)):
        m = cache[id]
    else:
        (status, response) = self.parent.imap4.select(self._name, readonly=1)
        (status, response1) = self.parent.imap4.fetch(str(i), '(BODY.PEEK[HEADER])')
        (status, response2) = self.parent.imap4.fetch(str(i), ('(BODY.PEEK[%s])' % (((not attachments) and 'TEXT') or '')))
        time.sleep(0.1)
        m = (response1[0][1] + response2[0][1])
        if cached:
            cache[id] = m
    m = email.message_from_string(encode_utf8(m))
    d = Message([(DATE, _decode(m.get(DATE), m)), (FROM, _decode(m.get(FROM), m)), (SUBJECT, _decode(m.get(SUBJECT), m)), (BODY, ''), (ATTACHMENTS, [])])
    for p in ((m.is_multipart() and m.get_payload()) or [m]):
        if (p.get_content_type() == 'text/plain'):
            d[BODY] += _decode(p.get_payload(decode=True), p)
        elif attachments:
            d[ATTACHMENTS].append((p.get_content_type(), p.get_payload()))
    for k in d:
        if isinstance(d[k], basestring):
            d[k] = d[k].strip()
            d[k] = d[k].replace('\r\n', '\n')
    return d
