def reconcile_message(new_message, session):
 from inbox.models.message import Message
 if (new_message.nylas_uid is None):
  q = session.query(Message).filter((Message.namespace_id == new_message.namespace_id), (Message.data_sha256 == new_message.data_sha256))
  return q.first()
 if ('-' not in new_message.nylas_uid):
  existing_message = session.query(Message).filter((Message.namespace_id == new_message.namespace_id), (Message.nylas_uid == new_message.nylas_uid), Message.is_created).first()
  version = None
 else:
  (expected_public_id, version) = new_message.nylas_uid.split('-')
  existing_message = session.query(Message).filter((Message.namespace_id == new_message.namespace_id), (Message.public_id == expected_public_id), Message.is_created).first()
 if (existing_message is None):
  return None
 if ((version is None) or (int(version) == existing_message.version)):
  existing_message.message_id_header = new_message.message_id_header
  existing_message.references = new_message.references
  existing_message.parsed_body = new_message.parsed_body
 return existing_message

def reconcile_message ( new_message , session ) : from inbox . models . message import Message if ( new_message . nylas_uid is None ) : q = session . query ( Message ) . filter ( ( Message . namespace_id == new_message . namespace_id ) , ( Message . data_sha256 == new_message . data_sha256 ) ) return q . first ( ) if ( '-' not in new_message . nylas_uid ) : existing_message = session . query ( Message ) . filter ( ( Message . namespace_id == new_message . namespace_id ) , ( Message . nylas_uid == new_message . nylas_uid ) , Message . is_created ) . first ( ) version = None else : ( expected_public_id , version ) = new_message . nylas_uid . split ( '-' ) existing_message = session . query ( Message ) . filter ( ( Message . namespace_id == new_message . namespace_id ) , ( Message . public_id == expected_public_id ) , Message . is_created ) . first ( ) if ( existing_message is None ) : return None if ( ( version is None ) or ( int ( version ) == existing_message . version ) ) : existing_message . message_id_header = new_message . message_id_header existing_message . references = new_message . references existing_message . parsed_body = new_message . parsed_body return existing_message
check to see if the message instance new_message was originally created/sent via the nylas api (based on the x-inbox-uid header .