def update_draft(db_session, account, draft, to_addr=None, subject=None, body=None, blocks=None, cc_addr=None, bcc_addr=None, from_addr=None, reply_to=None):
 def update(attr, value=None):
  if (value is not None):
   setattr(draft, attr, value)
   if (attr == 'body'):
    draft.size = len(value)
    draft.snippet = draft.calculate_html_snippet(value)
 update('to_addr', to_addr)
 update('cc_addr', cc_addr)
 update('bcc_addr', bcc_addr)
 update('reply_to', reply_to)
 update('from_addr', from_addr)
 update('subject', (subject if subject else None))
 update('body', (body if body else None))
 update('received_date', datetime.utcnow())
 new_block_ids = [b.id for b in blocks]
 for part in filter((lambda x: (x.block_id not in new_block_ids)), draft.parts):
  draft.parts.remove(part)
  db_session.delete(part)
 for block in blocks:
  if (block.id in [p.block_id for p in draft.parts]):
   continue
  draft.parts.append(block_to_part(block, draft, account.namespace))
 thread = draft.thread
 if (len(thread.messages) == 1):
  thread.subject = draft.subject
  thread.subjectdate = draft.received_date
  thread.recentdate = draft.received_date
 draft.contacts = []
 update_contacts_from_message(db_session, draft, account.namespace)
 draft.is_created = True
 old_message_id_header = draft.message_id_header
 draft.version += 1
 draft.regenerate_nylas_uid()
 schedule_action('update_draft', draft, draft.namespace.id, db_session, version=draft.version, old_message_id_header=old_message_id_header)
 db_session.commit()
 return draft

def update_draft ( db_session , account , draft , to_addr = None , subject = None , body = None , blocks = None , cc_addr = None , bcc_addr = None , from_addr = None , reply_to = None ) : def update ( attr , value = None ) : if ( value is not None ) : setattr ( draft , attr , value ) if ( attr == 'body' ) : draft . size = len ( value ) draft . snippet = draft . calculate_html_snippet ( value ) update ( 'to_addr' , to_addr ) update ( 'cc_addr' , cc_addr ) update ( 'bcc_addr' , bcc_addr ) update ( 'reply_to' , reply_to ) update ( 'from_addr' , from_addr ) update ( 'subject' , ( subject if subject else None ) ) update ( 'body' , ( body if body else None ) ) update ( 'received_date' , datetime . utcnow ( ) ) new_block_ids = [ b . id for b in blocks ] for part in filter ( ( lambda x : ( x . block_id not in new_block_ids ) ) , draft . parts ) : draft . parts . remove ( part ) db_session . delete ( part ) for block in blocks : if ( block . id in [ p . block_id for p in draft . parts ] ) : continue draft . parts . append ( block_to_part ( block , draft , account . namespace ) ) thread = draft . thread if ( len ( thread . messages ) == 1 ) : thread . subject = draft . subject thread . subjectdate = draft . received_date thread . recentdate = draft . received_date draft . contacts = [ ] update_contacts_from_message ( db_session , draft , account . namespace ) draft . is_created = True old_message_id_header = draft . message_id_header draft . version += 1 draft . regenerate_nylas_uid ( ) schedule_action ( 'update_draft' , draft , draft . namespace . id , db_session , version = draft . version , old_message_id_header = old_message_id_header ) db_session . commit ( ) return draft
sync an updated draft back to the remote backend .