def _receipt_received(self, event, received): receipt_id = received.getAttr('id') if receipt_id is None: log.warning('Receipt without ID: %s', event.stanza) return log.info('Received %s', receipt_id) app.nec.push_incoming_event( NetworkIncomingEvent('receipt-received', conn=self._con, receipt_id=receipt_id, jid=event.jid))
def _server_items_info_received(self, from_, *args): from_ = from_.getStripped() log.info('Server item info received: %s', from_) self._parse_transports(from_, *args) try: self._con.get_module('MUC').pass_disco(from_, *args) self._con.get_module('HTTPUpload').pass_disco(from_, *args) self._con.pass_bytestream_disco(from_, *args) except nbxmpp.NodeProcessed: pass app.nec.push_incoming_event( NetworkIncomingEvent('server-disco-received'))
def _server_items_info_received(self, result): if is_error_result(result): self._log.warning('Server item disco info failed') self._log.warning(result) return self._log.info('Server item info received: %s', result.jid) self._parse_transports(result) try: self._con.get_module('MUC').pass_disco(result) self._con.get_module('HTTPUpload').pass_disco(result) self._con.get_module('Bytestream').pass_disco(result) except nbxmpp.NodeProcessed: pass app.nec.push_incoming_event( NetworkIncomingEvent('server-disco-received'))
def _mam_message_received(self, _con, stanza, properties): if not properties.is_mam_message: return app.nec.push_incoming_event( NetworkIncomingEvent('mam-message-received', account=self._account, stanza=stanza, properties=properties)) if not self._from_valid_archive(stanza, properties): self._log.warning('Message from invalid archive %s', properties.mam.archive) raise nbxmpp.NodeProcessed self._log.info('Received message from archive: %s', properties.mam.archive) if not self._is_valid_request(properties): self._log.warning('Invalid MAM Message: unknown query id %s', properties.mam.query_id) self._log.debug(stanza) raise nbxmpp.NodeProcessed is_groupchat = properties.type.is_groupchat if is_groupchat: kind = KindConstant.GC_MSG else: if properties.from_.bareMatch(self._con.get_own_jid()): kind = KindConstant.CHAT_MSG_SENT else: kind = KindConstant.CHAT_MSG_RECV stanza_id, message_id = self._get_unique_id(properties) if properties.mam.is_ver_2: # Search only with stanza-id for duplicates on mam:2 if app.logger.find_stanza_id(self._account, str(properties.mam.archive), stanza_id, message_id, groupchat=is_groupchat): self._log.info( 'Found duplicate with stanza-id: %s, ' 'message-id: %s', stanza_id, message_id) raise nbxmpp.NodeProcessed additional_data = AdditionalDataDict() if properties.has_user_delay: # Record it as a user timestamp additional_data.set_value('gajim', 'user_timestamp', properties.user_timestamp) parse_oob(properties, additional_data) msgtxt = properties.body if properties.is_encrypted: additional_data['encrypted'] = properties.encrypted.additional_data else: if properties.eme is not None: msgtxt = get_eme_message(properties.eme) if not msgtxt: # For example Chatstates, Receipts, Chatmarkers self._log.debug(stanza.getProperties()) return with_ = properties.jid.getStripped() if properties.is_muc_pm: # we store the message with the full JID with_ = str(with_) if properties.is_self_message: # Self messages can only be deduped with origin-id if message_id is None: self._log.warning('Self message without origin-id found') return stanza_id = message_id if properties.mam.namespace == nbxmpp.NS_MAM_1: if app.logger.search_for_duplicate(self._account, with_, properties.mam.timestamp, msgtxt): self._log.info('Found duplicate with fallback for mam:1') return app.logger.insert_into_logs(self._account, with_, properties.mam.timestamp, kind, unread=False, message=msgtxt, contact_name=properties.muc_nickname, additional_data=additional_data, stanza_id=stanza_id, message_id=properties.id) app.nec.push_incoming_event( NetworkEvent( 'mam-decrypted-message-received', account=self._account, additional_data=additional_data, correct_id=parse_correction(properties), archive_jid=properties.mam.archive, msgtxt=properties.body, properties=properties, kind=kind, ))
def _mam_message_received(self, _con, stanza, properties): if not properties.is_mam_message: return app.nec.push_incoming_event( NetworkIncomingEvent('raw-mam-message-received', conn=self._con, stanza=stanza)) if not self._from_valid_archive(stanza, properties): self._log.warning('Message from invalid archive %s', properties.mam.archive) raise nbxmpp.NodeProcessed self._log.info('Received message from archive: %s', properties.mam.archive) if not self._is_valid_request(properties): self._log.warning('Invalid MAM Message: unknown query id %s', properties.mam.query_id) self._log.debug(stanza) raise nbxmpp.NodeProcessed event_attrs = {} groupchat = properties.type.is_groupchat if groupchat: event_attrs.update(self._parse_gc_attrs(properties)) else: event_attrs.update(self._parse_chat_attrs(stanza, properties)) stanza_id, message_id = self._get_unique_id(properties) if properties.mam.is_ver_2: # Search only with stanza-id for duplicates on mam:2 if app.logger.find_stanza_id(self._account, str(properties.mam.archive), stanza_id, message_id, groupchat=groupchat): self._log.info( 'Found duplicate with stanza-id: %s, ' 'message-id: %s', stanza_id, message_id) raise nbxmpp.NodeProcessed additional_data = AdditionalDataDict() if properties.has_user_delay: # Record it as a user timestamp additional_data.set_value('gajim', 'user_timestamp', properties.user_timestamp) event_attrs.update({ 'conn': self._con, 'account': self._account, 'additional_data': additional_data, 'encrypted': False, 'timestamp': properties.mam.timestamp, 'self_message': properties.is_self_message, 'groupchat': groupchat, 'muc_pm': properties.is_muc_pm, 'stanza_id': stanza_id, 'origin_id': message_id, 'message_id': properties.id, 'correct_id': None, 'archive_jid': properties.mam.archive, 'msgtxt': properties.body, 'message': stanza, 'stanza': stanza, 'namespace': properties.mam.namespace, }) if groupchat: event = MamGcMessageReceivedEvent(None, **event_attrs) else: event = MamMessageReceivedEvent(None, **event_attrs) if properties.is_encrypted: event.additional_data[ 'encrypted'] = properties.encrypted.additional_data self._decryption_finished(event) else: app.plugin_manager.extension_point('decrypt', self._con, event, self._decryption_finished) if not event.encrypted: if properties.eme is not None: event.msgtxt = get_eme_message(properties.eme) self._decryption_finished(event) raise nbxmpp.NodeProcessed
def _mam_message_received(self, conn, stanza): app.nec.push_incoming_event( NetworkIncomingEvent('raw-mam-message-received', conn=self._con, stanza=stanza)) result = stanza.getTag('result', protocol=True) queryid = result.getAttr('queryid') forwarded = result.getTag('forwarded', namespace=nbxmpp.NS_FORWARD, protocol=True) message = forwarded.getTag('message', protocol=True) groupchat = message.getType() == 'groupchat' archive_jid = self._from_valid_archive(stanza, message, groupchat) if archive_jid is None: log.warning('Message from invalid archive %s', stanza) raise nbxmpp.NodeProcessed log.info('Received message from archive: %s', archive_jid) if not self._is_valid_request(archive_jid, queryid): log.warning('Invalid MAM Message: unknown query id') log.debug(stanza) raise nbxmpp.NodeProcessed # Timestamp parsing timestamp = parse_delay(forwarded) if timestamp is None: raise nbxmpp.NodeProcessed user_timestamp = parse_delay(message) # Fix for self messaging if not groupchat: to = message.getTo() if to is None: # Some servers dont set the 'to' attribute when # we send a message to ourself message.setTo(self._con.get_own_jid()) event_attrs = {} if groupchat: event_attrs.update(self._parse_gc_attrs(message)) else: event_attrs.update(self._parse_chat_attrs(message)) self_message = is_self_message(message, groupchat) muc_pm = is_muc_pm(message, event_attrs['with_'], groupchat) stanza_id, origin_id = self._get_unique_id(result, message, groupchat, self_message, muc_pm) message_id = message.getID() # Check for duplicates namespace = self.archiving_namespace if groupchat: namespace = muc_caps_cache.get_mam_namespace( archive_jid.getStripped()) if namespace == nbxmpp.NS_MAM_2: # Search only with stanza-id for duplicates on mam:2 if app.logger.find_stanza_id(self._account, archive_jid.getStripped(), stanza_id, origin_id, groupchat=groupchat): log.info('Found duplicate with stanza-id') raise nbxmpp.NodeProcessed msgtxt = message.getTagData('body') event_attrs.update({ 'conn': self._con, 'additional_data': {}, 'encrypted': False, 'timestamp': timestamp, 'user_timestamp': user_timestamp, 'self_message': self_message, 'groupchat': groupchat, 'muc_pm': muc_pm, 'stanza_id': stanza_id, 'origin_id': origin_id, 'message_id': message_id, 'correct_id': None, 'archive_jid': archive_jid, 'msgtxt': msgtxt, 'message': message, 'namespace': namespace, }) if groupchat: event = MamGcMessageReceivedEvent(None, **event_attrs) else: event = MamMessageReceivedEvent(None, **event_attrs) app.plugin_manager.extension_point('decrypt', self._con, event, self._decryption_finished) if not event.encrypted: eme = parse_eme(event.message) if eme is not None: event.msgtxt = eme self._decryption_finished(event) raise nbxmpp.NodeProcessed