comparison src/readpst.c @ 205:5f3fa53cb0e1

make nested mime multipart/alternative to hold the text/html parts
author Carl Byington <carl@five-ten-sg.com>
date Sat, 06 Jun 2009 12:48:09 -0700
parents 9fb600ef4e03
children 94bde95d7e18
comparison
equal deleted inserted replaced
204:268458c79e9b 205:5f3fa53cb0e1
184 memset(child_processes, 0, sizeof(pid_t) * max_children); 184 memset(child_processes, 0, sizeof(pid_t) * max_children);
185 pst_reopen(&pstfile); // close and reopen the pst file to get an independent file position pointer 185 pst_reopen(&pstfile); // close and reopen the pst file to get an independent file position pointer
186 } 186 }
187 else { 187 else {
188 // fork worked, and we are the parent, record this child that we need to wait for 188 // fork worked, and we are the parent, record this child that we need to wait for
189 pid_t me = getpid(); 189 //pid_t me = getpid();
190 //printf("parent %d forked child pid %d to process folder %s\n", me, child, folder); 190 //printf("parent %d forked child pid %d to process folder %s\n", me, child, folder);
191 //fflush(stdout); 191 //fflush(stdout);
192 child_processes[active_children++] = child; 192 child_processes[active_children++] = child;
193 } 193 }
194 return child; 194 return child;
1214 1214
1215 1215
1216 void write_normal_email(FILE* f_output, char f_name[], pst_item* item, int mode, int mode_MH, pst_file* pst, int save_rtf, char** extra_mime_headers) 1216 void write_normal_email(FILE* f_output, char f_name[], pst_item* item, int mode, int mode_MH, pst_file* pst, int save_rtf, char** extra_mime_headers)
1217 { 1217 {
1218 char boundary[60]; 1218 char boundary[60];
1219 char altboundary[66];
1220 char *altboundaryp = NULL;
1219 char body_charset[60]; 1221 char body_charset[60];
1220 char body_report[60]; 1222 char body_report[60];
1221 char sender[60]; 1223 char sender[60];
1222 int sender_known = 0; 1224 int sender_known = 0;
1223 char *temp = NULL; 1225 char *temp = NULL;
1257 else 1259 else
1258 c_time = "Fri Dec 28 12:06:21 2001"; 1260 c_time = "Fri Dec 28 12:06:21 2001";
1259 } else 1261 } else
1260 c_time= "Fri Dec 28 12:06:21 2001"; 1262 c_time= "Fri Dec 28 12:06:21 2001";
1261 1263
1262 // create our MIME boundary here. 1264 // create our MIME boundaries here.
1263 snprintf(boundary, sizeof(boundary), "--boundary-LibPST-iamunique-%i_-_-", rand()); 1265 snprintf(boundary, sizeof(boundary), "--boundary-LibPST-iamunique-%i_-_-", rand());
1266 snprintf(altboundary, sizeof(altboundary), "alt-%s", boundary);
1264 1267
1265 // we will always look at the headers to discover some stuff 1268 // we will always look at the headers to discover some stuff
1266 if (headers ) { 1269 if (headers ) {
1267 char *t; 1270 char *t;
1268 removeCR(headers); 1271 removeCR(headers);
1397 fprintf(f_output, "MIME-Version: 1.0\n"); 1400 fprintf(f_output, "MIME-Version: 1.0\n");
1398 if (body_report[0] != '\0') { 1401 if (body_report[0] != '\0') {
1399 // multipart/report for DSN/MDN reports 1402 // multipart/report for DSN/MDN reports
1400 fprintf(f_output, "Content-Type: multipart/report; report-type=%s;\n\tboundary=\"%s\"\n", body_report, boundary); 1403 fprintf(f_output, "Content-Type: multipart/report; report-type=%s;\n\tboundary=\"%s\"\n", body_report, boundary);
1401 } 1404 }
1402 else if (item->attach || (item->email->rtf_compressed.data && save_rtf) 1405 else {
1403 || item->email->encrypted_body.data
1404 || item->email->encrypted_htmlbody.data
1405 || (item->type == PST_TYPE_SCHEDULE)) {
1406 // use multipart/mixed if we have attachments
1407 fprintf(f_output, "Content-Type: multipart/mixed;\n\tboundary=\"%s\"\n", boundary); 1406 fprintf(f_output, "Content-Type: multipart/mixed;\n\tboundary=\"%s\"\n", boundary);
1408 } else {
1409 // else use multipart/alternative
1410 fprintf(f_output, "Content-Type: multipart/alternative;\n\tboundary=\"%s\"\n", boundary);
1411 } 1407 }
1412 fprintf(f_output, "\n"); // end of headers, start of body 1408 fprintf(f_output, "\n"); // end of headers, start of body
1413 1409
1414 // now dump the body parts 1410 // now dump the body parts
1415 if (item->body.str) {
1416 write_body_part(f_output, &item->body, "text/plain", body_charset, boundary, pst);
1417 }
1418
1419 if ((item->email->report_text.str) && (body_report[0] != '\0')) { 1411 if ((item->email->report_text.str) && (body_report[0] != '\0')) {
1420 write_body_part(f_output, &item->email->report_text, "text/plain", body_charset, boundary, pst); 1412 write_body_part(f_output, &item->email->report_text, "text/plain", body_charset, boundary, pst);
1421 fprintf(f_output, "\n"); 1413 fprintf(f_output, "\n");
1422 } 1414 }
1423 1415
1416 if (item->body.str && item->email->htmlbody.str) {
1417 // start the nested alternative part
1418 fprintf(f_output, "\n--%s\n", boundary);
1419 fprintf(f_output, "Content-Type: multipart/alternative;\n\tboundary=\"%s\"\n", altboundary);
1420 altboundaryp = altboundary;
1421 }
1422 else {
1423 altboundaryp = boundary;
1424 }
1425
1426 if (item->body.str) {
1427 write_body_part(f_output, &item->body, "text/plain", body_charset, altboundaryp, pst);
1428 }
1429
1424 if (item->email->htmlbody.str) { 1430 if (item->email->htmlbody.str) {
1425 find_html_charset(item->email->htmlbody.str, body_charset, sizeof(body_charset)); 1431 find_html_charset(item->email->htmlbody.str, body_charset, sizeof(body_charset));
1426 write_body_part(f_output, &item->email->htmlbody, "text/html", body_charset, boundary, pst); 1432 write_body_part(f_output, &item->email->htmlbody, "text/html", body_charset, altboundaryp, pst);
1433 }
1434
1435 if (item->body.str && item->email->htmlbody.str) {
1436 // end the nested alternative part
1437 fprintf(f_output, "\n--%s--\n", altboundary);
1427 } 1438 }
1428 1439
1429 if (item->email->rtf_compressed.data && save_rtf) { 1440 if (item->email->rtf_compressed.data && save_rtf) {
1430 pst_item_attach* attach = (pst_item_attach*)pst_malloc(sizeof(pst_item_attach)); 1441 pst_item_attach* attach = (pst_item_attach*)pst_malloc(sizeof(pst_item_attach));
1431 DEBUG_INFO(("Adding RTF body as attachment\n")); 1442 DEBUG_INFO(("Adding RTF body as attachment\n"));
1437 attach->filename2.is_utf8 = 1; 1448 attach->filename2.is_utf8 = 1;
1438 attach->mimetype.str = strdup(RTF_ATTACH_TYPE); 1449 attach->mimetype.str = strdup(RTF_ATTACH_TYPE);
1439 attach->mimetype.is_utf8 = 1; 1450 attach->mimetype.is_utf8 = 1;
1440 } 1451 }
1441 1452
1442 if (item->email->encrypted_body.data || item->email->encrypted_htmlbody.data) { 1453 if (item->email->encrypted_body.data) {
1443 // if either the body or htmlbody is encrypted, add them as attachments 1454 pst_item_attach* attach = (pst_item_attach*)pst_malloc(sizeof(pst_item_attach));
1444 if (item->email->encrypted_body.data) { 1455 DEBUG_INFO(("Adding encrypted text body as attachment\n"));
1445 pst_item_attach* attach = (pst_item_attach*)pst_malloc(sizeof(pst_item_attach)); 1456 attach = (pst_item_attach*) pst_malloc(sizeof(pst_item_attach));
1446 DEBUG_INFO(("Adding Encrypted Body as attachment\n")); 1457 memset(attach, 0, sizeof(pst_item_attach));
1447 attach = (pst_item_attach*) pst_malloc(sizeof(pst_item_attach)); 1458 attach->next = item->attach;
1448 memset(attach, 0, sizeof(pst_item_attach)); 1459 item->attach = attach;
1449 attach->next = item->attach; 1460 attach->data.data = item->email->encrypted_body.data;
1450 item->attach = attach; 1461 attach->data.size = item->email->encrypted_body.size;
1451 attach->data.data = item->email->encrypted_body.data; 1462 item->email->encrypted_body.data = NULL;
1452 attach->data.size = item->email->encrypted_body.size; 1463 }
1453 item->email->encrypted_body.data = NULL; 1464
1454 } 1465 if (item->email->encrypted_htmlbody.data) {
1455 1466 pst_item_attach* attach = (pst_item_attach*)pst_malloc(sizeof(pst_item_attach));
1456 if (item->email->encrypted_htmlbody.data) { 1467 DEBUG_INFO(("Adding encrypted HTML body as attachment\n"));
1457 pst_item_attach* attach = (pst_item_attach*)pst_malloc(sizeof(pst_item_attach)); 1468 attach = (pst_item_attach*) pst_malloc(sizeof(pst_item_attach));
1458 DEBUG_INFO(("Adding encrypted HTML body as attachment\n")); 1469 memset(attach, 0, sizeof(pst_item_attach));
1459 attach = (pst_item_attach*) pst_malloc(sizeof(pst_item_attach)); 1470 attach->next = item->attach;
1460 memset(attach, 0, sizeof(pst_item_attach)); 1471 item->attach = attach;
1461 attach->next = item->attach; 1472 attach->data.data = item->email->encrypted_htmlbody.data;
1462 item->attach = attach; 1473 attach->data.size = item->email->encrypted_htmlbody.size;
1463 attach->data.data = item->email->encrypted_htmlbody.data; 1474 item->email->encrypted_htmlbody.data = NULL;
1464 attach->data.size = item->email->encrypted_htmlbody.size;
1465 item->email->encrypted_htmlbody.data = NULL;
1466 }
1467 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");
1468 } 1475 }
1469 1476
1470 if (item->type == PST_TYPE_SCHEDULE) { 1477 if (item->type == PST_TYPE_SCHEDULE) {
1471 write_schedule_part(f_output, item, sender, boundary); 1478 write_schedule_part(f_output, item, sender, boundary);
1472 } 1479 }
1492 write_inline_attachment(f_output, attach, boundary, pst); 1499 write_inline_attachment(f_output, attach, boundary, pst);
1493 } 1500 }
1494 } 1501 }
1495 } 1502 }
1496 1503
1497 fprintf(f_output, "\n--%s--\n\n\n", boundary); 1504 fprintf(f_output, "\n--%s--\n\n", boundary);
1498 DEBUG_RET(); 1505 DEBUG_RET();
1499 } 1506 }
1500 1507
1501 1508
1502 void write_vcard(FILE* f_output, pst_item *item, pst_item_contact* contact, char comment[]) 1509 void write_vcard(FILE* f_output, pst_item *item, pst_item_contact* contact, char comment[])