Happy New Year!
[quassel.git] / src / core / ctcpparser.cpp
index 7517db6..fba3d13 100644 (file)
@@ -1,5 +1,5 @@
 /***************************************************************************
- *   Copyright (C) 2005-2013 by the Quassel Project                        *
+ *   Copyright (C) 2005-2015 by the Quassel Project                        *
  *   devel@quassel-irc.org                                                 *
  *                                                                         *
  *   This program is free software; you can redistribute it and/or modify  *
@@ -24,6 +24,7 @@
 #include "coresession.h"
 #include "ctcpevent.h"
 #include "messageevent.h"
+#include "coreuserinputhandler.h"
 
 const QByteArray XDELIM = "\001";
 
@@ -313,7 +314,27 @@ void CtcpParser::query(CoreNetwork *net, const QString &bufname, const QString &
 {
     QList<QByteArray> params;
     params << net->serverEncode(bufname) << lowLevelQuote(pack(net->serverEncode(ctcpTag), net->userEncode(bufname, message)));
+
+    static const char *splitter = " .,-!?";
+    int maxSplitPos = message.count();
+    int splitPos = maxSplitPos;
+
+    int overrun = net->userInputHandler()->lastParamOverrun("PRIVMSG", params);
+    if (overrun) {
+        maxSplitPos = message.count() - overrun -2;
+        splitPos = -1;
+        for (const char *splitChar = splitter; *splitChar != 0; splitChar++) {
+            splitPos = qMax(splitPos, message.lastIndexOf(*splitChar, maxSplitPos) + 1); // keep split char on old line
+        }
+        if (splitPos <= 0 || splitPos > maxSplitPos)
+            splitPos = maxSplitPos;
+
+        params = params.mid(0, 1) <<  lowLevelQuote(pack(net->serverEncode(ctcpTag), net->userEncode(bufname, message.left(splitPos))));
+    }
     net->putCmd("PRIVMSG", params);
+
+    if (splitPos < message.count())
+        query(net, bufname, ctcpTag, message.mid(splitPos));
 }