def internal_prep_message(realm, sender_email, recipient_type_name, recipients, subject, content):
 if (len(content) > MAX_MESSAGE_LENGTH):
  content = (content[0:3900] + '\n\n[message was too long and has been truncated]')
 sender = get_user_profile_by_email(sender_email)
 if (realm is None):
  raise RuntimeError('None is not a valid realm for internal_prep_message!')
 parsed_recipients = extract_recipients(recipients)
 if (recipient_type_name == 'stream'):
  (stream, _) = create_stream_if_needed(realm, parsed_recipients[0])
 try:
  return check_message(sender, get_client('Internal'), recipient_type_name, parsed_recipients, subject, content, realm=realm)
 except JsonableError as e:
  logging.error(('Error queueing internal message by %s: %s' % (sender_email, str(e))))
 return None

def internal_prep_message ( realm , sender_email , recipient_type_name , recipients , subject , content ) : if ( len ( content ) > MAX_MESSAGE_LENGTH ) : content = ( content [ 0 : 3900 ] + '\n\n[message was too long and has been truncated]' ) sender = get_user_profile_by_email ( sender_email ) if ( realm is None ) : raise RuntimeError ( 'None is not a valid realm for internal_prep_message!' ) parsed_recipients = extract_recipients ( recipients ) if ( recipient_type_name == 'stream' ) : ( stream , _ ) = create_stream_if_needed ( realm , parsed_recipients [ 0 ] ) try : return check_message ( sender , get_client ( 'Internal' ) , recipient_type_name , parsed_recipients , subject , content , realm = realm ) except JsonableError as e : logging . error ( ( 'Error queueing internal message by %s: %s' % ( sender_email , str ( e ) ) ) ) return None
create a message object and checks it .