...
In other words, transactions can safely encompass the modification, filtering, and accumulation of messages, as long as there's a clear separation between that process and using the end result to create side effects. A good solution should maximize the extent to which this is possible, and minimize the potential for mistakes.
Something which satisfied all of the above would be a good candidate for inclusion in contrib.
some possible approaches
pure functions (a la Ring)
...