Пример #1
0
        /// <summary>
        /// Clone the <see cref="YDecoder"/> with its current state.
        /// </summary>
        /// <remarks>
        /// Creates a new <see cref="YDecoder"/> with exactly the same state as the current decoder.
        /// </remarks>
        /// <returns>A new <see cref="YDecoder"/> with identical state.</returns>
        public IMimeDecoder Clone()
        {
            var decoder = new YDecoder(initial == YDecoderState.Payload);

            decoder.crc   = crc.Clone();
            decoder.state = state;
            decoder.octet = octet;
            decoder.eoln  = eoln;

            return(decoder);
        }
Пример #2
0
		public void TestDecodeSimpleYEncMessage ()
		{
			using (var file = File.OpenRead ("../../TestData/yenc/simple.msg")) {
				var message = MimeMessage.Load (file);

				using (var decoded = new MemoryStream ()) {
					var ydec = new YDecoder ();

					using (var filtered = new FilteredStream (decoded)) {
						filtered.Add (new DecoderFilter (ydec));

						((MimePart) message.Body).ContentObject.WriteTo (filtered);
					}

					Assert.AreEqual (584, decoded.Length, "The decoded size does not match.");
					Assert.AreEqual (0xded29f4f, ydec.Checksum ^ 0xffffffff, "The checksum does not match.");
				}
			}
		}
Пример #3
0
		public void TestSimpleYEncMessage ()
		{
			using (var file = File.OpenRead ("../../TestData/yenc/simple.msg")) {
				var message = MimeMessage.Load (file);

				using (var decoded = new MemoryStream ()) {
					var ydec = new YDecoder ();

					using (var filtered = new FilteredStream (decoded)) {
						filtered.Add (new DecoderFilter (ydec));

						((MimePart) message.Body).ContentObject.WriteTo (filtered);
						filtered.Flush ();
					}

					decoded.Position = 0;

					Assert.AreEqual (584, decoded.Length, "The decoded size does not match.");
					Assert.AreEqual (0xded29f4f, ydec.Checksum ^ 0xffffffff, "The decoded checksum does not match.");

					// now re-encode it
					using (var encoded = new MemoryStream ()) {
						var ybegin = Encoding.ASCII.GetBytes ("-- \n=ybegin line=128 size=584 name=testfile.txt \n");
						var yend = Encoding.ASCII.GetBytes ("=yend size=584 crc32=ded29f4f \n");
						var yenc = new YEncoder ();

						encoded.Write (ybegin, 0, ybegin.Length);

						using (var filtered = new FilteredStream (encoded)) {
							filtered.Add (new EncoderFilter (yenc));

							decoded.CopyTo (filtered, 4096);
							filtered.Flush ();
						}

						encoded.Write (yend, 0, yend.Length);

						Assert.AreEqual (0xded29f4f, yenc.Checksum ^ 0xffffffff, "The encoded checksum does not match.");

						using (var original = new MemoryStream ()) {
							using (var filtered = new FilteredStream (original)) {
								filtered.Add (new Dos2UnixFilter ());

								((MimePart) message.Body).ContentObject.WriteTo (filtered);
								filtered.Flush ();
							}

							var latin1 = Encoding.GetEncoding ("iso-8859-1");
							var buf = original.GetBuffer ();

							var expected = latin1.GetString (buf, 0, (int) original.Length);

							buf = encoded.GetBuffer ();

							var actual = latin1.GetString (buf, 0, (int) encoded.Length);

							Assert.AreEqual (expected, actual, "Encoded value does not match original.");
						}
					}
				}
			}
		}
Пример #4
0
		/// <summary>
		/// Clone the <see cref="YDecoder"/> with its current state.
		/// </summary>
		/// <remarks>
		/// Creates a new <see cref="YDecoder"/> with exactly the same state as the current decoder.
		/// </remarks>
		/// <returns>A new <see cref="YDecoder"/> with identical state.</returns>
		public IMimeDecoder Clone ()
		{
			var decoder = new YDecoder (initial == YDecoderState.Payload);

			decoder.crc = crc.Clone ();
			decoder.state = state;
			decoder.octet = octet;
			decoder.eoln = eoln;

			return decoder;
		}