def MimeReplacePart(part, newpart):
 part.set_payload(newpart.get_payload())
 for h in newpart.keys():
  del part[h]
 if ('content-type' in part):
  del part['content-type']
 if ('content-transfer-encoding' in part):
  del part['content-transfer-encoding']
 for (h, v) in newpart.items():
  part.add_header(h, v)

def MimeReplacePart ( part , newpart ) : part . set_payload ( newpart . get_payload ( ) ) for h in newpart . keys ( ) : del part [ h ] if ( 'content-type' in part ) : del part [ 'content-type' ] if ( 'content-transfer-encoding' in part ) : del part [ 'content-transfer-encoding' ] for ( h , v ) in newpart . items ( ) : part . add_header ( h , v )
replace a mime part with new version retaining headers from the old part that are not in the new part .