def update_metadata(account_id, folder_id, folder_role, new_flags, session):
 if (not new_flags):
  return
 account = Account.get(account_id, session)
 change_count = 0
 for item in session.query(ImapUid).filter((ImapUid.account_id == account_id), ImapUid.msg_uid.in_(new_flags.keys()), (ImapUid.folder_id == folder_id)):
  flags = new_flags[item.msg_uid].flags
  labels = getattr(new_flags[item.msg_uid], 'labels', None)
  changed = item.update_flags(flags)
  if (labels is not None):
   item.update_labels(labels)
   changed = True
  if changed:
   change_count += 1
   is_draft = (item.is_draft and ((folder_role == 'drafts') or (folder_role == 'all')))
   update_message_metadata(session, account, item.message, is_draft)
   session.commit()
 log.info('Updated UID metadata', changed=change_count, out_of=len(new_flags))

def update_metadata ( account_id , folder_id , folder_role , new_flags , session ) : if ( not new_flags ) : return account = Account . get ( account_id , session ) change_count = 0 for item in session . query ( ImapUid ) . filter ( ( ImapUid . account_id == account_id ) , ImapUid . msg_uid . in_ ( new_flags . keys ( ) ) , ( ImapUid . folder_id == folder_id ) ) : flags = new_flags [ item . msg_uid ] . flags labels = getattr ( new_flags [ item . msg_uid ] , 'labels' , None ) changed = item . update_flags ( flags ) if ( labels is not None ) : item . update_labels ( labels ) changed = True if changed : change_count += 1 is_draft = ( item . is_draft and ( ( folder_role == 'drafts' ) or ( folder_role == 'all' ) ) ) update_message_metadata ( session , account , item . message , is_draft ) session . commit ( ) log . info ( 'Updated UID metadata' , changed = change_count , out_of = len ( new_flags ) )
update flags and labels .