From: Evgeniy Khramtsov Date: Fri, 13 Jan 2017 11:20:25 +0000 (+0300) Subject: Decode message before checking for expiration (#1458) X-Git-Tag: 17.01~20 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7606be93d5cfab2ea3219bf4e5b480afe9020da2;p=ejabberd Decode message before checking for expiration (#1458) --- diff --git a/src/mod_offline.erl b/src/mod_offline.erl index ae0915ee4..0c8c3f7a9 100644 --- a/src/mod_offline.erl +++ b/src/mod_offline.erl @@ -570,32 +570,34 @@ pop_offline_messages(Ls, User, Server) -> Mod = gen_mod:db_mod(LServer, ?MODULE), case Mod:pop_messages(LUser, LServer) of {ok, Rs} -> - TS = p1_time_compat:timestamp(), Ls ++ lists:flatmap( - fun(R) -> + fun(#offline_msg{expire = Expire} = R) -> case offline_msg_to_route(LServer, R) of - error -> []; - RouteMsg -> [RouteMsg] + error -> + []; + {route, _From, _To, Msg} = RouteMsg -> + case is_expired_message(Expire, Msg) of + true -> []; + false -> [RouteMsg] + end end - end, - lists:filter( - fun(#offline_msg{packet = Pkt} = R) -> - Expire = case R#offline_msg.expire of - undefined -> - find_x_expire(TS, Pkt); - Exp -> - Exp - end, - case Expire of - never -> true; - TimeStamp -> TS < TimeStamp - end - end, Rs)); + end, Rs); _ -> Ls end. +is_expired_message(Expire, Pkt) -> + TS = p1_time_compat:timestamp(), + Exp = case Expire of + undefined -> find_x_expire(TS, Pkt); + _ -> Expire + end, + case Exp of + never -> false; + TimeStamp -> TS >= TimeStamp + end. + remove_expired_messages(Server) -> LServer = jid:nameprep(Server), Mod = gen_mod:db_mod(LServer, ?MODULE),