瀏覽代碼

fix chat message encoding type sent via Kopete

Messages sent via Kopete show up blank in Windows AIM chat windows
because the encoding type is invalid. Kopete presents ISO 8859, when it
should be ISO-8859-1.
Mike 6 月之前
父節點
當前提交
0c486aba8a
共有 2 個文件被更改,包括 75 次插入4 次删除
  1. 12 4
      foodgroup/chat.go
  2. 63 0
      foodgroup/chat_test.go

+ 12 - 4
foodgroup/chat.go

@@ -117,12 +117,12 @@ func (s ChatService) transformChatMessage(inBody wire.SNAC_0x0E_0x05_ChatChannel
 		return wire.TLVRestBlock{}, errors.New("SNAC(0x0E,0x05) does not contain a message TLV")
 	}
 
-	restBlock := wire.TLVRestBlock{}
-	if err := wire.UnmarshalBE(&restBlock, bytes.NewBuffer(messageBlob)); err != nil {
+	msgBlock := wire.TLVRestBlock{}
+	if err := wire.UnmarshalBE(&msgBlock, bytes.NewBuffer(messageBlob)); err != nil {
 		return wire.TLVRestBlock{}, err
 	}
 
-	txt, err := extractChatMessage(restBlock)
+	txt, err := extractChatMessage(msgBlock)
 	if err != nil {
 		return wire.TLVRestBlock{}, err
 	}
@@ -133,6 +133,14 @@ func (s ChatService) transformChatMessage(inBody wire.SNAC_0x0E_0x05_ChatChannel
 		return newChatTLVBlock(inBody, sessOnlineHost, payload), nil
 	}
 
+	if enc, ok := msgBlock.String(wire.ChatTLVMessageInfoEncoding); ok {
+		if enc == "ISO 8859" {
+			// fix malformed content encoding type sent by Kopete, which causes
+			// chat messages to show up blank in Windows AIM chat windows
+			msgBlock.Replace(wire.NewTLVBE(wire.ChatTLVMessageInfoEncoding, []byte("ISO-8859-1")))
+		}
+	}
+
 	newRestBlock := wire.TLVRestBlock{}
 
 	// Strip down to the essential TLVs for cross-client compatibility.
@@ -141,7 +149,7 @@ func (s ChatService) transformChatMessage(inBody wire.SNAC_0x0E_0x05_ChatChannel
 	// sent by Windows AIM 5.9 will cause macOS AIM 2.x to crash. Rather than
 	// implement complex per-client filtering, we simply preserve only the three
 	// TLVs that every client expects.
-	for _, tlv := range restBlock.TLVList {
+	for _, tlv := range msgBlock.TLVList {
 		if tlv.Tag == wire.ChatTLVMessageInfoText ||
 			tlv.Tag == wire.ChatTLVMessageInfoEncoding ||
 			tlv.Tag == wire.ChatTLVMessageInfoLang {

+ 63 - 0
foodgroup/chat_test.go

@@ -465,6 +465,69 @@ func TestChatService_ChannelMsgToHost(t *testing.T) {
 				},
 			},
 		},
+		{
+			name: "fix malformed Kopete encoding ISO 8859 to ISO-8859-1",
+			instance: newTestInstance("user_sending_chat_msg", sessOptCannedSignonTime,
+				sessOptChatRoomCookie("the-chat-cookie")),
+			inputSNAC: wire.SNACMessage{
+				Frame: wire.SNACFrame{
+					RequestID: 1234,
+				},
+				Body: wire.SNAC_0x0E_0x05_ChatChannelMsgToHost{
+					Cookie:  1234,
+					Channel: 14,
+					TLVRestBlock: wire.TLVRestBlock{
+						TLVList: wire.TLVList{
+							{
+								Tag:   wire.ChatTLVPublicWhisperFlag,
+								Value: []byte{},
+							},
+							wire.NewTLVBE(wire.ChatTLVMessageInfo, wire.TLVRestBlock{
+								TLVList: wire.TLVList{
+									wire.NewTLVBE(wire.ChatTLVMessageInfoText,
+										"<HTML><BODY BGCOLOR=\"#ffffff\"><FONT LANG=\"0\">Hello</FONT></BODY></HTML>"),
+									wire.NewTLVBE(wire.ChatTLVMessageInfoEncoding, "ISO 8859"),
+								},
+							}),
+						},
+					},
+				},
+			},
+			mockParams: mockParams{
+				chatMessageRelayerParams: chatMessageRelayerParams{
+					chatRelayToAllExceptParams: chatRelayToAllExceptParams{
+						{
+							screenName: state.NewIdentScreenName("user_sending_chat_msg"),
+							cookie:     "the-chat-cookie",
+							message: wire.SNACMessage{
+								Frame: wire.SNACFrame{
+									FoodGroup: wire.Chat,
+									SubGroup:  wire.ChatChannelMsgToClient,
+								},
+								Body: wire.SNAC_0x0E_0x06_ChatChannelMsgToClient{
+									Cookie:  1234,
+									Channel: 14,
+									TLVRestBlock: wire.TLVRestBlock{
+										TLVList: wire.TLVList{
+											wire.NewTLVBE(wire.ChatTLVSenderInformation,
+												newTestInstance("user_sending_chat_msg", sessOptCannedSignonTime).Session().TLVUserInfo()),
+											wire.NewTLVBE(wire.ChatTLVPublicWhisperFlag, []byte{}),
+											wire.NewTLVBE(wire.ChatTLVMessageInfo, wire.TLVRestBlock{
+												TLVList: wire.TLVList{
+													wire.NewTLVBE(wire.ChatTLVMessageInfoText,
+														"<HTML><BODY BGCOLOR=\"#ffffff\"><FONT LANG=\"0\">Hello</FONT></BODY></HTML>"),
+													wire.NewTLVBE(wire.ChatTLVMessageInfoEncoding, "ISO-8859-1"),
+												},
+											}),
+										},
+									},
+								},
+							},
+						},
+					},
+				},
+			},
+		},
 	}
 
 	for _, tc := range cases {