diff --git a/src/chat/chat-message/chat-message.cpp b/src/chat/chat-message/chat-message.cpp index d26927c9e..0945f8480 100644 --- a/src/chat/chat-message/chat-message.cpp +++ b/src/chat/chat-message/chat-message.cpp @@ -21,6 +21,7 @@ #include "linphone/core.h" #include "linphone/lpconfig.h" +#include "linphone/utils/utils.h" #include "c-wrapper/c-wrapper.h" #include "address/address.h" @@ -389,6 +390,32 @@ LinphoneReason ChatMessagePrivate::receive () { contents.push_back(&internalContent); } + // Convert PlainText contents if they have a charset different than UTF-8 + for (Content *c : contents) { + if (c->getContentType() == ContentType::PlainText && !c->getContentType().getParameter().empty()) { + L_BEGIN_LOG_EXCEPTION + ContentType ct = c->getContentType(); + string charset = string(ct.getParameter()); + size_t n = charset.find("charset="); + if (n != string::npos) { + size_t begin = n + sizeof("charset"); + size_t end = charset.find(";", begin); + charset = charset.substr(begin, end - begin); + + if (Utils::stringToLower(charset) != "utf-8") { + string converted = Utils::convertString(c->getBodyAsUtf8String(), charset, "UTF-8"); + if (!converted.empty()) { + c->setBodyFromUtf8(converted); + string params = ct.getParameter(); + ct.setParameter(params.replace(begin, end - begin, "UTF-8")); + c->setContentType(ct); + } + } + } + L_END_LOG_EXCEPTION + } + } + // --------------------------------------- // End of message modification // --------------------------------------- diff --git a/src/chat/chat-room/chat-room.cpp b/src/chat/chat-room/chat-room.cpp index a2f9b0fa4..64ef93d21 100644 --- a/src/chat/chat-room/chat-room.cpp +++ b/src/chat/chat-room/chat-room.cpp @@ -19,6 +19,8 @@ #include +#include "linphone/utils/utils.h" + #include "c-wrapper/c-wrapper.h" #include "chat/chat-message/chat-message-p.h" #include "chat/chat-room/chat-room-p.h" @@ -194,7 +196,7 @@ LinphoneReason ChatRoomPrivate::onSipMessageReceived (SalOp *op, const SalMessag Content content; content.setContentType(message->content_type); - content.setBody(message->text ? message->text : ""); + content.setBodyFromUtf8(message->text ? message->text : ""); msg->setInternalContent(content); msg->getPrivate()->setTime(message->time);