def readmailcapfile(fp):
 caps = {}
 while 1:
  line = fp.readline()
  if (not line):
   break
  if ((line[0] == '#') or (line.strip() == '')):
   continue
  nextline = line
  while (nextline[(-2):] == '\\\n'):
   nextline = fp.readline()
   if (not nextline):
    nextline = '\n'
   line = (line[:(-2)] + nextline)
  (key, fields) = parseline(line)
  if (not (key and fields)):
   continue
  types = key.split('/')
  for j in range(len(types)):
   types[j] = types[j].strip()
  key = '/'.join(types).lower()
  if (key in caps):
   caps[key].append(fields)
  else:
   caps[key] = [fields]
 return caps

def readmailcapfile ( fp ) : caps = { } while 1 : line = fp . readline ( ) if ( not line ) : break if ( ( line [ 0 ] == '#' ) or ( line . strip ( ) == '' ) ) : continue nextline = line while ( nextline [ ( - 2 ) : ] == '\\\n' ) : nextline = fp . readline ( ) if ( not nextline ) : nextline = '\n' line = ( line [ : ( - 2 ) ] + nextline ) ( key , fields ) = parseline ( line ) if ( not ( key and fields ) ) : continue types = key . split ( '/' ) for j in range ( len ( types ) ) : types [ j ] = types [ j ] . strip ( ) key = '/' . join ( types ) . lower ( ) if ( key in caps ) : caps [ key ] . append ( fields ) else : caps [ key ] = [ fields ] return caps
read a mailcap file and return a dictionary keyed by mime type .