comparison src/libpst.c @ 59:7d5c637aaafb

General cleanup and code fixes. Use autoscan to cleanup our autoconf system. Use autoconf to detect when we need to use our XGetopt files and other header files. Decode BCC field. Fix missing LE32_CPU byte swapping for FILETIME types.
author Carl Byington <carl@five-ten-sg.com>
date Thu, 14 Feb 2008 14:55:32 -0800
parents a8b772313ff4
children 97b7706bdda2
comparison
equal deleted inserted replaced
58:a8b772313ff4 59:7d5c637aaafb
3 * Part of the LibPST project 3 * Part of the LibPST project
4 * Written by David Smith 4 * Written by David Smith
5 * dave.s@earthcorp.com 5 * dave.s@earthcorp.com
6 */ 6 */
7 #include "define.h" 7 #include "define.h"
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <time.h>
12 #include <string.h>
13 #include <ctype.h>
14 #include <limits.h>
15 #include <wchar.h>
16 #include <signal.h>
17 #include <errno.h>
18 #include <sys/stat.h> // mkdir
19 #include <fcntl.h> // for Win32 definition of _O_BINARY
20 #include "libstrfunc.h" 8 #include "libstrfunc.h"
21 #include "vbuf.h" 9 #include "vbuf.h"
22
23 #define ASSERT(x) { if(!(x)) raise( SIGSEGV ); }
24
25 #ifdef _MSC_VER
26 # include <windows.h>
27 #else
28 # include <unistd.h>
29 #endif //ifdef _MSC_VER
30
31 #include "libpst.h" 10 #include "libpst.h"
32 #include "timeconv.h" 11 #include "timeconv.h"
12
13 #define ASSERT(x) { if(!(x)) raise( SIGSEGV ); }
14
33 15
34 #define INDEX_TYPE32 0x0E 16 #define INDEX_TYPE32 0x0E
35 #define INDEX_TYPE64 0x17 17 #define INDEX_TYPE64 0x17
36 #define INDEX_TYPE_OFFSET (off_t)0x0A 18 #define INDEX_TYPE_OFFSET (off_t)0x0A
37 19
149 0x0e, 0x81, 0x65, 0x73, 0xe4, 0xc2, 0xa2, 0x8a, /*0xef*/ 131 0x0e, 0x81, 0x65, 0x73, 0xe4, 0xc2, 0xa2, 0x8a, /*0xef*/
150 0xd4, 0xe1, 0x11, 0xd0, 0x08, 0x8b, 0x2a, 0xf2, 132 0xd4, 0xe1, 0x11, 0xd0, 0x08, 0x8b, 0x2a, 0xf2,
151 0xed, 0x9a, 0x64, 0x3f, 0xc1, 0x6c, 0xf9, 0xec}; /*0xff*/ 133 0xed, 0x9a, 0x64, 0x3f, 0xc1, 0x6c, 0xf9, 0xec}; /*0xff*/
152 134
153 135
154 int pst_open(pst_file *pf, char *name, char *mode) { 136 int pst_open(pst_file *pf, char *name) {
155 int32_t sig; 137 int32_t sig;
156 138
157 unicode_init(); 139 unicode_init();
158 140
159 DEBUG_ENT("pst_open"); 141 DEBUG_ENT("pst_open");
163 DEBUG_RET(); 145 DEBUG_RET();
164 return -1; 146 return -1;
165 } 147 }
166 memset(pf, 0, sizeof(*pf)); 148 memset(pf, 0, sizeof(*pf));
167 149
168 #ifdef _MSC_VER 150 if ((pf->fp = fopen(name, "rb")) == NULL) {
169 // set the default open mode for windows
170 _fmode = _O_BINARY;
171 #endif //_MSC_VER
172 if ((pf->fp = fopen(name, mode)) == NULL) {
173 WARN(("cannot open PST file. Error\n")); 151 WARN(("cannot open PST file. Error\n"));
174 DEBUG_RET(); 152 DEBUG_RET();
175 return -1; 153 return -1;
176 } 154 }
177 155
1756 #define LIST_COPY(targ, type) { \ 1734 #define LIST_COPY(targ, type) { \
1757 targ = type realloc(targ, list->items[x]->size+1); \ 1735 targ = type realloc(targ, list->items[x]->size+1); \
1758 memcpy(targ, list->items[x]->data, list->items[x]->size); \ 1736 memcpy(targ, list->items[x]->data, list->items[x]->size); \
1759 memset(((char*)targ)+list->items[x]->size, 0, (size_t)1); \ 1737 memset(((char*)targ)+list->items[x]->size, 0, (size_t)1); \
1760 } 1738 }
1739 // malloc space and copy the item filetime
1740 #define LIST_COPY_TIME(targ) { \
1741 targ = (FILETIME*) realloc(targ, sizeof(FILETIME)); \
1742 memcpy(targ, list->items[x]->data, list->items[x]->size); \
1743 LE32_CPU(targ->dwLowDateTime); \
1744 LE32_CPU(targ->dwHighDateTime); \
1745 }
1761 // malloc space and copy the current item's data and size 1746 // malloc space and copy the current item's data and size
1762 #define LIST_COPY_SIZE(targ, type, mysize) { \ 1747 #define LIST_COPY_SIZE(targ, type, mysize) { \
1763 mysize = list->items[x]->size; \ 1748 mysize = list->items[x]->size; \
1764 if (mysize) { \ 1749 if (mysize) { \
1765 targ = type realloc(targ, mysize); \ 1750 targ = type realloc(targ, mysize); \
1985 } 1970 }
1986 break; 1971 break;
1987 case 0x0039: // PR_CLIENT_SUBMIT_TIME Date Email Sent/Created 1972 case 0x0039: // PR_CLIENT_SUBMIT_TIME Date Email Sent/Created
1988 DEBUG_EMAIL(("Date sent - ")); 1973 DEBUG_EMAIL(("Date sent - "));
1989 MALLOC_EMAIL(item); 1974 MALLOC_EMAIL(item);
1990 LIST_COPY(item->email->sent_date, (FILETIME*)); 1975 LIST_COPY_TIME(item->email->sent_date);
1991 LE32_CPU(item->email->sent_date->dwLowDateTime);
1992 LE32_CPU(item->email->sent_date->dwHighDateTime);
1993 DEBUG_EMAIL(("%s", fileTimeToAscii(item->email->sent_date))); 1976 DEBUG_EMAIL(("%s", fileTimeToAscii(item->email->sent_date)));
1994 break; 1977 break;
1995 case 0x003B: // PR_SENT_REPRESENTING_SEARCH_KEY Sender address 1 1978 case 0x003B: // PR_SENT_REPRESENTING_SEARCH_KEY Sender address 1
1996 DEBUG_EMAIL(("Sent on behalf of address 1 - ")); 1979 DEBUG_EMAIL(("Sent on behalf of address 1 - "));
1997 MALLOC_EMAIL(item); 1980 MALLOC_EMAIL(item);
2186 } else { 2169 } else {
2187 DEBUG_EMAIL(("False\n")); 2170 DEBUG_EMAIL(("False\n"));
2188 item->email->delete_after_submit = 0; 2171 item->email->delete_after_submit = 0;
2189 } 2172 }
2190 break; 2173 break;
2174 case 0x0E02: // PR_DISPLAY_BCC BCC Addresses
2175 DEBUG_EMAIL(("Display BCC Addresses - "));
2176 MALLOC_EMAIL(item);
2177 LIST_COPY(item->email->bcc_address, (char*));
2178 DEBUG_EMAIL(("%s\n", item->email->bcc_address));
2179 break;
2191 case 0x0E03: // PR_DISPLAY_CC CC Addresses 2180 case 0x0E03: // PR_DISPLAY_CC CC Addresses
2192 DEBUG_EMAIL(("Display CC Addresses - ")); 2181 DEBUG_EMAIL(("Display CC Addresses - "));
2193 MALLOC_EMAIL(item); 2182 MALLOC_EMAIL(item);
2194 LIST_COPY(item->email->cc_address, (char*)); 2183 LIST_COPY(item->email->cc_address, (char*));
2195 DEBUG_EMAIL(("%s\n", item->email->cc_address)); 2184 DEBUG_EMAIL(("%s\n", item->email->cc_address));
2201 DEBUG_EMAIL(("%s\n", item->email->sentto_address)); 2190 DEBUG_EMAIL(("%s\n", item->email->sentto_address));
2202 break; 2191 break;
2203 case 0x0E06: // PR_MESSAGE_DELIVERY_TIME Date 3 - Email Arrival Date 2192 case 0x0E06: // PR_MESSAGE_DELIVERY_TIME Date 3 - Email Arrival Date
2204 DEBUG_EMAIL(("Date 3 (Delivery Time) - ")); 2193 DEBUG_EMAIL(("Date 3 (Delivery Time) - "));
2205 MALLOC_EMAIL(item); 2194 MALLOC_EMAIL(item);
2206 LIST_COPY(item->email->arrival_date, (FILETIME*)); 2195 LIST_COPY_TIME(item->email->arrival_date);
2207 DEBUG_EMAIL(("%s", fileTimeToAscii(item->email->arrival_date))); 2196 DEBUG_EMAIL(("%s", fileTimeToAscii(item->email->arrival_date)));
2208 break; 2197 break;
2209 case 0x0E07: // PR_MESSAGE_FLAGS Email Flag 2198 case 0x0E07: // PR_MESSAGE_FLAGS Email Flag
2210 // 0x01 - Read 2199 // 0x01 - Read
2211 // 0x02 - Unmodified 2200 // 0x02 - Unmodified
2369 LIST_COPY(item->comment, (char*)); 2358 LIST_COPY(item->comment, (char*));
2370 DEBUG_EMAIL(("%s\n", item->comment)); 2359 DEBUG_EMAIL(("%s\n", item->comment));
2371 break; 2360 break;
2372 case 0x3007: // PR_CREATION_TIME Date 4 - Creation Date? 2361 case 0x3007: // PR_CREATION_TIME Date 4 - Creation Date?
2373 DEBUG_EMAIL(("Date 4 (Item Creation Date) - ")); 2362 DEBUG_EMAIL(("Date 4 (Item Creation Date) - "));
2374 LIST_COPY(item->create_date, (FILETIME*)); 2363 LIST_COPY_TIME(item->create_date);
2375 DEBUG_EMAIL(("%s", fileTimeToAscii(item->create_date))); 2364 DEBUG_EMAIL(("%s", fileTimeToAscii(item->create_date)));
2376 break; 2365 break;
2377 case 0x3008: // PR_LAST_MODIFICATION_TIME Date 5 - Modify Date 2366 case 0x3008: // PR_LAST_MODIFICATION_TIME Date 5 - Modify Date
2378 DEBUG_EMAIL(("Date 5 (Modify Date) - ")); 2367 DEBUG_EMAIL(("Date 5 (Modify Date) - "));
2379 LIST_COPY(item->modify_date, (FILETIME*)); 2368 LIST_COPY_TIME(item->modify_date);
2380 DEBUG_EMAIL(("%s", fileTimeToAscii(item->modify_date))); 2369 DEBUG_EMAIL(("%s", fileTimeToAscii(item->modify_date)));
2381 break; 2370 break;
2382 case 0x300B: // PR_SEARCH_KEY Record Header 2 2371 case 0x300B: // PR_SEARCH_KEY Record Header 2
2383 DEBUG_EMAIL(("Record Search 2 -- NOT HANDLED\n")); 2372 DEBUG_EMAIL(("Record Search 2 -- NOT HANDLED\n"));
2384 break; 2373 break;
2870 } 2859 }
2871 break; 2860 break;
2872 case 0x3A41: // PR_WEDDING_ANNIVERSARY 2861 case 0x3A41: // PR_WEDDING_ANNIVERSARY
2873 DEBUG_EMAIL(("Wedding Anniversary - ")); 2862 DEBUG_EMAIL(("Wedding Anniversary - "));
2874 MALLOC_CONTACT(item); 2863 MALLOC_CONTACT(item);
2875 LIST_COPY(item->contact->wedding_anniversary, (FILETIME*)); 2864 LIST_COPY_TIME(item->contact->wedding_anniversary);
2876 DEBUG_EMAIL(("%s\n", fileTimeToAscii(item->contact->wedding_anniversary))); 2865 DEBUG_EMAIL(("%s\n", fileTimeToAscii(item->contact->wedding_anniversary)));
2877 break; 2866 break;
2878 case 0x3A42: // PR_BIRTHDAY 2867 case 0x3A42: // PR_BIRTHDAY
2879 DEBUG_EMAIL(("Birthday - ")); 2868 DEBUG_EMAIL(("Birthday - "));
2880 MALLOC_CONTACT(item); 2869 MALLOC_CONTACT(item);
2881 LIST_COPY(item->contact->birthday, (FILETIME*)); 2870 LIST_COPY_TIME(item->contact->birthday);
2882 DEBUG_EMAIL(("%s\n", fileTimeToAscii(item->contact->birthday))); 2871 DEBUG_EMAIL(("%s\n", fileTimeToAscii(item->contact->birthday)));
2883 break; 2872 break;
2884 case 0x3A43: // PR_HOBBIES 2873 case 0x3A43: // PR_HOBBIES
2885 DEBUG_EMAIL(("Hobbies - ")); 2874 DEBUG_EMAIL(("Hobbies - "));
2886 MALLOC_CONTACT(item); 2875 MALLOC_CONTACT(item);
3282 DEBUG_EMAIL(("%s\n", item->appointment->location)); 3271 DEBUG_EMAIL(("%s\n", item->appointment->location));
3283 break; 3272 break;
3284 case 0x820d: // Appointment start 3273 case 0x820d: // Appointment start
3285 DEBUG_EMAIL(("Appointment Date Start - ")); 3274 DEBUG_EMAIL(("Appointment Date Start - "));
3286 MALLOC_APPOINTMENT(item); 3275 MALLOC_APPOINTMENT(item);
3287 LIST_COPY(item->appointment->start, (FILETIME*)); 3276 LIST_COPY_TIME(item->appointment->start);
3288 DEBUG_EMAIL(("%s\n", fileTimeToAscii(item->appointment->start))); 3277 DEBUG_EMAIL(("%s\n", fileTimeToAscii(item->appointment->start)));
3289 break; 3278 break;
3290 case 0x820e: // Appointment end 3279 case 0x820e: // Appointment end
3291 DEBUG_EMAIL(("Appointment Date End - ")); 3280 DEBUG_EMAIL(("Appointment Date End - "));
3292 MALLOC_APPOINTMENT(item); 3281 MALLOC_APPOINTMENT(item);
3293 LIST_COPY(item->appointment->end, (FILETIME*)); 3282 LIST_COPY_TIME(item->appointment->end);
3294 DEBUG_EMAIL(("%s\n", fileTimeToAscii(item->appointment->end))); 3283 DEBUG_EMAIL(("%s\n", fileTimeToAscii(item->appointment->end)));
3295 break; 3284 break;
3296 case 0x8214: // Label for an appointment 3285 case 0x8214: // Label for an appointment
3297 DEBUG_EMAIL(("Label for appointment - ")); 3286 DEBUG_EMAIL(("Label for appointment - "));
3298 MALLOC_APPOINTMENT(item); 3287 MALLOC_APPOINTMENT(item);
3369 DEBUG_EMAIL(("%s\n", item->appointment->timezonestring)); 3358 DEBUG_EMAIL(("%s\n", item->appointment->timezonestring));
3370 break; 3359 break;
3371 case 0x8235: // Recurrence start date 3360 case 0x8235: // Recurrence start date
3372 DEBUG_EMAIL(("Recurrence Start Date - ")); 3361 DEBUG_EMAIL(("Recurrence Start Date - "));
3373 MALLOC_APPOINTMENT(item); 3362 MALLOC_APPOINTMENT(item);
3374 LIST_COPY(item->appointment->recurrence_start, (FILETIME*)); 3363 LIST_COPY_TIME(item->appointment->recurrence_start);
3375 DEBUG_EMAIL(("%s\n", fileTimeToAscii(item->appointment->recurrence_start))); 3364 DEBUG_EMAIL(("%s\n", fileTimeToAscii(item->appointment->recurrence_start)));
3376 break; 3365 break;
3377 case 0x8236: // Recurrence end date 3366 case 0x8236: // Recurrence end date
3378 DEBUG_EMAIL(("Recurrence End Date - ")); 3367 DEBUG_EMAIL(("Recurrence End Date - "));
3379 MALLOC_APPOINTMENT(item); 3368 MALLOC_APPOINTMENT(item);
3380 LIST_COPY(item->appointment->recurrence_end, (FILETIME*)); 3369 LIST_COPY_TIME(item->appointment->recurrence_end);
3381 DEBUG_EMAIL(("%s\n", fileTimeToAscii(item->appointment->recurrence_end))); 3370 DEBUG_EMAIL(("%s\n", fileTimeToAscii(item->appointment->recurrence_end)));
3382 break; 3371 break;
3383 case 0x8501: // Reminder minutes before appointment start 3372 case 0x8501: // Reminder minutes before appointment start
3384 DEBUG_EMAIL(("Alarm minutes - ")); 3373 DEBUG_EMAIL(("Alarm minutes - "));
3385 MALLOC_APPOINTMENT(item); 3374 MALLOC_APPOINTMENT(item);
3436 DEBUG_EMAIL(("%s\n", item->outlook_version)); 3425 DEBUG_EMAIL(("%s\n", item->outlook_version));
3437 break; 3426 break;
3438 case 0x8560: // Appointment Reminder Time 3427 case 0x8560: // Appointment Reminder Time
3439 DEBUG_EMAIL(("Appointment Reminder Time - ")); 3428 DEBUG_EMAIL(("Appointment Reminder Time - "));
3440 MALLOC_APPOINTMENT(item); 3429 MALLOC_APPOINTMENT(item);
3441 LIST_COPY(item->appointment->reminder, (FILETIME*)); 3430 LIST_COPY_TIME(item->appointment->reminder);
3442 DEBUG_EMAIL(("%s\n", fileTimeToAscii(item->appointment->reminder))); 3431 DEBUG_EMAIL(("%s\n", fileTimeToAscii(item->appointment->reminder)));
3443 break; 3432 break;
3444 case 0x8700: // Journal Type 3433 case 0x8700: // Journal Type
3445 DEBUG_EMAIL(("Journal Entry Type - ")); 3434 DEBUG_EMAIL(("Journal Entry Type - "));
3446 MALLOC_JOURNAL(item); 3435 MALLOC_JOURNAL(item);
3448 DEBUG_EMAIL(("%s\n", item->journal->type)); 3437 DEBUG_EMAIL(("%s\n", item->journal->type));
3449 break; 3438 break;
3450 case 0x8706: // Journal Start date/time 3439 case 0x8706: // Journal Start date/time
3451 DEBUG_EMAIL(("Start Timestamp - ")); 3440 DEBUG_EMAIL(("Start Timestamp - "));
3452 MALLOC_JOURNAL(item); 3441 MALLOC_JOURNAL(item);
3453 LIST_COPY(item->journal->start, (FILETIME*)); 3442 LIST_COPY_TIME(item->journal->start);
3454 DEBUG_EMAIL(("%s\n", fileTimeToAscii(item->journal->start))); 3443 DEBUG_EMAIL(("%s\n", fileTimeToAscii(item->journal->start)));
3455 break; 3444 break;
3456 case 0x8708: // Journal End date/time 3445 case 0x8708: // Journal End date/time
3457 DEBUG_EMAIL(("End Timestamp - ")); 3446 DEBUG_EMAIL(("End Timestamp - "));
3458 MALLOC_JOURNAL(item); 3447 MALLOC_JOURNAL(item);
3459 LIST_COPY(item->journal->end, (FILETIME*)); 3448 LIST_COPY_TIME(item->journal->end);
3460 DEBUG_EMAIL(("%s\n", fileTimeToAscii(item->journal->end))); 3449 DEBUG_EMAIL(("%s\n", fileTimeToAscii(item->journal->end)));
3461 break; 3450 break;
3462 case 0x8712: // Title? 3451 case 0x8712: // Title?
3463 DEBUG_EMAIL(("Journal Entry Type - ")); 3452 DEBUG_EMAIL(("Journal Entry Type - "));
3464 MALLOC_JOURNAL(item); 3453 MALLOC_JOURNAL(item);
3755 if (item) { 3744 if (item) {
3756 if (item->email) { 3745 if (item->email) {
3757 SAFE_FREE(item->email->arrival_date); 3746 SAFE_FREE(item->email->arrival_date);
3758 SAFE_FREE(item->email->body); 3747 SAFE_FREE(item->email->body);
3759 SAFE_FREE(item->email->cc_address); 3748 SAFE_FREE(item->email->cc_address);
3749 SAFE_FREE(item->email->bcc_address);
3760 SAFE_FREE(item->email->common_name); 3750 SAFE_FREE(item->email->common_name);
3761 SAFE_FREE(item->email->encrypted_body); 3751 SAFE_FREE(item->email->encrypted_body);
3762 SAFE_FREE(item->email->encrypted_htmlbody); 3752 SAFE_FREE(item->email->encrypted_htmlbody);
3763 SAFE_FREE(item->email->header); 3753 SAFE_FREE(item->email->header);
3764 SAFE_FREE(item->email->htmlbody); 3754 SAFE_FREE(item->email->htmlbody);