- if (data != NULL)
- caplen += strlen(data) + 1;
-
- /* \r\n\0, possible "-~=", space, " *" */
- if(buflen + mlen >= BUFSIZE - 10)
- {
- /* remove our trailing space -- if buflen == mlen
- * here, we didnt even succeed in adding one.
- */
- capbuf[buflen] = '\0';
-
- sendto_one(source_p, "%s * :%s", buf, capbuf);
-
- buflen = mlen;
- memset(capbuf, 0, sizeof capbuf);
+ for (int attempts = 0; attempts < 2; attempts++) {
+ if (rb_snprintf_try_append(buf_list, max_list, "%s%s%s%s",
+ buf_list[0] == '\0' ? "" : " ", /* space between caps */
+ entry->cap,
+ data != NULL ? "=" : "", /* '=' between cap and data */
+ data != NULL ? data : "") < 0
+ && buf_list[0] != '\0') {
+
+ if (!(source_p->flags & FLAGS_CLICAP_DATA)) {
+ /* the client doesn't support multiple lines */
+ continue;
+ }
+
+ /* doesn't fit in the buffer, output what we have */
+ sendto_one(source_p, "%s%s%s", buf_prefix, str_cont, buf_list);
+
+ /* reset the buffer and go around the loop one more time */
+ buf_list[0] = '\0';
+ } else {
+ break;
+ }