def gm_fake(): from mailur import local def uid(name, *a, **kw): responces = getattr(gm_client, name.lower(), None) if responces: return responces.pop() return con._uid(name, *a, **kw) def xlist(*a, **kw): responces = getattr(gm_client, 'list', None) if responces: return responces.pop() return 'OK', [ b'(\\HasNoChildren \\All) "/" mlr', b'(\\HasNoChildren \\Junk) "/" mlr/All', b'(\\HasNoChildren \\Trash) "/" mlr/All', b'(\\HasNoChildren \\Draft) "/" mlr/All', ] con = local.connect(*local.master_login(username=test2)) con._uid = con.uid con.uid = uid con._list = con.list con.list = xlist return con
def init(request): from mailur import local for i in range(len(request.session.items)): users.append( ['test1_%s' % uuid.uuid4().hex, 'test2_%s' % uuid.uuid4().hex]) users_str = ' '.join(sum(users, [])) subprocess.call(''' path=/home/vmail/test rm -rf $path mkdir -p $path chown vmail:vmail $path names="%s" home=$path append=1 bin/install-users systemctl restart dovecot ''' % users_str, shell=True, cwd=root) # try to connect to dovecot for i in range(5): try: username, pwd = local.master_login(username=users[0][0]) local.connect(username, pwd) return except Exception as e: err = e time.sleep(1) print('Another try to connect to dovecot: %s' % err) raise err
def setup(new_users, gm_client, sendmail, patch_conf): from mailur import imap, local, remote global con_local, con_gmail con_local = local.client(None) con_gmail = local.connect(*local.master_login(username=test2)) remote.data_account({ 'username': '******', 'password': '******', 'imap_host': 'imap.gmail.com', 'smtp_host': 'smtp.gmail.com', }) yield con_local.logout() con_gmail.logout() imap.clean_pool(test1) imap.clean_pool(test2)