www.pudn.com > MailAccess.rar > DecodeQP.cs


/****************************************************************************** 
	Copyright 2003-2004 Hamid Qureshi and Unruled Boy  
	OpenPOP.Net is free software; you can redistribute it and/or modify 
	it under the terms of the Lesser GNU General Public License as published by 
	the Free Software Foundation; either version 2 of the License, or 
	(at your option) any later version. 
 
	OpenPOP.Net is distributed in the hope that it will be useful, 
	but WITHOUT ANY WARRANTY; without even the implied warranty of 
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
	Lesser GNU General Public License for more details. 
 
	You should have received a copy of the Lesser GNU General Public License 
	along with this program; if not, write to the Free Software 
	Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
/*******************************************************************************/ 
 
/* 
*Name:			OpenPOP.MIMEParser.DecodeQP 
*Function:		Decoding Quoted-Printable text 
*Author:		coollzh(coollzh@hotmail.com) 
*Created:		2003/8 
*Modified:		2004/3/29 12:33 GMT+8 
*Description: 
*Changes:		 
*/ 
using System; 
using System.Text; 
using System.Globalization; 
 
namespace OpenPOP.MIMEParser 
{ 
	///  
	/// Decoding Quoted-Printable text 
	///  
	///  
	public class DecodeQP 
	{ 
		public DecodeQP() 
		{ 
		} 
 
		///  
		/// Decoding Quoted-Printable string 
		///  
		/// Quoted-Printable encoded string 
		/// encoding method 
		/// decoded string 
		public static string ConvertHexToString(string Hexstring,string Encoding) 
		{ 
			try 
			{return ConvertHexToString(Hexstring, System.Text.Encoding.GetEncoding(Encoding));} 
			catch 
			{return ConvertHexContent(Hexstring);} 
		} 
 
		///  
		/// Decoding Quoted-Printable string 
		///  
		/// Quoted-Printable encoded string 
		/// encoding method 
		/// decoded string 
		public static string ConvertHexToString(string Hexstring,Encoding encode) 
		{			 
			try 
			{ 
				if(Hexstring==null||Hexstring.Equals("")) return ""; 
 
				if(Hexstring.StartsWith("=")) Hexstring=Hexstring.Substring(1); 
			 
				string[] aHex= Hexstring.Split(new char[1]{'='}); 
				byte[] abyte = new Byte[aHex.Length]; 
			 
				for(int i=0;i 
		/// Decoding Quoted-Printable string at a position 
		///  
		/// Quoted-Printable encoded string 
		/// encoding method, "Default" is suggested 
		/// position to start, normally 0 
		/// decoded string 
		public static string ConvertHexContent(string Hexstring,Encoding encode,long nStart) 
		{			 
			if(nStart>=Hexstring.Length) return Hexstring; 
 
			//to hold string to be decoded 
			StringBuilder sbHex = new  StringBuilder(); 
			sbHex.Append(""); 
			//to hold decoded string 
			StringBuilder sbEncoded = new StringBuilder(); 
			sbEncoded.Append(""); 
			//wether we reach Quoted-Printable string 
			bool isBegin = false; 
			string temp; 
			int i = (int)nStart; 
 
			while(i 
		/// Decoding Quoted-Printable string using default encoding and begin at 0 
		///  
		/// Quoted-Printable encoded string 
		/// decoded string 
		public static string ConvertHexContent(string Hexstring) 
		{ 
			if(Hexstring==null || Hexstring.Equals("")) return Hexstring; 
 
			return ConvertHexContent(Hexstring,Encoding.Default,0); 
			 
		} 
	} 
}