Esempio n. 1
0
		/// <summary>
		/// Clone the <see cref="Base64Decoder"/> with its current state.
		/// </summary>
		/// <remarks>
		/// Creates a new <see cref="Base64Decoder"/> with exactly the same state as the current decoder.
		/// </remarks>
		/// <returns>A new <see cref="Base64Decoder"/> with identical state.</returns>
		public IMimeDecoder Clone ()
		{
			var decoder = new Base64Decoder ();

			decoder.saved = saved;
			decoder.bytes = bytes;
			decoder.npad = npad;

			return decoder;
		}
Esempio n. 2
0
        /// <summary>
        /// Clone the <see cref="Base64Decoder"/> with its current state.
        /// </summary>
        /// <remarks>
        /// Creates a new <see cref="Base64Decoder"/> with exactly the same state as the current decoder.
        /// </remarks>
        /// <returns>A new <see cref="Base64Decoder"/> with identical state.</returns>
        public IMimeDecoder Clone()
        {
            var decoder = new Base64Decoder();

            decoder.saved = saved;
            decoder.bytes = bytes;
            decoder.npad  = npad;

            return(decoder);
        }
Esempio n. 3
0
        /// <summary>
        /// Clone the <see cref="Base64Decoder"/> with its current state.
        /// </summary>
        /// <remarks>
        /// Creates a new <see cref="Base64Decoder"/> with exactly the same state as the current decoder.
        /// </remarks>
        /// <returns>A new <see cref="Base64Decoder"/> with identical state.</returns>
        public IMimeDecoder Clone()
        {
            var decoder = new Base64Decoder();

            decoder.previous = previous;
            decoder.saved    = saved;
            decoder.bytes    = bytes;

            return(decoder);
        }
Esempio n. 4
0
		static unsafe string DecodeTokens (ParserOptions options, IList<Token> tokens, byte[] input, byte* inbuf, int length)
		{
			var decoded = new StringBuilder (length);
			var qp = new QuotedPrintableDecoder (true);
			var base64 = new Base64Decoder ();
			var output = new byte[length];
			Token token;
			int len;

			fixed (byte* outbuf = output) {
				for (int i = 0; i < tokens.Count; i++) {
					token = tokens[i];

					if (token.Encoding != ContentEncoding.Default) {
						// In order to work around broken mailers, we need to combine the raw
						// decoded content of runs of identically encoded word tokens before
						// converting to unicode strings.
						ContentEncoding encoding = token.Encoding;
						int codepage = token.CodePage;
						IMimeDecoder decoder;
						int outlen, n;
						byte* outptr;

						// find the end of this run (and measure the buffer length we'll need)
						for (n = i + 1; n < tokens.Count; n++) {
							if (tokens[n].Encoding != encoding || tokens[n].CodePage != codepage)
								break;
						}

						// base64 / quoted-printable decode each of the tokens...
						if (encoding == ContentEncoding.Base64)
							decoder = base64;
						else
							decoder = qp;

						outptr = outbuf;
						outlen = 0;

						do {
							// Note: by not resetting the decoder state each loop, we effectively
							// treat the payloads as one continuous block, thus allowing us to
							// handle cases where a hex-encoded triplet of a quoted-printable
							// encoded payload is split between 2 or more encoded-word tokens.
							len = DecodeToken (tokens[i], decoder, inbuf, outptr);
							outptr += len;
							outlen += len;
							i++;
						} while (i < n);

						decoder.Reset ();
						i--;

						var unicode = CharsetUtils.ConvertToUnicode (options, codepage, output, 0, outlen, out len);
						decoded.Append (unicode, 0, len);
					} else if (token.Is8bit) {
						// *sigh* I hate broken mailers...
						var unicode = CharsetUtils.ConvertToUnicode (options, input, token.StartIndex, token.Length, out len);
						decoded.Append (unicode, 0, len);
					} else {
						// pure 7bit ascii, a breath of fresh air...
						byte* inptr = inbuf + token.StartIndex;
						byte* inend = inptr + token.Length;

						while (inptr < inend)
							decoded.Append ((char) *inptr++);
					}
				}
			}

			return decoded.ToString ();
		}