class_docstr: +
  PROVISIONAL
  
  The API extensions enabled by this policy are currently provisional.
  Refer to the documentation for details.
  
  This policy adds new header parsing and folding algorithms.  Instead of
  simple strings, headers are custom objects with custom attributes
  depending on the type of the field.  The folding algorithm fully
  implements RFCs 2047 and 5322.
  
  In addition to the settable attributes listed above that apply to
  all Policies, this policy adds the following additional attributes:
  
  utf8                -- if False (the default) message headers will be
                         serialized as ASCII, using encoded words to encode
                         any non-ASCII characters in the source strings.  If
                         True, the message headers will be serialized using
                         utf8 and will not contain encoded words (see RFC
                         6532 for more on this serialization format).
  
  refold_source       -- if the value for a header in the Message object
                         came from the parsing of some source, this attribute
                         indicates whether or not a generator should refold
                         that value when transforming the message back into
                         stream form.  The possible values are:
  
                         none  -- all source values use original folding
                         long  -- source values that have any line that is
                                  longer than max_line_length will be
                                  refolded
                         all  -- all values are refolded.
  
                         The default is 'long'.
  
  header_factory      -- a callable that takes two arguments, 'name' and
                         'value', where 'name' is a header field name and
                         'value' is an unfolded header field value, and
                         returns a string-like object that represents that
                         header.  A default header_factory is provided that
                         understands some of the RFC5322 header field types.
                         (Currently address fields and date fields have
                         special treatment, while all other fields are
                         treated as unstructured.  This list will be
                         completed before the extension is marked stable.)
  
  content_manager     -- an object with at least two methods: get_content
                         and set_content.  When the get_content or
                         set_content method of a Message object is called,
                         it calls the corresponding method of this object,
                         passing it the message object as its first argument,
                         and any arguments or keywords that were passed to
                         it as additional arguments.  The default
                         content_manager is
                         :data:`~email.contentmanager.raw_data_manager`.
class_docstr_tok: ["+","PROVISIONAL","The","API","extensions","enabled","by","this","policy","are","currently","provisional",".","Refer","to","the","documentation","for","details",".","This","policy","adds","new","header","parsing","and","folding","algorithms",".","Instead","of","simple","strings",",","headers","are","custom","objects","with","custom","attributes","depending","on","the","type","of","the","field",".","The","folding","algorithm","fully","implements","RFCs","2047","and","5322",".","In","addition","to","the","settable","attributes","listed","above","that","apply","to","all","Policies",",","this","policy","adds","the","following","additional","attributes",":","utf8","--","if","False","(","the","default",")","message","headers","will","be","serialized","as","ASCII",",","using","encoded","words","to","encode","any","non-ASCII","characters","in","the","source","strings",".","If","True",",","the","message","headers","will","be","serialized","using","utf8","and","will","not","contain","encoded","words","(","see","RFC","6532","for","more","on","this","serialization","format",")",".","refold_source","--","if","the","value","for","a","header","in","the","Message","object","came","from","the","parsing","of","some","source",",","this","attribute","indicates","whether","or","not","a","generator","should","refold","that","value","when","transforming","the","message","back","into","stream","form",".","The","possible","values","are",":","none","--","all","source","values","use","original","folding","long","--","source","values","that","have","any","line","that","is","longer","than","max_line_length","will","be","refolded","all","--","all","values","are","refolded",".","The","default","is","'long","'",".","header_factory","--","a","callable","that","takes","two","arguments",",","'name","'","and","'value","'",",","where","'name","'","is","a","header","field","name","and","'value","'","is","an","unfolded","header","field","value",",","and","returns","a","string-like","object","that","represents","that","header",".","A","default","header_factory","is","provided","that","understands","some","of","the","RFC5322","header","field","types",".","(","Currently","address","fields","and","date","fields","have","special","treatment",",","while","all","other","fields","are","treated","as","unstructured",".","This","list","will","be","completed","before","the","extension","is","marked","stable",".",")","content_manager","--","an","object","with","at","least","two","methods",":","get_content","and","set_content",".","When","the","get_content","or","set_content","method","of","a","Message","object","is","called",",","it","calls","the","corresponding","method","of","this","object",",","passing","it","the","message","object","as","its","first","argument",",","and","any","arguments","or","keywords","that","were","passed","to","it","as","additional","arguments",".","The","default","content_manager","is",":","data",":","`","~email.contentmanager.raw_data_manager","`","."]
docstr: +
  Header folding is controlled by the refold_source policy setting.  A
  value is considered to be a 'source value' if and only if it does not
  have a 'name' attribute (having a 'name' attribute means it is a header
  object of some sort).  If a source value needs to be refolded according
  to the policy, it is converted into a custom header object by passing
  the name and the value with any linesep characters removed to the
  header_factory method.  Folding of a custom header object is done by
  calling its fold method with the current policy.
  
  Source values are split into lines using splitlines.  If the value is
  not to be refolded, the lines are rejoined using the linesep from the
  policy and returned.  The exception is lines containing non-ascii
  binary data.  In that case the value is refolded regardless of the
  refold_source setting, which causes the binary data to be CTE encoded
  using the unknown-8bit charset.
docstr_tok: ["+","Header","folding","is","controlled","by","the","refold_source","policy","setting",".","A","value","is","considered","to","be","a","'source","value","'","if","and","only","if","it","does","not","have","a","'name","'","attribute","(","having","a","'name","'","attribute","means","it","is","a","header","object","of","some","sort",")",".","If","a","source","value","needs","to","be","refolded","according","to","the","policy",",","it","is","converted","into","a","custom","header","object","by","passing","the","name","and","the","value","with","any","linesep","characters","removed","to","the","header_factory","method",".","Folding","of","a","custom","header","object","is","done","by","calling","its","fold","method","with","the","current","policy",".","Source","values","are","split","into","lines","using","splitlines",".","If","the","value","is","not","to","be","refolded",",","the","lines","are","rejoined","using","the","linesep","from","the","policy","and","returned",".","The","exception","is","lines","containing","non-ascii","binary","data",".","In","that","case","the","value","is","refolded","regardless","of","the","refold_source","setting",",","which","causes","the","binary","data","to","be","CTE","encoded","using","the","unknown-8bit","charset","."]
code: def fold(self, name, value):
      """+
      Header folding is controlled by the refold_source policy setting.  A
      value is considered to be a 'source value' if and only if it does not
      have a 'name' attribute (having a 'name' attribute means it is a header
      object of some sort).  If a source value needs to be refolded according
      to the policy, it is converted into a custom header object by passing
      the name and the value with any linesep characters removed to the
      header_factory method.  Folding of a custom header object is done by
      calling its fold method with the current policy.
  
      Source values are split into lines using splitlines.  If the value is
      not to be refolded, the lines are rejoined using the linesep from the
      policy and returned.  The exception is lines containing non-ascii
      binary data.  In that case the value is refolded regardless of the
      refold_source setting, which causes the binary data to be CTE encoded
      using the unknown-8bit charset.
  
      """
      return self._fold(name, value, refold_binary=True)
  
file_path: cpython/Lib/email/policy.py
imports: import re
  import sys
  from email._policybase import Policy, Compat32, compat32, _extend_docstrings
  from email.utils import _has_surrogates
  from email.headerregistry import HeaderRegistry
  from email.contentmanager import raw_data_manager
  from email.message import EmailMessage
label_desc: Use image node_id 6 for calling the EmailPolicy obj's underlying member method code with example usage: obj.fold(name, value) and returns: self