+ bool isStatusMsg = false;
+
+ // First remove all statusmsg prefix characters that are not also channel prefix characters.
+ while (e->network()->isStatusMsg(e->target()) && !e->network()->isChannelName(e->target())) {
+ isStatusMsg = true;
+ e->setTarget(e->target().remove(0, 1));
+ }
+
+ // Then continue removing statusmsg characters as long as removing the character will still result in a
+ // valid channel name. This prevents removing the channel prefix character if said character is in the
+ // overlap between the statusmsg characters and the channel prefix characters.
+ while (e->network()->isStatusMsg(e->target()) && e->network()->isChannelName(e->target().remove(0, 1))) {
+ isStatusMsg = true;
+ e->setTarget(e->target().remove(0, 1));
+ }
+
+ // If any statusmsg characters were removed, Flag the message as a StatusMsg.
+ if (isStatusMsg) {
+ flags |= Message::StatusMsg;
+ }
+
+ // For self-messages, pass the flag on to the message, too
+ if (e->testFlag(EventManager::Self)) {
+ flags |= Message::Self;
+ }
+