예제 #1
0
        /// <summary>
        /// Decode body of a MimeEntity
        /// </summary>
        /// <param name="message"></param>
        /// <returns></returns>
        /// <exception cref="MimeException"></exception>
        public static StringSegment DecodeBody(MimeEntity message)
        {
            StringSegment    innerMessageText = message.Body.SourceText;
            TransferEncoding encoding         = message.GetTransferEncoding();

            switch (encoding)
            {
            case TransferEncoding.QuotedPrintable:
                string decodedText = QuotedPrintableDecoder.Decode(innerMessageText);
                innerMessageText = new StringSegment(decodedText);
                break;

            case TransferEncoding.Base64:
                byte[] bytes         = Convert.FromBase64String(innerMessageText.ToString());
                string textFromBytes = Encoding.ASCII.GetString(bytes);
                innerMessageText = new StringSegment(textFromBytes);
                break;

                //
                // Case UUEncoding
                // Not supported.
                // TransferEncoding is a System.Net.Mime type without support for UUEncoding
                // Code would need to be refactored to accomodate.
                //
            }

            return(innerMessageText);
        }
예제 #2
0
 public void TestStandard(string text, string expectedText)
 {
     QuotedPrintableDecoder decoder = new QuotedPrintableDecoder(text);
     char[] chars = null;
     Assert.DoesNotThrow(() => chars = decoder.GetChars().ToArray()); 
     Assert.True(chars.Length == expectedText.Length);
     
     string decodedString = null;    
     Assert.DoesNotThrow(() => decodedString = new string(chars));
     Assert.True(string.Equals(decodedString , expectedText));
 }
예제 #3
0
        public void TestFiles(string fileName)
        {
            string text = LoadFile(fileName);
            QuotedPrintableDecoder decoder = new QuotedPrintableDecoder(text);

            char[] chars = null;
            Assert.DoesNotThrow(() => chars = decoder.GetChars().ToArray());
            string decodedString = null;
            Assert.DoesNotThrow(() => decodedString = new string(chars));            
        }
예제 #4
0
 public void TestFailures(string badString)
 {
     string decoded = null;
     Assert.Throws<MimeException>(() => decoded = new QuotedPrintableDecoder(badString).GetString());
 }
예제 #5
0
 public void TestRandom(int textLength, double encodeProbability, double lowerCaseProbability)
 {
     TestString testString = this.MakeRandom(textLength, encodeProbability,lowerCaseProbability);            
     string decodedString = null;
     Assert.DoesNotThrow(() => decodedString = new QuotedPrintableDecoder(testString.Encoded).GetString());
     Assert.True(testString.Expected.Length == decodedString.Length);
     Assert.True(testString.Expected.Equals(decodedString));            
 }
예제 #6
0
 public void TestAllChars(bool lowerCase)
 {
     // Quoted printable all possible chars
     TestString testString = this.MakeAllEncodeChars(lowerCase);
     string decoded = null;
     Assert.DoesNotThrow(() => decoded = new QuotedPrintableDecoder(testString.Encoded).GetString());
     
     Assert.True(testString.Expected.Length == decoded.Length);
     for (byte i = 0; i < decoded.Length; ++i)
     {
         Assert.True(testString.Expected[i] == decoded[i]);
     } 
 }
예제 #7
0
 /// <summary>
 /// Decodes the quoted printable encoded segment
 /// </summary>
 /// <param name="encodedSegment"><see cref="StringSegment"/> to decode</param>
 /// <returns>Decoded string</returns>
 public static string Decode(StringSegment encodedSegment)
 {
     QuotedPrintableDecoder decoder = new QuotedPrintableDecoder(encodedSegment);
     return decoder.GetString();
 }
예제 #8
0
        /// <summary>
        /// Decodes the quoted printable encoded segment
        /// </summary>
        /// <param name="encodedSegment"><see cref="StringSegment"/> to decode</param>
        /// <returns>Decoded string</returns>
        public static string Decode(StringSegment encodedSegment)
        {
            QuotedPrintableDecoder decoder = new QuotedPrintableDecoder(encodedSegment);

            return(decoder.GetString());
        }