 
     return xOAuthCache[account.id]
 
+
+# force the generator to create a new access token
+# used when the connection fail in imap
+# (smtp calls the generateToken function directly)
 module.exports.forceOauthRefresh = (account, callback) ->
     log.info "FORCE OAUTH REFRESH"
     getXoauth2Generator(account).generateToken callback
 
+
+# create a nodemailer config for this account
 module.exports.makeSMTPConfig = (account) ->
     options =
         port: account.smtpPort

    return options



module.exports.makeIMAPConfig = (account, callback) ->

    if account.oauthProvider is "GMAIL"


xOAuthCache = {}

# This file handle the generation of config for node-imap and nodemailer
# it also handles xoauthgenerators as singletons by account
# to prevent race between imap & smtp in creating access tokens

CLIENT_ID = '260645850650-2oeufakc8ddbrn8p4o58emsl7u0r0c8s' +
            '.apps.googleusercontent.com'

# @TODO : investigate a better way to distribute this
CLIENT_SECRET = '1gNUceDM59TjFAks58ftsniZ'


# get the single instance of xoauthGenerator for this account
getXoauth2Generator = (account) ->
    unless xOAuthCache[account.id]
        log.info "XOAUTH GENERATOR FOR #{account.label}"

        timeout = 1000 * account.oauthTimeout - Date.now() # timeout in ms
        timeout = Math.floor(timeout / 1000) # timeout in s
        timeout = Math.max(timeout, 0) # min = 0

        generator = xoauth2.createXOAuth2Generator
            user: account.login
