'Add message and return assigned key.'

def add(self, message):

    key = self._encryption_key_func()
    es = None
    try:
        tmpdir = os.path.join(self._path, 'tmp')
        if (not os.path.exists(tmpdir)):
            os.mkdir(tmpdir, 448)
        if key:
            es = EncryptingStreamer(key, dir=tmpdir, name='WERVD', delimited=False)
        else:
            es = ChecksummingStreamer(dir=tmpdir, name='WERVD')
        self._dump_message(message, es)
        es.finish()
        saved = False
        key = None
        outer_mac = es.outer_mac_sha256()
        for l in range(10, len(outer_mac)):
            key = outer_mac[:l]
            fn = os.path.join(self._path, 'new', key)
            if (not os.path.exists(fn)):
                es.save(fn)
                saved = self._toc[key] = os.path.join('new', key)
                break
        if (not saved):
            raise mailbox.ExternalClashError(_('Could    not    find    a    filename    for    the    message.'))
        return key
    finally:
        if (es is not None):
            es.close()
