예제 #1
0
        public void EncodeDoesNotEncodeTabsOrSpacesIfSpecified()
        {
            var text     = "!This Is A Basic\tTest^";
            var expected = text.Replace(" ", "=20").Replace("\t", "=09");

            var actual = new QuotedPrintable(DoNotEncode.Tab & DoNotEncode.Space).Encode(Encoding.ASCII.GetBytes(text));

            Assert.Equal(expected, actual);
        }
예제 #2
0
        public void EncodeEncodesTabsAndSpacesByDefault()
        {
            var text     = "!This Is A Basic\tTest^";
            var expected = text.Replace(" ", "=20").Replace("\t", "=09");

            var actual = new QuotedPrintable().Encode(Encoding.ASCII.GetBytes(text));

            Assert.Equal(expected, actual);
        }
예제 #3
0
        public void EncodeDoesNotCreateLinesOver76CharsInLength()
        {
            var text = String.Join("-", Enumerable.Repeat("A quick brown fox ", 100));

            var actual = new QuotedPrintable(DoNotEncode.Space).Encode(Encoding.ASCII.GetBytes(text));

            using (var reader = new StringReader(actual))
                Assert.True(reader.ReadLine().Length <= 76);
        }
예제 #4
0
        public void DecodeIgnoresTrailingEquals()
        {
            var text     = " A =";
            var expected = new byte[] { 0x20, 0x41, 0x20 };

            var actual = new QuotedPrintable().Decode(text);

            Assert.Equal(expected, actual);
        }
예제 #5
0
        public void DecodeGivenMixReturnsDecodedBytes()
        {
            var text     = "^Aa =20\t=09!";
            var expected = new byte[] { 0x5E, 0x41, 0x61, 0x20, 0x20, 0x09, 0x09, 0x21 };

            var actual = new QuotedPrintable().Decode(text);

            Assert.Equal(expected, actual);
        }
예제 #6
0
        public void DecodeGivenAsciiReturnsAsciiBytes()
        {
            var text     = "This is a cool test";
            var expected = Encoding.ASCII.GetBytes(text);

            var actual = new QuotedPrintable().Decode(text);

            Assert.Equal(expected, actual);
        }
예제 #7
0
        public void EncodeDoesNotPutsEqualsAtEndIfLastCharacterEncoded()
        {
            var text     = "Line Ends With ";
            var expected = text.Replace(" ", "=20");

            var actual = new QuotedPrintable().Encode(Encoding.ASCII.GetBytes(text));

            Assert.Equal(expected, actual);
        }
예제 #8
0
    // 解碼
    protected void bn_dcode_Click(object sender, EventArgs e)
    {
        QuotedPrintable qupt = new QuotedPrintable();

        qupt.CodePage = int.Parse(tb_codepage.Text);
        qupt.EnQuotedCode = tb_ecode.Text.Trim();

        tb_dcode.Text = qupt.DeQuotedCode;
    }
예제 #9
0
        public void EncodeEncodesEquals()
        {
            var text     = "This=Is=A=Test";
            var expected = text.Replace("=", "=3D");

            var actual = new QuotedPrintable().Encode(Encoding.ASCII.GetBytes(text));

            Assert.Equal(expected, actual);
        }
예제 #10
0
        public void DoNotDoubleDecode()
        {
            const string input          = "=3D3D";
            const string expectedOutput = "=3D";             // Checks that the output itself is not decoded, as this is encoded equal sign

            string output = QuotedPrintable.DecodeEncodedWord(input, Encoding.GetEncoding("iso-8859-1"));

            Assert.AreEqual(expectedOutput, output);
        }
예제 #11
0
        public void CanDecodeEqualSignTwoTimes()
        {
            const string input          = "=3D=3D";
            const string expectedOutput = "==";

            string output = QuotedPrintable.DecodeEncodedWord(input, Encoding.GetEncoding("iso-8859-1"));

            Assert.AreEqual(expectedOutput, output);
        }
예제 #12
0
        public void EncodeGivenBinaryEncodesBinary()
        {
            var unencoded = new byte[] { 0x10, 0x44, 0x00, 0xA3, 0xFF, 0xDE, 0x4E };
            var expected  = "=10D=00=A3=FF=DEN";

            var actual = new QuotedPrintable().Encode(unencoded);

            Assert.Equal(expected, actual);
        }
예제 #13
0
        public void RFCExample()
        {
            const string input          = "Now is the time =\r\nfor all folk to come=\r\n to the aid of their country.";
            const string expectedOutput = "Now is the time for all folk to come to the aid of their country.";

            string output = QuotedPrintable.DecodeEncodedWord(input, Encoding.GetEncoding("iso-8859-1"));

            Assert.AreEqual(expectedOutput, output);
        }
예제 #14
0
        public void DoNotTouchLiterals()
        {
            const string input          = "!\"#$%&'()*+,-./0123456789:;<>@ABCDEFGHIJKLMNIOQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";
            const string expectedOutput = "!\"#$%&'()*+,-./0123456789:;<>@ABCDEFGHIJKLMNIOQRSTUVWXYZ[\\]^ `abcdefghijklmnopqrstuvwxyz{|}~";             // Only change is that _ delimits SPACE

            string output = QuotedPrintable.DecodeEncodedWord(input, Encoding.GetEncoding("iso-8859-1"));

            Assert.AreEqual(expectedOutput, output);
        }
예제 #15
0
        public void LiteralSpaceAndTabSupported()
        {
            const string input          = "Test for space\tand\ttabs";
            const string expectedOutput = input;             // Nothing should happen, spaces and tabs should be kept

            string output = QuotedPrintable.DecodeEncodedWord(input, Encoding.GetEncoding("iso-8859-1"));

            Assert.AreEqual(expectedOutput, output);
        }
예제 #16
0
        public void EncodingShortStringInlineTest()
        {
            var str      = "the quick brown fox jumps over the lazy dog";
            var expected = @"=?utf-8?Q?the quick brown fox jumps over the lazy dog?=";

            var result = QuotedPrintable.Inline(str);

            Assert.AreEqual(expected, result);
        }
예제 #17
0
 public void DecodeMessageLines( )
 {
     if (AcCommon.StringValue(Properties.ContentTransferEncoding)
         == "quoted-printable")
     {
         mRawMessageLines = mMessageLines;
         mMessageLines    = QuotedPrintable.DecodeLines(mRawMessageLines);
     }
 }
예제 #18
0
        public void TestUnderscoresNotConvertedToSpacesInContentTransferEncoding()
        {
            const string input = "a_b_c_d_e_f";

            const string expectedOutput = "a_b_c_d_e_f";

            string output = Encoding.ASCII.GetString(QuotedPrintable.DecodeContentTransferEncoding(input));

            Assert.AreEqual(expectedOutput, output);
        }
예제 #19
0
        public void EncodingQuotedCharAtEndOfLineTest()
        {
            var str      = "If you believe that truth=beauty, then surely mathematics is the most beãutiful branch of philosophy.";
            var expected = @"If you believe that truth=3Dbeauty, then surely mathematics is the most be=
=C3=A3utiful branch of philosophy.";

            var result = QuotedPrintable.Encode(str);

            Assert.AreEqual(expected, result);
        }
예제 #20
0
        public void EncodingWithDotStuffingTest()
        {
            var str      = "If you believe that truth=beauty, then surely mathematics is the most bea.utiful branch of philosophy.";
            var expected = @"If you believe that truth=3Dbeauty, then surely mathematics is the most bea=
..utiful branch of philosophy.";

            var result = QuotedPrintable.Encode(str);

            Assert.AreEqual(expected, result);
        }
예제 #21
0
        public void EncodingLongStringInlineTest()
        {
            var str      = "If you believe that truth=beauty, then surely mathematics is the most beãutiful branch of philosophy.";
            var expected = @"=?utf-8?Q?If you believe that truth=3Dbeauty, then surely mathematics is t?=
 =?utf-8?Q?he most be=C3=A3utiful branch of philosophy.?=";

            var result = QuotedPrintable.Inline(str);

            Assert.AreEqual(expected, result);
        }
예제 #22
0
        private void WriteBody()
        {
            var contentType = (GetMessage().IsBodyHtml ? "text/html" : "text/plain");

            WriteHeader(HeaderName.ContentType, contentType + "; charset=utf-8");
            WriteHeader(HeaderName.ContentTransferEncoding, "quoted-printable");
            WriteLine();
            WriteLine(QuotedPrintable.Encode(GetMessage().Body));
            WriteLine();
        }
예제 #23
0
        public void CanDecodeUnderscoreToSpace()
        {
            // Space is represented as an _

            const string input          = "_";
            const string expectedOutput = " ";

            string output = QuotedPrintable.DecodeEncodedWord(input, Encoding.GetEncoding("iso-8859-1"));

            Assert.AreEqual(expectedOutput, output);
        }
예제 #24
0
        public void CanDecodeSpanishSentence()
        {
            // Space is represented as an _ in

            const string input          = "=A1Hola,_se=F1or!";
            const string expectedOutput = "¡Hola, señor!";

            string output = QuotedPrintable.DecodeEncodedWord(input, Encoding.GetEncoding("iso-8859-1"));

            Assert.AreEqual(expectedOutput, output);
        }
예제 #25
0
        public void CanHandleWindows1252Encoding()
        {
            const string input = "=C5=F7=96";

            // http://en.wikipedia.org/wiki/Windows-1254
            const string expectedOutput = "Å÷–";

            string output = QuotedPrintable.DecodeEncodedWord(input, Encoding.GetEncoding(1252));

            Assert.AreEqual(expectedOutput, output);
        }
예제 #26
0
        public void CanDecodeSoftLineBreak()
        {
            const string input          = "=\r\n";
            const string expectedOutput = "";

            // =20 should be a space
            // = just after should be a soft line break

            string output = QuotedPrintable.DecodeEncodedWord(input, Encoding.GetEncoding("iso-8859-1"));

            Assert.AreEqual(expectedOutput, output);
        }
예제 #27
0
        public void ImplementationShouldBeRobustControlCharactersCarriageReturnNewlineNotPair()
        {
            const string input          = "\n\runit\ned\r";    // Notice the ordering is wrong with the first pair, and therefore not allowed
            const string expectedOutput = "united";            // All illegal control characters should have been deleted

            // Do not throw exceptions
            Assert.DoesNotThrow(delegate { QuotedPrintable.DecodeEncodedWord(input, Encoding.GetEncoding("iso-8859-1")); });

            string output = QuotedPrintable.DecodeEncodedWord(input, Encoding.GetEncoding("iso-8859-1"));

            // And output should be correct
            Assert.AreEqual(expectedOutput, output);
        }
예제 #28
0
        public void ImplementationShouldBeRobustSmallHexDigitsAfterEqual()
        {
            const string input          = "=3d=a1";
            const string expectedOutput = "=¡";             // Should simply be decoded as if hex characters were uppercase

            // Therefore no exceptions must be thrown
            Assert.DoesNotThrow(delegate { QuotedPrintable.DecodeEncodedWord(input, Encoding.GetEncoding("iso-8859-1")); });

            string output = QuotedPrintable.DecodeEncodedWord(input, Encoding.GetEncoding("iso-8859-1"));

            // And output should be correct
            Assert.AreEqual(expectedOutput, output);
        }
예제 #29
0
        public void CanDecodeLongSentence()
        {
            // Includes a space (=20 is SPACE) and and a soft line break (=\r\n is soft line break)
            const string input          = "If you believe that truth=3Dbeauty, then surely=20=\r\nmathematics is the most beautiful branch of philosophy.";
            const string expectedOutput = "If you believe that truth=beauty, then surely mathematics is the most beautiful branch of philosophy.";

            // No exceptions
            Assert.DoesNotThrow(delegate { QuotedPrintable.DecodeEncodedWord(input, Encoding.GetEncoding("iso-8859-1")); });

            // And output is to be decoded anyway
            string output = QuotedPrintable.DecodeEncodedWord(input, Encoding.GetEncoding("iso-8859-1"));

            Assert.AreEqual(expectedOutput, output);
        }
예제 #30
0
        public void ImplementationShouldBeRobustNothingAfterEqual()
        {
            const string input = "=";             // This is clearly illigal input, as the RFC says there MUST be something after

            // the equal sign. It also states that the parser should be robust. Therefore no exceptions must be thrown

            Assert.DoesNotThrow(delegate { QuotedPrintable.DecodeEncodedWord(input, Encoding.GetEncoding("iso-8859-1")); });             // Maybe exception thrown?

            // The RFC says that the input should be though of as not encoded at all
            const string expectedOutput = "=";

            string output = QuotedPrintable.DecodeEncodedWord(input, Encoding.GetEncoding("iso-8859-1"));

            // And output should be correct
            Assert.AreEqual(expectedOutput, output);
        }
예제 #31
0
        public void ImplementationShouldBeRobustNoHexAfterEqual()
        {
            const string input = "=PK";             // This is clearly illigal input, as the RFC says there MUST be a HEX string after the
            // equal sign.

            // It also states that the parser should be robust, and that in such case the input is not to be touched.
            const string expectedOutput = input;

            // Therefore no exceptions must be thrown
            Assert.DoesNotThrow(delegate { QuotedPrintable.DecodeEncodedWord(input, Encoding.GetEncoding("iso-8859-1")); });

            string output = QuotedPrintable.DecodeEncodedWord(input, Encoding.GetEncoding("iso-8859-1"));

            // And output should be equal input
            Assert.AreEqual(expectedOutput, output);
        }
예제 #32
0
    private bool SendMail (
                        string fromName,
                        string fromAddress,
                        string toName,
                        string toAddress,
                        string subject,
                        string bodyPlain)
    {
        QuotedPrintable qpUTF8 = new QuotedPrintable(Encoding.UTF8);
        QuotedPrintable qp8859 = new QuotedPrintable(Encoding.GetEncoding("ISO-8859-1"));
        MailMessage message = null;


        message = new MailMessage(new MailAddress(fromAddress, qpUTF8.EncodeMailHeaderString(fromName), Encoding.UTF8),
                                  new MailAddress(toAddress, qpUTF8.EncodeMailHeaderString(toName), Encoding.UTF8));

        message.Subject = subject;
        message.Body = bodyPlain;

        message.SubjectEncoding = Encoding.UTF8;
        message.BodyEncoding = Encoding.UTF8;


        try
        {
            SmtpClient client = new SmtpClient("mail.piratpartiet.se", 587);
            client.Credentials = null;
            client.Send(message);
            return true;
        }

        catch (Exception)
        {
            return false;
        }

    }