code: def canonical_headers(self):
          
          canonical_headers = ''
  
          for header in HEADERS:
              if header not in self.message:
                  continue
  
              for value in self.message.get_all(header):
                  canonical_value = self.canonical_header_value(header, value)
                  if re.search(r'\S', canonical_value):
                      canonical_headers += '{}: {}\n'.format(
                          header, canonical_value)
  
          canonical_headers = canonical_headers.encode('utf-8')
          if len(canonical_headers) > 50:
              return canonical_headers
  
          # At this point we should have at absolute minimum 3 or 4 headers, e.g.
          # From/To/Date/Subject; if not, something went badly wrong.
  
          if len(canonical_headers) == 0:
              raise InsufficientHeadersError("No canonical headers found")
  
          err = textwrap.dedent("""\
              Not enough data from canonical headers to compute reliable hash!
              Headers:
              --------- 8< --------- 8< --------- 8< --------- 8< ---------
              {}
              --------- 8< --------- 8< --------- 8< --------- 8< ---------""")
          raise InsufficientHeadersError(err.format(canonical_headers))
docs: Copy selected headers into a new string.