How to use the nbxmpp.Message function in nbxmpp

To help you get started, we’ve selected a few nbxmpp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gajim / gajim / gajim / common / stanza_session.py View on Github external
def send(self, msg):
        if self.thread_id:
            msg.NT.thread = self.thread_id

        msg.setAttr('to', self.get_to())
        self.conn.send_stanza(msg)

        if isinstance(msg, nbxmpp.Message):
            self.last_send = time.time()
github gajim / gajim / gajim / common / stanza_session.py View on Github external
def reject_negotiation(self, body=None):
        msg = nbxmpp.Message()
        feature = msg.NT.feature
        feature.setNamespace(nbxmpp.NS_FEATURE)

        x = nbxmpp.DataForm(typ='submit')
        x.addChild(node=nbxmpp.DataField(name='FORM_TYPE',
            value='urn:xmpp:ssn'))
        x.addChild(node=nbxmpp.DataField(name='accept', value='0'))

        feature.addChild(node=x)

        if body:
            msg.setBody(body)

        self.send(msg)

        self.cancelled_negotiation()
github python-otr / pure-python-otr / src / gajim-plugin / gotr / otrmodule.py View on Github external
def inject(self, msg, appdata=None):
            log.debug('inject(appdata=%s)', appdata)
            msg = unicode(msg)
            account = self.user.accountname

            if not nb_xmpp:
                stanza = common.xmpp.Message(to=self.peer, body=msg, typ='chat')
            else:
                stanza = nbxmpp.Message(to=self.peer, body=msg, typ='chat')
            if appdata is not None:
                session = appdata.get('session', None)
                if session is not None:
                    stanza.setThread(session.thread_id)
            gajim.connections[account].connection.send(stanza, now=True)
github gajim / gajim / gajim / common / stanza_session.py View on Github external
def accept_e2e_alice(self, form, negotiated):
        """
        'Alice Accepts', continued
        """
        self.encryptable_stanzas = ['message']
        self.sas_algs = 'sas28x5'
        self.cipher = AES
        self.hash_alg = sha256
        self.compression = None

        self.negotiated = negotiated

        accept = nbxmpp.Message()
        feature = accept.NT.feature
        feature.setNamespace(nbxmpp.NS_FEATURE)

        result = nbxmpp.DataForm(typ='result')

        self.c_s = crypto.decode_mpi(base64.b64decode(form['counter']))
        self.c_o = self.c_s ^ (2 ** (self.n - 1))
        self.n_o = base64.b64decode(form['my_nonce'])

        mod_p = int(form['modp'])
        p = dh.primes[mod_p]
        x = self.xes[mod_p]
        e = self.es[mod_p]

        self.d = crypto.decode_mpi(base64.b64decode(form['dhkeys']))
        self.k = self.get_shared_secret(self.d, x, p)
github gajim / gajim / gajim / common / connection.py View on Github external
def _build_message_stanza(self, obj):
        if obj.jid == app.get_jid_from_account(self.name):
            fjid = obj.jid
        else:
            fjid = obj.get_full_jid()

        if obj.type_ == 'chat':
            msg_iq = nbxmpp.Message(body=obj.message, typ=obj.type_,
                    xhtml=obj.xhtml)
        else:
            if obj.subject:
                msg_iq = nbxmpp.Message(body=obj.message, typ='normal',
                        subject=obj.subject, xhtml=obj.xhtml)
            else:
                msg_iq = nbxmpp.Message(body=obj.message, typ='normal',
                        xhtml=obj.xhtml)

        if obj.correct_id:
            msg_iq.setTag('replace', attrs={'id': obj.correct_id},
                          namespace=nbxmpp.NS_CORRECT)

        # XEP-0359
        obj.stanza_id = self.connection.getAnID()
        msg_iq.setID(obj.stanza_id)
        if obj.message:
            msg_iq.setOriginID(obj.stanza_id)

        if obj.form_node:
github gajim / gajim / gajim / negotiation.py View on Github external
def on_cancel_button_clicked(self, widget):
        rejection = nbxmpp.Message(self.jid)
        rejection.setThread(self.session.thread_id)
        feature = rejection.NT.feature
        feature.setNamespace(nbxmpp.NS_FEATURE)

        x = nbxmpp.DataForm(typ='submit')
        x.addChild(node=nbxmpp.DataField('FORM_TYPE', value='urn:xmpp:ssn'))
        x.addChild(node=nbxmpp.DataField('accept', value='false', typ='boolean'))

        feature.addChild(node=x)

        app.connections[self.account].send_stanza(rejection)

        self.window.destroy()
github gajim / gajim / gajim / common / connection.py View on Github external
# XEP-0224
        if obj.attention:
            msg_iq.setTag('attention', namespace=nbxmpp.NS_ATTENTION)

        if isinstance(obj.jid, list):
            if self.addressing_supported:
                msg_iq.setTo(app.config.get_per('accounts', self.name, 'hostname'))
                addresses = msg_iq.addChild('addresses',
                    namespace=nbxmpp.NS_ADDRESS)
                for j in obj.jid:
                    addresses.addChild('address',
                                       attrs={'type': 'to', 'jid': j})
            else:
                iqs = []
                for j in obj.jid:
                    iq = nbxmpp.Message(node=msg_iq)
                    iq.setTo(j)
                    iqs.append(iq)
                msg_iq = iqs
        else:
            msg_iq.setTo(fjid)
            r_ = obj.resource
            if not r_ and obj.jid != fjid: # Only if we're not in a pm
                r_ = app.get_resource_from_jid(fjid)
            if r_:
                contact = app.contacts.get_contact(self.name, obj.jid, r_)
            else:
                contact = app.contacts.get_contact_with_highest_priority(
                    self.name, obj.jid)

            # Mark Message as MUC PM
            if isinstance(contact, GC_Contact):
github gajim / gajim / gajim / common / connection.py View on Github external
def _nec_gc_message_outgoing(self, obj):
        if obj.account != self.name:
            return
        if not app.account_is_connected(self.name):
            return

        if not obj.xhtml and app.config.get('rst_formatting_outgoing_messages'):
            from gajim.common.rst_xhtml_generator import create_xhtml
            obj.xhtml = create_xhtml(obj.message)

        msg_iq = nbxmpp.Message(obj.jid, obj.message, typ='groupchat',
                                xhtml=obj.xhtml)

        obj.stanza_id = self.connection.getAnID()
        msg_iq.setID(obj.stanza_id)
        if obj.message:
            msg_iq.setOriginID(obj.stanza_id)

        if obj.correct_id:
            msg_iq.setTag('replace', attrs={'id': obj.correct_id},
                          namespace=nbxmpp.NS_CORRECT)

        if obj.chatstate is not None:
            msg_iq.setTag(obj.chatstate, namespace=nbxmpp.NS_CHATSTATES)
            if not obj.message:
                msg_iq.setTag('no-store', namespace=nbxmpp.NS_MSG_HINTS)
        if obj.label is not None: