code: def prepare_string(partname, thread, maxw):
      
      # map part names to function extracting content string and custom shortener
      prep = {
          'mailcount': (prepare_mailcount_string, None),
          'date': (prepare_date_string, None),
          'authors': (prepare_authors_string, shorten_author_string),
          'subject': (prepare_subject_string, None),
          'content': (prepare_content_string, None),
      }
  
      s = ' '  # fallback value
      if thread:
          # get extractor and shortener
          content, shortener = prep[partname]
  
          # get string
          s = content(thread)
  
      # sanitize
      s = s.replace('\n', ' ')
      s = s.replace('\r', '')
  
      # shorten if max width is requested
      if maxw:
          if len(s) > maxw and shortener:
              s = shortener(s, maxw)
          else:
              s = s[:maxw]
      return s
docs: extract a content string for part 'partname' from 'thread' of maximal
      length 'maxw'.