processone/ejabberd — pull request #161 by weiss (2014-04-09 22:07:45+00:00)
Title: Let mod_carboncopy take care of messages sent to bare/unavailable JIDs

Currently, `mod_carboncopy` [assumes][1] that messages sent to bare JIDs are delivered to all connected resources anyway and therefore don't need to be carbon-copied. This assumption is wrong: Messages sent to bare JIDs are only delivered to those resources with the highest priority. So, `mod_carboncopy` must forward them to all carbon-copy-enabled resources that *don't* have a top priority.

Apart from that, messages sent to unavailable resources currently aren't handled correctly: `mod_carboncopy` forwards those to *all* carbon-copy-enabled resources, including those that receive these messages anyway, and therefore produces duplicates. The session manager routes messages sent to unavailable resources just like messages sent to bare JIDs, so `mod_carboncopy` should handle them in just the same way, too.

[1]: https://github.com/processone/ejabberd/blob/66006ba0171121eec047b87699ad8f1e582ca241/src/mod_carboncopy.erl#L134