def display_structure(structure, parentparts=[]):
 if parentparts:
  name = '.'.join(parentparts)
 else:
  print 'HEADER'
  name = 'TEXT'
 is_multipart = isinstance(structure[0], list)
 if is_multipart:
  parttype = ('multipart/%s' % structure[1].lower())
 else:
  parttype = ('%s/%s' % structure[:2]).lower()
 print ('%-9s' % name), parttype,
 if is_multipart:
  print
  subparts = structure[0]
  for i in range(len(subparts)):
   display_structure(subparts[i], (parentparts + [str((i + 1))]))
 else:
  if structure[6]:
   print ('size=%s' % structure[6]),
  if structure[8]:
   (disposition, namevalues) = structure[8]
   print disposition,
   for i in range(0, len(namevalues), 2):
    print ('%s=%r' % namevalues[i:(i + 2)])
  print

def display_structure ( structure , parentparts = [ ] ) : if parentparts : name = '.' . join ( parentparts ) else : print 'HEADER' name = 'TEXT' is_multipart = isinstance ( structure [ 0 ] , list ) if is_multipart : parttype = ( 'multipart/%s' % structure [ 1 ] . lower ( ) ) else : parttype = ( '%s/%s' % structure [ : 2 ] ) . lower ( ) print ( '%-9s' % name ) , parttype , if is_multipart : print subparts = structure [ 0 ] for i in range ( len ( subparts ) ) : display_structure ( subparts [ i ] , ( parentparts + [ str ( ( i + 1 ) ) ] ) ) else : if structure [ 6 ] : print ( 'size=%s' % structure [ 6 ] ) , if structure [ 8 ] : ( disposition , namevalues ) = structure [ 8 ] print disposition , for i in range ( 0 , len ( namevalues ) , 2 ) : print ( '%s=%r' % namevalues [ i : ( i + 2 ) ] ) print
attractively display a given message structure .