Mercurial > libpst
comparison readpst.c @ 1:43e8802f08c5 debian libpst_0_5_1
imported from debian 0.5.1
author | carl |
---|---|
date | Thu, 23 Dec 2004 11:17:37 -0800 |
parents | 6b1b602514db |
children |
comparison
equal
deleted
inserted
replaced
0:6b1b602514db | 1:43e8802f08c5 |
---|---|
2 * readpst.c | 2 * readpst.c |
3 * Part of the LibPST project | 3 * Part of the LibPST project |
4 * Written by David Smith | 4 * Written by David Smith |
5 * dave.s@earthcorp.com | 5 * dave.s@earthcorp.com |
6 */ | 6 */ |
7 // Includes {{{1 | |
7 #include <stdio.h> | 8 #include <stdio.h> |
8 #include <stdlib.h> | 9 #include <stdlib.h> |
9 #include <time.h> | 10 #include <time.h> |
10 #include <string.h> | 11 #include <string.h> |
11 #include <ctype.h> | 12 #include <ctype.h> |
34 #include "define.h" | 35 #include "define.h" |
35 #include "libpst.h" | 36 #include "libpst.h" |
36 #include "common.h" | 37 #include "common.h" |
37 #include "timeconv.h" | 38 #include "timeconv.h" |
38 #include "lzfu.h" | 39 #include "lzfu.h" |
39 | 40 // }}}1 |
41 // Defines {{{1 | |
40 #define OUTPUT_TEMPLATE "%s" | 42 #define OUTPUT_TEMPLATE "%s" |
41 #define OUTPUT_KMAIL_DIR_TEMPLATE ".%s.directory" | 43 #define OUTPUT_KMAIL_DIR_TEMPLATE ".%s.directory" |
42 #define KMAIL_INDEX ".%s.index" | 44 #define KMAIL_INDEX ".%s.index" |
43 | 45 |
44 #define VERSION "0.5" | 46 #define VERSION "0.5.1" |
45 // max size of the c_time char*. It will store the date of the email | 47 // max size of the c_time char*. It will store the date of the email |
46 #define C_TIME_SIZE 500 | 48 #define C_TIME_SIZE 500 |
47 #define PERM_DIRS 0777 | 49 #define PERM_DIRS 0777 |
48 | 50 |
49 // macro used for creating directories | 51 // macro used for creating directories |
50 #ifndef WIN32 | 52 #ifndef WIN32 |
51 #define D_MKDIR(x) mkdir(x, PERM_DIRS) | 53 #define D_MKDIR(x) mkdir(x, PERM_DIRS) |
52 #else | 54 #else |
53 #define D_MKDIR(x) mkdir(x) | 55 #define D_MKDIR(x) mkdir(x) |
54 #endif | 56 #endif |
55 | 57 // }}}1 |
58 // struct file_ll {{{1 | |
56 struct file_ll { | 59 struct file_ll { |
57 char *name; | 60 char *name; |
58 char *dname; | 61 char *dname; |
59 FILE * output; | 62 FILE * output; |
60 int32_t stored_count; | 63 int32_t stored_count; |
61 int32_t email_count; | 64 int32_t email_count; |
62 int32_t skip_count; | 65 int32_t skip_count; |
63 int32_t type; | 66 int32_t type; |
64 struct file_ll *next; | 67 struct file_ll *next; |
65 }; | 68 }; |
66 | 69 // }}}1 |
67 | 70 // Function Declarations {{{1 |
68 void write_email_body(FILE *f, char *body); | 71 void write_email_body(FILE *f, char *body); |
69 char *removeCR (char *c); | 72 char *removeCR (char *c); |
70 int32_t usage(); | 73 int32_t usage(); |
71 int32_t version(); | 74 int32_t version(); |
72 char *mk_kmail_dir(char*); | 75 char *mk_kmail_dir(char*); |
80 char *check_filename(char *fname); | 83 char *check_filename(char *fname); |
81 char *rfc2426_escape(char *str); | 84 char *rfc2426_escape(char *str); |
82 int32_t chr_count(char *str, char x); | 85 int32_t chr_count(char *str, char x); |
83 char *rfc2425_datetime_format(FILETIME *ft); | 86 char *rfc2425_datetime_format(FILETIME *ft); |
84 char *rfc2445_datetime_format(FILETIME *ft); | 87 char *rfc2445_datetime_format(FILETIME *ft); |
85 | 88 char *skip_header_prologue(char *headers); |
89 // }}}1 | |
90 // Global Variables {{{1 | |
86 char *prog_name; | 91 char *prog_name; |
87 char *output_dir = "."; | 92 char *output_dir = "."; |
88 | 93 char *kmail_chdir = NULL; |
94 // }}}1 | |
95 // More Defines {{{1 | |
89 // Normal mode just creates mbox format files in the current directory. Each file is named | 96 // Normal mode just creates mbox format files in the current directory. Each file is named |
90 // the same as the folder's name that it represents | 97 // the same as the folder's name that it represents |
91 #define MODE_NORMAL 0 | 98 #define MODE_NORMAL 0 |
92 // KMail mode creates a directory structure suitable for being used directly | 99 // KMail mode creates a directory structure suitable for being used directly |
93 // by the KMail application | 100 // by the KMail application |
117 // output settings for RTF bodies | 124 // output settings for RTF bodies |
118 // filename for the attachment | 125 // filename for the attachment |
119 #define RTF_ATTACH_NAME "rtf-body.rtf" | 126 #define RTF_ATTACH_NAME "rtf-body.rtf" |
120 // mime type for the attachment | 127 // mime type for the attachment |
121 #define RTF_ATTACH_TYPE "application/rtf" | 128 #define RTF_ATTACH_TYPE "application/rtf" |
122 | 129 // }}}1 |
130 // int main(int argc, char** argv) {{{1 | |
123 int main(int argc, char** argv) { | 131 int main(int argc, char** argv) { |
132 // declarations {{{2 | |
124 pst_item *item = NULL; | 133 pst_item *item = NULL; |
125 pst_file pstfile; | 134 pst_file pstfile; |
126 pst_desc_ll *d_ptr; | 135 pst_desc_ll *d_ptr; |
127 char * fname = NULL; | 136 char * fname = NULL; |
128 time_t em_time; | 137 time_t em_time; |
140 char *temp = NULL; //temporary char pointer | 149 char *temp = NULL; //temporary char pointer |
141 int attach_num = 0; | 150 int attach_num = 0; |
142 int skip_child = 0; | 151 int skip_child = 0; |
143 struct file_ll *f, *head; | 152 struct file_ll *f, *head; |
144 prog_name = argv[0]; | 153 prog_name = argv[0]; |
154 // }}}2 | |
145 | 155 |
146 while ((c = getopt(argc, argv, "d:hko:qrSVwc:"))!= -1) { | 156 while ((c = getopt(argc, argv, "d:hko:qrSVwc:"))!= -1) { |
147 switch (c) { | 157 switch (c) { |
148 case 'c': | 158 case 'c': |
149 if (optarg!=NULL && optarg[0]=='v') | 159 if (optarg!=NULL && optarg[0]=='v') |
189 exit(1); | 199 exit(1); |
190 break; | 200 break; |
191 } | 201 } |
192 } | 202 } |
193 | 203 |
204 #ifdef DEBUG_ALL | |
205 // initialize log file | |
194 if (d_log == NULL) | 206 if (d_log == NULL) |
195 d_log = "readpst.log"; | 207 d_log = "readpst.log"; |
196 DEBUG_INIT(d_log); | 208 DEBUG_INIT(d_log); |
197 DEBUG_REGISTER_CLOSE(); | 209 DEBUG_REGISTER_CLOSE(); |
210 #endif // defined DEBUG_ALL | |
211 | |
198 DEBUG_ENT("main"); | 212 DEBUG_ENT("main"); |
199 | 213 |
200 if (argc > optind) { | 214 if (argc > optind) { |
201 fname = argv[optind]; | 215 fname = argv[optind]; |
202 } else { | 216 } else { |
338 // there should only be one message_store, and we have already done it | 352 // there should only be one message_store, and we have already done it |
339 DIE(("main: A second message_store has been found. Sorry, this must be an error.\n")); | 353 DIE(("main: A second message_store has been found. Sorry, this must be an error.\n")); |
340 } | 354 } |
341 | 355 |
342 | 356 |
343 if (item->folder != NULL) { //if this is a folder, we want to recurse into it | 357 if (item->folder != NULL) { |
358 // Process Folder item {{{2 | |
359 // 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); | 360 if (output_mode != OUTPUT_QUIET) printf("Processing Folder \"%s\"\n", item->file_as); |
345 // f->email_count++; | 361 // f->email_count++; |
346 DEBUG_MAIN(("main: I think I may try to go into folder \"%s\"\n", item->file_as)); | 362 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)); | 363 f = (struct file_ll*) malloc(sizeof(struct file_ll)); |
348 memset(f, 0, sizeof(struct file_ll)); | 364 memset(f, 0, sizeof(struct file_ll)); |
428 f = head; | 444 f = head; |
429 } | 445 } |
430 _pst_freeItem(item); | 446 _pst_freeItem(item); |
431 item = NULL; // just for the odd situations! | 447 item = NULL; // just for the odd situations! |
432 goto check_parent; | 448 goto check_parent; |
449 // }}}2 | |
433 } else if (item->contact != NULL) { | 450 } else if (item->contact != NULL) { |
451 // Process Contact item {{{2 | |
434 // deal with a contact | 452 // deal with a contact |
435 // write them to the file, one per line in this format | 453 // write them to the file, one per line in this format |
436 // Desc Name <email@address>\n | 454 // Desc Name <email@address>\n |
437 if (mode == MODE_SEPERATE) { | 455 if (mode == MODE_SEPERATE) { |
438 mk_seperate_file(f); | 456 mk_seperate_file(f); |
556 fprintf(f->output, "END:VCARD\n\n"); | 574 fprintf(f->output, "END:VCARD\n\n"); |
557 } else { | 575 } else { |
558 fprintf(f->output, "%s <%s>\n", item->contact->fullname, item->contact->address1); | 576 fprintf(f->output, "%s <%s>\n", item->contact->fullname, item->contact->address1); |
559 } | 577 } |
560 } | 578 } |
579 // }}}2 | |
561 } else if (item->email != NULL && | 580 } else if (item->email != NULL && |
562 (item->type == PST_TYPE_NOTE || item->type == PST_TYPE_REPORT)) { | 581 (item->type == PST_TYPE_NOTE || item->type == PST_TYPE_REPORT)) { |
582 // Process Email item {{{2 | |
563 if (mode == MODE_SEPERATE) { | 583 if (mode == MODE_SEPERATE) { |
564 mk_seperate_file(f); | 584 mk_seperate_file(f); |
565 } | 585 } |
566 | 586 |
567 f->email_count++; | 587 f->email_count++; |
671 temp += 2; // get past the \n\n | 691 temp += 2; // get past the \n\n |
672 *temp = '\0'; | 692 *temp = '\0'; |
673 } | 693 } |
674 | 694 |
675 if (mode != MODE_SEPERATE) { | 695 if (mode != MODE_SEPERATE) { |
696 char *soh = NULL; // real start of headers. | |
676 // don't put rubbish in if we are doing seperate | 697 // don't put rubbish in if we are doing seperate |
677 fprintf(f->output, "From \"%s\" %s\n%s\n", | 698 fprintf(f->output, "From \"%s\" %s\n", item->email->outlook_sender_name, c_time); |
678 item->email->outlook_sender_name, c_time, item->email->header); | 699 soh = skip_header_prologue(item->email->header); |
679 fprintf(f->output, "\n"); | 700 fprintf(f->output, "%s\n\n", soh); |
680 } else { | 701 } else { |
681 fprintf(f->output, "%s\n", item->email->header); | 702 fprintf(f->output, "%s\n", item->email->header); |
682 } | 703 } |
683 } else { | 704 } else { |
684 //make up our own header! | 705 //make up our own header! |
880 DEBUG_MAIN(("main: Writing buffer between emails\n")); | 901 DEBUG_MAIN(("main: Writing buffer between emails\n")); |
881 if (boundary) | 902 if (boundary) |
882 fprintf(f->output, "\n--%s--\n", boundary); | 903 fprintf(f->output, "\n--%s--\n", boundary); |
883 fprintf(f->output, "\n\n"); | 904 fprintf(f->output, "\n\n"); |
884 } | 905 } |
906 // }}}2 | |
885 } else if (item->type == PST_TYPE_JOURNAL) { | 907 } else if (item->type == PST_TYPE_JOURNAL) { |
908 // Process Journal item {{{2 | |
886 // deal with journal items | 909 // deal with journal items |
887 if (mode == MODE_SEPERATE) { | 910 if (mode == MODE_SEPERATE) { |
888 mk_seperate_file(f); | 911 mk_seperate_file(f); |
889 } | 912 } |
890 f->email_count++; | 913 f->email_count++; |
904 if (item->email->body != NULL) | 927 if (item->email->body != NULL) |
905 fprintf(f->output, "DESCRIPTION:%s\n", rfc2426_escape(item->email->body)); | 928 fprintf(f->output, "DESCRIPTION:%s\n", rfc2426_escape(item->email->body)); |
906 if (item->journal->start != NULL) | 929 if (item->journal->start != NULL) |
907 fprintf(f->output, "DTSTART;VALUE=DATE-TIME:%s\n", rfc2445_datetime_format(item->journal->start)); | 930 fprintf(f->output, "DTSTART;VALUE=DATE-TIME:%s\n", rfc2445_datetime_format(item->journal->start)); |
908 fprintf(f->output, "END:VJOURNAL\n\n"); | 931 fprintf(f->output, "END:VJOURNAL\n\n"); |
932 // }}}2 | |
909 } else if (item->type == PST_TYPE_APPOINTMENT) { | 933 } else if (item->type == PST_TYPE_APPOINTMENT) { |
934 // Process Calendar Appointment item {{{2 | |
910 // deal with Calendar appointments | 935 // deal with Calendar appointments |
911 if (mode == MODE_SEPERATE) { | 936 if (mode == MODE_SEPERATE) { |
912 mk_seperate_file(f); | 937 mk_seperate_file(f); |
913 } | 938 } |
914 f->email_count++; | 939 f->email_count++; |
969 case PST_APP_LABEL_PHONE_CALL: | 994 case PST_APP_LABEL_PHONE_CALL: |
970 fprintf(f->output, "CATEGORIES:PHONE-CALL\n"); break; | 995 fprintf(f->output, "CATEGORIES:PHONE-CALL\n"); break; |
971 } | 996 } |
972 } | 997 } |
973 fprintf(f->output, "END:VEVENT\n\n"); | 998 fprintf(f->output, "END:VEVENT\n\n"); |
999 // }}}2 | |
974 } else { | 1000 } else { |
975 f->skip_count++; | 1001 f->skip_count++; |
976 DEBUG_MAIN(("main: Unknown item type. %i. Ascii1=\"%s\"\n", | 1002 DEBUG_MAIN(("main: Unknown item type. %i. Ascii1=\"%s\"\n", |
977 item->type, item->ascii_type)); | 1003 item->type, item->ascii_type)); |
978 } | 1004 } |
979 } else { | 1005 } else { |
980 f->skip_count++; | 1006 f->skip_count++; |
981 DEBUG_MAIN(("main: A NULL item was seen\n")); | 1007 DEBUG_MAIN(("main: A NULL item was seen\n")); |
982 } | 1008 } |
1009 | |
983 DEBUG_MAIN(("main: Going to next d_ptr\n")); | 1010 DEBUG_MAIN(("main: Going to next d_ptr\n")); |
984 if (boundary) { | 1011 if (boundary) { |
985 free(boundary); | 1012 free(boundary); |
986 boundary = NULL; | 1013 boundary = NULL; |
987 } | 1014 } |
1015 | |
988 check_parent: | 1016 check_parent: |
989 // _pst_freeItem(item); | 1017 // _pst_freeItem(item); |
990 while (!skip_child && d_ptr->next == NULL && d_ptr->parent != NULL) { | 1018 while (!skip_child && d_ptr->next == NULL && d_ptr->parent != NULL) { |
991 DEBUG_MAIN(("main: Going to Parent\n")); | 1019 DEBUG_MAIN(("main: Going to Parent\n")); |
992 head = f->next; | 1020 head = f->next; |
1017 if (item != NULL) { | 1045 if (item != NULL) { |
1018 DEBUG_MAIN(("main: Freeing memory used by item\n")); | 1046 DEBUG_MAIN(("main: Freeing memory used by item\n")); |
1019 _pst_freeItem(item); | 1047 _pst_freeItem(item); |
1020 item = NULL; | 1048 item = NULL; |
1021 } | 1049 } |
1050 | |
1022 if (!skip_child) | 1051 if (!skip_child) |
1023 d_ptr = d_ptr->next; | 1052 d_ptr = d_ptr->next; |
1024 else | 1053 else |
1025 skip_child = 0; | 1054 skip_child = 0; |
1026 | 1055 |
1027 if (d_ptr == NULL) { | 1056 if (d_ptr == NULL) { |
1028 DEBUG_MAIN(("main: d_ptr is now NULL\n")); | 1057 DEBUG_MAIN(("main: d_ptr is now NULL\n")); |
1029 } | 1058 } |
1030 } | 1059 } |
1031 if (output_mode != OUTPUT_QUIET) printf("Finished.\n"); | 1060 if (output_mode != OUTPUT_QUIET) printf("Finished.\n"); |
1032 | |
1033 DEBUG_MAIN(("main: Finished.\n")); | 1061 DEBUG_MAIN(("main: Finished.\n")); |
1062 | |
1063 // Cleanup {{{2 | |
1034 pst_close(&pstfile); | 1064 pst_close(&pstfile); |
1035 // fclose(pstfile.fp); | 1065 // fclose(pstfile.fp); |
1036 while (f != NULL) { | 1066 while (f != NULL) { |
1037 if (f->output != NULL) | 1067 if (f->output != NULL) |
1038 fclose(f->output); | 1068 fclose(f->output); |
1050 free (f); | 1080 free (f); |
1051 f = head; | 1081 f = head; |
1052 } | 1082 } |
1053 | 1083 |
1054 DEBUG_RET(); | 1084 DEBUG_RET(); |
1085 // }}}2 | |
1086 | |
1055 return 0; | 1087 return 0; |
1056 } | 1088 } |
1057 | 1089 // }}}1 |
1090 // void write_email_body(FILE *f, char *body) {{{1 | |
1058 void write_email_body(FILE *f, char *body) { | 1091 void write_email_body(FILE *f, char *body) { |
1059 char *n = body; | 1092 char *n = body; |
1060 // DEBUG_MAIN(("write_email_body(): \"%s\"\n", body)); | 1093 // DEBUG_MAIN(("write_email_body(): \"%s\"\n", body)); |
1061 DEBUG_ENT("write_email_body"); | 1094 DEBUG_ENT("write_email_body"); |
1062 while (n != NULL) { | 1095 while (n != NULL) { |
1070 } | 1103 } |
1071 } | 1104 } |
1072 fwrite(body, strlen(body), 1, f); | 1105 fwrite(body, strlen(body), 1, f); |
1073 DEBUG_RET(); | 1106 DEBUG_RET(); |
1074 } | 1107 } |
1075 | 1108 // }}}1 |
1076 char * removeCR (char *c) { | 1109 // char *removeCR (char *c) {{{1 |
1110 char *removeCR (char *c) { | |
1077 // converts /r/n to /n | 1111 // converts /r/n to /n |
1078 char *a, *b; | 1112 char *a, *b; |
1079 DEBUG_ENT("removeCR"); | 1113 DEBUG_ENT("removeCR"); |
1080 a = b = c; | 1114 a = b = c; |
1081 while (*a != '\0') { | 1115 while (*a != '\0') { |
1086 } | 1120 } |
1087 *b = '\0'; | 1121 *b = '\0'; |
1088 DEBUG_RET(); | 1122 DEBUG_RET(); |
1089 return c; | 1123 return c; |
1090 } | 1124 } |
1091 | 1125 // }}}1 |
1126 // int usage() {{{1 | |
1092 int usage() { | 1127 int usage() { |
1093 DEBUG_ENT("usage"); | 1128 DEBUG_ENT("usage"); |
1094 version(); | 1129 version(); |
1095 printf("Usage: %s [OPTIONS] {PST FILENAME}\n", prog_name); | 1130 printf("Usage: %s [OPTIONS] {PST FILENAME}\n", prog_name); |
1096 printf("OPTIONS:\n"); | 1131 printf("OPTIONS:\n"); |
1105 printf("\t-V\t- Version. Display program version\n"); | 1140 printf("\t-V\t- Version. Display program version\n"); |
1106 printf("\t-w\t- Overwrite any output mbox files\n"); | 1141 printf("\t-w\t- Overwrite any output mbox files\n"); |
1107 DEBUG_RET(); | 1142 DEBUG_RET(); |
1108 return 0; | 1143 return 0; |
1109 } | 1144 } |
1110 | 1145 // }}}1 |
1146 // int version() {{{1 | |
1111 int version() { | 1147 int version() { |
1112 DEBUG_ENT("version"); | 1148 DEBUG_ENT("version"); |
1113 printf("ReadPST v%s implementing LibPST v%s\n", VERSION, PST_VERSION); | 1149 printf("ReadPST v%s implementing LibPST v%s\n", VERSION, PST_VERSION); |
1114 #if BYTE_ORDER == BIG_ENDIAN | 1150 #if BYTE_ORDER == BIG_ENDIAN |
1115 printf("Big Endian implementation being used.\n"); | 1151 printf("Big Endian implementation being used.\n"); |
1122 printf("GCC %d.%d : %s %s\n", __GNUC__, __GNUC_MINOR__, __DATE__, __TIME__); | 1158 printf("GCC %d.%d : %s %s\n", __GNUC__, __GNUC_MINOR__, __DATE__, __TIME__); |
1123 #endif | 1159 #endif |
1124 DEBUG_RET(); | 1160 DEBUG_RET(); |
1125 return 0; | 1161 return 0; |
1126 } | 1162 } |
1127 | 1163 // }}}1 |
1128 char *kmail_chdir = NULL; | 1164 // char *mk_kmail_dir(char *fname) {{{1 |
1129 | 1165 char *mk_kmail_dir(char *fname) { |
1130 char* mk_kmail_dir(char *fname) { | |
1131 //change to that directory | 1166 //change to that directory |
1132 //make a directory based on OUTPUT_KMAIL_DIR_TEMPLATE | 1167 //make a directory based on OUTPUT_KMAIL_DIR_TEMPLATE |
1133 //allocate space for OUTPUT_TEMPLATE and form a char* with fname | 1168 //allocate space for OUTPUT_TEMPLATE and form a char* with fname |
1134 //return that value | 1169 //return that value |
1135 char *dir, *out_name, *index; | 1170 char *dir, *out_name, *index; |
1162 out_name = malloc(strlen(fname)+strlen(OUTPUT_TEMPLATE)+1); | 1197 out_name = malloc(strlen(fname)+strlen(OUTPUT_TEMPLATE)+1); |
1163 sprintf(out_name, OUTPUT_TEMPLATE, fname); | 1198 sprintf(out_name, OUTPUT_TEMPLATE, fname); |
1164 DEBUG_RET(); | 1199 DEBUG_RET(); |
1165 return out_name; | 1200 return out_name; |
1166 } | 1201 } |
1167 | 1202 // }}}1 |
1203 // int close_kmail_dir() {{{1 | |
1168 int close_kmail_dir() { | 1204 int close_kmail_dir() { |
1169 // change .. | 1205 // change .. |
1170 int x; | 1206 int x; |
1171 DEBUG_ENT("close_kmail_dir"); | 1207 DEBUG_ENT("close_kmail_dir"); |
1172 if (kmail_chdir != NULL) { //only free kmail_chdir if not NULL. do not change directory | 1208 if (kmail_chdir != NULL) { //only free kmail_chdir if not NULL. do not change directory |
1179 } | 1215 } |
1180 } | 1216 } |
1181 DEBUG_RET(); | 1217 DEBUG_RET(); |
1182 return 0; | 1218 return 0; |
1183 } | 1219 } |
1184 | 1220 // }}}1 |
1185 char* mk_recurse_dir(char *dir) { | 1221 // char *mk_recurse_dir(char *dir) {{{1 |
1186 // this will create a directory by that name, then make an mbox file inside that dir. | 1222 // this will create a directory by that name, then make an mbox file inside |
1187 // any subsequent dirs will be created by name, and they will contain mbox files | 1223 // that dir. any subsequent dirs will be created by name, and they will |
1224 // contain mbox files | |
1225 char *mk_recurse_dir(char *dir) { | |
1188 int x; | 1226 int x; |
1189 char *out_name; | 1227 char *out_name; |
1190 DEBUG_ENT("mk_recurse_dir"); | 1228 DEBUG_ENT("mk_recurse_dir"); |
1191 dir = check_filename(dir); | 1229 dir = check_filename(dir); |
1192 if (D_MKDIR (dir)) { | 1230 if (D_MKDIR (dir)) { |
1202 out_name = malloc(strlen("mbox")+1); | 1240 out_name = malloc(strlen("mbox")+1); |
1203 strcpy(out_name, "mbox"); | 1241 strcpy(out_name, "mbox"); |
1204 DEBUG_RET(); | 1242 DEBUG_RET(); |
1205 return out_name; | 1243 return out_name; |
1206 } | 1244 } |
1207 | 1245 // }}}1 |
1246 // int close_recurse_dir() {{{1 | |
1208 int close_recurse_dir() { | 1247 int close_recurse_dir() { |
1209 int x; | 1248 int x; |
1210 DEBUG_ENT("close_recurse_dir"); | 1249 DEBUG_ENT("close_recurse_dir"); |
1211 if (chdir("..")) { | 1250 if (chdir("..")) { |
1212 x = errno; | 1251 x = errno; |
1213 DIE(("close_recurse_dir: Cannot go up dir (..): %s\n", strerror(x))); | 1252 DIE(("close_recurse_dir: Cannot go up dir (..): %s\n", strerror(x))); |
1214 } | 1253 } |
1215 DEBUG_RET(); | 1254 DEBUG_RET(); |
1216 return 0; | 1255 return 0; |
1217 } | 1256 } |
1218 | 1257 // }}}1 |
1219 char* mk_seperate_dir(char *dir, int overwrite) { | 1258 // char *mk_seperate_dir(char *dir, int overwrite) {{{1 |
1259 char *mk_seperate_dir(char *dir, int overwrite) { | |
1220 #if !defined(WIN32) && !defined(__CYGWIN__) | 1260 #if !defined(WIN32) && !defined(__CYGWIN__) |
1221 DIR * sdir = NULL; | 1261 DIR * sdir = NULL; |
1222 struct dirent *dirent = NULL; | 1262 struct dirent *dirent = NULL; |
1223 struct stat *filestat = xmalloc(sizeof(struct stat)); | 1263 struct stat *filestat = xmalloc(sizeof(struct stat)); |
1224 #endif | 1264 #endif |
1280 | 1320 |
1281 // we don't return a filename here cause it isn't necessary. | 1321 // we don't return a filename here cause it isn't necessary. |
1282 DEBUG_RET(); | 1322 DEBUG_RET(); |
1283 return NULL; | 1323 return NULL; |
1284 } | 1324 } |
1285 | 1325 // }}}1 |
1326 // int close_seperate_dir() {{{1 | |
1286 int close_seperate_dir() { | 1327 int close_seperate_dir() { |
1287 int x; | 1328 int x; |
1288 DEBUG_ENT("close_seperate_dir"); | 1329 DEBUG_ENT("close_seperate_dir"); |
1289 if (chdir("..")) { | 1330 if (chdir("..")) { |
1290 x = errno; | 1331 x = errno; |
1291 DIE(("close_seperate_dir: Cannot go up dir (..): %s\n", strerror(x))); | 1332 DIE(("close_seperate_dir: Cannot go up dir (..): %s\n", strerror(x))); |
1292 } | 1333 } |
1293 DEBUG_RET(); | 1334 DEBUG_RET(); |
1294 return 0; | 1335 return 0; |
1295 } | 1336 } |
1296 | 1337 // }}}1 |
1338 // int mk_seperate_file(struct file_ll *f) {{{1 | |
1297 int mk_seperate_file(struct file_ll *f) { | 1339 int mk_seperate_file(struct file_ll *f) { |
1298 DEBUG_ENT("mk_seperate_file"); | 1340 DEBUG_ENT("mk_seperate_file"); |
1299 DEBUG_MAIN(("mk_seperate_file: opening next file to save email\n")); | 1341 DEBUG_MAIN(("mk_seperate_file: opening next file to save email\n")); |
1300 if (f->email_count > 999999999) { // bigger than nine 9's | 1342 if (f->email_count > 999999999) { // bigger than nine 9's |
1301 DIE(("mk_seperate_file: The number of emails in this folder has become too high to handle")); | 1343 DIE(("mk_seperate_file: The number of emails in this folder has become too high to handle")); |
1309 DIE(("mk_seperate_file: Cannot open file to save email \"%s\"\n", f->name)); | 1351 DIE(("mk_seperate_file: Cannot open file to save email \"%s\"\n", f->name)); |
1310 } | 1352 } |
1311 DEBUG_RET(); | 1353 DEBUG_RET(); |
1312 return 0; | 1354 return 0; |
1313 } | 1355 } |
1314 | 1356 // }}}1 |
1357 // char *my_stristr(char *haystack, char *needle) {{{1 | |
1358 char *my_stristr(char *haystack, char *needle) { | |
1315 // my_stristr varies from strstr in that its searches are case-insensitive | 1359 // my_stristr varies from strstr in that its searches are case-insensitive |
1316 char * my_stristr(char *haystack, char *needle) { | |
1317 char *x=haystack, *y=needle, *z = NULL; | 1360 char *x=haystack, *y=needle, *z = NULL; |
1318 DEBUG_ENT("my_stristr"); | 1361 DEBUG_ENT("my_stristr"); |
1319 if (haystack == NULL || needle == NULL) | 1362 if (haystack == NULL || needle == NULL) |
1320 return NULL; | 1363 return NULL; |
1321 while (*y != '\0' && *x != '\0') { | 1364 while (*y != '\0' && *x != '\0') { |
1332 x++; // advance the search in the haystack | 1375 x++; // advance the search in the haystack |
1333 } | 1376 } |
1334 DEBUG_RET(); | 1377 DEBUG_RET(); |
1335 return z; | 1378 return z; |
1336 } | 1379 } |
1337 | 1380 // }}}1 |
1381 // char *check_filename(char *fname) {{{1 | |
1338 char *check_filename(char *fname) { | 1382 char *check_filename(char *fname) { |
1339 char *t = fname; | 1383 char *t = fname; |
1340 DEBUG_ENT("check_filename"); | 1384 DEBUG_ENT("check_filename"); |
1341 if (t == NULL) { | 1385 if (t == NULL) { |
1342 DEBUG_RET(); | 1386 DEBUG_RET(); |
1347 *t = '_'; //replace them with an underscore | 1391 *t = '_'; //replace them with an underscore |
1348 } | 1392 } |
1349 DEBUG_RET(); | 1393 DEBUG_RET(); |
1350 return fname; | 1394 return fname; |
1351 } | 1395 } |
1352 | 1396 // }}}1 |
1397 // char *rfc2426_escape(char *str) {{{1 | |
1353 char *rfc2426_escape(char *str) { | 1398 char *rfc2426_escape(char *str) { |
1354 static char* buf = NULL; | 1399 static char* buf = NULL; |
1355 char *ret, *a, *b; | 1400 char *ret, *a, *b; |
1356 int x = 0, y, z; | 1401 int x = 0, y, z; |
1357 DEBUG_ENT("rfc2426_escape"); | 1402 DEBUG_ENT("rfc2426_escape"); |
1390 ret = buf; | 1435 ret = buf; |
1391 } | 1436 } |
1392 } | 1437 } |
1393 DEBUG_RET(); | 1438 DEBUG_RET(); |
1394 return ret; | 1439 return ret; |
1395 } | 1440 } |
1396 | 1441 // }}}1 |
1442 // int chr_count(char *str, char x) {{{1 | |
1397 int chr_count(char *str, char x) { | 1443 int chr_count(char *str, char x) { |
1398 int r = 0; | 1444 int r = 0; |
1399 while (*str != '\0') { | 1445 while (*str != '\0') { |
1400 if (*str == x) | 1446 if (*str == x) |
1401 r++; | 1447 r++; |
1402 str++; | 1448 str++; |
1403 } | 1449 } |
1404 return r; | 1450 return r; |
1405 } | 1451 } |
1406 | 1452 // }}}1 |
1453 // char *rfc2425_datetime_format(FILETIME *ft) {{{1 | |
1407 char *rfc2425_datetime_format(FILETIME *ft) { | 1454 char *rfc2425_datetime_format(FILETIME *ft) { |
1408 static char * buffer = NULL; | 1455 static char * buffer = NULL; |
1409 struct tm *stm = NULL; | 1456 struct tm *stm = NULL; |
1410 DEBUG_ENT("rfc2425_datetime_format"); | 1457 DEBUG_ENT("rfc2425_datetime_format"); |
1411 if (buffer == NULL) | 1458 if (buffer == NULL) |
1417 DEBUG_INFO(("Problem occured formatting date\n")); | 1464 DEBUG_INFO(("Problem occured formatting date\n")); |
1418 } | 1465 } |
1419 DEBUG_RET(); | 1466 DEBUG_RET(); |
1420 return buffer; | 1467 return buffer; |
1421 } | 1468 } |
1469 // }}}1 | |
1470 // char *rfc2445_datetime_format(FILETIME *ft) {{{1 | |
1422 char *rfc2445_datetime_format(FILETIME *ft) { | 1471 char *rfc2445_datetime_format(FILETIME *ft) { |
1423 static char* buffer = NULL; | 1472 static char* buffer = NULL; |
1424 struct tm *stm = NULL; | 1473 struct tm *stm = NULL; |
1425 DEBUG_ENT("rfc2445_datetime_format"); | 1474 DEBUG_ENT("rfc2445_datetime_format"); |
1426 if (buffer == NULL) | 1475 if (buffer == NULL) |
1430 DEBUG_INFO(("Problem occured formatting date\n")); | 1479 DEBUG_INFO(("Problem occured formatting date\n")); |
1431 } | 1480 } |
1432 DEBUG_RET(); | 1481 DEBUG_RET(); |
1433 return buffer; | 1482 return buffer; |
1434 } | 1483 } |
1484 // }}}1 | |
1485 // char *skip_header_prologue(char *headers) {{{1 | |
1486 // The sole purpose of this function is to bypass the pseudo-header prologue | |
1487 // that Microsoft Outlook inserts at the beginning of the internet email | |
1488 // headers for emails stored in their "Personal Folders" files. | |
1489 char *skip_header_prologue(char *headers) { | |
1490 const char *bad = "Microsoft Mail Internet Headers"; | |
1491 | |
1492 if ( strncmp(headers, bad, strlen(bad)) == 0 ) { | |
1493 // Found the offensive header prologue | |
1494 char *pc; | |
1495 | |
1496 pc = strchr(headers, '\n'); | |
1497 return pc + 1; | |
1498 } | |
1499 | |
1500 return headers; | |
1501 } | |
1502 // }}}1 | |
1503 | |
1504 // vim:sw=4 ts=4: | |
1505 // vim600: set foldlevel=0 foldmethod=marker: |