2 * This is the MIME parser for Citadel.
4 * Copyright (c) 1998-2010 by the citadel.org development team.
5 * This code is distributed under the GNU General Public License v3.
13 #include <sys/types.h>
17 #include <sys/types.h>
21 #include "xdgmime/xdgmime.h"
22 #include "libcitadel.h"
23 #include "libcitadellocal.h"
25 const unsigned char FromHexTable [256] = {
26 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 0
27 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 10
28 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 20
29 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 30
30 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x00, 0x01, // 40
31 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0xFF, 0xFF, // 50
32 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, // 60
33 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 70
34 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // 80
35 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0x0A, 0x0B, 0x0C, // 90
36 0x0D, 0x0E, 0x0F, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //100
37 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //110
38 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //120
39 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //130
40 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //140
41 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //150
42 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //160
43 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //170
44 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //180
45 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //190
46 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //200
47 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //210
48 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //220
49 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //230
50 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, //240
51 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF //250
55 long extract_key(char *target, char *source, long sourcelen, char *key, long keylen, char KeyEnd)
57 char *sptr, *ptr = NULL;
58 int double_quotes = 0;
59 long RealKeyLen = keylen;
65 ptr = bmstrcasestr_len(sptr, sourcelen - (sptr - source),
69 while (isspace(*(ptr + RealKeyLen)))
71 if (*(ptr + RealKeyLen) == KeyEnd)
78 sptr = ptr + RealKeyLen + 1;
88 strcpy(target, (ptr + RealKeyLen));
90 for (ptr=target; (*ptr != 0); ptr++) {
92 /* A semicolon means we've hit the end of the key, unless we're inside double quotes */
93 if ( (double_quotes != 1) && (*ptr == ';')) {
97 /* if we find double quotes, we've got a great set of string boundaries */
100 if (double_quotes == 1) {
114 * For non-multipart messages, we need to generate a quickie partnum of "1"
115 * to return to callback functions. Some callbacks demand it.
117 char *fixed_partnum(char *supplied_partnum) {
118 if (supplied_partnum == NULL) return "1";
119 if (strlen(supplied_partnum)==0) return "1";
120 return supplied_partnum;
124 static inline unsigned int _decode_hex(const char *Source)
127 unsigned char LO_NIBBLE;
128 unsigned char HI_NIBBLE;
130 HI_NIBBLE = FromHexTable[(unsigned char) *Source];
131 LO_NIBBLE = FromHexTable[(unsigned char) *(Source+1)];
133 if ((LO_NIBBLE == 0xFF) || (LO_NIBBLE == 0xFF))
137 ret = ret | LO_NIBBLE;
141 unsigned int decode_hex(char *Source) {return _decode_hex(Source);}
144 * Convert "quoted-printable" to binary. Returns number of bytes decoded.
145 * according to RFC2045 section 6.7
147 int CtdlDecodeQuotedPrintable(char *decoded, char *encoded, int sourcelen) {
149 int decoded_length = 0;
152 while (pos < sourcelen)
154 if (*(encoded + pos) == '=')
157 if (*(encoded + pos) == '\n')
161 else if (*(encoded + pos) == '\r')
164 if (*(encoded + pos) == '\n')
170 ch = _decode_hex(&encoded[pos]);
172 decoded[decoded_length++] = ch;
177 decoded[decoded_length++] = encoded[pos];
181 decoded[decoded_length] = 0;
182 return(decoded_length);
187 * Given a message or message-part body and a length, handle any necessary
188 * decoding and pass the request up the stack.
190 void mime_decode(char *partnum,
191 char *part_start, size_t length,
192 char *content_type, char *charset, char *encoding,
195 char *name, char *filename,
196 MimeParserCallBackType CallBack,
197 MimeParserCallBackType PreMultiPartCallBack,
198 MimeParserCallBackType PostMultiPartCallBack,
204 size_t bytes_decoded = 0;
206 /* Some encodings aren't really encodings */
207 if (!strcasecmp(encoding, "7bit"))
208 strcpy(encoding, "");
209 if (!strcasecmp(encoding, "8bit"))
210 strcpy(encoding, "");
211 if (!strcasecmp(encoding, "binary"))
212 strcpy(encoding, "");
214 /* If this part is not encoded, send as-is */
215 if ( (strlen(encoding) == 0) || (dont_decode)) {
216 if (CallBack != NULL) {
219 fixed_partnum(partnum),
232 /* Fail silently if we hit an unknown encoding. */
233 if ((strcasecmp(encoding, "base64"))
234 && (strcasecmp(encoding, "quoted-printable"))) {
239 * Allocate a buffer for the decoded data. The output buffer is slightly
240 * larger than the input buffer; this assumes that the decoded data
241 * will never be significantly larger than the encoded data. This is a
242 * safe assumption with base64, uuencode, and quoted-printable.
244 decoded = malloc(length + 32768);
245 if (decoded == NULL) {
249 if (!strcasecmp(encoding, "base64")) {
250 bytes_decoded = CtdlDecodeBase64(decoded, part_start, length);
252 else if (!strcasecmp(encoding, "quoted-printable")) {
253 bytes_decoded = CtdlDecodeQuotedPrintable(decoded, part_start, length);
256 if (bytes_decoded > 0) if (CallBack != NULL) {
257 CallBack(name, filename, fixed_partnum(partnum),
258 disposition, decoded,
259 content_type, charset, bytes_decoded, "binary", id, userdata);
266 * this is the extract of mime_decode which can be called if 'dont_decode' was set;
267 * to save the cpu intense process of decoding to the time when it realy wants the content.
269 * - > 0 we decoded something, its on *decoded, you need to free it.
270 * - = 0 no need to decode stuff. *decoded will be NULL.
271 * - < 0 an error occured, either an unknown encoding, or alloc failed. no need to free.
273 int mime_decode_now (char *part_start,
277 size_t *bytes_decoded)
281 /* Some encodings aren't really encodings */
282 if (!strcasecmp(encoding, "7bit"))
283 strcpy(encoding, "");
284 if (!strcasecmp(encoding, "8bit"))
285 strcpy(encoding, "");
286 if (!strcasecmp(encoding, "binary"))
287 strcpy(encoding, "");
289 /* If this part is not encoded, send as-is */
290 if (strlen(encoding) == 0) {
295 /* Fail if we hit an unknown encoding. */
296 if ((strcasecmp(encoding, "base64"))
297 && (strcasecmp(encoding, "quoted-printable"))) {
302 * Allocate a buffer for the decoded data. The output buffer is slightly
303 * larger than the input buffer; this assumes that the decoded data
304 * will never be significantly larger than the encoded data. This is a
305 * safe assumption with base64, uuencode, and quoted-printable.
307 *decoded = malloc(length + 32768);
308 if (decoded == NULL) {
312 if (!strcasecmp(encoding, "base64")) {
313 *bytes_decoded = CtdlDecodeBase64(*decoded, part_start, length);
316 else if (!strcasecmp(encoding, "quoted-printable")) {
317 *bytes_decoded = CtdlDecodeQuotedPrintable(*decoded, part_start, length);
323 typedef enum _eIntMimeHdrs {
331 content_disposition_name,
335 eMax /* don't move ! */
338 typedef struct _CBufStr {
343 typedef struct _interesting_mime_headers {
347 } interesting_mime_headers;
349 interesting_mime_headers *InitInterestingMimes(void)
352 interesting_mime_headers *m;
353 m = (interesting_mime_headers*) malloc( sizeof(interesting_mime_headers));
355 for (i = 0; i < eMax; i++) {
356 m->b[i].Key[0] = '\0';
359 m->content_length = -1;
365 long parse_MimeHeaders(interesting_mime_headers *m, char* content_start, char *content_end)
374 /* Learn interesting things from the headers */
379 ptr = memreadlinelen(ptr, buf, SIZ, &buflen);
380 if (ptr >= content_end) {
384 for (i = 0; i < buflen; ++i) {
385 if (isspace(buf[i])) {
390 if (!isspace(buf[0])) {
391 if (!strncasecmp(header, "Content-type:", 13)) {
392 memcpy (m->b[content_type].Key, &header[13], headerlen - 12);
393 m->b[content_type].len = striplt (m->b[content_type].Key);
395 m->b[content_type_name].len = extract_key(m->b[content_type_name].Key, CKEY(m->b[content_type]), HKEY("name"), '=');
396 m->b[charset].len = extract_key(m->b[charset].Key, CKEY(m->b[content_type]), HKEY("charset"), '=');
397 m->b[boundary].len = extract_key(m->b[boundary].Key, header, headerlen, HKEY("boundary"), '=');
399 /* Deal with weird headers */
400 if (strchr(m->b[content_type].Key, ' '))
401 *(strchr(m->b[content_type].Key, ' ')) = '\0';
402 if (strchr(m->b[content_type].Key, ';'))
403 *(strchr(m->b[content_type].Key, ';')) = '\0';
405 else if (!strncasecmp(header, "Content-Disposition:", 20)) {
406 memcpy (m->b[disposition].Key, &header[20], headerlen - 19);
407 m->b[disposition].len = striplt(m->b[disposition].Key);
409 m->b[content_disposition_name].len = extract_key(m->b[content_disposition_name].Key, CKEY(m->b[disposition]), HKEY("name"), '=');
410 m->b[filename].len = extract_key(m->b[filename].Key, CKEY(m->b[disposition]), HKEY("filename"), '=');
412 else if (!strncasecmp(header, "Content-ID:", 11)) {
413 memcpy(m->b[id].Key, &header[11], headerlen);
414 striplt(m->b[id].Key);
415 m->b[id].len = stripallbut(m->b[id].Key, '<', '>');
417 else if (!strncasecmp(header, "Content-length: ", 15)) {
420 while (isspace(clbuf))
422 m->content_length = (size_t) atol(clbuf);
424 else if (!strncasecmp(header, "Content-transfer-encoding: ", 26)) {
425 memcpy(m->b[encoding].Key, &header[26], headerlen - 26);
426 m->b[encoding].len = striplt(m->b[encoding].Key);
431 if ((headerlen + buflen + 2) < SIZ) {
432 memcpy(&header[headerlen], buf, buflen);
434 header[headerlen] = '\0';
436 } while ((!IsEmptyStr(buf)) && (*ptr != 0));
438 ptr = strchr(m->b[disposition].Key, ';');
439 if (ptr != NULL) *ptr = '\0';
440 m->b[disposition].len = striplt(m->b[disposition].Key);
442 ptr = strchr(m->b[content_type].Key, ';');
443 if (ptr != NULL) *ptr = '\0';
444 m->b[content_type].len = striplt(m->b[content_type].Key);
446 m->is_multipart = m->b[boundary].len != 0;
452 * Break out the components of a multipart message
453 * (This function expects to be fed HEADERS + CONTENT)
454 * Note: NULL can be supplied as content_end; in this case, the message is
455 * considered to have ended when the parser encounters a 0x00 byte.
457 void the_mime_parser(char *partnum,
458 char *content_start, char *content_end,
459 MimeParserCallBackType CallBack,
460 MimeParserCallBackType PreMultiPartCallBack,
461 MimeParserCallBackType PostMultiPartCallBack,
467 char *part_start, *part_end = NULL;
470 size_t content_length;
473 char nested_partnum[256];
475 char *evaluate_crlf_ptr = NULL;
477 interesting_mime_headers *m;
478 CBufStr *chosen_name;
483 m = InitInterestingMimes();
486 /* If the caller didn't supply an endpointer, generate one by measure */
487 if (content_end == NULL) {
488 content_end = &content_start[strlen(content_start)];
492 if (parse_MimeHeaders(m, content_start, content_end) != 0)
495 /* If this is a multipart message, then recursively process it */
497 if (m->is_multipart) {
499 /* Tell the client about this message's multipartedness */
500 if (PreMultiPartCallBack != NULL) {
501 PreMultiPartCallBack("",
506 m->b[content_type].Key,
514 /* Figure out where the boundaries are */
515 m->b[startary].len = snprintf(m->b[startary].Key, SIZ, "--%s", m->b[boundary].Key);
524 next_boundary = strstr(ptr, m->b[startary].Key);
527 if ( (part_start != NULL) && (next_boundary != NULL) ) {
528 part_end = next_boundary;
529 --part_end; /* omit the trailing LF */
531 --part_end; /* omit the trailing CR */
534 if (!IsEmptyStr(partnum)) {
535 snprintf(nested_partnum,
536 sizeof nested_partnum,
541 snprintf(nested_partnum,
542 sizeof nested_partnum,
545 the_mime_parser(nested_partnum,
549 PreMultiPartCallBack,
550 PostMultiPartCallBack,
555 if (next_boundary != NULL) {
556 /* If we pass out of scope, don't attempt to
557 * read past the end boundary. */
558 if ((*(next_boundary + m->b[startary].len + 1) == '-') &&
559 (*(next_boundary + m->b[startary].len + 2) == '-') ){
563 /* Set up for the next part. */
564 part_start = strstr(next_boundary, "\n");
566 /* Determine whether newlines are LF or CRLF */
567 evaluate_crlf_ptr = part_start;
569 if ((*evaluate_crlf_ptr == '\r') &&
570 (*(evaluate_crlf_ptr + 1) == '\n'))
578 /* Advance past the LF ... now we're in the next part */
584 /* Invalid end of multipart. Bail out! */
587 } while ( (ptr < content_end) && (next_boundary != NULL) );
589 if (PostMultiPartCallBack != NULL) {
590 PostMultiPartCallBack("",
595 m->b[content_type].Key,
605 /* If it's not a multipart message, then do something with it */
606 if (!m->is_multipart) {
609 while (ptr < content_end) {
613 part_end = content_end;
616 /* The following code will truncate the MIME part to the size
617 * specified by the Content-length: header. We have commented it
618 * out because these headers have a tendency to be wrong.
620 * if ( (content_length > 0) && (length > content_length) ) {
621 * length = content_length;
625 /* Sometimes the "name" field is tacked on to Content-type,
626 * and sometimes it's tacked on to Content-disposition. Use
627 * whichever one we have.
629 if (m->b[content_disposition_name].len > m->b[content_type_name].len) {
630 chosen_name = &m->b[content_disposition_name];
633 chosen_name = &m->b[content_type_name];
636 /* Ok, we've got a non-multipart part here, so do something with it.
641 m->b[content_type].Key,
644 m->b[disposition].Key,
655 * Now if it's an encapsulated message/rfc822 then we have to recurse into it
657 if (!strcasecmp(&m->b[content_type].Key[0], "message/rfc822")) {
659 if (PreMultiPartCallBack != NULL) {
660 PreMultiPartCallBack("",
665 m->b[content_type].Key,
672 if (CallBack != NULL) {
673 if (strlen(partnum) > 0) {
674 snprintf(nested_partnum,
675 sizeof nested_partnum,
680 snprintf(nested_partnum,
681 sizeof nested_partnum,
684 the_mime_parser(nested_partnum,
688 PreMultiPartCallBack,
689 PostMultiPartCallBack,
694 if (PostMultiPartCallBack != NULL) {
695 PostMultiPartCallBack("",
700 m->b[content_type].Key,
713 end_parser: /* free the buffers! end the oppression!! */
720 * Entry point for the MIME parser.
721 * (This function expects to be fed HEADERS + CONTENT)
722 * Note: NULL can be supplied as content_end; in this case, the message is
723 * considered to have ended when the parser encounters a 0x00 byte.
725 void mime_parser(char *content_start,
727 MimeParserCallBackType CallBack,
728 MimeParserCallBackType PreMultiPartCallBack,
729 MimeParserCallBackType PostMultiPartCallBack,
734 the_mime_parser("", content_start, content_end,
736 PreMultiPartCallBack,
737 PostMultiPartCallBack,
738 userdata, dont_decode);
746 typedef struct _MimeGuess {
750 const char *MimeString;
753 MimeGuess MyMimes [] = {
781 const char *GuessMimeType(const char *data, size_t dlen)
785 while (MyMimes[MimeIndex].PatternLen != 0)
787 if ((MyMimes[MimeIndex].PatternLen +
788 MyMimes[MimeIndex].PatternOffset < dlen) &&
789 strncmp(MyMimes[MimeIndex].Pattern,
790 &data[MyMimes[MimeIndex].PatternOffset],
791 MyMimes[MimeIndex].PatternLen) == 0)
793 return MyMimes[MimeIndex].MimeString;
798 * ok, our simple minded algorythm didn't find anything,
799 * let the big chegger try it, he wil default to application/octet-stream
801 return (xdg_mime_get_mime_type_for_data(data, dlen));
805 const char* GuessMimeByFilename(const char *what, size_t len)
807 /* we know some hardcoded on our own, try them... */
808 if ((len > 3) && !strncasecmp(&what[len - 4], ".gif", 4))
810 else if ((len > 2) && !strncasecmp(&what[len - 3], ".js", 3))
811 return "text/javascript";
812 else if ((len > 3) && !strncasecmp(&what[len - 4], ".txt", 4))
814 else if ((len > 3) && !strncasecmp(&what[len - 4], ".css", 4))
816 else if ((len > 3) && !strncasecmp(&what[len - 4], ".htc", 4))
817 return "text/x-component";
818 else if ((len > 3) && !strncasecmp(&what[len - 4], ".jpg", 4))
820 else if ((len > 3) && !strncasecmp(&what[len - 4], ".png", 4))
822 else if ((len > 3) && !strncasecmp(&what[len - 4], ".ico", 4))
823 return "image/x-icon";
824 else if ((len > 3) && !strncasecmp(&what[len - 4], ".vcf", 4))
825 return "text/x-vcard";
826 else if ((len > 4) && !strncasecmp(&what[len - 5], ".html", 5))
828 else if ((len > 3) && !strncasecmp(&what[len - 4], ".htm", 4))
830 else if ((len > 3) && !strncasecmp(&what[len - 4], ".wml", 4))
831 return "text/vnd.wap.wml";
832 else if ((len > 4) && !strncasecmp(&what[len - 5], ".wmls", 5))
833 return "text/vnd.wap.wmlscript";
834 else if ((len > 4) && !strncasecmp(&what[len - 5], ".wmlc", 5))
835 return "application/vnd.wap.wmlc";
836 else if ((len > 5) && !strncasecmp(&what[len - 6], ".wmlsc", 6))
837 return "application/vnd.wap.wmlscriptc";
838 else if ((len > 4) && !strncasecmp(&what[len - 5], ".wbmp", 5))
839 return "image/vnd.wap.wbmp";
841 /* and let xdgmime do the fallback. */
842 return xdg_mime_get_mime_type_from_file_name(what);
845 static HashList *IconHash = NULL;
847 typedef struct IconName IconName;
854 static void DeleteIcon(void *IconNamePtr)
856 IconName *Icon = (IconName*) IconNamePtr;
857 free(Icon->FlatName);
858 free(Icon->FileName);
863 static const char *PrintFlat(void *IconNamePtr)
865 IconName *Icon = (IconName*) IconNamePtr;
866 return Icon->FlatName;
868 static const char *PrintFile(void *IconNamePtr)
870 IconName *Icon = (IconName*) IconNamePtr;
871 return Icon->FileName;
875 #define GENSTR "x-generic"
876 #define IGNORE_PREFIX_1 "gnome-mime"
877 int LoadIconDir(const char *DirName)
880 struct dirent *filedir_entry;
885 filedir = opendir (DirName);
886 IconHash = NewHash(1, NULL);
887 if (filedir == NULL) {
891 while ((filedir_entry = readdir(filedir)))
895 #ifdef _DIRENT_HAVE_D_NAMELEN
896 d_namelen = filedir_entry->d_namelen;
898 d_namelen = strlen(filedir_entry->d_name);
900 d_without_ext = d_namelen;
901 while ((d_without_ext > 0) && (filedir_entry->d_name[d_without_ext] != '.'))
903 if ((d_without_ext == 0) || (d_namelen < 3))
906 if ((sizeof(IGNORE_PREFIX_1) < d_namelen) &&
907 (strncmp(IGNORE_PREFIX_1,
908 filedir_entry->d_name,
909 sizeof(IGNORE_PREFIX_1) - 1) == 0)) {
910 PStart = filedir_entry->d_name + sizeof(IGNORE_PREFIX_1);
911 d_without_ext -= sizeof(IGNORE_PREFIX_1);
914 PStart = filedir_entry->d_name;
916 Icon = malloc(sizeof(IconName));
918 Icon->FileName = malloc(d_namelen + 1);
919 memcpy(Icon->FileName, filedir_entry->d_name, d_namelen + 1);
921 Icon->FlatName = malloc(d_without_ext + 1);
922 memcpy(Icon->FlatName, PStart, d_without_ext);
923 Icon->FlatName[d_without_ext] = '\0';
924 /* Try to find Minor type in image-jpeg */
925 MinorPtr = strchr(Icon->FlatName, '-');
926 if (MinorPtr != NULL) {
928 MinorLen = 1 + d_without_ext - (MinorPtr - Icon->FlatName + 1);
929 if ((MinorLen == sizeof(GENSTR)) &&
930 (strncmp(MinorPtr + 1, GENSTR, sizeof(GENSTR)) == 0)) {
931 /* ok, we found a generic filename. cut the generic. */
933 d_without_ext = d_without_ext - (MinorPtr - Icon->FlatName);
935 else { /* Map the major / minor separator to / */
940 // PrintHash(IconHash, PrintFlat, PrintFile);
941 // printf("%s - %s\n", Icon->FlatName, Icon->FileName);
942 Put(IconHash, Icon->FlatName, d_without_ext, Icon, DeleteIcon);
943 // PrintHash(IconHash, PrintFlat, PrintFile);
949 const char *GetIconFilename(char *MimeType, size_t len)
957 GetHash(IconHash, MimeType, len, &vIcon), Icon = (IconName*) vIcon;
958 /* didn't find the exact mimetype? try major only. */
961 pMinor = strchr(MimeType, '/');
962 if (pMinor != NULL) {
964 GetHash(IconHash, MimeType, pMinor - MimeType, &vIcon),
965 Icon = (IconName*) vIcon;
972 /*printf("Getting: [%s] == [%s] -> [%s]\n", MimeType, Icon->FlatName, Icon->FileName);*/
973 return Icon->FileName;
976 void ShutDownLibCitadelMime(void)
978 DeleteHash(&IconHash);