VOID CALLBACK OnReconnectTimer(HWND, UINT, UINT_PTR, DWORD) { _popupUtil(TranslateT("Forcefully reconnecting to Exchange server ...")); exchangeServer.Reconnect(); //reconnect }
int CExchangeServer::Connect(int bForceConnect) { int maxRetries = db_get_b(NULL, ModuleName, "MaxRetries", MAX_EXCHANGE_CONNECT_RETRIES); if (bForceConnect) { bTryConnect = 1; cConnections = 0; } if (cConnections >= maxRetries) { bTryConnect = 0; cConnections = 0; _popupUtil("Maximum number of retries reached.\nPlugin will stop trying to connect automatically."); } if (bTryConnect) cConnections++; if ((bTryConnect) && !IsServerAvailable()) { bTryConnect = 0; _popupUtil("Server not available"); } if ( !IsConnected() && bTryConnect) { TCHAR user[1024]; //lovely TCHAR password[1024]; //i know TCHAR server[1024]; GetStringFromDatabase("Username", _T(""), user, _countof(user)); if (ServiceExists(MS_UTILS_REPLACEVARS)) _tcsncpy_s(user, VARST(user), _TRUNCATE); GetStringFromDatabase("Password", _T(""), password, _countof(password)); GetStringFromDatabase("Server", _T(""), server, _countof(server)); int port = db_get_dw(NULL, ModuleName, "Port", EXCHANGE_PORT); if (_tcslen(server) > 0) //only connect if there's a server to connect to return DoConnect(user, password, server, port); _popupUtil("Server is not configured..."); } return -1; //0 on success, != 0 otherwise }
int CExchangeServer::Check(int bNoEmailsNotify) { int count = -1; if (IsConnected()) { count = GetUnreadEmailsCount(); if (count == -1) { Reconnect(); if (IsConnected()) count = GetUnreadEmailsCount(); else return -1; } } else { Reconnect(); if (IsConnected()) count = GetUnreadEmailsCount(); else return -1; if (count==-1) return -1; } if (((count > 0) || ((bNoEmailsNotify) && (count >= 0))) && (count != -1)) { TCHAR buffer[1024]; if (count != 1) mir_sntprintf(buffer, SIZEOF(buffer), TranslateT("You have %d unread emails..."), count); else mir_sntprintf(buffer, SIZEOF(buffer), TranslateT("You have one unread email...")); ShowMessage(buffer, count); } if (count==-1) _popupUtil("Cannot connect to Exchange server..."); return count; }