

def _fold(self, name, value, refold_binary=False):
    if hasattr(value, 'name'):
        return value.fold(policy=self)
    maxlen = (self.max_line_length if self.max_line_length else float('inf'))
    lines = value.splitlines()
    refold = ((self.refold_source == 'all') or ((self.refold_source == 'long') and ((lines and (((len(lines[0]) + len(name)) + 2) > maxlen)) or any(((len(x) > maxlen) for x in lines[1:])))))
    if (refold or (refold_binary and _has_surrogates(value))):
        return self.header_factory(name, ''.join(lines)).fold(policy=self)
    return (((name + ': ') + self.linesep.join(lines)) + self.linesep)

dataset/ETHPy150Open OpenCobolIDE/OpenCobolIDE/open_cobol_ide/extlibs/future/backports/email/policy.py EmailPolicy._fold/original