1 /** Basic filter type definitions.
2 
3 	Copyright: © 2013-2017 RejectedSoftware e.K.
4 	License: Subject to the terms of the General Public License version 3, as written in the included LICENSE.txt file.
5 	Authors: Sönke Ludwig
6 */
7 module antispam.filter;
8 
9 import vibe.data.json : Json;
10 import vibe.inet.message : InetHeaderMap;
11 
12 
13 /**
14 	Base interface for all spam filters.
15 */
16 interface SpamFilter {
17 @safe:
18 
19 	/// Unique string identifier for the filter type
20 	@property string id() const;
21 
22 	/// Applies the given JSON settings object (filter specific format).
23 	void applySettings(Json settings);
24 
25 	/// Returns a JSON object that contains all filter specific settings.
26 	Json getSettings() const;
27 
28 	/// Performs immediate spam detection.
29 	SpamAction determineImmediateSpamStatus(in ref AntispamMessage);
30 
31 	/// Performs I/O heavy spam detection (e.g. using an external web service)
32 	SpamAction determineAsyncSpamStatus(in ref AntispamMessage);
33 
34 	/// Clears any learned classification information.
35 	void resetClassification();
36 
37 	/// Manually classifies a message as spam/ham to feed learning routines.
38 	void classify(in ref AntispamMessage art, bool spam, bool unclassify = false);
39 }
40 
41 
42 /**
43 	Determins what to do with a certain message.
44 */
45 enum SpamAction {
46 	amnesty, /// Accept message no matter what later filters may decide
47 	pass,    /// Do not block the message, but let other filers decide
48 	revoke,  /// Message is spam and should be revoked/hidden after being posted
49 	block,   /// Message is spam and should be blocked/deleted before being posted
50 }
51 
52 struct AntispamMessage {
53 	InetHeaderMap headers;
54 	const(ubyte)[] message;
55 	const(string)[] peerAddress; // list of hops starting from the original client
56 }