IdMIMETypes.pas 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. {
  2. $Project$
  3. $Workfile$
  4. $Revision$
  5. $DateUTC$
  6. $Id$
  7. This file is part of the Indy (Internet Direct) project, and is offered
  8. under the dual-licensing agreement described on the Indy website.
  9. (http://www.indyproject.org/)
  10. Copyright:
  11. (c) 1993-2005, Chad Z. Hower and the Indy Pit Crew. All rights reserved.
  12. }
  13. {
  14. $Log$
  15. }
  16. {
  17. Rev 1.1 2004.02.03 5:44:08 PM czhower
  18. Name changes
  19. Rev 1.0 11/13/2002 07:57:36 AM JPMugaas
  20. 2000-Mar-27 Pete Mee
  21. - ReturnMIMETypes should return the most relevant MIME type+encoding pair
  22. to the values passed - i.e., removes x- where it is unnecessary & modifies
  23. the type if it is known to be incorrect. (Stupid-)Example:
  24. application/octet-stream + x-base64 should be application/octet-stream +
  25. base64... Warning: this file is expected to grow to become mainly constants!!
  26. }
  27. unit IdMIMETypes;
  28. interface
  29. {$i IdCompilerDefines.inc}
  30. const
  31. MIMESplit = '/'; {Do not Localize}
  32. MIMEXVal = 'x-'; {Do not Localize}
  33. MIMETypeApplication = 'application' + MIMESplit; {Do not Localize}
  34. MIMETypeAudio = 'audio' + MIMESplit; {Do not Localize}
  35. MIMETypeImage = 'image' + MIMESplit; {Do not Localize}
  36. MIMETypeMessage = 'message' + MIMESplit; {Do not Localize}
  37. MIMETypeMultipart = 'multipart' + MIMESplit; {Do not Localize}
  38. MIMETypeText = 'text' + MIMESplit; {Do not Localize}
  39. MIMETypeVideo = 'video' + MIMESplit; {Do not Localize}
  40. MaxMIMEType = 6;
  41. // MIME Sub-Types
  42. MIMESubOctetStream = 'octet-stream'; {Do not Localize}
  43. MIMESubMacBinHex40 = 'mac-binhex40'; {Do not Localize}
  44. MaxMIMESubTypes = 1;
  45. // BinToASCII
  46. MIMEEncBase64 = 'base64'; // Correct MIME type {Do not Localize}
  47. MIMEEncUUEncode = MIMEXVal + 'uu'; // A guess... {Do not Localize}
  48. MIMEEncXXEncode = MIMEXVal + 'xx'; // A guess... {Do not Localize}
  49. MaxMIMEBinToASCIIType = 2;
  50. // Message Digests - a MIME type probably doesn't exist for these... {Do not Localize}
  51. MIMEEncRSAMD2 = MIMEXVal + 'rsa-md2'; {Do not Localize}
  52. MIMEEncRSAMD4 = MIMEXVal + 'rsa-md4'; {Do not Localize}
  53. MIMEEncRSAMD5 = MIMEXVal + 'rsa-md5'; {Do not Localize}
  54. MIMEEncNISTSHA = MIMEXVal + 'nist-sha'; {Do not Localize}
  55. MaxMIMEMessageDigestType = 3;
  56. // Compression Types
  57. MIMEEncRLECompress = MIMEXVal + 'rle-compress'; // Probably doesn't exist {Do not Localize}
  58. MaxMIMECompressType = 0;
  59. MaxMIMEEncType = MaxMIMEBinToASCIIType + MaxMIMEMessageDigestType + 1 + MaxMIMECompressType + 1;
  60. // Only put long, frequent full values in. Keep this list short, otherwise
  61. // it'll be a nightmare & produce HUGE .exe files with LARGE useless {Do not Localize}
  62. // sections (the above is bad enough on it's own!). {Do not Localize}
  63. MIMEFullApplicationOctetStream = MIMETypeApplication + MIMESubOctetStream;
  64. // Returns true if matched, false if not. If true, vars may be altered.
  65. function ReturnMIMEType(var MediaType, EncType : String) : Boolean;
  66. var
  67. MIMEMediaType : array [0..MaxMIMEType] of String;
  68. implementation
  69. uses
  70. IdGlobal,
  71. IdGlobalProtocols;
  72. function ReturnMIMEType(var MediaType, EncType : String) : Boolean;
  73. var
  74. MType, SType, EType : String;
  75. i : LongWord;
  76. begin
  77. i := IndyPos(MIMESplit, MediaType);
  78. MType := Copy(MediaType, 1, i);
  79. SType := Copy(MediaType, i + 1, MaxInt);
  80. EType := EncType;
  81. i := PosInStrArray(MType, MIMEMediaType, False);
  82. case i of
  83. 0 : begin end; // MIMETypeApplication - application/
  84. 1 : begin end; // MIMETypeAudio - audio/
  85. 2 : begin end; // MIMETypeImage - image/
  86. 3 : begin end; // MIMETypeMessage - message/
  87. 4 : begin end; // MIMETypeMultipart - multipart/
  88. 5 : begin end; // MIMETypeText - text/
  89. 6 : begin end; // MIMETypeVideo - video/
  90. else
  91. begin
  92. if TextStartsWith(MType, MIMEXVal) then begin
  93. i := PosInStrArray(Copy(MType, 3, MaxInt), MIMEMediaType, False);
  94. case i of
  95. 0 :
  96. begin
  97. // MIMETypeApplication - application/
  98. MType := MIMETypeApplication;
  99. end;
  100. 1 :
  101. begin
  102. // MIMETypeAudio - audio/
  103. MType := MIMETypeAudio;
  104. end;
  105. 2 :
  106. begin
  107. // MIMETypeImage - image/
  108. MType := MIMETypeImage;
  109. end;
  110. 3 :
  111. begin
  112. // MIMETypeMessage - message/
  113. MType := MIMETypeMessage;
  114. end;
  115. 4 :
  116. begin
  117. // MIMETypeMultipart - multipart/
  118. MType := MIMETypeMultipart;
  119. end;
  120. 5 :
  121. begin
  122. // MIMETypeText - text/
  123. MType := MIMETypeText;
  124. end;
  125. 6 :
  126. begin
  127. // MIMETypeVideo - video/
  128. MType := MIMETypeVideo;
  129. end;
  130. end;
  131. end;
  132. end;
  133. end;
  134. Result := False;
  135. end;
  136. initialization
  137. MIMEMediaType[0] := MIMETypeApplication;
  138. MIMEMediaType[1] := MIMETypeAudio;
  139. MIMEMediaType[2] := MIMETypeImage;
  140. MIMEMediaType[3] := MIMETypeMessage;
  141. MIMEMediaType[4] := MIMETypeMultipart;
  142. MIMEMediaType[5] := MIMETypeText;
  143. MIMEMediaType[6] := MIMETypeVideo;
  144. end.