1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
#pragma once
#include <windows.h>
#include <commctrl.h>
#include <stdlib.h>
#include <time.h>
#include <newpluginapi.h>
#include <m_database.h>
#include <m_system.h>
#include <m_utils.h>
#include <m_clist.h>
#include <m_options.h>
#include <m_protocols.h>
#include <m_skin.h>
#include <m_popup.h>
#include <m_langpack.h>
#include <m_protosvc.h>
#include "m_folders.h"
#include "../../libs/pcre16/src/pcre.h"
#include "resource.h"
#include "version.h"
#define PLUGIN_NAME "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
#define _getCOptB(a,b,c) db_get_b(a, PLUGIN_NAME, b, c)
#define _setCOptB(a,b,c) db_set_b(a, PLUGIN_NAME, b, c)
#define _getCOptD(a,b,c) db_get_dw(a, PLUGIN_NAME, b, c)
#define _setCOptD(a,b,c) db_set_dw(a, PLUGIN_NAME, b, c)
#define _getOptB(a,b) _getCOptB(NULL, a, b)
#define _setOptB(a,b) _setCOptB(NULL, a, b)
#define _getOptD(a,b) _getCOptD(NULL, a, b)
#define _setOptD(a,b) _setCOptD(NULL, a, b)
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 _setCOptTS(a,b,c) db_set_ws(a, PLUGIN_NAME, b, c)
#define _setCOptS(a,b,c) db_set_s(a, PLUGIN_NAME, b, c)
#define _setOptTS(a,b) _setCOptTS(NULL, a, b)
#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 _getOptB("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(DWORD timestamp1, DWORD timestamp2);
void MarkUnread(MCONTACT hContact);
int ShowPopup(MCONTACT hContact, BYTE popupType, wchar_t *line1, wchar_t *line2);
int ShowPopupPreview(HWND optDlg, BYTE popupType, wchar_t *line1, wchar_t *line2);
int _notify(MCONTACT hContact, BYTE 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 "../../Libs/sqlite3/src/sqlite3.h"
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, DWORD msgtime, wchar_t *message);
void bayes_approve_contact(MCONTACT hContact);
void dequeue_messages();
#ifdef _DEBUG
extern sqlite3 *bayesdbg;
#define BAYESDBG_FILENAME "bayes.dbg"
#endif
|