def fold(header):
    "Fold a header line into multiple crlf-separated lines at column 72.\n    Borrowed from dkimpy and updated to only add \n instead of \r\n because\n    that's what the milter protocol wants.\n\n    >>> text(fold(b'foo'))\n    'foo'\n    >>> text(fold(b'foo  '+b'foo'*24).splitlines()[0])\n    'foo  '\n    >>> text(fold(b'foo'*25).splitlines()[-1])\n    ' foo'\n    >>> len(fold(b'foo'*25).splitlines()[0])\n    72\n    "
    i = header.rfind(b'\r\n ')
    if i == -1:
        pre = b''
    else:
        i += 3
        pre = header[:i]
        header = header[i:]
    maxleng = 72
    while len(header) > maxleng:
        i = header[:maxleng].rfind(b' ')
        if i == -1:
            j = maxleng
        else:
            j = i + 1
        pre += header[:j] + b'\n   '
        header = header[j:]
    return pre + header
