comparison src/libpst.c @ 116:ed2a260bbb98 stable-0-6-25

improve handling of content-type charset values in mime parts
author Carl Byington <carl@five-ten-sg.com>
date Fri, 16 Jan 2009 15:23:52 -0800
parents e213bfcf9aa7
children 0f1492b7fe8b
comparison
equal deleted inserted replaced
115:7689c006b166 116:ed2a260bbb98
1604 na_ptr->items[x]->data = NULL; 1604 na_ptr->items[x]->data = NULL;
1605 } 1605 }
1606 } 1606 }
1607 if (table_rec.ref_type == (uint16_t)0x1f) { 1607 if (table_rec.ref_type == (uint16_t)0x1f) {
1608 // there is more to do for the type 0x1f unicode strings 1608 // there is more to do for the type 0x1f unicode strings
1609 size_t rc;
1609 static vbuf *strbuf = NULL; 1610 static vbuf *strbuf = NULL;
1610 static vbuf *unibuf = NULL; 1611 static vbuf *unibuf = NULL;
1611 if (!strbuf) strbuf=vballoc((size_t)1024); 1612 if (!strbuf) strbuf=vballoc((size_t)1024);
1612 if (!unibuf) unibuf=vballoc((size_t)1024); 1613 if (!unibuf) unibuf=vballoc((size_t)1024);
1613 1614
1618 //need UTF-16 zero-termination 1619 //need UTF-16 zero-termination
1619 vbset(strbuf, na_ptr->items[x]->data, na_ptr->items[x]->size); 1620 vbset(strbuf, na_ptr->items[x]->data, na_ptr->items[x]->size);
1620 vbappend(strbuf, "\0\0", (size_t)2); 1621 vbappend(strbuf, "\0\0", (size_t)2);
1621 DEBUG_INDEX(("Iconv in:\n")); 1622 DEBUG_INDEX(("Iconv in:\n"));
1622 DEBUG_HEXDUMPC(strbuf->b, strbuf->dlen, 0x10); 1623 DEBUG_HEXDUMPC(strbuf->b, strbuf->dlen, 0x10);
1623 (void)vb_utf16to8(unibuf, strbuf->b, strbuf->dlen); 1624 rc = vb_utf16to8(unibuf, strbuf->b, strbuf->dlen);
1624 free(na_ptr->items[x]->data); 1625 if (rc == (size_t)-1) {
1625 na_ptr->items[x]->size = unibuf->dlen; 1626 free(unibuf->b);
1626 na_ptr->items[x]->data = xmalloc(unibuf->dlen); 1627 DEBUG_EMAIL(("Failed to convert utf-16 to utf-8\n"));
1627 memcpy(na_ptr->items[x]->data, unibuf->b, unibuf->dlen); 1628 }
1629 else {
1630 free(na_ptr->items[x]->data);
1631 na_ptr->items[x]->size = unibuf->dlen;
1632 na_ptr->items[x]->data = xmalloc(unibuf->dlen);
1633 memcpy(na_ptr->items[x]->data, unibuf->b, unibuf->dlen);
1634 }
1628 DEBUG_INDEX(("Iconv out:\n")); 1635 DEBUG_INDEX(("Iconv out:\n"));
1629 DEBUG_HEXDUMPC(na_ptr->items[x]->data, na_ptr->items[x]->size, 0x10); 1636 DEBUG_HEXDUMPC(na_ptr->items[x]->data, na_ptr->items[x]->size, 0x10);
1630 } 1637 }
1631 if (na_ptr->items[x]->type == 0) na_ptr->items[x]->type = table_rec.ref_type; 1638 if (na_ptr->items[x]->type == 0) na_ptr->items[x]->type = table_rec.ref_type;
1632 } else { 1639 } else {
1730 strcpy(ef->field_name, list->items[x]->extra); 1737 strcpy(ef->field_name, list->items[x]->extra);
1731 LIST_COPY(ef->value, (char*)); 1738 LIST_COPY(ef->value, (char*));
1732 ef->next = item->extra_fields; 1739 ef->next = item->extra_fields;
1733 item->extra_fields = ef; 1740 item->extra_fields = ef;
1734 DEBUG_EMAIL(("\"%s\" = \"%s\"\n", ef->field_name, ef->value)); 1741 DEBUG_EMAIL(("\"%s\" = \"%s\"\n", ef->field_name, ef->value));
1742 if (strcmp(ef->field_name, "content-type") == 0) {
1743 char *p = strstr(ef->value, "charset=\"");
1744 if (p) {
1745 p += 9; // skip over charset="
1746 char *pp = strchr(p, '"');
1747 if (pp) {
1748 *pp = '\0';
1749 char *set = strdup(p);
1750 *pp = '"';
1751 MALLOC_EMAIL(item);
1752 if (item->email->body_charset) free(item->email->body_charset);
1753 item->email->body_charset = set;
1754 DEBUG_EMAIL(("body charset %s from content-type extra field\n", set));
1755 }
1756 }
1757 }
1735 } 1758 }
1736 else { 1759 else {
1737 DEBUG_EMAIL(("NULL extra field\n")); 1760 DEBUG_EMAIL(("NULL extra field\n"));
1738 } 1761 }
1739 break; 1762 break;
2207 break; 2230 break;
2208 case 0x1000: // PR_BODY Plain Text body 2231 case 0x1000: // PR_BODY Plain Text body
2209 DEBUG_EMAIL(("Plain Text body - ")); 2232 DEBUG_EMAIL(("Plain Text body - "));
2210 MALLOC_EMAIL(item); 2233 MALLOC_EMAIL(item);
2211 LIST_COPY(item->email->body, (char*)); 2234 LIST_COPY(item->email->body, (char*));
2212 //DEBUG_EMAIL("%s\n", item->email->body); 2235 DEBUG_EMAIL(("%s\n", item->email->body));
2213 DEBUG_EMAIL(("NOT PRINTED\n"));
2214 break; 2236 break;
2215 case 0x1006: // PR_RTF_SYNC_BODY_CRC 2237 case 0x1006: // PR_RTF_SYNC_BODY_CRC
2216 DEBUG_EMAIL(("RTF Sync Body CRC - ")); 2238 DEBUG_EMAIL(("RTF Sync Body CRC - "));
2217 MALLOC_EMAIL(item); 2239 MALLOC_EMAIL(item);
2218 memcpy(&(item->email->rtf_body_crc), list->items[x]->data, sizeof(item->email->rtf_body_crc)); 2240 memcpy(&(item->email->rtf_body_crc), list->items[x]->data, sizeof(item->email->rtf_body_crc));
2259 break; 2281 break;
2260 case 0x1013: // HTML body 2282 case 0x1013: // HTML body
2261 DEBUG_EMAIL(("HTML body - ")); 2283 DEBUG_EMAIL(("HTML body - "));
2262 MALLOC_EMAIL(item); 2284 MALLOC_EMAIL(item);
2263 LIST_COPY(item->email->htmlbody, (char*)); 2285 LIST_COPY(item->email->htmlbody, (char*));
2264 // DEBUG_EMAIL(("%s\n", item->email->htmlbody)); 2286 DEBUG_EMAIL(("%s\n", item->email->htmlbody));
2265 DEBUG_EMAIL(("NOT PRINTED\n"));
2266 break; 2287 break;
2267 case 0x1035: // Message ID 2288 case 0x1035: // Message ID
2268 DEBUG_EMAIL(("Message ID - ")); 2289 DEBUG_EMAIL(("Message ID - "));
2269 MALLOC_EMAIL(item); 2290 MALLOC_EMAIL(item);
2270 LIST_COPY(item->email->messageid, (char*)); 2291 LIST_COPY(item->email->messageid, (char*));
3697 DEBUG_ENT("pst_freeItem"); 3718 DEBUG_ENT("pst_freeItem");
3698 if (item) { 3719 if (item) {
3699 if (item->email) { 3720 if (item->email) {
3700 SAFE_FREE(item->email->arrival_date); 3721 SAFE_FREE(item->email->arrival_date);
3701 SAFE_FREE(item->email->body); 3722 SAFE_FREE(item->email->body);
3723 SAFE_FREE(item->email->body_charset);
3702 SAFE_FREE(item->email->cc_address); 3724 SAFE_FREE(item->email->cc_address);
3703 SAFE_FREE(item->email->bcc_address); 3725 SAFE_FREE(item->email->bcc_address);
3704 SAFE_FREE(item->email->common_name); 3726 SAFE_FREE(item->email->common_name);
3705 SAFE_FREE(item->email->encrypted_body); 3727 SAFE_FREE(item->email->encrypted_body);
3706 SAFE_FREE(item->email->encrypted_htmlbody); 3728 SAFE_FREE(item->email->encrypted_htmlbody);