# HG changeset patch
# Node ID d87f84040f39bba4f8e777234bd77660f714deae
# Parent  9244056af6238b60259eb6f428d818b623353e0f
diff --git a/ibis/ibismessage.c b/ibis/ibismessage.c
--- a/ibis/ibismessage.c
+++ b/ibis/ibismessage.c
@@ -132,7 +132,9 @@
 	if(message->params != NULL) {
 		ibis_message_serialize_add_delimiter(str);
 		ibis_message_serialize_params(message, str);
-	} else if(IBIS_IS_CTCP_MESSAGE(message->ctcp_message)) {
+	}
+
+	if(IBIS_IS_CTCP_MESSAGE(message->ctcp_message)) {
 		char *body = NULL;
 
 		ibis_message_serialize_add_delimiter(str);
diff --git a/ibis/tests/test_message.c b/ibis/tests/test_message.c
--- a/ibis/tests/test_message.c
+++ b/ibis/tests/test_message.c
@@ -473,13 +473,14 @@
 	char *serialized = NULL;
 
 	message = ibis_message_new(IBIS_MSG_PRIVMSG);
+	ibis_message_set_params(message, "irene", NULL);
 
 	ctcp_message = ibis_ctcp_message_new("VERSION");
 	ibis_message_set_ctcp_message(message, ctcp_message);
 	g_clear_object(&ctcp_message);
 
 	serialized = ibis_message_serialize_to_string(message, TRUE);
-	g_assert_cmpstr(serialized, ==, "PRIVMSG :\001VERSION\001\r\n");
+	g_assert_cmpstr(serialized, ==, "PRIVMSG irene :\001VERSION\001\r\n");
 	g_clear_pointer(&serialized, g_free);
 
 	g_assert_finalize_object(message);
@@ -494,6 +495,7 @@
 	                        NULL};
 
 	message = ibis_message_new(IBIS_MSG_PRIVMSG);
+	ibis_message_set_params(message, "#ibis", NULL);
 
 	ctcp_message = ibis_ctcp_message_new("ACTION");
 	ibis_ctcp_message_set_paramsv(ctcp_message, (GStrv)params);
@@ -502,7 +504,7 @@
 
 	serialized = ibis_message_serialize_to_string(message, TRUE);
 	g_assert_cmpstr(serialized, ==,
-	                "PRIVMSG :\001ACTION slaps grim with a large trout\001\r\n");
+	                "PRIVMSG #ibis :\001ACTION slaps grim with a large trout\001\r\n");
 
 	g_clear_pointer(&serialized, g_free);
 	g_assert_finalize_object(message);
@@ -516,6 +518,7 @@
 	const char *ctcp_params[] = {"SEND", "pidgin.ico", "::1", "0", NULL};
 
 	message = ibis_message_new(IBIS_MSG_PRIVMSG);
+	ibis_message_set_params(message, "irene", NULL);
 
 	ctcp_message = ibis_ctcp_message_new(IBIS_CTCP_DCC);
 	ibis_ctcp_message_set_paramsv(ctcp_message, (GStrv)ctcp_params);
@@ -525,7 +528,7 @@
 	serialized = ibis_message_serialize_to_string(message, TRUE);
 
 	g_assert_cmpstr(serialized, ==,
-	                "PRIVMSG :\001DCC SEND pidgin.ico ::1 0\001\r\n");
+	                "PRIVMSG irene :\001DCC SEND pidgin.ico ::1 0\001\r\n");
 
 	g_clear_pointer(&serialized, g_free);
 	g_assert_finalize_object(message);
@@ -539,6 +542,7 @@
 	const char *ctcp_params[] = {"SEND", "pidgin.ico ::1 0", NULL};
 
 	message = ibis_message_new(IBIS_MSG_PRIVMSG);
+	ibis_message_set_params(message, "irene", NULL);
 
 	ctcp_message = ibis_ctcp_message_new(IBIS_CTCP_DCC);
 	ibis_ctcp_message_set_paramsv(ctcp_message, (GStrv)ctcp_params);
@@ -548,7 +552,30 @@
 	serialized = ibis_message_serialize_to_string(message, TRUE);
 
 	g_assert_cmpstr(serialized, ==,
-	                "PRIVMSG :\001DCC SEND pidgin.ico ::1 0\001\r\n");
+	                "PRIVMSG irene :\001DCC SEND pidgin.ico ::1 0\001\r\n");
+
+	g_clear_pointer(&serialized, g_free);
+	g_assert_finalize_object(message);
+}
+
+static void
+test_ibis_message_serialize_ctcp_version(void) {
+	IbisCTCPMessage *ctcp_message = NULL;
+	IbisMessage *message = NULL;
+	char *serialized = NULL;
+	const char *ctcp_params[] = {"ibis 0.8.1", NULL};
+
+	message = ibis_message_new(IBIS_MSG_NOTICE);
+	ibis_message_set_params(message, "irene", NULL);
+
+	ctcp_message = ibis_ctcp_message_new(IBIS_CTCP_VERSION);
+	ibis_ctcp_message_set_paramsv(ctcp_message, (GStrv)ctcp_params);
+	ibis_message_set_ctcp_message(message, ctcp_message);
+	g_clear_object(&ctcp_message);
+
+	serialized = ibis_message_serialize_to_string(message, TRUE);
+
+	g_assert_cmpstr(serialized, ==, "NOTICE irene :\001VERSION ibis 0.8.1\001\r\n");
 
 	g_clear_pointer(&serialized, g_free);
 	g_assert_finalize_object(message);
@@ -952,6 +979,8 @@
 	                test_ibis_message_serialize_ctcp_multiple_params);
 	g_test_add_func("/ibis/message/serialize/ctcp/mixed-params",
 	                test_ibis_message_serialize_ctcp_mixed_params);
+	g_test_add_func("/ibis/message/serialize/ctcp-version",
+	                test_ibis_message_serialize_ctcp_version);
 
 	/* These tests are based on the msg-join tests from
 	 * https://github.com/ircdocs/parser-tests/blob/master/tests/msg-join.yaml
