def create_imap_message(db_session, account, folder, msg):
 new_message = Message.create_from_synced(account=account, mid=msg.uid, folder_name=folder.name, received_date=msg.internaldate, body_string=msg.body)
 existing_copy = reconcile_message(new_message, db_session)
 if (existing_copy is not None):
  new_message = existing_copy
 imapuid = ImapUid(account=account, folder=folder, msg_uid=msg.uid, message=new_message)
 imapuid.update_flags(msg.flags)
 if (msg.g_labels is not None):
  imapuid.update_labels(msg.g_labels)
 with db_session.no_autoflush:
  is_draft = (imapuid.is_draft and ((folder.canonical_name == 'drafts') or (folder.canonical_name == 'all')))
  update_message_metadata(db_session, account, new_message, is_draft)
 update_contacts_from_message(db_session, new_message, account.namespace)
 return imapuid

def create_imap_message ( db_session , account , folder , msg ) : new_message = Message . create_from_synced ( account = account , mid = msg . uid , folder_name = folder . name , received_date = msg . internaldate , body_string = msg . body ) existing_copy = reconcile_message ( new_message , db_session ) if ( existing_copy is not None ) : new_message = existing_copy imapuid = ImapUid ( account = account , folder = folder , msg_uid = msg . uid , message = new_message ) imapuid . update_flags ( msg . flags ) if ( msg . g_labels is not None ) : imapuid . update_labels ( msg . g_labels ) with db_session . no_autoflush : is_draft = ( imapuid . is_draft and ( ( folder . canonical_name == 'drafts' ) or ( folder . canonical_name == 'all' ) ) ) update_message_metadata ( db_session , account , new_message , is_draft ) update_contacts_from_message ( db_session , new_message , account . namespace ) return imapuid
imap-specific message creation logic .