pmarti/python-messaging

Solution to problems with Polish characters

TKasperczyk opened this issue · 0 comments

Hi,

Your library isn't properly converting Polish characters like ą, ś, ę, ć etc. from UTF-8 to UCS2. The resulting data in the PDU gets malformed and after sending it through a GSM modem, the text becomes just a bunch of random characters.
To fix that, you need to change your pack_8bits_to_ucs2 function in messaging/utils.py. Here's how it should look like in order for it to work properly with Polish chars:

def pack_8bits_to_ucs2(message, udh=None):
    # XXX: This does not control the size respect to UDH
    text = message
    nmesg = ''

    if udh is not None:
        text = udh.encode('utf-8', 'ignore') + text

    for n in unicode(text, "utf-8"):
        nmesg += chr(ord(n) >> 8) + chr(ord(n) & 0xFF)
    mlen = len(text.decode("utf-8")) * 2
    message = chr(mlen) + nmesg
    return encode_str(message)