1 #include <string>
2 using namespace std;
3 #include "strsep.h"
4 #include "mask.h"
5
CMask()6 CMask::CMask()
7 {
8 }
9
~CMask()10 CMask::~CMask()
11 {
12
13 }
14
CMask(const CMask & msk)15 CMask::CMask(const CMask& msk)
16 {
17 s_Sender = msk.s_Sender;
18 s_Recipient = msk.s_Recipient;
19 F_From = msk.F_From;
20 F_To = msk.F_To;
21 s_Subject = msk.s_Subject;
22 d_Flags = msk.d_Flags;
23 }
24
CMask(string sndr,string recpt,CFtnAddr frm,CFtnAddr to,string subj,dword flgs)25 CMask::CMask(string sndr, string recpt, CFtnAddr frm, CFtnAddr to, string subj, dword flgs)
26 {
27 s_Sender = sndr;
28 s_Recipient = recpt;
29 F_From = frm;
30 F_To = to;
31 s_Subject = subj;
32 d_Flags = flgs;
33 }
34
operator =(const CMask & msk)35 CMask& CMask::operator=(const CMask& msk)
36 {
37 if ((this)==(&msk)) return (*this);
38 s_Sender = msk.s_Sender;
39 s_Recipient = msk.s_Recipient;
40 s_Subject=msk.s_Subject;
41 F_From=msk.F_From;
42 F_To=msk.F_To;
43 d_Flags=msk.d_Flags;
44 return (*this);
45 }
46
operator =(const string & str)47 CMask& CMask::operator=(const string& str)
48 {
49 char *buf;
50 buf = new char[128];
51 buf=const_cast<char*>(str.c_str());
52 s_Sender=strseparate(&buf, ",");
53 F_From=strseparate(&buf, ",");
54 s_Recipient=strseparate(&buf, ",");
55 F_To=strseparate(&buf, ",");
56 s_Subject=strseparate(&buf, ",");
57 strseparate(&buf,",");
58 delete [] buf;
59 return (*this);
60 }
61
operator ==(const CMask & msk)62 bool CMask::operator==(const CMask& msk)
63 {
64 bool sndMatch=false;
65 bool rcpMatch=false;
66 bool frmMatch=false;
67 bool toMatch=false;
68 bool subjMatch=false;
69 bool attrMatch=true;
70
71 /* try to determine matches simply */
72 if (msk.s_Sender == s_Sender) sndMatch=true;
73 if (s_Sender=="*") sndMatch=true;
74 if (msk.s_Recipient == s_Recipient) rcpMatch=true;
75 if (s_Recipient=="*") rcpMatch=true;
76 if (F_From == msk.F_From) frmMatch=true;
77 if (F_To == msk.F_To) toMatch=true;
78 if (msk.s_Subject == s_Subject) subjMatch=true;
79 if (s_Subject=="*") subjMatch=true;
80
81 /* do dirty checking with ~ */
82 if (strchr(s_Sender.c_str(), '~')!=NULL)
83 {
84 if (strstr(msk.s_Sender.c_str(), strchr(s_Sender.c_str(),'~')+1)!=NULL)
85 sndMatch=true;
86 }
87
88 if (strchr(s_Recipient.c_str(), '~')!=NULL)
89 {
90 if (strstr(msk.s_Recipient.c_str(), strchr(s_Recipient.c_str(),'~')+1)!=NULL)
91 rcpMatch=true;
92 }
93
94 if (strchr(s_Subject.c_str(), '~')!=NULL)
95 {
96 if (strstr(msk.s_Subject.c_str(), strchr(s_Subject.c_str(),'~')+1)!=NULL)
97 subjMatch=true;
98 }
99
100 if (sndMatch && rcpMatch && frmMatch && toMatch && subjMatch && attrMatch)
101 return true;
102 else return false;
103
104 }
105
parseAttr(string s_Flags)106 int CMask::parseAttr(string s_Flags)
107 {
108 bool mand=false;
109 for (unsigned int i=0;i<s_Flags.size()-1;i+=2)
110 {
111 char prefix, flag;
112 prefix=s_Flags[i];
113 flag=s_Flags[i+1];
114 if (prefix=='+') mand=true;
115 if (flag=='p' || flag=='P')
116 {
117 if (mand) priv=1;
118 else priv=-1;
119 }
120 if (flag=='c' || flag=='C')
121 {
122 if (mand) crash=1;
123 else crash=-1;
124 }
125 if (flag=='s' || flag=='S')
126 {
127 if (mand) sent=1;
128 else sent=-1;
129 }
130 if (flag=='a' || flag=='A')
131 {
132 if (mand) attach=1;
133 else attach=-1;
134 }
135 if (flag=='i' || flag=='I')
136 {
137 if (mand) immediate=1;
138 else immediate=-1;
139 }
140 if (flag=='o' || flag=='O')
141 {
142 if (mand) orphan=1;
143 else orphan=-1;
144 }
145 if (flag=='k' || flag=='K')
146 {
147 if (mand) kill=1;
148 else kill=-1;
149 }
150 if (flag=='l' || flag=='L')
151 {
152 if (mand) local=1;
153 else local=-1;
154 }
155 if (flag=='h' || flag=='H')
156 {
157 if (mand) hold=1;
158 else hold=-1;
159 }
160 if (flag=='f' || flag=='F')
161 {
162 if (mand) file_request=1;
163 else file_request=-1;
164 }
165 if (flag=='n' || flag=='N')
166 {
167 if (mand) file_request=1;
168 else file_request=-1;
169 }
170 if (flag=='d' || flag=='D')
171 {
172 if (mand) file_request=1;
173 else file_request=-1;
174 }
175 if (flag=='u' || flag=='U')
176 {
177 if (mand) file_request=1;
178 else file_request=-1;
179 }
180 if (flag=='q' || flag=='Q')
181 {
182 if (mand) file_request=1;
183 else file_request=-1;
184 }
185 if (flag=='y' || flag=='Y')
186 {
187 if (mand) file_request=1;
188 else file_request=-1;
189 }
190 if (flag=='e' || flag=='E')
191 {
192 if (mand) file_request=1;
193 else file_request=-1;
194 }
195 if (flag=='m' || flag=='M')
196 {
197 if (mand) file_request=1;
198 else file_request=-1;
199 }
200 if (flag=='t' || flag=='T')
201 {
202 if (mand) file_request=1;
203 else file_request=-1;
204 }
205 if (flag=='z' || flag=='Z')
206 {
207 if (mand) file_request=1;
208 else file_request=-1;
209 }
210 }
211 return 0;
212 }
213
compareAttr(dword attr)214 bool CMask::compareAttr(dword attr)
215 {
216 return true;
217 }
218