Mercurial > libpst
comparison src/libpst.c @ 242:67b24d6a45d6 stable-0-6-45
patch from Hugo DesRosiers to export categories and notes into vcards.
extend that patch to export categories into vcalendar appointments also.
author | Carl Byington <carl@five-ten-sg.com> |
---|---|
date | Fri, 11 Dec 2009 08:45:30 -0800 |
parents | 1d50ff3c5091 |
children | 4573b536177f 97c53c6868ab |
comparison
equal
deleted
inserted
replaced
241:fa4042b0a566 | 242:67b24d6a45d6 |
---|---|
1878 (list->elements[x]->type == 0x1e) || \ | 1878 (list->elements[x]->type == 0x1e) || \ |
1879 (list->elements[x]->type == 0x102)) { \ | 1879 (list->elements[x]->type == 0x102)) { \ |
1880 LIST_COPY(targ, (char*)) \ | 1880 LIST_COPY(targ, (char*)) \ |
1881 } \ | 1881 } \ |
1882 else { \ | 1882 else { \ |
1883 DEBUG_WARN(("src not 0x1e or 0x1f or 0x102 for string dst\n")); \ | 1883 DEBUG_WARN(("src not 0x1e or 0x1f or 0x102 for string dst\n")); \ |
1884 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); \ | 1884 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); \ |
1885 SAFE_FREE(targ); \ | 1885 SAFE_FREE(targ); \ |
1886 targ = NULL; \ | 1886 targ = NULL; \ |
1887 } \ | 1887 } \ |
1888 } | 1888 } |
1889 | 1889 |
1890 #define LIST_COPY_BOOL(label, targ) { \ | 1890 #define LIST_COPY_BOOL(label, targ) { \ |
1891 if (list->elements[x]->type != 0x0b) { \ | 1891 if (list->elements[x]->type != 0x0b) { \ |
1892 DEBUG_WARN(("src not 0x0b for boolean dst\n")); \ | 1892 DEBUG_WARN(("src not 0x0b for boolean dst\n")); \ |
1893 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); \ | 1893 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); \ |
1894 } \ | 1894 } \ |
1895 if (*(int16_t*)list->elements[x]->data) { \ | 1895 if (*(int16_t*)list->elements[x]->data) { \ |
1896 DEBUG_INFO((label" - True\n")); \ | 1896 DEBUG_INFO((label" - True\n")); \ |
1897 targ = 1; \ | 1897 targ = 1; \ |
1898 } else { \ | 1898 } else { \ |
1899 DEBUG_INFO((label" - False\n")); \ | 1899 DEBUG_INFO((label" - False\n")); \ |
1900 targ = 0; \ | 1900 targ = 0; \ |
1901 } \ | 1901 } \ |
1902 } | 1902 } |
1903 | 1903 |
1904 #define LIST_COPY_EMAIL_BOOL(label, targ) { \ | 1904 #define LIST_COPY_EMAIL_BOOL(label, targ) { \ |
1916 LIST_COPY_BOOL(label, targ) \ | 1916 LIST_COPY_BOOL(label, targ) \ |
1917 } | 1917 } |
1918 | 1918 |
1919 #define LIST_COPY_INT16_N(targ) { \ | 1919 #define LIST_COPY_INT16_N(targ) { \ |
1920 if (list->elements[x]->type != 0x02) { \ | 1920 if (list->elements[x]->type != 0x02) { \ |
1921 DEBUG_WARN(("src not 0x02 for int16 dst\n")); \ | 1921 DEBUG_WARN(("src not 0x02 for int16 dst\n")); \ |
1922 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); \ | 1922 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); \ |
1923 } \ | 1923 } \ |
1924 memcpy(&(targ), list->elements[x]->data, sizeof(targ)); \ | 1924 memcpy(&(targ), list->elements[x]->data, sizeof(targ)); \ |
1925 LE16_CPU(targ); \ | 1925 LE16_CPU(targ); \ |
1926 } | 1926 } |
1927 | 1927 |
1928 #define LIST_COPY_INT16(label, targ) { \ | 1928 #define LIST_COPY_INT16(label, targ) { \ |
1929 LIST_COPY_INT16_N(targ); \ | 1929 LIST_COPY_INT16_N(targ); \ |
1930 DEBUG_INFO((label" - %i %#x\n", (int)targ, (int)targ)); \ | 1930 DEBUG_INFO((label" - %i %#x\n", (int)targ, (int)targ)); \ |
1931 } | 1931 } |
1932 | 1932 |
1933 #define LIST_COPY_INT32_N(targ) { \ | 1933 #define LIST_COPY_INT32_N(targ) { \ |
1934 if (list->elements[x]->type != 0x03) { \ | 1934 if (list->elements[x]->type != 0x03) { \ |
1935 DEBUG_WARN(("src not 0x03 for int32 dst\n")); \ | 1935 DEBUG_WARN(("src not 0x03 for int32 dst\n")); \ |
1936 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); \ | 1936 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); \ |
1937 } \ | 1937 } \ |
1938 memcpy(&(targ), list->elements[x]->data, sizeof(targ)); \ | 1938 memcpy(&(targ), list->elements[x]->data, sizeof(targ)); \ |
1939 LE32_CPU(targ); \ | 1939 LE32_CPU(targ); \ |
1940 } | 1940 } |
1941 | 1941 |
1942 #define LIST_COPY_INT32(label, targ) { \ | 1942 #define LIST_COPY_INT32(label, targ) { \ |
1943 LIST_COPY_INT32_N(targ); \ | 1943 LIST_COPY_INT32_N(targ); \ |
1944 DEBUG_INFO((label" - %i %#x\n", (int)targ, (int)targ)); \ | 1944 DEBUG_INFO((label" - %i %#x\n", (int)targ, (int)targ)); \ |
1945 } | 1945 } |
1946 | 1946 |
1947 #define LIST_COPY_EMAIL_INT32(label, targ) { \ | 1947 #define LIST_COPY_EMAIL_INT32(label, targ) { \ |
1948 MALLOC_EMAIL(item); \ | 1948 MALLOC_EMAIL(item); \ |
1949 LIST_COPY_INT32(label, targ); \ | 1949 LIST_COPY_INT32(label, targ); \ |
1966 | 1966 |
1967 #define LIST_COPY_ENUM(label, targ, delta, count, ...) { \ | 1967 #define LIST_COPY_ENUM(label, targ, delta, count, ...) { \ |
1968 char *tlabels[] = {__VA_ARGS__}; \ | 1968 char *tlabels[] = {__VA_ARGS__}; \ |
1969 LIST_COPY_INT32_N(targ); \ | 1969 LIST_COPY_INT32_N(targ); \ |
1970 targ += delta; \ | 1970 targ += delta; \ |
1971 DEBUG_INFO((label" - %s [%i]\n", \ | 1971 DEBUG_INFO((label" - %s [%i]\n", \ |
1972 (((int)targ < 0) || ((int)targ >= count)) \ | 1972 (((int)targ < 0) || ((int)targ >= count)) \ |
1973 ? "**invalid" \ | 1973 ? "**invalid" \ |
1974 : tlabels[(int)targ], (int)targ)); \ | 1974 : tlabels[(int)targ], (int)targ)); \ |
1975 } | 1975 } |
1976 | 1976 |
1986 | 1986 |
1987 #define LIST_COPY_ENUM16(label, targ, delta, count, ...) { \ | 1987 #define LIST_COPY_ENUM16(label, targ, delta, count, ...) { \ |
1988 char *tlabels[] = {__VA_ARGS__}; \ | 1988 char *tlabels[] = {__VA_ARGS__}; \ |
1989 LIST_COPY_INT16_N(targ); \ | 1989 LIST_COPY_INT16_N(targ); \ |
1990 targ += delta; \ | 1990 targ += delta; \ |
1991 DEBUG_INFO((label" - %s [%i]\n", \ | 1991 DEBUG_INFO((label" - %s [%i]\n", \ |
1992 (((int)targ < 0) || ((int)targ >= count)) \ | 1992 (((int)targ < 0) || ((int)targ >= count)) \ |
1993 ? "**invalid" \ | 1993 ? "**invalid" \ |
1994 : tlabels[(int)targ], (int)targ)); \ | 1994 : tlabels[(int)targ], (int)targ)); \ |
1995 } | 1995 } |
1996 | 1996 |
2001 | 2001 |
2002 #define LIST_COPY_ENTRYID(label, targ) { \ | 2002 #define LIST_COPY_ENTRYID(label, targ) { \ |
2003 LIST_COPY(targ, (pst_entryid*)); \ | 2003 LIST_COPY(targ, (pst_entryid*)); \ |
2004 LE32_CPU(targ->u1); \ | 2004 LE32_CPU(targ->u1); \ |
2005 LE32_CPU(targ->id); \ | 2005 LE32_CPU(targ->id); \ |
2006 DEBUG_INFO((label" u1=%#x, id=%#x\n", targ->u1, targ->id));\ | 2006 DEBUG_INFO((label" u1=%#x, id=%#x\n", targ->u1, targ->id)); \ |
2007 } | 2007 } |
2008 | 2008 |
2009 #define LIST_COPY_EMAIL_ENTRYID(label, targ) { \ | 2009 #define LIST_COPY_EMAIL_ENTRYID(label, targ) { \ |
2010 MALLOC_EMAIL(item); \ | 2010 MALLOC_EMAIL(item); \ |
2011 LIST_COPY_ENTRYID(label, targ); \ | 2011 LIST_COPY_ENTRYID(label, targ); \ |
2020 // malloc space and copy the current item's data null terminated | 2020 // malloc space and copy the current item's data null terminated |
2021 // including the utf8 flag | 2021 // including the utf8 flag |
2022 #define LIST_COPY_STR(label, targ) { \ | 2022 #define LIST_COPY_STR(label, targ) { \ |
2023 LIST_COPY_CSTR(targ.str); \ | 2023 LIST_COPY_CSTR(targ.str); \ |
2024 targ.is_utf8 = (list->elements[x]->type == 0x1f) ? 1 : 0; \ | 2024 targ.is_utf8 = (list->elements[x]->type == 0x1f) ? 1 : 0; \ |
2025 DEBUG_INFO((label" - unicode %d - %s\n", targ.is_utf8, targ.str)); \ | 2025 DEBUG_INFO((label" - unicode %d - %s\n", targ.is_utf8, targ.str)); \ |
2026 } | 2026 } |
2027 | 2027 |
2028 #define LIST_COPY_EMAIL_STR(label, targ) { \ | 2028 #define LIST_COPY_EMAIL_STR(label, targ) { \ |
2029 MALLOC_EMAIL(item); \ | 2029 MALLOC_EMAIL(item); \ |
2030 LIST_COPY_STR(label, targ); \ | 2030 LIST_COPY_STR(label, targ); \ |
2053 } \ | 2053 } \ |
2054 targ = (FILETIME*) realloc(targ, sizeof(FILETIME)); \ | 2054 targ = (FILETIME*) realloc(targ, sizeof(FILETIME)); \ |
2055 memcpy(targ, list->elements[x]->data, list->elements[x]->size); \ | 2055 memcpy(targ, list->elements[x]->data, list->elements[x]->size); \ |
2056 LE32_CPU(targ->dwLowDateTime); \ | 2056 LE32_CPU(targ->dwLowDateTime); \ |
2057 LE32_CPU(targ->dwHighDateTime); \ | 2057 LE32_CPU(targ->dwHighDateTime); \ |
2058 DEBUG_INFO((label" - %s", pst_fileTimeToAscii(targ, time_buffer))); \ | 2058 DEBUG_INFO((label" - %s", pst_fileTimeToAscii(targ, time_buffer))); \ |
2059 } | 2059 } |
2060 | 2060 |
2061 #define LIST_COPY_EMAIL_TIME(label, targ) { \ | 2061 #define LIST_COPY_EMAIL_TIME(label, targ) { \ |
2062 MALLOC_EMAIL(item); \ | 2062 MALLOC_EMAIL(item); \ |
2063 LIST_COPY_TIME(label, targ); \ | 2063 LIST_COPY_TIME(label, targ); \ |
2092 } | 2092 } |
2093 | 2093 |
2094 #define LIST_COPY_EMAIL_BIN(label, targ) { \ | 2094 #define LIST_COPY_EMAIL_BIN(label, targ) { \ |
2095 MALLOC_EMAIL(item); \ | 2095 MALLOC_EMAIL(item); \ |
2096 LIST_COPY_BIN(targ); \ | 2096 LIST_COPY_BIN(targ); \ |
2097 DEBUG_INFO((label"\n")); \ | 2097 DEBUG_INFO((label"\n")); \ |
2098 } | 2098 } |
2099 #define LIST_COPY_APPT_BIN(label, targ) { \ | 2099 #define LIST_COPY_APPT_BIN(label, targ) { \ |
2100 MALLOC_APPOINTMENT(item); \ | 2100 MALLOC_APPOINTMENT(item); \ |
2101 LIST_COPY_BIN(targ); \ | 2101 LIST_COPY_BIN(targ); \ |
2102 DEBUG_INFO((label"\n")); \ | 2102 DEBUG_INFO((label"\n")); \ |
2103 DEBUG_HEXDUMP(targ.data, targ.size); \ | 2103 DEBUG_HEXDUMP(targ.data, targ.size); \ |
2104 } | 2104 } |
2105 | 2105 |
2106 #define NULL_CHECK(x) { if (!x) { DEBUG_WARN(("NULL_CHECK: Null Found\n")); break;} } | 2106 #define NULL_CHECK(x) { if (!x) { DEBUG_WARN(("NULL_CHECK: Null Found\n")); break;} } |
2107 | 2107 |
2136 DEBUG_INFO(("#%d - mapi-id: %#x type: %#x length: %#x\n", x, list->elements[x]->mapi_id, list->elements[x]->type, list->elements[x]->size)); | 2136 DEBUG_INFO(("#%d - mapi-id: %#x type: %#x length: %#x\n", x, list->elements[x]->mapi_id, list->elements[x]->type, list->elements[x]->size)); |
2137 | 2137 |
2138 switch (list->elements[x]->mapi_id) { | 2138 switch (list->elements[x]->mapi_id) { |
2139 case PST_ATTRIB_HEADER: // CUSTOM attribute for saying the Extra Headers | 2139 case PST_ATTRIB_HEADER: // CUSTOM attribute for saying the Extra Headers |
2140 if (list->elements[x]->extra) { | 2140 if (list->elements[x]->extra) { |
2141 pst_item_extra_field *ef = (pst_item_extra_field*) pst_malloc(sizeof(pst_item_extra_field)); | 2141 if (list->elements[x]->type == 0x0101e) { |
2142 memset(ef, 0, sizeof(pst_item_extra_field)); | 2142 // an array of strings, rather than a single string |
2143 LIST_COPY_CSTR(ef->value); | 2143 int32_t string_length, i, offset, next_offset; |
2144 if (ef->value) { | 2144 int32_t p = 0; |
2145 ef->field_name = strdup(list->elements[x]->extra); | 2145 int32_t array_element_count = PST_LE_GET_INT32(list->elements[x]->data); p+=4; |
2146 ef->next = item->extra_fields; | 2146 for (i = 1; i <= array_element_count; i++) { |
2147 item->extra_fields = ef; | 2147 pst_item_extra_field *ef = (pst_item_extra_field*) pst_malloc(sizeof(pst_item_extra_field)); |
2148 DEBUG_INFO(("Extra Field - \"%s\" = \"%s\"\n", ef->field_name, ef->value)); | 2148 memset(ef, 0, sizeof(pst_item_extra_field)); |
2149 if (strcmp(ef->field_name, "content-type") == 0) { | 2149 offset = PST_LE_GET_INT32(list->elements[x]->data + p); p+=4; |
2150 char *p = strstr(ef->value, "charset=\""); | 2150 next_offset = (i == array_element_count) ? list->elements[x]->size : PST_LE_GET_INT32(list->elements[x]->data + p);; |
2151 if (p) { | 2151 string_length = next_offset - offset; |
2152 p += 9; // skip over charset=" | 2152 ef->value = malloc(string_length + 1); |
2153 char *pp = strchr(p, '"'); | 2153 memcpy(ef->value, list->elements[x]->data + offset, string_length); |
2154 if (pp) { | 2154 ef->value[string_length] = '\0'; |
2155 *pp = '\0'; | 2155 ef->field_name = strdup(list->elements[x]->extra); |
2156 char *set = strdup(p); | 2156 ef->next = item->extra_fields; |
2157 *pp = '"'; | 2157 item->extra_fields = ef; |
2158 if (item->body_charset.str) free(item->body_charset.str); | 2158 DEBUG_INFO(("Extra Field - \"%s\" = \"%s\"\n", ef->field_name, ef->value)); |
2159 item->body_charset.str = set; | 2159 } |
2160 item->body_charset.is_utf8 = 1; | 2160 } |
2161 DEBUG_INFO(("body charset %s from content-type extra field\n", set)); | 2161 else { |
2162 // should be a single string | |
2163 pst_item_extra_field *ef = (pst_item_extra_field*) pst_malloc(sizeof(pst_item_extra_field)); | |
2164 memset(ef, 0, sizeof(pst_item_extra_field)); | |
2165 LIST_COPY_CSTR(ef->value); | |
2166 if (ef->value) { | |
2167 ef->field_name = strdup(list->elements[x]->extra); | |
2168 ef->next = item->extra_fields; | |
2169 item->extra_fields = ef; | |
2170 DEBUG_INFO(("Extra Field - \"%s\" = \"%s\"\n", ef->field_name, ef->value)); | |
2171 if (strcmp(ef->field_name, "content-type") == 0) { | |
2172 char *p = strstr(ef->value, "charset=\""); | |
2173 if (p) { | |
2174 p += 9; // skip over charset=" | |
2175 char *pp = strchr(p, '"'); | |
2176 if (pp) { | |
2177 *pp = '\0'; | |
2178 char *set = strdup(p); | |
2179 *pp = '"'; | |
2180 if (item->body_charset.str) free(item->body_charset.str); | |
2181 item->body_charset.str = set; | |
2182 item->body_charset.is_utf8 = 1; | |
2183 DEBUG_INFO(("body charset %s from content-type extra field\n", set)); | |
2184 } | |
2162 } | 2185 } |
2163 } | 2186 } |
2164 } | 2187 } |
2165 } | 2188 else { |
2166 else { | 2189 DEBUG_WARN(("What does this mean? Internet header %s value\n", list->elements[x]->extra)); |
2167 DEBUG_WARN(("What does this mean? Internet header %s value\n", list->elements[x]->extra)); | 2190 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); |
2168 DEBUG_HEXDUMP(list->elements[x]->data, list->elements[x]->size); | 2191 free(ef); // caught by valgrind |
2169 free(ef); // caught by valgrind | 2192 } |
2170 } | 2193 } |
2171 } | 2194 } |
2172 break; | 2195 break; |
2173 case 0x0002: // PR_ALTERNATE_RECIPIENT_ALLOWED | 2196 case 0x0002: // PR_ALTERNATE_RECIPIENT_ALLOWED |
2174 if (list->elements[x]->type == 0x0b) { | 2197 if (list->elements[x]->type == 0x0b) { |
3979 size_t z, a; | 4002 size_t z, a; |
3980 uint16_t count, y; | 4003 uint16_t count, y; |
3981 char *buf3 = NULL; | 4004 char *buf3 = NULL; |
3982 char *buf2 = NULL; | 4005 char *buf2 = NULL; |
3983 char *b_ptr; | 4006 char *b_ptr; |
3984 int line_count = 0; | |
3985 pst_block_hdr block_hdr; | 4007 pst_block_hdr block_hdr; |
3986 pst_table3_rec table3_rec; //for type 3 (0x0101) blocks | 4008 pst_table3_rec table3_rec; //for type 3 (0x0101) blocks |
3987 | 4009 |
3988 DEBUG_ENT("pst_ff_compile_ID"); | 4010 DEBUG_ENT("pst_ff_compile_ID"); |
3989 a = pst_ff_getIDblock(pf, i_id, &buf3); | 4011 a = pst_ff_getIDblock(pf, i_id, &buf3); |