Mercurial > pidgin
comparison src/util.c @ 8063:f1822a0c103a
[gaim-migrate @ 8756]
Potpourri for 500, Alex
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sat, 10 Jan 2004 18:13:52 +0000 |
parents | fa6395637e2c |
children | 9b6bc1010054 |
comparison
equal
deleted
inserted
replaced
8062:3c4313120c63 | 8063:f1822a0c103a |
---|---|
277 } | 277 } |
278 | 278 |
279 /************************************************************************** | 279 /************************************************************************** |
280 * MIME Functions | 280 * MIME Functions |
281 **************************************************************************/ | 281 **************************************************************************/ |
282 static char * | |
283 gaim_mime_decode_word(const char *charset, const char *encoding, const char *str) | |
284 { | |
285 char *decoded, *converted; | |
286 int len = 0; | |
287 | |
288 if ((charset == NULL) || (encoding == NULL) || (str == NULL)) | |
289 return NULL; | |
290 | |
291 if (g_ascii_strcasecmp(encoding, "Q") == 0) | |
292 gaim_quotedp_decode(str, &decoded, &len); | |
293 else if (g_ascii_strcasecmp(encoding, "B") == 0) | |
294 gaim_base64_decode(str, &decoded, &len); | |
295 else | |
296 return NULL; | |
297 | |
298 converted = g_convert(decoded, len, "utf-8", charset, NULL, NULL, NULL); | |
299 g_free(decoded); | |
300 | |
301 return converted; | |
302 } | |
303 | |
304 char * | 282 char * |
305 gaim_mime_decode_field(const char *str) | 283 gaim_mime_decode_field(const char *str) |
306 { | 284 { |
307 /* | 285 /* |
308 * This is revo/shx's version. It has had some problems with | 286 * This is revo/shx's version. It has had some problems with |
397 /* There is unencoded text at the end. */ | 375 /* There is unencoded text at the end. */ |
398 if (*unencoded) | 376 if (*unencoded) |
399 n = strcpy(n, unencoded); | 377 n = strcpy(n, unencoded); |
400 | 378 |
401 return new; | 379 return new; |
402 #if 0 | 380 } |
403 /* | |
404 * This is KingAnt's function. It should work, but I don't know if it | |
405 * follows the RFC fully. | |
406 */ | |
407 GString *donedeal; | |
408 char *orig, *start, *end, *end_of_last, *tmp; | |
409 char **encoded_word; | |
410 char *charset, *encoding, *word; | |
411 | |
412 g_return_val_if_fail(str != NULL, NULL); | |
413 | |
414 orig = g_strdup(str); | |
415 donedeal = g_string_sized_new(strlen(orig)); | |
416 | |
417 /* One iteration per encoded-word */ | |
418 end_of_last = orig; | |
419 while ((start = strstr(end_of_last, "=?"))) { | |
420 /* | |
421 * Get to the end of the encoded word by finding the first ?, | |
422 * the second ?, then finally the ?= If we can't find any of | |
423 * these, then break out of here because this isn't actually an | |
424 * encoded word. | |
425 */ | |
426 if (((end = strstr(start + 2, "?")) == NULL) || | |
427 ((end = strstr(end + 1, "?")) == NULL) || | |
428 ((end = strstr(end + 2, "?=")) == NULL)) { | |
429 break; | |
430 } | |
431 | |
432 /* Append everything from the end of the last encoded-word to the beginning of the next */ | |
433 tmp = g_strndup(end_of_last, (start - end_of_last)); | |
434 donedeal = g_string_append(donedeal, tmp); | |
435 g_free(tmp); | |
436 | |
437 /* Split the encoded word */ | |
438 tmp = g_strndup(start + 2, end - start - 2); | |
439 encoded_word = g_strsplit(tmp, "?", 3); | |
440 g_free(tmp); | |
441 charset = encoded_word[0]; | |
442 encoding = charset != NULL ? encoded_word[1] : NULL; | |
443 word = encoding != NULL ? encoded_word[2] : NULL; | |
444 | |
445 /* Convert the decoded word to utf8 and append it */ | |
446 tmp = gaim_mime_decode_word(charset, encoding, word); | |
447 if (tmp != NULL) { | |
448 donedeal = g_string_append(donedeal, tmp); | |
449 g_free(tmp); | |
450 } | |
451 | |
452 g_strfreev(encoded_word); | |
453 | |
454 end_of_last = end + 2; | |
455 } | |
456 | |
457 /* Append everything from the end of the last encoded-word to the end of the string */ | |
458 tmp = g_strndup(end_of_last, ((orig + strlen(orig)) - end_of_last)); | |
459 donedeal = g_string_append(donedeal, tmp); | |
460 g_free(tmp); | |
461 | |
462 /* Free at last, free at last... */ | |
463 tmp = donedeal->str; | |
464 g_string_free(donedeal, FALSE); | |
465 g_free(orig); | |
466 | |
467 return tmp; | |
468 #endif | |
469 } | |
470 | |
471 | 381 |
472 | 382 |
473 /************************************************************************** | 383 /************************************************************************** |
474 * Date/Time Functions | 384 * Date/Time Functions |
475 **************************************************************************/ | 385 **************************************************************************/ |