diff --git a/session.py b/session.py index 64655ec..7883305 100644 --- a/session.py +++ b/session.py @@ -29,7 +29,7 @@ import logging import urllib import time -from PIL import Image +# from PIL import Image import sys import os @@ -281,9 +281,11 @@ class Session(YowsupApp): def onTextMessage(self, _id, _from, to, notify, timestamp, participant, offline, retry, body): - self.logger.debug('received TextMessage: %s' % - [_id, _from, to, notify, timestamp, - participant, offline, retry, body] + self.logger.debug('received TextMessage' + + ' '.join(map(str, [ + _id, _from, to, notify, timestamp, + participant, offline, retry, body.encode("utf-8") + ])) ) buddy = _from.split('@')[0] messageContent = utils.softToUni(body) @@ -311,6 +313,13 @@ class Session(YowsupApp): participant = image.participant if image.caption is None: image.caption = '' + + # Add to message data for descrypt + iv, cipherKey = image.getDecryptData(); + ivHexString = "".join("{:02x}".format(ord(c)) for c in iv) + cipherKeyHexString = "".join("{:02x}".format(ord(c)) for c in cipherKey) + message = image.url + ';' + ivHexString + ';' + cipherKeyHexString + if participant is not None: # Group message partname = participant.split('@')[0] if image._from.split('@')[1] == 'broadcast': # Broadcast message diff --git a/utils.py b/utils.py index 9a5d2df..795e48a 100644 --- a/utils.py +++ b/utils.py @@ -48,7 +48,7 @@ def ago(secs): return "%d %s ago" % (diff, period) def softToUni(message): - return e4u.translate(message, reverse=False, **e4u.SOFTBANK_TRANSLATE_PROFILE) + return e4u.translate(message.encode("utf-8"), reverse=False, **e4u.SOFTBANK_TRANSLATE_PROFILE) def decodePassword(password): return base64.b64decode(bytes(password)) diff --git a/yowsupwrapper.py b/yowsupwrapper.py index c70ba8a..348f3c5 100644 --- a/yowsupwrapper.py +++ b/yowsupwrapper.py @@ -4,6 +4,7 @@ from __future__ import unicode_literals import logging from yowsup import env +from yowsup.env import S40YowsupEnv from yowsup.stacks import YowStack from yowsup.common import YowConstants from yowsup.layers import YowLayerEvent, YowParallelLayer @@ -56,8 +57,6 @@ from yowsup.registration import WARegRequest from functools import partial -#from session import MsgIDs - class YowsupApp(object): def __init__(self): env.CURRENT_ENV = env.AndroidYowsupEnv() @@ -85,8 +84,14 @@ class YowsupApp(object): YowStanzaRegulator, YowNetworkLayer ) + self.logger = logging.getLogger(self.__class__.__name__) - self.stack = YowStack(layers) + stackBuilder = YowStackBuilder() + + self.stack = stackBuilder \ + .pushDefaultLayers(True) \ + .push(YowsupAppLayer) \ + .build() self.stack.broadcastEvent( YowLayerEvent(YowsupAppLayer.EVENT_START, caller = self) )