MIMETypes.cs
上传用户:hncsjykj
上传日期:2022-08-09
资源大小:461k
文件大小:17k
源码类别:

Email客户端

开发平台:

C#

  1. /******************************************************************************
  2. Copyright 2003-2004 Hamid Qureshi and Unruled Boy 
  3. OpenPOP.Net is free software; you can redistribute it and/or modify
  4. it under the terms of the Lesser GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. OpenPOP.Net is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  10. Lesser GNU General Public License for more details.
  11. You should have received a copy of the Lesser GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  14. /*******************************************************************************/
  15. /*
  16. *Name: OpenPOP.MIMETypes
  17. *Function: MIME Types
  18. *Author: Unruled Boy
  19. *Created: 2004/3/29
  20. *Modified: 2004/3/30 09:10 GMT+8
  21. *Description:
  22. *Changes:
  23. * 2004/3/30 09:10 GMT+8 by Unruled Boy
  24. * 1.Adding full list of MIME Types
  25. */
  26. using System;
  27. using System.IO;
  28. using System.Collections;
  29. namespace OpenPOP
  30. {
  31. /// <summary>
  32. /// MIMETypes
  33. /// </summary>
  34. public class MIMETypes
  35. {
  36. public const string MIMEType_MSTNEF="application/ms-tnef";
  37. private const string Content_Transfer_Encoding_Tag="Content-Transfer-Encoding";
  38. private static Hashtable _MIMETypeList=null;
  39. public static string GetContentTransferEncoding(string strBuffer, int pos)
  40. {
  41. int begin=0,end=0;
  42. begin=strBuffer.ToLower().IndexOf(Content_Transfer_Encoding_Tag.ToLower(),pos);
  43. if(begin!=-1)
  44. {
  45. end=strBuffer.ToLower().IndexOf("rn".ToLower(),begin+1);
  46. return strBuffer.Substring(begin+Content_Transfer_Encoding_Tag.Length+1,end-begin-Content_Transfer_Encoding_Tag.Length).Trim();
  47. }
  48. else
  49. return "";
  50. }
  51. public static bool IsMSTNEF(string strContentType)
  52. {
  53. if(strContentType!=null & strContentType!="")
  54. if(strContentType.ToLower() == MIMEType_MSTNEF.ToLower())
  55. return true;
  56. else
  57. return false;
  58. else
  59. return false;
  60. }
  61. public static string ContentType(string strExtension)
  62. {
  63. if(_MIMETypeList.ContainsKey(strExtension))
  64. return _MIMETypeList[strExtension].ToString();
  65. else
  66. return null;
  67. }
  68. public static Hashtable MIMETypeList
  69. {
  70. get{return _MIMETypeList;}
  71. set{_MIMETypeList=value;}
  72. }
  73. ~MIMETypes()
  74. {
  75. _MIMETypeList.Clear();
  76. _MIMETypeList=null;
  77. }
  78. public MIMETypes()
  79. {
  80. _MIMETypeList.Add(".323","text/h323");
  81. _MIMETypeList.Add(".3gp","video/3gpp");
  82. _MIMETypeList.Add(".3gpp","video/3gpp");
  83. _MIMETypeList.Add(".acp","audio/x-mei-aac");
  84. _MIMETypeList.Add(".act","text/xml");
  85. _MIMETypeList.Add(".actproj","text/plain");
  86. _MIMETypeList.Add(".ade","application/msaccess");
  87. _MIMETypeList.Add(".adp","application/msaccess");
  88. _MIMETypeList.Add(".ai","application/postscript");
  89. _MIMETypeList.Add(".aif","audio/aiff");
  90. _MIMETypeList.Add(".aifc","audio/aiff");
  91. _MIMETypeList.Add(".aiff","audio/aiff");
  92. _MIMETypeList.Add(".asf","video/x-ms-asf");
  93. _MIMETypeList.Add(".asm","text/plain");
  94. _MIMETypeList.Add(".asx","video/x-ms-asf");
  95. _MIMETypeList.Add(".au","audio/basic");
  96. _MIMETypeList.Add(".avi","video/avi");
  97. _MIMETypeList.Add(".bmp","image/bmp");
  98. _MIMETypeList.Add(".bwp","application/x-bwpreview");
  99. _MIMETypeList.Add(".c","text/plain");
  100. _MIMETypeList.Add(".cat","application/vnd.ms-pki.seccat");
  101. _MIMETypeList.Add(".cc","text/plain");
  102. _MIMETypeList.Add(".cdf","application/x-cdf");
  103. _MIMETypeList.Add(".cer","application/x-x509-ca-cert");
  104. _MIMETypeList.Add(".cod","text/plain");
  105. _MIMETypeList.Add(".cpp","text/plain");
  106. _MIMETypeList.Add(".crl","application/pkix-crl");
  107. _MIMETypeList.Add(".crt","application/x-x509-ca-cert");
  108. _MIMETypeList.Add(".cs","text/plain");
  109. _MIMETypeList.Add(".css","text/css");
  110. _MIMETypeList.Add(".csv","application/vnd.ms-excel");
  111. _MIMETypeList.Add(".cxx","text/plain");
  112. _MIMETypeList.Add(".dbs","text/plain");
  113. _MIMETypeList.Add(".def","text/plain");
  114. _MIMETypeList.Add(".der","application/x-x509-ca-cert");
  115. _MIMETypeList.Add(".dib","image/bmp");
  116. _MIMETypeList.Add(".dif","video/x-dv");
  117. _MIMETypeList.Add(".dll","application/x-msdownload");
  118. _MIMETypeList.Add(".doc","application/msword");
  119. _MIMETypeList.Add(".dot","application/msword");
  120. _MIMETypeList.Add(".dsp","text/plain");
  121. _MIMETypeList.Add(".dsw","text/plain");
  122. _MIMETypeList.Add(".dv","video/x-dv");
  123. _MIMETypeList.Add(".edn","application/vnd.adobe.edn");
  124. _MIMETypeList.Add(".eml","message/rfc822");
  125. _MIMETypeList.Add(".eps","application/postscript");
  126. _MIMETypeList.Add(".etd","application/x-ebx");
  127. _MIMETypeList.Add(".etp","text/plain");
  128. _MIMETypeList.Add(".exe","application/x-msdownload");
  129. _MIMETypeList.Add(".ext","text/plain");
  130. _MIMETypeList.Add(".fdf","application/vnd.fdf");
  131. _MIMETypeList.Add(".fif","application/fractals");
  132. _MIMETypeList.Add(".fky","text/plain");
  133. _MIMETypeList.Add(".gif","image/gif");
  134. _MIMETypeList.Add(".gz","application/x-gzip");
  135. _MIMETypeList.Add(".h","text/plain");
  136. _MIMETypeList.Add(".hpp","text/plain");
  137. _MIMETypeList.Add(".hqx","application/mac-binhex40");
  138. _MIMETypeList.Add(".hta","application/hta");
  139. _MIMETypeList.Add(".htc","text/x-component");
  140. _MIMETypeList.Add(".htm","text/html");
  141. _MIMETypeList.Add(".html","text/html");
  142. _MIMETypeList.Add(".htt","text/webviewhtml");
  143. _MIMETypeList.Add(".hxx","text/plain");
  144. _MIMETypeList.Add(".i","text/plain");
  145. _MIMETypeList.Add(".iad","application/x-iad");
  146. _MIMETypeList.Add(".ico","image/x-icon");
  147. _MIMETypeList.Add(".ics","text/calendar");
  148. _MIMETypeList.Add(".idl","text/plain");
  149. _MIMETypeList.Add(".iii","application/x-iphone");
  150. _MIMETypeList.Add(".inc","text/plain");
  151. _MIMETypeList.Add(".infopathxml","application/ms-infopath.xml");
  152. _MIMETypeList.Add(".inl","text/plain");
  153. _MIMETypeList.Add(".ins","application/x-internet-signup");
  154. _MIMETypeList.Add(".iqy","text/x-ms-iqy");
  155. _MIMETypeList.Add(".isp","application/x-internet-signup");
  156. _MIMETypeList.Add(".java","text/java");
  157. _MIMETypeList.Add(".jfif","image/jpeg");
  158. _MIMETypeList.Add(".jnlp","application/x-java-jnlp-file");
  159. _MIMETypeList.Add(".jpe","image/jpeg");
  160. _MIMETypeList.Add(".jpeg","image/jpeg");
  161. _MIMETypeList.Add(".jpg","image/jpeg");
  162. _MIMETypeList.Add(".jsl","text/plain");
  163. _MIMETypeList.Add(".kci","text/plain");
  164. _MIMETypeList.Add(".la1","audio/x-liquid-file");
  165. _MIMETypeList.Add(".lar","application/x-laplayer-reg");
  166. _MIMETypeList.Add(".latex","application/x-latex");
  167. _MIMETypeList.Add(".lavs","audio/x-liquid-secure");
  168. _MIMETypeList.Add(".lgn","text/plain");
  169. _MIMETypeList.Add(".lmsff","audio/x-la-lms");
  170. _MIMETypeList.Add(".lqt","audio/x-la-lqt");
  171. _MIMETypeList.Add(".lst","text/plain");
  172. _MIMETypeList.Add(".m1v","video/mpeg");
  173. _MIMETypeList.Add(".m3u","audio/mpegurl");
  174. _MIMETypeList.Add(".m4e","video/mpeg4");
  175. _MIMETypeList.Add(".MAC","image/x-macpaint");
  176. _MIMETypeList.Add(".mak","text/plain");
  177. _MIMETypeList.Add(".man","application/x-troff-man");
  178. _MIMETypeList.Add(".map","text/plain");
  179. _MIMETypeList.Add(".mda","application/msaccess");
  180. _MIMETypeList.Add(".mdb","application/msaccess");
  181. _MIMETypeList.Add(".mde","application/msaccess");
  182. _MIMETypeList.Add(".mdi","image/vnd.ms-modi");
  183. _MIMETypeList.Add(".mfp","application/x-shockwave-flash");
  184. _MIMETypeList.Add(".mht","message/rfc822");
  185. _MIMETypeList.Add(".mhtml","message/rfc822");
  186. _MIMETypeList.Add(".mid","audio/mid");
  187. _MIMETypeList.Add(".midi","audio/mid");
  188. _MIMETypeList.Add(".mk","text/plain");
  189. _MIMETypeList.Add(".mnd","audio/x-musicnet-download");
  190. _MIMETypeList.Add(".mns","audio/x-musicnet-stream");
  191. _MIMETypeList.Add(".MP1","audio/mp1");
  192. _MIMETypeList.Add(".mp2","video/mpeg");
  193. _MIMETypeList.Add(".mp2v","video/mpeg");
  194. _MIMETypeList.Add(".mp3","audio/mpeg");
  195. _MIMETypeList.Add(".mp4","video/mp4");
  196. _MIMETypeList.Add(".mpa","video/mpeg");
  197. _MIMETypeList.Add(".mpe","video/mpeg");
  198. _MIMETypeList.Add(".mpeg","video/mpeg");
  199. _MIMETypeList.Add(".mpf","application/vnd.ms-mediapackage");
  200. _MIMETypeList.Add(".mpg","video/mpeg");
  201. _MIMETypeList.Add(".mpg4","video/mp4");
  202. _MIMETypeList.Add(".mpga","audio/rn-mpeg");
  203. _MIMETypeList.Add(".mpv2","video/mpeg");
  204. _MIMETypeList.Add(".NMW","application/nmwb");
  205. _MIMETypeList.Add(".nws","message/rfc822");
  206. _MIMETypeList.Add(".odc","text/x-ms-odc");
  207. _MIMETypeList.Add(".odh","text/plain");
  208. _MIMETypeList.Add(".odl","text/plain");
  209. _MIMETypeList.Add(".p10","application/pkcs10");
  210. _MIMETypeList.Add(".p12","application/x-pkcs12");
  211. _MIMETypeList.Add(".p7b","application/x-pkcs7-certificates");
  212. _MIMETypeList.Add(".p7c","application/pkcs7-mime");
  213. _MIMETypeList.Add(".p7m","application/pkcs7-mime");
  214. _MIMETypeList.Add(".p7r","application/x-pkcs7-certreqresp");
  215. _MIMETypeList.Add(".p7s","application/pkcs7-signature");
  216. _MIMETypeList.Add(".PCT","image/pict");
  217. _MIMETypeList.Add(".pdf","application/pdf");
  218. _MIMETypeList.Add(".pdx","application/vnd.adobe.pdx");
  219. _MIMETypeList.Add(".pfx","application/x-pkcs12");
  220. _MIMETypeList.Add(".pic","image/pict");
  221. _MIMETypeList.Add(".PICT","image/pict");
  222. _MIMETypeList.Add(".pko","application/vnd.ms-pki.pko");
  223. _MIMETypeList.Add(".png","image/png");
  224. _MIMETypeList.Add(".pnt","image/x-macpaint");
  225. _MIMETypeList.Add(".pntg","image/x-macpaint");
  226. _MIMETypeList.Add(".pot","application/vnd.ms-powerpoint");
  227. _MIMETypeList.Add(".ppa","application/vnd.ms-powerpoint");
  228. _MIMETypeList.Add(".pps","application/vnd.ms-powerpoint");
  229. _MIMETypeList.Add(".ppt","application/vnd.ms-powerpoint");
  230. _MIMETypeList.Add(".prc","text/plain");
  231. _MIMETypeList.Add(".prf","application/pics-rules");
  232. _MIMETypeList.Add(".ps","application/postscript");
  233. _MIMETypeList.Add(".pub","application/vnd.ms-publisher");
  234. _MIMETypeList.Add(".pwz","application/vnd.ms-powerpoint");
  235. _MIMETypeList.Add(".qt","video/quicktime");
  236. _MIMETypeList.Add(".qti","image/x-quicktime");
  237. _MIMETypeList.Add(".qtif","image/x-quicktime");
  238. _MIMETypeList.Add(".qtl","application/x-quicktimeplayer");
  239. _MIMETypeList.Add(".qup","application/x-quicktimeupdater");
  240. _MIMETypeList.Add(".r1m","application/vnd.rn-recording");
  241. _MIMETypeList.Add(".r3t","text/vnd.rn-realtext3d");
  242. _MIMETypeList.Add(".RA","audio/vnd.rn-realaudio");
  243. _MIMETypeList.Add(".RAM","audio/x-pn-realaudio");
  244. _MIMETypeList.Add(".rat","application/rat-file");
  245. _MIMETypeList.Add(".rc","text/plain");
  246. _MIMETypeList.Add(".rc2","text/plain");
  247. _MIMETypeList.Add(".rct","text/plain");
  248. _MIMETypeList.Add(".rec","application/vnd.rn-recording");
  249. _MIMETypeList.Add(".rgs","text/plain");
  250. _MIMETypeList.Add(".rjs","application/vnd.rn-realsystem-rjs");
  251. _MIMETypeList.Add(".rjt","application/vnd.rn-realsystem-rjt");
  252. _MIMETypeList.Add(".RM","application/vnd.rn-realmedia");
  253. _MIMETypeList.Add(".rmf","application/vnd.adobe.rmf");
  254. _MIMETypeList.Add(".rmi","audio/mid");
  255. _MIMETypeList.Add(".RMJ","application/vnd.rn-realsystem-rmj");
  256. _MIMETypeList.Add(".RMM","audio/x-pn-realaudio");
  257. _MIMETypeList.Add(".rms","application/vnd.rn-realmedia-secure");
  258. _MIMETypeList.Add(".rmvb","application/vnd.rn-realmedia-vbr");
  259. _MIMETypeList.Add(".RMX","application/vnd.rn-realsystem-rmx");
  260. _MIMETypeList.Add(".RNX","application/vnd.rn-realplayer");
  261. _MIMETypeList.Add(".rp","image/vnd.rn-realpix");
  262. _MIMETypeList.Add(".RPM","audio/x-pn-realaudio-plugin");
  263. _MIMETypeList.Add(".rqy","text/x-ms-rqy");
  264. _MIMETypeList.Add(".rsml","application/vnd.rn-rsml");
  265. _MIMETypeList.Add(".rt","text/vnd.rn-realtext");
  266. _MIMETypeList.Add(".rtf","application/msword");
  267. _MIMETypeList.Add(".rul","text/plain");
  268. _MIMETypeList.Add(".RV","video/vnd.rn-realvideo");
  269. _MIMETypeList.Add(".s","text/plain");
  270. _MIMETypeList.Add(".sc2","application/schdpl32");
  271. _MIMETypeList.Add(".scd","application/schdpl32");
  272. _MIMETypeList.Add(".sch","application/schdpl32");
  273. _MIMETypeList.Add(".sct","text/scriptlet");
  274. _MIMETypeList.Add(".sd2","audio/x-sd2");
  275. _MIMETypeList.Add(".sdp","application/sdp");
  276. _MIMETypeList.Add(".sit","application/x-stuffit");
  277. _MIMETypeList.Add(".slk","application/vnd.ms-excel");
  278. _MIMETypeList.Add(".sln","application/octet-stream");
  279. _MIMETypeList.Add(".SMI","application/smil");
  280. _MIMETypeList.Add(".smil","application/smil");
  281. _MIMETypeList.Add(".snd","audio/basic");
  282. _MIMETypeList.Add(".snp","application/msaccess");
  283. _MIMETypeList.Add(".spc","application/x-pkcs7-certificates");
  284. _MIMETypeList.Add(".spl","application/futuresplash");
  285. _MIMETypeList.Add(".sql","text/plain");
  286. _MIMETypeList.Add(".srf","text/plain");
  287. _MIMETypeList.Add(".ssm","application/streamingmedia");
  288. _MIMETypeList.Add(".sst","application/vnd.ms-pki.certstore");
  289. _MIMETypeList.Add(".stl","application/vnd.ms-pki.stl");
  290. _MIMETypeList.Add(".swf","application/x-shockwave-flash");
  291. _MIMETypeList.Add(".tab","text/plain");
  292. _MIMETypeList.Add(".tar","application/x-tar");
  293. _MIMETypeList.Add(".tdl","text/xml");
  294. _MIMETypeList.Add(".tgz","application/x-compressed");
  295. _MIMETypeList.Add(".tif","image/tiff");
  296. _MIMETypeList.Add(".tiff","image/tiff");
  297. _MIMETypeList.Add(".tlh","text/plain");
  298. _MIMETypeList.Add(".tli","text/plain");
  299. _MIMETypeList.Add(".torrent","application/x-bittorrent");
  300. _MIMETypeList.Add(".trg","text/plain");
  301. _MIMETypeList.Add(".txt","text/plain");
  302. _MIMETypeList.Add(".udf","text/plain");
  303. _MIMETypeList.Add(".udt","text/plain");
  304. _MIMETypeList.Add(".uls","text/iuls");
  305. _MIMETypeList.Add(".user","text/plain");
  306. _MIMETypeList.Add(".usr","text/plain");
  307. _MIMETypeList.Add(".vb","text/plain");
  308. _MIMETypeList.Add(".vcf","text/x-vcard");
  309. _MIMETypeList.Add(".vcproj","text/plain");
  310. _MIMETypeList.Add(".viw","text/plain");
  311. _MIMETypeList.Add(".vpg","application/x-vpeg005");
  312. _MIMETypeList.Add(".vspscc","text/plain");
  313. _MIMETypeList.Add(".vsscc","text/plain");
  314. _MIMETypeList.Add(".vssscc","text/plain");
  315. _MIMETypeList.Add(".wav","audio/wav");
  316. _MIMETypeList.Add(".wax","audio/x-ms-wax");
  317. _MIMETypeList.Add(".wbk","application/msword");
  318. _MIMETypeList.Add(".wiz","application/msword");
  319. _MIMETypeList.Add(".wm","video/x-ms-wm");
  320. _MIMETypeList.Add(".wma","audio/x-ms-wma");
  321. _MIMETypeList.Add(".wmd","application/x-ms-wmd");
  322. _MIMETypeList.Add(".wmv","video/x-ms-wmv");
  323. _MIMETypeList.Add(".wmx","video/x-ms-wmx");
  324. _MIMETypeList.Add(".wmz","application/x-ms-wmz");
  325. _MIMETypeList.Add(".wpl","application/vnd.ms-wpl");
  326. _MIMETypeList.Add(".wprj","application/webzip");
  327. _MIMETypeList.Add(".wsc","text/scriptlet");
  328. _MIMETypeList.Add(".wvx","video/x-ms-wvx");
  329. _MIMETypeList.Add(".XBM","image/x-xbitmap");
  330. _MIMETypeList.Add(".xdp","application/vnd.adobe.xdp+xml");
  331. _MIMETypeList.Add(".xfd","application/vnd.adobe.xfd+xml");
  332. _MIMETypeList.Add(".xfdf","application/vnd.adobe.xfdf");
  333. _MIMETypeList.Add(".xla","application/vnd.ms-excel");
  334. _MIMETypeList.Add(".xlb","application/vnd.ms-excel");
  335. _MIMETypeList.Add(".xlc","application/vnd.ms-excel");
  336. _MIMETypeList.Add(".xld","application/vnd.ms-excel");
  337. _MIMETypeList.Add(".xlk","application/vnd.ms-excel");
  338. _MIMETypeList.Add(".xll","application/vnd.ms-excel");
  339. _MIMETypeList.Add(".xlm","application/vnd.ms-excel");
  340. _MIMETypeList.Add(".xls","application/vnd.ms-excel");
  341. _MIMETypeList.Add(".xlt","application/vnd.ms-excel");
  342. _MIMETypeList.Add(".xlv","application/vnd.ms-excel");
  343. _MIMETypeList.Add(".xlw","application/vnd.ms-excel");
  344. _MIMETypeList.Add(".xml","text/xml");
  345. _MIMETypeList.Add(".xpl","audio/scpls");
  346. _MIMETypeList.Add(".xsl","text/xml");
  347. _MIMETypeList.Add(".z","application/x-compress");
  348. _MIMETypeList.Add(".zip","application/x-zip-compressed");
  349. }
  350. /// <summary>Returns the MIME content-type for the supplied file extension</summary>
  351. /// <returns>string MIME type (Example: "text/plain")</returns>
  352. public static string GetMimeType(string strFileName)
  353. {
  354. try
  355. {
  356. string strFileExtension=new FileInfo(strFileName).Extension;
  357. string strContentType=null;
  358. bool MONO=false;
  359. if(MONO)
  360. {
  361. strContentType=MIMETypes.ContentType(strFileExtension);
  362. }
  363. else
  364. {
  365. Microsoft.Win32.RegistryKey extKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(strFileExtension);
  366. strContentType = (string)extKey.GetValue("Content Type");
  367. }
  368. if (strContentType.ToString() != null)
  369. {
  370. return strContentType.ToString(); 
  371. }
  372. else
  373. { return "application/octet-stream"; }
  374. }
  375. catch(System.Exception)
  376. { return "application/octet-stream"; }
  377. }
  378. }
  379. }