Пример #1
0
        public static string ToQuotedPrintable(this byte[] bytes)
        {
            if (bytes == null)
            {
                return(string.Empty);
            }

            return(QUOTED_PRINTABLE.Encode(bytes));
        }
Пример #2
0
        protected string EncodeQuotedPrintable(byte[] inputBytes)
        {
            try
            {
                QuotedPrintableEncoder encoder = new QuotedPrintableEncoder();

                byte[] outputBytes = new byte[encoder.EstimateOutputLength(inputBytes.Length)];

                int length = encoder.Encode(inputBytes, 0, inputBytes.Length, outputBytes);

                return(Encoding.UTF8.GetString(outputBytes.Take(length).ToArray()));
            }
            catch
            {
                return(null);
            }
        }
        public static string EncodeQuotedPrintableText(string text)
        {
            var encoder    = new QuotedPrintableEncoder();
            var buffer     = Encoding.UTF8.GetBytes(text);
            var multiplier = 3.0d;

            while (true)
            {
                try
                {
                    var length = (int)Math.Floor(buffer.Length * multiplier);
                    var output = new byte[length];
                    var count  = encoder.Encode(buffer, 0, buffer.Length, output);

                    return(Encoding.ASCII.GetString(output, 0, count));
                }
                catch (ArgumentException)
                {
                    multiplier *= 1.44;
                }
            }
        }