Ejemplo n.º 1
0
    def _incoming_pdu_to_msg(self, pdu):
        if pdu.text is None or len(pdu.text) == 0:
            self.modem._log('Blank inbound text, ignoring')
            return

        msg = message.IncomingMessage(self, pdu.address, pdu.sent_ts, pdu.text)
        return msg
Ejemplo n.º 2
0
    def _incoming_to_msg(self, timestamp, sender, text):

        # since neither message notifications nor messages
        # fetched from storage give any indication of their
        # encoding, we're going to have to guess. if the
        # text has a multiple-of-four length and starts
        # with a UTF-16 Byte Order Mark, try to decode it
        # into a unicode string
        try:
            if (len(text) % 4 == 0) and (len(text) > 0):
                bom = text[:4].lower()
                if bom == "fffe"\
                or bom == "feff":

                    # decode the text into a unicode string,
                    # so developers embedding pyGSM need never
                    # experience this confusion and pain
                    text = text.decode("hex").decode("utf-16")

        # oh dear. it looked like hex-encoded utf-16,
        # but wasn't. who sends a message like that?!
        except:
            pass

        # create and store the IncomingMessage object
        time_sent = None
        if timestamp is not None:
            time_sent = self._parse_incoming_timestamp(timestamp)
        return message.IncomingMessage(self, sender, time_sent, text)
Ejemplo n.º 3
0
    def _add_incoming(self, timestamp, sender, text):

        # since neither message notifications nor messages
        # fetched from storage give any indication of their
        # encoding, we're going to have to guess. if the
        # text has a multiple-of-four length and starts
        # with a UTF-16 Byte Order Mark, try to decode it
        # into a unicode string
        try:
            if (len(text) % 4 == 0) and (len(text) > 0):
                if re.match('^[0-9A-F]+$', text):

                    # insert a bom if there isn't one
                    bom = text[:4].lower()
                    if bom != "fffe" and bom != "feff":
                        text = "feff" + text

                    # decode the text into a unicode string,
                    # so developers embedding pyGSM need never
                    # experience this confusion and pain
                    text = text.decode("hex").decode("utf-16")

        # oh dear. it looked like hex-encoded utf-16,
        # but wasn't. who sends a message like that?!
        except:
            pass

        # create and store the IncomingMessage object
        self._log("Adding incoming message")
        time_sent = self._parse_incoming_timestamp(timestamp)
        msg = message.IncomingMessage(self, sender, time_sent, text)
        self.incoming_queue.append(msg)
        return msg