code: def body_encode(s, maxlinelen=76, eol=NL):
      r
      if not s:
          return s
  
      encvec = []
      max_unencoded = maxlinelen * 3 // 4
      for i in range(0, len(s), max_unencoded):
          # BAW: should encode() inherit b2a_base64()'s dubious behavior in
          # adding a newline to the encoded string?
          enc = b2a_base64(s[i:i + max_unencoded]).decode("ascii")
          if enc.endswith(NL) and eol != NL:
              enc = enc[:-1] + eol
          encvec.append(enc)
      return EMPTYSTRING.join(encvec)
docs: r"""Encode a string with base64.
  
      Each line will be wrapped at, at most, maxlinelen characters (defaults to
      76 characters).
  
      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.