comparison src/readpst.c @ 172:6954d315aaa8

move version-info into main configure.in, and set it properly. prefix all external symbols in the shared library with pst_ to avoid symbol clashes with other shared libraries.
author Carl Byington <carl@five-ten-sg.com>
date Sat, 04 Apr 2009 16:00:48 -0700
parents 6c1e75bc4cac
children b65e8d0a088a
comparison
equal deleted inserted replaced
171:6c1e75bc4cac 172:6954d315aaa8
404 temp = fname; 404 temp = fname;
405 else 405 else
406 temp++; // get past the "\\" 406 temp++; // get past the "\\"
407 else 407 else
408 temp++; // get past the "/" 408 temp++; // get past the "/"
409 item->file_as.str = (char*)xmalloc(strlen(temp)+1); 409 item->file_as.str = (char*)pst_malloc(strlen(temp)+1);
410 strcpy(item->file_as.str, temp); 410 strcpy(item->file_as.str, temp);
411 item->file_as.is_utf8 = 1; 411 item->file_as.is_utf8 = 1;
412 DEBUG_MAIN(("file_as was blank, so am using %s\n", item->file_as.str)); 412 DEBUG_MAIN(("file_as was blank, so am using %s\n", item->file_as.str));
413 } 413 }
414 DEBUG_MAIN(("main: Root Folder Name: %s\n", item->file_as.str)); 414 DEBUG_MAIN(("main: Root Folder Name: %s\n", item->file_as.str));
764 } 764 }
765 765
766 check_filename(f_name); 766 check_filename(f_name);
767 if (!attach_filename) { 767 if (!attach_filename) {
768 // generate our own (dummy) filename for the attachement 768 // generate our own (dummy) filename for the attachement
769 temp = xmalloc(strlen(f_name)+15); 769 temp = pst_malloc(strlen(f_name)+15);
770 sprintf(temp, "%s-attach%i", f_name, attach_num); 770 sprintf(temp, "%s-attach%i", f_name, attach_num);
771 } else { 771 } else {
772 // have an attachment name, make sure it's unique 772 // have an attachment name, make sure it's unique
773 temp = xmalloc(strlen(f_name)+strlen(attach_filename)+15); 773 temp = pst_malloc(strlen(f_name)+strlen(attach_filename)+15);
774 do { 774 do {
775 if (fp) fclose(fp); 775 if (fp) fclose(fp);
776 if (x == 0) 776 if (x == 0)
777 sprintf(temp, "%s-%s", f_name, attach_filename); 777 sprintf(temp, "%s-%s", f_name, attach_filename);
778 else 778 else
831 char *attach_filename; 831 char *attach_filename;
832 char *enc = NULL; // base64 encoded attachment 832 char *enc = NULL; // base64 encoded attachment
833 DEBUG_ENT("write_inline_attachment"); 833 DEBUG_ENT("write_inline_attachment");
834 DEBUG_EMAIL(("Attachment Size is %"PRIu64", id %#"PRIx64"\n", (uint64_t)attach->data.size, attach->i_id)); 834 DEBUG_EMAIL(("Attachment Size is %"PRIu64", id %#"PRIx64"\n", (uint64_t)attach->data.size, attach->i_id));
835 if (attach->data.data) { 835 if (attach->data.data) {
836 enc = base64_encode (attach->data.data, attach->data.size); 836 enc = pst_base64_encode (attach->data.data, attach->data.size);
837 if (!enc) { 837 if (!enc) {
838 DEBUG_EMAIL(("ERROR base64_encode returned NULL. Must have failed\n")); 838 DEBUG_EMAIL(("ERROR base64_encode returned NULL. Must have failed\n"));
839 DEBUG_RET(); 839 DEBUG_RET();
840 return; 840 return;
841 } 841 }
1052 // try to convert to the specified charset since the target 1052 // try to convert to the specified charset since the target
1053 // is not utf-8, and the data came from a unicode (utf16) field 1053 // is not utf-8, and the data came from a unicode (utf16) field
1054 // and is now in utf-8. 1054 // and is now in utf-8.
1055 size_t rc; 1055 size_t rc;
1056 DEBUG_EMAIL(("Convert %s utf-8 to %s\n", mime, charset)); 1056 DEBUG_EMAIL(("Convert %s utf-8 to %s\n", mime, charset));
1057 vbuf *newer = vballoc(2); 1057 vbuf *newer = pst_vballoc(2);
1058 rc = vb_utf8to8bit(newer, body->str, strlen(body->str), charset); 1058 rc = pst_vb_utf8to8bit(newer, body->str, strlen(body->str), charset);
1059 if (rc == (size_t)-1) { 1059 if (rc == (size_t)-1) {
1060 // unable to convert, change the charset to utf8 1060 // unable to convert, change the charset to utf8
1061 free(newer->b); 1061 free(newer->b);
1062 DEBUG_EMAIL(("Failed to convert %s utf-8 to %s\n", mime, charset)); 1062 DEBUG_EMAIL(("Failed to convert %s utf-8 to %s\n", mime, charset));
1063 charset = "utf-8"; 1063 charset = "utf-8";
1064 } 1064 }
1065 else { 1065 else {
1066 // null terminate the output string 1066 // null terminate the output string
1067 vbgrow(newer, 1); 1067 pst_vbgrow(newer, 1);
1068 newer->b[newer->dlen] = '\0'; 1068 newer->b[newer->dlen] = '\0';
1069 free(body->str); 1069 free(body->str);
1070 body->str = newer->b; 1070 body->str = newer->b;
1071 } 1071 }
1072 free(newer); 1072 free(newer);
1076 fprintf(f_output, "\n--%s\n", boundary); 1076 fprintf(f_output, "\n--%s\n", boundary);
1077 fprintf(f_output, "Content-Type: %s; charset=\"%s\"\n", mime, charset); 1077 fprintf(f_output, "Content-Type: %s; charset=\"%s\"\n", mime, charset);
1078 if (base64) fprintf(f_output, "Content-Transfer-Encoding: base64\n"); 1078 if (base64) fprintf(f_output, "Content-Transfer-Encoding: base64\n");
1079 fprintf(f_output, "\n"); 1079 fprintf(f_output, "\n");
1080 if (base64) { 1080 if (base64) {
1081 char *enc = base64_encode(body->str, strlen(body->str)); 1081 char *enc = pst_base64_encode(body->str, strlen(body->str));
1082 if (enc) { 1082 if (enc) {
1083 write_email_body(f_output, enc); 1083 write_email_body(f_output, enc);
1084 fprintf(f_output, "\n"); 1084 fprintf(f_output, "\n");
1085 free(enc); 1085 free(enc);
1086 } 1086 }
1128 strncpy(sender, temp, sizeof(sender)); 1128 strncpy(sender, temp, sizeof(sender));
1129 sender[sizeof(sender)-1] = '\0'; 1129 sender[sizeof(sender)-1] = '\0';
1130 1130
1131 // convert the sent date if it exists, or set it to a fixed date 1131 // convert the sent date if it exists, or set it to a fixed date
1132 if (item->email->sent_date) { 1132 if (item->email->sent_date) {
1133 em_time = fileTimeToUnixTime(item->email->sent_date, 0); 1133 em_time = pst_fileTimeToUnixTime(item->email->sent_date, 0);
1134 c_time = ctime(&em_time); 1134 c_time = ctime(&em_time);
1135 if (c_time) 1135 if (c_time)
1136 c_time[strlen(c_time)-1] = '\0'; //remove end \n 1136 c_time[strlen(c_time)-1] = '\0'; //remove end \n
1137 else 1137 else
1138 c_time = "Fri Dec 28 12:06:21 2001"; 1138 c_time = "Fri Dec 28 12:06:21 2001";
1302 find_html_charset(item->email->htmlbody.str, body_charset, sizeof(body_charset)); 1302 find_html_charset(item->email->htmlbody.str, body_charset, sizeof(body_charset));
1303 write_body_part(f_output, &item->email->htmlbody, "text/html", body_charset, boundary, pst); 1303 write_body_part(f_output, &item->email->htmlbody, "text/html", body_charset, boundary, pst);
1304 } 1304 }
1305 1305
1306 if (item->email->rtf_compressed.data && save_rtf) { 1306 if (item->email->rtf_compressed.data && save_rtf) {
1307 pst_item_attach* attach = (pst_item_attach*)xmalloc(sizeof(pst_item_attach)); 1307 pst_item_attach* attach = (pst_item_attach*)pst_malloc(sizeof(pst_item_attach));
1308 DEBUG_EMAIL(("Adding RTF body as attachment\n")); 1308 DEBUG_EMAIL(("Adding RTF body as attachment\n"));
1309 memset(attach, 0, sizeof(pst_item_attach)); 1309 memset(attach, 0, sizeof(pst_item_attach));
1310 attach->next = item->attach; 1310 attach->next = item->attach;
1311 item->attach = attach; 1311 item->attach = attach;
1312 attach->data.data = lzfu_decompress(item->email->rtf_compressed.data, item->email->rtf_compressed.size, &attach->data.size); 1312 attach->data.data = pst_lzfu_decompress(item->email->rtf_compressed.data, item->email->rtf_compressed.size, &attach->data.size);
1313 attach->filename2.str = strdup(RTF_ATTACH_NAME); 1313 attach->filename2.str = strdup(RTF_ATTACH_NAME);
1314 attach->filename2.is_utf8 = 1; 1314 attach->filename2.is_utf8 = 1;
1315 attach->mimetype.str = strdup(RTF_ATTACH_TYPE); 1315 attach->mimetype.str = strdup(RTF_ATTACH_TYPE);
1316 attach->mimetype.is_utf8 = 1; 1316 attach->mimetype.is_utf8 = 1;
1317 } 1317 }
1318 1318
1319 if (item->email->encrypted_body.data || item->email->encrypted_htmlbody.data) { 1319 if (item->email->encrypted_body.data || item->email->encrypted_htmlbody.data) {
1320 // if either the body or htmlbody is encrypted, add them as attachments 1320 // if either the body or htmlbody is encrypted, add them as attachments
1321 if (item->email->encrypted_body.data) { 1321 if (item->email->encrypted_body.data) {
1322 pst_item_attach* attach = (pst_item_attach*)xmalloc(sizeof(pst_item_attach)); 1322 pst_item_attach* attach = (pst_item_attach*)pst_malloc(sizeof(pst_item_attach));
1323 DEBUG_EMAIL(("Adding Encrypted Body as attachment\n")); 1323 DEBUG_EMAIL(("Adding Encrypted Body as attachment\n"));
1324 attach = (pst_item_attach*) xmalloc(sizeof(pst_item_attach)); 1324 attach = (pst_item_attach*) pst_malloc(sizeof(pst_item_attach));
1325 memset(attach, 0, sizeof(pst_item_attach)); 1325 memset(attach, 0, sizeof(pst_item_attach));
1326 attach->next = item->attach; 1326 attach->next = item->attach;
1327 item->attach = attach; 1327 item->attach = attach;
1328 attach->data.data = item->email->encrypted_body.data; 1328 attach->data.data = item->email->encrypted_body.data;
1329 attach->data.size = item->email->encrypted_body.size; 1329 attach->data.size = item->email->encrypted_body.size;
1330 item->email->encrypted_body.data = NULL; 1330 item->email->encrypted_body.data = NULL;
1331 } 1331 }
1332 1332
1333 if (item->email->encrypted_htmlbody.data) { 1333 if (item->email->encrypted_htmlbody.data) {
1334 pst_item_attach* attach = (pst_item_attach*)xmalloc(sizeof(pst_item_attach)); 1334 pst_item_attach* attach = (pst_item_attach*)pst_malloc(sizeof(pst_item_attach));
1335 DEBUG_EMAIL(("Adding encrypted HTML body as attachment\n")); 1335 DEBUG_EMAIL(("Adding encrypted HTML body as attachment\n"));
1336 attach = (pst_item_attach*) xmalloc(sizeof(pst_item_attach)); 1336 attach = (pst_item_attach*) pst_malloc(sizeof(pst_item_attach));
1337 memset(attach, 0, sizeof(pst_item_attach)); 1337 memset(attach, 0, sizeof(pst_item_attach));
1338 attach->next = item->attach; 1338 attach->next = item->attach;
1339 item->attach = attach; 1339 item->attach = attach;
1340 attach->data.data = item->email->encrypted_htmlbody.data; 1340 attach->data.data = item->email->encrypted_htmlbody.data;
1341 attach->data.size = item->email->encrypted_htmlbody.size; 1341 attach->data.size = item->email->encrypted_htmlbody.size;
1612 else if (mode == MODE_RECURSE) 1612 else if (mode == MODE_RECURSE)
1613 f->name = mk_recurse_dir(item->file_as.str, f->type); 1613 f->name = mk_recurse_dir(item->file_as.str, f->type);
1614 else if (mode == MODE_SEPARATE) { 1614 else if (mode == MODE_SEPARATE) {
1615 // do similar stuff to recurse here. 1615 // do similar stuff to recurse here.
1616 mk_separate_dir(item->file_as.str); 1616 mk_separate_dir(item->file_as.str);
1617 f->name = (char*) xmalloc(10); 1617 f->name = (char*) pst_malloc(10);
1618 memset(f->name, 0, 10); 1618 memset(f->name, 0, 10);
1619 } else { 1619 } else {
1620 f->name = (char*) xmalloc(strlen(item->file_as.str)+strlen(OUTPUT_TEMPLATE)+1); 1620 f->name = (char*) pst_malloc(strlen(item->file_as.str)+strlen(OUTPUT_TEMPLATE)+1);
1621 sprintf(f->name, OUTPUT_TEMPLATE, item->file_as.str); 1621 sprintf(f->name, OUTPUT_TEMPLATE, item->file_as.str);
1622 } 1622 }
1623 1623
1624 f->dname = (char*) xmalloc(strlen(item->file_as.str)+1); 1624 f->dname = (char*) pst_malloc(strlen(item->file_as.str)+1);
1625 strcpy(f->dname, item->file_as.str); 1625 strcpy(f->dname, item->file_as.str);
1626 1626
1627 if (overwrite != 1) { 1627 if (overwrite != 1) {
1628 int x = 0; 1628 int x = 0;
1629 char *temp = (char*) xmalloc (strlen(f->name)+10); //enough room for 10 digits 1629 char *temp = (char*) pst_malloc (strlen(f->name)+10); //enough room for 10 digits
1630 1630
1631 sprintf(temp, "%s", f->name); 1631 sprintf(temp, "%s", f->name);
1632 check_filename(temp); 1632 check_filename(temp);
1633 while ((f->output = fopen(temp, "r"))) { 1633 while ((f->output = fopen(temp, "r"))) {
1634 DEBUG_MAIN(("need to increase filename because one already exists with that name\n")); 1634 DEBUG_MAIN(("need to increase filename because one already exists with that name\n"));