Example #1
0
    def parse(self, chunk):
        HTTPMessage.parse(self, chunk)

        content_type = self.headers.get("Content-Type", "null")
        
        raw_body = self.body
        self.body = SLPMessageBody.build(content_type, raw_body)
Example #2
0
    def parse(self, chunk):
        HTTPMessage.parse(self, chunk)

        content_type = self.headers.get("Content-Type", "null")

        raw_body = self.body
        self.body = SLPMessageBody.build(content_type, raw_body)
Example #3
0
 def __init__(self, sender=None, message=""):
     """Initializer
         
         @param message: The body of the message, it is put after the headers
         @type message: string"""
     HTTPMessage.__init__(self)
     self.sender = sender
     if message:
         self.parse(message)
Example #4
0
 def __init__(self, sender=None, message=""):
     """Initializer
         
         @param message: The body of the message, it is put after the headers
         @type message: string"""
     HTTPMessage.__init__(self)
     self.sender = sender
     if message:
         self.parse(message)
Example #5
0
    def __init__(self, content_type, session_id=None, s_channel_state=0, capabilities_flags=1):
        HTTPMessage.__init__(self)
        self.content_type = content_type

        if session_id is not None:
            self.add_header("SessionID", session_id)
        if s_channel_state is not None:
            self.add_header("SChannelState", s_channel_state)
        if capabilities_flags is not None:
            self.add_header("Capabilities-Flags", capabilities_flags)
Example #6
0
    def __init__(self, to="", frm="", branch="", cseq=0, call_id="", max_forwards=0):
        HTTPMessage.__init__(self)
        self.add_header("To", "<msnmsgr:%s>" % to)
        self.add_header("From", "<msnmsgr:%s>" % frm)
        if branch:
            self.add_header("Via", "MSNSLP/1.0/TLP ;branch=%s" % branch)
        self.add_header("CSeq", str(cseq))
        if call_id:
            self.add_header("Call-ID", call_id)
        self.add_header("Max-Forwards", str(max_forwards))

        # Make the body a SLP Message wih "null" content type
        self.body = SLPNullBody()
Example #7
0
    def __init__(self,
                 content_type,
                 session_id=None,
                 s_channel_state=0,
                 capabilities_flags=1):
        HTTPMessage.__init__(self)
        self.type = content_type

        if session_id is not None:
            self.add_header("SessionID", session_id)
        if s_channel_state is not None:
            self.add_header("SChannelState", s_channel_state)
        if capabilities_flags is not None:
            self.add_header("Capabilities-Flags", capabilities_flags)
Example #8
0
    def __str__(self):
        if self.body is None:
            self.add_header("Content-Type", "null")
            self.add_header("Content-Length", 0)
        else:
            self.add_header("Content-Type", self.body.type)
            self.add_header("Content-Length", len(str(self.body)))

        return HTTPMessage.__str__(self)
Example #9
0
 def __str__(self):
     if self.body is None:
         self.add_header("Content-Type", "null")
         self.add_header("Content-Length", 0)
     else:
         self.add_header("Content-Type", self.body.content_type)
         self.add_header("Content-Length", len(str(self.body)))
         
     return HTTPMessage.__str__(self)
Example #10
0
    def __init__(self,
                 to="",
                 frm="",
                 branch="",
                 cseq=0,
                 call_id="",
                 max_forwards=0):
        HTTPMessage.__init__(self)
        self.add_header("To", "<msnmsgr:%s>" % to)
        self.add_header("From", "<msnmsgr:%s>" % frm)
        if branch:
            self.add_header("Via", "MSNSLP/1.0/TLP ;branch=%s" % branch)
        self.add_header("CSeq", str(cseq))
        if call_id:
            self.add_header("Call-ID", call_id)
        self.add_header("Max-Forwards", str(max_forwards))

        # Make the body a SLP Message wih "null" content type
        self.body = SLPNullBody()
Example #11
0
    def _handle_MSG(self, command):
        message = Message(None, command.payload)
        content_type = message.content_type
        if content_type[0] == 'text/x-msmsgsprofile':
            profile = {}
            lines = command.payload.split("\r\n")
            for line in lines:
                line = line.strip()
                if line:
                    name, value = line.split(":", 1)
                    profile[name] = value.strip()
            self._client.profile._server_property_changed("profile", profile)

            self.set_privacy(self._client.profile.privacy)
            self._state = ProtocolState.SYNCHRONIZING
            self._client.address_book.sync()
        elif content_type[0] in \
                ('text/x-msmsgsinitialmdatanotification', \
                 'text/x-msmsgsoimnotification'):
            if self._client.oim_box is not None:
                self._client.oim_box._state = \
                    OIM.OfflineMessagesBoxState.NOT_SYNCHRONIZED
                m = HTTPMessage()
                m.parse(message.body)
                mail_data = m.get_header('Mail-Data').strip()
                if mail_data == 'too-large':
                    mail_data = None
                self._client.oim_box.sync(mail_data)
                if mail_data and \
                   content_type[0] == 'text/x-msmsgsinitialmdatanotification':
                    #Initial mail
                    start = mail_data.find('<IU>') + 4
                    end = mail_data.find('</IU>')
                    if start < end:
                        mailbox_unread = int(mail_data[start:end])
                        self._client.mailbox._initial_set(mailbox_unread)
        elif content_type[0] == 'text/x-msmsgsinitialemailnotification':
            #Initial mail (obsolete by MSNP11)
            pass
        elif content_type[0] == 'text/x-msmsgsemailnotification':
            #New mail
            m = HTTPMessage()
            m.parse(message.body)
            name = decode_rfc2047_string(m.get_header('From'))
            address = m.get_header('From-Addr')
            subject = decode_rfc2047_string(m.get_header('Subject'))
            message_url = m.get_header('Message-URL')
            post_url = m.get_header('Post-URL')
            post_id = m.get_header('id')
            dest = m.get_header('Dest-Folder')
            if dest == 'ACTIVE':
                self._client.mailbox._unread_mail_increased(1)
                build = self._build_url_post_data
                post_url, form_data = build(message_url, post_url, post_id)
                self._client.mailbox._new_mail(name, address, subject,
                                               post_url, form_data)
        elif content_type[0] == 'text/x-msmsgsactivemailnotification':
            #Movement of unread mail
            m = HTTPMessage()
            m.parse(message.body)
            src = m.get_header('Src-Folder')
            dest = m.get_header('Dest-Folder')
            delta = int(m.get_header('Message-Delta'))
            if src == 'ACTIVE':
                self._client.mailbox._unread_mail_decreased(delta)
            elif dest == 'ACTIVE':
                self._client.mailbox._unread_mail_increased(delta)
Example #12
0
 def __str__(self):
     return HTTPMessage.__str__(self) + "\x00"
Example #13
0
 def parse(self, data):
     if len(data) == 0:
         return
     data = data.rstrip('\x00')
     HTTPMessage.parse(self, data)
Example #14
0
    def _handle_MSG(self, command):
        message = Message(None, command.payload)
        content_type = message.content_type
        if content_type[0] == 'text/x-msmsgsprofile':
            self._client.profile._server_property_changed("profile",
                    command.payload)

            if self._protocol_version < 15:
                #self._send_command('SYN', ('0', '0'))
                raise NotImplementedError, "Missing Implementation, please fix"
            else:
                self._send_command("BLP",
                        (self._client.profile.privacy,))
                self._state = ProtocolState.SYNCHRONIZING
                self._client.address_book.sync()
        elif content_type[0] in \
                ('text/x-msmsgsinitialmdatanotification', \
                 'text/x-msmsgsoimnotification'):
            if self._client.oim_box is not None:
                self._client.oim_box._state = \
                    OIM.OfflineMessagesBoxState.NOT_SYNCHRONIZED
                m = HTTPMessage()
                m.parse(message.body)
                mail_data = m.get_header('Mail-Data').strip()
                if mail_data == 'too-large':
                    mail_data = None
                self._client.oim_box.sync(mail_data)
                if mail_data and \
                   content_type[0] == 'text/x-msmsgsinitialmdatanotification':
                    #Initial mail
                    start = mail_data.find('<IU>') + 4
                    end = mail_data.find('</IU>')
                    if start < end:
                        mailbox_unread = int(mail_data[start:end])
                        self._client.mailbox._initial_set(mailbox_unread)
                        
        elif content_type[0] == 'text/x-msmsgsinitialemailnotification':
            #Initial mail (obsolete by MSNP11)
            pass
        elif content_type[0] == 'text/x-msmsgsemailnotification':
            #New mail
            m = HTTPMessage()
            m.parse(message.body)
            name = m.get_header('From')
            address = m.get_header('From-Addr')
            subject = m.get_header('Subject')
            message_url = m.get_header('Message-URL')
            post_url = m.get_header('Post-URL')
            post_id = m.get_header('id')
            dest = m.get_header('Dest-Folder')
            if dest == 'ACTIVE':
                self._client.mailbox._unread_mail_increased(1)
                build = self._build_url_post_data
                post_url, form_data = build(message_url, post_url, post_id)
                self._client.mailbox._new_mail(name, address, subject,
                                               post_url, form_data)
        elif content_type[0] == 'text/x-msmsgsactivemailnotification':
            #Movement of unread mail
            m = HTTPMessage()
            m.parse(message.body)
            src = m.get_header('Src-Folder')
            dest = m.get_header('Dest-Folder')
            delta = int(m.get_header('Message-Delta'))
            if src == 'ACTIVE':
                self._client.mailbox._unread_mail_decreased(delta)
            elif dest == 'ACTIVE':
                self._client.mailbox._unread_mail_increased(delta)
Example #15
0
    def _handle_MSG(self, command):
        message = Message(None, command.payload)
        content_type = message.content_type
        if content_type[0] == 'text/x-msmsgsprofile':
            profile = {}
            lines = command.payload.split("\r\n")
            for line in lines:
                line = line.strip()
                if line:
                    name, value = line.split(":", 1)
                    profile[name] = value.strip()
            self._client.profile._server_property_changed("profile", profile)

            self._send_command("BLP", (self._client.profile.privacy, ))
            self._state = ProtocolState.SYNCHRONIZING
            self._client.address_book.sync()
        elif content_type[0] in \
                ('text/x-msmsgsinitialmdatanotification', \
                 'text/x-msmsgsoimnotification'):
            if self._client.oim_box is not None:
                self._client.oim_box._state = \
                    OIM.OfflineMessagesBoxState.NOT_SYNCHRONIZED
                m = HTTPMessage()
                m.parse(message.body)
                mail_data = m.get_header('Mail-Data').strip()
                if mail_data == 'too-large':
                    mail_data = None
                self._client.oim_box.sync(mail_data)
                if mail_data and \
                   content_type[0] == 'text/x-msmsgsinitialmdatanotification':
                    #Initial mail
                    start = mail_data.find('<IU>') + 4
                    end = mail_data.find('</IU>')
                    if start < end:
                        mailbox_unread = int(mail_data[start:end])
                        self._client.mailbox._initial_set(mailbox_unread)
        elif content_type[0] == 'text/x-msmsgsinitialemailnotification':
            #Initial mail (obsolete by MSNP11)
            pass
        elif content_type[0] == 'text/x-msmsgsemailnotification':
            #New mail
            m = HTTPMessage()
            m.parse(message.body)
            name = m.get_header('From')
            address = m.get_header('From-Addr')
            subject = m.get_header('Subject')
            message_url = m.get_header('Message-URL')
            post_url = m.get_header('Post-URL')
            post_id = m.get_header('id')
            dest = m.get_header('Dest-Folder')
            if dest == 'ACTIVE':
                self._client.mailbox._unread_mail_increased(1)
                build = self._build_url_post_data
                post_url, form_data = build(message_url, post_url, post_id)
                self._client.mailbox._new_mail(name, address, subject,
                                               post_url, form_data)
        elif content_type[0] == 'text/x-msmsgsactivemailnotification':
            #Movement of unread mail
            m = HTTPMessage()
            m.parse(message.body)
            src = m.get_header('Src-Folder')
            dest = m.get_header('Dest-Folder')
            delta = int(m.get_header('Message-Delta'))
            if src == 'ACTIVE':
                self._client.mailbox._unread_mail_decreased(delta)
            elif dest == 'ACTIVE':
                self._client.mailbox._unread_mail_increased(delta)
Example #16
0
 def parse(self, data):
     if len(data) == 0:
         return
     data = data.rstrip('\x00')
     HTTPMessage.parse(self, data)
Example #17
0
 def __str__(self):
     return HTTPMessage.__str__(self) + "\x00"