Click here to Skip to main content
15,884,099 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 150.7K   4.2K   38  
A C# implementation of Mime de/encode
using System;

namespace MIME
{
	/// <summary>
	/// 
	/// </summary>
	public class MimeType
	{
		public MimeType()
		{
			// 
			// TODO: Add constructor logic here
			//
		}

		
		public struct MediaTypeCvt
		{
			public MediaType nMediaType;
			public string pszSubType;
			public string pszFileExt;
			public MediaTypeCvt(MediaType nMediaType, string pszSubType, string pszFileExt)
			{
				this.nMediaType = nMediaType;
				this.pszSubType = pszSubType;
				this.pszFileExt = pszFileExt;
			}
		}

		public enum MediaType
		{
			MEDIA_TEXT=0, MEDIA_IMAGE, MEDIA_AUDIO, MEDIA_VEDIO, MEDIA_APPLICATION,
			MEDIA_MULTIPART, MEDIA_MESSAGE,
			MEDIA_UNKNOWN
		}

		public static readonly string[] TypeTable = {"text", "image", "audio", "vedio", "application", "multipart", "message", null};

		public static readonly MediaTypeCvt[]  TypeCvtTable = 
			new MediaTypeCvt[] {
								   // media-type, sub-type, file extension
								   new MediaTypeCvt( MediaType.MEDIA_APPLICATION, "xml", "xml" ),
								   new MediaTypeCvt( MediaType.MEDIA_APPLICATION, "msword", "doc" ),
								   new MediaTypeCvt( MediaType.MEDIA_APPLICATION, "rtf", "rtf" ),
								   new MediaTypeCvt( MediaType.MEDIA_APPLICATION, "vnd.ms-excel", "xls" ),
								   new MediaTypeCvt( MediaType.MEDIA_APPLICATION, "vnd.ms-powerpoint", "ppt" ),
								   new MediaTypeCvt( MediaType.MEDIA_APPLICATION, "pdf", "pdf" ),
								   new MediaTypeCvt( MediaType.MEDIA_APPLICATION, "zip", "zip" ),

								   new MediaTypeCvt( MediaType.MEDIA_IMAGE, "jpeg", "jpeg" ),
								   new MediaTypeCvt( MediaType.MEDIA_IMAGE, "jpeg", "jpg" ),
								   new MediaTypeCvt( MediaType.MEDIA_IMAGE, "gif", "gif" ),
								   new MediaTypeCvt( MediaType.MEDIA_IMAGE, "tiff", "tif" ),
								   new MediaTypeCvt( MediaType.MEDIA_IMAGE, "tiff", "tiff" ),

								   new MediaTypeCvt( MediaType.MEDIA_AUDIO, "basic", "wav" ),
								   new MediaTypeCvt( MediaType.MEDIA_AUDIO, "basic", "mp3" ),

								   new MediaTypeCvt( MediaType.MEDIA_VEDIO, "mpeg", "mpg" ),
								   new MediaTypeCvt( MediaType.MEDIA_VEDIO, "mpeg", "mpeg" ),

								   new MediaTypeCvt( MediaType.MEDIA_UNKNOWN, "", "" )		// add new subtypes before this line
							   };
	}
}

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