From 7d5e63be1fd6602ab8e62316202924b316c7436f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C5=99emysl=20Eric=20Janouch?=
Date: Sat, 10 Sep 2022 18:48:15 +0200 Subject: [PATCH] xC: deal with so far unexpected multiline messages And get rid of an outdated unmarked TODO comment. --- xC.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/xC.c b/xC.c index eedb769..c440abc 100644 --- a/xC.c +++ b/xC.c @@ -9075,12 +9075,21 @@ irc_autosplit_message (struct server *s, const char *message, - 1 - (int) strlen (s->irc_user_host) - 1 - fixed_part; - // However we don't always have the full info for message splitting - if (!space_in_one_message) - strv_append (output, message); - else if (!wrap_message (message, space_in_one_message, output, e)) - return false; - return true; + // Multiline messages can be triggered through hooks and plugins. + struct strv lines = strv_make (); + cstr_split (message, "\r\n", false, &lines); + bool success = true; + for (size_t i = 0; i < lines.len; i++) + { + // We don't always have the full info for message splitting. + if (!space_in_one_message) + strv_append (output, lines.vector[i]); + else if (!(success = + wrap_message (lines.vector[i], space_in_one_message, output, e))) + break; + } + strv_free (&lines); + return success; } static void @@ -9089,12 +9098,11 @@ send_autosplit_message (struct server *s, const char *prefix, const char *suffix) { struct buffer *buffer = str_map_find (&s->irc_buffer_map, target); + + // "COMMAND target * :prefix*suffix" int fixed_part = strlen (command) + 1 + strlen (target) + 1 + 1 + strlen (prefix) + strlen (suffix); - // We might also want to preserve attributes across splits but - // that would make this code a lot more complicated - struct strv lines = strv_make (); struct error *e = NULL; if (!irc_autosplit_message (s, message, fixed_part, &lines, &e))