public static function encode($body, $encoding, $wrapWidth = 76, $le = "\r\n", $cut = false)
    {
        $encoding = strtolower($encoding);
        switch ($encoding) {
            case 'quoted-printable':
                $body = quoted_printable_encode($body);
                return $wrapWidth ? rtrim(chunk_split($body, $wrapWidth, $le)) : $body;
                break;
            case 'base64':
                $body = base64_encode($body);
                return $wrapWidth ? rtrim(chunk_split($body, $wrapWidth, $le)) : $body;
                break;
            case '7bit':
                if (preg_match('~[^\x00-\x7F]~', $body)) {
                    throw new RuntimeException("Can't use `'{$encoding}'` encoding, non 7 bit characters detected.");
                }
            case '8bit':
            case 'binary':
                $body = ltrim(str_replace("\r", '', $body), "\n");
                return $wrapWidth ? wordwrap($body, $wrapWidth, "\n", $cut) : $body;
                break;
            default:
                throw new InvalidArgumentException("Unsupported encoding `'{$encoding}'`.");
                break;
        }
    }