Truncate messages that are longer than 512 bytes and catch any exceptions irclib...
authorAlexander van Gessel <ai0867@gmail.com>
Mon, 21 Jan 2013 03:04:06 +0000 (04:04 +0100)
committerEric S. Raymond <esr@thyrsus.com>
Sun, 3 Feb 2013 18:57:43 +0000 (13:57 -0500)
Signed-off-by: Eric S. Raymond <esr@thyrsus.com>
irkerd

diff --git a/irkerd b/irkerd
index 8ec8412902a05f92d1690d7fc14181e07429ab01..36b34aba4746e8c71b2d54182bef94198876a8f7 100755 (executable)
--- a/irkerd
+++ b/irkerd
@@ -245,7 +245,17 @@ class Connection:
                         self.connection.join(channel)
                         self.irker.debug(1, "joining %s on %s." % (channel, self.servername))
                     for segment in message.split("\n"):
-                        self.connection.privmsg(channel, segment)
+                        # Truncate the message if it's too long,
+                        # but we're working with characters here,
+                        # not bytes, so we could be off.
+                        # 500 = 512 - CRLF - 'PRIVMSG ' - ' :'
+                        maxlength = 500 - len(channel)
+                        if len(segment) > maxlength:
+                            segment = segment[:maxlength]
+                        try:
+                            self.connection.privmsg(channel, segment)
+                        except ValueError as err:
+                            self.irker.debug(1, "irclib rejected a message to %s on %s because: %s" % (channel, self.servername, str(err)))
                         time.sleep(ANTI_FLOOD_DELAY)
                     self.last_xmit = self.channels_joined[channel] = time.time()
                     self.irker.debug(1, "XMIT_TTL bump (%s transmission) at %s" % (self.servername, time.asctime()))