From 8f63b2cbae0e0867ff9542e1cc7eb67382462e02 Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Tue, 9 Apr 2019 01:21:55 +0200 Subject: [PATCH] mod_spam_filter: Check recipient's domain Don't crash if the module isn't loaded for the 'to' domain. This would otherwise happen for stanzas sent to subdomains (e.g., MUC messages). Thanks to Nico Wellpott for reporting the bug and testing the fix. --- mod_spam_filter/src/mod_spam_filter.erl | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/mod_spam_filter/src/mod_spam_filter.erl b/mod_spam_filter/src/mod_spam_filter.erl index 20d9926..dfa7c1d 100644 --- a/mod_spam_filter/src/mod_spam_filter.erl +++ b/mod_spam_filter/src/mod_spam_filter.erl @@ -293,14 +293,20 @@ s2s_in_handle_info(State, _) -> %%-------------------------------------------------------------------- -spec needs_checking(jid(), jid()) -> boolean(). needs_checking(From, #jid{lserver = LServer} = To) -> - Access = gen_mod:get_module_opt(LServer, ?MODULE, access_spam), - case acl:match_rule(LServer, Access, To) of - allow -> - ?DEBUG("Spam not filtered for ~s", [jid:encode(To)]), - false; - deny -> - ?DEBUG("Spam is filtered for ~s", [jid:encode(To)]), - not mod_roster:is_subscribed(From, To) + case gen_mod:is_loaded(LServer, ?MODULE) of + true -> + Access = gen_mod:get_module_opt(LServer, ?MODULE, access_spam), + case acl:match_rule(LServer, Access, To) of + allow -> + ?DEBUG("Spam not filtered for ~s", [jid:encode(To)]), + false; + deny -> + ?DEBUG("Spam is filtered for ~s", [jid:encode(To)]), + not mod_roster:is_subscribed(From, To) + end; + false -> + ?DEBUG("~s not loaded for ~s", [?MODULE, LServer]), + false end. -spec check_from(binary(), jid()) -> ham | spam.