From 7c1b83941cee3b805f4d4a5bc69c9c87520ccfeb Mon Sep 17 00:00:00 2001 From: Holger Weiss Date: Sat, 13 Jul 2019 14:43:16 +0200 Subject: [PATCH] mod_spam_filter: Apply small code simplification --- mod_spam_filter/src/mod_spam_filter.erl | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/mod_spam_filter/src/mod_spam_filter.erl b/mod_spam_filter/src/mod_spam_filter.erl index bc82a87..5373bcb 100644 --- a/mod_spam_filter/src/mod_spam_filter.erl +++ b/mod_spam_filter/src/mod_spam_filter.erl @@ -249,8 +249,7 @@ handle_cast({reload, NewOpts, OldOpts}, #state{host = Host} = State) -> {_Result, State3} = reload_files(JIDsFile, URLsFile, State2), {noreply, State3}; handle_cast(reopen_log, State) -> - close_dump_file(State), - {noreply, open_dump_file(State)}; + {noreply, reopen_dump_file(State)}; handle_cast(Request, State) -> ?ERROR_MSG("Got unexpected request from: ~p", [Request]), {noreply, State}. @@ -558,12 +557,6 @@ reject(#presence{from = From, to = To, lang = Lang} = Presence) -> reject(_) -> ok. --spec open_dump_file(state()) -> state(). -open_dump_file(#state{host = Host} = State) -> - DumpFile = gen_mod:get_module_opt(Host, ?MODULE, spam_dump_file), - DumpFile1 = expand_host(DumpFile, Host), - open_dump_file(DumpFile1, State). - -spec open_dump_file(filename(), state()) -> state(). open_dump_file(none, State) -> State#state{dump_fd = undefined}; @@ -578,12 +571,6 @@ open_dump_file(Name, State) -> State#state{dump_fd = undefined} end. --spec close_dump_file(state()) -> ok. -close_dump_file(#state{host = Host} = State) -> - DumpFile = gen_mod:get_module_opt(Host, ?MODULE, spam_dump_file), - DumpFile1 = expand_host(DumpFile, Host), - close_dump_file(DumpFile1, State). - -spec close_dump_file(filename(), state()) -> ok. close_dump_file(_Name, #state{dump_fd = undefined}) -> ok; @@ -595,6 +582,13 @@ close_dump_file(Name, #state{dump_fd = Fd}) -> ?ERROR_MSG("Cannot close ~s: ~s", [Name, file:format_error(Reason)]) end. +-spec reopen_dump_file(state()) -> state(). +reopen_dump_file(#state{host = Host} = State) -> + DumpFile = gen_mod:get_module_opt(Host, ?MODULE, spam_dump_file), + DumpFile1 = expand_host(DumpFile, Host), + close_dump_file(DumpFile1, State), + open_dump_file(DumpFile1, State). + -spec maybe_dump_spam(message()) -> ok. maybe_dump_spam(#message{to = #jid{lserver = LServer}} = Msg) -> By = jid:make(<<>>, LServer),