Bug 920801 - Port chat/ changes from Instantbird to comm-central - 6 - Bio 2153 - Make UTF-8 conversion warnings less noisy, r=clokep.
--- a/chat/protocols/irc/irc.js
+++ b/chat/protocols/irc/irc.js
@@ -651,48 +651,55 @@ ircSocket.prototype = {
delete this._converter;
this.ERROR("Failed to set character set to: " + this._account._encoding +
" for " + this._account.name + ".");
}
},
// Implement Section 5 of RFC 2812.
onDataReceived: function(aRawMessage) {
- this.DEBUG(aRawMessage);
+ let conversionWarning = "";
if (this._converter) {
try {
aRawMessage = this._converter.ConvertToUnicode(aRawMessage);
} catch (e) {
- this.WARN("This message doesn't seem to be " + this._account._encoding +
- " encoded: " + aRawMessage);
+ conversionWarning = "\nThis message doesn't seem to be " +
+ this._account._encoding + " encoded.";
// Unfortunately, if the unicode converter failed once,
// it will keep failing so we need to reinitialize it.
this._initCharsetConverter();
}
}
// We've received data and are past the authentication stage.
if (this._account.connected)
this.resetPingTimer();
// Low level dequote: replace quote character \020 followed by 0, n, r or
// \020 with a \0, \n, \r or \020, respectively. Any other character is
// replaced with itself.
const lowDequote = {"0": "\0", "n": "\n", "r": "\r", "\x10": "\x10"};
- aRawMessage = aRawMessage.replace(/\x10./g,
+ let dequotedMessage = aRawMessage.replace(/\x10./g,
function(aStr) lowDequote[aStr[1]] || aStr[1]);
try {
- // If nothing handled the message, throw a warning.
- if (!ircHandlers.handleMessage(this._account, new ircMessage(aRawMessage)))
- this.WARN("Unhandled IRC message: " + aRawMessage);
+ let message = new ircMessage(dequotedMessage);
+ let isHandled = ircHandlers.handleMessage(this._account, message);
+ message.rawMessage = aRawMessage; // Log the quoted message.
+ let logEntry = JSON.stringify(message) + conversionWarning;
+ // Log the message if it was handled, otherwise throw a warning.
+ if (isHandled)
+ this.DEBUG(logEntry);
+ else
+ this.WARN("Unhandled IRC message:\n" + logEntry);
} catch (e) {
// Catch the error, display it and hope the connection can continue with
// this message in error. Errors are also caught inside of handleMessage,
// but we expect to handle message parsing errors here.
+ this.DEBUG(aRawMessage + conversionWarning);
this.ERROR(e);
}
},
onConnection: function() {
this._account._connectionRegistration.call(this._account);
},
disconnect: function() {
if (!this._account)
--- a/chat/protocols/irc/ircHandlers.jsm
+++ b/chat/protocols/irc/ircHandlers.jsm
@@ -86,17 +86,16 @@ var ircHandlers = {
registerServicesHandler: function(aHandler)
this._registerHandler(this._servicesHandlers, aHandler),
unregisterServicesHandler: function(aHandler)
this._unregisterHandler(this._servicesHandlers, aHandler),
// Handle a message based on a set of handlers.
_handleMessage: function(aHandlers, aAccount, aMessage, aCommand) {
- aAccount.DEBUG(JSON.stringify(aMessage));
// Loop over each handler and run the command until one handles the message.
for each (let handler in aHandlers) {
try {
// Attempt to execute the command, by checking if the handler has the
// command.
// Parse the command with the JavaScript account object as "this".
if (handler.isEnabled.call(aAccount) &&
Object.prototype.hasOwnProperty.call(handler.commands, aCommand) &&