mod_spam_filter: Silence reload_spam_filter_files

Don't let the reload_spam_filter_files command spit out text on success.
This commit is contained in:
Holger Weiss 2019-04-25 10:05:47 +02:00
parent a0a9aaa1e0
commit 4476c95f14
1 changed files with 9 additions and 10 deletions

View File

@ -449,7 +449,7 @@ filter_body(none, _Set, _From, State) ->
{ham, State}. {ham, State}.
-spec reload_files(filename(), filename(), state()) -spec reload_files(filename(), filename(), state())
-> {{ok | error, binary()}, state()}. -> {ok | {error, binary()}, state()}.
reload_files(JIDsFile, URLsFile, #state{host = Host} = State) -> reload_files(JIDsFile, URLsFile, #state{host = Host} = State) ->
try read_files(JIDsFile, URLsFile) of try read_files(JIDsFile, URLsFile) of
{JIDsSet, URLsSet} -> {JIDsSet, URLsSet} ->
@ -465,8 +465,7 @@ reload_files(JIDsFile, URLsFile, #state{host = Host} = State) ->
false -> false ->
?INFO_MSG("Reloaded spam URLs for ~s (changed)", [Host]) ?INFO_MSG("Reloaded spam URLs for ~s (changed)", [Host])
end, end,
Txt = <<"Reloaded spam JID/URL files">>, {ok, State#state{jid_set = JIDsSet, url_set = URLsSet}}
{{ok, Txt}, State#state{jid_set = JIDsSet, url_set = URLsSet}}
catch {Op, File, Reason} when Op == open; catch {Op, File, Reason} when Op == open;
Op == read -> Op == read ->
Txt = format("Cannot ~s ~s for ~s: ~s", Txt = format("Cannot ~s ~s for ~s: ~s",
@ -684,7 +683,7 @@ get_commands_spec() ->
desc = "Reload spam JID/URL files", desc = "Reload spam JID/URL files",
module = ?MODULE, function = reload_spam_filter_files, module = ?MODULE, function = reload_spam_filter_files,
args = [{host, binary}], args = [{host, binary}],
result = {res, restuple}}, result = {res, rescode}},
#ejabberd_commands{name = get_spam_filter_cache, tags = [filter], #ejabberd_commands{name = get_spam_filter_cache, tags = [filter],
desc = "Show spam filter cache contents", desc = "Show spam filter cache contents",
module = ?MODULE, function = get_spam_filter_cache, module = ?MODULE, function = get_spam_filter_cache,
@ -706,10 +705,8 @@ get_commands_spec() ->
-spec reload_spam_filter_files(binary()) -> {ok | error, string()}. -spec reload_spam_filter_files(binary()) -> {ok | error, string()}.
reload_spam_filter_files(<<"global">>) -> reload_spam_filter_files(<<"global">>) ->
try lists:foreach(fun(Host) -> try lists:foreach(fun(Host) ->
{ok, _} = reload_spam_filter_files(Host) ok = reload_spam_filter_files(Host)
end, ejabberd_config:get_myhosts()) of end, ejabberd_config:get_myhosts())
ok ->
{ok, "Reloaded spam JID/URL files"}
catch error:{badmatch, {error, _Reason} = Error} -> catch error:{badmatch, {error, _Reason} = Error} ->
Error Error
end; end;
@ -721,8 +718,10 @@ reload_spam_filter_files(Host) ->
Proc = get_proc_name(LServer), Proc = get_proc_name(LServer),
try gen_server:call(Proc, {reload_files, JIDsFile, URLsFile}, try gen_server:call(Proc, {reload_files, JIDsFile, URLsFile},
?COMMAND_TIMEOUT) of ?COMMAND_TIMEOUT) of
{spam_filter, {Status, Txt}} -> {spam_filter, ok} ->
{Status, binary_to_list(Txt)} ok;
{spam_filter, {error, Txt}} ->
{error, binary_to_list(Txt)}
catch exit:{noproc, _} -> catch exit:{noproc, _} ->
{error, "Not configured for " ++ binary_to_list(Host)}; {error, "Not configured for " ++ binary_to_list(Host)};
exit:{timeout, _} -> exit:{timeout, _} ->