From 28e2acf8360a852a3f4f5bd7dd105955a77af054 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Wed, 10 Jul 2024 20:24:11 +0300 Subject: =?UTF-8?q?fixes=20#4497=20(Spamotron:=20=D0=BF=D1=80=D0=B5=D0=BA?= =?UTF-8?q?=D1=80=D0=B0=D1=82=D0=B8=D1=82=D1=8C=20=D0=BF=D0=BE=D0=B4=D0=B4?= =?UTF-8?q?=D0=B5=D1=80=D0=B6=D0=BA=D1=83=20=D0=B8=D0=BB=D0=B8=20=D0=B4?= =?UTF-8?q?=D0=BE=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D1=82=D1=8C)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/PluginUpdater/src/DlgUpdate.cpp | 1 + plugins/Spamotron/Spamotron.vcxproj | 56 --- plugins/Spamotron/Spamotron.vcxproj.filters | 46 --- plugins/Spamotron/res/Version.rc | 9 - plugins/Spamotron/res/spamotron.rc | 267 ------------- plugins/Spamotron/src/bayes.cpp | 386 ------------------ plugins/Spamotron/src/options.cpp | 580 ---------------------------- plugins/Spamotron/src/popups.cpp | 240 ------------ plugins/Spamotron/src/resource.h | 90 ----- plugins/Spamotron/src/spamotron.cpp | 520 ------------------------- plugins/Spamotron/src/stdafx.cxx | 18 - plugins/Spamotron/src/stdafx.h | 150 ------- plugins/Spamotron/src/utils.cpp | 509 ------------------------ plugins/Spamotron/src/version.h | 13 - 14 files changed, 1 insertion(+), 2884 deletions(-) delete mode 100644 plugins/Spamotron/Spamotron.vcxproj delete mode 100644 plugins/Spamotron/Spamotron.vcxproj.filters delete mode 100644 plugins/Spamotron/res/Version.rc delete mode 100644 plugins/Spamotron/res/spamotron.rc delete mode 100644 plugins/Spamotron/src/bayes.cpp delete mode 100644 plugins/Spamotron/src/options.cpp delete mode 100644 plugins/Spamotron/src/popups.cpp delete mode 100644 plugins/Spamotron/src/resource.h delete mode 100644 plugins/Spamotron/src/spamotron.cpp delete mode 100644 plugins/Spamotron/src/stdafx.cxx delete mode 100644 plugins/Spamotron/src/stdafx.h delete mode 100644 plugins/Spamotron/src/utils.cpp delete mode 100644 plugins/Spamotron/src/version.h (limited to 'plugins') diff --git a/plugins/PluginUpdater/src/DlgUpdate.cpp b/plugins/PluginUpdater/src/DlgUpdate.cpp index a9ab7fd60b..4ddae467ab 100644 --- a/plugins/PluginUpdater/src/DlgUpdate.cpp +++ b/plugins/PluginUpdater/src/DlgUpdate.cpp @@ -561,6 +561,7 @@ static renameTable[] = { L"omegle.dll", nullptr }, { L"openssl.dll", nullptr }, { L"rate.dll", nullptr }, + { L"spamotron.dll", nullptr }, { L"sms.dll", nullptr }, { L"tlen.dll", nullptr }, { L"xfire.dll", nullptr }, diff --git a/plugins/Spamotron/Spamotron.vcxproj b/plugins/Spamotron/Spamotron.vcxproj deleted file mode 100644 index d3bf8ace4d..0000000000 --- a/plugins/Spamotron/Spamotron.vcxproj +++ /dev/null @@ -1,56 +0,0 @@ - - - - - Debug - Win32 - - - Debug - x64 - - - Release - Win32 - - - Release - x64 - - - - {DBB261B4-E433-4DFF-8A5D-6C3B5B5F4FF4} - Spamotron - - - - - - - - - - - Create - - - - - - - - - - - - {6124e997-426e-4a0b-9617-d6d577d5e7d7} - - - {0c02e395-e73f-47e3-8b95-b7924c0c7a6a} - - - - - - - \ No newline at end of file diff --git a/plugins/Spamotron/Spamotron.vcxproj.filters b/plugins/Spamotron/Spamotron.vcxproj.filters deleted file mode 100644 index 6c4289cf1c..0000000000 --- a/plugins/Spamotron/Spamotron.vcxproj.filters +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - Source Files - - - - - Header Files - - - Header Files - - - Header Files - - - Header Files - - - - - Resource Files - - - Resource Files - - - \ No newline at end of file diff --git a/plugins/Spamotron/res/Version.rc b/plugins/Spamotron/res/Version.rc deleted file mode 100644 index 5a5ddd63ed..0000000000 --- a/plugins/Spamotron/res/Version.rc +++ /dev/null @@ -1,9 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#ifdef APSTUDIO_INVOKED -#error this file is not editable by Microsoft Visual C++ -#endif //APSTUDIO_INVOKED - -#include "..\src\version.h" - -#include "..\..\build\Version.rc" diff --git a/plugins/Spamotron/res/spamotron.rc b/plugins/Spamotron/res/spamotron.rc deleted file mode 100644 index 50f0337bac..0000000000 --- a/plugins/Spamotron/res/spamotron.rc +++ /dev/null @@ -1,267 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#include "..\src\resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include "afxres.h" - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// Russian (Russia) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_RUS) -LANGUAGE LANG_RUSSIAN, SUBLANG_DEFAULT -#pragma code_page(1251) - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE -BEGIN - "..\\src\\resource.h\0" -END - -2 TEXTINCLUDE -BEGIN - "#include ""afxres.h""\r\n" - "\0" -END - -3 TEXTINCLUDE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED - - -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_SPAMOTRON_BAYES DIALOGEX 0, 0, 309, 230 -STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD -EXSTYLE WS_EX_CONTROLPARENT -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - CONTROL "Enabled",IDC_OPT_BAYES_ENABLED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,15,101,10 - RTEXT "Learned ham messages:",IDC_STATIC_HAMCOUNT_LABEL,122,21,122,8 - LTEXT "0",IDC_STATIC_HAM_COUNT,249,21,44,8 - RTEXT "Learned spam messages:",IDC_STATIC_SPAMCOUNT_LABEL,122,11,122,8 - LTEXT "0",IDC_STATIC_SPAM_COUNT,249,11,44,8 - GROUPBOX "Filtering options",IDC_STATIC,8,32,293,63 - CONTROL "Do not send challenge request if message score above",IDC_OPT_BAYES_BLOCK_MSG, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,45,185,10 - EDITTEXT IDC_OPT_BAYES_SPAM_SCORE,204,44,22,12,ES_CENTER | ES_AUTOHSCROLL - CONTROL "Auto approve contact if message score below",IDC_OPT_BAYES_AUTO_APPROVE, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,59,160,10 - EDITTEXT IDC_OPT_BAYES_HAM_SCORE,176,58,22,12,ES_CENTER | ES_AUTOHSCROLL - CONTROL "and learn as ham",IDC_OPT_BAYES_AUTOLEARN_AUTOAPPROVED, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,203,59,90,10 - LTEXT "Do not enable any of these options until Spam-o-tron has learned at least 20 of ham and 50 of spam messages.",IDC_STATIC,16,72,277,18,WS_DISABLED - GROUPBOX "Learning options",IDC_STATIC,8,95,293,127 - CONTROL "Auto-learn messages from approved contacts as ham",IDC_OPT_BAYES_AUTOLEARN_APPROVED, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,108,277,10 - CONTROL "Auto-learn messages from contacts if not approved in",IDC_OPT_BAYES_AUTOLEARN_NOT_APPROVED, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,122,183,10 - EDITTEXT IDC_OPT_BAYES_WAIT_APPROVE,201,120,22,12,ES_CENTER | ES_AUTOHSCROLL - LTEXT "days as spam",IDC_STATIC_DAYSASSPAM,226,122,67,8 - CONTROL "Auto-learn outgoing messages as ham",IDC_OPT_BAYES_AUTOLEARN_OUTGOING, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,136,277,10 - LTEXT "Learn message:",IDC_STATIC,16,154,222,8 - EDITTEXT IDC_OPT_BAYES_LEARNBOX,16,165,222,49,ES_MULTILINE | ES_AUTOVSCROLL | ES_WANTRETURN - PUSHBUTTON "Spam",IDC_OPT_BAYES_SPAM,244,165,49,14,WS_GROUP - PUSHBUTTON "Ham",IDC_OPT_BAYES_HAM,244,182,49,14,WS_GROUP - PUSHBUTTON "Analyze",IDC_CHECK_MSG,244,200,49,14,WS_GROUP -END - - -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO -BEGIN - IDD_SPAMOTRON_BAYES, DIALOG - BEGIN - LEFTMARGIN, 8 - RIGHTMARGIN, 301 - VERTGUIDE, 16 - VERTGUIDE, 238 - VERTGUIDE, 244 - VERTGUIDE, 249 - VERTGUIDE, 293 - TOPMARGIN, 8 - BOTTOMMARGIN, 222 - HORZGUIDE, 15 - HORZGUIDE, 25 - HORZGUIDE, 32 - HORZGUIDE, 50 - HORZGUIDE, 64 - HORZGUIDE, 95 - HORZGUIDE, 113 - HORZGUIDE, 127 - HORZGUIDE, 141 - HORZGUIDE, 165 - HORZGUIDE, 214 - END -END -#endif // APSTUDIO_INVOKED - -#endif // Russian (Russia) resources -///////////////////////////////////////////////////////////////////////////// - - -///////////////////////////////////////////////////////////////////////////// -// English (United States) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US -#pragma code_page(1252) - -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_SPAMOTRON_MAIN DIALOGEX 0, 0, 309, 230 -STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD -EXSTYLE WS_EX_CONTROLPARENT -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - GROUPBOX "Settings",IDC_STATIC,8,8,293,121 - LTEXT "Enabled accounts:",IDC_STATIC,16,21,98,8 - CONTROL "",IDC_OPT_PROTOCOLS,"SysListView32",LVS_REPORT | LVS_SINGLESEL | LVS_ALIGNLEFT | LVS_NOCOLUMNHEADER | LVS_NOSORTHEADER | WS_BORDER | WS_TABSTOP,16,33,98,89 - LTEXT "Auto approve on:",IDC_STATIC,122,17,171,8 - CONTROL "Outgoing message",IDC_OPT_OUT_MSG_APPROVE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,122,28,171,10 - CONTROL "Incoming message with any word from list:",IDC_OPT_IN_MSG_APPROVE, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,122,42,171,10 - EDITTEXT IDC_OPT_IN_MSG_APPROVE_WORDLIST,122,56,171,24,ES_AUTOHSCROLL - CONTROL "Hide contact until verified",IDC_OPT_HIDE_UNTIL_VERIFIED, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,122,86,171,10 - CONTROL "Add permanently to list on verified",IDC_OPT_ADD_PERMANENTLY, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,122,100,171,10 - CONTROL "Log actions to system history",IDC_OPT_LOG_ACTIONS, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,122,114,171,10 - GROUPBOX "Flood protection",IDC_STATIC,8,134,293,88 - LTEXT "Do not send more than",IDC_STATIC,16,148,74,8 - EDITTEXT IDC_OPT_MAX_MSG_CONTACT,91,146,22,12,ES_CENTER | ES_AUTOHSCROLL | ES_NUMBER - LTEXT "messages to one contact per day",IDC_STATIC,118,148,175,8 - CONTROL "Do not reply to the same message more than",IDC_OPT_DONT_REPLY_SAME_MSG, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,161,152,10 - EDITTEXT IDC_OPT_MAX_SAME_MSG,170,160,22,12,ES_CENTER | ES_AUTOHSCROLL | ES_NUMBER - LTEXT "times a day",IDC_STATIC,196,162,97,8 - CONTROL "Do not reply to messages with words in this list:",IDC_OPT_DONT_REPLY_MSG, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,175,277,10 - EDITTEXT IDC_OPT_DONT_REPLY_MSG_WORDLIST,16,189,277,24,ES_MULTILINE | ES_AUTOVSCROLL | ES_WANTRETURN -END - -IDD_SPAMOTRON_Q DIALOGEX 0, 0, 309, 230 -STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD -EXSTYLE WS_EX_CONTROLPARENT -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - LTEXT "Mode:",IDC_STATIC,8,10,25,8 - COMBOBOX IDC_OPT_MODE,35,8,85,50,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP - CONTROL "Case-sensitive",IDC_OPT_CCRESPONSE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,126,10,175,10 - LTEXT "will be saved in %mathexpr%",IDC_STATIC_MODEMSG,126,10,175,10 - CONTROL "Send challenge on incoming message:",IDC_OPT_REPLY_ON_MSG, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,28,293,10 - EDITTEXT IDC_OPT_CHALLENGE,8,40,293,28,ES_MULTILINE | ES_AUTOVSCROLL | ES_WANTRETURN | WS_VSCROLL | WS_GROUP - LTEXT "Responses: (saved in %response%, %response-n% variables)",IDC_STATIC_RESPONSE,8,72,293,8 - EDITTEXT IDC_OPT_RESPONSE,8,82,293,28,ES_MULTILINE | ES_AUTOHSCROLL | ES_WANTRETURN | WS_VSCROLL - EDITTEXT IDC_OPT_MATH_RESPONSE,8,82,293,28,ES_AUTOHSCROLL | NOT WS_VISIBLE | WS_DISABLED - CONTROL "Reply on success:",IDC_OPT_REPLY_ON_SUCCESS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,115,293,10 - EDITTEXT IDC_OPT_SUCCESS_RESPONSE,8,127,293,20,ES_MULTILINE | ES_AUTOVSCROLL | ES_WANTRETURN | WS_VSCROLL - CONTROL "Send challenge on authorization request:",IDC_OPT_REPLY_ON_AUTH, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,153,293,10 - EDITTEXT IDC_OPT_AUTH_CHALLENGE,8,165,293,28,ES_MULTILINE | ES_AUTOVSCROLL | ES_WANTRETURN | WS_VSCROLL - CONTROL "Keep blocked messages in contact history",IDC_OPT_KEEP_BLOCKED_MSG, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,198,201,10 - CONTROL "and mark them unread after approval",IDC_OPT_MARK_MSG_UNREAD_ON_APPROVAL, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,210,191,11 - PUSHBUTTON "Reset to defaults",IDC_DEFAULTS,214,208,87,14 -END - -IDD_SPAMOTRON_POPUPS DIALOGEX 0, 0, 309, 230 -STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD -EXSTYLE WS_EX_CONTROLPARENT -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - CONTROL "Enable popup notifications",IDC_OPT_POPUPS_ENABLED, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,19,277,10 - GROUPBOX "Appearance",IDC_STATIC,8,41,293,181 - CTEXT "Foreground",IDC_STATIC,126,54,50,8 - CTEXT "Background",IDC_STATIC,184,54,50,8 - CTEXT "Timeout (sec)",IDC_STATIC,235,54,54,8 - CONTROL "Contact blocked",IDC_OPT_POPUPS_NOTIFY_BLOCKED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,67,105,10 - CONTROL "",IDC_OPT_POPUPS_BLOCKED_FOREGROUND,"ColourPicker",WS_TABSTOP,126,67,50,10 - CONTROL "",IDC_OPT_POPUPS_BLOCKED_BACKGROUND,"ColourPicker",WS_TABSTOP,184,67,50,10 - EDITTEXT IDC_OPT_POPUPS_BLOCKED_TIMEOUT,248,66,28,12,ES_CENTER | ES_AUTOHSCROLL - CONTROL "Contact approved",IDC_OPT_POPUPS_NOTIFY_APPROVED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,83,105,10 - CONTROL "",IDC_OPT_POPUPS_APPROVED_FOREGROUND,"ColourPicker",WS_TABSTOP,126,83,50,10 - CONTROL "",IDC_OPT_POPUPS_APPROVED_BACKGROUND,"ColourPicker",WS_TABSTOP,184,83,50,10 - EDITTEXT IDC_OPT_POPUPS_APPROVED_TIMEOUT,248,82,28,12,ES_CENTER | ES_AUTOHSCROLL - CONTROL "Challenge sent",IDC_OPT_POPUPS_NOTIFY_CHALLENGE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,99,105,10 - CONTROL "",IDC_OPT_POPUPS_CHALLENGE_FOREGROUND,"ColourPicker",WS_TABSTOP,126,99,50,10 - CONTROL "",IDC_OPT_POPUPS_CHALLENGE_BACKGROUND,"ColourPicker",WS_TABSTOP,184,99,50,10 - EDITTEXT IDC_OPT_POPUPS_CHALLENGE_TIMEOUT,248,98,28,12,ES_CENTER | ES_AUTOHSCROLL - CONTROL "Use default colors",IDC_OPT_POPUPS_DEFAULT_COLORS, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,139,269,10 - CONTROL "Use Windows colors",IDC_OPT_POPUPS_WINDOWS_COLORS, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,152,269,10 - CONTROL "Default timeout",IDC_OPT_POPUPS_DEFAULT_TIMEOUT,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,16,166,269,8 - PUSHBUTTON "Preview",IDC_OPT_POPUPS_PREVIEW,227,198,66,14 -END - - -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO -BEGIN - IDD_SPAMOTRON_MAIN, DIALOG - BEGIN - END - - IDD_SPAMOTRON_Q, DIALOG - BEGIN - END - - IDD_SPAMOTRON_POPUPS, DIALOG - BEGIN - END -END -#endif // APSTUDIO_INVOKED - -#endif // English (United States) resources -///////////////////////////////////////////////////////////////////////////// - - - -#ifndef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 3 resource. -// - - -///////////////////////////////////////////////////////////////////////////// -#endif // not APSTUDIO_INVOKED - diff --git a/plugins/Spamotron/src/bayes.cpp b/plugins/Spamotron/src/bayes.cpp deleted file mode 100644 index d4d7d26d5f..0000000000 --- a/plugins/Spamotron/src/bayes.cpp +++ /dev/null @@ -1,386 +0,0 @@ -#include "stdafx.h" -#include "io.h" - -#define DELIMS " ,.;!?@-\\/+&\x0D\x0A" - -sqlite3 *bayesdb; -#ifdef _DEBUG -sqlite3 *bayesdbg; -#endif -HANDLE hBayesFolder; - -int CheckBayes() -{ - char bayesdb_fullpath[MAX_PATH]; - char bayesdb_tmp[MAX_PATH]; - - char* tmp = Utils_ReplaceVars("%miranda_userdata%"); - if (tmp[mir_strlen(tmp)-1] == '\\') - tmp[mir_strlen(tmp)-1] = 0; - mir_snprintf(bayesdb_tmp, "%s\\%s", tmp, BAYESDB_PATH); - mir_free(tmp); - - if (ServiceExists(MS_FOLDERS_REGISTER_PATH)) { - hBayesFolder = FoldersRegisterCustomPath(MODULENAME, Translate("Bayes database path"), bayesdb_tmp); - } else hBayesFolder = nullptr; - - if (hBayesFolder) - FoldersGetCustomPath(hBayesFolder, bayesdb_fullpath, MAX_PATH, bayesdb_tmp); - else - strncpy_s(bayesdb_fullpath, bayesdb_tmp, _TRUNCATE); - - mir_strcat(bayesdb_fullpath, "\\" BAYESDB_FILENAME); - if (_access(bayesdb_fullpath,0) == 0) - return 1; - - return 0; -} - -int OpenBayes() -{ - char bayesdb_fullpath[MAX_PATH]; - char *bayesdb_fullpath_utf8; - char *errmsg, *tmp; - sqlite3_stmt *stmt; - - if (hBayesFolder) { - FoldersGetCustomPath(hBayesFolder, bayesdb_fullpath, MAX_PATH, ""); - } - else { - tmp = Utils_ReplaceVars("%miranda_userdata%"); - if (tmp[mir_strlen(tmp)-1] == '\\') - tmp[mir_strlen(tmp)-1] = 0; - mir_strcpy(bayesdb_fullpath, tmp); - mir_strcat(bayesdb_fullpath, "\\" BAYESDB_PATH); - mir_free(tmp); - } - - CreateDirectoryTree(bayesdb_fullpath); - - mir_strcat(bayesdb_fullpath, "\\" BAYESDB_FILENAME); - bayesdb_fullpath_utf8 = mir_utf8encode(bayesdb_fullpath); - - if (sqlite3_open(bayesdb_fullpath_utf8, &bayesdb) == SQLITE_OK) - { - sqlite3_exec(bayesdb, "CREATE TABLE IF NOT EXISTS spam (token blob(16), num int)", nullptr, nullptr, &errmsg); - sqlite3_exec(bayesdb, "CREATE TABLE IF NOT EXISTS ham (token blob(16), num int)", nullptr, nullptr, &errmsg); - sqlite3_exec(bayesdb, "CREATE TABLE IF NOT EXISTS stats (key varchar(32), value int)", nullptr, nullptr, &errmsg); - sqlite3_exec(bayesdb, "CREATE TABLE IF NOT EXISTS queue (contact int, msgtime int, message text)", nullptr, nullptr, &errmsg); - sqlite3_prepare_v2(bayesdb, "SELECT count(1) FROM stats WHERE key='spam_msgcount' OR key='ham_msgcount'", -1, &stmt, nullptr); - if (sqlite3_step(stmt) == SQLITE_ROW) - if (sqlite3_column_int(stmt, 0) != 2) { - sqlite3_exec(bayesdb, "INSERT INTO stats VALUES ('spam_msgcount', 0)", nullptr, nullptr, nullptr); - sqlite3_exec(bayesdb, "INSERT INTO stats VALUES ('ham_msgcount', 0)", nullptr, nullptr, nullptr); - } - } else { - MessageBoxA(nullptr, bayesdb_fullpath_utf8, "Can't open database", MB_OK); - } - - mir_free(bayesdb_fullpath_utf8); - -#ifdef _DEBUG - tmp = Utils_ReplaceVars("%miranda_userdata%"); - if (tmp[mir_strlen(tmp)-1] == '\\') - tmp[mir_strlen(tmp)-1] = 0; - mir_snprintf(bayesdb_fullpath, "%s\\%s\\%s", tmp, BAYESDB_PATH, BAYESDBG_FILENAME); - mir_free(tmp); - bayesdb_fullpath_utf8 = mir_utf8encode(bayesdb_fullpath); - if (sqlite3_open(bayesdb_fullpath_utf8, &bayesdbg) == SQLITE_OK) - { - sqlite3_exec(bayesdbg, "CREATE TABLE spam (token varchar(50), num int)", nullptr, nullptr, &errmsg); - sqlite3_exec(bayesdbg, "CREATE TABLE ham (token varchar(50), num int)", nullptr, nullptr, &errmsg); - } - mir_free(bayesdb_fullpath_utf8); -#endif - - return 0; -} - -char *tokenhash(const char *token, uint8_t *digest) -{ - mir_md5_hash((uint8_t *)token, (int)mir_strlen(token), digest); - return (char*)digest; -} - -int get_token_count(int type) -{ - char q[200]; - int count = 0; - sqlite3_stmt *stmt; - - if (bayesdb == nullptr) - return 0; - mir_snprintf(q, "SELECT COUNT(1) FROM %s", type == SPAM ? "spam" : "ham"); - sqlite3_prepare_v2(bayesdb, q, -1, &stmt, nullptr); - if (sqlite3_step(stmt) == SQLITE_ROW) { - count = sqlite3_column_int(stmt, 0); - } - sqlite3_finalize(stmt); - return count; -} - -int get_msg_count(int type) -{ - int count = 0; - sqlite3_stmt *stmt; - - if (bayesdb == nullptr) - return 0; - sqlite3_prepare_v2(bayesdb, "SELECT value FROM stats WHERE key=?", -1, &stmt, nullptr); - sqlite3_bind_text(stmt, 1, type == SPAM ? "spam_msgcount" : "ham_msgcount", type == SPAM ? 13 : 12, nullptr); - if (sqlite3_step(stmt) == SQLITE_ROW) { - count = sqlite3_column_int(stmt, 0); - } - sqlite3_finalize(stmt); - return count; -} - -BOOL is_token_valid(char *token) -{ - unsigned int i; - // skip digits only tokens - for (i = 0; i < mir_strlen(token); i++) { - if ((unsigned char)token[i] >= 48 && (unsigned char)token[i] <= 57) - return FALSE; - } - - // skip 1- and 2-character tokens - if (mir_strlen(token) < 3) - return FALSE; - - // skip "www", "com", "org", etc. - if (!mir_strcmp(token, "www") || !mir_strcmp(token, "com") || !mir_strcmp(token, "org") || !mir_strcmp(token, "edu") || - !mir_strcmp(token, "net") || !mir_strcmp(token, "biz") || !mir_strcmp(token, "http") || !mir_strcmp(token, "ftp")) - return FALSE; - - return TRUE; -} - -int get_token_score(int type, char *token) -{ - char sql[200]; - int score = 0; - uint8_t digest[16]; - sqlite3_stmt *stmt; - - if (bayesdb == nullptr) - return 0; - mir_snprintf(sql, "SELECT num FROM %s WHERE token=?", type == SPAM ? "spam" : "ham"); - tokenhash(token, digest); - sqlite3_prepare_v2(bayesdb, sql, -1, &stmt, nullptr); - sqlite3_bind_blob(stmt, 1, digest, 16, nullptr); - - if (sqlite3_step(stmt) == SQLITE_ROW) { - score = sqlite3_column_int(stmt, 0); - } - sqlite3_finalize(stmt); - return score; -} - -double get_msg_score(wchar_t *msg) -{ - char *message, *token; - double spam_prob, ham_prob, tmp1 = 1, tmp2 = 1; - double *scores = nullptr; - int spam_msgcount, ham_msgcount, n = 0, i; - - if (bayesdb == nullptr) - return 0; - - message = mir_u2a(msg); - spam_msgcount = get_msg_count(SPAM); - ham_msgcount = get_msg_count(HAM); - token = strtok(message, DELIMS); - while (token) - { - if (!is_token_valid(token)) { - token = strtok(nullptr, DELIMS); - continue; - } - scores = (double*)realloc(scores, sizeof(double)*(n + 1)); - spam_prob = spam_msgcount == 0 ? 0 : (double)get_token_score(SPAM, token) / (double)spam_msgcount; - ham_prob = ham_msgcount == 0 ? 0 : (double)get_token_score(HAM, token) / (double)ham_msgcount; - if (ham_prob == 0 && spam_prob == 0) { - spam_prob = 0.4; ham_prob = 0.6; - } - spam_prob = spam_prob > 1.0 ? 1.0 : (spam_prob < 0.01 ? 0.01 : spam_prob); - ham_prob = ham_prob > 1.0 ? 1.0 : (ham_prob < 0.01 ? 0.01 : ham_prob); - scores[n++] = spam_prob / (spam_prob + ham_prob); - - token = strtok(nullptr, DELIMS); - } - - for (i = 0; i < n; i++) { - tmp1 *= scores[i]; - tmp2 *= 1-scores[i]; - } - - mir_free(message); - free(scores); - return tmp1 / (tmp1 + tmp2); -} - -void queue_message(MCONTACT hContact, uint32_t msgtime, wchar_t *message) -{ - char *tmp; - sqlite3_stmt *stmt; - - if (!g_plugin.getByte("BayesAutolearnApproved", defaultBayesAutolearnApproved) && - !g_plugin.getByte("BayesAutolearnNotApproved", defaultBayesAutolearnNotApproved)) - return; - - if (g_plugin.getByte("BayesEnabled", defaultBayesEnabled) == 0) - return; - if (bayesdb == nullptr) - OpenBayes(); - - sqlite3_prepare_v2(bayesdb, "INSERT INTO queue VALUES(?,?,?)", -1, &stmt, nullptr); - sqlite3_bind_int(stmt, 1, (uint32_t)hContact); - sqlite3_bind_int(stmt, 2, msgtime); - tmp = mir_u2a(message); - sqlite3_bind_text(stmt, 3, tmp, (int)mir_strlen(tmp), nullptr); - sqlite3_step(stmt); - mir_free(tmp); - sqlite3_finalize(stmt); -} - -void bayes_approve_contact(MCONTACT hContact) -{ - const char *message; - wchar_t *messageW; - int d = 0; - sqlite3_stmt *stmt; - - if (bayesdb == nullptr) - return; - - sqlite3_prepare_v2(bayesdb, "SELECT message FROM queue WHERE contact=?", -1, &stmt, nullptr); - sqlite3_bind_int(stmt, 1, (uint32_t)hContact); - while (sqlite3_step(stmt) == SQLITE_ROW) - { - d = 1; - message = (char*)sqlite3_column_text(stmt, 0); - messageW = mir_a2u(message); - learn_ham(messageW); - mir_free(messageW); - } - sqlite3_finalize(stmt); - if (d) { - sqlite3_prepare_v2(bayesdb, "DELETE FROM queue WHERE contact=?", -1, &stmt, nullptr); - sqlite3_bind_int(stmt, 1, (uint32_t)hContact); - sqlite3_step(stmt); - sqlite3_finalize(stmt); - } - -} - -void dequeue_messages() -{ - time_t t = time(0); - sqlite3_stmt *stmt; - const char *message; - wchar_t *messageW; - int d = 0; - - if (bayesdb == nullptr) - return; - - sqlite3_prepare_v2(bayesdb, "SELECT message FROM queue WHERE msgtime + ? < ?", -1, &stmt, nullptr); - sqlite3_bind_int(stmt, 1, g_plugin.getDword("BayesWaitApprove", defaultBayesWaitApprove)*86400); - sqlite3_bind_int(stmt, 2, (uint32_t)t); - while (sqlite3_step(stmt) == SQLITE_ROW) { - d = 1; - message = (char*)sqlite3_column_text(stmt, 0); - messageW = mir_a2u(message); - learn_spam(messageW); - mir_free(messageW); - } - sqlite3_finalize(stmt); - if (d) { - sqlite3_prepare_v2(bayesdb, "DELETE FROM queue WHERE msgtime + ? < ?", -1, &stmt, nullptr); - sqlite3_bind_int(stmt, 1, g_plugin.getDword("BayesWaitApprove", defaultBayesWaitApprove)*86400); - sqlite3_bind_int(stmt, 2, (uint32_t)t); - sqlite3_step(stmt); - sqlite3_finalize(stmt); - } -} - -/* Learn one message as either SPAM or HAM as specified in type parameter */ -void learn(int type, wchar_t *msg) -{ - char *tok, *message; - uint8_t digest[16]; - char sql_select[200], sql_update[200], sql_insert[200], sql_counter[200]; - sqlite3_stmt *stmt; -#ifdef _DEBUG - sqlite3_stmt *stmtdbg; -#endif - - if (g_plugin.getByte("BayesEnabled", defaultBayesEnabled) == 0) - return; - if (bayesdb == nullptr) - OpenBayes(); - - message = mir_u2a(msg); - tok = strtok(message, DELIMS); - mir_snprintf(sql_counter, "UPDATE stats SET value=value+1 WHERE key='%s'", type == SPAM ? "spam_msgcount" : "ham_msgcount"); - mir_snprintf(sql_select, "SELECT 1 FROM %s WHERE token=?", type == SPAM ? "spam" : "ham"); - mir_snprintf(sql_update, "UPDATE %s SET num=num+1 WHERE token=?", type ? "spam" : "ham"); - mir_snprintf(sql_insert, "INSERT INTO %s VALUES(?, 1)", type ? "spam" : "ham"); -#ifdef _DEBUG - sqlite3_exec(bayesdbg, "BEGIN", nullptr, nullptr, nullptr); -#endif - sqlite3_exec(bayesdb, "BEGIN", nullptr, nullptr, nullptr); - while (tok) { - if (!is_token_valid(tok)) { - tok = strtok(nullptr, DELIMS); - continue; - } - tokenhash(tok, digest); - sqlite3_prepare_v2(bayesdb, sql_select, -1, &stmt, nullptr); - sqlite3_bind_blob(stmt, 1, digest, 16, SQLITE_STATIC); - if (SQLITE_ROW == sqlite3_step(stmt)) { - sqlite3_finalize(stmt); - sqlite3_prepare_v2(bayesdb, sql_update, -1, &stmt, nullptr); - } else { - sqlite3_finalize(stmt); - sqlite3_prepare_v2(bayesdb, sql_insert, -1, &stmt, nullptr); - } - sqlite3_bind_blob(stmt, 1, digest, 16, SQLITE_STATIC); - sqlite3_step(stmt); - sqlite3_finalize(stmt); - -#ifdef _DEBUG - sqlite3_prepare_v2(bayesdbg, sql_select, -1, &stmtdbg, nullptr); - sqlite3_bind_text(stmtdbg, 1, tok, (int)mir_strlen(tok), nullptr); - if (SQLITE_ROW == sqlite3_step(stmtdbg)) { - sqlite3_finalize(stmtdbg); - sqlite3_prepare_v2(bayesdbg, sql_update, -1, &stmtdbg, nullptr); - } else { - sqlite3_finalize(stmtdbg); - sqlite3_prepare_v2(bayesdbg, sql_insert, -1, &stmtdbg, nullptr); - } - sqlite3_bind_text(stmtdbg, 1, tok, (int)mir_strlen(tok), SQLITE_STATIC); - sqlite3_step(stmtdbg); - sqlite3_finalize(stmtdbg); -#endif - - tok = strtok(nullptr, DELIMS); - } - sqlite3_exec(bayesdb, sql_counter, nullptr, nullptr, nullptr); - sqlite3_exec(bayesdb, "COMMIT", nullptr, nullptr, nullptr); -#ifdef _DEBUG - sqlite3_exec(bayesdbg, "COMMIT", nullptr, nullptr, nullptr); -#endif - mir_free(message); -} - -void learn_ham(wchar_t *msg) -{ - learn(0, msg); -} - -void learn_spam(wchar_t *msg) -{ - learn(1, msg); -} \ No newline at end of file diff --git a/plugins/Spamotron/src/options.cpp b/plugins/Spamotron/src/options.cpp deleted file mode 100644 index 9cea04b1e6..0000000000 --- a/plugins/Spamotron/src/options.cpp +++ /dev/null @@ -1,580 +0,0 @@ -#include "stdafx.h" - -wchar_t currentResponse[256] = {0}; - -wchar_t* _getCOptS(wchar_t *buf, unsigned int buflen, MCONTACT hContact, const char* option, const wchar_t *def) -{ - DBVARIANT dbv = {0}; - wcsnset(buf, 0, buflen); - if (g_plugin.getWString(hContact, option, &dbv) != 0) - wcsncpy(buf, def, min(buflen, mir_wstrlen(def)+1)); - else if (dbv.type == DBVT_WCHAR) { - wcsncpy(buf, dbv.pwszVal, min(buflen, mir_wstrlen(dbv.pwszVal)+1)); - } - db_free(&dbv); - return buf; -} -wchar_t* _getMOptS(wchar_t *buf, unsigned int buflen, const char* module, const char* option, const wchar_t *def) -{ - wchar_t* tmp; - DBVARIANT dbv = {0}; - wcsnset(buf, 0, buflen); - if (db_get_s(0, module, option, &dbv) != 0) - wcsncpy(buf, def, min(buflen, mir_wstrlen(def)+1)); - else if (dbv.type == DBVT_WCHAR) { - wcsncpy(buf, dbv.pwszVal, min(buflen, mir_wstrlen(dbv.pwszVal)+1)); - } else { - tmp = mir_a2u(dbv.pszVal); - wcsncpy(buf, tmp, min(buflen, mir_wstrlen(tmp)+1)); - mir_free(tmp); - } - db_free(&dbv); - return buf; -} - - -BOOL _saveDlgItemText(HWND hDialog, int controlID, char* option) -{ - int len; - wchar_t *tmp; - len = GetWindowTextLength(GetDlgItem(hDialog, controlID)); - tmp = (wchar_t *)malloc((len + 1)*sizeof(wchar_t)); - GetDlgItemText(hDialog, controlID, tmp, len + 1); - g_plugin.setWString(option, tmp); - free(tmp); - return TRUE; -} -int _saveDlgItemResponse(HWND hDialog, int controlID, char* option) -{ - int ret = 0; - int isRegex = 0; - int len; - wchar_t *tmp; - len = GetWindowTextLength(GetDlgItem(hDialog, controlID)); - tmp = (wchar_t*)malloc((len+1)*sizeof(wchar_t)); - GetDlgItemText(hDialog, controlID, tmp, len+1); - isRegex = _isregex(tmp); - if (!isRegex) - ret = _saveDlgItemText(hDialog, controlID, option) ? 1 : 0; - else { - if (_isvalidregex(tmp)) - ret = _saveDlgItemText(hDialog, controlID, option) ? 1 : 0; - else - ret = -1; - } - free(tmp); - return ret; -} -BOOL _saveDlgItemInt(HWND hDialog, int controlID, char* option) -{ - int len; - wchar_t *tmp; - len = GetWindowTextLength(GetDlgItem(hDialog, controlID)); - tmp = (wchar_t *)malloc((len + 1)*sizeof(wchar_t)); - GetDlgItemText(hDialog, controlID, tmp, len + 1); - g_plugin.setDword(option, _wtoi(tmp)); - free(tmp); - return TRUE; -} -BOOL _saveDlgItemScore(HWND hDialog, int controlID, char* option) -{ - int len; - wchar_t *tmp; - len = GetWindowTextLength(GetDlgItem(hDialog, controlID)); - tmp = (wchar_t *)malloc((len + 1)*sizeof(wchar_t)); - GetDlgItemText(hDialog, controlID, tmp, len + 1); - g_plugin.setDword(option, wcstod(tmp, nullptr)/SCORE_C); - return TRUE; -} - -INT_PTR CALLBACK DlgProcOptionsMain(HWND optDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - static int bInitializing = 0, i, j; - wchar_t pName[256] = {0}; - char protoOption[256] = {0}; - HWND hProtocolsList = GetDlgItem(optDlg, IDC_OPT_PROTOCOLS); - LVITEM lvi = {0}; - LVCOLUMN lvc = {0}; - wchar_t buf[512]; - - switch (msg) { - case WM_INITDIALOG: - TranslateDialogDefault(optDlg); - bInitializing = 1; - - ///Main enable switch - CheckDlgButton(optDlg, IDC_OPT_OUT_MSG_APPROVE, g_plugin.getByte("ApproveOnMsgOut", defaultApproveOnMsgOut) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(optDlg, IDC_OPT_IN_MSG_APPROVE, g_plugin.getByte("ApproveOnMsgIn", defaultApproveOnMsgIn) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(optDlg, IDC_OPT_DONT_REPLY_SAME_MSG, g_plugin.getByte("DontReplySameMsg", defaultDontReplySameMsg) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(optDlg, IDC_OPT_DONT_REPLY_MSG, g_plugin.getByte("DontReplyMsg", defaultDontReplyMsg) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(optDlg, IDC_OPT_HIDE_UNTIL_VERIFIED, g_plugin.getByte("HideUnverified", defaultHideUnverified) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(optDlg, IDC_OPT_ADD_PERMANENTLY, g_plugin.getByte("AddPermanently", defaultAddPermanently) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(optDlg, IDC_OPT_LOG_ACTIONS, g_plugin.getByte("LogActions", defaultLogActions) ? BST_CHECKED : BST_UNCHECKED); - - SetDlgItemText(optDlg, IDC_OPT_IN_MSG_APPROVE_WORDLIST, _getOptS(buf, _countof(buf), "ApproveOnMsgInWordlist", defaultApproveOnMsgInWordlist)); - SetDlgItemText(optDlg, IDC_OPT_MAX_MSG_CONTACT, _itow(g_plugin.getDword("MaxMsgContactCountPerDay", defaultMaxMsgContactCountPerDay), buf, 10)); - SetDlgItemText(optDlg, IDC_OPT_MAX_SAME_MSG, _itow(g_plugin.getDword("MaxSameMsgCountPerDay", defaultMaxSameMsgCountPerDay), buf, 10)); - SetDlgItemText(optDlg, IDC_OPT_DONT_REPLY_MSG_WORDLIST, _getOptS(buf, _countof(buf), "DontReplyMsgWordlist", defaultDontReplyMsgWordlist)); - - ///Individual protocols list - ListView_SetExtendedListViewStyle(hProtocolsList, LVS_EX_CHECKBOXES | LVS_EX_FULLROWSELECT); - lvc.mask = LVCF_WIDTH; - lvc.cx = 120; - ListView_InsertColumn(hProtocolsList, 0, &lvc); - lvi.mask = LVIF_TEXT | LVIF_STATE; - - for (auto &pa : Accounts()) { - lvi.iItem = i; - _getMOptS(pName, 200*sizeof(wchar_t), pa->szModuleName, "AM_BaseProto", L""); - if (mir_wstrcmp(pName, L"ICQ") != 0) - continue; - lvi.pszText = mir_a2u(pa->szModuleName); - ListView_InsertItem(hProtocolsList, &lvi); - memset(protoOption, 0, sizeof(protoOption)); - mir_strcat(protoOption, "proto_"); - mir_strcat(protoOption, pa->szModuleName); - ListView_SetCheckState(hProtocolsList, j++, g_plugin.getByte(protoOption, 0)); - } - - bInitializing = 0; - return TRUE; - - case WM_COMMAND: - if (bInitializing) - return FALSE; - switch (LOWORD(wParam)) { - case IDC_OPT_OUT_MSG_APPROVE: - case IDC_OPT_IN_MSG_APPROVE: - case IDC_OPT_DONT_REPLY_SAME_MSG: - case IDC_OPT_DONT_REPLY_MSG: - case IDC_OPT_ADD_PERMANENTLY: - case IDC_OPT_HIDE_UNTIL_VERIFIED: - case IDC_OPT_LOG_ACTIONS: - if (HIWORD(wParam) != BN_CLICKED) - return FALSE; - break; - case IDC_OPT_IN_MSG_APPROVE_WORDLIST: - case IDC_OPT_MAX_MSG_CONTACT: - case IDC_OPT_MAX_SAME_MSG: - case IDC_OPT_DONT_REPLY_MSG_WORDLIST: - if (HIWORD(wParam) != EN_CHANGE) - return FALSE; - break; - } - SendMessage(GetParent(optDlg), PSM_CHANGED, 0, 0); - break; - - case WM_NOTIFY: - if (bInitializing) - return FALSE; - - switch (LOWORD(wParam)) { - case IDC_OPT_PROTOCOLS: - if ( - ((LPNMHDR)lParam)->code == LVN_ITEMCHANGED && - ((LPNMLISTVIEW)lParam)->uChanged & LVIF_STATE && - (((LPNMLISTVIEW)lParam)->uOldState & LVIS_STATEIMAGEMASK) != \ - (((LPNMLISTVIEW)lParam)->uNewState & LVIS_STATEIMAGEMASK) - ) - SendMessage(GetParent(optDlg), PSM_CHANGED, 0, 0); - break; - } - switch (((NMHDR*)lParam)->code) { - case PSN_APPLY: - g_plugin.setByte("ApproveOnMsgOut", IsDlgButtonChecked(optDlg, IDC_OPT_OUT_MSG_APPROVE)); - g_plugin.setByte("ApproveOnMsgIn", IsDlgButtonChecked(optDlg, IDC_OPT_IN_MSG_APPROVE)); - g_plugin.setByte("DontReplySameMsg", IsDlgButtonChecked(optDlg, IDC_OPT_DONT_REPLY_SAME_MSG)); - g_plugin.setByte("DontReplyMsg", IsDlgButtonChecked(optDlg, IDC_OPT_DONT_REPLY_MSG)); - g_plugin.setByte("AddPermanently", IsDlgButtonChecked(optDlg, IDC_OPT_ADD_PERMANENTLY)); - g_plugin.setByte("HideUnverified", IsDlgButtonChecked(optDlg, IDC_OPT_HIDE_UNTIL_VERIFIED)); - g_plugin.setByte("LogActions", IsDlgButtonChecked(optDlg, IDC_OPT_LOG_ACTIONS)); - _saveDlgItemText(optDlg, IDC_OPT_IN_MSG_APPROVE_WORDLIST, "ApproveOnMsgInWordlist"); - _saveDlgItemText(optDlg, IDC_OPT_DONT_REPLY_MSG_WORDLIST, "DontReplyMsgWordlist"); - _saveDlgItemInt(optDlg, IDC_OPT_MAX_MSG_CONTACT, "MaxMsgContactCountPerDay"); - _saveDlgItemInt(optDlg, IDC_OPT_MAX_SAME_MSG, "MaxSameMsgCountPerDay"); - - int numProtocols = ListView_GetItemCount(hProtocolsList); - for (i = 0; i < numProtocols; i++) { - ListView_GetItemText(hProtocolsList, i, 0, buf, _countof(buf)); - //wcstombs(protoName, buf, _countof(buf)); - memset(protoOption, 0, sizeof(protoOption)); - mir_strcat(protoOption, "proto_"); - mir_strcat(protoOption, mir_u2a(buf)); - g_plugin.setByte(protoOption, ListView_GetCheckState(hProtocolsList, i)); - } - return TRUE; - } - break; - } - return FALSE; -} - -INT_PTR CALLBACK DlgProcOptionsQuestion(HWND optDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - static int bInitializing = 0; - int i, selectedMode; - HWND ht; - wchar_t *buf; - unsigned int buflen = 500; - - switch (msg) { - case WM_INITDIALOG: - TranslateDialogDefault(optDlg); - bInitializing = 1; - - ht = GetDlgItem(optDlg, IDC_OPT_MODE); - SendMessage(ht, CB_ADDSTRING, 0, (LPARAM)TranslateT("Simple")); - SendMessage(ht, CB_SETITEMDATA, 0, SPAMOTRON_MODE_PLAIN); - SendMessage(ht, CB_ADDSTRING, 0, (LPARAM)TranslateT("Math expression")); - SendMessage(ht, CB_SETITEMDATA, 1, SPAMOTRON_MODE_MATH); - SendMessage(ht, CB_ADDSTRING, 0, (LPARAM)TranslateT("Round-robin")); - SendMessage(ht, CB_SETITEMDATA, 2, SPAMOTRON_MODE_ROTATE); - SendMessage(ht, CB_ADDSTRING, 0, (LPARAM)TranslateT("Random")); - SendMessage(ht, CB_SETITEMDATA, 3, SPAMOTRON_MODE_RANDOM); - - selectedMode = g_plugin.getByte("Mode", defaultMode); - for (i = 0; i < SendMessage(ht, CB_GETCOUNT, 0, 0); i++) { - if (SendMessage(ht, CB_GETITEMDATA, i, 0) == selectedMode) { - SendMessage(ht, CB_SETCURSEL, i, 0); - break; - } - } - SetDlgItemText(optDlg, IDC_OPT_MATH_RESPONSE, TranslateT("Will be automatically evaluated from %mathexpr%")); - buf = (wchar_t *)malloc(buflen*sizeof(wchar_t)); - switch (selectedMode) { - case SPAMOTRON_MODE_PLAIN: - case SPAMOTRON_MODE_ROTATE: - case SPAMOTRON_MODE_RANDOM: - ShowWindow(GetDlgItem(optDlg, IDC_STATIC_MODEMSG), 0); - ShowWindow(GetDlgItem(optDlg, IDC_OPT_MATH_RESPONSE), 0); - ShowWindow(GetDlgItem(optDlg, IDC_OPT_RESPONSE), 1); - ShowWindow(GetDlgItem(optDlg, IDC_OPT_CCRESPONSE), 1); - EnableWindow(GetDlgItem(optDlg, IDC_OPT_RESPONSE), TRUE); - SetDlgItemText(optDlg, IDC_OPT_CHALLENGE, _getOptS(buf, buflen, "Challenge", defaultChallenge)); - SetDlgItemText(optDlg, IDC_OPT_AUTH_CHALLENGE, _getOptS(buf, buflen, "AuthChallenge", defaultAuthChallenge)); - break; - case SPAMOTRON_MODE_MATH: - ShowWindow(GetDlgItem(optDlg, IDC_STATIC_MODEMSG), 1); - ShowWindow(GetDlgItem(optDlg, IDC_OPT_MATH_RESPONSE), 1); - ShowWindow(GetDlgItem(optDlg, IDC_OPT_RESPONSE), 0); - ShowWindow(GetDlgItem(optDlg, IDC_OPT_CCRESPONSE), 0); - EnableWindow(GetDlgItem(optDlg, IDC_OPT_RESPONSE), FALSE); - SetDlgItemText(optDlg, IDC_OPT_CHALLENGE, _getOptS(buf, buflen, "ChallengeMath", defaultChallengeMath)); - SetDlgItemText(optDlg, IDC_OPT_AUTH_CHALLENGE, _getOptS(buf, buflen, "AuthChallengeMath", defaultAuthChallengeMath)); - break; - } - CheckDlgButton(optDlg, IDC_OPT_REPLY_ON_SUCCESS, g_plugin.getByte("ReplyOnSuccess", defaultReplyOnSuccess) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(optDlg, IDC_OPT_REPLY_ON_AUTH, g_plugin.getByte("ReplyOnAuth", defaultReplyOnAuth) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(optDlg, IDC_OPT_REPLY_ON_MSG, g_plugin.getByte("ReplyOnMsg", defaultReplyOnMsg) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(optDlg, IDC_OPT_KEEP_BLOCKED_MSG, g_plugin.getByte("KeepBlockedMsg", defaultKeepBlockedMsg) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(optDlg, IDC_OPT_MARK_MSG_UNREAD_ON_APPROVAL, g_plugin.getByte("MarkMsgUnreadOnApproval", defaultMarkMsgUnreadOnApproval) ? BST_CHECKED : BST_UNCHECKED); - EnableWindow(GetDlgItem(optDlg, IDC_OPT_MARK_MSG_UNREAD_ON_APPROVAL), g_plugin.getByte("KeepBlockedMsg", defaultKeepBlockedMsg)); - CheckDlgButton(optDlg, IDC_OPT_CCRESPONSE, g_plugin.getByte("ResponseCC", defaultResponseCC) ? BST_CHECKED : BST_UNCHECKED); - SetDlgItemText(optDlg, IDC_OPT_RESPONSE, _getOptS(buf, buflen, "Response", defaultResponse)); - SetDlgItemText(optDlg, IDC_OPT_SUCCESS_RESPONSE, _getOptS(buf, buflen, "SuccessResponse", defaultSuccessResponse)); - free(buf); - - bInitializing = 0; - return TRUE; - - case WM_COMMAND: - if (bInitializing) - return FALSE; - switch (LOWORD(wParam)) { - case IDC_OPT_MODE: - if (HIWORD(wParam) != CBN_SELCHANGE) - return FALSE; - i = SendDlgItemMessage(optDlg, IDC_OPT_MODE, CB_GETCURSEL, 0, 0); - selectedMode = SendDlgItemMessage(optDlg, IDC_OPT_MODE, CB_GETITEMDATA, i, 0); - buf = (wchar_t*)malloc(buflen*sizeof(wchar_t)); - switch (selectedMode) { - case SPAMOTRON_MODE_PLAIN: - case SPAMOTRON_MODE_ROTATE: - case SPAMOTRON_MODE_RANDOM: - ShowWindow(GetDlgItem(optDlg, IDC_STATIC_MODEMSG), 0); - ShowWindow(GetDlgItem(optDlg, IDC_OPT_MATH_RESPONSE), 0); - ShowWindow(GetDlgItem(optDlg, IDC_OPT_RESPONSE), 1); - ShowWindow(GetDlgItem(optDlg, IDC_OPT_CCRESPONSE), 1); - EnableWindow(GetDlgItem(optDlg, IDC_OPT_RESPONSE), TRUE); - SetDlgItemText(optDlg, IDC_OPT_CHALLENGE, _getOptS(buf, buflen, "Challenge", defaultChallenge)); - SetDlgItemText(optDlg, IDC_OPT_AUTH_CHALLENGE, _getOptS(buf, buflen, "AuthChallenge", defaultAuthChallenge)); - break; - case SPAMOTRON_MODE_MATH: - ShowWindow(GetDlgItem(optDlg, IDC_STATIC_MODEMSG), 1); - ShowWindow(GetDlgItem(optDlg, IDC_OPT_MATH_RESPONSE), 1); - ShowWindow(GetDlgItem(optDlg, IDC_OPT_RESPONSE), 0); - ShowWindow(GetDlgItem(optDlg, IDC_OPT_CCRESPONSE), 0); - EnableWindow(GetDlgItem(optDlg, IDC_OPT_RESPONSE), FALSE); - SetDlgItemText(optDlg, IDC_OPT_CHALLENGE, _getOptS(buf, buflen, "ChallengeMath", defaultChallengeMath)); - SetDlgItemText(optDlg, IDC_OPT_AUTH_CHALLENGE, _getOptS(buf, buflen, "AuthChallengeMath", defaultAuthChallengeMath)); - break; - } - free(buf); - break; - case IDC_OPT_REPLY_ON_SUCCESS: - case IDC_OPT_REPLY_ON_AUTH: - case IDC_OPT_REPLY_ON_MSG: - case IDC_OPT_KEEP_BLOCKED_MSG: - case IDC_OPT_MARK_MSG_UNREAD_ON_APPROVAL: - case IDC_OPT_CCRESPONSE: - EnableWindow(GetDlgItem(optDlg, IDC_OPT_MARK_MSG_UNREAD_ON_APPROVAL), IsDlgButtonChecked(optDlg, IDC_OPT_KEEP_BLOCKED_MSG)); - if (HIWORD(wParam) != BN_CLICKED) - return FALSE; - break; - case IDC_OPT_CHALLENGE: - case IDC_OPT_RESPONSE: - case IDC_OPT_SUCCESS_RESPONSE: - case IDC_OPT_AUTH_CHALLENGE: - if (HIWORD(wParam) != EN_CHANGE) - return FALSE; - break; - case IDC_DEFAULTS: - SetDlgItemText(optDlg, IDC_STATIC_MODEMSG, L""); - ShowWindow(GetDlgItem(optDlg, IDC_OPT_MATH_RESPONSE), 0); - ShowWindow(GetDlgItem(optDlg, IDC_OPT_RESPONSE), 1); - EnableWindow(GetDlgItem(optDlg, IDC_OPT_RESPONSE), TRUE); - SendDlgItemMessage(optDlg, IDC_OPT_MODE, CB_SETCURSEL, 0, 0); - CheckDlgButton(optDlg, IDC_OPT_CCRESPONSE, defaultResponseCC ? BST_CHECKED : BST_UNCHECKED); - SetDlgItemText(optDlg, IDC_OPT_CHALLENGE, defaultChallenge); - SetDlgItemText(optDlg, IDC_OPT_RESPONSE, defaultResponse); - SetDlgItemText(optDlg, IDC_OPT_SUCCESS_RESPONSE, defaultSuccessResponse); - SetDlgItemText(optDlg, IDC_OPT_AUTH_CHALLENGE, defaultAuthChallenge); - CheckDlgButton(optDlg, IDC_OPT_REPLY_ON_SUCCESS, defaultReplyOnSuccess ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(optDlg, IDC_OPT_REPLY_ON_AUTH, defaultReplyOnAuth ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(optDlg, IDC_OPT_REPLY_ON_MSG, defaultReplyOnMsg ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(optDlg, IDC_OPT_KEEP_BLOCKED_MSG, defaultKeepBlockedMsg ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(optDlg, IDC_OPT_MARK_MSG_UNREAD_ON_APPROVAL, defaultMarkMsgUnreadOnApproval ? BST_CHECKED : BST_UNCHECKED); - break; - } - SendMessage(GetParent(optDlg), PSM_CHANGED, 0, 0); - break; - case WM_NOTIFY: - switch (((NMHDR*)lParam)->code) { - case PSN_APPLY: - i = SendDlgItemMessage(optDlg, IDC_OPT_MODE, CB_GETCURSEL, 0, 0); - selectedMode = SendDlgItemMessage(optDlg, IDC_OPT_MODE, CB_GETITEMDATA, i, 0); - g_plugin.setByte("Mode", selectedMode); - g_plugin.setByte("ReplyOnSuccess", IsDlgButtonChecked(optDlg, IDC_OPT_REPLY_ON_SUCCESS)); - g_plugin.setByte("ReplyOnAuth", IsDlgButtonChecked(optDlg, IDC_OPT_REPLY_ON_AUTH)); - g_plugin.setByte("ReplyOnMsg", IsDlgButtonChecked(optDlg, IDC_OPT_REPLY_ON_MSG)); - g_plugin.setByte("KeepBlockedMsg", IsDlgButtonChecked(optDlg, IDC_OPT_KEEP_BLOCKED_MSG)); - g_plugin.setByte("MarkMsgUnreadOnApproval", IsDlgButtonChecked(optDlg, IDC_OPT_MARK_MSG_UNREAD_ON_APPROVAL)); - g_plugin.setByte("ResponseCC", IsDlgButtonChecked(optDlg, IDC_OPT_CCRESPONSE)); - switch (selectedMode) { - case SPAMOTRON_MODE_PLAIN: - _saveDlgItemText(optDlg, IDC_OPT_CHALLENGE, "Challenge"); - _saveDlgItemText(optDlg, IDC_OPT_AUTH_CHALLENGE, "AuthChallenge"); - break; - case SPAMOTRON_MODE_MATH: - _saveDlgItemText(optDlg, IDC_OPT_CHALLENGE, "ChallengeMath"); - _saveDlgItemText(optDlg, IDC_OPT_AUTH_CHALLENGE, "AuthChallengeMath"); - break; - } - if (_saveDlgItemResponse(optDlg, IDC_OPT_RESPONSE, "Response") == -1) { - MessageBox(nullptr, TranslateT("Invalid regular expression.\nKeeping previous value."), L"Error", MB_OK); - return FALSE; - } - _saveDlgItemText(optDlg, IDC_OPT_SUCCESS_RESPONSE, "SuccessResponse"); - - return TRUE; - } - break; - case WM_DESTROY: - break; - } - return FALSE; -} - - -void EnableControlsBayes(HWND hwnd, BOOL enable) -{ - EnableWindow(GetDlgItem(hwnd, IDC_OPT_FILTERING_GROUP), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_LEARNING_GROUP), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_BAYES_BLOCK_MSG), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_BAYES_SPAM_SCORE), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_BAYES_AUTO_APPROVE), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_BAYES_HAM_SCORE), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_BAYES_AUTOLEARN_APPROVED), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_BAYES_AUTOLEARN_AUTOAPPROVED), enable && IsDlgButtonChecked(hwnd, IDC_OPT_BAYES_AUTO_APPROVE)); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_BAYES_AUTOLEARN_NOT_APPROVED), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_BAYES_WAIT_APPROVE), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_BAYES_AUTOLEARN_NOT_APPROVED2), enable); - EnableWindow(GetDlgItem(hwnd, IDC_STATIC_DAYSASSPAM), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_BAYES_AUTOLEARN_OUTGOING), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_BAYES_LEARNBOX), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_BAYES_SPAM), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_BAYES_HAM), enable); - EnableWindow(GetDlgItem(hwnd, IDC_CHECK_MSG), enable); - EnableWindow(GetDlgItem(hwnd, IDC_STATIC_SPAM_COUNT), enable); - EnableWindow(GetDlgItem(hwnd, IDC_STATIC_HAM_COUNT), enable); - EnableWindow(GetDlgItem(hwnd, IDC_STATIC_SPAMCOUNT_LABEL), enable); - EnableWindow(GetDlgItem(hwnd, IDC_STATIC_HAMCOUNT_LABEL), enable); -} - -INT_PTR CALLBACK DlgProcOptionsBayes(HWND optDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - static int bInitializing = 0, len; - BOOL bEnabled; - wchar_t *dbuf; - wchar_t buf[MAX_BUFFER_LENGTH]; - char cbuf[MAX_BUFFER_LENGTH]; - switch (msg) { - case WM_INITDIALOG: - bInitializing = 1; - TranslateDialogDefault(optDlg); - bEnabled = g_plugin.getByte("BayesEnabled", defaultBayesEnabled); - CheckDlgButton(optDlg, IDC_OPT_BAYES_ENABLED, bEnabled ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(optDlg, IDC_OPT_BAYES_BLOCK_MSG, g_plugin.getByte("BayesBlockMsg", defaultBayesBlockMsg) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(optDlg, IDC_OPT_BAYES_AUTO_APPROVE, g_plugin.getByte("BayesAutoApprove", defaultBayesAutoApprove) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(optDlg, IDC_OPT_BAYES_AUTOLEARN_APPROVED, g_plugin.getByte("BayesAutolearnApproved", defaultBayesAutolearnApproved) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(optDlg, IDC_OPT_BAYES_AUTOLEARN_AUTOAPPROVED, g_plugin.getByte("BayesAutolearnAutoApproved", defaultBayesAutolearnAutoApproved) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(optDlg, IDC_OPT_BAYES_AUTOLEARN_NOT_APPROVED, g_plugin.getByte("BayesAutolearnNotApproved", defaultBayesAutolearnNotApproved) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(optDlg, IDC_OPT_BAYES_AUTOLEARN_OUTGOING, g_plugin.getByte("BayesAutolearnOutgoing", defaultBayesAutolearnOutgoing) ? BST_CHECKED : BST_UNCHECKED); - - EnableControlsBayes(optDlg, bEnabled); - - mir_snwprintf(buf, L"%0.02f", (double)g_plugin.getDword("BayesSpamScore", defaultBayesSpamScore)*SCORE_C); - SetDlgItemText(optDlg, IDC_OPT_BAYES_SPAM_SCORE, buf); - mir_snwprintf(buf, L"%.02f", (double)g_plugin.getDword("BayesHamScore", defaultBayesHamScore)*SCORE_C); - SetDlgItemText(optDlg, IDC_OPT_BAYES_HAM_SCORE, buf); - mir_snwprintf(buf, L"%d", g_plugin.getDword("BayesWaitApprove", defaultBayesWaitApprove)); - SetDlgItemText(optDlg, IDC_OPT_BAYES_WAIT_APPROVE, buf); - - if (bEnabled) { - mir_snwprintf(buf, L"%d", get_msg_count(SPAM)); - SetDlgItemText(optDlg, IDC_STATIC_SPAM_COUNT, buf); - mir_snwprintf(buf, L"%d", get_msg_count(HAM)); - SetDlgItemText(optDlg, IDC_STATIC_HAM_COUNT, buf); - } - - bInitializing = 0; - break; - case WM_COMMAND: - if (bInitializing) - return FALSE; - switch (LOWORD(wParam)) { - case IDC_OPT_BAYES_ENABLED: - bEnabled = IsDlgButtonChecked(optDlg, IDC_OPT_BAYES_ENABLED); - EnableControlsBayes(optDlg, bEnabled); - case IDC_OPT_BAYES_AUTO_APPROVE: - bEnabled = IsDlgButtonChecked(optDlg, IDC_OPT_BAYES_ENABLED); - EnableWindow(GetDlgItem(optDlg, IDC_OPT_BAYES_AUTOLEARN_AUTOAPPROVED), - bEnabled && IsDlgButtonChecked(optDlg, IDC_OPT_BAYES_AUTO_APPROVE)); - case IDC_OPT_BAYES_BLOCK_MSG: - case IDC_OPT_BAYES_AUTOLEARN_APPROVED: - case IDC_OPT_BAYES_AUTOLEARN_AUTOAPPROVED: - case IDC_OPT_BAYES_AUTOLEARN_NOT_APPROVED: - case IDC_OPT_BAYES_AUTOLEARN_OUTGOING: - if (HIWORD(wParam) != BN_CLICKED) - return FALSE; - break; - case IDC_OPT_BAYES_SPAM_SCORE: - case IDC_OPT_BAYES_HAM_SCORE: - case IDC_OPT_BAYES_WAIT_APPROVE: - if (HIWORD(wParam) != EN_CHANGE) - return FALSE; - break; - case IDC_OPT_BAYES_LEARNBOX: - return FALSE; - case IDC_OPT_BAYES_HAM: - // Learn ham from learnbox - len = GetWindowTextLength(GetDlgItem(optDlg, IDC_OPT_BAYES_LEARNBOX))+1; - dbuf = (wchar_t *)malloc(len*sizeof(wchar_t)); - if (!dbuf) - return FALSE; - GetDlgItemText(optDlg, IDC_OPT_BAYES_LEARNBOX, dbuf, len); - learn_ham(dbuf); - SetDlgItemText(optDlg, IDC_OPT_BAYES_LEARNBOX, L""); - free(dbuf); - - mir_snwprintf(buf, L"%d", get_msg_count(SPAM)); - SetDlgItemText(optDlg, IDC_STATIC_SPAM_COUNT, buf); - mir_snwprintf(buf, L"%d", get_msg_count(HAM)); - SetDlgItemText(optDlg, IDC_STATIC_HAM_COUNT, buf); - return FALSE; - - case IDC_OPT_BAYES_SPAM: - // Learn spam from learnbox - len = GetWindowTextLength(GetDlgItem(optDlg, IDC_OPT_BAYES_LEARNBOX))+1; - dbuf = (wchar_t *)malloc(len*sizeof(wchar_t)); - if (!dbuf) - return FALSE; - GetDlgItemText(optDlg, IDC_OPT_BAYES_LEARNBOX, dbuf, len); - learn_spam(dbuf); - SetDlgItemText(optDlg, IDC_OPT_BAYES_LEARNBOX, L""); - free(dbuf); - - mir_snwprintf(buf, L"%d", get_msg_count(SPAM)); - SetDlgItemText(optDlg, IDC_STATIC_SPAM_COUNT, buf); - mir_snwprintf(buf, L"%d", get_msg_count(HAM)); - SetDlgItemText(optDlg, IDC_STATIC_HAM_COUNT, buf); - return FALSE; - - case IDC_CHECK_MSG: - len = GetWindowTextLength(GetDlgItem(optDlg, IDC_OPT_BAYES_LEARNBOX))+1; - dbuf = (wchar_t *)malloc((len)*sizeof(wchar_t)); - if (!dbuf) - return FALSE; - GetDlgItemText(optDlg, IDC_OPT_BAYES_LEARNBOX, dbuf, len); - mir_snprintf(cbuf, "%0.04f", get_msg_score(dbuf)); - SetDlgItemText(optDlg, IDC_OPT_BAYES_LEARNBOX, L""); - MessageBoxA(nullptr, cbuf, Translate("Message score"), MB_OK); - free(dbuf); - return FALSE; - - } - SendMessage(GetParent(optDlg), PSM_CHANGED, 0, 0); - break; - case WM_NOTIFY: - switch (((NMHDR*)lParam)->code) { - case PSN_APPLY: - g_plugin.setByte("BayesEnabled", IsDlgButtonChecked(optDlg, IDC_OPT_BAYES_ENABLED)); - g_plugin.setByte("BayesBlockMsg", IsDlgButtonChecked(optDlg, IDC_OPT_BAYES_BLOCK_MSG)); - g_plugin.setByte("BayesAutoApprove", IsDlgButtonChecked(optDlg, IDC_OPT_BAYES_AUTO_APPROVE)); - g_plugin.setByte("BayesAutolearnApproved", IsDlgButtonChecked(optDlg, IDC_OPT_BAYES_AUTOLEARN_APPROVED)); - g_plugin.setByte("BayesAutolearnAutoApproved", IsDlgButtonChecked(optDlg, IDC_OPT_BAYES_AUTOLEARN_AUTOAPPROVED)); - g_plugin.setByte("BayesAutolearnNotApproved", IsDlgButtonChecked(optDlg, IDC_OPT_BAYES_AUTOLEARN_NOT_APPROVED)); - g_plugin.setByte("BayesAutolearnOutgoing", IsDlgButtonChecked(optDlg, IDC_OPT_BAYES_AUTOLEARN_OUTGOING)); - _saveDlgItemScore(optDlg, IDC_OPT_BAYES_SPAM_SCORE, "BayesSpamScore"); - _saveDlgItemScore(optDlg, IDC_OPT_BAYES_HAM_SCORE, "BayesHamScore"); - _saveDlgItemInt(optDlg, IDC_OPT_BAYES_WAIT_APPROVE, "BayesWaitApprove"); - break; - } - break; - case WM_DESTROY: - break; - } - return FALSE; -} - -extern INT_PTR CALLBACK DlgProcOptionsPopups(HWND optDlg, UINT msg, WPARAM wParam, LPARAM lParam); - -int OnOptInitialize(WPARAM wParam, LPARAM) -{ - OPTIONSDIALOGPAGE odp = {}; - odp.szGroup.a = LPGEN("Message sessions"); - odp.szTitle.a = MODULENAME; - odp.flags = ODPF_BOLDGROUPS; - - odp.szTab.a = LPGEN("Settings"); - odp.pszTemplate = MAKEINTRESOURCEA(IDD_SPAMOTRON_MAIN); - odp.pfnDlgProc = DlgProcOptionsMain; - g_plugin.addOptions(wParam, &odp); - - odp.szTab.a = LPGEN("Messages"); - odp.pszTemplate = MAKEINTRESOURCEA(IDD_SPAMOTRON_Q); - odp.pfnDlgProc = DlgProcOptionsQuestion; - g_plugin.addOptions(wParam, &odp); - - odp.szTab.a = LPGEN("Bayes"); - odp.pszTemplate = MAKEINTRESOURCEA(IDD_SPAMOTRON_BAYES); - odp.pfnDlgProc = DlgProcOptionsBayes; - g_plugin.addOptions(wParam, &odp); - - odp.pszTemplate = MAKEINTRESOURCEA(IDD_SPAMOTRON_POPUPS); - odp.pfnDlgProc = DlgProcOptionsPopups; - odp.szGroup.a = LPGEN("Popups"); - odp.szTab.a = nullptr; - g_plugin.addOptions(wParam, &odp); - return 0; -} diff --git a/plugins/Spamotron/src/popups.cpp b/plugins/Spamotron/src/popups.cpp deleted file mode 100644 index 70336e9bd8..0000000000 --- a/plugins/Spamotron/src/popups.cpp +++ /dev/null @@ -1,240 +0,0 @@ -#include "stdafx.h" - -extern BOOL _saveDlgItemInt(HWND hDialog, int controlID, char* option); - -void EnablePopupControls(HWND hwnd, BOOL enable) -{ - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_NOTIFY_BLOCKED), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_NOTIFY_APPROVED), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_NOTIFY_CHALLENGE), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_BLOCKED_FOREGROUND), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_BLOCKED_BACKGROUND), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_APPROVED_FOREGROUND), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_APPROVED_BACKGROUND), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_CHALLENGE_FOREGROUND), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_CHALLENGE_BACKGROUND), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_BLOCKED_TIMEOUT), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_APPROVED_TIMEOUT), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_CHALLENGE_TIMEOUT), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_DEFAULT_COLORS), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_WINDOWS_COLORS), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_DEFAULT_TIMEOUT), enable); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_PREVIEW), enable); -} - -void EnablePopupColors(HWND hwnd, BOOL enableDefault, BOOL enableWindows) -{ - BOOL enable, bEnabled; - bEnabled = IsDlgButtonChecked(hwnd, IDC_OPT_POPUPS_ENABLED); - enable = enableDefault || enableWindows; - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_BLOCKED_FOREGROUND), !enable && bEnabled); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_BLOCKED_BACKGROUND), !enable && bEnabled); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_APPROVED_FOREGROUND), !enable && bEnabled); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_APPROVED_BACKGROUND), !enable && bEnabled); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_CHALLENGE_FOREGROUND), !enable && bEnabled); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_CHALLENGE_BACKGROUND), !enable && bEnabled); - - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_WINDOWS_COLORS), !enableDefault && bEnabled); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_DEFAULT_COLORS), !enableWindows && bEnabled); -} - -void EnablePopupTimeouts(HWND hwnd, BOOL enable) -{ - BOOL bEnabled = IsDlgButtonChecked(hwnd, IDC_OPT_POPUPS_ENABLED); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_BLOCKED_TIMEOUT), !enable && bEnabled); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_APPROVED_TIMEOUT), !enable && bEnabled); - EnableWindow(GetDlgItem(hwnd, IDC_OPT_POPUPS_CHALLENGE_TIMEOUT), !enable && bEnabled); -} - -INT_PTR CALLBACK DlgProcOptionsPopups(HWND optDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - BOOL bEnabled; - static int bInitializing = 0; - switch (msg) { - case WM_INITDIALOG: - bInitializing = 1; - TranslateDialogDefault(optDlg); - bEnabled = g_plugin.getByte("NotifyPopup", defaultNotifyPopup); - CheckDlgButton(optDlg, IDC_OPT_POPUPS_ENABLED, bEnabled ? BST_CHECKED : BST_UNCHECKED); - EnablePopupControls(optDlg, bEnabled); - - CheckDlgButton(optDlg, IDC_OPT_POPUPS_NOTIFY_BLOCKED, g_plugin.getByte("NotifyPopupBlocked", defaultNotifyPopupBlocked) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(optDlg, IDC_OPT_POPUPS_NOTIFY_APPROVED, g_plugin.getByte("NotifyPopupApproved", defaultNotifyPopupApproved) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(optDlg, IDC_OPT_POPUPS_NOTIFY_CHALLENGE, g_plugin.getByte("NotifyPopupChallenge", defaultNotifyPopupChallenge) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(optDlg, IDC_OPT_POPUPS_DEFAULT_COLORS, g_plugin.getByte("PopupDefaultColors", defaultPopupDefaultColors) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(optDlg, IDC_OPT_POPUPS_WINDOWS_COLORS, g_plugin.getByte("PopupWindowsColors", defaultPopupWindowsColors) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(optDlg, IDC_OPT_POPUPS_DEFAULT_TIMEOUT, g_plugin.getByte("PopupDefaultTimeout", defaultPopupDefaultTimeout) ? BST_CHECKED : BST_UNCHECKED); - SetDlgItemInt(optDlg, IDC_OPT_POPUPS_BLOCKED_TIMEOUT, g_plugin.getDword("PopupBlockedTimeout", defaultPopupBlockedTimeout), FALSE); - SetDlgItemInt(optDlg, IDC_OPT_POPUPS_APPROVED_TIMEOUT, g_plugin.getDword("PopupApprovedTimeout", defaultPopupApprovedTimeout), FALSE); - SetDlgItemInt(optDlg, IDC_OPT_POPUPS_CHALLENGE_TIMEOUT, g_plugin.getDword("PopupChallengeTimeout", defaultPopupChallengeTimeout), FALSE); - SendDlgItemMessage(optDlg, IDC_OPT_POPUPS_BLOCKED_FOREGROUND, CPM_SETCOLOUR, 0, g_plugin.getDword("PopupBlockedForeground", defaultPopupBlockedForeground)); - SendDlgItemMessage(optDlg, IDC_OPT_POPUPS_BLOCKED_BACKGROUND, CPM_SETCOLOUR, 0, g_plugin.getDword("PopupBlockedBackground", defaultPopupBlockedBackground)); - SendDlgItemMessage(optDlg, IDC_OPT_POPUPS_APPROVED_FOREGROUND, CPM_SETCOLOUR, 0, g_plugin.getDword("PopupApprovedForeground", defaultPopupApprovedForeground)); - SendDlgItemMessage(optDlg, IDC_OPT_POPUPS_APPROVED_BACKGROUND, CPM_SETCOLOUR, 0, g_plugin.getDword("PopupApprovedBackground", defaultPopupApprovedBackground)); - SendDlgItemMessage(optDlg, IDC_OPT_POPUPS_CHALLENGE_FOREGROUND, CPM_SETCOLOUR, 0, g_plugin.getDword("PopupChallengeForeground", defaultPopupChallengeForeground)); - SendDlgItemMessage(optDlg, IDC_OPT_POPUPS_CHALLENGE_BACKGROUND, CPM_SETCOLOUR, 0, g_plugin.getDword("PopupChallengeBackground", defaultPopupChallengeBackground)); - EnablePopupTimeouts(optDlg, IsDlgButtonChecked(optDlg, IDC_OPT_POPUPS_DEFAULT_TIMEOUT)); - EnablePopupColors(optDlg, - g_plugin.getByte("PopupDefaultColors", defaultPopupDefaultColors), - g_plugin.getByte("PopupWindowsColors", defaultPopupWindowsColors)); - - bInitializing = 0; - break; - case WM_COMMAND: - if (bInitializing) - return FALSE; - switch (LOWORD(wParam)) { - case IDC_OPT_POPUPS_ENABLED: - bEnabled = IsDlgButtonChecked(optDlg, IDC_OPT_POPUPS_ENABLED); - EnablePopupControls(optDlg, bEnabled); - case IDC_OPT_POPUPS_NOTIFY_BLOCKED: - case IDC_OPT_POPUPS_NOTIFY_APPROVED: - case IDC_OPT_POPUPS_NOTIFY_CHALLENGE: - case IDC_OPT_POPUPS_DEFAULT_COLORS: - case IDC_OPT_POPUPS_WINDOWS_COLORS: - case IDC_OPT_POPUPS_DEFAULT_TIMEOUT: - EnablePopupColors(optDlg, - IsDlgButtonChecked(optDlg, IDC_OPT_POPUPS_DEFAULT_COLORS), - IsDlgButtonChecked(optDlg, IDC_OPT_POPUPS_WINDOWS_COLORS)); - EnablePopupTimeouts(optDlg, IsDlgButtonChecked(optDlg, IDC_OPT_POPUPS_DEFAULT_TIMEOUT)); - - if (HIWORD(wParam) != BN_CLICKED) - return FALSE; - break; - case IDC_OPT_POPUPS_BLOCKED_TIMEOUT: - case IDC_OPT_POPUPS_APPROVED_TIMEOUT: - case IDC_OPT_POPUPS_CHALLENGE_TIMEOUT: - if (HIWORD(wParam) != EN_CHANGE) - return FALSE; - break; - case IDC_OPT_POPUPS_PREVIEW: - ShowPopupPreview(optDlg, POPUP_BLOCKED, nullptr, TranslateT("Message blocked due to preview action")); - ShowPopupPreview(optDlg, POPUP_APPROVED, nullptr, TranslateT("Contact approved due to preview action")); - ShowPopupPreview(optDlg, POPUP_CHALLENGE, nullptr, TranslateT("Challenge sent to preview contact")); - return FALSE; - } - SendMessage(GetParent(optDlg), PSM_CHANGED, 0, 0); - break; - case WM_NOTIFY: - switch (((NMHDR*)lParam)->code) { - case PSN_APPLY: - g_plugin.setByte("NotifyPopup", IsDlgButtonChecked(optDlg, IDC_OPT_POPUPS_ENABLED)); - g_plugin.setByte("NotifyPopupBlocked", IsDlgButtonChecked(optDlg, IDC_OPT_POPUPS_NOTIFY_BLOCKED)); - g_plugin.setByte("NotifyPopupApproved", IsDlgButtonChecked(optDlg, IDC_OPT_POPUPS_NOTIFY_APPROVED)); - g_plugin.setByte("NotifyPopupChallenge", IsDlgButtonChecked(optDlg, IDC_OPT_POPUPS_NOTIFY_CHALLENGE)); - g_plugin.setByte("PopupDefaultColors", IsDlgButtonChecked(optDlg, IDC_OPT_POPUPS_DEFAULT_COLORS)); - g_plugin.setByte("PopupWindowsColors", IsDlgButtonChecked(optDlg, IDC_OPT_POPUPS_WINDOWS_COLORS)); - g_plugin.setByte("PopupDefaultTimeout", IsDlgButtonChecked(optDlg, IDC_OPT_POPUPS_DEFAULT_TIMEOUT)); - _saveDlgItemInt(optDlg, IDC_OPT_POPUPS_BLOCKED_TIMEOUT, "PopupBlockedTimeout"); - _saveDlgItemInt(optDlg, IDC_OPT_POPUPS_APPROVED_TIMEOUT, "PopupApprovedTimeout"); - _saveDlgItemInt(optDlg, IDC_OPT_POPUPS_CHALLENGE_TIMEOUT, "PopupChallengeTimeout"); - g_plugin.setDword("PopupBlockedForeground", SendDlgItemMessage(optDlg,IDC_OPT_POPUPS_BLOCKED_FOREGROUND,CPM_GETCOLOUR,0,0)); - g_plugin.setDword("PopupBlockedBackground", SendDlgItemMessage(optDlg,IDC_OPT_POPUPS_BLOCKED_BACKGROUND,CPM_GETCOLOUR,0,0)); - g_plugin.setDword("PopupApprovedForeground", SendDlgItemMessage(optDlg,IDC_OPT_POPUPS_APPROVED_FOREGROUND,CPM_GETCOLOUR,0,0)); - g_plugin.setDword("PopupApprovedBackground", SendDlgItemMessage(optDlg,IDC_OPT_POPUPS_APPROVED_BACKGROUND,CPM_GETCOLOUR,0,0)); - g_plugin.setDword("PopupChallengeForeground", SendDlgItemMessage(optDlg,IDC_OPT_POPUPS_CHALLENGE_FOREGROUND,CPM_GETCOLOUR,0,0)); - g_plugin.setDword("PopupChallengeBackground", SendDlgItemMessage(optDlg,IDC_OPT_POPUPS_CHALLENGE_BACKGROUND,CPM_GETCOLOUR,0,0)); - break; - } - break; - case WM_DESTROY: - break; - } - return FALSE; -} - -int ShowPopupPreview(HWND optDlg, uint8_t popupType, wchar_t *line1, wchar_t *line2) -{ - POPUPDATAW ppd; - switch (popupType) - { - case POPUP_DEFAULT: - ppd.colorText = SendDlgItemMessage(optDlg,IDC_OPT_POPUPS_APPROVED_FOREGROUND,CPM_GETCOLOUR,0,0); - ppd.colorBack = SendDlgItemMessage(optDlg,IDC_OPT_POPUPS_APPROVED_BACKGROUND,CPM_GETCOLOUR,0,0); - break; - case POPUP_BLOCKED: - ppd.colorText = SendDlgItemMessage(optDlg,IDC_OPT_POPUPS_BLOCKED_FOREGROUND,CPM_GETCOLOUR,0,0); - ppd.colorBack = SendDlgItemMessage(optDlg,IDC_OPT_POPUPS_BLOCKED_BACKGROUND,CPM_GETCOLOUR,0,0); - ppd.iSeconds = GetDlgItemInt(optDlg, IDC_OPT_POPUPS_BLOCKED_TIMEOUT, nullptr, TRUE); - ppd.lchIcon = Skin_LoadIcon(SKINICON_OTHER_DELETE); - break; - case POPUP_APPROVED: - ppd.colorText = SendDlgItemMessage(optDlg,IDC_OPT_POPUPS_APPROVED_FOREGROUND,CPM_GETCOLOUR,0,0); - ppd.colorBack = SendDlgItemMessage(optDlg,IDC_OPT_POPUPS_APPROVED_BACKGROUND,CPM_GETCOLOUR,0,0); - ppd.iSeconds = GetDlgItemInt(optDlg, IDC_OPT_POPUPS_APPROVED_TIMEOUT, nullptr, TRUE); - ppd.lchIcon = Skin_LoadIcon(SKINICON_OTHER_ADDCONTACT); - break; - case POPUP_CHALLENGE: - ppd.colorText = SendDlgItemMessage(optDlg,IDC_OPT_POPUPS_CHALLENGE_FOREGROUND,CPM_GETCOLOUR,0,0); - ppd.colorBack = SendDlgItemMessage(optDlg,IDC_OPT_POPUPS_CHALLENGE_BACKGROUND,CPM_GETCOLOUR,0,0); - ppd.iSeconds = GetDlgItemInt(optDlg, IDC_OPT_POPUPS_CHALLENGE_TIMEOUT, nullptr, TRUE); - ppd.lchIcon = Skin_LoadIcon(SKINICON_EVENT_MESSAGE); - break; - } - if (IsDlgButtonChecked(optDlg, IDC_OPT_POPUPS_WINDOWS_COLORS)) { - ppd.colorText = GetSysColor(COLOR_WINDOWTEXT); - ppd.colorBack = GetSysColor(COLOR_WINDOW); - } - if (IsDlgButtonChecked(optDlg, IDC_OPT_POPUPS_DEFAULT_COLORS)) { - ppd.colorText = NULL; - ppd.colorBack = NULL; - } - if (ppd.iSeconds < 1) - ppd.iSeconds = -1; - if (IsDlgButtonChecked(optDlg, IDC_OPT_POPUPS_DEFAULT_TIMEOUT) || popupType == POPUP_DEFAULT) - ppd.iSeconds = 0; - - ppd.lchContact = NULL; - wcsncpy_s(ppd.lpwzContactName, (line1 ? line1 : _A2W(MODULENAME)), _TRUNCATE); - if (line2) - wcsncpy_s(ppd.lpwzText, line2, _TRUNCATE); - return (int)PUAddPopupW(&ppd); -} - -int ShowPopup(MCONTACT hContact, uint8_t popupType, wchar_t *line1, wchar_t *line2) -{ - POPUPDATAW ppd; - switch (popupType) - { - case POPUP_DEFAULT: - ppd.colorText = g_plugin.getDword("PopupApprovedForeground", defaultPopupApprovedForeground); - ppd.colorBack = g_plugin.getDword("PopupApprovedBackground", defaultPopupApprovedBackground); - break; - case POPUP_BLOCKED: - ppd.colorText = g_plugin.getDword("PopupBlockedForeground", defaultPopupBlockedForeground); - ppd.colorBack = g_plugin.getDword("PopupBlockedBackground", defaultPopupBlockedBackground); - ppd.iSeconds = g_plugin.getDword("PopupBlockedTimeout", defaultPopupBlockedTimeout); - ppd.lchIcon = Skin_LoadIcon(SKINICON_OTHER_DELETE); - break; - case POPUP_APPROVED: - ppd.colorText = g_plugin.getDword("PopupApprovedForeground", defaultPopupApprovedForeground); - ppd.colorBack = g_plugin.getDword("PopupApprovedBackground", defaultPopupApprovedBackground); - ppd.iSeconds = g_plugin.getDword("PopupApprovedTimeout", defaultPopupApprovedTimeout); - ppd.lchIcon = Skin_LoadIcon(SKINICON_OTHER_ADDCONTACT); - break; - case POPUP_CHALLENGE: - ppd.colorText = g_plugin.getDword("PopupChallengeForeground", defaultPopupChallengeForeground); - ppd.colorBack = g_plugin.getDword("PopupChallengeBackground", defaultPopupChallengeBackground); - ppd.iSeconds = g_plugin.getDword("PopupChallengeTimeout", defaultPopupChallengeTimeout); - ppd.lchIcon = Skin_LoadIcon(SKINICON_EVENT_MESSAGE); - break; - } - if (g_plugin.getByte("PopupWindowsColors", defaultPopupWindowsColors)) { - ppd.colorText = GetSysColor(COLOR_WINDOWTEXT); - ppd.colorBack = GetSysColor(COLOR_WINDOW); - } - if (g_plugin.getByte("PopupDefaultColors", defaultPopupDefaultColors)) { - ppd.colorText = NULL; - ppd.colorBack = NULL; - } - if (ppd.iSeconds < 1) - ppd.iSeconds = -1; - if (g_plugin.getByte("PopupDefaultTimeout", defaultPopupDefaultTimeout) || popupType == POPUP_DEFAULT) - ppd.iSeconds = 0; - - ppd.lchContact = hContact; - wcsncpy_s(ppd.lpwzContactName, (line1 ? line1 : _A2W(MODULENAME)), _TRUNCATE); - if (line2) - wcsncpy_s(ppd.lpwzText, line2, _TRUNCATE); - return (int)PUAddPopupW(&ppd); -} \ No newline at end of file diff --git a/plugins/Spamotron/src/resource.h b/plugins/Spamotron/src/resource.h deleted file mode 100644 index 5a13092d35..0000000000 --- a/plugins/Spamotron/src/resource.h +++ /dev/null @@ -1,90 +0,0 @@ -//{{NO_DEPENDENCIES}} -// Microsoft Visual C++ generated include file. -// Used by W:\miranda-ng\plugins\Spamotron\res\spamotron.rc -// -#define IDD_SPAMOTRON_MAIN 101 -#define IDD_SPAMOTRON_Q 102 -#define IDD_SPAMOTRON_BAYES 103 -#define IDD_SPAMOTRON_POPUPS 104 -#define IDD_SPAMOTRON_MAIN1 105 -#define IDC_OPT_OUT_MSG_APPROVE 1002 -#define IDC_OPT_MODE 1003 -#define IDC_OPT_CHALLENGE 1004 -#define IDC_OPT_RESPONSE 1005 -#define IDC_OPT_SUCCESS_RESPONSE 1006 -#define IDC_OPT_AUTH_CHALLENGE 1007 -#define IDC_OPT_MATH_RESPONSE 1008 -#define IDC_STATIC_RESPONSE 1009 -#define IDC_STATIC_MODEMSG 1010 -#define IDC_DEFAULTS 1011 -#define IDC_OPT_PROTOCOLS 1012 -#define IDC_OPT_REPLY_ON_SUCCESS 1013 -#define IDC_OPT_DONT_REPLY_SAME_MSG 1014 -#define IDC_OPT_REPLY_ON_AUTH 1015 -#define IDC_OPT_BAYES_AUTOLEARN_APPROVED 1016 -#define IDC_OPT_POPUPS_NOTIFY_APPROVED 1017 -#define IDC_OPT_LOG_ACTIONS 1019 -#define IDC_OPT_MAX_MSG_CONTACT 1023 -#define IDC_OPT_DONT_REPLY_MSG_WORDLIST 1024 -#define IDC_OPT_MAX_SAME_MSG 1025 -#define IDC_OPT_IN_MSG_APPROVE 1027 -#define IDC_OPT_IN_MSG_APPROVE_WORDLIST 1028 -#define IDC_OPT_DONT_REPLY_MSG 1029 -#define IDC_OPT_HIDE_UNTIL_VERIFIED 1033 -#define IDC_OPT_ADD_PERMANENTLY 1034 -#define IDC_OPT_BAYES_SPAM 1036 -#define IDC_OPT_POPUPS_PREVIEW 1036 -#define IDC_OPT_KEEP_BLOCKED_MSG 1037 -#define IDC_OPT_BAYES_BLOCK_MSG 1039 -#define IDC_OPT_BAYES_AUTOLEARN_OUTGOING 1041 -#define IDC_OPT_BAYES_LEARNBOX 1042 -#define IDC_OPT_BAYES_HAM 1043 -#define IDC_OPT_BAYES_SPAM_SCORE 1044 -#define IDC_OPT_BAYES_AUTO_APPROVE 1045 -#define IDC_EDIT3 1046 -#define IDC_OPT_BAYES_HAM_SCORE 1046 -#define IDC_STATIC_HAM_COUNT 1047 -#define IDC_STATIC_SPAM_COUNT 1048 -#define IDC_CHECK_MSG 1049 -#define IDC_OPT_BAYES_AUTOLEARN_NOT_APPROVED 1050 -#define IDC_OPT_BAYES_WAIT_APPROVE 1051 -#define IDC_OPT_BAYES_ENABLED 1052 -#define IDC_OPT_FILTERING_GROUP 1053 -#define IDC_OPT_LEARNING_GROUP 1054 -#define IDC_OPT_BAYES_AUTOLEARN_NOT_APPROVED2 1055 -#define IDC_OPT_CCRESPONSE 1056 -#define IDC_OPT_BAYES_AUTOLEARN_AUTOAPPROVED 1058 -#define IDC_STATIC_DAYSASSPAM 1059 -#define IDC_STATIC_SPAMCOUNT_LABEL 1060 -#define IDC_STATIC_HAMCOUNT_LABEL 1061 -#define IDC_OPT_REPLY_ON_MSG 1062 -#define IDC_OPT_POPUPS_ENABLE 1063 -#define IDC_OPT_POPUPS_ENABLED 1063 -#define IDC_OPT_POPUPS_NOTIFY_BLOCKED 1064 -#define IDC_OPT_POPUPS_BLOCKED_FOREGROUND 1065 -#define IDC_OPT_POPUPS_BLOCKED_BACKGROUND 1066 -#define IDC_OPT_POPUPS_APPROVED_FOREGROUND 1067 -#define IDC_OPT_POPUPS_APPROVED_BACKGROUND 1068 -#define IDC_OPT_POPUPS_CHALLENGE_FOREGROUND 1069 -#define IDC_OPT_POPUPS_CHALLENGE_BACKGROUND 1070 -#define IDC_OPT_POPUPS_BLOCKED_TIMEOUT 1073 -#define IDC_OPT_POPUPS_APPROVED_TIMEOUT 1074 -#define IDC_OPT_POPUPS_CHALLENGE_TIMEOUT 1075 -#define IDC_OPT_POPUPS_DEFAULT_COLORS 1076 -#define IDC_OPT_POPUPS_DEFAULT_TIMEOUT 1077 -#define IDC_OPT_POPUPS_WINDOWS_COLORS 1078 -#define IDC_OPT_POPUPS_NOTIFY_CHALLENGE 1079 -#define IDC_OPT_MARK_MSG_AS_NEW_ON_APPROVAL 1080 -#define IDC_OPT_MARK_MSG_UNREAD_ON_APPROVAL 1080 - -// Next default values for new objects -// -#ifdef APSTUDIO_INVOKED -#ifndef APSTUDIO_READONLY_SYMBOLS -#define _APS_NO_MFC 1 -#define _APS_NEXT_RESOURCE_VALUE 105 -#define _APS_NEXT_COMMAND_VALUE 40001 -#define _APS_NEXT_CONTROL_VALUE 1081 -#define _APS_NEXT_SYMED_VALUE 101 -#endif -#endif diff --git a/plugins/Spamotron/src/spamotron.cpp b/plugins/Spamotron/src/spamotron.cpp deleted file mode 100644 index 40340c72a7..0000000000 --- a/plugins/Spamotron/src/spamotron.cpp +++ /dev/null @@ -1,520 +0,0 @@ -#include "stdafx.h" - -time_t last_queue_check = 0; - -CMPlugin g_plugin; - -///////////////////////////////////////////////////////////////////////////////////////// - -PLUGININFOEX pluginInfoEx = { - sizeof(PLUGININFOEX), - __PLUGIN_NAME, - PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM), - __DESCRIPTION, - __AUTHOR, - __COPYRIGHT, - __AUTHORWEB, - UNICODE_AWARE, - // 14331048-5a73-4fdb-b909-2d7e1825a012 - {0x14331048, 0x5a73, 0x4fdb, {0xb9, 0x09, 0x2d, 0x7e, 0x18, 0x25, 0xa0, 0x12}} -}; - -CMPlugin::CMPlugin() : - PLUGIN(MODULENAME, pluginInfoEx) -{} - -///////////////////////////////////////////////////////////////////////////////////////// - -extern int OnOptInitialize(WPARAM wParam, LPARAM lParam); - -int OnDBEventFilterAdd(WPARAM wParam, LPARAM lParam) -{ - MCONTACT hContact = wParam; - DBEVENTINFO *dbei = (DBEVENTINFO *)lParam; - char protoOption[256] = {0}; - int buflen = MAX_BUFFER_LENGTH; - wchar_t buf[MAX_BUFFER_LENGTH]; - wchar_t *challengeW = nullptr, *tmpW = nullptr; - wchar_t mexpr[64]; - int maxmsglen = 0, a, b, i; - BOOL bayesEnabled = g_plugin.getByte("BayesEnabled", defaultBayesEnabled); - BOOL bCorrectResponse = FALSE; - - // get hContact from DBEVENTINFO as icq_proto.c doesn't pass hContact the usual way for some reason. - if (dbei->eventType == EVENTTYPE_AUTHREQUEST) - hContact = (MCONTACT)*(PDWORD(dbei->pBlob+sizeof(uint32_t))); - - // get maximum length of the message a protocol supports - maxmsglen = CallProtoService(dbei->szModule, PS_GETCAPS, PFLAG_MAXLENOFMESSAGE, hContact); - - - /*** Dequeue and learn messages ***/ - - if (bayesEnabled && g_plugin.getByte("BayesAutolearnNotApproved", defaultBayesAutolearnNotApproved)) - if (time(0) - last_queue_check > 4*3600) { // dequeue every 4 hours - dequeue_messages(); - last_queue_check = time(0); - } - - /*** Check for conditional and unconditional approval ***/ - - // Pass-through if protocol is not enabled - mir_strcat(protoOption, "proto_"); - mir_strcat(protoOption, dbei->szModule); - if (g_plugin.getByte(protoOption, 0) == 0) // Protocol is not handled by Spam-o-tron - return 0; - - // Pass-through if the event is not of type EVENTTYPE_MESSAGE or EVENTTYPE_AUTHREQUEST - if (dbei->eventType != EVENTTYPE_MESSAGE && dbei->eventType != EVENTTYPE_AUTHREQUEST) - return 0; - - // Pass-through if contact is already verified. - if (g_plugin.getByte(hContact, "Verified", 0) == 1) - return 0; - - // Pass-through if the event is already read. - if (dbei->flags & DBEF_READ) - return 0; - - // Pass-through if event is from a contact that is already in the list. - if (!Contact::OnList(hContact)) // Already in the list - return 0; - - // Pass-through if event is from a contact that is already in the server-side contact list - if (db_get_w(hContact, dbei->szModule, "ServerId", 0)) - return 0; - - // Pass-through if contact is a MetaContact - if (db_get_dw(hContact, "MetaContacts", "NumContacts", 0)) - return 0; - - // Pass-through and approve if outgoing event. - if (dbei->flags & DBEF_SENT) { - if (g_plugin.getByte("ApproveOnMsgOut", 0)) { - g_plugin.setByte(hContact, "Verified", 1); - if (g_plugin.getByte("AddPermanently", defaultAddPermanently)) - Contact::PutOnList(hContact); - db_unset(hContact, "CList", "Delete"); - } - return 0; - } - - // Hide the contact until verified if option set. - if (g_plugin.getByte("HideUnverified", defaultHideUnverified)) - Contact::Hide(hContact); - - // Fetch the incoming message body - char *msgblob; - if (dbei->eventType == EVENTTYPE_MESSAGE) { - msgblob = (char *)dbei->pBlob; - } - else if (dbei->eventType == EVENTTYPE_AUTHREQUEST) { - msgblob = (char *)(dbei->pBlob + sizeof(uint32_t) + sizeof(uint32_t)); - for(a = 4; a > 0; a--) - msgblob += mir_strlen(msgblob)+1; - } - else msgblob = nullptr; - - wchar_t *message = nullptr; - if (dbei->flags & DBEF_UTF) - message = mir_utf8decodeW(msgblob); - else - message = mir_a2u(msgblob); - - /*** Check for words in white-list ***/ - if (g_plugin.getByte("ApproveOnMsgIn", defaultApproveOnMsgIn)) { - wchar_t *whitelist = (wchar_t*)malloc(2048 * sizeof(wchar_t)); - if (whitelist != nullptr) { - _getOptS(whitelist, 2048, "ApproveOnMsgInWordlist", defaultApproveOnMsgInWordlist); - if (_isregex(whitelist)) { - if (_regmatch(message, whitelist)) - bCorrectResponse = TRUE; - } - else { - wchar_t *ptok = wcstok(whitelist, L" "); - while (ptok != nullptr) { - if (wcsstr(message, ptok)) { - bCorrectResponse = TRUE; - break; - } - ptok = wcstok(nullptr, L" "); - } - } - free(whitelist); - - if (bCorrectResponse) { - g_plugin.setByte(hContact, "Verified", 1); - if (g_plugin.getByte("HideUnverified", defaultHideUnverified)) - Contact::Hide(hContact, false); - if (g_plugin.getByte("AddPermanently", defaultAddPermanently)) - Contact::PutOnList(hContact); - db_unset(hContact, "CList", "Delete"); - if (g_plugin.getByte("ReplyOnSuccess", defaultReplyOnSuccess) && (g_plugin.getByte(hContact, "MsgSent", 0))) { - T2Utf response(_getOptS(buf, buflen, "SuccessResponse", defaultSuccessResponse)); - ProtoChainSend(hContact, PSS_MESSAGE, 0, response); - } - return 0; - } - } - } - - - /*** Check for correct answer ***/ - - switch (g_plugin.getByte("Mode", defaultMode)) - { - case SPAMOTRON_MODE_ROTATE: - case SPAMOTRON_MODE_RANDOM: - get_response(buf, buflen, g_plugin.getDword(hContact, "ResponseNum", 0)); - if (_isregex(buf)) { - if (_regmatch(message, buf)) - bCorrectResponse = TRUE; - } else { - if (_tcsstr_cc(message, buf, g_plugin.getByte("ResponseCC", defaultResponseCC)) && - (mir_wstrlen(message) == mir_wstrlen(buf))) - bCorrectResponse = TRUE; - } - break; - - case SPAMOTRON_MODE_PLAIN: - _getOptS(buf, buflen, "Response", defaultResponse); - i = get_response_num(buf); - while (i-- > 0) { - get_response(buf, buflen, i-1); - if (_isregex(buf)) { - if (_regmatch(message, buf)) { - bCorrectResponse = TRUE; - break; - } - } else { - if (_tcsstr_cc(message, buf, g_plugin.getByte("ResponseCC", defaultResponseCC)) && - (mir_wstrlen(message) == mir_wstrlen(buf))) { - bCorrectResponse = TRUE; - break; - } - } - } - break; - - case SPAMOTRON_MODE_MATH: - if (message == nullptr) - break; - _itow(g_plugin.getDword(hContact, "ResponseMath", -1), buf, 10); - if (wcsstr(message, buf) && (mir_wstrlen(buf) == mir_wstrlen(message))) { - bCorrectResponse = TRUE; - } - break; - } - - if (bCorrectResponse) - { - g_plugin.setByte(hContact, "Verified", 1); - if (g_plugin.getByte("HideUnverified", defaultHideUnverified)) - Contact::Hide(hContact, false); - if (g_plugin.getByte("AddPermanently", defaultAddPermanently)) - Contact::PutOnList(hContact); - db_unset(hContact, "CList", "Delete"); - db_unset(hContact, "CList", "ResponseNum"); - if (g_plugin.getByte("ReplyOnSuccess", defaultReplyOnSuccess)) { - T2Utf response(_getOptS(buf, buflen, "SuccessResponse", defaultSuccessResponse)); - ProtoChainSend(hContact, PSS_MESSAGE, 0, response); - } - _notify(hContact, POPUP_APPROVED, TranslateT("Contact %s approved."), nullptr); - - // Resubmit pending authorization request - if (g_plugin.getByte(hContact, "AuthEventPending", FALSE)) { - DBVARIANT _dbv; - wchar_t AuthEventModule[100]; - char* szAuthEventModule; - if (db_get(hContact, MODULENAME, "AuthEvent", &_dbv) == 0) { - DBEVENTINFO dbei2 = {}; - dbei2.cbBlob = *(uint32_t *)_dbv.pbVal; - dbei2.eventType = EVENTTYPE_AUTHREQUEST; - _getCOptS(AuthEventModule, 100, hContact, "AuthEventModule", L"ICQ"); - szAuthEventModule = mir_u2a(AuthEventModule); - dbei2.szModule = szAuthEventModule; - dbei2.timestamp = dbei->timestamp; - dbei2.pBlob = (char*)_dbv.pbVal + sizeof(uint32_t); - db_event_add(hContact, &dbei2); - - g_plugin.delSetting(hContact, "AuthEvent"); - g_plugin.delSetting(hContact, "AuthEventPending"); - g_plugin.delSetting(hContact, "AuthEventModule"); - mir_free(szAuthEventModule); - - db_free(&_dbv); - } - } - - // User approved, learn from previous messages - if (bayesEnabled && g_plugin.getByte("BayesAutolearnApproved", defaultBayesAutolearnApproved)) - bayes_approve_contact(hContact); - - // Mark previous messages unread if option set - if (g_plugin.getByte("KeepBlockedMsg", defaultKeepBlockedMsg) && - g_plugin.getByte("MarkMsgUnreadOnApproval", defaultMarkMsgUnreadOnApproval) && - hContact != NULL) { - // We will mark unread all blocked messages for the most recent day - MarkUnread(hContact); - } - - return 1; - } - - - - /*** Check for rejection ***/ - - // Completely reject if challenge was already sent today for MaxMsgContactCountPerDay times - // and the option is turned on. - if (isOneDay(dbei->timestamp, g_plugin.getDword(hContact, "MsgSentTime", 0)) && - g_plugin.getDword("MaxMsgContactCountPerDay", defaultMaxMsgContactCountPerDay) > 0 && - g_plugin.getDword(hContact, "MsgSent", 0) >= g_plugin.getDword("MaxMsgContactCountPerDay", defaultMaxMsgContactCountPerDay)) { - _notify(hContact, POPUP_BLOCKED, TranslateT("Message from %s rejected because it reached a maximum for challenge requests per day."), message); - if (bayesEnabled) - queue_message(hContact, dbei->timestamp, message); - return 1; - } - - // Completely reject if duplicate incoming message found - if (g_plugin.getDword("MaxSameMsgCountPerDay", defaultMaxSameMsgCountPerDay) > 0 && - g_plugin.getDword(hContact, "SameMsgCount", 0) >= g_plugin.getDword("MaxSameMsgCountPerDay", defaultMaxSameMsgCountPerDay) && - mir_wstrcmp(message, _getCOptS(buf, buflen, hContact, "LastInMsg", L"")) == 0) { - _notify(hContact, POPUP_BLOCKED, TranslateT("Message from %s rejected because it reached a maximum for same responses per day."), message); - if (bayesEnabled) - queue_message(hContact, dbei->timestamp, message); - return 1; - } - - // Completely reject if incoming message contains any word from DontReplyMsgWordlist option - if (g_plugin.getByte("DontReplyMsg", defaultDontReplyMsg) && - Contains(message, _getOptS(buf, buflen, "DontReplyMsgWordlist", defaultDontReplyMsgWordlist))) { - _notify(hContact, POPUP_BLOCKED, TranslateT("Message from %s dropped because it has a word from black list."), message); - return 1; - } - - - /*** Bayes checks ***/ - - // Drop if score > spam score - if (bayesEnabled && g_plugin.getByte("BayesBlockMsg", defaultBayesBlockMsg)) - if (get_msg_score(message) >= (double)g_plugin.getDword("BayesSpamScore", defaultBayesSpamScore) * SCORE_C) { - _notify(hContact, POPUP_BLOCKED, TranslateT("Message from %s dropped because of high spam score."), message); - if (bayesEnabled && g_plugin.getByte("BayesAutolearnNotApproved", defaultBayesAutolearnNotApproved)) - queue_message(hContact, dbei->timestamp, message); - return 1; - } - - // Accept if score < ham score - if (bayesEnabled && g_plugin.getByte("BayesAutoApprove", defaultBayesAutoApprove)) - if (get_msg_score(message) <= (double)g_plugin.getDword("BayesHamScore", defaultBayesHamScore) * SCORE_C) { - _notify(hContact, POPUP_APPROVED, TranslateT("Contact %s approved."), message); - g_plugin.setByte(hContact, "Verified", 1); - if (g_plugin.getByte("HideUnverified", defaultHideUnverified)) - Contact::Hide(hContact, false); - if (g_plugin.getByte("AddPermanently", defaultAddPermanently)) - Contact::PutOnList(hContact); - db_unset(hContact, "CList", "Delete"); - if (bayesEnabled && - g_plugin.getByte("BayesAutolearnApproved", defaultBayesAutolearnApproved) && - g_plugin.getByte("BayesAutolearnAutoApproved", defaultBayesAutolearnAutoApproved)) { - queue_message(hContact, dbei->timestamp, message); - bayes_approve_contact(hContact); - } - return 0; - } - - // Accept if event is EVENTTYPE_AUTHREQUEST and ReplyOnAuth is NOT set - if (dbei->eventType == EVENTTYPE_AUTHREQUEST && !g_plugin.getByte("ReplyOnAuth", defaultReplyOnAuth)) - return 0; - // Accept if event is EVENTTYPE_MESSAGE and ReplyOnMsg is NOT set - if (dbei->eventType == EVENTTYPE_MESSAGE && !g_plugin.getByte("ReplyOnMsg", defaultReplyOnMsg)) - return 0; - - /*** Send Challenge ***/ - - challengeW = (wchar_t *)malloc(maxmsglen * sizeof(wchar_t)); - tmpW = (wchar_t *)malloc(maxmsglen * sizeof(wchar_t)); - switch (g_plugin.getByte("Mode", defaultMode)) { - case SPAMOTRON_MODE_PLAIN: - if (dbei->eventType == EVENTTYPE_AUTHREQUEST) - _getOptS(challengeW, maxmsglen, "AuthChallenge", defaultAuthChallenge); - else - _getOptS(challengeW, maxmsglen, "Challenge", defaultChallenge); - ReplaceVars(challengeW, maxmsglen); - ProtoChainSend(hContact, PSS_MESSAGE, 0, T2Utf(challengeW)); - _notify(hContact, POPUP_CHALLENGE, TranslateT("Sending plain challenge to %s."), message); - break; - - case SPAMOTRON_MODE_ROTATE: - if (dbei->eventType == EVENTTYPE_AUTHREQUEST) - _getOptS(challengeW, maxmsglen, "AuthChallenge", defaultAuthChallenge); - else - _getOptS(challengeW, maxmsglen, "Challenge", defaultChallenge); - _getOptS(buf, buflen, "Response", defaultResponse); - if (g_plugin.getDword(hContact, "ResponseNum", 0) >= (unsigned int)(get_response_num(buf) - 1)) - g_plugin.setDword(hContact, "ResponseNum", -1); - - g_plugin.setDword(hContact, "ResponseNum", g_plugin.getDword(hContact, "ResponseNum", -1) + 1); - ReplaceVarsNum(challengeW, maxmsglen, g_plugin.getDword(hContact, "ResponseNum", 0)); - ProtoChainSend(hContact, PSS_MESSAGE, 0, T2Utf(challengeW)); - _notify(hContact, POPUP_CHALLENGE, TranslateT("Sending round-robin challenge to %s."), message); - break; - - case SPAMOTRON_MODE_RANDOM: - if (dbei->eventType == EVENTTYPE_AUTHREQUEST) - _getOptS(challengeW, maxmsglen, "AuthChallenge", defaultAuthChallenge); - else - _getOptS(challengeW, maxmsglen, "Challenge", defaultChallenge); - _getOptS(buf, buflen, "Response", defaultResponse); - srand(time(0)); - g_plugin.setDword(hContact, "ResponseNum", rand() % get_response_num(buf)); - ReplaceVarsNum(challengeW, maxmsglen, g_plugin.getDword(hContact, "ResponseNum", 0)); - ProtoChainSend(hContact, PSS_MESSAGE, 0, T2Utf(challengeW)); - _notify(hContact, POPUP_CHALLENGE, TranslateT("Sending random challenge to %s."), message); - break; - - case SPAMOTRON_MODE_MATH: - a = (rand() % 10) + 1; - b = (rand() % 10) + 1; - mir_snwprintf(mexpr, L"%d + %d", a, b); - if (dbei->eventType == EVENTTYPE_AUTHREQUEST) - _getOptS(challengeW, maxmsglen, "AuthChallengeMath", defaultAuthChallengeMath); - else - _getOptS(challengeW, maxmsglen, "ChallengeMath", defaultChallengeMath); - ReplaceVar(challengeW, maxmsglen, L"%mathexpr%", mexpr); - g_plugin.setDword(hContact, "ResponseMath", a + b); - ProtoChainSend(hContact, PSS_MESSAGE, 0, T2Utf(challengeW)); - _notify(hContact, POPUP_CHALLENGE, TranslateT("Sending math expression challenge to %s."), message); - break; - } - free(challengeW); - free(tmpW); - - // As a workaround for temporary NotOnList contact not being deleted from server-side list - // (which was added by the ICQ server itself upon first outgoing challenge request message) - // we need to set Delete setting, so that contacts gets deleted on next restart/connect. - db_set_b(hContact, "CList", "Delete", 1); - - // Queue user message in Bayes db - if (bayesEnabled && message != nullptr) - queue_message(hContact, dbei->timestamp, message); - - - /*** Do any post-send procedures we need to do ***/ - - // Increment MsgSent if it was sent the same day. Otherwise set it to 1. - if (isOneDay(dbei->timestamp, g_plugin.getDword(hContact, "MsgSentTime", 0))) - g_plugin.setDword(hContact, "MsgSent", g_plugin.getDword(hContact, "MsgSent", 0) + 1); - else - g_plugin.setDword(hContact, "MsgSent", 1); - g_plugin.setDword(hContact, "MsgSentTime", dbei->timestamp); - - // Save Last Msg and update SameMsgCount - if (message != nullptr) { - if (mir_wstrcmp(_getCOptS(buf, buflen, hContact, "LastInMsg", L""), message) == 0) - g_plugin.setDword(hContact, "SameMsgCount", 1 + g_plugin.getDword(hContact, "SameMsgCount", 0)); - else - g_plugin.setDword(hContact, "SameMsgCount", 1); - g_plugin.setWString(hContact, "LastInMsg", message); - } - - if (message != nullptr) - mir_free(message); - - // Finally silently save the message to contact history if corresponding option is set - if (g_plugin.getByte("KeepBlockedMsg", defaultKeepBlockedMsg)) { - if (dbei->eventType == EVENTTYPE_AUTHREQUEST) { - // Save the request to database so that it can be automatically submitted on user approval - uint8_t *eventdata = (uint8_t*)malloc(sizeof(uint32_t) + dbei->cbBlob); - if (eventdata != nullptr && dbei->cbBlob > 0) { - memcpy(eventdata, &dbei->cbBlob, sizeof(uint32_t)); - memcpy(eventdata + sizeof(uint32_t), dbei->pBlob, dbei->cbBlob); - db_set_blob(hContact, MODULENAME, "AuthEvent", eventdata, sizeof(uint32_t) + dbei->cbBlob); - g_plugin.setString(hContact, "AuthEventModule", dbei->szModule); - g_plugin.setByte(hContact, "AuthEventPending", TRUE); - free(eventdata); - } - } - else { - if (g_plugin.getByte("MarkMsgUnreadOnApproval", defaultMarkMsgUnreadOnApproval)) { - DBVARIANT _dbv; - uint32_t dbei_size = 3 * sizeof(uint32_t) + sizeof(uint16_t) + dbei->cbBlob + (uint32_t)mir_strlen(dbei->szModule) + 1; - uint8_t *eventdata = (uint8_t*)malloc(dbei_size); - uint8_t *pos = eventdata; - if (eventdata != nullptr && dbei->cbBlob > 0) { - if (db_get(hContact, MODULENAME, "LastMsgEvents", &_dbv) == 0) { - eventdata = (uint8_t*)realloc(eventdata, dbei_size + _dbv.cpbVal); - pos = eventdata; - memcpy(eventdata, _dbv.pbVal, _dbv.cpbVal); - pos += _dbv.cpbVal; - db_free(&_dbv); - } - memcpy(pos, &dbei->eventType, sizeof(uint16_t)); - memcpy(pos + sizeof(uint16_t), &dbei->flags, sizeof(uint32_t)); - memcpy(pos + sizeof(uint16_t) + sizeof(uint32_t), &dbei->timestamp, sizeof(uint32_t)); - memcpy(pos + sizeof(uint16_t) + sizeof(uint32_t) * 2, dbei->szModule, mir_strlen(dbei->szModule) + 1); - memcpy(pos + sizeof(uint16_t) + sizeof(uint32_t) * 2 + mir_strlen(dbei->szModule) + 1, &dbei->cbBlob, sizeof(uint32_t)); - memcpy(pos + sizeof(uint16_t) + sizeof(uint32_t) * 3 + mir_strlen(dbei->szModule) + 1, dbei->pBlob, dbei->cbBlob); - db_set_blob(hContact, MODULENAME, "LastMsgEvents", eventdata, (pos - eventdata) + dbei_size); - free(eventdata); - } - - } - else { - dbei->flags |= DBEF_READ; - db_event_add(hContact, dbei); - } - } - } - return 1; -} - -/* Removes NotOnList settings from contacts with Delete setting present */ -void RemoveNotOnListSettings() -{ - DBVARIANT dbv; - char protoName[256] = { 0 }; - mir_strcpy(protoName, "proto_"); - for (auto &hContact : Contacts()) { - if (db_get_s(hContact, "Protocol", "p", &dbv) == 0) { - mir_strcat(protoName, dbv.pszVal); - if (g_plugin.getByte(protoName, 0) != 0) { - if (db_get_b(hContact, "CList", "Delete", 0) == 1) { - Contact::PutOnList(hContact); - } - } - db_free(&dbv); - } - protoName[6] = 0; - } -} - -///////////////////////////////////////////////////////////////////////////////////////// - -int CMPlugin::Load() -{ - srand((unsigned)time(0)); - bayesdb = nullptr; - if (g_plugin.getByte("BayesEnabled", defaultBayesEnabled)) { - if (CheckBayes()) { - OpenBayes(); - if (g_plugin.getByte("BayesAutolearnNotApproved", defaultBayesAutolearnNotApproved)) { - dequeue_messages(); - last_queue_check = time(0); - } - } - } - - HookEvent(ME_DB_EVENT_FILTER_ADD, OnDBEventFilterAdd); - HookEvent(ME_OPT_INITIALISE, OnOptInitialize); - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// - -int CMPlugin::Unload() -{ - RemoveNotOnListSettings(); - return 0; -} diff --git a/plugins/Spamotron/src/stdafx.cxx b/plugins/Spamotron/src/stdafx.cxx deleted file mode 100644 index 13f28e1314..0000000000 --- a/plugins/Spamotron/src/stdafx.cxx +++ /dev/null @@ -1,18 +0,0 @@ -/* -Copyright (C) 2012-24 Miranda NG team (https://miranda-ng.org) - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation version 2 -of the License. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program. If not, see . -*/ - -#include "stdafx.h" \ No newline at end of file diff --git a/plugins/Spamotron/src/stdafx.h b/plugins/Spamotron/src/stdafx.h deleted file mode 100644 index d51269ee37..0000000000 --- a/plugins/Spamotron/src/stdafx.h +++ /dev/null @@ -1,150 +0,0 @@ -#pragma once - -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "resource.h" -#include "version.h" - -#define MODULENAME "Spam-o-tron" - -#define SPAMOTRON_MODE_PLAIN 0 -#define SPAMOTRON_MODE_MATH 1 -#define SPAMOTRON_MODE_ROTATE 2 -#define SPAMOTRON_MODE_RANDOM 3 - -#define MAX_BUFFER_LENGTH 1024 - -wchar_t* _getCOptS(wchar_t *buf, unsigned int buflen, MCONTACT hContact, const char* option, const wchar_t *def); -#define _getOptS(a,b,c,d) _getCOptS(a, b, NULL, c, d) - -#define defaultMode SPAMOTRON_MODE_PLAIN -#define defaultChallenge TranslateT("Spam-o-tron needs to verify you're not a bot. Reply with \"%response%\" without quotes.") -#define defaultChallengeMath TranslateT("Spam-o-tron needs to verify you're not a bot. Reply with a result of expression %mathexpr%.") -#define defaultResponse L"no-spam" -#define defaultResponseCC TRUE -#define defaultSuccessResponse TranslateT("Verified.") -#define defaultAuthChallenge TranslateT("Spam-o-tron delayed authorization request. First reply with \"%response%\" without quotes.") -#define defaultAuthChallengeMath TranslateT("Spam-o-tron delayed authorization request. First reply with a result of expression %mathexpr%.") -#define defaultReplyOnSuccess TRUE -#define defaultReplyOnAuth TRUE -#define defaultReplyOnMsg TRUE -#define defaultApproveOnMsgOut TRUE -#define defaultApproveOnMsgIn FALSE -#define defaultAddPermanently FALSE -#define defaultHideUnverified TRUE -#define defaultKeepBlockedMsg TRUE -#define defaultMarkMsgUnreadOnApproval FALSE -#define defaultLogActions TRUE -#define defaultNotifyPopup FALSE -#define defaultDontReplySameMsg TRUE -#define defaultDontReplyMsg TRUE -#define defaultApproveOnMsgInWordlist L"" -#define defaultDontReplyMsgWordlist L"Spam-o-tron, StopSpam, Anti-Spam" -#define defaultMaxMsgContactCountPerDay 3 -#define defaultMaxSameMsgCountPerDay 2 - -#define defaultNotifyPopupBlocked TRUE -#define defaultNotifyPopupApproved TRUE -#define defaultNotifyPopupChallenge TRUE -#define defaultPopupDefaultColors FALSE -#define defaultPopupWindowsColors FALSE -#define defaultPopupDefaultTimeout TRUE -#define defaultPopupBlockedTimeout 2 -#define defaultPopupApprovedTimeout 2 -#define defaultPopupChallengeTimeout 2 -#define defaultPopupBlockedForeground RGB(0, 0, 0) -#define defaultPopupBlockedBackground RGB(240, 128, 128) -#define defaultPopupApprovedForeground RGB(0, 0, 0) -#define defaultPopupApprovedBackground RGB(128, 240, 128) -#define defaultPopupChallengeForeground RGB(0, 0, 0) -#define defaultPopupChallengeBackground RGB(180, 210, 240) - -#define _NOTIFYP g_plugin.getByte("NotifyPopup", defaultNotifyPopup) - -wchar_t* ReplaceVars(wchar_t *dst, unsigned int len); -wchar_t* ReplaceVarsNum(wchar_t *dst, unsigned int len, int num); -wchar_t* ReplaceVar(wchar_t *dst, unsigned int len, const wchar_t *var, const wchar_t *rvar); -int get_response_id(const wchar_t *strvar); -int get_response_num(const wchar_t *str); -wchar_t* get_response(wchar_t* dst, unsigned int dstlen, int num); - -wchar_t* _tcsstr_cc(wchar_t* str, wchar_t* strSearch, BOOL cc); -BOOL _isregex(wchar_t* strSearch); -BOOL _isvalidregex(wchar_t* strSearch); -BOOL _regmatch(wchar_t* str, wchar_t* strSearch); -BOOL Contains(wchar_t* dst, wchar_t* src); -BOOL isOneDay(uint32_t timestamp1, uint32_t timestamp2); -void MarkUnread(MCONTACT hContact); - -int ShowPopup(MCONTACT hContact, uint8_t popupType, wchar_t *line1, wchar_t *line2); -int ShowPopupPreview(HWND optDlg, uint8_t popupType, wchar_t *line1, wchar_t *line2); -int _notify(MCONTACT hContact, uint8_t type, wchar_t *message, wchar_t *origmessage); -int LogToSystemHistory(char *message, char *origmessage); -#define POPUP_DEFAULT 0 -#define POPUP_BLOCKED 1 -#define POPUP_APPROVED 2 -#define POPUP_CHALLENGE 3 - -/* bayes.c */ - -#include - -extern sqlite3 *bayesdb; -#define BAYESDB_PATH "spamotron" -#define BAYESDB_FILENAME "bayes.db" -#define defaultBayesEnabled TRUE -#define defaultBayesBlockMsg FALSE -#define defaultBayesAutoApprove FALSE -#define defaultBayesAutolearnApproved TRUE -#define defaultBayesAutolearnAutoApproved FALSE -#define defaultBayesAutolearnNotApproved TRUE -#define defaultBayesAutolearnOutgoing FALSE -#define defaultBayesWaitApprove 2 -#define SCORE_C 0.0001 -#define defaultBayesSpamScore 9500 -#define defaultBayesHamScore 500 -#define HAM 0 -#define SPAM 1 - -int OpenBayes(); -int CheckBayes(); -void learn(int type, wchar_t *msg); -void learn_ham(wchar_t *msg); -void learn_spam(wchar_t *msg); -int get_token_count(int type); -int get_msg_count(int type); -double get_msg_score(wchar_t *msg); -void queue_message(MCONTACT hContact, uint32_t msgtime, wchar_t *message); -void bayes_approve_contact(MCONTACT hContact); -void dequeue_messages(); - -struct CMPlugin : public PLUGIN -{ - CMPlugin(); - - int Load() override; - int Unload() override; -}; - -#ifdef _DEBUG -extern sqlite3 *bayesdbg; -#define BAYESDBG_FILENAME "bayes.dbg" -#endif diff --git a/plugins/Spamotron/src/utils.cpp b/plugins/Spamotron/src/utils.cpp deleted file mode 100644 index 3c17ff7dbb..0000000000 --- a/plugins/Spamotron/src/utils.cpp +++ /dev/null @@ -1,509 +0,0 @@ -#include "stdafx.h" -#include - - -wchar_t *_tcstolower(wchar_t *dst) -{ - if (dst == nullptr) - return nullptr; - - SIZE_T dst_len = mir_wstrlen(dst); - for (SIZE_T i = 0; i < dst_len; i ++) - dst[i] = towlower(dst[i]); - return dst; -} - -wchar_t *_tcstoupper(wchar_t *dst) -{ - if (dst == nullptr) - return nullptr; - - SIZE_T dst_len = mir_wstrlen(dst); - for (SIZE_T i = 0; i < dst_len; i ++) - dst[i] = towupper(dst[i]); - return dst; -} - -BOOL _isregex(wchar_t* strSearch) -{ - BOOL ret = FALSE; - pcre16 *re; - const char *error; - int erroroffs, rc; - wchar_t *regex; - wchar_t regex_parse[] = L"/(.*)/([igsm]*)"; - int ovector[9]; - - if (strSearch == nullptr) - return FALSE; - re = pcre16_compile(regex_parse, 0, &error, &erroroffs, nullptr); - if (re == nullptr) - return FALSE; - regex = mir_wstrdup(strSearch); - if (regex == nullptr) - goto err_out; - rc = pcre16_exec(re, nullptr, regex, (int)mir_wstrlen(regex), 0, 0, ovector, 9); - if (rc == 3) - ret = TRUE; - mir_free(regex); -err_out: - pcre16_free(re); - - return ret; -} - -BOOL _isvalidregex(wchar_t* strSearch) -{ - BOOL ret = FALSE; - pcre16 *re; - const char *error; - int erroroffs, rc; - wchar_t *regex, *regexp, *mod; - int opts = 0; - wchar_t regex_parse[] = L"/(.*)/([igsm]*)"; - int ovector[9]; - - if (strSearch == nullptr) - return FALSE; - re = pcre16_compile(regex_parse, 0, &error, &erroroffs, nullptr); - if (re == nullptr) - return FALSE; - regex = mir_wstrdup(strSearch); - if (regex == nullptr) { - pcre16_free(re); - return FALSE; - } - rc = pcre16_exec(re, nullptr, regex, (int)mir_wstrlen(regex), 0, 0, ovector, 9); - pcre16_free(re); - if (rc != 3) - goto err_out; - regexp = regex + ovector[2]; - regexp[ovector[3] - ovector[2]] = 0; - mod = regex + ovector[4]; - mod[ovector[5] - ovector[4]] = 0; - - if (wcsstr(mod, L"i")) - opts |= PCRE_CASELESS; - if (wcsstr(mod, L"m")) - opts |= PCRE_MULTILINE; - if (wcsstr(mod, L"s")) - opts |= PCRE_DOTALL; - - re = pcre16_compile(regexp, opts, &error, &erroroffs, nullptr); - if (re != nullptr) { - pcre16_free(re); - ret = TRUE; - } -err_out: - mir_free(regex); - - return ret; -} - -BOOL _regmatch(wchar_t* str, wchar_t* strSearch) -{ - BOOL ret = FALSE; - pcre16 *re; - const char *error; - int erroroffs, rc; - wchar_t *regex, *regexp, *data = nullptr, *mod; - int opts = 0; - wchar_t regex_parse[] = L"^/(.*)/([igsm]*)"; - int ovector[9]; - - if (str == nullptr || strSearch == nullptr) - return FALSE; - re = pcre16_compile(regex_parse, 0, &error, &erroroffs, nullptr); - if (re == nullptr) - return FALSE; // [TODO] and log some error - regex = mir_wstrdup(strSearch); - if (regex == nullptr) { - pcre16_free(re); - return FALSE; - } - rc = pcre16_exec(re, nullptr, regex, (int)mir_wstrlen(regex), 0, 0, ovector, 9); - pcre16_free(re); - if (rc != 3) - goto err_out; // [TODO] and log some error (better check for valid regex on options save) - regexp = regex + ovector[2]; - regexp[ovector[3] - ovector[2]] = 0; - mod = regex + ovector[4]; - mod[ovector[5] - ovector[4]] = 0; - - data = mir_wstrdup(str); - if (data == nullptr) - goto err_out; - if (wcsstr(mod, L"i")) - opts |= PCRE_CASELESS; - if (wcsstr(mod, L"m")) - opts |= PCRE_MULTILINE; - if (wcsstr(mod, L"s")) - opts |= PCRE_DOTALL; - - re = pcre16_compile(regexp, opts, &error, &erroroffs, nullptr); - if (re == nullptr) - goto err_out; - rc = pcre16_exec(re, nullptr, data, (int)mir_wstrlen(data), 0, 0, nullptr, 0); - pcre16_free(re); - if (rc >= 0) - ret = TRUE; -err_out: - mir_free(regex); - mir_free(data); - - return ret; -} - -int get_response_id(const wchar_t* strvar) -{ - int ret = 0; - pcre16 *re; - const char *error; - int erroroffs, rc; - wchar_t *_str, *_strvar; - wchar_t regex[] = L"^%response([#-_]([0-9]+))?%$"; - int ovector[9]; - - if (strvar == nullptr) - return 0; - re = pcre16_compile(regex, 0, &error, &erroroffs, nullptr); - if (re == nullptr) - return 0; // [TODO] and log some error - _strvar = mir_wstrdup(strvar); - if (_strvar == nullptr) { - pcre16_free(re); - return 0; - } - rc = pcre16_exec(re, nullptr, _strvar, (int)mir_wstrlen(_strvar), 0, 0, ovector, 9); - pcre16_free(re); - if (rc < 0) { - ret = -1; - } else if (rc == 3) { - _str = _strvar + ovector[4]; - _str[ovector[5] - ovector[4]] = 0; - ret = _wtoi(_str); - } - mir_free(_strvar); - - return ret; -} - -int get_response_num(const wchar_t *str) -{ - int i = 0; - wchar_t *tmp, *strc; - - if (str == nullptr) - return 0; - strc = mir_wstrdup(str); - if (strc == nullptr) - return 0; - tmp = wcstok(strc, L"\r\n"); - while (tmp) { - i ++; - tmp = wcstok(nullptr, L"\r\n"); /* Move next. */ - } - mir_free(strc); - - return i; -} - -wchar_t* get_response(wchar_t* dst, unsigned int dstlen, int num) -{ - int i = 0; - wchar_t *tmp, *src; - - if (dst == nullptr || dstlen == 0 || num < 0) - return dst; - src = (wchar_t*)mir_alloc(MAX_BUFFER_LENGTH * sizeof(wchar_t)); - if (src == nullptr) - goto err_out; - _getOptS(src, MAX_BUFFER_LENGTH, "Response", defaultResponse); - tmp = wcstok(src, L"\r\n"); - while (tmp) { - if (i == num) { - mir_wstrcpy(dst, tmp); - mir_free(src); - return dst; - } - i ++; - tmp = wcstok(nullptr, L"\r\n"); /* Move next. */ - } - mir_free(src); -err_out: - dst[0] = 0; - return dst; -} - -wchar_t* _tcsstr_cc(wchar_t* str, wchar_t* strSearch, BOOL cc) -{ - wchar_t *ret = nullptr, *_str = nullptr, *_strSearch = nullptr; - - if (cc) - return wcsstr(str, strSearch); - - _str = mir_wstrdup(str); - if (_str == nullptr) - goto err_out; - _strSearch = mir_wstrdup(strSearch); - if (_strSearch == nullptr) - goto err_out; - ret = wcsstr(_tcstolower(_str), _tcstolower(_strSearch)); - if (ret != nullptr) - ret = ((ret - _str) + str); -err_out: - mir_free(_str); - mir_free(_strSearch); - - return ret; -} - -BOOL Contains(wchar_t* dst, wchar_t* src) // Checks for occurence of substring from src in dst -{ - BOOL ret = FALSE; - wchar_t *tsrc = nullptr, *tdst = nullptr, *token, *token_end; - SIZE_T dst_len; - - if (dst == nullptr || src == nullptr) - return FALSE; - tsrc = mir_wstrdup(src); - if (tsrc == nullptr) - goto err_out; - tdst = mir_wstrdup(dst); - if (tdst == nullptr) - goto err_out; - tdst = _tcstoupper(tdst); - dst_len = mir_wstrlen(tdst); - token = wcstok(tsrc, L","); - while (token) { - token_end = (token + mir_wstrlen(token)); - while (!wcsncmp(token, L" ", 1)) { /* Skeep spaces at start. */ - token ++; - } - /* Skeep spaces at end. */ - while (token > token_end && wcschr((token_end - 1), ' ')) { - token_end --; - token_end[0] = 0; - } - /* Compare. */ - if (dst_len == (token_end - token) && - 0 == memcmp(tdst, _tcstoupper(token), (dst_len * sizeof(wchar_t)))) { - ret = TRUE; - break; - } - token = wcstok(nullptr, L","); /* Move next. */ - } -err_out: - mir_free(tsrc); - mir_free(tdst); - return ret; -} - -BOOL isOneDay(uint32_t timestamp1, uint32_t timestamp2) -{ - time_t t1, t2; - int at1[3], at2[3]; - struct tm *tm; - if (!timestamp1 || !timestamp2) - return FALSE; - t1 = (time_t)timestamp1; - t2 = (time_t)timestamp2; - tm = gmtime(&t1); - at1[0] = tm->tm_mday; - at1[1] = tm->tm_mon; - at1[2] = tm->tm_year; - tm = gmtime(&t2); - at2[0] = tm->tm_mday; - at2[1] = tm->tm_mon; - at2[2] = tm->tm_year; - if (memcmp(&at1, &at2, 3*sizeof(int)) == 0) - return TRUE; - return FALSE; -} - -wchar_t* ReplaceVar(wchar_t *dst, unsigned int len, const wchar_t *var, const wchar_t *rvar) -{ - wchar_t *var_start; - SIZE_T dst_len, var_len, rvar_len; - - if (dst == nullptr || var == nullptr || rvar == nullptr) - return nullptr; - dst_len = mir_wstrlen(dst); - var_len = mir_wstrlen(var); - rvar_len = mir_wstrlen(rvar); - var_start = wcsstr(dst, var); - while (var_start) { - if (len < (dst_len + rvar_len - var_len + 1)) - return nullptr; /* Out of buf space. */ - memmove((var_start + rvar_len), - (var_start + var_len), - (((dst + dst_len + 1) - (var_start + var_len)) * sizeof(wchar_t))); - if (var_len >= rvar_len) { /* Buf data size not changed or decreased. */ - dst_len -= (var_len - rvar_len); - } else { /* Buf data size increased. */ - dst_len += (rvar_len - var_len); - } - memcpy(var_start, rvar, (rvar_len * sizeof(wchar_t))); - var_start = wcsstr(dst, var); /* Move next. */ - } - - return dst; -} - -wchar_t* ReplaceVars(wchar_t *dst, unsigned int len) -{ - return ReplaceVarsNum(dst, len, -1); -} - -wchar_t* ReplaceVarsNum(wchar_t *dst, unsigned int len, int num) -{ - wchar_t response[MAX_BUFFER_LENGTH]; - int ret, i; - pcre16 *re; - const char *error; - int erroroffs, rc; - wchar_t *_str, *tmp, **r = nullptr, **tr, *ttmp, *dstcopy; - wchar_t regex[] = L"%response([#-_]([0-9]+))?%"; - int ovector[9]; - - re = pcre16_compile(regex, 0, &error, &erroroffs, nullptr); - if (re == nullptr) - return FALSE; // [TODO] and log some error - _getOptS(response, _countof(response), "Response", defaultResponse); - - ttmp = wcstok(response, L"\r\n"); - for (i = 0; ttmp != nullptr; i ++) { - tr = (wchar_t**)mir_realloc(r, ((i + 1) * sizeof(wchar_t*))); - if (tr == nullptr) - goto err_out; - r = tr; - r[i] = ttmp; - ttmp = wcstok(nullptr, L"\r\n"); /* Move next. */ - } - - do { - _str = mir_wstrdup(dst); - dstcopy = mir_wstrdup(dst); - if (_str == nullptr || dstcopy == nullptr) { - mir_free(_str); - mir_free(dstcopy); - goto err_out; - } - rc = pcre16_exec(re, nullptr, _str, (int)mir_wstrlen(_str), 0, 0, ovector, 9); - if (rc < 0) { - ret = -1; - } else if (rc == 3) { - ttmp = dstcopy + ovector[0]; - ttmp[ovector[1] - ovector[0]] = 0; - tmp = _str + ovector[4]; - tmp[ovector[5] - ovector[4]] = 0; - ret = _wtoi(tmp); - } else { - ttmp = dstcopy + ovector[0]; - ttmp[ovector[1] - ovector[0]] = 0; - ret = 0; - } - - if (ret >= 0) { - if (ret > i) - ReplaceVar(dst, len, ttmp, r[0]); - else if (ret == 0 && num > 0 && num < i) - ReplaceVar(dst, len, ttmp, r[num]); - else - ReplaceVar(dst, len, ttmp, r[ret == 0 ? 0 : (ret - 1)]); - } - - mir_free(_str); - mir_free(dstcopy); - } while (rc >= 0); -err_out: - mir_free(r); - pcre16_free(re); - - return dst; -} - -int _notify(MCONTACT hContact, uint8_t type, wchar_t *message, wchar_t *origmessage) -{ - char *tmp, *tmporig; - wchar_t msg[MAX_BUFFER_LENGTH]; - mir_snwprintf(msg, message, Clist_GetContactDisplayName(hContact)); - - if (g_plugin.getByte("LogActions", defaultLogActions)) { - tmp = mir_u2a(msg); - tmporig = mir_u2a(origmessage); - LogToSystemHistory(tmp, origmessage ? tmporig : nullptr); - mir_free(tmp); - mir_free(tmporig); - } - - if (_NOTIFYP) { - if (type == POPUP_BLOCKED) { - if (g_plugin.getByte("NotifyPopupBlocked", defaultNotifyPopupBlocked)) - ShowPopup(hContact, type, nullptr, msg); - } else if (type == POPUP_APPROVED) { - if (g_plugin.getByte("NotifyPopupApproved", defaultNotifyPopupApproved)) - ShowPopup(hContact, type, nullptr, msg); - } else if (type == POPUP_CHALLENGE) { - if (g_plugin.getByte("NotifyPopupChallenge", defaultNotifyPopupChallenge)) - ShowPopup(hContact, type, nullptr, msg); - } else { - ShowPopup(hContact, type, nullptr, msg); - } - } - return 0; -} -#define DOT(a) (a[mir_strlen(a)-1] == 46) ? "" : "." -int LogToSystemHistory(char *message, char *origmessage) -{ - char msg[MAX_BUFFER_LENGTH]; - time_t tm; - - if (message == nullptr) - return 0; - - DBEVENTINFO dbei = {}; - dbei.timestamp = time(&tm); - dbei.szModule = MODULENAME; - dbei.pBlob = msg; - if (origmessage) - dbei.cbBlob = (1 + mir_snprintf(msg, "%s: %s%s %s: %s", MODULENAME, message, DOT(message), Translate("Their message was"), origmessage)); - else - dbei.cbBlob = (1 + mir_snprintf(msg, "%s: %s%s", MODULENAME, message, DOT(message))); - dbei.eventType = EVENTTYPE_MESSAGE; - dbei.flags = DBEF_READ; - db_event_add(NULL, &dbei); - return 0; -} - -void MarkUnread(MCONTACT hContact) -{ - // We're not actually marking anything. We just pushing saved events to the database from a temporary location - DBVARIANT _dbv = {0}; - uint8_t *pos; - - if (hContact == NULL) - return; - - if (db_get(hContact, MODULENAME, "LastMsgEvents", &_dbv) == 0) { - pos = _dbv.pbVal; - while (pos - _dbv.pbVal < _dbv.cpbVal) { - DBEVENTINFO dbei = {}; - memcpy(&dbei.eventType, pos, sizeof(uint16_t)); pos += sizeof(uint16_t); - memcpy(&dbei.flags, pos, sizeof(uint32_t)); pos += sizeof(uint32_t); - memcpy(&dbei.timestamp, pos, sizeof(uint32_t)); pos += sizeof(uint32_t); - - dbei.szModule = (char*)malloc(mir_strlen((const char*)pos)+1); - mir_strcpy((char*)dbei.szModule, (const char*)pos); - pos += mir_strlen((const char*)pos)+1; - - memcpy(&dbei.cbBlob, pos, sizeof(uint32_t)); pos += sizeof(uint32_t); - dbei.pBlob = (char *)malloc(dbei.cbBlob); - memcpy(dbei.pBlob, pos, dbei.cbBlob); - pos += dbei.cbBlob; - db_event_add(hContact,&dbei); - } - db_free(&_dbv); - g_plugin.delSetting(hContact, "LastMsgEvents"); - } -} diff --git a/plugins/Spamotron/src/version.h b/plugins/Spamotron/src/version.h deleted file mode 100644 index 839fa586b5..0000000000 --- a/plugins/Spamotron/src/version.h +++ /dev/null @@ -1,13 +0,0 @@ -#define __MAJOR_VERSION 0 -#define __MINOR_VERSION 0 -#define __RELEASE_NUM 4 -#define __BUILD_NUM 7 - -#include - -#define __PLUGIN_NAME "Spam-o-tron" -#define __FILENAME "Spamotron.dll" -#define __DESCRIPTION "Anti-spam plugin with captcha and Bayes filtering." -#define __AUTHOR "vu1tur" -#define __AUTHORWEB "https://miranda-ng.org/p/Spamotron" -#define __COPYRIGHT "© 2010 vu1tur" -- cgit v1.2.3