-
Notifications
You must be signed in to change notification settings - Fork 0
/
wxMsGetMessageFilter.cpp
226 lines (220 loc) · 7.38 KB
/
wxMsGetMessageFilter.cpp
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*-----------------------------------------------------------------
* Name: wxMsGetMessageFilter.cpp
* Purpose:
* Author: A. Wiegert
*
* Copyright:
* Licence: wxWidgets licence
*---------------------------------------------------------------- */
/*----------------------------------------------------------------
* Standard wxWidgets headers
*---------------------------------------------------------------- */
// Note __VISUALC__ is defined by wxWidgets, not by MSVC IDE
// and thus won't be defined until some wxWidgets headers are included
#if defined( _MSC_VER )
# if defined ( _DEBUG )
// this statement NEEDS to go BEFORE all headers
# define _CRTDBG_MAP_ALLOC
# endif
#endif
#include "wxMsPreProcDefsh.h" // needs to be first
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
/* For all others, include the necessary headers
* (this file is usually all you need because it
* includes almost all "standard" wxWidgets headers) */
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
// ------------------------------------------------------------------
#include "wxMsFrameh.h"
#include "wxMsFilterDialogh.h"
#include <wx/colour.h>
#include <wx/tokenzr.h>
// ------------------------------------------------------------------
// Note __VISUALC__ is defined by wxWidgets, not by MSVC IDE // from Autohotkey-hummer.ahk
// and thus won't be defined until some wxWidgets headers are included
#if defined( _MSC_VER )
// this block needs to go AFTER all headers
#include <crtdbg.h>
# ifdef _DEBUG
# define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
# define new DEBUG_NEW
# endif
#endif
// ------------------------------------------------------------------
/**
* Apply the filters to a specific message line.
* Still needs 'bounce' & 'black list'???
*/
void MyFrame::GetMessageFilterStatus( long a_lIndex, std::list<MyPop3MsgElement>::iterator a_it,
bool& ar_bDelete, wxString& ar_wsStatus, wxString& ar_wsColor )
{
// set the defaults
ar_wsStatus = _T("Normal" );
ar_wsColor= g_iniPrefs.data[IE_STATUS_DEFAULT_COLOR].dataCurrent.wsVal;
int i = 0;
wxString wsAddr;
wxString wsFilterName;
wxString wsAction;
wxString wsSubject = a_it->m_wsSubject;
ar_bDelete = false;
bool bFirstToken;
wxUnusedVar( bFirstToken );
// get the 'action' token
for ( std::vector<MyFilterListEl>::iterator filterIt = wxGetApp().m_FilterList.begin();
filterIt != wxGetApp().m_FilterList.end(); ++filterIt, i++ )
{
wxString wsFilterName = filterIt->m_wsName;
wxString wsRuleText = filterIt->m_wsRuleText; // do NOT modify the rule string
wsRuleText = wsRuleText.MakeLower();
wsRuleText = _T("*") + wsRuleText + _T("*");
wsFilterName = wsFilterName.MakeLower();
bFirstToken = true;
wxStringTokenizer tokenizer( filterIt->m_wsAction, ",");
while ( tokenizer. HasMoreTokens() )
{
// we should only have one token per action
wxASSERT_MSG( bFirstToken, _("Too many 'action' tokens: ") + wsFilterName.MakeUpper() );
bFirstToken = false;
wxString token = tokenizer.GetNextToken();
if ( token.IsSameAs( _T("legit" ) ) )
{
if ( filterIt->m_wsRuleSource.Find( _T("'From'") ) != wxNOT_FOUND )
{
wsAddr = a_it->m_wsFrom;
// assume we have a quoted string if we have a leading '"'
if( wsAddr.StartsWith( _T("\"") ) )
{
wsAddr = wsAddr.AfterFirst( '"' );
wsAddr = wsAddr.BeforeLast( '"' );
}
wsAddr = wsAddr.MakeLower();
// make a simple match string
if( wsAddr.Matches( wsRuleText ) )
{
ar_wsColor = filterIt->m_wsColorHex;
ar_wsStatus = filterIt->m_wsStatus;
return;
}
}
else if ( filterIt->m_wsRuleSource.Find( _T("'Subject'") ) != wxNOT_FOUND )
{
// make a simple match string
if( wsSubject.MakeLower().Matches( wsRuleText ) )
{
ar_wsColor = filterIt->m_wsColorHex;
ar_wsStatus = filterIt->m_wsStatus;
return;
}
}
else if ( filterIt->m_wsRuleSource.Find( _T("'To'") ) != wxNOT_FOUND )
{
wsAddr = a_it->m_wsTo;
// make a simple match string
if( wsAddr.Matches( wsRuleText ) )
{
ar_wsColor = filterIt->m_wsColorHex;
ar_wsStatus = filterIt->m_wsStatus;
return;
}
}
#if 0 // not implemented yet
else if ( filterIt->m_wsRuleSource.Find( _T("'CC'") ) != wxNOT_FOUND )
{
#if 0
if ( ccArray.size() )
;
#else
// make a simple match string
if( wsAddr.Matches( wsRuleText ) )
{
ar_wsColor = filterIt->m_wsColorHex;
ar_wsStatus = filterIt->m_wsStatus;
return;
}
#endif
}
#endif
}
else // we need to look at the rest
{
if ( token.IsSameAs( _T("delete" ) ) )
{
if ( filterIt->m_wsRuleSource.Find( _T("'From'") ) != wxNOT_FOUND )
{
wsAddr = a_it->m_wsFrom;
#if 1
// for quoted strings we caNOT assume that the second " is at
// the end of the string.
// Simply remove all "
wsAddr.Replace( _T("\""), _T(""), true );
#else
// assume we have a quoted string if we have a leading '"'
if( wsAddr.StartsWith( _T("\"") ) )
{
wsAddr = wsAddr.AfterFirst( '"' );
wsAddr = wsAddr.BeforeLast( '"' );
}
#endif
wsAddr = wsAddr.MakeLower();
// make a simple match string
if( wsAddr.Matches( wsRuleText ) )
{
ar_wsColor = filterIt->m_wsColorHex;
ar_wsStatus = filterIt->m_wsStatus;
if ( filterIt->m_bState )
ar_bDelete = true;
return;
}
}
else if ( filterIt->m_wsRuleSource.Find( _T("'Subject'") ) != wxNOT_FOUND )
{
// make a simple match string
if( wsSubject.MakeLower().Matches( wsRuleText ) )
{
ar_wsColor = filterIt->m_wsColorHex;
ar_wsStatus = filterIt->m_wsStatus;
if ( filterIt->m_bState )
ar_bDelete = true;
return;
}
}
else if ( filterIt->m_wsRuleSource.Find( _T("'To'") ) != wxNOT_FOUND )
{
wsAddr = a_it->m_wsTo;
// make a simple match string
if( wsAddr.Matches( wsRuleText ) )
{
ar_wsColor = filterIt->m_wsColorHex;
ar_wsStatus = filterIt->m_wsStatus;
if ( filterIt->m_bState )
ar_bDelete = true;
return;
}
}
#if 0 // not implemented yet
else if ( filterIt->m_wsRuleSource.Find( _T("'CC'") ) != wxNOT_FOUND )
{
wsAddr = a_it->m_wsTo;
// make a simple match string
if( wsAddr.MakeLower().Matches( wsRuleText ) )
{
ar_wsColor = filterIt->m_wsColorHex;
ar_wsStatus = filterIt->m_wsStatus;
ar_bDelete = true;
return;
}
}
#endif
}
else
continue;
}
}
}
}
// ------------------------------- eof ------------------------------