16
|
1 /***
|
|
2 * readpst.c
|
|
3 * Part of the LibPST project
|
|
4 * Written by David Smith
|
|
5 * dave.s@earthcorp.com
|
|
6 */
|
|
7 #include <stdio.h>
|
|
8 #include <stdlib.h>
|
|
9 #include <time.h>
|
|
10 #include <string.h>
|
|
11 #include <ctype.h>
|
|
12 #include <limits.h>
|
|
13 #include <errno.h>
|
|
14
|
|
15 #ifndef _WIN32
|
|
16 # include <unistd.h>
|
|
17 # include <sys/stat.h> //mkdir
|
|
18
|
|
19 // for reading of directory and clearing in function mk_seperate_dir
|
|
20 # include <sys/types.h>
|
|
21 # include <dirent.h>
|
|
22 #else
|
|
23 # include <direct.h>
|
|
24 # define chdir _chdir
|
|
25 # define int32_t __int32
|
|
26 #endif
|
|
27
|
|
28 #ifndef __GNUC__
|
|
29 # include "XGetopt.h"
|
|
30 #endif
|
|
31
|
|
32 #include "libstrfunc.h" // for base64_encoding
|
|
33
|
21
|
34 #include "version.h"
|
16
|
35 #include "define.h"
|
|
36 #include "libpst.h"
|
|
37 #include "common.h"
|
|
38 #include "timeconv.h"
|
|
39 #include "lzfu.h"
|
|
40 #define OUTPUT_TEMPLATE "%s"
|
|
41 #define OUTPUT_KMAIL_DIR_TEMPLATE ".%s.directory"
|
|
42 #define KMAIL_INDEX ".%s.index"
|
|
43
|
|
44 // max size of the c_time char*. It will store the date of the email
|
|
45 #define C_TIME_SIZE 500
|
|
46 #define PERM_DIRS 0777
|
|
47
|
|
48 // macro used for creating directories
|
|
49 #ifndef WIN32
|
|
50 #define D_MKDIR(x) mkdir(x, PERM_DIRS)
|
|
51 #else
|
|
52 #define D_MKDIR(x) mkdir(x)
|
|
53 #endif
|
|
54 struct file_ll {
|
|
55 char *name;
|
|
56 char *dname;
|
|
57 FILE * output;
|
|
58 int32_t stored_count;
|
|
59 int32_t email_count;
|
|
60 int32_t skip_count;
|
|
61 int32_t type;
|
|
62 struct file_ll *next;
|
|
63 };
|
|
64 void write_email_body(FILE *f, char *body);
|
|
65 char *removeCR (char *c);
|
|
66 int32_t usage();
|
|
67 int32_t version();
|
|
68 char *mk_kmail_dir(char*);
|
|
69 int32_t close_kmail_dir();
|
|
70 char *mk_recurse_dir(char*);
|
|
71 int32_t close_recurse_dir();
|
|
72 char *mk_seperate_dir(char *dir, int overwrite);
|
|
73 int32_t close_seperate_dir();
|
|
74 int32_t mk_seperate_file(struct file_ll *f);
|
|
75 char *my_stristr(char *haystack, char *needle);
|
|
76 char *check_filename(char *fname);
|
|
77 char *rfc2426_escape(char *str);
|
|
78 int32_t chr_count(char *str, char x);
|
|
79 char *rfc2425_datetime_format(FILETIME *ft);
|
|
80 char *rfc2445_datetime_format(FILETIME *ft);
|
|
81 char *skip_header_prologue(char *headers);
|
|
82 char *prog_name;
|
|
83 char *output_dir = ".";
|
|
84 char *kmail_chdir = NULL;
|
|
85 // Normal mode just creates mbox format files in the current directory. Each file is named
|
|
86 // the same as the folder's name that it represents
|
|
87 #define MODE_NORMAL 0
|
|
88 // KMail mode creates a directory structure suitable for being used directly
|
|
89 // by the KMail application
|
|
90 #define MODE_KMAIL 1
|
|
91 // recurse mode creates a directory structure like the PST file. Each directory
|
|
92 // contains only one file which stores the emails in mbox format.
|
|
93 #define MODE_RECURSE 2
|
|
94 // seperate mode is similar directory structure to RECURSE. The emails are stored in
|
|
95 // seperate files, numbering from 1 upward. Attachments belonging to the emails are
|
|
96 // saved as email_no-filename (e.g. 1-samplefile.doc or 000001-Attachment2.zip)
|
|
97 #define MODE_SEPERATE 3
|
|
98
|
|
99
|
|
100 // Output Normal just prints the standard information about what is going on
|
|
101 #define OUTPUT_NORMAL 0
|
|
102 // Output Quiet is provided so that only errors are printed
|
|
103 #define OUTPUT_QUIET 1
|
|
104
|
|
105 // default mime-type for attachments that have a null mime-type
|
|
106 #define MIME_TYPE_DEFAULT "application/octet-stream"
|
|
107
|
|
108
|
|
109 // output mode for contacts
|
|
110 #define CMODE_VCARD 0
|
|
111 #define CMODE_LIST 1
|
|
112
|
|
113 // output settings for RTF bodies
|
|
114 // filename for the attachment
|
|
115 #define RTF_ATTACH_NAME "rtf-body.rtf"
|
|
116 // mime type for the attachment
|
|
117 #define RTF_ATTACH_TYPE "application/rtf"
|
|
118 int main(int argc, char** argv) {
|
|
119 pst_item *item = NULL;
|
|
120 pst_file pstfile;
|
|
121 pst_desc_ll *d_ptr;
|
|
122 char * fname = NULL;
|
|
123 time_t em_time;
|
|
124 char * c_time, *d_log=NULL;
|
|
125 int c,x;
|
|
126 int mode = MODE_NORMAL;
|
|
127 int output_mode = OUTPUT_NORMAL;
|
|
128 int contact_mode = CMODE_VCARD;
|
|
129 int overwrite = 0;
|
|
130 int base64_body = 0;
|
|
131 // int encrypt = 0;
|
|
132 FILE *fp;
|
|
133 char *enc; // base64 encoded attachment
|
|
134 char *boundary = NULL, *b1, *b2; // the boundary marker between multipart sections
|
|
135 char *temp = NULL; //temporary char pointer
|
|
136 int attach_num = 0;
|
|
137 int skip_child = 0;
|
|
138 struct file_ll *f, *head;
|
|
139 prog_name = argv[0];
|
|
140
|
|
141 while ((c = getopt(argc, argv, "d:hko:qrSVwc:"))!= -1) {
|
|
142 switch (c) {
|
|
143 case 'c':
|
|
144 if (optarg!=NULL && optarg[0]=='v')
|
|
145 contact_mode=CMODE_VCARD;
|
|
146 else if (optarg!=NULL && optarg[0]=='l')
|
|
147 contact_mode=CMODE_LIST;
|
|
148 else {
|
|
149 usage();
|
|
150 exit(0);
|
|
151 }
|
|
152 break;
|
|
153 case 'd':
|
|
154 d_log = optarg;
|
|
155 break;
|
|
156 case 'h':
|
|
157 usage();
|
|
158 exit(0);
|
|
159 break;
|
|
160 case 'V':
|
|
161 version();
|
|
162 exit(0);
|
|
163 break;
|
|
164 case 'k':
|
|
165 mode = MODE_KMAIL;
|
|
166 break;
|
|
167 case 'o':
|
|
168 output_dir = optarg;
|
|
169 break;
|
|
170 case 'q':
|
|
171 output_mode = OUTPUT_QUIET;
|
|
172 break;
|
|
173 case 'r':
|
|
174 mode = MODE_RECURSE;
|
|
175 break;
|
|
176 case 'S':
|
|
177 mode = MODE_SEPERATE;
|
|
178 break;
|
|
179 case 'w':
|
|
180 overwrite = 1;
|
|
181 break;
|
|
182 default:
|
|
183 usage();
|
|
184 exit(1);
|
|
185 break;
|
|
186 }
|
|
187 }
|
|
188
|
|
189 #ifdef DEBUG_ALL
|
|
190 // initialize log file
|
|
191 if (d_log == NULL)
|
|
192 d_log = "readpst.log";
|
|
193 DEBUG_INIT(d_log);
|
|
194 DEBUG_REGISTER_CLOSE();
|
|
195 #endif // defined DEBUG_ALL
|
|
196
|
|
197 DEBUG_ENT("main");
|
|
198
|
|
199 if (argc > optind) {
|
|
200 fname = argv[optind];
|
|
201 } else {
|
|
202 usage();
|
|
203 exit(2);
|
|
204 }
|
|
205
|
|
206 if (output_mode != OUTPUT_QUIET) printf("Opening PST file and indexes...\n");
|
|
207
|
|
208 DEBUG_MAIN(("main: Opening PST file '%s'\n", fname));
|
|
209 RET_DERROR(pst_open(&pstfile, fname, "r"), 1, ("Error opening File\n"));
|
|
210 DEBUG_MAIN(("main: Loading Indexes\n"));
|
|
211 RET_DERROR(pst_load_index(&pstfile), 2, ("Index Error\n"));
|
|
212 DEBUG_MAIN(("processing file items\n"));
|
|
213
|
|
214 pst_load_extended_attributes(&pstfile);
|
|
215
|
|
216 if (chdir(output_dir)) {
|
|
217 x = errno;
|
|
218 pst_close(&pstfile);
|
|
219 DIE(("main: Cannot change to output dir %s: %s\n", output_dir, strerror(x)));
|
|
220 }
|
|
221
|
|
222 if (output_mode != OUTPUT_QUIET) printf("About to start processing first record...\n");
|
|
223
|
|
224 d_ptr = pstfile.d_head; // first record is main record
|
|
225 if ((item = _pst_parse_item(&pstfile, d_ptr)) == NULL || item->message_store == NULL) {
|
|
226 DIE(("main: Could not get root record\n"));
|
|
227 }
|
|
228
|
|
229 // default the file_as to the same as the main filename if it doesn't exist
|
|
230 if (item->file_as == NULL) {
|
|
231 if ((temp = strrchr(fname, '/')) == NULL)
|
|
232 if ((temp = strrchr(fname, '\\')) == NULL)
|
|
233 temp = fname;
|
|
234 else
|
|
235 temp++; // get past the "\\"
|
|
236 else
|
|
237 temp++; // get past the "/"
|
|
238 item->file_as = (char*)xmalloc(strlen(temp)+1);
|
|
239 strcpy(item->file_as, temp);
|
|
240 DEBUG_MAIN(("file_as was blank, so am using %s\n", item->file_as));
|
|
241 }
|
|
242 DEBUG_MAIN(("main: Root Folder Name: %s\n", item->file_as));
|
|
243
|
|
244
|
|
245 f = (struct file_ll*) malloc(sizeof(struct file_ll));
|
|
246 memset(f, 0, sizeof(struct file_ll));
|
|
247 f->email_count = 0;
|
|
248 f->skip_count = 0;
|
|
249 f->next = NULL;
|
|
250 head = f;
|
|
251 if (mode == MODE_KMAIL)
|
|
252 f->name = mk_kmail_dir(item->file_as);
|
|
253 else if (mode == MODE_RECURSE)
|
|
254 f->name = mk_recurse_dir(item->file_as);
|
|
255 else if (mode == MODE_SEPERATE) {
|
|
256 // do similar stuff to recurse here.
|
|
257 mk_seperate_dir(item->file_as, overwrite);
|
|
258 f->name = (char*) xmalloc(10);
|
|
259 sprintf(f->name, "%09i", f->email_count);
|
|
260 } else {
|
|
261 f->name = (char*) malloc(strlen(item->file_as)+strlen(OUTPUT_TEMPLATE)+1);
|
|
262 sprintf(f->name, OUTPUT_TEMPLATE, item->file_as);
|
|
263 }
|
|
264
|
|
265 f->dname = (char*) malloc(strlen(item->file_as)+1);
|
|
266 strcpy(f->dname, item->file_as);
|
|
267
|
|
268 if (overwrite != 1 && mode != MODE_SEPERATE) {
|
|
269 // if overwrite is set to 1 we keep the existing name and don't modify anything
|
|
270 // we don't want to go changing the file name of the SEPERATE items
|
|
271 temp = (char*) malloc (strlen(f->name)+10); //enough room for 10 digits
|
|
272 sprintf(temp, "%s", f->name);
|
|
273 temp = check_filename(temp);
|
|
274 x = 0;
|
|
275 while ((f->output = fopen(temp, "r")) != NULL) {
|
|
276 DEBUG_MAIN(("main: need to increase filename cause one already exists with that name\n"));
|
|
277 DEBUG_MAIN(("main: - increasing it to %s%d\n", f->name, x));
|
|
278 x++;
|
|
279 sprintf(temp, "%s%08d", f->name, x);
|
|
280 DEBUG_MAIN(("main: - trying \"%s\"\n", temp));
|
|
281 if (x == 99999999) {
|
|
282 DIE(("main: Why can I not create a folder %s? I have tried %i extensions...\n", f->name, x));
|
|
283 }
|
|
284 fclose(f->output);
|
|
285 }
|
|
286 if (x > 0) { //then the f->name should change
|
|
287 free (f->name);
|
|
288 f->name = temp;
|
|
289 } else {
|
|
290 free (temp);
|
|
291 }
|
|
292 }
|
|
293 if (mode != MODE_SEPERATE) {
|
|
294 f->name = check_filename(f->name);
|
|
295 if ((f->output = fopen(f->name, "w")) == NULL) {
|
|
296 DIE(("main: Could not open file \"%s\" for write\n", f->name));
|
|
297 }
|
|
298 }
|
|
299 f->type = item->type;
|
|
300
|
|
301 if ((d_ptr = pst_getTopOfFolders(&pstfile, item)) == NULL) {
|
|
302 DIE(("Top of folders record not found. Cannot continue\n"));
|
|
303 }
|
|
304
|
|
305 if (item){
|
|
306 _pst_freeItem(item);
|
|
307 item = NULL;
|
|
308 }
|
|
309
|
|
310 /* if ((item = _pst_parse_item(&pstfile, d_ptr)) == NULL || item->folder == NULL) {
|
|
311 DEBUG_MAIN(("main: Could not get \"Top Of Personal Folder\" record\n"));
|
|
312 return -2;
|
|
313 }*/
|
|
314 d_ptr = d_ptr->child; // do the children of TOPF
|
|
315
|
|
316 if (output_mode != OUTPUT_QUIET) printf("Processing items...\n");
|
|
317
|
|
318 DEBUG_MAIN(("main: About to do email stuff\n"));
|
|
319 while (d_ptr != NULL) {
|
|
320 DEBUG_MAIN(("main: New item record\n"));
|
|
321 if (d_ptr->desc == NULL) {
|
|
322 DEBUG_WARN(("main: ERROR ?? item's desc record is NULL\n"));
|
|
323 f->skip_count++;
|
|
324 goto check_parent;
|
|
325 }
|
|
326 DEBUG_MAIN(("main: Desc Email ID %#x [d_ptr->id = %#x]\n", d_ptr->desc->id, d_ptr->id));
|
|
327
|
|
328 item = _pst_parse_item(&pstfile, d_ptr);
|
|
329 DEBUG_MAIN(("main: About to process item\n"));
|
|
330 if (item != NULL && item->email != NULL && item->email->subject != NULL &&
|
|
331 item->email->subject->subj != NULL) {
|
|
332 // DEBUG_EMAIL(("item->email->subject = %p\n", item->email->subject));
|
|
333 // DEBUG_EMAIL(("item->email->subject->subj = %p\n", item->email->subject->subj));
|
|
334 }
|
|
335 if (item != NULL) {
|
|
336 if (item->message_store != NULL) {
|
|
337 // there should only be one message_store, and we have already done it
|
|
338 DIE(("main: A second message_store has been found. Sorry, this must be an error.\n"));
|
|
339 }
|
|
340
|
|
341
|
|
342 if (item->folder != NULL) {
|
|
343 // if this is a folder, we want to recurse into it
|
|
344 if (output_mode != OUTPUT_QUIET) printf("Processing Folder \"%s\"\n", item->file_as);
|
|
345 // f->email_count++;
|
|
346 DEBUG_MAIN(("main: I think I may try to go into folder \"%s\"\n", item->file_as));
|
|
347 f = (struct file_ll*) malloc(sizeof(struct file_ll));
|
|
348 memset(f, 0, sizeof(struct file_ll));
|
|
349
|
|
350 f->next = head;
|
|
351 f->email_count = 0;
|
|
352 f->type = item->type;
|
|
353 f->stored_count = item->folder->email_count;
|
|
354 head = f;
|
|
355
|
|
356 temp = item->file_as;
|
|
357 temp = check_filename(temp);
|
|
358
|
|
359 if (mode == MODE_KMAIL)
|
|
360 f->name = mk_kmail_dir(item->file_as); //create directory and form filename
|
|
361 else if (mode == MODE_RECURSE)
|
|
362 f->name = mk_recurse_dir(item->file_as);
|
|
363 else if (mode == MODE_SEPERATE) {
|
|
364 // do similar stuff to recurse here.
|
|
365 mk_seperate_dir(item->file_as, overwrite);
|
|
366 f->name = (char*) xmalloc(10);
|
|
367 memset(f->name, 0, 10);
|
|
368 // sprintf(f->name, "%09i", f->email_count);
|
|
369 } else {
|
|
370 f->name = (char*) xmalloc(strlen(item->file_as)+strlen(OUTPUT_TEMPLATE+1));
|
|
371 sprintf(f->name, OUTPUT_TEMPLATE, item->file_as);
|
|
372 }
|
|
373
|
|
374 f->dname = (char*) xmalloc(strlen(item->file_as)+1);
|
|
375 strcpy(f->dname, item->file_as);
|
|
376
|
|
377 if (overwrite != 1) {
|
|
378 temp = (char*) xmalloc (strlen(f->name)+10); //enough room for 10 digits
|
|
379 sprintf(temp, "%s", f->name);
|
|
380 x = 0;
|
|
381 temp = check_filename(temp);
|
|
382 while ((f->output = fopen(temp, "r")) != NULL) {
|
|
383 DEBUG_MAIN(("main: need to increase filename cause one already exists with that name\n"));
|
|
384 DEBUG_MAIN(("main: - increasing it to %s%d\n", f->name, x));
|
|
385 x++;
|
|
386 sprintf(temp, "%s%08d", f->name, x);
|
|
387 DEBUG_MAIN(("main: - trying \"%s\"\n", f->name));
|
|
388 if (x == 99999999) {
|
|
389 DIE(("main: Why can I not create a folder %s? I have tried %i extensions...\n", f->name, x));
|
|
390 }
|
|
391 fclose(f->output);
|
|
392 }
|
|
393 if (x > 0) { //then the f->name should change
|
|
394 free (f->name);
|
|
395 f->name = temp;
|
|
396 } else {
|
|
397 free(temp);
|
|
398 }
|
|
399 }
|
|
400
|
|
401 DEBUG_MAIN(("main: f->name = %s\nitem->folder_name = %s\n", f->name, item->file_as));
|
|
402 if (mode != MODE_SEPERATE) {
|
|
403 f->name = check_filename(f->name);
|
|
404 if ((f->output = fopen(f->name, "w")) == NULL) {
|
|
405 DIE(("main: Could not open file \"%s\" for write\n", f->name));
|
|
406 }
|
|
407 }
|
|
408 if (d_ptr->child != NULL) {
|
|
409 d_ptr = d_ptr->child;
|
|
410 skip_child = 1;
|
|
411 } else {
|
|
412 DEBUG_MAIN(("main: Folder has NO children. Creating directory, and closing again\n"));
|
|
413 if (output_mode != OUTPUT_QUIET)
|
|
414 printf("\tNo items to process in folder \"%s\", should have been %i\n", f->dname, f->stored_count);
|
|
415 head = f->next;
|
|
416 if (f->output != NULL)
|
|
417 fclose(f->output);
|
|
418 if (mode == MODE_KMAIL)
|
|
419 close_kmail_dir();
|
|
420 else if (mode == MODE_RECURSE)
|
|
421 close_recurse_dir();
|
|
422 else if (mode == MODE_SEPERATE)
|
|
423 close_seperate_dir();
|
|
424 free(f->dname);
|
|
425 free(f->name);
|
|
426 free(f);
|
|
427
|
|
428 f = head;
|
|
429 }
|
|
430 _pst_freeItem(item);
|
|
431 item = NULL; // just for the odd situations!
|
|
432 goto check_parent;
|
|
433 } else if (item->contact != NULL) {
|
|
434 // deal with a contact
|
|
435 // write them to the file, one per line in this format
|
|
436 // Desc Name <email@address>\n
|
|
437 if (mode == MODE_SEPERATE) {
|
|
438 mk_seperate_file(f);
|
|
439 }
|
|
440 f->email_count++;
|
|
441
|
|
442 DEBUG_MAIN(("main: Processing Contact\n"));
|
|
443 if (f->type != PST_TYPE_CONTACT) {
|
|
444 DEBUG_MAIN(("main: I have a contact, but the folder isn't a contacts folder. "
|
|
445 "Will process anyway\n"));
|
|
446 }
|
|
447 if (item->type != PST_TYPE_CONTACT) {
|
|
448 DEBUG_MAIN(("main: I have an item that has contact info, but doesn't say that"
|
|
449 " it is a contact. Type is \"%s\"\n", item->ascii_type));
|
|
450 DEBUG_MAIN(("main: Processing anyway\n"));
|
|
451 }
|
|
452 if (item->contact == NULL) { // this is an incorrect situation. Inform user
|
|
453 DEBUG_MAIN(("main: ERROR. This contact has not been fully parsed. one of the pre-requisties is NULL\n"));
|
|
454 } else {
|
|
455 if (contact_mode == CMODE_VCARD) {
|
|
456 // the specification I am following is (hopefully) RFC2426 vCard Mime Directory Profile
|
|
457 fprintf(f->output, "BEGIN:VCARD\n");
|
|
458 fprintf(f->output, "FN:%s\n", rfc2426_escape(item->contact->fullname));
|
|
459 fprintf(f->output, "N:%s;%s;%s;%s;%s\n",
|
|
460 rfc2426_escape((item->contact->surname==NULL?"":item->contact->surname)),
|
|
461 rfc2426_escape((item->contact->first_name==NULL?"":item->contact->first_name)),
|
|
462 rfc2426_escape((item->contact->middle_name==NULL?"":item->contact->middle_name)),
|
|
463 rfc2426_escape((item->contact->display_name_prefix==NULL?"":item->contact->display_name_prefix)),
|
|
464 rfc2426_escape((item->contact->suffix==NULL?"":item->contact->suffix)));
|
|
465 if (item->contact->nickname != NULL)
|
|
466 fprintf(f->output, "NICKNAME:%s\n", rfc2426_escape(item->contact->nickname));
|
|
467 if (item->contact->address1 != NULL)
|
|
468 fprintf(f->output, "EMAIL:%s\n", rfc2426_escape(item->contact->address1));
|
|
469 if (item->contact->address2 != NULL)
|
|
470 fprintf(f->output, "EMAIL:%s\n", rfc2426_escape(item->contact->address2));
|
|
471 if (item->contact->address3 != NULL)
|
|
472 fprintf(f->output, "EMAIL:%s\n", rfc2426_escape(item->contact->address3));
|
|
473 if (item->contact->birthday != NULL)
|
|
474 fprintf(f->output, "BDAY:%s\n", rfc2425_datetime_format(item->contact->birthday));
|
|
475 if (item->contact->home_address != NULL) {
|
|
476 fprintf(f->output, "ADR;TYPE=home:%s;%s;%s;%s;%s;%s;%s\n",
|
|
477 rfc2426_escape((item->contact->home_po_box!=NULL?item->contact->home_po_box:"")),
|
|
478 "", // extended Address
|
|
479 rfc2426_escape((item->contact->home_street!=NULL?item->contact->home_street:"")),
|
|
480 rfc2426_escape((item->contact->home_city!=NULL?item->contact->home_city:"")),
|
|
481 rfc2426_escape((item->contact->home_state!=NULL?item->contact->home_state:"")),
|
|
482 rfc2426_escape((item->contact->home_postal_code!=NULL?item->contact->home_postal_code:"")),
|
|
483 rfc2426_escape((item->contact->home_country!=NULL?item->contact->home_country:"")));
|
|
484 fprintf(f->output, "LABEL;TYPE=home:%s\n", rfc2426_escape(item->contact->home_address));
|
|
485 }
|
|
486 if (item->contact->business_address != NULL) {
|
|
487 fprintf(f->output, "ADR;TYPE=work:%s;%s;%s;%s;%s;%s;%s\n",
|
|
488 rfc2426_escape((item->contact->business_po_box!=NULL?item->contact->business_po_box:"")),
|
|
489 "", // extended Address
|
|
490 rfc2426_escape((item->contact->business_street!=NULL?item->contact->business_street:"")),
|
|
491 rfc2426_escape((item->contact->business_city!=NULL?item->contact->business_city:"")),
|
|
492 rfc2426_escape((item->contact->business_state!=NULL?item->contact->business_state:"")),
|
|
493 rfc2426_escape((item->contact->business_postal_code!=NULL?item->contact->business_postal_code:"")),
|
|
494 rfc2426_escape((item->contact->business_country!=NULL?item->contact->business_country:"")));
|
|
495 fprintf(f->output, "LABEL;TYPE=work:%s\n", rfc2426_escape(item->contact->business_address));
|
|
496 }
|
|
497 if (item->contact->other_address != NULL) {
|
|
498 fprintf(f->output, "ADR;TYPE=postal:%s;%s;%s;%s;%s;%s;%s\n",
|
|
499 rfc2426_escape((item->contact->other_po_box!=NULL?item->contact->business_po_box:"")),
|
|
500 "", // extended Address
|
|
501 rfc2426_escape((item->contact->other_street!=NULL?item->contact->other_street:"")),
|
|
502 rfc2426_escape((item->contact->other_city!=NULL?item->contact->other_city:"")),
|
|
503 rfc2426_escape((item->contact->other_state!=NULL?item->contact->other_state:"")),
|
|
504 rfc2426_escape((item->contact->other_postal_code!=NULL?item->contact->other_postal_code:"")),
|
|
505 rfc2426_escape((item->contact->other_country!=NULL?item->contact->other_country:"")));
|
|
506 fprintf(f->output, "ADR;TYPE=postal:%s\n", rfc2426_escape(item->contact->other_address));
|
|
507 }
|
|
508 if (item->contact->business_fax != NULL)
|
|
509 fprintf(f->output, "TEL;TYPE=work,fax:%s\n", rfc2426_escape(item->contact->business_fax));
|
|
510 if (item->contact->business_phone != NULL)
|
|
511 fprintf(f->output, "TEL;TYPE=work,voice:%s\n", rfc2426_escape(item->contact->business_phone));
|
|
512 if (item->contact->business_phone2 != NULL)
|
|
513 fprintf(f->output, "TEL;TYPE=work,voice:%s\n", rfc2426_escape(item->contact->business_phone2));
|
|
514 if (item->contact->car_phone != NULL)
|
|
515 fprintf(f->output, "TEL;TYPE=car,voice:%s\n", rfc2426_escape(item->contact->car_phone));
|
|
516 if (item->contact->home_fax != NULL)
|
|
517 fprintf(f->output, "TEL;TYPE=home,fax:%s\n", rfc2426_escape(item->contact->home_fax));
|
|
518 if (item->contact->home_phone != NULL)
|
|
519 fprintf(f->output, "TEL;TYPE=home,voice:%s\n", rfc2426_escape(item->contact->home_phone));
|
|
520 if (item->contact->home_phone2 != NULL)
|
|
521 fprintf(f->output, "TEL;TYPE=home,voice:%s\n", rfc2426_escape(item->contact->home_phone2));
|
|
522 if (item->contact->isdn_phone != NULL)
|
|
523 fprintf(f->output, "TEL;TYPE=isdn:%s\n", rfc2426_escape(item->contact->isdn_phone));
|
|
524 if (item->contact->mobile_phone != NULL)
|
|
525 fprintf(f->output, "TEL;TYPE=cell,voice:%s\n", rfc2426_escape(item->contact->mobile_phone));
|
|
526 if (item->contact->other_phone != NULL)
|
|
527 fprintf(f->output, "TEL;TYPE=msg:%s\n", rfc2426_escape(item->contact->other_phone));
|
|
528 if (item->contact->pager_phone != NULL)
|
|
529 fprintf(f->output, "TEL;TYPE=pager:%s\n", rfc2426_escape(item->contact->pager_phone));
|
|
530 if (item->contact->primary_fax != NULL)
|
|
531 fprintf(f->output, "TEL;TYPE=fax,pref:%s\n", rfc2426_escape(item->contact->primary_fax));
|
|
532 if (item->contact->primary_phone != NULL)
|
|
533 fprintf(f->output, "TEL;TYPE=phone,pref:%s\n", rfc2426_escape(item->contact->primary_phone));
|
|
534 if (item->contact->radio_phone != NULL)
|
|
535 fprintf(f->output, "TEL;TYPE=pcs:%s\n", rfc2426_escape(item->contact->radio_phone));
|
|
536 if (item->contact->telex != NULL)
|
|
537 fprintf(f->output, "TEL;TYPE=bbs:%s\n", rfc2426_escape(item->contact->telex));
|
|
538 if (item->contact->job_title != NULL)
|
|
539 fprintf(f->output, "TITLE:%s\n", rfc2426_escape(item->contact->job_title));
|
|
540 if (item->contact->profession != NULL)
|
|
541 fprintf(f->output, "ROLE:%s\n", rfc2426_escape(item->contact->profession));
|
|
542 if (item->contact->assistant_name != NULL || item->contact->assistant_phone != NULL) {
|
|
543 fprintf(f->output, "AGENT:BEGIN:VCARD\\n");
|
|
544 if (item->contact->assistant_name != NULL)
|
|
545 fprintf(f->output, "FN:%s\\n", rfc2426_escape(item->contact->assistant_name));
|
|
546 if (item->contact->assistant_phone != NULL)
|
|
547 fprintf(f->output, "TEL:%s\\n", rfc2426_escape(item->contact->assistant_phone));
|
|
548 fprintf(f->output, "END:VCARD\\n\n");
|
|
549 }
|
|
550 if (item->contact->company_name != NULL)
|
|
551 fprintf(f->output, "ORG:%s\n", rfc2426_escape(item->contact->company_name));
|
|
552 if (item->comment != NULL)
|
|
553 fprintf(f->output, "NOTE:%s\n", rfc2426_escape(item->comment));
|
|
554
|
|
555 fprintf(f->output, "VERSION: 3.0\n");
|
|
556 fprintf(f->output, "END:VCARD\n\n");
|
|
557 } else {
|
|
558 fprintf(f->output, "%s <%s>\n", item->contact->fullname, item->contact->address1);
|
|
559 }
|
|
560 }
|
|
561 } else if (item->email != NULL &&
|
|
562 (item->type == PST_TYPE_NOTE || item->type == PST_TYPE_REPORT)) {
|
|
563 if (mode == MODE_SEPERATE) {
|
|
564 mk_seperate_file(f);
|
|
565 }
|
|
566
|
|
567 f->email_count++;
|
|
568
|
|
569 DEBUG_MAIN(("main: seen an email\n"));
|
|
570
|
|
571 // convert the sent date if it exists, or set it to a fixed date
|
|
572 if (item->email->sent_date != NULL) {
|
|
573 em_time = fileTimeToUnixTime(item->email->sent_date, 0);
|
|
574 c_time = ctime(&em_time);
|
|
575 if (c_time != NULL)
|
|
576 c_time[strlen(c_time)-1] = '\0'; //remove end \n
|
|
577 else
|
|
578 c_time = "Fri Dec 28 12:06:21 2001";
|
|
579 } else
|
|
580 c_time= "Fri Dec 28 12:06:21 2001";
|
|
581
|
|
582 // if the boundary is still set from the previous run, then free it
|
|
583 if (boundary != NULL) {
|
|
584 free (boundary);
|
|
585 boundary = NULL;
|
|
586 }
|
|
587
|
|
588 // we will always look at the header to discover some stuff
|
|
589 if (item->email->header != NULL ) {
|
|
590 // see if there is a boundary variable there
|
|
591 // this search MUST be made case insensitive (DONE).
|
|
592 // Also, some check to find out if we
|
|
593 // are looking at the boundary associated with content-type, and that the content
|
|
594 // type really is "multipart"
|
|
595 if ((b2 = my_stristr(item->email->header, "boundary=")) != NULL) {
|
|
596 b2 += strlen("boundary="); // move boundary to first char of marker
|
|
597
|
|
598 if (*b2 == '"') {
|
|
599 b2++;
|
|
600 b1 = strchr(b2, '"'); // find terminating quote
|
|
601 } else {
|
|
602 b1 = b2;
|
|
603 while (isgraph(*b1)) // find first char that isn't part of boundary
|
|
604 b1++;
|
|
605 }
|
|
606
|
|
607 boundary = malloc ((b1-b2)+1); //malloc that length
|
|
608 memset (boundary, 0, (b1-b2)+1); // blank it
|
|
609 strncpy(boundary, b2, b1-b2); // copy boundary to another variable
|
|
610 b1 = b2 = boundary;
|
|
611 while (*b2 != '\0') { // remove any CRs and Tabs
|
|
612 if (*b2 != '\n' && *b2 != '\r' && *b2 != '\t') {
|
|
613 *b1 = *b2;
|
|
614 b1++;
|
|
615 }
|
|
616 b2++;
|
|
617 }
|
|
618 *b1 = '\0';
|
|
619
|
|
620 DEBUG_MAIN(("main: Found boundary of - %s\n", boundary));
|
|
621 } else {
|
|
622
|
|
623 DEBUG_MAIN(("main: boundary not found in header\n"));
|
|
624 }
|
|
625
|
|
626 // also possible to set 7bit encoding detection here.
|
|
627 if ((b2 = my_stristr(item->email->header, "Content-Transfer-Encoding:")) != NULL) {
|
|
628 if ((b2 = strchr(b2, ':')) != NULL) {
|
|
629 b2++; // skip to the : at the end of the string
|
|
630
|
|
631 while (*b2 == ' ' || *b2 == '\t')
|
|
632 b2++;
|
|
633 if (pst_strincmp(b2, "base64", 6)==0) {
|
|
634 DEBUG_MAIN(("body is base64 encoded\n"));
|
|
635 base64_body = 1;
|
|
636 }
|
|
637 } else {
|
|
638 DEBUG_WARN(("found a ':' during the my_stristr, but not after that..\n"));
|
|
639 }
|
|
640 }
|
|
641
|
|
642 }
|
|
643
|
|
644 DEBUG_MAIN(("main: About to print Header\n"));
|
|
645
|
|
646 if (item != NULL && item->email != NULL && item->email->subject != NULL &&
|
|
647 item->email->subject->subj != NULL) {
|
|
648 DEBUG_EMAIL(("item->email->subject->subj = %p\n", item->email->subject->subj));
|
|
649 }
|
|
650 if (item->email->header != NULL) {
|
|
651 // some of the headers we get from the file are not properly defined.
|
|
652 // they can contain some email stuff too. We will cut off the header
|
|
653 // when we see a \n\n or \r\n\r\n
|
|
654
|
|
655 removeCR(item->email->header);
|
|
656
|
|
657 temp = strstr(item->email->header, "\n\n");
|
|
658
|
|
659 if (temp != NULL) {
|
|
660 DEBUG_MAIN(("main: Found body text in header\n"));
|
|
661 *temp = '\0';
|
|
662 }
|
|
663
|
|
664 if (mode != MODE_SEPERATE) {
|
|
665 char *soh = NULL; // real start of headers.
|
|
666 // don't put rubbish in if we are doing seperate
|
|
667 fprintf(f->output, "From \"%s\" %s\n", item->email->outlook_sender_name, c_time);
|
|
668 soh = skip_header_prologue(item->email->header);
|
|
669 fprintf(f->output, "%s\n", soh);
|
|
670 } else {
|
|
671 fprintf(f->output, "%s", item->email->header);
|
|
672 }
|
|
673 } else {
|
|
674 //make up our own header!
|
|
675 if (mode != MODE_SEPERATE) {
|
|
676 // don't want this first line for this mode
|
|
677 if (item->email->outlook_sender_name != NULL) {
|
|
678 temp = item->email->outlook_sender_name;
|
|
679 } else {
|
|
680 temp = "(readpst_null)";
|
|
681 }
|
|
682 fprintf(f->output, "From \"%s\" %s\n", temp, c_time);
|
|
683 }
|
|
684 if ((temp = item->email->outlook_sender) == NULL)
|
|
685 temp = "";
|
|
686 fprintf(f->output, "From: \"%s\" <%s>\n", item->email->outlook_sender_name, temp);
|
|
687 if (item->email->subject != NULL) {
|
|
688 fprintf(f->output, "Subject: %s\n", item->email->subject->subj);
|
|
689 } else {
|
|
690 fprintf(f->output, "Subject: \n");
|
|
691 }
|
|
692 fprintf(f->output, "To: %s\n", item->email->sentto_address);
|
|
693 if (item->email->cc_address != NULL) {
|
|
694 fprintf(f->output, "Cc: %s\n", item->email->cc_address);
|
|
695 }
|
|
696 if (item->email->sent_date != NULL) {
|
|
697 c_time = (char*) xmalloc(C_TIME_SIZE);
|
|
698 strftime(c_time, C_TIME_SIZE, "%a, %d %b %Y %H:%M:%S %z", gmtime(&em_time));
|
|
699 fprintf(f->output, "Date: %s\n", c_time);
|
|
700 free(c_time);
|
|
701 }
|
|
702
|
|
703 fprintf(f->output, "MIME-Version: 1.0\n");
|
|
704 }
|
|
705 if (boundary == NULL && (item->attach ||(item->email->body && item->email->htmlbody)
|
|
706 || item->email->rtf_compressed || item->email->encrypted_body
|
|
707 || item->email->encrypted_htmlbody)) {
|
|
708 // we need to create a boundary here.
|
|
709 DEBUG_EMAIL(("main: must create own boundary. oh dear.\n"));
|
|
710 boundary = malloc(50 * sizeof(char)); // allow 50 chars for boundary
|
|
711 boundary[0] = '\0';
|
|
712 sprintf(boundary, "--boundary-LibPST-iamunique-%i_-_-", rand());
|
|
713 DEBUG_EMAIL(("main: created boundary is %s\n", boundary));
|
|
714
|
|
715 /* If boundary != NULL, then it'll already be printed with existing
|
|
716 * headers. Otherwise, we generate it here, and print it.
|
|
717 */
|
|
718 if (item->attach != NULL) {
|
|
719 // write the boundary stuff if we have attachments
|
|
720 fprintf(f->output, "Content-type: multipart/mixed;\n\tboundary=\"%s\"\n",
|
|
721 boundary);
|
|
722 } else if (boundary != NULL) {
|
|
723 // else if we have multipart/alternative then tell it so
|
|
724 fprintf(f->output, "Content-type: multipart/alternative;\n\tboundary=\"%s\"\n",
|
|
725 boundary);
|
|
726 } else if (item->email->htmlbody) {
|
|
727 fprintf(f->output, "Content-type: text/html\n");
|
|
728 }
|
|
729 }
|
|
730 fprintf(f->output, "\n");
|
|
731
|
|
732 DEBUG_MAIN(("main: About to print Body\n"));
|
|
733
|
|
734 if (item->email->body != NULL) {
|
|
735 if (boundary) {
|
|
736 fprintf(f->output, "\n--%s\n", boundary);
|
|
737 fprintf(f->output, "Content-type: text/plain\n");
|
|
738 if (base64_body) fprintf(f->output, "Content-Transfer-Encoding: base64\n");
|
|
739 fprintf(f->output, "\n");
|
|
740 }
|
|
741 removeCR(item->email->body);
|
|
742 if (base64_body)
|
|
743 write_email_body(f->output, base64_encode(item->email->body,
|
|
744 strlen(item->email->body)));
|
|
745 else
|
|
746 write_email_body(f->output, item->email->body);
|
|
747 }
|
|
748
|
|
749 if (item->email->htmlbody != NULL) {
|
|
750 if (boundary) {
|
|
751 fprintf(f->output, "\n--%s\n", boundary);
|
|
752 fprintf(f->output, "Content-type: text/html\n");
|
|
753 if (base64_body) fprintf(f->output, "Content-Transfer-Encoding: base64\n");
|
|
754 fprintf(f->output, "\n");
|
|
755 }
|
|
756 removeCR(item->email->htmlbody);
|
|
757 if (base64_body)
|
|
758 write_email_body(f->output, base64_encode(item->email->htmlbody,
|
|
759 strlen(item->email->htmlbody)));
|
|
760 else
|
|
761 write_email_body(f->output, item->email->htmlbody);
|
|
762 }
|
|
763
|
|
764 attach_num = 0;
|
|
765
|
|
766 if (item->email->rtf_compressed != NULL) {
|
|
767 DEBUG_MAIN(("Adding RTF body as attachment\n"));
|
|
768 item->current_attach = (pst_item_attach*)xmalloc(sizeof(pst_item_attach));
|
|
769 memset(item->current_attach, 0, sizeof(pst_item_attach));
|
|
770 item->current_attach->next = item->attach;
|
|
771 item->attach = item->current_attach;
|
|
772 item->current_attach->data = lzfu_decompress(item->email->rtf_compressed);
|
|
773 item->current_attach->filename2 = xmalloc(strlen(RTF_ATTACH_NAME)+2);
|
|
774 strcpy(item->current_attach->filename2, RTF_ATTACH_NAME);
|
|
775 item->current_attach->mimetype = xmalloc(strlen(RTF_ATTACH_TYPE)+2);
|
|
776 strcpy(item->current_attach->mimetype, RTF_ATTACH_TYPE);
|
|
777 memcpy(&(item->current_attach->size), item->email->rtf_compressed+sizeof(int32_t), sizeof(int32_t));
|
|
778 LE32_CPU(item->current_attach->size);
|
|
779 // item->email->rtf_compressed = ;
|
|
780 // attach_num++;
|
|
781 }
|
|
782 if (item->email->encrypted_body || item->email->encrypted_htmlbody) {
|
|
783 // if either the body or htmlbody is encrypted, add them as attachments
|
|
784 if (item->email->encrypted_body) {
|
|
785 DEBUG_MAIN(("Adding Encrypted Body as attachment\n"));
|
|
786 item->current_attach = (pst_item_attach*) xmalloc(sizeof(pst_item_attach));
|
|
787 memset(item->current_attach, 0, sizeof(pst_item_attach));
|
|
788 item->current_attach->next = item->attach;
|
|
789 item->attach = item->current_attach;
|
|
790
|
|
791 item->current_attach->data = item->email->encrypted_body;
|
|
792 item->current_attach->size = item->email->encrypted_body_size;
|
|
793 item->email->encrypted_body = NULL;
|
|
794 }
|
|
795 if (item->email->encrypted_htmlbody) {
|
|
796 DEBUG_MAIN(("Adding encrypted HTML body as attachment\n"));
|
|
797 item->current_attach = (pst_item_attach*) xmalloc(sizeof(pst_item_attach));
|
|
798 memset(item->current_attach, 0, sizeof(pst_item_attach));
|
|
799 item->current_attach->next = item->attach;
|
|
800 item->attach = item->current_attach;
|
|
801
|
|
802 item->current_attach->data = item->email->encrypted_htmlbody;
|
|
803 item->current_attach->size = item->email->encrypted_htmlbody_size;
|
|
804 item->email->encrypted_htmlbody = NULL;
|
|
805 }
|
|
806 write_email_body(f->output, "The body of this email is encrypted. This isn't supported yet, but the body is now an attachment\n");
|
|
807 }
|
|
808 base64_body = 0;
|
|
809 // attachments
|
|
810 item->current_attach = item->attach;
|
|
811 while (item->current_attach != NULL) {
|
|
812 DEBUG_MAIN(("main: Attempting Attachment encoding\n"));
|
|
813 if (item->current_attach->data == NULL) {
|
|
814 DEBUG_MAIN(("main: Data of attachment is NULL!. Size is supposed to be %i\n", item->current_attach->size));
|
|
815 }
|
|
816 if (mode == MODE_SEPERATE) {
|
|
817 f->name = check_filename(f->name);
|
|
818 if (item->current_attach->filename2 == NULL) {
|
|
819 temp = xmalloc(strlen(f->name)+15);
|
|
820 sprintf(temp, "%s-attach%i", f->name, attach_num);
|
|
821 } else {
|
|
822 temp = xmalloc(strlen(f->name)+strlen(item->current_attach->filename2)+15);
|
|
823 fp = NULL; x=0;
|
|
824 do {
|
|
825 if (fp != NULL) fclose(fp);
|
|
826 if (x == 0)
|
|
827 sprintf(temp, "%s-%s", f->name, item->current_attach->filename2);
|
|
828 else
|
|
829 sprintf(temp, "%s-%s-%i", f->name, item->current_attach->filename2, x);
|
|
830 } while ((fp = fopen(temp, "r"))!=NULL && ++x < 99999999);
|
|
831 if (x > 99999999) {
|
|
832 DIE(("error finding attachment name. exhausted possibilities to %s\n", temp));
|
|
833 }
|
|
834 }
|
|
835 DEBUG_MAIN(("main: Saving attachment to %s\n", temp));
|
|
836 if ((fp = fopen(temp, "w")) == NULL) {
|
|
837 WARN(("main: Cannot open attachment save file \"%s\"\n", temp));
|
|
838 } else {
|
|
839 if (item->current_attach->data != NULL)
|
|
840 fwrite(item->current_attach->data, 1, item->current_attach->size, fp);
|
|
841 else {
|
|
842 pst_attach_to_file(&pstfile, item->current_attach, fp);
|
|
843 }
|
|
844 fclose(fp);
|
|
845 }
|
|
846 } else {
|
|
847 DEBUG_MAIN(("main: Attachment Size is %i\n", item->current_attach->size));
|
|
848 DEBUG_MAIN(("main: Attachment Pointer is %p\n", item->current_attach->data));
|
|
849 if (item->current_attach->data != NULL) {
|
|
850 if ((enc = base64_encode (item->current_attach->data, item->current_attach->size)) == NULL) {
|
|
851 DEBUG_MAIN(("main: ERROR base64_encode returned NULL. Must have failed\n"));
|
|
852 item->current_attach = item->current_attach->next;
|
|
853 continue;
|
|
854 }
|
|
855 }
|
|
856 if (boundary) {
|
|
857 fprintf(f->output, "\n--%s\n", boundary);
|
|
858 if (item->current_attach->mimetype == NULL) {
|
|
859 fprintf(f->output, "Content-type: %s\n", MIME_TYPE_DEFAULT);
|
|
860 } else {
|
|
861 fprintf(f->output, "Content-type: %s\n", item->current_attach->mimetype);
|
|
862 }
|
|
863 fprintf(f->output, "Content-transfer-encoding: base64\n");
|
|
864 if (item->current_attach->filename2 == NULL) {
|
|
865 fprintf(f->output, "Content-Disposition: inline\n\n");
|
|
866 } else {
|
|
867 fprintf(f->output, "Content-Disposition: attachment; filename=\"%s\"\n\n",
|
|
868 item->current_attach->filename2);
|
|
869 }
|
|
870 }
|
|
871 if (item->current_attach->data != NULL) {
|
|
872 fwrite(enc, 1, strlen(enc), f->output);
|
|
873 DEBUG_MAIN(("Attachment Size after encoding is %i\n", strlen(enc)));
|
|
874 } else {
|
|
875 pst_attach_to_file_base64(&pstfile, item->current_attach, f->output);
|
|
876 }
|
|
877 fprintf(f->output, "\n\n");
|
|
878 }
|
|
879 item->current_attach = item->current_attach->next;
|
|
880 attach_num++;
|
|
881 }
|
|
882 if (mode != MODE_SEPERATE) {
|
|
883 DEBUG_MAIN(("main: Writing buffer between emails\n"));
|
|
884 if (boundary)
|
|
885 fprintf(f->output, "\n--%s--\n", boundary);
|
|
886 fprintf(f->output, "\n\n");
|
|
887 }
|
|
888 } else if (item->type == PST_TYPE_JOURNAL) {
|
|
889 // deal with journal items
|
|
890 if (mode == MODE_SEPERATE) {
|
|
891 mk_seperate_file(f);
|
|
892 }
|
|
893 f->email_count++;
|
|
894
|
|
895 DEBUG_MAIN(("main: Processing Journal Entry\n"));
|
|
896 if (f->type != PST_TYPE_JOURNAL) {
|
|
897 DEBUG_MAIN(("main: I have a journal entry, but folder isn't specified as a journal type. Processing...\n"));
|
|
898 }
|
|
899
|
|
900 /* if (item->type != PST_TYPE_JOURNAL) {
|
|
901 DEBUG_MAIN(("main: I have an item with journal info, but it's type is \"%s\" \n. Processing...\n",
|
|
902 item->ascii_type));
|
|
903 }*/
|
|
904 fprintf(f->output, "BEGIN:VJOURNAL\n");
|
|
905 if (item->email->subject != NULL)
|
|
906 fprintf(f->output, "SUMMARY:%s\n", rfc2426_escape(item->email->subject->subj));
|
|
907 if (item->email->body != NULL)
|
|
908 fprintf(f->output, "DESCRIPTION:%s\n", rfc2426_escape(item->email->body));
|
|
909 if (item->journal->start != NULL)
|
|
910 fprintf(f->output, "DTSTART;VALUE=DATE-TIME:%s\n", rfc2445_datetime_format(item->journal->start));
|
|
911 fprintf(f->output, "END:VJOURNAL\n\n");
|
|
912 } else if (item->type == PST_TYPE_APPOINTMENT) {
|
|
913 // deal with Calendar appointments
|
|
914 if (mode == MODE_SEPERATE) {
|
|
915 mk_seperate_file(f);
|
|
916 }
|
|
917 f->email_count++;
|
|
918
|
|
919 DEBUG_MAIN(("main: Processing Appointment Entry\n"));
|
|
920 if (f->type != PST_TYPE_APPOINTMENT) {
|
|
921 DEBUG_MAIN(("main: I have an appointment, but folder isn't specified as an appointment type. Processing...\n"));
|
|
922 }
|
|
923 fprintf(f->output, "BEGIN:VEVENT\n");
|
|
924 if (item->create_date != NULL)
|
|
925 fprintf(f->output, "CREATED:%s\n", rfc2445_datetime_format(item->create_date));
|
|
926 if (item->modify_date != NULL)
|
|
927 fprintf(f->output, "LAST-MOD:%s\n", rfc2445_datetime_format(item->modify_date));
|
|
928 if (item->email != NULL && item->email->subject != NULL)
|
|
929 fprintf(f->output, "SUMMARY:%s\n", rfc2426_escape(item->email->subject->subj));
|
|
930 if (item->email != NULL && item->email->body != NULL)
|
|
931 fprintf(f->output, "DESCRIPTION:%s\n", rfc2426_escape(item->email->body));
|
|
932 if (item->appointment != NULL && item->appointment->start != NULL)
|
|
933 fprintf(f->output, "DTSTART;VALUE=DATE-TIME:%s\n", rfc2445_datetime_format(item->appointment->start));
|
|
934 if (item->appointment != NULL && item->appointment->end != NULL)
|
|
935 fprintf(f->output, "DTEND;VALUE=DATE-TIME:%s\n", rfc2445_datetime_format(item->appointment->end));
|
|
936 if (item->appointment != NULL && item->appointment->location != NULL)
|
|
937 fprintf(f->output, "LOCATION:%s\n", rfc2426_escape(item->appointment->location));
|
|
938 if (item->appointment != NULL) {
|
|
939 switch (item->appointment->showas) {
|
|
940 case PST_FREEBUSY_TENTATIVE:
|
|
941 fprintf(f->output, "STATUS:TENTATIVE\n");
|
|
942 break;
|
|
943 case PST_FREEBUSY_FREE:
|
|
944 // mark as transparent and as confirmed
|
|
945 fprintf(f->output, "TRANSP:TRANSPARENT\n");
|
|
946 case PST_FREEBUSY_BUSY:
|
|
947 case PST_FREEBUSY_OUT_OF_OFFICE:
|
|
948 fprintf(f->output, "STATUS:CONFIRMED\n");
|
|
949 break;
|
|
950 }
|
|
951 switch (item->appointment->label) {
|
|
952 case PST_APP_LABEL_NONE:
|
|
953 fprintf(f->output, "CATEGORIES:NONE\n"); break;
|
|
954 case PST_APP_LABEL_IMPORTANT:
|
|
955 fprintf(f->output, "CATEGORIES:IMPORTANT\n"); break;
|
|
956 case PST_APP_LABEL_BUSINESS:
|
|
957 fprintf(f->output, "CATEGORIES:BUSINESS\n"); break;
|
|
958 case PST_APP_LABEL_PERSONAL:
|
|
959 fprintf(f->output, "CATEGORIES:PERSONAL\n"); break;
|
|
960 case PST_APP_LABEL_VACATION:
|
|
961 fprintf(f->output, "CATEGORIES:VACATION\n"); break;
|
|
962 case PST_APP_LABEL_MUST_ATTEND:
|
|
963 fprintf(f->output, "CATEGORIES:MUST-ATTEND\n"); break;
|
|
964 case PST_APP_LABEL_TRAVEL_REQ:
|
|
965 fprintf(f->output, "CATEGORIES:TRAVEL-REQUIRED\n"); break;
|
|
966 case PST_APP_LABEL_NEEDS_PREP:
|
|
967 fprintf(f->output, "CATEGORIES:NEEDS-PREPARATION\n"); break;
|
|
968 case PST_APP_LABEL_BIRTHDAY:
|
|
969 fprintf(f->output, "CATEGORIES:BIRTHDAY\n"); break;
|
|
970 case PST_APP_LABEL_ANNIVERSARY:
|
|
971 fprintf(f->output, "CATEGORIES:ANNIVERSARY\n"); break;
|
|
972 case PST_APP_LABEL_PHONE_CALL:
|
|
973 fprintf(f->output, "CATEGORIES:PHONE-CALL\n"); break;
|
|
974 }
|
|
975 }
|
|
976 fprintf(f->output, "END:VEVENT\n\n");
|
|
977 } else {
|
|
978 f->skip_count++;
|
|
979 DEBUG_MAIN(("main: Unknown item type. %i. Ascii1=\"%s\"\n",
|
|
980 item->type, item->ascii_type));
|
|
981 }
|
|
982 } else {
|
|
983 f->skip_count++;
|
|
984 DEBUG_MAIN(("main: A NULL item was seen\n"));
|
|
985 }
|
|
986
|
|
987 DEBUG_MAIN(("main: Going to next d_ptr\n"));
|
|
988 if (boundary) {
|
|
989 free(boundary);
|
|
990 boundary = NULL;
|
|
991 }
|
|
992
|
|
993 check_parent:
|
|
994 // _pst_freeItem(item);
|
|
995 while (!skip_child && d_ptr->next == NULL && d_ptr->parent != NULL) {
|
|
996 DEBUG_MAIN(("main: Going to Parent\n"));
|
|
997 head = f->next;
|
|
998 if (f->output != NULL)
|
|
999 fclose(f->output);
|
|
1000 DEBUG_MAIN(("main: Email Count for folder %s is %i\n", f->dname, f->email_count));
|
|
1001 if (output_mode != OUTPUT_QUIET)
|
|
1002 printf("\t\"%s\" - %i items done, skipped %i, should have been %i\n",
|
|
1003 f->dname, f->email_count, f->skip_count, f->stored_count);
|
|
1004 if (mode == MODE_KMAIL)
|
|
1005 close_kmail_dir();
|
|
1006 else if (mode == MODE_RECURSE)
|
|
1007 close_recurse_dir();
|
|
1008 else if (mode == MODE_SEPERATE)
|
|
1009 close_seperate_dir();
|
|
1010 free(f->name);
|
|
1011 free(f->dname);
|
|
1012 free(f);
|
|
1013 f = head;
|
|
1014 if (head == NULL) { //we can't go higher. Must be at start?
|
|
1015 DEBUG_MAIN(("main: We are now trying to go above the highest level. We must be finished\n"));
|
|
1016 break; //from main while loop
|
|
1017 }
|
|
1018 d_ptr = d_ptr->parent;
|
|
1019 skip_child = 0;
|
|
1020 }
|
|
1021
|
|
1022 if (item != NULL) {
|
|
1023 DEBUG_MAIN(("main: Freeing memory used by item\n"));
|
|
1024 _pst_freeItem(item);
|
|
1025 item = NULL;
|
|
1026 }
|
|
1027
|
|
1028 if (!skip_child)
|
|
1029 d_ptr = d_ptr->next;
|
|
1030 else
|
|
1031 skip_child = 0;
|
|
1032
|
|
1033 if (d_ptr == NULL) {
|
|
1034 DEBUG_MAIN(("main: d_ptr is now NULL\n"));
|
|
1035 }
|
|
1036 }
|
|
1037 if (output_mode != OUTPUT_QUIET) printf("Finished.\n");
|
|
1038 DEBUG_MAIN(("main: Finished.\n"));
|
|
1039
|
|
1040 pst_close(&pstfile);
|
|
1041 // fclose(pstfile.fp);
|
|
1042 while (f != NULL) {
|
|
1043 if (f->output != NULL)
|
|
1044 fclose(f->output);
|
|
1045 free(f->name);
|
|
1046 free(f->dname);
|
|
1047
|
|
1048 if (mode == MODE_KMAIL)
|
|
1049 close_kmail_dir();
|
|
1050 else if (mode == MODE_RECURSE)
|
|
1051 close_recurse_dir();
|
|
1052 else if (mode == MODE_SEPERATE)
|
|
1053 // DO SOMETHING HERE
|
|
1054 ;
|
|
1055 head = f->next;
|
|
1056 free (f);
|
|
1057 f = head;
|
|
1058 }
|
|
1059
|
|
1060 DEBUG_RET();
|
|
1061
|
|
1062 return 0;
|
|
1063 }
|
|
1064 void write_email_body(FILE *f, char *body) {
|
|
1065 char *n = body;
|
|
1066 // DEBUG_MAIN(("write_email_body(): \"%s\"\n", body));
|
|
1067 DEBUG_ENT("write_email_body");
|
|
1068 while (n != NULL) {
|
|
1069 if (strncmp(body, "From ", 5) == 0)
|
|
1070 fprintf(f, ">");
|
|
1071 if ((n = strchr(body, '\n'))) {
|
|
1072 n++;
|
|
1073 fwrite(body, n-body, 1, f); //write just a line
|
|
1074
|
|
1075 body = n;
|
|
1076 }
|
|
1077 }
|
|
1078 fwrite(body, strlen(body), 1, f);
|
|
1079 DEBUG_RET();
|
|
1080 }
|
|
1081 char *removeCR (char *c) {
|
|
1082 // converts /r/n to /n
|
|
1083 char *a, *b;
|
|
1084 DEBUG_ENT("removeCR");
|
|
1085 a = b = c;
|
|
1086 while (*a != '\0') {
|
|
1087 *b = *a;
|
|
1088 if (*a != '\r')
|
|
1089 b++;
|
|
1090 a++;
|
|
1091 }
|
|
1092 *b = '\0';
|
|
1093 DEBUG_RET();
|
|
1094 return c;
|
|
1095 }
|
|
1096 int usage() {
|
|
1097 DEBUG_ENT("usage");
|
|
1098 version();
|
|
1099 printf("Usage: %s [OPTIONS] {PST FILENAME}\n", prog_name);
|
|
1100 printf("OPTIONS:\n");
|
|
1101 printf("\t-c[v|l]\t- Set the Contact output mode. -cv = VCard, -cl = EMail list\n");
|
|
1102 printf("\t-d\t- Debug to file. This is a binary log. Use readlog to print it\n");
|
|
1103 printf("\t-h\t- Help. This screen\n");
|
|
1104 printf("\t-k\t- KMail. Output in kmail format\n");
|
|
1105 printf("\t-o\t- Output Dir. Directory to write files to. CWD is changed *after* opening pst file\n");
|
|
1106 printf("\t-q\t- Quiet. Only print error messages\n");
|
|
1107 printf("\t-r\t- Recursive. Output in a recursive format\n");
|
|
1108 printf("\t-S\t- Seperate. Write emails in the seperate format\n");
|
|
1109 printf("\t-V\t- Version. Display program version\n");
|
|
1110 printf("\t-w\t- Overwrite any output mbox files\n");
|
|
1111 DEBUG_RET();
|
|
1112 return 0;
|
|
1113 }
|
|
1114 int version() {
|
|
1115 DEBUG_ENT("version");
|
|
1116 printf("ReadPST v%s\n", VERSION);
|
|
1117 #if BYTE_ORDER == BIG_ENDIAN
|
|
1118 printf("Big Endian implementation being used.\n");
|
|
1119 #elif BYTE_ORDER == LITTLE_ENDIAN
|
|
1120 printf("Little Endian implementation being used.\n");
|
|
1121 #else
|
|
1122 # error "Byte order not supported by this library"
|
|
1123 #endif
|
|
1124 #ifdef __GNUC__
|
|
1125 printf("GCC %d.%d : %s %s\n", __GNUC__, __GNUC_MINOR__, __DATE__, __TIME__);
|
|
1126 #endif
|
|
1127 DEBUG_RET();
|
|
1128 return 0;
|
|
1129 }
|
|
1130 char *mk_kmail_dir(char *fname) {
|
|
1131 //change to that directory
|
|
1132 //make a directory based on OUTPUT_KMAIL_DIR_TEMPLATE
|
|
1133 //allocate space for OUTPUT_TEMPLATE and form a char* with fname
|
|
1134 //return that value
|
|
1135 char *dir, *out_name, *index;
|
|
1136 int x;
|
|
1137 DEBUG_ENT("mk_kmail_dir");
|
|
1138 if (kmail_chdir != NULL && chdir(kmail_chdir)) {
|
|
1139 x = errno;
|
|
1140 DIE(("mk_kmail_dir: Cannot change to directory %s: %s\n", kmail_chdir, strerror(x)));
|
|
1141 }
|
|
1142 dir = malloc(strlen(fname)+strlen(OUTPUT_KMAIL_DIR_TEMPLATE)+1);
|
|
1143 sprintf(dir, OUTPUT_KMAIL_DIR_TEMPLATE, fname);
|
|
1144 dir = check_filename(dir);
|
|
1145 if (D_MKDIR(dir)) {
|
|
1146 //error occured
|
|
1147 if (errno != EEXIST) {
|
|
1148 x = errno;
|
|
1149 DIE(("mk_kmail_dir: Cannot create directory %s: %s\n", dir, strerror(x)));
|
|
1150 }
|
|
1151 }
|
|
1152 kmail_chdir = realloc(kmail_chdir, strlen(dir)+1);
|
|
1153 strcpy(kmail_chdir, dir);
|
|
1154 free (dir);
|
|
1155
|
|
1156 //we should remove any existing indexes created by KMail, cause they might be different now
|
|
1157 index = malloc(strlen(fname)+strlen(KMAIL_INDEX)+1);
|
|
1158 sprintf(index, KMAIL_INDEX, fname);
|
|
1159 unlink(index);
|
|
1160 free(index);
|
|
1161
|
|
1162 out_name = malloc(strlen(fname)+strlen(OUTPUT_TEMPLATE)+1);
|
|
1163 sprintf(out_name, OUTPUT_TEMPLATE, fname);
|
|
1164 DEBUG_RET();
|
|
1165 return out_name;
|
|
1166 }
|
|
1167 int close_kmail_dir() {
|
|
1168 // change ..
|
|
1169 int x;
|
|
1170 DEBUG_ENT("close_kmail_dir");
|
|
1171 if (kmail_chdir != NULL) { //only free kmail_chdir if not NULL. do not change directory
|
|
1172 free(kmail_chdir);
|
|
1173 kmail_chdir = NULL;
|
|
1174 } else {
|
|
1175 if (chdir("..")) {
|
|
1176 x = errno;
|
|
1177 DIE(("close_kmail_dir: Cannot move up dir (..): %s\n", strerror(x)));
|
|
1178 }
|
|
1179 }
|
|
1180 DEBUG_RET();
|
|
1181 return 0;
|
|
1182 }
|
|
1183 // this will create a directory by that name, then make an mbox file inside
|
|
1184 // that dir. any subsequent dirs will be created by name, and they will
|
|
1185 // contain mbox files
|
|
1186 char *mk_recurse_dir(char *dir) {
|
|
1187 int x;
|
|
1188 char *out_name;
|
|
1189 DEBUG_ENT("mk_recurse_dir");
|
|
1190 dir = check_filename(dir);
|
|
1191 if (D_MKDIR (dir)) {
|
|
1192 if (errno != EEXIST) { // not an error because it exists
|
|
1193 x = errno;
|
|
1194 DIE(("mk_recurse_dir: Cannot create directory %s: %s\n", dir, strerror(x)));
|
|
1195 }
|
|
1196 }
|
|
1197 if (chdir (dir)) {
|
|
1198 x = errno;
|
|
1199 DIE(("mk_recurse_dir: Cannot change to directory %s: %s\n", dir, strerror(x)));
|
|
1200 }
|
|
1201 out_name = malloc(strlen("mbox")+1);
|
|
1202 strcpy(out_name, "mbox");
|
|
1203 DEBUG_RET();
|
|
1204 return out_name;
|
|
1205 }
|
|
1206 int close_recurse_dir() {
|
|
1207 int x;
|
|
1208 DEBUG_ENT("close_recurse_dir");
|
|
1209 if (chdir("..")) {
|
|
1210 x = errno;
|
|
1211 DIE(("close_recurse_dir: Cannot go up dir (..): %s\n", strerror(x)));
|
|
1212 }
|
|
1213 DEBUG_RET();
|
|
1214 return 0;
|
|
1215 }
|
|
1216 char *mk_seperate_dir(char *dir, int overwrite) {
|
|
1217 #if !defined(WIN32) && !defined(__CYGWIN__)
|
|
1218 DIR * sdir = NULL;
|
|
1219 struct dirent *dirent = NULL;
|
|
1220 struct stat *filestat = xmalloc(sizeof(struct stat));
|
|
1221 #endif
|
|
1222
|
|
1223 char *dir_name = NULL;
|
|
1224 int x = 0, y = 0;
|
|
1225 DEBUG_ENT("mk_seperate_dir");
|
|
1226 /*#if defined(WIN32) || defined(__CYGWIN__)
|
|
1227 DIE(("mk_seperate_dir: Win32 applications cannot use this function yet.\n"));
|
|
1228 #endif*/
|
|
1229
|
|
1230 dir_name = xmalloc(strlen(dir)+10);
|
|
1231
|
|
1232 do {
|
|
1233 if (y == 0)
|
|
1234 sprintf(dir_name, "%s", dir);
|
|
1235 else
|
|
1236 sprintf(dir_name, "%s%09i", dir, y); // enough for 9 digits allocated above
|
|
1237
|
|
1238 dir_name = check_filename(dir_name);
|
|
1239 DEBUG_MAIN(("mk_seperate_dir: about to try creating %s\n", dir_name));
|
|
1240 if (D_MKDIR(dir_name)) {
|
|
1241 if (errno != EEXIST) { // if there is an error, and it doesn't already exist
|
|
1242 x = errno;
|
|
1243 DIE(("mk_seperate_dir: Cannot create directory %s: %s\n", dir, strerror(x)));
|
|
1244 }
|
|
1245 } else {
|
|
1246 break;
|
|
1247 }
|
|
1248 y++;
|
|
1249 } while (overwrite == 0);
|
|
1250
|
|
1251 if (chdir (dir_name)) {
|
|
1252 x = errno;
|
|
1253 DIE(("mk_recurse_dir: Cannot change to directory %s: %s\n", dir, strerror(x)));
|
|
1254 }
|
|
1255
|
|
1256 if (overwrite) {
|
|
1257 // we should probably delete all files from this directory
|
|
1258 #if !defined(WIN32) && !defined(__CYGWIN__)
|
|
1259 if ((sdir = opendir("./")) == NULL) {
|
|
1260 WARN(("mk_seperate_dir: Cannot open dir \"%s\" for deletion of old contents\n", "./"));
|
|
1261 } else {
|
|
1262 while ((dirent = readdir(sdir)) != NULL) {
|
|
1263 if (lstat(dirent->d_name, filestat) != -1)
|
|
1264 if (S_ISREG(filestat->st_mode)) {
|
|
1265 if (unlink(dirent->d_name)) {
|
|
1266 y = errno;
|
|
1267 DIE(("mk_seperate_dir: unlink returned error on file %s: %s\n", dirent->d_name, strerror(y)));
|
|
1268 }
|
|
1269 }
|
|
1270 }
|
|
1271 }
|
|
1272 #endif
|
|
1273 }
|
|
1274
|
|
1275 // overwrite will never change during this function, it is just there so that
|
|
1276 // if overwrite is set, we only go through this loop once.
|
|
1277
|
|
1278 // we don't return a filename here cause it isn't necessary.
|
|
1279 DEBUG_RET();
|
|
1280 return NULL;
|
|
1281 }
|
|
1282 int close_seperate_dir() {
|
|
1283 int x;
|
|
1284 DEBUG_ENT("close_seperate_dir");
|
|
1285 if (chdir("..")) {
|
|
1286 x = errno;
|
|
1287 DIE(("close_seperate_dir: Cannot go up dir (..): %s\n", strerror(x)));
|
|
1288 }
|
|
1289 DEBUG_RET();
|
|
1290 return 0;
|
|
1291 }
|
|
1292 int mk_seperate_file(struct file_ll *f) {
|
|
1293 DEBUG_ENT("mk_seperate_file");
|
|
1294 DEBUG_MAIN(("mk_seperate_file: opening next file to save email\n"));
|
|
1295 if (f->email_count > 999999999) { // bigger than nine 9's
|
|
1296 DIE(("mk_seperate_file: The number of emails in this folder has become too high to handle"));
|
|
1297 }
|
|
1298 sprintf(f->name, "%09i", f->email_count);
|
|
1299 if (f->output != NULL)
|
|
1300 fclose(f->output);
|
|
1301 f->output = NULL;
|
|
1302 f->name = check_filename(f->name);
|
|
1303 if ((f->output = fopen(f->name, "w")) == NULL) {
|
|
1304 DIE(("mk_seperate_file: Cannot open file to save email \"%s\"\n", f->name));
|
|
1305 }
|
|
1306 DEBUG_RET();
|
|
1307 return 0;
|
|
1308 }
|
|
1309 char *my_stristr(char *haystack, char *needle) {
|
|
1310 // my_stristr varies from strstr in that its searches are case-insensitive
|
|
1311 char *x=haystack, *y=needle, *z = NULL;
|
|
1312 DEBUG_ENT("my_stristr");
|
|
1313 if (haystack == NULL || needle == NULL)
|
|
1314 return NULL;
|
|
1315 while (*y != '\0' && *x != '\0') {
|
|
1316 if (tolower(*y) == tolower(*x)) {
|
|
1317 // move y on one
|
|
1318 y++;
|
|
1319 if (z == NULL) {
|
|
1320 z = x; // store first position in haystack where a match is made
|
|
1321 }
|
|
1322 } else {
|
|
1323 y = needle; // reset y to the beginning of the needle
|
|
1324 z = NULL; // reset the haystack storage point
|
|
1325 }
|
|
1326 x++; // advance the search in the haystack
|
|
1327 }
|
|
1328 DEBUG_RET();
|
|
1329 return z;
|
|
1330 }
|
|
1331 char *check_filename(char *fname) {
|
|
1332 char *t = fname;
|
|
1333 DEBUG_ENT("check_filename");
|
|
1334 if (t == NULL) {
|
|
1335 DEBUG_RET();
|
|
1336 return fname;
|
|
1337 }
|
|
1338 while ((t = strpbrk(t, "/\\:")) != NULL) {
|
|
1339 // while there are characters in the second string that we don't want
|
|
1340 *t = '_'; //replace them with an underscore
|
|
1341 }
|
|
1342 DEBUG_RET();
|
|
1343 return fname;
|
|
1344 }
|
|
1345 char *rfc2426_escape(char *str) {
|
|
1346 static char* buf = NULL;
|
|
1347 char *ret, *a, *b;
|
|
1348 int x = 0, y, z;
|
|
1349 DEBUG_ENT("rfc2426_escape");
|
|
1350 if (str == NULL)
|
|
1351 ret = str;
|
|
1352 else {
|
|
1353
|
|
1354 // calculate space required to escape all the following characters
|
|
1355 x = strlen(str) +(y=(chr_count(str, ',')*2) + (chr_count(str, '\\')*2) + (chr_count(str, ';')*2) + (chr_count(str, '\n')*2));
|
|
1356 z = chr_count(str, '\r');
|
|
1357 if (y == 0 && z == 0)
|
|
1358 // there isn't any extra space required
|
|
1359 ret = str;
|
|
1360 else {
|
|
1361 buf = (char*) realloc(buf, x+1);
|
|
1362 a = str;
|
|
1363 b = buf;
|
|
1364 while (*a != '\0') {
|
|
1365 switch(*a) {
|
|
1366 case ',' :
|
|
1367 case '\\':
|
|
1368 case ';' :
|
|
1369 case '\n':
|
|
1370 *(b++)='\\';
|
|
1371 *b=*a;
|
|
1372 break;
|
|
1373 case '\r':
|
|
1374 break;
|
|
1375 default:
|
|
1376 *b=*a;
|
|
1377 }
|
|
1378 b++;
|
|
1379 a++;
|
|
1380 }
|
|
1381 *b = '\0';
|
|
1382 ret = buf;
|
|
1383 }
|
|
1384 }
|
|
1385 DEBUG_RET();
|
|
1386 return ret;
|
|
1387 }
|
|
1388 int chr_count(char *str, char x) {
|
|
1389 int r = 0;
|
|
1390 while (*str != '\0') {
|
|
1391 if (*str == x)
|
|
1392 r++;
|
|
1393 str++;
|
|
1394 }
|
|
1395 return r;
|
|
1396 }
|
|
1397 char *rfc2425_datetime_format(FILETIME *ft) {
|
|
1398 static char * buffer = NULL;
|
|
1399 struct tm *stm = NULL;
|
|
1400 DEBUG_ENT("rfc2425_datetime_format");
|
|
1401 if (buffer == NULL)
|
|
1402 buffer = malloc(30); // should be enough for the date as defined below
|
|
1403
|
|
1404 stm = fileTimeToStructTM(ft);
|
|
1405 //Year[4]-Month[2]-Day[2] Hour[2]:Min[2]:Sec[2]
|
|
1406 if (strftime(buffer, 30, "%Y-%m-%dT%H:%M:%SZ", stm)==0) {
|
|
1407 DEBUG_INFO(("Problem occured formatting date\n"));
|
|
1408 }
|
|
1409 DEBUG_RET();
|
|
1410 return buffer;
|
|
1411 }
|
|
1412 char *rfc2445_datetime_format(FILETIME *ft) {
|
|
1413 static char* buffer = NULL;
|
|
1414 struct tm *stm = NULL;
|
|
1415 DEBUG_ENT("rfc2445_datetime_format");
|
|
1416 if (buffer == NULL)
|
|
1417 buffer = malloc(30); // should be enough
|
|
1418 stm = fileTimeToStructTM(ft);
|
|
1419 if (strftime(buffer, 30, "%Y%m%dT%H%M%SZ", stm)==0) {
|
|
1420 DEBUG_INFO(("Problem occured formatting date\n"));
|
|
1421 }
|
|
1422 DEBUG_RET();
|
|
1423 return buffer;
|
|
1424 }
|
|
1425 // The sole purpose of this function is to bypass the pseudo-header prologue
|
|
1426 // that Microsoft Outlook inserts at the beginning of the internet email
|
|
1427 // headers for emails stored in their "Personal Folders" files.
|
|
1428 char *skip_header_prologue(char *headers) {
|
|
1429 const char *bad = "Microsoft Mail Internet Headers";
|
|
1430
|
|
1431 if ( strncmp(headers, bad, strlen(bad)) == 0 ) {
|
|
1432 // Found the offensive header prologue
|
|
1433 char *pc;
|
|
1434
|
|
1435 pc = strchr(headers, '\n');
|
|
1436 return pc + 1;
|
|
1437 }
|
|
1438
|
|
1439 return headers;
|
|
1440 }
|
|
1441
|
|
1442 // vim:sw=4 ts=4:
|
|
1443 // vim600: set foldlevel=0 foldmethod=marker:
|