Click here to Skip to main content
15,893,161 members
Articles / Programming Languages / C#

A C# Implementation of Mime De/encode

Rate me:
Please Sign up or sign in to vote.
4.00/5 (16 votes)
21 Aug 2005CPOL 151.2K   4.2K   38  
A C# implementation of Mime de/encode
using System;
using System.Collections;

namespace MIME
{
	/// <summary>
	/// 
	/// </summary>
	public class MimeCodeManager
	{
		private MimeCodeManager()
		{
			// 
			// TODO: Add constructor logic here
			//
			InitialCode();
		}

		private static Hashtable codeHT = new Hashtable();

		private static readonly MimeCodeManager instance = new MimeCodeManager();

		public static MimeCodeManager Instance
		{
			get{ return instance;}
		}

		private void InitialCode()
		{
			MimeCode aFieldCode = new MimeFieldCodeBase();
			SetCode("Subject", aFieldCode);
			SetCode("Comments", aFieldCode);
			SetCode("Content-Description", aFieldCode);

			aFieldCode = new MimeFieldCodeAddress();
			SetCode("From", aFieldCode);
			SetCode("To", aFieldCode);
			SetCode("Resent-To", aFieldCode);
			SetCode("Cc", aFieldCode);
			SetCode("Resent-Cc", aFieldCode);
			SetCode("Bcc", aFieldCode);
			SetCode("Resent-Bcc", aFieldCode);
			SetCode("Reply-To", aFieldCode);
			SetCode("Resent-Reply-To", aFieldCode);
			
			aFieldCode = new MimeFieldCodeParameter();
			SetCode("Content-Type", aFieldCode);
			SetCode("Content-Disposition", aFieldCode);

			MimeCode aCode = new MimeCode();
			SetCode("7bit", aCode);
			
			SetCode("8bit", aCode);

			aCode = new MimeCodeBase64();
			SetCode("base64", aCode);

			aCode = new MimeCodeQP();
			SetCode("quoted-printable", aCode);

		}

		public void SetCode(string name, MimeCode code)
		{
			codeHT.Add(name.ToLower(), code);
		}

		public MimeCode GetCode(string name)
		{
			return (MimeCode)codeHT[name.ToLower()];
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
China China
I think I have to start coding my life now...Smile | :)

Comments and Discussions