def _on_message_decrypted(self, event): try: self.get_module('Receipts').delegate(event) except nbxmpp.NodeProcessed: return event_attr = { 'popup': False, 'msg_log_id': None, 'subject': None, 'displaymarking': None, 'form_node': None, 'attention': parse_attention(event.stanza), 'correct_id': parse_correction(event.stanza), 'user_nick': parse_nickname(event.stanza), 'xhtml': parse_xhtml(event.stanza), 'chatstate': parse_chatstate(event.stanza), 'stanza_id': event.unique_id } parse_oob(event.stanza, event.additional_data) for name, value in event_attr.items(): setattr(event, name, value) if event.mtype == 'error': if not event.msgtxt: event.msgtxt = _('message') self.dispatch_error_message(event.stanza, event.msgtxt, event.session, event.fjid, event.timestamp) return app.nec.push_incoming_event( DecryptedMessageReceivedEvent(None, **vars(event)))
def _on_message_decrypted(self, event): try: self.get_module('Receipts').delegate(event) self.get_module('Chatstate').delegate(event) except nbxmpp.NodeProcessed: return event_attr = { 'popup': False, 'msg_log_id': None, 'subject': None, 'displaymarking': None, 'form_node': None, 'attention': parse_attention(event.stanza), 'correct_id': parse_correction(event.stanza), 'user_nick': parse_nickname(event.stanza), 'xhtml': parse_xhtml(event.stanza), 'stanza_id': event.unique_id } parse_oob(event) for name, value in event_attr.items(): setattr(event, name, value) if event.mtype == 'error': if not event.msgtxt: event.msgtxt = _('message') self._log_error_message(event) error_msg = event.stanza.getErrorMsg() or event.msgtxt msgtxt = None if error_msg == event.msgtxt else event.msgtxt app.nec.push_incoming_event( MessageErrorEvent(None, conn=self, fjid=event.fjid, error_code=event.stanza.getErrorCode(), error_msg=error_msg, msg=msgtxt, time_=event.timestamp, session=event.session, stanza=event.stanza)) return app.nec.push_incoming_event( DecryptedMessageReceivedEvent(None, **vars(event)))
def _decryption_finished(self, event): if not event.msgtxt: # For example Chatstates, Receipts, Chatmarkers self._log.debug(event.message.getProperties()) return event.correct_id = parse_correction(event.message) parse_oob(event) with_ = event.with_.getStripped() if event.muc_pm: # we store the message with the full JID with_ = str(event.with_) stanza_id = event.stanza_id if event.self_message: # Self messages can only be deduped with origin-id if event.origin_id is None: self._log.warning('Self message without origin-id found') return stanza_id = event.origin_id if event.namespace == nbxmpp.NS_MAM_1: if app.logger.search_for_duplicate(self._account, with_, event.timestamp, event.msgtxt): self._log.info('Found duplicate with fallback for mam:1') return app.logger.insert_into_logs(self._account, with_, event.timestamp, event.kind, unread=False, message=event.msgtxt, contact_name=event.nick, additional_data=event.additional_data, stanza_id=stanza_id, message_id=event.message_id) app.nec.push_incoming_event( MamDecryptedMessageReceived(None, **vars(event)))
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 _on_message_decrypted(self, event): try: self._con.get_module('Receipts').delegate(event) self._con.get_module('Chatstate').delegate(event) except nbxmpp.NodeProcessed: return subject = event.stanza.getSubject() groupchat = event.mtype == 'groupchat' event_attr = { 'popup': False, 'msg_log_id': None, 'subject': subject, 'displaymarking': parse_securitylabel(event.stanza), 'attention': parse_attention(event.stanza), 'correct_id': parse_correction(event.stanza), 'user_nick': '' if event.sent else parse_nickname(event.stanza), 'form_node': parse_form(event.stanza), 'xhtml': parse_xhtml(event.stanza), } parse_oob(event) for name, value in event_attr.items(): setattr(event, name, value) if event.mtype == 'error': if not event.msgtxt: event.msgtxt = _('message') if event.gc_control: event.gc_control.add_info_message(event.msgtxt) else: self._log_error_message(event) error_msg = event.stanza.getErrorMsg() or event.msgtxt msgtxt = None if error_msg == event.msgtxt else event.msgtxt app.nec.push_incoming_event( MessageErrorEvent(None, conn=self._con, fjid=event.fjid, error_code=event.stanza.getErrorCode(), error_msg=error_msg, msg=msgtxt, time_=event.timestamp, session=event.session, stanza=event.stanza)) return if groupchat: if not event.msgtxt: return event.room_jid = event.jid event.nickname = event.resource event.xhtml_msgtxt = event.xhtml event.nick = event.resource or '' app.nec.push_incoming_event( NetworkEvent('gc-message-received', **vars(event))) # TODO: Some plugins modify msgtxt in the GUI event self._log_muc_message(event) return app.nec.push_incoming_event( DecryptedMessageReceivedEvent(None, **vars(event)))
def _message_received(self, _con, stanza, properties): if (properties.is_mam_message or properties.is_pubsub or properties.type.is_error): return # Check if a child of the message contains any # namespaces that we handle in other modules. # nbxmpp executes less common handlers last if self._message_namespaces & set(stanza.getProperties()): return self._log.info('Received from %s', stanza.getFrom()) app.nec.push_incoming_event( NetworkEvent('raw-message-received', conn=self._con, stanza=stanza, account=self._account)) if properties.is_carbon_message and properties.carbon.is_sent: # Ugly, we treat the from attr as the remote jid, # to make that work with sent carbons we have to do this. # TODO: Check where in Gajim and plugins we depend on that behavior stanza.setFrom(stanza.getTo()) from_ = stanza.getFrom() fjid = str(from_) jid = from_.bare resource = from_.resource type_ = properties.type stanza_id, message_id = self._get_unique_id(properties) if properties.type.is_groupchat and properties.has_server_delay: # Only for XEP-0045 MUC History # Don’t check for message text because the message could be # encrypted. if app.storage.archive.deduplicate_muc_message( self._account, properties.jid.bare, properties.jid.resource, properties.timestamp, properties.id): raise nbxmpp.NodeProcessed if (properties.is_self_message or properties.is_muc_pm): archive_jid = self._con.get_own_jid().bare if app.storage.archive.find_stanza_id( self._account, archive_jid, stanza_id, message_id, properties.type.is_groupchat): return msgtxt = properties.body # TODO: remove all control UI stuff gc_control = app.interface.msg_win_mgr.get_gc_control( jid, self._account) if not gc_control: minimized = app.interface.minimized_controls[self._account] gc_control = minimized.get(jid) session = None if not properties.type.is_groupchat: if properties.is_muc_pm and properties.type.is_error: session = self._con.find_session(fjid, properties.thread) if not session: session = self._con.get_latest_session(fjid) if not session: session = self._con.make_new_session(fjid, properties.thread, type_='pm') else: session = self._con.get_or_create_session( fjid, properties.thread) if properties.thread and not session.received_thread_id: session.received_thread_id = True session.last_receive = time.time() additional_data = AdditionalDataDict() if properties.has_user_delay: additional_data.set_value('gajim', 'user_timestamp', properties.user_timestamp) parse_oob(properties, additional_data) parse_xhtml(properties, additional_data) app.nec.push_incoming_event( NetworkEvent('update-client-info', account=self._account, jid=jid, resource=resource)) if properties.is_encrypted: additional_data['encrypted'] = properties.encrypted.additional_data else: if properties.eme is not None: msgtxt = get_eme_message(properties.eme) displaymarking = None if properties.has_security_label: displaymarking = properties.security_label.displaymarking event_attr = { 'conn': self._con, 'stanza': stanza, 'account': self._account, 'additional_data': additional_data, 'fjid': fjid, 'jid': jid, 'resource': resource, 'stanza_id': stanza_id, 'unique_id': stanza_id or message_id, 'correct_id': parse_correction(properties), 'msgtxt': msgtxt, 'session': session, 'delayed': properties.user_timestamp is not None, 'gc_control': gc_control, 'popup': False, 'msg_log_id': None, 'displaymarking': displaymarking, 'properties': properties, } if type_.is_groupchat: if not msgtxt: return event_attr.update({ 'room_jid': jid, }) event = NetworkEvent('gc-message-received', **event_attr) app.nec.push_incoming_event(event) # TODO: Some plugins modify msgtxt in the GUI event self._log_muc_message(event) return app.nec.push_incoming_event( NetworkEvent('decrypted-message-received', **event_attr))
def _messageCB(self, con, stanza, properties): """ Called when we receive a message """ if properties.type.is_error: return log.info('Zeroconf MessageCB') # Don’t trust from attr set by sender stanza.setFrom(con._owner.to) app.nec.push_incoming_event( NetworkEvent('raw-message-received', conn=self, stanza=stanza, account=self.name)) type_ = stanza.getType() if type_ is None: type_ = 'normal' id_ = stanza.getID() fjid = str(stanza.getFrom()) jid, resource = app.get_room_and_nick_from_fjid(fjid) msgtxt = stanza.getBody() session = self.get_or_create_session(fjid, properties.thread) if properties.thread and not session.received_thread_id: session.received_thread_id = True timestamp = time.time() session.last_receive = timestamp additional_data = AdditionalDataDict() parse_oob(properties, additional_data) parse_xhtml(properties, additional_data) if properties.is_encrypted: additional_data['encrypted'] = properties.encrypted.additional_data else: if properties.eme is not None: msgtxt = get_eme_message(properties.eme) event_attr = { 'conn': self, 'stanza': stanza, 'account': self.name, 'additional_data': additional_data, 'timestamp': time.time(), 'fjid': fjid, 'jid': jid, 'resource': resource, 'unique_id': id_, 'correct_id': parse_correction(properties), 'msgtxt': msgtxt, 'session': session, 'gc_control': None, 'popup': False, 'msg_log_id': None, 'displaymarking': None, 'stanza_id': id_, 'properties': properties, } app.nec.push_incoming_event( NetworkEvent('decrypted-message-received', **event_attr))