add support to unicode string for ktnef library #11

已合併
MicheleC 5 年之前 將 1 次代碼提交從 bug/307 合併至 master
協同者

I have enabled the ktnef library to decode unicode strings, it may solve the bug #307 (that was my case) but the original author of the bug should provide more data about his issue

I have enabled the ktnef library to decode unicode strings, it may solve the bug [#307](http://bugs.trinitydesktop.org/show_bug.cgi?id=307) (that was my case) but the original author of the bug should provide more data about his issue
SlavekB reviewed 5 年之前
所有者

Using ascii() in almost all cases is not a good idea. Therefore, it is not good to add code that use ascii().
At least for the unicode string value, it seems better to use utf8().

Please, can you test the patch where you will use utf8() instead of ascii()?

Using `ascii()` in almost all cases is not a good idea. Therefore, it is not good to add code that use `ascii()`. At least for the unicode string value, it seems better to use `utf8()`. Please, can you test the patch where you will use `utf8()` instead of `ascii()`?
MicheleC reviewed 5 年之前
MicheleC left a comment
所有者

toString().ascii()
is used in many places for debug here. Although the use of ascii() can give wrong result for strings with special characters, for the scope of the patch provided by Fabio I think it is acceptable to use ascii() here, in line with the rest of the code.

Converting from ascii() to utf8() should be the scope of a different PR and the conversion should be global.

toString().ascii() is used in many places for debug here. Although the use of ascii() can give wrong result for strings with special characters, for the scope of the patch provided by Fabio I think it is acceptable to use ascii() here, in line with the rest of the code. Converting from ascii() to utf8() should be the scope of a different PR and the conversion should be global.
所有者

sorry, comment above in "Review" was intended in reply to Slavek's comment in the code, but it seems gitea does not accept a comment in reply to another comment. still testing comment feature out 😉

sorry, comment above in "Review" was intended in reply to Slavek's comment in the code, but it seems gitea does not accept a comment in reply to another comment. still testing comment feature out :wink:
發佈者
協同者

@SlavekB: utf8() doesn't work because the strings are UCS2, which is common on Windows platforms. I have changed the code to leave TQString() managing the encoding and it seems to work as expected now.

@SlavekB: utf8() doesn't work because the strings are UCS2, which is common on Windows platforms. I have changed the code to leave TQString() managing the encoding and it seems to work as expected now.
所有者

Ciao Fabio,

hopefully I am not saying something totally wrong here.

utf8() alone should fail. The reason is in the way utf8() and TQCString work.

In short, utf8() returns a TQCString object. TQCString has a conversion "operator char * " method to convert to char . This works fine whenever utf8() result is passed to a const char * parameter. But when passed to a variable format string (%s), the conversion is not done automatically: the address of the TQCString is passed and interpreted as a const char, resulting in garbage printed to the screen.

Using printf(), I am 100% sure this happens (I had the same problem just yesterday 😉), using kdDebug() I am not 100% sure but it is likely to be the same.

Using utf8() requires something like this:

 mapi.value.toString().utf8().data()

PS: ascii() works fine because it returns a const char *

Ciao Fabio,<br> hopefully I am not saying something totally wrong here. utf8() alone should fail. The reason is in the way utf8() and TQCString work.<br> In short, utf8() returns a TQCString object. TQCString has a conversion "operator char * " method to convert to char *. This works fine whenever utf8() result is passed to a const char * parameter. But when passed to a variable format string (%s), the conversion is not done automatically: the address of the TQCString is passed and interpreted as a const char*, resulting in garbage printed to the screen. Using printf(), I am 100% sure this happens (I had the same problem just yesterday :wink:), using kdDebug() I am not 100% sure but it is likely to be the same. Using utf8() requires something like this: ``` mapi.value.toString().utf8().data() ``` PS: ascii() works fine because it returns a const char *
SlavekB approved these changes 5 年之前
SlavekB left a comment
所有者

Using kdDebug() as a stream looks very good. I have no objections. Thank you for your good contribution.

Using kdDebug() as a stream looks very good. I have no objections. Thank you for your good contribution.
發佈者
協同者

First of all I am using the file unicode-mapi-attr-name.tnef as usecase

The raw data is ucs2 so utf8 cannot work (I guess), please have a look to the new commit that should fix the debugging statement (at least on my system, I am not sure which is the default coding for TQString, otherwise it should be set in advance).

The above referenced TNEF file has unicode chars even in strings advertised as not unicode (so probably it's buggy). You can see in the GUI with Action -> Message Properties looking at the subject property.

I don't know anything about MAPI details (and I am not interested to know more :-) ), but it seems that the message subject is repeated twice in the file, the first time as "stand-alone" property (0x8004) and the second one in the MAPI properties (tag 0x0037). The first time is treated as regular string, the second as unicode.

First of all I am using the file [unicode-mapi-attr-name.tnef](https://github.com/verdammelt/tnef/blob/master/tests/files/datafiles/unicode-mapi-attr-name.tnef) as usecase The raw data is ucs2 so utf8 cannot work (I guess), please have a look to the new commit that should fix the debugging statement (at least on my system, I am not sure which is the default coding for TQString, otherwise it should be set in advance). The above referenced TNEF file has unicode chars even in strings advertised as not unicode (so probably it's buggy). You can see in the GUI with Action -> Message Properties looking at the subject property. I don't know anything about MAPI details (and I am not interested to know more :-) ), but it seems that the message subject is repeated twice in the file, the first time as "stand-alone" property (0x8004) and the second one in the MAPI properties (tag 0x0037). The first time is treated as regular string, the second as unicode.
MicheleC closed this pull request 5 年之前
MicheleC 刪除分支 bug/307 5 年之前
所有者

Thanks Fabio, looks good. Merged and closed.

Keep up the good work 😉

Thanks Fabio, looks good. Merged and closed. Keep up the good work :wink:
MicheleC 新增至R14.0.6 release 里程碑 5 年之前
The pull request has been merged as 1340cc3235.
登入 才能加入這對話。
No reviewers
未選擇里程碑
No Assignees
3 參與者
訊息
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: TDE/tdepim#11
Loading…
尚未有任何內容