     return username.replace(/[^a-zA-Z]/gm, "")
 
 getEmails = () ->
+    await resetImapClient()
     lock = await imapClient.getMailboxLock('INBOX')
     try
         count = (await imapClient.status('INBOX', {messages: true})).messages

import logger from '../log'

imapClient = undefined
if process.env["EMAIL_USER"] and process.env["EMAIL_PASSWORD"]
    imapClient = new ImapFlow
        host: 'imap.gmail.com',
        port: 993,
        secure: true,
        auth:
            user: process.env["EMAIL_USER"],
            pass: process.env["EMAIL_PASSWORD"]

    imapClient.connect()
else
    logger.error("No imap data specified")

randomString = (len) ->
    Math.random().toString(36).substr(2, len)

    return result

findConfirmLink = (login) ->
    try
        emails = await getEmails()
        for email in emails
            res = RegExp("https:\\/\\/informatics\\.msk\\.ru\\/login\\/confirm\\.php\\?data=\\w+\\/#{login}").exec(email)?[0]
            if res
                return res
    catch e
        logger.error(e)
        return undefined
    return undefined

registerOnInformatics = (data) ->
