This is a multi-part message in MIME format. --------------020007020000030909080202 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Hi, as reported on https://bugs.launchpad.net/bugs/378428 there were problems when importing history logs from pidgin, because of a slightly different format used by different pidgin versions. The latest patch posted there (which is also attached to this email) solves the mentioned problems and should be applied to the kopete source. Could someone (maybe Olivier Goffart?) of you do this? It would be very nice if this patch will made it into the first release of KDE 4.3. Thanks, Timo --------------020007020000030909080202 Content-Type: text/plain; name="kopete-history-import-fix.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="kopete-history-import-fix.patch" Index: kopete/plugins/history/historyimport.cpp =================================================================== --- kopete/plugins/history/historyimport.cpp (revision 980159) +++ kopete/plugins/history/historyimport.cpp (working copy) @@ -1,9 +1,9 @@ /* historyimport.cpp - Copyright (c) 2008 by Timo Schluessler + Copyright (c) 2009 by Timo Schluessler - Kopete (c) 2008 by the Kopete developers + Kopete (c) 2009 by the Kopete developers ************************************************************************* * * @@ -19,6 +19,7 @@ #include #include +#include #include #include #include @@ -429,14 +430,16 @@ void HistoryImport::parsePidginTxt(QFile &file, struct Log *log, QDate date) { - QByteArray line; + QString line; QTime time; QDateTime dateTime; QString messageText, nick; bool incoming = false; // =false to make the compiler not complain + QTextStream txtStream(&file); + txtStream.setCodec(QTextCodec::codecForName("UTF-8")); - while (!file.atEnd()) { - line = file.readLine(); + while (!txtStream.atEnd()) { + line = txtStream.readLine(); if (line[0] == '(') { if (!messageText.isEmpty()) { @@ -469,12 +472,11 @@ return; messageText = line.mid(nickEnd + 1); - } - else if (line[0] == ' ') { + } else if (line[0] != 'C') { // an already started message is continued in this line int start = QRegExp("\\S").indexIn(line); messageText.append('\n' + line.mid(start)); - } + } } if (!messageText.isEmpty()) { struct Message message; @@ -489,71 +491,47 @@ void HistoryImport::parsePidginXml(QFile &file, struct Log * log, QDate date) { - bool incoming = false, inMessage = false, textComes = false; - QString messageText, status; + QString line; QTime time; QDateTime dateTime; + QString messageText, nick; + bool incoming = false; // =false to make the compiler not complain + QTextStream txtStream(&file); + txtStream.setCodec(QTextCodec::codecForName("UTF-8")); - // unfortunately pidgin doesn't write <... /> for the tag - QByteArray data = file.readAll(); - if (data.contains("", data.indexOf(" "); + QRegExp incomingRegExp(""); + QRegExp messageRegExp(""); + tags.setMinimal(true); // we always want to only match single tags (i.e. not the text between tags) - QXmlStreamReader reader(data); + while (!txtStream.atEnd()) { + line = txtStream.readLine(); - while (!reader.atEnd()) { - reader.readNext(); + if (line.indexOf(messageRegExp) == 0) { + incoming = line.indexOf(incomingRegExp) == 0; - if (reader.isStartElement() && reader.name() == "font" && !reader.attributes().value("color").isEmpty()) { - if (reader.attributes().value("color") == "#A82F2F") - incoming = true; - else - incoming = false; + int beginTime = line.indexOf('('); + int endTime = line.indexOf(')',beginTime); + dateTime = extractTime(line.mid(beginTime,endTime-beginTime+1), date); - while (reader.readNext() != QXmlStreamReader::Characters) { }; + int beginMsg = line.indexOf(beginMessage,endTime)+beginMessage.size(); + messageText = line.mid(beginMsg).replace("
","\n").remove(tags).remove(QRegExp("\\n$")); - dateTime = extractTime(reader.text().toString(), date); - inMessage = true; - } - if (inMessage && reader.isStartElement() && reader.name() == "b") { - reader.readNext(); - status = reader.text().toString(); - textComes = true; - } - else if (textComes && reader.isCharacters()) { - messageText += reader.text().toString(); - } - else if (reader.isStartElement() && reader.name() == "br" && !messageText.isEmpty()) { - messageText.remove(0, 1); // remove the leading blank - + messageText.replace(""", "\""); // replace named entities used by pidgin + messageText.replace("'", "'"); + messageText.replace("&", "&"); + messageText.replace("<", "<"); + messageText.replace(">", ">"); + struct Message message; message.incoming = incoming; message.text = messageText; message.timestamp = dateTime; log->messages.append(message); - messageText.clear(); - textComes = false; - inMessage = false; - } - + } } - if (reader.hasError()) { - // we ignore error 4: premature end of document - if (reader.error() != 4) { - int i, pos = 0; - for (i=1;i