comparison src/readpst.c @ 233:1d50ff3c5091

better rfc822 embedded message decoding
author Carl Byington <carl@five-ten-sg.com>
date Thu, 10 Sep 2009 22:49:24 -0700
parents fe64279df92b
children ed0cb66b23d4
comparison
equal deleted inserted replaced
232:f8dc1b7201ad 233:1d50ff3c5091
272 #endif 272 #endif
273 } 273 }
274 } 274 }
275 275
276 } else if (item->contact && (item->type == PST_TYPE_CONTACT)) { 276 } else if (item->contact && (item->type == PST_TYPE_CONTACT)) {
277 if (!ff.type) ff.type = item->type;
278 DEBUG_INFO(("Processing Contact\n")); 277 DEBUG_INFO(("Processing Contact\n"));
279 if (ff.type != PST_TYPE_CONTACT) { 278 if (!(output_type_mode & OTMODE_CONTACT)) {
280 ff.skip_count++;
281 DEBUG_INFO(("I have a contact, but the folder type %"PRIi32" isn't a contacts folder. Skipping it\n", ff.type));
282 }
283 else if (!(output_type_mode & OTMODE_CONTACT)) {
284 ff.skip_count++; 279 ff.skip_count++;
285 DEBUG_INFO(("skipping contact: not in output type list\n")); 280 DEBUG_INFO(("skipping contact: not in output type list\n"));
286 } 281 }
287 else { 282 else {
288 ff.item_count++; 283 if (!ff.type) ff.type = item->type;
289 if (mode == MODE_SEPARATE) mk_separate_file(&ff); 284 if (ff.type != PST_TYPE_CONTACT) {
290 if (contact_mode == CMODE_VCARD) { 285 ff.skip_count++;
291 pst_convert_utf8_null(item, &item->comment); 286 DEBUG_INFO(("I have a contact, but the folder type %"PRIi32" isn't a contacts folder. Skipping it\n", ff.type));
292 write_vcard(ff.output, item, item->contact, item->comment.str);
293 } 287 }
294 else { 288 else {
295 pst_convert_utf8(item, &item->contact->fullname); 289 ff.item_count++;
296 pst_convert_utf8(item, &item->contact->address1); 290 if (mode == MODE_SEPARATE) mk_separate_file(&ff);
297 fprintf(ff.output, "%s <%s>\n", item->contact->fullname.str, item->contact->address1.str); 291 if (contact_mode == CMODE_VCARD) {
292 pst_convert_utf8_null(item, &item->comment);
293 write_vcard(ff.output, item, item->contact, item->comment.str);
294 }
295 else {
296 pst_convert_utf8(item, &item->contact->fullname);
297 pst_convert_utf8(item, &item->contact->address1);
298 fprintf(ff.output, "%s <%s>\n", item->contact->fullname.str, item->contact->address1.str);
299 }
298 } 300 }
299 } 301 }
300 302
301 } else if (item->email && ((item->type == PST_TYPE_NOTE) || (item->type == PST_TYPE_SCHEDULE) || (item->type == PST_TYPE_REPORT))) { 303 } else if (item->email && ((item->type == PST_TYPE_NOTE) || (item->type == PST_TYPE_SCHEDULE) || (item->type == PST_TYPE_REPORT))) {
302 if (!ff.type) ff.type = item->type;
303 DEBUG_INFO(("Processing Email\n")); 304 DEBUG_INFO(("Processing Email\n"));
304 if ((ff.type != PST_TYPE_NOTE) && (ff.type != PST_TYPE_SCHEDULE) && (ff.type != PST_TYPE_REPORT)) { 305 if (!(output_type_mode & OTMODE_EMAIL)) {
305 ff.skip_count++;
306 DEBUG_INFO(("I have an email type %"PRIi32", but the folder type %"PRIi32" isn't an email folder. Skipping it\n", item->type, ff.type));
307 }
308 else if (!(output_type_mode & OTMODE_EMAIL)) {
309 ff.skip_count++; 306 ff.skip_count++;
310 DEBUG_INFO(("skipping email: not in output type list\n")); 307 DEBUG_INFO(("skipping email: not in output type list\n"));
311 } 308 }
312 else { 309 else {
313 char *extra_mime_headers = NULL; 310 if (!ff.type) ff.type = item->type;
314 ff.item_count++; 311 if ((ff.type != PST_TYPE_NOTE) && (ff.type != PST_TYPE_SCHEDULE) && (ff.type != PST_TYPE_REPORT)) {
315 if (mode == MODE_SEPARATE) mk_separate_file(&ff); 312 ff.skip_count++;
316 write_normal_email(ff.output, ff.name, item, mode, mode_MH, &pstfile, save_rtf_body, &extra_mime_headers); 313 DEBUG_INFO(("I have an email type %"PRIi32", but the folder type %"PRIi32" isn't an email folder. Skipping it\n", item->type, ff.type));
314 }
315 else {
316 char *extra_mime_headers = NULL;
317 ff.item_count++;
318 if (mode == MODE_SEPARATE) mk_separate_file(&ff);
319 write_normal_email(ff.output, ff.name, item, mode, mode_MH, &pstfile, save_rtf_body, &extra_mime_headers);
320 }
317 } 321 }
318 322
319 } else if (item->journal && (item->type == PST_TYPE_JOURNAL)) { 323 } else if (item->journal && (item->type == PST_TYPE_JOURNAL)) {
320 if (!ff.type) ff.type = item->type;
321 DEBUG_INFO(("Processing Journal Entry\n")); 324 DEBUG_INFO(("Processing Journal Entry\n"));
322 if (ff.type != PST_TYPE_JOURNAL) { 325 if (!(output_type_mode & OTMODE_JOURNAL)) {
323 ff.skip_count++;
324 DEBUG_INFO(("I have a journal entry, but the folder type %"PRIi32" isn't a journal folder. Skipping it\n", ff.type));
325 }
326 else if (!(output_type_mode & OTMODE_JOURNAL)) {
327 ff.skip_count++; 326 ff.skip_count++;
328 DEBUG_INFO(("skipping journal entry: not in output type list\n")); 327 DEBUG_INFO(("skipping journal entry: not in output type list\n"));
329 } 328 }
330 else { 329 else {
331 ff.item_count++; 330 if (!ff.type) ff.type = item->type;
332 if (mode == MODE_SEPARATE) mk_separate_file(&ff); 331 if (ff.type != PST_TYPE_JOURNAL) {
333 write_journal(ff.output, item); 332 ff.skip_count++;
334 fprintf(ff.output, "\n"); 333 DEBUG_INFO(("I have a journal entry, but the folder type %"PRIi32" isn't a journal folder. Skipping it\n", ff.type));
334 }
335 else {
336 ff.item_count++;
337 if (mode == MODE_SEPARATE) mk_separate_file(&ff);
338 write_journal(ff.output, item);
339 fprintf(ff.output, "\n");
340 }
335 } 341 }
336 342
337 } else if (item->appointment && (item->type == PST_TYPE_APPOINTMENT)) { 343 } else if (item->appointment && (item->type == PST_TYPE_APPOINTMENT)) {
338 if (!ff.type) ff.type = item->type;
339 DEBUG_INFO(("Processing Appointment Entry\n")); 344 DEBUG_INFO(("Processing Appointment Entry\n"));
340 if (ff.type != PST_TYPE_APPOINTMENT) { 345 if (!(output_type_mode & OTMODE_APPOINTMENT)) {
341 ff.skip_count++;
342 DEBUG_INFO(("I have an appointment, but the folder type %"PRIi32" isn't an appointment folder. Skipping it\n", ff.type));
343 }
344 else if (!(output_type_mode & OTMODE_APPOINTMENT)) {
345 ff.skip_count++; 346 ff.skip_count++;
346 DEBUG_INFO(("skipping appointment: not in output type list\n")); 347 DEBUG_INFO(("skipping appointment: not in output type list\n"));
347 } 348 }
348 else { 349 else {
349 ff.item_count++; 350 if (!ff.type) ff.type = item->type;
350 if (mode == MODE_SEPARATE) mk_separate_file(&ff); 351 if (ff.type != PST_TYPE_APPOINTMENT) {
351 write_appointment(ff.output, item, 0); 352 ff.skip_count++;
352 fprintf(ff.output, "\n"); 353 DEBUG_INFO(("I have an appointment, but the folder type %"PRIi32" isn't an appointment folder. Skipping it\n", ff.type));
354 }
355 else {
356 ff.item_count++;
357 if (mode == MODE_SEPARATE) mk_separate_file(&ff);
358 write_appointment(ff.output, item, 0);
359 fprintf(ff.output, "\n");
360 }
353 } 361 }
354 362
355 } else if (item->message_store) { 363 } else if (item->message_store) {
356 // there should only be one message_store, and we have already done it 364 // there should only be one message_store, and we have already done it
357 ff.skip_count++; 365 ff.skip_count++;
1311 1319
1312 // setup default body character set and report type 1320 // setup default body character set and report type
1313 strncpy(body_charset, pst_default_charset(item, sizeof(buffer_charset), buffer_charset), sizeof(body_charset)); 1321 strncpy(body_charset, pst_default_charset(item, sizeof(buffer_charset), buffer_charset), sizeof(body_charset));
1314 body_charset[sizeof(body_charset)-1] = '\0'; 1322 body_charset[sizeof(body_charset)-1] = '\0';
1315 body_report[0] = '\0'; 1323 body_report[0] = '\0';
1324 if (item->email->report_text.str && !item->body.str) {
1325 strncpy(body_report, "delivery-status", sizeof(body_report));
1326 }
1316 1327
1317 // setup default sender 1328 // setup default sender
1318 pst_convert_utf8(item, &item->email->sender_address); 1329 pst_convert_utf8(item, &item->email->sender_address);
1319 if (item->email->sender_address.str && strchr(item->email->sender_address.str, '@')) { 1330 if (item->email->sender_address.str && strchr(item->email->sender_address.str, '@')) {
1320 temp = item->email->sender_address.str; 1331 temp = item->email->sender_address.str;
1462 1473
1463 // add forensic headers to capture some .pst stuff that is not really 1474 // add forensic headers to capture some .pst stuff that is not really
1464 // needed or used by mail clients 1475 // needed or used by mail clients
1465 pst_convert_utf8_null(item, &item->email->sender_address); 1476 pst_convert_utf8_null(item, &item->email->sender_address);
1466 if (item->email->sender_address.str && !strchr(item->email->sender_address.str, '@') 1477 if (item->email->sender_address.str && !strchr(item->email->sender_address.str, '@')
1467 && strcmp(item->email->sender_address.str, ".")) { 1478 && strcmp(item->email->sender_address.str, ".")
1479 && (strlen(item->email->sender_address.str) > 0)) {
1468 fprintf(f_output, "X-libpst-forensic-sender: %s\n", item->email->sender_address.str); 1480 fprintf(f_output, "X-libpst-forensic-sender: %s\n", item->email->sender_address.str);
1469 } 1481 }
1470 1482
1471 if (item->email->bcc_address.str) { 1483 if (item->email->bcc_address.str) {
1472 pst_convert_utf8(item, &item->email->bcc_address); 1484 pst_convert_utf8(item, &item->email->bcc_address);
1562 for (attach = item->attach; attach; attach = attach->next) { 1574 for (attach = item->attach; attach; attach = attach->next) {
1563 pst_convert_utf8_null(item, &attach->filename1); 1575 pst_convert_utf8_null(item, &attach->filename1);
1564 pst_convert_utf8_null(item, &attach->filename2); 1576 pst_convert_utf8_null(item, &attach->filename2);
1565 pst_convert_utf8_null(item, &attach->mimetype); 1577 pst_convert_utf8_null(item, &attach->mimetype);
1566 DEBUG_INFO(("Attempting Attachment encoding\n")); 1578 DEBUG_INFO(("Attempting Attachment encoding\n"));
1567 if (!attach->data.data && attach->mimetype.str && !strcmp(attach->mimetype.str, RFC822)) { 1579 if (attach->method == PST_ATTACH_EMBEDDED) {
1568 DEBUG_INFO(("seem to have special embedded message attachment\n")); 1580 DEBUG_INFO(("seem to have special embedded message attachment\n"));
1581 char *m = NULL;
1582 if (attach->mimetype.str) {
1583 DEBUG_INFO(("already has a mime-type of %s\n", attach->mimetype.str));
1584 free(attach->mimetype.str);
1585 }
1586 attach->mimetype.str = strdup(RFC822);
1587 attach->mimetype.is_utf8 = 1;
1588 write_embedded_message(f_output, attach, boundary, pst, &m);
1589 }
1590 else if (!attach->data.data && attach->mimetype.str && !strcmp(attach->mimetype.str, RFC822)) {
1591 DEBUG_INFO(("seem to have embedded message attachment\n"));
1569 find_rfc822_headers(extra_mime_headers); 1592 find_rfc822_headers(extra_mime_headers);
1570 write_embedded_message(f_output, attach, boundary, pst, extra_mime_headers); 1593 write_embedded_message(f_output, attach, boundary, pst, extra_mime_headers);
1571 } 1594 }
1572 else if (attach->data.data || attach->i_id) { 1595 else if (attach->data.data || attach->i_id) {
1573 if (mode == MODE_SEPARATE && !mode_MH) 1596 if (mode == MODE_SEPARATE && !mode_MH)