Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

#148 Carbon copy sends message back to original sender solved #149

Merged
merged 1 commit into from

3 participants

@iulianlaz

Current implementation of carbon copies sends message back to original sender.
(original sender receives a carbon copy of a carbon copy message).

Scenario:
Having two users: User A and User B with three resources each: Res1, Res2, Res3; we want to send a message from user A/Res1 to User B.
Firstly, the message will be forwarded to User A resources (Res2 and Res3). When message arrives to User A/Res2, it will be forwarded to Res1 and Res3, because it does not have the badge "received". User A/Res1 (original sender) must not receive the message again. In order to do that, we must check if the message contains "sent" follow by "forwarded" tags. If the message does not
contain those tags, the message will be forwarded. For user A/Res3 it is the same scenario.
Secondly, the message wil be sent to User B resources. Here, we do not have to worry about.

@badlop badlop merged commit 2b527f5 into processone:master
@hejazee

Thank you so much. I spent a lot of time to figure out the problem and at last I fount that you've already solved it. but this commit is not included in ejabberd 13.12
thanks a lot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 1 deletion.
  1. +13 −1 src/mod_carboncopy.erl
View
14 src/mod_carboncopy.erl
@@ -151,7 +151,19 @@ check_and_forward(JID, #xmlel{name = <<"message">>, attrs = Attrs} = Packet, Dir
false ->
case xml:get_subtag(Packet,<<"received">>) of
false ->
- send_copies(JID, Packet, Direction);
+ %% We must check if a packet contains "<sent><forwarded></sent></forwarded>" tags in order to avoid
+ %% receiving message back to original sender.
+ SubTag = xml:get_subtag(Packet,<<"sent">>),
+ if SubTag == false ->
+ send_copies(JID, Packet, Direction);
+ true ->
+ case xml:get_subtag(SubTag,<<"forwarded">>) of
+ false->
+ send_copies(JID, Packet, Direction);
+ _ ->
+ stop
+ end
+ end;
_ ->
%% stop the hook chain, we don't want mod_logdb to register this message (duplicate)
stop
Something went wrong with that request. Please try again.