Alexander Sashnov <[EMAIL PROTECTED]> writes:

>> I have just tested with my two ICQ acounts and it seems to work.
>
> I create another test account and test offline messages between 2 test ICQ 
> accounts.
>
> And it works.
>
> Why it not work with my primary ICQ account I now know for now.


Partially researched.

Offline messages works fine on pyicq-t-0.8a

But it have some problems with away status with non-ascii text.


Offline messages not work on pyicq-t-0.8a with patch for fix backtraces
like this:

Unhandled error in Deferred:
Traceback (most recent call last):
  File "/home/alex/pj/pyicq-t/src/tlib/oscar.py", line 647, in dataReceived
    state=func(flap)
  File "/home/alex/pj/pyicq-t/src/tlib/oscar.py", line 756, in oscar_Data
    d.callback(snac)
  File "/usr/lib/python2.4/site-packages/twisted/internet/defer.py", line 239, 
in callback
    self._startRunCallbacks(result)
  File "/usr/lib/python2.4/site-packages/twisted/internet/defer.py", line 304, 
in _startRunCallbacks
    self._runCallbacks()
--- <exception caught here> ---
  File "/usr/lib/python2.4/site-packages/twisted/internet/defer.py", line 317, 
in _runCallbacks
    self.result = callback(self.result, *args, **kw)
  File "/home/alex/pj/pyicq-t/src/legacy/icqt.py", line 330, in sendAwayPresence
    LogEvent(INFO, self.session.jabberID, "Away (%s, %s) message %s" % 
(charset, msg[0], status))
exceptions.UnicodeDecodeError: 'utf8' codec can't decode bytes in position 
19-22: invalid data



Here is the patch (not from me, I just find it on forum):


diff -ur /home/alex/pj/pyicq-t/src/globals.py 
/home/alex/tmp/pyicq_on_make/src/globals.py
--- /home/alex/pj/pyicq-t/src/globals.py        2007-09-21 09:37:07.000000000 
+0700
+++ /home/alex/tmp/pyicq_on_make/src/globals.py 2007-09-26 11:33:34.000000000 
+0700
@@ -37,6 +37,7 @@
 XAVATAR                = "jabber:x:avatar"
 XCONFERENCE    = "jabber:x:conference"
 XDATA          = "jabber:x:data"
+XDELAY         = "jabber:x:delay"
 XEVENT         = "jabber:x:event"
 XHTML          = "http://jabber.org/protocol/xhtml-im";
 SAPO_NOERROR   = "sapo:noerror"


diff -ur /home/alex/pj/pyicq-t/src/jabw.py 
/home/alex/tmp/pyicq_on_make/src/jabw.py
--- /home/alex/pj/pyicq-t/src/jabw.py   2007-09-21 09:37:07.000000000 +0700
+++ /home/alex/tmp/pyicq_on_make/src/jabw.py    2007-09-26 11:33:34.000000000 
+0700
@@ -22,7 +22,7 @@
 
        if delay:
                x = el.addElement("x")
-               x.attributes["xmlns"] = globals.IQDELAY
+               x.attributes["xmlns"] = globals.XDELAY
                x.attributes["from"] = fro
                x.attributes["stamp"] = delay
 


diff -ur /home/alex/pj/pyicq-t/src/legacy/icqt.py 
/home/alex/tmp/pyicq_on_make/src/legacy/icqt.py
--- /home/alex/pj/pyicq-t/src/legacy/icqt.py    2007-09-21 09:37:06.000000000 
+0700
+++ /home/alex/tmp/pyicq_on_make/src/legacy/icqt.py     2007-09-26 
11:33:32.000000000 +0700
@@ -153,6 +153,11 @@
                                status = status.decode("iso-8859-1", "replace")
                if status == "Away" or status=="I am currently away from the 
computer." or status=="I am away from my computer right now.":
                        status = ""
+               try:
+                       status = status.decode("utf16be", "replace")
+                       debug.log("mxx: icqt status.decode utf16be")
+               except:
+                       pass
                if user.idleTime:
                        if user.idleTime>60*24:
                                idle_time = "Idle %d 
days"%(user.idleTime/(60*24))
@@ -176,7 +181,6 @@
 
                if user.caps:
                        self.oscarcon.legacyList.setCapabilities(user.name, 
user.caps)
-               status = status.encode("utf-8", "replace")
                if user.flags.count("away"):
                        
self.getAway(user.name).addCallback(self.sendAwayPresence, user)
                else:
@@ -201,7 +205,7 @@
                c.updatePresence(show=show, status=status, ptype=ptype)
                self.oscarcon.legacyList.updateSSIContact(user.name, 
presence=ptype, show=show, status=status)
 
-       def receiveMessage(self, user, multiparts, flags):
+       def receiveMessage(self, user, multiparts, flags, delay=None):
                from glue import icq2jid
 
                LogEvent(INFO, self.session.jabberID, "%s %s %s" % (user.name, 
multiparts, flags))
@@ -224,7 +228,7 @@
                if "auto" in flags:
                        mtype = "headline"
 
-               self.session.sendMessage(to=self.session.jabberID, 
fro=sourcejid, body=text, mtype=mtype, xhtml=xhtml)
+               self.session.sendMessage(to=self.session.jabberID, 
fro=sourcejid, body=text, mtype=mtype, delay=delay, xhtml=xhtml)
                
self.session.pytrans.serviceplugins['Statistics'].stats['IncomingMessages'] += 1
                
self.session.pytrans.serviceplugins['Statistics'].sessionUpdate(self.session.jabberID,
 'IncomingMessages', 1)
                if not config.disableAwayMessage and self.awayMessage and not 
"auto" in flags:
@@ -306,11 +310,12 @@
                else:
                        show = 'away'
 
-               status = oscar.dehtml(msg[1]) # Removes any HTML tags
+               #status = oscar.dehtml(msg[1]) # Removes any HTML tags
+               status = msg[1]
                url = user.url
 
                if status != None:
-                       charset = "iso-8859-1"
+                       charset = config.encoding
                        m = None
                        if msg[0]:
                                m = re.search('charset="(.+)"', msg[0])
@@ -327,7 +332,14 @@
                                        status = msg[0] + ": " + status
 
                        status = status.decode(charset, 'replace')
-                       LogEvent(INFO, self.session.jabberID, "Away (%s, %s) 
message %s" % (charset, msg[0], status))
+                       if charset == 'utf-16be':
+                               status = status.encode(config.encoding, 
'replace')
+                       status = oscar.dehtml(status) # Removes any HTML tags
+                       try:
+                               LogEvent(INFO, self.session.jabberID, "Away 
(%s, %s) message %s" % (charset, msg[0], status))
+                       except:
+                               LogEvent(INFO, self.session.jabberID, "Away 
broken (%s, s) message s" % (charset))
+                               pass
 
                if status == "Away" or status=="I am currently away from the 
computer." or status=="I am away from my computer right now.":
                        status = ""


diff -ur /home/alex/pj/pyicq-t/src/main.py 
/home/alex/tmp/pyicq_on_make/src/main.py
--- /home/alex/pj/pyicq-t/src/main.py   2007-09-21 09:37:07.000000000 +0700
+++ /home/alex/tmp/pyicq_on_make/src/main.py    2007-09-26 11:33:34.000000000 
+0700
@@ -89,7 +89,10 @@
        import signal
        signal.signal(signal.SIGHUP, reloadConfig)
        # Load scripts for PID and daemonizing
-       from twisted.scripts import twistd
+       try:
+               from twisted.scripts import _twistd_unix as twistd
+       except:
+               from twisted.scripts import twistd
 
 selectWarning = "Unable to install any good reactors (kqueue, cf, epoll, 
poll).\nWe fell back to using select. You may have scalability problems.\nThis 
reactor will not support more than 1024 connections +at a time.  You may 
silence this message by choosing 'select' or 'default' as your reactor in the 
transport config."
 if config.reactor and len(config.reactor) > 0:


diff -ur /home/alex/pj/pyicq-t/src/tlib/oscar.py 
/home/alex/tmp/pyicq_on_make/src/tlib/oscar.py
--- /home/alex/pj/pyicq-t/src/tlib/oscar.py     2007-09-21 09:37:06.000000000 
+0700
+++ /home/alex/tmp/pyicq_on_make/src/tlib/oscar.py      2007-09-26 
11:33:47.000000000 +0700
@@ -19,6 +19,7 @@
 
 from scheduler import Scheduler
 
+import config
 import struct
 import md5
 import string
@@ -199,7 +200,7 @@
 # in the docutils extension module
 # see http://docutils.sourceforge.net
 # modified for better use here
-def guess_encoding(data, defaultencoding='iso-8859-1'):
+def guess_encoding(data, defaultencoding=config.encoding):
     """
     Given a byte string, attempt to decode it.
     Tries 'utf-16be, 'utf-8' and 'iso-8859-1' (or something else) encodings.
@@ -870,7 +871,7 @@
         self.connectPort = 5190
         # Note that this is "no unicode" default encoding
         # We use unicode if it's there
-        self.defaultEncoding = 'iso-8859-1'
+        self.defaultEncoding = config.encoding
 
         if not self.capabilities:
             self.capabilities = [CAP_CHAT]
@@ -1641,12 +1642,12 @@
                     # Offline message
                     senderuin = struct.unpack('<I',v[10:14])[0]
                     #print "senderuin: "+str(senderuin)+"\n"
-                    msg_date = str( "%4d-%02d-%02d %02d:%02d"
-                                    % struct.unpack('<HBBBB', v[14:20]) )
+                    msg_date = str( "%4d-%02d-%02dT%02d:%02d:00Z" #XEP-091 
date format
+                                 % struct.unpack('<HBBBB', v[14:20]) )
                     messagetype, messageflags,messagelen = 
struct.unpack('<BBH',v[20:24])
                     umessage, encoding = 
guess_encoding(v[24:24+messagelen-1],self.defaultEncoding)
                     log.msg("Converted message, encoding %r: %r" % (encoding, 
umessage))
-                    umessage = umessage + "\n\n/sent " + msg_date
+                    #umessage = umessage + "\n\n/sent " + msg_date
                     message = [ umessage.encode("utf-16be"), "unicode" ]
                     #message = [ str( v[24:24+messagelen-1] )
                     #            + "\n\n/sent " + msg_date ]
@@ -1657,7 +1658,7 @@
                         tlvs = dict()
                         multiparts.append(tuple(message))
                         user = OSCARUser(str(senderuin), None, tlvs)
-                        self.receiveMessage(user, multiparts, flags)
+                        self.receiveMessage(user, multiparts, flags, msg_date)
                 elif (type == 0x42):
                     # End of offline messages
                     reqdata = 
'\x08\x00'+struct.pack("<I",int(self.username))+'\x3e\x00\x02\x00'
@@ -2022,14 +2023,14 @@
                     charSet = 0x0000
                 except:
                     try:
-                        part[0] = part[0].encode('iso-8859-1')
+                        part[0] = part[0].encode(config.encoding)
                         charSet = 0x0003
                     except:
                         try:
                             part[0] = part[0].encode('utf-16be', 'replace')
                             charSet = 0x0002
                         except:
-                            part[0] = part[0].encode('iso-8859-1', 'replace')
+                            part[0] = part[0].encode(config.encoding, 
'replace')
                             charSet = 0x0003
             if 'macintosh' in part[1:]:
                 charSubSet = 0x000b
@@ -2042,7 +2043,7 @@
         # We'll investigate this in more detail later.
         features = '\x01\x01\x02'
         # Why do i need to encode this?  I shouldn't .. it's data.
-        data = data.encode('iso-8859-1', 'replace') + TLV(2, TLV(0x0501, 
features)+messageData)
+        data = data.encode(config.encoding, 'replace') + TLV(2, TLV(0x0501, 
features)+messageData)
         if wantAck:
             log.msg("sendMessage: Sending wanting ACK")
             data = data + TLV(3)




Seems this patch is not correct, so I will remove them.

But question with away messages incoding is open, I think changes like this

-      part[0] = part[0].encode('iso-8859-1')
+      part[0] = part[0].encode(config.encoding)

reasonable.

-- 
Alexander Sashnov

_______________________________________________
py-transports mailing list
py-transports@blathersource.org
http://lists.modevia.com/cgi-bin/mailman/listinfo/py-transports

Reply via email to