(body, binary=False, maxlinelen=76, eol=NL)
return encoded_body
Encode with quoted-printable, wrapping at maxlinelen characters.

    If binary is False (the default), end-of-line characters will be converted
    to the canonical email end-of-line sequence \\r\\n.  Otherwise they will
    be left verbatim.

    Each line of encoded text will end with eol, which defaults to "\\n".  Set
    this to "\\r\\n" if you will be using the result of this function directly
    in an email.

    Each line will be wrapped at, at most, maxlinelen characters (defaults to
    76 characters).  Long lines will have the `soft linefeed' quoted-printable
    character "=" appended to them, so the decoded text will be identical to
    the original text.
Encode with quoted-printable, wrapping at maxlinelen characters.
Encode with quoted - printable wrapping at maxlinelen characters .
def encode(body, binary=False, maxlinelen=76, eol=NL):
    """Encode with quoted-printable, wrapping at maxlinelen characters.

    If binary is False (the default), end-of-line characters will be converted
    to the canonical email end-of-line sequence \\r\\n.  Otherwise they will
    be left verbatim.

    Each line of encoded text will end with eol, which defaults to "\\n".  Set
    this to "\\r\\n" if you will be using the result of this function directly
    in an email.

    Each line will be wrapped at, at most, maxlinelen characters (defaults to
    76 characters).  Long lines will have the `soft linefeed' quoted-printable
    character "=" appended to them, so the decoded text will be identical to
    the original text.
    """
    if not body:
        return body

    if not binary:
        body = fix_eols(body)

    # BAW: We're accumulating the body text by string concatenation.  That
    # can't be very efficient, but I don't have time now to rewrite it.  It
    # just feels like this algorithm could be more efficient.
    encoded_body = ''
    lineno = -1
    # Preserve line endings here so we can check later to see an eol needs to
    # be added to the output later.
    lines = body.splitlines(1)
    for line in lines:
        # But strip off line-endings for processing this line.
        if line.endswith(CRLF):
            line = line[:-2]
        elif line[-1] in CRLF:
            line = line[:-1]

        lineno += 1
        encoded_line = ''
        prev = None
        linelen = len(line)
        # Now we need to examine every character to see if it needs to be
        # quopri encoded.  BAW: again, string concatenation is inefficient.
        for j in range(linelen):
            c = line[j]
            prev = c
            if bqre.match(c):
                c = quote(c)
            elif j+1 == linelen:
                # Check for whitespace at end of line; special case
                if c not in ' \t':
                    encoded_line += c
                prev = c
                continue
            # Check to see to see if the line has reached its maximum length
            if len(encoded_line) + len(c) >= maxlinelen:
                encoded_body += encoded_line + '=' + eol
                encoded_line = ''
            encoded_line += c
        # Now at end of line..
        if prev and prev in ' \t':
            # Special case for whitespace at end of file
            if lineno + 1 == len(lines):
                prev = quote(prev)
                if len(encoded_line) + len(prev) > maxlinelen:
                    encoded_body += encoded_line + '=' + eol + prev
                else:
                    encoded_body += encoded_line + prev
            # Just normal whitespace at end of line
            else:
                encoded_body += encoded_line + prev + '=' + eol
            encoded_line = ''
        # Now look at the line we just finished and it has a line ending, we
        # need to add eol to the end of the line.
        if lines[lineno].endswith(CRLF) or lines[lineno][-1] in CRLF:
            encoded_body += encoded_line + eol
        else:
            encoded_body += encoded_line
        encoded_line = ''
    return encoded_body
def encode ( body , binary = False , maxlinelen = 76 , eol = NL ) : if not body : return body if not binary : body = fix_eols ( body ) # BAW: We're accumulating the body text by string concatenation.  That # can't be very efficient, but I don't have time now to rewrite it.  It # just feels like this algorithm could be more efficient. encoded_body = '' lineno = - 1 # Preserve line endings here so we can check later to see an eol needs to # be added to the output later. lines = body . splitlines ( 1 ) for line in lines : # But strip off line-endings for processing this line. if line . endswith ( CRLF ) : line = line [ : - 2 ] elif line [ - 1 ] in CRLF : line = line [ : - 1 ] lineno += 1 encoded_line = '' prev = None linelen = len ( line ) # Now we need to examine every character to see if it needs to be # quopri encoded.  BAW: again, string concatenation is inefficient. for j in range ( linelen ) : c = line [ j ] prev = c if bqre . match ( c ) : c = quote ( c ) elif j + 1 == linelen : # Check for whitespace at end of line; special case if c not in ' \t' : encoded_line += c prev = c continue # Check to see to see if the line has reached its maximum length if len ( encoded_line ) + len ( c ) >= maxlinelen : encoded_body += encoded_line + '=' + eol encoded_line = '' encoded_line += c # Now at end of line.. if prev and prev in ' \t' : # Special case for whitespace at end of file if lineno + 1 == len ( lines ) : prev = quote ( prev ) if len ( encoded_line ) + len ( prev ) > maxlinelen : encoded_body += encoded_line + '=' + eol + prev else : encoded_body += encoded_line + prev # Just normal whitespace at end of line else : encoded_body += encoded_line + prev + '=' + eol encoded_line = '' # Now look at the line we just finished and it has a line ending, we # need to add eol to the end of the line. if lines [ lineno ] . endswith ( CRLF ) or lines [ lineno ] [ - 1 ] in CRLF : encoded_body += encoded_line + eol else : encoded_body += encoded_line encoded_line = '' return encoded_body