comparison src/readpst.c @ 167:40e9de445038

improve consistency checking when fetching items from the pst file. avoid putting mixed item types into the same output folder.
author Carl Byington <carl@five-ten-sg.com>
date Wed, 18 Mar 2009 22:31:18 -0700
parents ab384fed78c5
children c1a2fd06ffe6
comparison
equal deleted inserted replaced
166:55d4f17a35f2 167:40e9de445038
19 struct file_ll { 19 struct file_ll {
20 char *name; 20 char *name;
21 char *dname; 21 char *dname;
22 FILE * output; 22 FILE * output;
23 int32_t stored_count; 23 int32_t stored_count;
24 int32_t email_count; 24 int32_t item_count;
25 int32_t skip_count; 25 int32_t skip_count;
26 int32_t type; 26 int32_t type;
27 }; 27 };
28 28
29 void process(pst_item *outeritem, pst_desc_ll *d_ptr); 29 void process(pst_item *outeritem, pst_desc_ll *d_ptr);
128 128
129 DEBUG_ENT("process"); 129 DEBUG_ENT("process");
130 memset(&ff, 0, sizeof(ff)); 130 memset(&ff, 0, sizeof(ff));
131 create_enter_dir(&ff, outeritem); 131 create_enter_dir(&ff, outeritem);
132 132
133 while (d_ptr) { 133 for (; d_ptr; d_ptr = d_ptr->next) {
134 DEBUG_MAIN(("main: New item record\n")); 134 DEBUG_MAIN(("main: New item record\n"));
135 if (!d_ptr->desc) { 135 if (!d_ptr->desc) {
136 ff.skip_count++;
136 DEBUG_WARN(("main: ERROR item's desc record is NULL\n")); 137 DEBUG_WARN(("main: ERROR item's desc record is NULL\n"));
138 continue;
139 }
140 DEBUG_MAIN(("main: Desc Email ID %#"PRIx64" [d_ptr->d_id = %#"PRIx64"]\n", d_ptr->desc->i_id, d_ptr->d_id));
141
142 item = pst_parse_item(&pstfile, d_ptr, NULL);
143 DEBUG_MAIN(("main: About to process item\n"));
144
145 if (!item) {
137 ff.skip_count++; 146 ff.skip_count++;
138 } 147 DEBUG_MAIN(("main: A NULL item was seen\n"));
139 else { 148 continue;
140 DEBUG_MAIN(("main: Desc Email ID %#"PRIx64" [d_ptr->d_id = %#"PRIx64"]\n", d_ptr->desc->i_id, d_ptr->d_id)); 149 }
141 150
142 item = pst_parse_item(&pstfile, d_ptr, NULL); 151 if (item->subject.str) {
143 DEBUG_MAIN(("main: About to process item\n")); 152 DEBUG_EMAIL(("item->subject = %s\n", item->subject.str));
144 if (item && item->subject.str) { 153 }
145 DEBUG_EMAIL(("item->subject = %s\n", item->subject.str)); 154
146 } 155 if (item->folder && item->file_as.str) {
147 if (item) { 156 DEBUG_MAIN(("Processing Folder \"%s\"\n", item->file_as.str));
148 if (item->folder && d_ptr->child && item->file_as.str && (deleted_mode == DMODE_INCLUDE || strcasecmp(item->file_as.str, "Deleted Items"))) { 157 if (output_mode != OUTPUT_QUIET) printf("Processing Folder \"%s\"\n", item->file_as.str);
149 //if this is a non-empty folder other than deleted items, we want to recurse into it 158 ff.item_count++;
150 if (output_mode != OUTPUT_QUIET) printf("Processing Folder \"%s\"\n", item->file_as.str); 159 if (d_ptr->child && (deleted_mode == DMODE_INCLUDE || strcasecmp(item->file_as.str, "Deleted Items"))) {
151 process(item, d_ptr->child); 160 //if this is a non-empty folder other than deleted items, we want to recurse into it
152 161 process(item, d_ptr->child);
153 } else if (item->contact && (item->type == PST_TYPE_CONTACT)) { 162 }
154 if (mode == MODE_SEPARATE) mk_separate_file(&ff); 163
155 ff.email_count++; 164 } else if (item->contact && (item->type == PST_TYPE_CONTACT)) {
156 DEBUG_MAIN(("main: Processing Contact\n")); 165 if (!ff.type) ff.type = item->type;
157 if (ff.type != PST_TYPE_CONTACT) { 166 DEBUG_MAIN(("main: Processing Contact\n"));
158 DEBUG_MAIN(("main: I have a contact, but the folder type %"PRIi32" isn't a contacts folder. Processing anyway\n", ff.type)); 167 if (ff.type != PST_TYPE_CONTACT) {
159 } 168 ff.skip_count++;
160 if (contact_mode == CMODE_VCARD) { 169 DEBUG_MAIN(("main: I have a contact, but the folder type %"PRIi32" isn't a contacts folder. Skipping it\n", ff.type));
161 pst_convert_utf8_null(item, &item->comment); 170 }
162 write_vcard(ff.output, item, item->contact, item->comment.str); 171 else {
163 } 172 ff.item_count++;
164 else { 173 if (mode == MODE_SEPARATE) mk_separate_file(&ff);
165 pst_convert_utf8(item, &item->contact->fullname); 174 if (contact_mode == CMODE_VCARD) {
166 pst_convert_utf8(item, &item->contact->address1); 175 pst_convert_utf8_null(item, &item->comment);
167 fprintf(ff.output, "%s <%s>\n", item->contact->fullname.str, item->contact->address1.str); 176 write_vcard(ff.output, item, item->contact, item->comment.str);
168 }
169
170 } else if (item->email && (item->type == PST_TYPE_NOTE || item->type == PST_TYPE_REPORT)) {
171 char *extra_mime_headers = NULL;
172 if (mode == MODE_SEPARATE) mk_separate_file(&ff);
173 ff.email_count++;
174 DEBUG_MAIN(("main: Processing Email\n"));
175 if ((ff.type != PST_TYPE_NOTE) && (ff.type != PST_TYPE_REPORT)) {
176 DEBUG_MAIN(("main: I have an email type %"PRIi32", but the folder type %"PRIi32" isn't an email folder. Processing anyway\n", item->type, ff.type));
177 }
178 write_normal_email(ff.output, ff.name, item, mode, mode_MH, &pstfile, save_rtf_body, &extra_mime_headers);
179
180 } else if (item->journal && (item->type == PST_TYPE_JOURNAL)) {
181 if (mode == MODE_SEPARATE) mk_separate_file(&ff);
182 ff.email_count++;
183 DEBUG_MAIN(("main: Processing Journal Entry\n"));
184 if (ff.type != PST_TYPE_JOURNAL) {
185 DEBUG_MAIN(("main: I have a journal entry, but the folder type %"PRIi32" isn't a journal folder. Processing anyway\n", ff.type));
186 }
187 fprintf(ff.output, "BEGIN:VJOURNAL\n");
188 if (item->subject.str) {
189 pst_convert_utf8(item, &item->subject);
190 fprintf(ff.output, "SUMMARY:%s\n", pst_rfc2426_escape(item->subject.str));
191 }
192 if (item->body.str) {
193 pst_convert_utf8(item, &item->body);
194 fprintf(ff.output, "DESCRIPTION:%s\n", pst_rfc2426_escape(item->body.str));
195 }
196 if (item->journal->start)
197 fprintf(ff.output, "DTSTART;VALUE=DATE-TIME:%s\n", pst_rfc2445_datetime_format(item->journal->start));
198 fprintf(ff.output, "END:VJOURNAL\n\n");
199
200 } else if (item->appointment && (item->type == PST_TYPE_APPOINTMENT)) {
201 if (mode == MODE_SEPARATE) mk_separate_file(&ff);
202 ff.email_count++;
203 DEBUG_MAIN(("main: Processing Appointment Entry\n"));
204 if (ff.type != PST_TYPE_APPOINTMENT) {
205 DEBUG_MAIN(("main: I have an appointment, but folder type %"PRIi32" isn't an appointment folder. Processing anyway\n", ff.type));
206 }
207 write_appointment(ff.output, item, item->appointment, item->create_date, item->modify_date);
208
209 } else if (item->message_store) {
210 // there should only be one message_store, and we have already done it
211 DEBUG_MAIN(("item with message store content, type %i %s folder type %i, skipping it\n", item->type, item->ascii_type, ff.type));
212
213 } else {
214 // these all seem to be things that MS agrees are not included in the item count
215 //ff.skip_count++;
216 DEBUG_MAIN(("main: Unknown item type %i (%s) name (%s)\n",
217 item->type, item->ascii_type, item->file_as.str));
218 } 177 }
219 pst_freeItem(item); 178 else {
220 } else { 179 pst_convert_utf8(item, &item->contact->fullname);
180 pst_convert_utf8(item, &item->contact->address1);
181 fprintf(ff.output, "%s <%s>\n", item->contact->fullname.str, item->contact->address1.str);
182 }
183 }
184
185 } else if (item->email && (item->type == PST_TYPE_NOTE || item->type == PST_TYPE_REPORT)) {
186 if (!ff.type) ff.type = item->type;
187 DEBUG_MAIN(("main: Processing Email\n"));
188 if ((ff.type != PST_TYPE_NOTE) && (ff.type != PST_TYPE_REPORT)) {
221 ff.skip_count++; 189 ff.skip_count++;
222 DEBUG_MAIN(("main: A NULL item was seen\n")); 190 DEBUG_MAIN(("main: I have an email type %"PRIi32", but the folder type %"PRIi32" isn't an email folder. Skipping it\n", item->type, ff.type));
223 } 191 }
224 d_ptr = d_ptr->next; 192 else {
225 } 193 char *extra_mime_headers = NULL;
194 ff.item_count++;
195 if (mode == MODE_SEPARATE) mk_separate_file(&ff);
196 write_normal_email(ff.output, ff.name, item, mode, mode_MH, &pstfile, save_rtf_body, &extra_mime_headers);
197 }
198
199 } else if (item->journal && (item->type == PST_TYPE_JOURNAL)) {
200 if (!ff.type) ff.type = item->type;
201 DEBUG_MAIN(("main: Processing Journal Entry\n"));
202 if (ff.type != PST_TYPE_JOURNAL) {
203 ff.skip_count++;
204 DEBUG_MAIN(("main: I have a journal entry, but the folder type %"PRIi32" isn't a journal folder. Skipping it\n", ff.type));
205 }
206 else {
207 ff.item_count++;
208 if (mode == MODE_SEPARATE) mk_separate_file(&ff);
209 fprintf(ff.output, "BEGIN:VJOURNAL\n");
210 if (item->subject.str) {
211 pst_convert_utf8(item, &item->subject);
212 fprintf(ff.output, "SUMMARY:%s\n", pst_rfc2426_escape(item->subject.str));
213 }
214 if (item->body.str) {
215 pst_convert_utf8(item, &item->body);
216 fprintf(ff.output, "DESCRIPTION:%s\n", pst_rfc2426_escape(item->body.str));
217 }
218 if (item->journal->start)
219 fprintf(ff.output, "DTSTART;VALUE=DATE-TIME:%s\n", pst_rfc2445_datetime_format(item->journal->start));
220 fprintf(ff.output, "END:VJOURNAL\n\n");
221 }
222
223 } else if (item->appointment && (item->type == PST_TYPE_APPOINTMENT)) {
224 if (!ff.type) ff.type = item->type;
225 DEBUG_MAIN(("main: Processing Appointment Entry\n"));
226 if (ff.type != PST_TYPE_APPOINTMENT) {
227 ff.skip_count++;
228 DEBUG_MAIN(("main: I have an appointment, but the folder type %"PRIi32" isn't an appointment folder. Skipping it\n", ff.type));
229 }
230 else {
231 ff.item_count++;
232 if (mode == MODE_SEPARATE) mk_separate_file(&ff);
233 write_appointment(ff.output, item, item->appointment, item->create_date, item->modify_date);
234 }
235
236 } else if (item->message_store) {
237 // there should only be one message_store, and we have already done it
238 ff.skip_count++;
239 DEBUG_MAIN(("item with message store content, type %i %s folder type %i, skipping it\n", item->type, item->ascii_type, ff.type));
240
241 } else {
242 ff.skip_count++;
243 DEBUG_MAIN(("main: Unknown item type %i (%s) name (%s)\n",
244 item->type, item->ascii_type, item->file_as.str));
245 }
246 pst_freeItem(item);
226 } 247 }
227 close_enter_dir(&ff); 248 close_enter_dir(&ff);
228 DEBUG_RET(); 249 DEBUG_RET();
229 } 250 }
230 251
663 684
664 int mk_separate_file(struct file_ll *f) { 685 int mk_separate_file(struct file_ll *f) {
665 const int name_offset = 1; 686 const int name_offset = 1;
666 DEBUG_ENT("mk_separate_file"); 687 DEBUG_ENT("mk_separate_file");
667 DEBUG_MAIN(("opening next file to save email\n")); 688 DEBUG_MAIN(("opening next file to save email\n"));
668 if (f->email_count > 999999999) { // bigger than nine 9's 689 if (f->item_count > 999999999) { // bigger than nine 9's
669 DIE(("mk_separate_file: The number of emails in this folder has become too high to handle")); 690 DIE(("mk_separate_file: The number of emails in this folder has become too high to handle"));
670 } 691 }
671 sprintf(f->name, SEP_MAIL_FILE_TEMPLATE, f->email_count + name_offset); 692 sprintf(f->name, SEP_MAIL_FILE_TEMPLATE, f->item_count + name_offset);
672 if (f->output) fclose(f->output); 693 if (f->output) fclose(f->output);
673 f->output = NULL; 694 f->output = NULL;
674 check_filename(f->name); 695 check_filename(f->name);
675 if (!(f->output = fopen(f->name, "w"))) { 696 if (!(f->output = fopen(f->name, "w"))) {
676 DIE(("mk_separate_file: Cannot open file to save email \"%s\"\n", f->name)); 697 DIE(("mk_separate_file: Cannot open file to save email \"%s\"\n", f->name));
730 // use the 8.3 filename (filename1) 751 // use the 8.3 filename (filename1)
731 char *attach_filename = (attach->filename2.str) ? attach->filename2.str 752 char *attach_filename = (attach->filename2.str) ? attach->filename2.str
732 : attach->filename1.str; 753 : attach->filename1.str;
733 DEBUG_ENT("write_separate_attachment"); 754 DEBUG_ENT("write_separate_attachment");
734 755
735 if (!attach->data) { 756 if (!attach->data.data) {
736 // make sure we can fetch data from the id 757 // make sure we can fetch data from the id
737 pst_index_ll *ptr = pst_getID(pst, attach->i_id); 758 pst_index_ll *ptr = pst_getID(pst, attach->i_id);
738 if (!ptr) { 759 if (!ptr) {
739 DEBUG_WARN(("Couldn't find i_id %#"PRIx64". Cannot save attachment to file\n", attach->i_id)); 760 DEBUG_WARN(("Couldn't find i_id %#"PRIx64". Cannot save attachment to file\n", attach->i_id));
740 DEBUG_RET(); 761 DEBUG_RET();
763 } 784 }
764 DEBUG_EMAIL(("Saving attachment to %s\n", temp)); 785 DEBUG_EMAIL(("Saving attachment to %s\n", temp));
765 if (!(fp = fopen(temp, "w"))) { 786 if (!(fp = fopen(temp, "w"))) {
766 WARN(("write_separate_attachment: Cannot open attachment save file \"%s\"\n", temp)); 787 WARN(("write_separate_attachment: Cannot open attachment save file \"%s\"\n", temp));
767 } else { 788 } else {
768 if (attach->data) 789 if (attach->data.data)
769 pst_fwrite(attach->data, (size_t)1, attach->size, fp); 790 pst_fwrite(attach->data.data, (size_t)1, attach->data.size, fp);
770 else { 791 else {
771 (void)pst_attach_to_file(pst, attach, fp); 792 (void)pst_attach_to_file(pst, attach, fp);
772 } 793 }
773 fclose(fp); 794 fclose(fp);
774 } 795 }
808 void write_inline_attachment(FILE* f_output, pst_item_attach* attach, char *boundary, pst_file* pst) 829 void write_inline_attachment(FILE* f_output, pst_item_attach* attach, char *boundary, pst_file* pst)
809 { 830 {
810 char *attach_filename; 831 char *attach_filename;
811 char *enc = NULL; // base64 encoded attachment 832 char *enc = NULL; // base64 encoded attachment
812 DEBUG_ENT("write_inline_attachment"); 833 DEBUG_ENT("write_inline_attachment");
813 DEBUG_EMAIL(("Attachment Size is %"PRIu64", id %#"PRIx64"\n", (uint64_t)attach->size, attach->i_id)); 834 DEBUG_EMAIL(("Attachment Size is %"PRIu64", id %#"PRIx64"\n", (uint64_t)attach->data.size, attach->i_id));
814 if (attach->data) { 835 if (attach->data.data) {
815 enc = base64_encode (attach->data, attach->size); 836 enc = base64_encode (attach->data.data, attach->data.size);
816 if (!enc) { 837 if (!enc) {
817 DEBUG_EMAIL(("ERROR base64_encode returned NULL. Must have failed\n")); 838 DEBUG_EMAIL(("ERROR base64_encode returned NULL. Must have failed\n"));
818 DEBUG_RET(); 839 DEBUG_RET();
819 return; 840 return;
820 } 841 }
844 fprintf(f_output, "Content-Disposition: inline\n\n"); 865 fprintf(f_output, "Content-Disposition: inline\n\n");
845 } else { 866 } else {
846 fprintf(f_output, "Content-Disposition: attachment; filename=\"%s\"\n\n", attach_filename); 867 fprintf(f_output, "Content-Disposition: attachment; filename=\"%s\"\n\n", attach_filename);
847 } 868 }
848 869
849 if (attach->data) { 870 if (attach->data.data) {
850 pst_fwrite(enc, 1, strlen(enc), f_output); 871 pst_fwrite(enc, 1, strlen(enc), f_output);
851 DEBUG_EMAIL(("Attachment Size after encoding is %i\n", strlen(enc))); 872 DEBUG_EMAIL(("Attachment Size after encoding is %i\n", strlen(enc)));
852 free(enc); // caught by valgrind 873 free(enc); // caught by valgrind
853 } else { 874 } else {
854 (void)pst_attach_to_file_base64(pst, attach, f_output); 875 (void)pst_attach_to_file_base64(pst, attach, f_output);
1254 fprintf(f_output, "MIME-Version: 1.0\n"); 1275 fprintf(f_output, "MIME-Version: 1.0\n");
1255 if (body_report[0] != '\0') { 1276 if (body_report[0] != '\0') {
1256 // multipart/report for DSN/MDN reports 1277 // multipart/report for DSN/MDN reports
1257 fprintf(f_output, "Content-Type: multipart/report; report-type=%s;\n\tboundary=\"%s\"\n", body_report, boundary); 1278 fprintf(f_output, "Content-Type: multipart/report; report-type=%s;\n\tboundary=\"%s\"\n", body_report, boundary);
1258 } 1279 }
1259 else if (item->attach || (item->email->rtf_compressed && save_rtf) 1280 else if (item->attach || (item->email->rtf_compressed.data && save_rtf)
1260 || item->email->encrypted_body 1281 || item->email->encrypted_body.data
1261 || item->email->encrypted_htmlbody) { 1282 || item->email->encrypted_htmlbody.data) {
1262 // use multipart/mixed if we have attachments 1283 // use multipart/mixed if we have attachments
1263 fprintf(f_output, "Content-Type: multipart/mixed;\n\tboundary=\"%s\"\n", boundary); 1284 fprintf(f_output, "Content-Type: multipart/mixed;\n\tboundary=\"%s\"\n", boundary);
1264 } else { 1285 } else {
1265 // else use multipart/alternative 1286 // else use multipart/alternative
1266 fprintf(f_output, "Content-Type: multipart/alternative;\n\tboundary=\"%s\"\n", boundary); 1287 fprintf(f_output, "Content-Type: multipart/alternative;\n\tboundary=\"%s\"\n", boundary);
1280 if (item->email->htmlbody.str) { 1301 if (item->email->htmlbody.str) {
1281 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));
1282 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);
1283 } 1304 }
1284 1305
1285 if (item->email->rtf_compressed && save_rtf) { 1306 if (item->email->rtf_compressed.data && save_rtf) {
1286 pst_item_attach* attach = (pst_item_attach*)xmalloc(sizeof(pst_item_attach)); 1307 pst_item_attach* attach = (pst_item_attach*)xmalloc(sizeof(pst_item_attach));
1287 DEBUG_EMAIL(("Adding RTF body as attachment\n")); 1308 DEBUG_EMAIL(("Adding RTF body as attachment\n"));
1288 memset(attach, 0, sizeof(pst_item_attach)); 1309 memset(attach, 0, sizeof(pst_item_attach));
1289 attach->next = item->attach; 1310 attach->next = item->attach;
1290 item->attach = attach; 1311 item->attach = attach;
1291 attach->data = lzfu_decompress(item->email->rtf_compressed, item->email->rtf_compressed_size, &attach->size); 1312 attach->data.data = lzfu_decompress(item->email->rtf_compressed.data, item->email->rtf_compressed.size, &attach->data.size);
1292 attach->filename2.str = strdup(RTF_ATTACH_NAME); 1313 attach->filename2.str = strdup(RTF_ATTACH_NAME);
1293 attach->filename2.is_utf8 = 1; 1314 attach->filename2.is_utf8 = 1;
1294 attach->mimetype.str = strdup(RTF_ATTACH_TYPE); 1315 attach->mimetype.str = strdup(RTF_ATTACH_TYPE);
1295 attach->mimetype.is_utf8 = 1; 1316 attach->mimetype.is_utf8 = 1;
1296 } 1317 }
1297 1318
1298 if (item->email->encrypted_body || item->email->encrypted_htmlbody) { 1319 if (item->email->encrypted_body.data || item->email->encrypted_htmlbody.data) {
1299 // 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
1300 if (item->email->encrypted_body) { 1321 if (item->email->encrypted_body.data) {
1301 pst_item_attach* attach = (pst_item_attach*)xmalloc(sizeof(pst_item_attach)); 1322 pst_item_attach* attach = (pst_item_attach*)xmalloc(sizeof(pst_item_attach));
1302 DEBUG_EMAIL(("Adding Encrypted Body as attachment\n")); 1323 DEBUG_EMAIL(("Adding Encrypted Body as attachment\n"));
1303 attach = (pst_item_attach*) xmalloc(sizeof(pst_item_attach)); 1324 attach = (pst_item_attach*) xmalloc(sizeof(pst_item_attach));
1304 memset(attach, 0, sizeof(pst_item_attach)); 1325 memset(attach, 0, sizeof(pst_item_attach));
1305 attach->next = item->attach; 1326 attach->next = item->attach;
1306 item->attach = attach; 1327 item->attach = attach;
1307 attach->data = item->email->encrypted_body; 1328 attach->data.data = item->email->encrypted_body.data;
1308 attach->size = item->email->encrypted_body_size; 1329 attach->data.size = item->email->encrypted_body.size;
1309 item->email->encrypted_body = NULL; 1330 item->email->encrypted_body.data = NULL;
1310 } 1331 }
1311 1332
1312 if (item->email->encrypted_htmlbody) { 1333 if (item->email->encrypted_htmlbody.data) {
1313 pst_item_attach* attach = (pst_item_attach*)xmalloc(sizeof(pst_item_attach)); 1334 pst_item_attach* attach = (pst_item_attach*)xmalloc(sizeof(pst_item_attach));
1314 DEBUG_EMAIL(("Adding encrypted HTML body as attachment\n")); 1335 DEBUG_EMAIL(("Adding encrypted HTML body as attachment\n"));
1315 attach = (pst_item_attach*) xmalloc(sizeof(pst_item_attach)); 1336 attach = (pst_item_attach*) xmalloc(sizeof(pst_item_attach));
1316 memset(attach, 0, sizeof(pst_item_attach)); 1337 memset(attach, 0, sizeof(pst_item_attach));
1317 attach->next = item->attach; 1338 attach->next = item->attach;
1318 item->attach = attach; 1339 item->attach = attach;
1319 attach->data = item->email->encrypted_htmlbody; 1340 attach->data.data = item->email->encrypted_htmlbody.data;
1320 attach->size = item->email->encrypted_htmlbody_size; 1341 attach->data.size = item->email->encrypted_htmlbody.size;
1321 item->email->encrypted_htmlbody = NULL; 1342 item->email->encrypted_htmlbody.data = NULL;
1322 } 1343 }
1323 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"); 1344 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");
1324 } 1345 }
1325 1346
1326 // other attachments 1347 // other attachments
1330 for (attach = item->attach; attach; attach = attach->next) { 1351 for (attach = item->attach; attach; attach = attach->next) {
1331 pst_convert_utf8_null(item, &attach->filename1); 1352 pst_convert_utf8_null(item, &attach->filename1);
1332 pst_convert_utf8_null(item, &attach->filename2); 1353 pst_convert_utf8_null(item, &attach->filename2);
1333 pst_convert_utf8_null(item, &attach->mimetype); 1354 pst_convert_utf8_null(item, &attach->mimetype);
1334 DEBUG_EMAIL(("Attempting Attachment encoding\n")); 1355 DEBUG_EMAIL(("Attempting Attachment encoding\n"));
1335 if (!attach->data && attach->mimetype.str && !strcmp(attach->mimetype.str, RFC822)) { 1356 if (!attach->data.data && attach->mimetype.str && !strcmp(attach->mimetype.str, RFC822)) {
1336 DEBUG_EMAIL(("seem to have special embedded message attachment\n")); 1357 DEBUG_EMAIL(("seem to have special embedded message attachment\n"));
1337 find_rfc822_headers(extra_mime_headers); 1358 find_rfc822_headers(extra_mime_headers);
1338 write_embedded_message(f_output, attach, boundary, pst, extra_mime_headers); 1359 write_embedded_message(f_output, attach, boundary, pst, extra_mime_headers);
1339 } 1360 }
1340 else if (attach->data || attach->i_id) { 1361 else if (attach->data.data || attach->i_id) {
1341 if (mode == MODE_SEPARATE && !mode_MH) 1362 if (mode == MODE_SEPARATE && !mode_MH)
1342 write_separate_attachment(f_name, attach, ++attach_num, pst); 1363 write_separate_attachment(f_name, attach, ++attach_num, pst);
1343 else 1364 else
1344 write_inline_attachment(f_output, attach, boundary, pst); 1365 write_inline_attachment(f_output, attach, boundary, pst);
1345 } 1366 }
1583 1604
1584 1605
1585 void create_enter_dir(struct file_ll* f, pst_item *item) 1606 void create_enter_dir(struct file_ll* f, pst_item *item)
1586 { 1607 {
1587 pst_convert_utf8(item, &item->file_as); 1608 pst_convert_utf8(item, &item->file_as);
1588 f->email_count = 0; 1609 f->item_count = 0;
1589 f->skip_count = 0; 1610 f->skip_count = 0;
1590 f->type = item->type; 1611 f->type = item->type;
1591 f->stored_count = (item->folder) ? item->folder->email_count : 0; 1612 f->stored_count = (item->folder) ? item->folder->item_count : 0;
1592 1613
1593 DEBUG_ENT("create_enter_dir"); 1614 DEBUG_ENT("create_enter_dir");
1594 if (mode == MODE_KMAIL) 1615 if (mode == MODE_KMAIL)
1595 f->name = mk_kmail_dir(item->file_as.str); 1616 f->name = mk_kmail_dir(item->file_as.str);
1596 else if (mode == MODE_RECURSE) 1617 else if (mode == MODE_RECURSE)
1598 else if (mode == MODE_SEPARATE) { 1619 else if (mode == MODE_SEPARATE) {
1599 // do similar stuff to recurse here. 1620 // do similar stuff to recurse here.
1600 mk_separate_dir(item->file_as.str); 1621 mk_separate_dir(item->file_as.str);
1601 f->name = (char*) xmalloc(10); 1622 f->name = (char*) xmalloc(10);
1602 memset(f->name, 0, 10); 1623 memset(f->name, 0, 10);
1603 // sprintf(f->name, SEP_MAIL_FILE_TEMPLATE, f->email_count);
1604 } else { 1624 } else {
1605 f->name = (char*) xmalloc(strlen(item->file_as.str)+strlen(OUTPUT_TEMPLATE)+1); 1625 f->name = (char*) xmalloc(strlen(item->file_as.str)+strlen(OUTPUT_TEMPLATE)+1);
1606 sprintf(f->name, OUTPUT_TEMPLATE, item->file_as.str); 1626 sprintf(f->name, OUTPUT_TEMPLATE, item->file_as.str);
1607 } 1627 }
1608 1628
1645 } 1665 }
1646 1666
1647 1667
1648 void close_enter_dir(struct file_ll *f) 1668 void close_enter_dir(struct file_ll *f)
1649 { 1669 {
1650 DEBUG_MAIN(("main: Email Count for folder %s is %i\n", f->dname, f->email_count)); 1670 DEBUG_MAIN(("main: processed item count for folder %s is %i, skipped %i, total %i \n",
1671 f->dname, f->item_count, f->skip_count, f->stored_count));
1651 if (output_mode != OUTPUT_QUIET) 1672 if (output_mode != OUTPUT_QUIET)
1652 printf("\t\"%s\" - %i items done, skipped %i, should have been %i\n", 1673 printf("\t\"%s\" - %i items done.\n", f->dname, f->item_count);
1653 f->dname, f->email_count, f->skip_count, f->stored_count);
1654 if (f->output) fclose(f->output); 1674 if (f->output) fclose(f->output);
1655 free(f->name); 1675 free(f->name);
1656 free(f->dname); 1676 free(f->dname);
1657 1677
1658 if (mode == MODE_KMAIL) 1678 if (mode == MODE_KMAIL)