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
|
//---------------------------------------------------------------------------
#include <windows.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <newpluginapi.h>
#include <m_system.h>
#include <m_langpack.h>
#include <m_options.h>
#include "../../m_filterplugin.h"
#if !defined(_WIN64)
#include "aggressiveoptimize.h"
#endif
typedef INT_PTR(* MIRANDASERVICE)(WPARAM,LPARAM);
DWORD WINAPI FilterMail(HACCOUNT Account,DWORD AccountVer,HYAMNMAIL Mail,DWORD MailVer);//Function marks mail as spam when it is spam...
DWORD WINAPI UnLoadFilter(LPVOID);
YAMN_FILTERIMPORTFCN FilterFunctions= //we set for YAMN which is our filter function
{
FilterMail,
UnLoadFilter, //No unloading
};
YAMN_FILTERREGISTRATION FilterRegistration= //classical YAMN registration
{
"Simple filter plugin for YAMN",
__DATE__,
"© porter+ majvan",
"Classifies mails using the blacklist emails stored in file",
"porterbox@hotmail.com",
"http://www.majvan.host.sk/Projekty/YAMN?fm=soft",
};
char *FilterPath=NULL;
struct YAMNExportedFcn
{
YAMN_SETFILTERPLUGINFCNIMPORTFCN SetFilterPluginFcnImportFcn;
MIRANDASERVICE RegisterFilterPlugin;
} YAMNFcn,*pYAMNFcn; //exported functions from YAMN we will use
HYAMNFILTERPLUGIN POPFilePlugin; //handle of this plugin for YAMN
HINSTANCE hInst; //handle of this DLL for Windows
extern "C" BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fwdreason, LPVOID lpvReserved)
{
hInst=hinstDLL;
return true;
}
extern "C" int __declspec(dllexport) LoadFilter(MIRANDASERVICE GetYAMNFcnPtr)
{
FilterPath=new char[MAX_PATH];
char *delim;
pYAMNFcn=&YAMNFcn;
GetModuleFileName(GetModuleHandle(NULL),FilterPath,MAX_PATH);
if(NULL!=(delim=strrchr(FilterPath,'\\')))
*delim=0;
lstrcat(FilterPath,"\\simplefilterdeny.txt");
pYAMNFcn->RegisterFilterPlugin=(MIRANDASERVICE)GetYAMNFcnPtr((WPARAM)MS_YAMN_REGISTERFILTERPLUGIN,(LPARAM)0);
pYAMNFcn->SetFilterPluginFcnImportFcn=(YAMN_SETFILTERPLUGINFCNIMPORTFCN)GetYAMNFcnPtr((WPARAM)YAMN_SETFILTERPLUGINFCNIMPORTID,(LPARAM)0);
//Register our filter plugin to YAMN
if(NULL==(POPFilePlugin=(HYAMNFILTERPLUGIN)pYAMNFcn->RegisterFilterPlugin((WPARAM)&FilterRegistration,(LPARAM)YAMN_FILTERREGISTRATIONVERSION)))
return 0;
//And add our imported functions for YAMN
if(!pYAMNFcn->SetFilterPluginFcnImportFcn(POPFilePlugin,0xb0000000,&FilterFunctions,YAMN_FILTERIMPORTFCNVERSION))
return 0;
return 1; //Load luccess
}
DWORD WINAPI UnLoadFilter(LPVOID)
{
if(FilterPath!=NULL)
delete[] FilterPath;
FilterPath=NULL;
return 0;
}
extern "C" int __declspec(dllexport) UninstallFilter()
{
if(FilterPath==NULL)
MessageBox(NULL,"Cannot delete blacklist file when Simple Filter is not loaded. Please do it manually.","Simple Filter uninstalling",MB_OK|MB_ICONWARNING);
else
DeleteFile(FilterPath);
return 0;
}
//And this is main filter function.
DWORD WINAPI FilterMail(HACCOUNT Account,DWORD AccountVer,HYAMNMAIL Mail,DWORD MailVer)
{
FILE *fp;
char EmailSpam[256];
unsigned char spamLevel;
struct CMimeItem *Browser;
if(MailVer!=YAMN_MAILVERSION) //we test if we work with the right YAMNMAIL
return 0;
if(Mail->MailData==NULL) //MailData should be available
return 0;
fp=fopen(FilterPath,"rt");
if(fp != NULL) {
if(!(Mail->Flags & YAMN_MSG_VIRTUAL))
for(Browser=Mail->MailData->TranslatedHeader;Browser!=NULL;Browser=Browser->Next) { //we browse all header stored in Mail->TranslatedHeader
if((!lstrcmp(Browser->name,"Return-Path")) || (!lstrcmp(Browser->name,"From"))) { //and if we find
fseek(fp, 0L, SEEK_SET);
while(!feof(fp)) {
if(fscanf(fp, "%255s", EmailSpam) != 0) {
if(!feof(fp))
if(fscanf(fp, "%d", &spamLevel)==0)
spamLevel=2;
if(spamLevel>4)
spamLevel=2;
if(strstr(Browser->value,EmailSpam)!=NULL) {
if((Mail->Flags & (YAMN_MSG_SPAMMASK==0)) && (spamLevel==0))
Mail->Flags&=~(YAMN_MSG_SOUND | YAMN_MSG_APP | YAMN_MSG_POPUP | YAMN_MSG_SYSTRAY | YAMN_MSG_BROWSER);
else if((Mail->Flags & YAMN_MSG_SPAMMASK) < spamLevel) //if some filter plugin set higher level of spam, we do nothing
Mail->Flags=(Mail->Flags & ~YAMN_MSG_SPAMMASK)+spamLevel; //else we set spam level 2 (clearing spam bits and then settting them to level 2
}
}
}
}
}
fclose(fp);
}
return 1;
}
|