From cdd6ef2304db35998e3aae09774de2892846e63f Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 9 Oct 2023 12:08:54 +0300 Subject: =?UTF-8?q?fixes=20#3718=20(YAMN:=20=D0=BD=D0=B5=D0=B8=D0=B7=D0=B2?= =?UTF-8?q?=D0=B5=D1=81=D1=82=D0=BD=D1=8B=D0=B9=20=D0=BA=D0=BE=D0=BD=D1=82?= =?UTF-8?q?=D0=B0=D0=BA=D1=82)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocols/YAMN/src/account.cpp | 9 ++ protocols/YAMN/src/browser/mailbrowser.cpp | 133 +++++++++++------------------ protocols/YAMN/src/services.cpp | 62 ++++---------- protocols/YAMN/src/stdafx.h | 1 + 4 files changed, 76 insertions(+), 129 deletions(-) diff --git a/protocols/YAMN/src/account.cpp b/protocols/YAMN/src/account.cpp index d8ae8abc97..e65ac6417b 100644 --- a/protocols/YAMN/src/account.cpp +++ b/protocols/YAMN/src/account.cpp @@ -799,6 +799,15 @@ uint32_t WriteAccountsToFile(YAMN_PROTOPLUGIN *Plugin, const wchar_t *pwszFilena return PerformAccountWriting(Plugin, hFile); } +CAccount* FindAccountByContact(YAMN_PROTOPLUGIN *Plugin, MCONTACT hContact) +{ + ptrA szId(g_plugin.getStringA(hContact, "Id")); + if (!mir_strlen(szId)) + return nullptr; + + return FindAccountByName(Plugin, szId); +} + CAccount* FindAccountByName(YAMN_PROTOPLUGIN *Plugin, const char *SearchedAccount) { SReadGuard srb(Plugin->AccountBrowserSO); diff --git a/protocols/YAMN/src/browser/mailbrowser.cpp b/protocols/YAMN/src/browser/mailbrowser.cpp index 3284293754..727110be89 100644 --- a/protocols/YAMN/src/browser/mailbrowser.cpp +++ b/protocols/YAMN/src/browser/mailbrowser.cpp @@ -753,29 +753,24 @@ LRESULT CALLBACK NewMailPopupProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPa } else { hContact = PUGetContact(hWnd); - - DBVARIANT dbv; - if (!g_plugin.getString(hContact, "Id", &dbv)) { - Account = FindAccountByName(POP3Plugin, dbv.pszVal); - db_free(&dbv); - } - else Account = (CAccount *)hContact; //???? - - SReadGuard sra(Account->AccountAccessSO); - if (sra.Succeeded()) { - switch (msg) { - case WM_COMMAND: - { - YAMN_MAILBROWSERPARAM Param = { Account, - (Account->NewMailN.Flags & ~YAMN_ACC_POP) | YAMN_ACC_MSGP | YAMN_ACC_MSG, - (Account->NoNewMailN.Flags & ~YAMN_ACC_POP) | YAMN_ACC_MSGP | YAMN_ACC_MSG }; - - RunMailBrowser(&Param); + if (Account = FindAccountByContact(POP3Plugin, hContact)) { + SReadGuard sra(Account->AccountAccessSO); + if (sra.Succeeded()) { + switch (msg) { + case WM_COMMAND: + { + YAMN_MAILBROWSERPARAM Param = { Account, + (Account->NewMailN.Flags & ~YAMN_ACC_POP) | YAMN_ACC_MSGP | YAMN_ACC_MSG, + (Account->NoNewMailN.Flags & ~YAMN_ACC_POP) | YAMN_ACC_MSGP | YAMN_ACC_MSG }; + + RunMailBrowser(&Param); + } + break; } - break; } } } + if ((Account->NewMailN.Flags & YAMN_ACC_CONT) && !(Account->NewMailN.Flags & YAMN_ACC_CONTNOEVENT)) Clist_RemoveEvent(hContact, hContact); } @@ -784,41 +779,29 @@ LRESULT CALLBACK NewMailPopupProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPa case WM_CONTEXTMENU: PUDeletePopup(hWnd); break; + case UM_FREEPLUGINDATA: - { - auto *mpd = (YAMN_MAILSHOWPARAM *)PUGetPluginData(hWnd); - delete mpd; - return FALSE; - } + delete (YAMN_MAILSHOWPARAM *)PUGetPluginData(hWnd); + return FALSE; + case UM_INITPOPUP: - //This is the equivalent to WM_INITDIALOG you'd get if you were the maker of dialog popups. + // This is the equivalent to WM_INITDIALOG you'd get if you were the maker of dialog popups. WindowList_Add(YAMNVar.MessageWnds, hWnd); break; + case UM_DESTROYPOPUP: WindowList_Remove(YAMNVar.MessageWnds, hWnd); break; - case WM_YAMN_STOPACCOUNT: - { - CAccount *ActualAccount; - DBVARIANT dbv; - - MCONTACT hContact = PUGetContact(hWnd); - if (!g_plugin.getString(hContact, "Id", &dbv)) { - ActualAccount = FindAccountByName(POP3Plugin, dbv.pszVal); - db_free(&dbv); - } - else ActualAccount = (CAccount *)hContact; - - if ((CAccount *)wParam != ActualAccount) - break; - DestroyWindow(hWnd); - return 0; - } - case WM_NOTIFY: - default: - break; + case WM_YAMN_STOPACCOUNT: + MCONTACT hContact = PUGetContact(hWnd); + auto *ActualAccount = FindAccountByContact(POP3Plugin, hContact); + if ((CAccount *)wParam != ActualAccount) + break; + DestroyWindow(hWnd); + return 0; } + return DefWindowProc(hWnd, msg, wParam, lParam); } @@ -828,31 +811,18 @@ LRESULT CALLBACK NoNewMailPopupProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM l case WM_COMMAND: if ((HIWORD(wParam) == STN_CLICKED) && (msg == WM_COMMAND)) { MCONTACT hContact = PUGetContact(hWnd); + if (CAccount *ActualAccount = FindAccountByContact(POP3Plugin, hContact)) { + SReadGuard sra(ActualAccount->AccountAccessSO); + if (sra.Succeeded() && msg == WM_COMMAND) { + YAMN_MAILBROWSERPARAM Param = { ActualAccount, ActualAccount->NewMailN.Flags, ActualAccount->NoNewMailN.Flags, nullptr }; - DBVARIANT dbv; - CAccount *ActualAccount; - if (!g_plugin.getString(hContact, "Id", &dbv)) { - ActualAccount = FindAccountByName(POP3Plugin, dbv.pszVal); - db_free(&dbv); - } - else ActualAccount = (CAccount *)hContact; - - SReadGuard sra(ActualAccount->AccountAccessSO); - if (sra.Succeeded()) { - switch (msg) { - case WM_COMMAND: - { - YAMN_MAILBROWSERPARAM Param = { ActualAccount, ActualAccount->NewMailN.Flags, ActualAccount->NoNewMailN.Flags, nullptr }; - - Param.nnflags = Param.nnflags | YAMN_ACC_MSG; //show mails in account even no new mail in account - Param.nnflags = Param.nnflags & ~YAMN_ACC_POP; + Param.nnflags = Param.nnflags | YAMN_ACC_MSG; //show mails in account even no new mail in account + Param.nnflags = Param.nnflags & ~YAMN_ACC_POP; - Param.nflags = Param.nflags | YAMN_ACC_MSG; //show mails in account even no new mail in account - Param.nflags = Param.nflags & ~YAMN_ACC_POP; + Param.nflags = Param.nflags | YAMN_ACC_MSG; //show mails in account even no new mail in account + Param.nflags = Param.nflags & ~YAMN_ACC_POP; - RunMailBrowser(&Param); - } - break; + RunMailBrowser(&Param); } } PUDeletePopup(hWnd); @@ -864,35 +834,28 @@ LRESULT CALLBACK NoNewMailPopupProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM l break; case UM_FREEPLUGINDATA: - //Here we'd free our own data, if we had it. + // Here we'd free our own data, if we had it. return FALSE; + case UM_INITPOPUP: //This is the equivalent to WM_INITDIALOG you'd get if you were the maker of dialog popups. WindowList_Add(YAMNVar.MessageWnds, hWnd); break; + case UM_DESTROYPOPUP: WindowList_Remove(YAMNVar.MessageWnds, hWnd); break; - case WM_YAMN_STOPACCOUNT: - { - CAccount *ActualAccount; - DBVARIANT dbv; - - MCONTACT hContact = PUGetContact(hWnd); - - if (!g_plugin.getString(hContact, "Id", &dbv)) { - ActualAccount = FindAccountByName(POP3Plugin, dbv.pszVal); - db_free(&dbv); - } - else ActualAccount = (CAccount *)hContact; - if ((CAccount *)wParam != ActualAccount) - break; + case WM_YAMN_STOPACCOUNT: + MCONTACT hContact = PUGetContact(hWnd); + CAccount *ActualAccount = FindAccountByContact(POP3Plugin, hContact); + if ((CAccount *)wParam != ActualAccount) + break; - DestroyWindow(hWnd); - return 0; - } + DestroyWindow(hWnd); + return 0; } + return DefWindowProc(hWnd, msg, wParam, lParam); } diff --git a/protocols/YAMN/src/services.cpp b/protocols/YAMN/src/services.cpp index 703b8433c2..b72de25011 100644 --- a/protocols/YAMN/src/services.cpp +++ b/protocols/YAMN/src/services.cpp @@ -43,45 +43,29 @@ static int Service_ContactDoubleclicked(WPARAM wParam, LPARAM lParam) return 0; } -static INT_PTR ContactApplication(WPARAM wParam, LPARAM) +static INT_PTR ContactApplication(WPARAM hContact, LPARAM) { - char *szProto = Proto_GetBaseAccountName(wParam); + char *szProto = Proto_GetBaseAccountName(hContact); if (mir_strcmp(szProto, YAMN_DBMODULE)) return 0; - DBVARIANT dbv; - if (g_plugin.getString(wParam, "Id", &dbv)) - return 0; - - CAccount *ActualAccount = FindAccountByName(POP3Plugin, dbv.pszVal); - if (ActualAccount != nullptr) { - STARTUPINFOW si = { 0 }; - si.cb = sizeof(si); - + if (CAccount *ActualAccount = FindAccountByContact(POP3Plugin, hContact)) { SReadGuard sra(ActualAccount->AccountAccessSO); if (sra.Succeeded()) { if (ActualAccount->NewMailN.App != nullptr) { - wchar_t *Command; + CMStringW wszCommand(L"\""); + wszCommand.Append(ActualAccount->NewMailN.App); + wszCommand.Append(L"\" "); if (ActualAccount->NewMailN.AppParam != nullptr) - Command = new wchar_t[mir_wstrlen(ActualAccount->NewMailN.App) + mir_wstrlen(ActualAccount->NewMailN.AppParam) + 6]; - else - Command = new wchar_t[mir_wstrlen(ActualAccount->NewMailN.App) + 6]; - - if (Command != nullptr) { - mir_wstrcpy(Command, L"\""); - mir_wstrcat(Command, ActualAccount->NewMailN.App); - mir_wstrcat(Command, L"\" "); - if (ActualAccount->NewMailN.AppParam != nullptr) - mir_wstrcat(Command, ActualAccount->NewMailN.AppParam); - - PROCESS_INFORMATION pi; - CreateProcessW(nullptr, Command, nullptr, nullptr, FALSE, NORMAL_PRIORITY_CLASS, nullptr, nullptr, &si, &pi); - delete[] Command; - } + wszCommand.Append(ActualAccount->NewMailN.AppParam); + + PROCESS_INFORMATION pi; + STARTUPINFOW si = {}; + si.cb = sizeof(si); + CreateProcessW(nullptr, wszCommand.GetBuffer(), nullptr, nullptr, FALSE, NORMAL_PRIORITY_CLASS, nullptr, nullptr, &si, &pi); } } } - db_free(&dbv); return 0; } @@ -126,11 +110,7 @@ static INT_PTR ContactMailCheck(WPARAM hContact, LPARAM) if (mir_strcmp(szProto, YAMN_DBMODULE)) return 0; - DBVARIANT dbv; - if (g_plugin.getString(hContact, "Id", &dbv)) - return 0; - - if (CAccount *ActualAccount = FindAccountByName(POP3Plugin, dbv.pszVal)) { + if (CAccount *ActualAccount = FindAccountByContact(POP3Plugin, hContact)) { // we use event to signal, that running thread has all needed stack parameters copied HANDLE ThreadRunningEV; if (nullptr == (ThreadRunningEV = CreateEvent(nullptr, FALSE, FALSE, nullptr))) @@ -153,21 +133,16 @@ static INT_PTR ContactMailCheck(WPARAM hContact, LPARAM) } CloseHandle(ThreadRunningEV); } - db_free(&dbv); return 0; } -/*static*/ void ContactDoubleclicked(WPARAM wParam, LPARAM) +/*static*/ void ContactDoubleclicked(WPARAM hContact, LPARAM) { - char *szProto = Proto_GetBaseAccountName(wParam); + char *szProto = Proto_GetBaseAccountName(hContact); if (mir_strcmp(szProto, YAMN_DBMODULE)) return; - DBVARIANT dbv; - if (g_plugin.getString(wParam, "Id", &dbv)) - return; - - if (CAccount *ActualAccount = FindAccountByName(POP3Plugin, dbv.pszVal)) { + if (CAccount *ActualAccount = FindAccountByContact(POP3Plugin, hContact)) { SReadGuard sra(ActualAccount->AccountAccessSO); if (sra.Succeeded()) { YAMN_MAILBROWSERPARAM Param = { ActualAccount, ActualAccount->NewMailN.Flags, ActualAccount->NoNewMailN.Flags, nullptr }; @@ -181,10 +156,9 @@ static INT_PTR ContactMailCheck(WPARAM hContact, LPARAM) RunMailBrowser(&Param); } } - db_free(&dbv); } -// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // / +///////////////////////////////////////////////////////////////////////////////////////// HBITMAP LoadBmpFromIcon(HICON hIcon) { @@ -227,7 +201,7 @@ static int AddTopToolbarIcon(WPARAM, LPARAM) return 0; } -// // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // // / +///////////////////////////////////////////////////////////////////////////////////////// int Shutdown(WPARAM, LPARAM) { diff --git a/protocols/YAMN/src/stdafx.h b/protocols/YAMN/src/stdafx.h index cb317d8230..c22e2e1bbd 100644 --- a/protocols/YAMN/src/stdafx.h +++ b/protocols/YAMN/src/stdafx.h @@ -88,6 +88,7 @@ uint32_t AddAccountsFromFile(YAMN_PROTOPLUGIN *Plugin, const wchar_t *pwszFilen CAccount* CreatePluginAccount(YAMN_PROTOPLUGIN *Plugin); int DeleteAccount(YAMN_PROTOPLUGIN *Plugin, CAccount *Which); void DeletePluginAccount(CAccount *OldAccount); +CAccount* FindAccountByContact(YAMN_PROTOPLUGIN *Plugin, MCONTACT hContact); CAccount* FindAccountByName(YAMN_PROTOPLUGIN *Plugin, const char *SearchedAccount); CAccount* GetNextFreeAccount(YAMN_PROTOPLUGIN *Plugin); uint32_t WriteAccountsToFile(YAMN_PROTOPLUGIN *Plugin, const wchar_t *pwszFilename); -- cgit v1.2.3