// started: 19.12.2006 #include "Mra.h" #include "MraAntiSpam.h" #include "MraRTFMsg.h" typedef struct { LPWSTR lpwszBadWord; DWORD dwBadWordLen; } MRA_ANTISPAM_BAD_WORD; static MRA_ANTISPAM_BAD_WORD *pmabwBadWords=NULL; static SIZE_T dwBadWordsCount=0; #define MRA_ANTISPAM_PREALLOC_COUNT 256 SIZE_T MraAntiSpamLoadBadWordsW() { SIZE_T dwRet=0; char szSettingName[MAX_PATH]; SIZE_T i=0,dwValueSize,dwAllocatedItemsCount=MRA_ANTISPAM_PREALLOC_COUNT; DBVARIANT dbv={0}; DBCONTACTGETSETTING sVal={0}; dbv.type=DBVT_WCHAR; sVal.pValue=&dbv; sVal.szModule=PROTOCOL_NAMEA; sVal.szSetting=szSettingName; if (pmabwBadWords || dwBadWordsCount) MraAntiSpamFreeBadWords(); pmabwBadWords=(MRA_ANTISPAM_BAD_WORD*)MEMALLOC((sizeof(MRA_ANTISPAM_BAD_WORD)*dwAllocatedItemsCount)); for(i=0;TRUE;i++) { mir_snprintf(szSettingName,SIZEOF(szSettingName),"AntiSpamBadWord %lu",i); dbv.type=DBVT_WCHAR; if (CallService(MS_DB_CONTACT_GETSETTING_STR,NULL,(LPARAM)&sVal)) { break; }else{ if (dwAllocatedItemsCount==i) { dwAllocatedItemsCount+=MRA_ANTISPAM_PREALLOC_COUNT; pmabwBadWords=(MRA_ANTISPAM_BAD_WORD*)MEMREALLOC(pmabwBadWords,(sizeof(MRA_ANTISPAM_BAD_WORD)*dwAllocatedItemsCount)); if (pmabwBadWords==NULL) break; } dwValueSize=lstrlenW(dbv.pwszVal); pmabwBadWords[i].lpwszBadWord=(LPWSTR)MEMALLOC((dwValueSize*sizeof(WCHAR))); if (pmabwBadWords[i].lpwszBadWord) {//BuffToLowerCase(szValue,dbv.pszVal,dwValueSize); memmove(pmabwBadWords[i].lpwszBadWord,dbv.pwszVal,(dwValueSize*sizeof(WCHAR))); CharLowerBuffW(pmabwBadWords[i].lpwszBadWord,dwValueSize); pmabwBadWords[i].dwBadWordLen=dwValueSize; } DBFreeVariant(&dbv); if (pmabwBadWords[i].lpwszBadWord==NULL) break; } } dwBadWordsCount=i; return(dwRet); } void MraAntiSpamFreeBadWords() { SIZE_T i; for(i=0;icode){ case PSN_APPLY: { char szSettingName[MAX_PATH]; WCHAR szBadWord[MAX_PATH]; SIZE_T i,dwCount; DBWriteContactSettingByte(NULL,PROTOCOL_NAMEA,"AntiSpamEnable",IS_DLG_BUTTON_CHECKED(hWndDlg,IDC_ENABLE)); DBWriteContactSettingByte(NULL,PROTOCOL_NAMEA,"AntiSpamCheckTempContacts",IS_DLG_BUTTON_CHECKED(hWndDlg,IDC_CHK_TEMP_CONTACTS)); DBWriteContactSettingByte(NULL,PROTOCOL_NAMEA,"AntiSpamDeteleSpamBotContacts",IS_DLG_BUTTON_CHECKED(hWndDlg,IDC_DELETE_SPAMBOT_CONTACT)); DBWriteContactSettingByte(NULL,PROTOCOL_NAMEA,"AntiSpamCleanNonAlphaNumeric",IS_DLG_BUTTON_CHECKED(hWndDlg,IDC_CLN_NON_ALPHNUM)); DB_Mra_SetDword(NULL,"AntiSpamMaxLangChanges",(DWORD)GetDlgItemInt(hWndDlg,IDC_MAX_LANG_CHANGES,NULL,FALSE)); DBWriteContactSettingByte(NULL,PROTOCOL_NAMEA,"AntiSpamShowPopUp",IS_DLG_BUTTON_CHECKED(hWndDlg,IDC_SHOWPOPUP)); DBWriteContactSettingByte(NULL,PROTOCOL_NAMEA,"AntiSpamWriteToSystemHistory",IS_DLG_BUTTON_CHECKED(hWndDlg,IDC_WRITETOSYSTEMHISTORY)); DBWriteContactSettingByte(NULL,PROTOCOL_NAMEA,"AntiSpamSendSpamReportToSrv",IS_DLG_BUTTON_CHECKED(hWndDlg,IDC_SEND_SPAM_REPORT_TO_SERVER)); dwCount=SEND_DLG_ITEM_MESSAGE(hWndDlg,IDC_BAD_WORDS_LIST,LB_GETCOUNT,0,0); for(i=0;i//?;:'\"\\][}{`-=~!@#$%^&*()_+№1234567890"; //lstrlenW(lpwszExceptedChars)=46 for(i=0;i<46;i++) { if (lpwszExceptedChars[i]==wcTestChar) { bRet=TRUE; break; } } return(bRet); } SIZE_T MraAntiSpamCalcLangChanges(LPWSTR lpwszMessage,SIZE_T dwMessageSize) { SIZE_T dwRet=0; if (lpwszMessage && dwMessageSize) { WCHAR wcPrevChar=0; SIZE_T i; for(i=1;i 255) { dwRet++; } wcPrevChar=lpwszMessage[i]; } } } return(dwRet); } SIZE_T MraAntiSpamCleanNonAlphaNumeric(LPWSTR lpwszMessage,SIZE_T dwMessageSize) { SIZE_T dwRet=0; if (lpwszMessage && dwMessageSize) { LPWSTR lpwszCurWritePos=lpwszMessage; SIZE_T i; for(i=0;i(SIZEOF(wszBuff)-(dwDBMessageSize+sizeof(DWORD)))) dwMessageSize=(SIZEOF(wszBuff)-(dwDBMessageSize+sizeof(DWORD))); memmove((wszBuff+dwDBMessageSize),lpwszMessage,(dwMessageSize*sizeof(WCHAR))); dwDBMessageSize+=dwMessageSize; (*((DWORD*)(wszBuff+dwDBMessageSize)))=0; dwDBMessageSize+=sizeof(DWORD); if (bAntiSpamShowPopUp) MraPopupShowFromAgentW(MRA_POPUP_TYPE_INFORMATION,0,wszBuff); if (bAntiSpamWriteToSystemHistory) { CHAR szBuff[MRA_MAXLENOFMESSAGE*2]; DBEVENTINFO dbei={0}; WideCharToMultiByte(CP_UTF8,0,wszBuff,dwDBMessageSize,szBuff,SIZEOF(szBuff),NULL,NULL); dbei.cbSize=sizeof(dbei); dbei.szModule=PROTOCOL_NAMEA; dbei.timestamp=_time32(NULL); dbei.flags=(DBEF_READ|DBEF_UTF); dbei.eventType=EVENTTYPE_MESSAGE; dbei.cbBlob=(dwDBMessageSize*sizeof(WCHAR)); dbei.pBlob=(PBYTE)szBuff; CallService(MS_DB_EVENT_ADD,0,(LPARAM)&dbei); } if (hContact && bAntiSpamDeteleSpamBotContacts) { dwDBMessageSize=mir_sntprintf(wszBuff,SIZEOF(wszBuff),L"%s: %S",TranslateW(L"Spam bot contact deleted"),szEMail); if (bAntiSpamShowPopUp) MraPopupShowFromAgentW(MRA_POPUP_TYPE_INFORMATION,0,wszBuff); if (bAntiSpamWriteToSystemHistory) { CHAR szBuff[MRA_MAXLENOFMESSAGE*2]; DBEVENTINFO dbei={0}; (*((DWORD*)(wszBuff+dwDBMessageSize)))=0; dwDBMessageSize+=sizeof(DWORD); WideCharToMultiByte(CP_UTF8,0,wszBuff,dwDBMessageSize,szBuff,SIZEOF(szBuff),NULL,NULL); dbei.cbSize=sizeof(dbei); dbei.szModule=PROTOCOL_NAMEA; dbei.timestamp=_time32(NULL); dbei.flags=(DBEF_READ|DBEF_UTF); dbei.eventType=EVENTTYPE_MESSAGE; dbei.cbBlob=(dwDBMessageSize*sizeof(WCHAR)); dbei.pBlob=(PBYTE)szBuff; CallService(MS_DB_EVENT_ADD,0,(LPARAM)&dbei); } } } if (hContact && bAntiSpamDeteleSpamBotContacts) CallService(MS_DB_CONTACT_DELETE,(WPARAM)hContact,0); } } return(dwRet); }