annotate src/lspst.c @ 16:c508ee15dfca

switch to automake/autoconf
author carl
date Sun, 19 Feb 2006 18:47:46 -0800
parents
children b88ceb81dba2
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
1 /***
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
2 * lspst.c
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
3 * Part of the LibPST project
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
4 * Author: Joe Nahmias <joe@nahmias.net>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
5 * Based on readpst.c by by David Smith <dave.s@earthcorp.com>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
6 *
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
7 */
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
8
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
9 // header file includes {{{1
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
10 #include <stdio.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
11 #include <stdlib.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
12 #include <time.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
13 #include <string.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
14 #include <ctype.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
15 #include <errno.h>
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
16
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
17 #include "libpst.h"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
18 #include "define.h"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
19 #include "timeconv.h"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
20 // }}}1
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
21 // struct file_ll {{{1
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
22 struct file_ll {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
23 char *name;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
24 char *dname;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
25 FILE * output;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
26 int32_t stored_count;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
27 int32_t email_count;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
28 int32_t skip_count;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
29 int32_t type;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
30 struct file_ll *next;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
31 };
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
32 // }}}1
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
33 // Function Declarations {{{1
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
34 void canonicalize_filename(char *fname);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
35 int chr_count(char *str, char x);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
36 void debug_print(char *fmt, ...);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
37 char *rfc2426_escape(char *str);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
38 char *rfc2445_datetime_format(FILETIME *ft);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
39 // }}}1
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
40 #ifndef DEBUG_MAIN
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
41 #define DEBUG_MAIN(x) debug_print x;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
42 #endif
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
43 // int main(int argc, char** argv) {{{1
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
44 int main(int argc, char** argv) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
45
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
46 // declarations {{{2
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
47 pst_item *item = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
48 pst_file pstfile;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
49 pst_desc_ll *d_ptr;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
50 char *temp = NULL; //temporary char pointer
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
51 int skip_child = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
52 struct file_ll *f, *head;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
53 // }}}2
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
54
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
55 if (argc <= 1)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
56 DIE(("Missing PST filename.\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
57
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
58 // Open PST file
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
59 if ( pst_open(&pstfile, argv[1], "r") )
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
60 DIE(("Error opening File\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
61 // Load PST index
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
62 if ( pst_load_index(&pstfile) )
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
63 DIE(("Index Error\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
64 pst_load_extended_attributes(&pstfile);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
65
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
66 d_ptr = pstfile.d_head; // first record is main record
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
67 if ((item = _pst_parse_item(&pstfile, d_ptr)) == NULL || item->message_store == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
68 DIE(("main: Could not get root record\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
69 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
70
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
71 // default the file_as to the same as the main filename if it doesn't exist
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
72 if (item->file_as == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
73 if ((temp = strrchr(argv[1], '/')) == NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
74 if ((temp = strrchr(argv[1], '\\')) == NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
75 temp = argv[1];
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
76 else
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
77 temp++; // get past the "\\"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
78 else
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
79 temp++; // get past the "/"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
80 item->file_as = (char*)xmalloc(strlen(temp)+1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
81 strcpy(item->file_as, temp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
82 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
83 fprintf(stderr, "item->file_as = '%s'.\n", item->file_as);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
84
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
85 // setup head file_ll
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
86 head = (struct file_ll*) malloc(sizeof(struct file_ll));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
87 memset(head, 0, sizeof(struct file_ll));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
88 head->email_count = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
89 head->skip_count = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
90 head->next = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
91 head->name = "mbox";
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
92 head->dname = (char*) malloc(strlen(item->file_as)+1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
93 strcpy(head->dname, item->file_as);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
94 head->type = item->type;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
95 DEBUG_MAIN(("head @ %p: name = '%s', dname = '%s', next = %p.\n", head, head->name, head->dname, head->next));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
96
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
97 if ((d_ptr = pst_getTopOfFolders(&pstfile, item)) == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
98 DIE(("Top of folders record not found. Cannot continue\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
99 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
100 DEBUG_MAIN(("d_ptr(TOF) = %p.\n", d_ptr));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
101
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
102 if (item){
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
103 _pst_freeItem(item);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
104 item = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
105 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
106
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
107 d_ptr = d_ptr->child; // do the children of TOPF
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
108 DEBUG_MAIN(("d_ptr(TOF->child) = %p.\n", d_ptr));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
109
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
110 DEBUG_MAIN(("main: About to do email stuff\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
111 while (d_ptr != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
112 // Process d_ptr {{{2
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
113 DEBUG_MAIN(("main: New item record, d_ptr = %p.\n", d_ptr));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
114 if (d_ptr->desc == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
115 DEBUG_WARN(("main: ERROR ?? item's desc record is NULL\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
116 f->skip_count++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
117 goto check_parent;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
118 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
119 DEBUG_MAIN(("main: Desc Email ID %x [d_ptr->id = %x]\n", d_ptr->desc->id, d_ptr->id));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
120
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
121 item = _pst_parse_item(&pstfile, d_ptr);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
122 DEBUG_MAIN(("main: About to process item @ %p.\n", item));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
123 if (item != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
124
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
125 // there should only be one message_store, and we have already
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
126 // done it
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
127 if (item->message_store != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
128 DIE(("ERROR(main): A second message_store has been found.\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
129 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
130
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
131 if (item->folder != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
132 // Process Folder item {{{3
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
133 // if this is a folder, we want to recurse into it
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
134 printf("Folder");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
135 if (item->file_as != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
136 printf("\t%s/", item->file_as);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
137 printf("\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
138
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
139 DEBUG_MAIN(("main: I think I may try to go into folder \"%s\"\n", item->file_as));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
140 f = (struct file_ll*) malloc(sizeof(struct file_ll));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
141 memset(f, 0, sizeof(struct file_ll));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
142 f->next = head;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
143 f->email_count = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
144 f->type = item->type;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
145 f->stored_count = item->folder->email_count;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
146 head = f;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
147 f->name = "mbox";
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
148 f->dname = (char*) xmalloc(strlen(item->file_as)+1);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
149 strcpy(f->dname, item->file_as);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
150
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
151 DEBUG_MAIN(("main: f->name = %s\nitem->folder_name = %s\n", f->name, item->file_as));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
152 canonicalize_filename(f->name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
153
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
154 if (d_ptr->child != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
155 d_ptr = d_ptr->child;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
156 skip_child = 1;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
157 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
158 DEBUG_MAIN(("main: Folder has NO children. Creating directory, and closing again\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
159 // printf("\tNo items to process in folder \"%s\", should have been %i\n", f->dname, f->stored_count);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
160 head = f->next;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
161 if (f->output != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
162 fclose(f->output);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
163 free(f->dname);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
164 free(f->name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
165 free(f);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
166
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
167 f = head;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
168 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
169 _pst_freeItem(item);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
170 item = NULL; // just for the odd situations!
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
171 goto check_parent;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
172 // }}}3
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
173 } else if (item->contact != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
174 // Process Contact item {{{3
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
175 if (f->type != PST_TYPE_CONTACT) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
176 DEBUG_MAIN(("main: I have a contact, but the folder isn't a contacts folder. "
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
177 "Will process anyway\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
178 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
179 if (item->type != PST_TYPE_CONTACT) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
180 DEBUG_MAIN(("main: I have an item that has contact info, but doesn't say that"
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
181 " it is a contact. Type is \"%s\"\n", item->ascii_type));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
182 DEBUG_MAIN(("main: Processing anyway\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
183 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
184
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
185 printf("Contact");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
186 if (item->contact->fullname != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
187 printf("\t%s", rfc2426_escape(item->contact->fullname));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
188 printf("\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
189 // }}}3
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
190 } else if (item->email != NULL &&
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
191 (item->type == PST_TYPE_NOTE || item->type == PST_TYPE_REPORT)) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
192 // Process Email item {{{3
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
193 printf("Email");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
194 if (item->email->outlook_sender_name != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
195 printf("\tFrom: %s", item->email->outlook_sender_name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
196 if (item->email->subject->subj != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
197 printf("\tSubject: %s", item->email->subject->subj);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
198 printf("\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
199 // }}}3
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
200 } else if (item->type == PST_TYPE_JOURNAL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
201 // Process Journal item {{{3
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
202 if (f->type != PST_TYPE_JOURNAL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
203 DEBUG_MAIN(("main: I have a journal entry, but folder isn't specified as a journal type. Processing...\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
204 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
205
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
206 printf("Journal\t%s\n", rfc2426_escape(item->email->subject->subj));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
207 // }}}3
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
208 } else if (item->type == PST_TYPE_APPOINTMENT) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
209 // Process Calendar Appointment item {{{3
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
210 // deal with Calendar appointments
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
211
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
212 DEBUG_MAIN(("main: Processing Appointment Entry\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
213 if (f->type != PST_TYPE_APPOINTMENT) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
214 DEBUG_MAIN(("main: I have an appointment, but folder isn't specified as an appointment type. Processing...\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
215 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
216
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
217 printf("Appointment");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
218 if (item->email != NULL && item->email->subject != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
219 printf("\tSUMMARY: %s", rfc2426_escape(item->email->subject->subj));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
220 if (item->appointment != NULL && item->appointment->start != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
221 printf("\tSTART: %s", rfc2445_datetime_format(item->appointment->start));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
222 printf("\n");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
223
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
224 // }}}3
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
225 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
226 f->skip_count++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
227 DEBUG_MAIN(("main: Unknown item type. %i. Ascii1=\"%s\"\n", \
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
228 item->type, item->ascii_type));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
229 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
230 } else {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
231 f->skip_count++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
232 DEBUG_MAIN(("main: A NULL item was seen\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
233 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
234
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
235 check_parent:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
236 // _pst_freeItem(item);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
237 while (!skip_child && d_ptr->next == NULL && d_ptr->parent != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
238 DEBUG_MAIN(("main: Going to Parent\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
239 head = f->next;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
240 if (f->output != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
241 fclose(f->output);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
242 DEBUG_MAIN(("main: Email Count for folder %s is %i\n", f->dname, f->email_count));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
243 /*
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
244 printf("\t\"%s\" - %i items done, skipped %i, should have been %i\n", \
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
245 f->dname, f->email_count, f->skip_count, f->stored_count);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
246 */
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
247
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
248 free(f->name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
249 free(f->dname);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
250 free(f);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
251 f = head;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
252 if (head == NULL) { //we can't go higher. Must be at start?
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
253 DEBUG_MAIN(("main: We are now trying to go above the highest level. We must be finished\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
254 break; //from main while loop
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
255 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
256 d_ptr = d_ptr->parent;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
257 skip_child = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
258 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
259
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
260 if (item != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
261 DEBUG_MAIN(("main: Freeing memory used by item\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
262 _pst_freeItem(item);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
263 item = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
264 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
265
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
266 if (!skip_child)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
267 d_ptr = d_ptr->next;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
268 else
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
269 skip_child = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
270
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
271 if (d_ptr == NULL) { DEBUG_MAIN(("main: d_ptr is now NULL\n")); }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
272
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
273 // }}}2
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
274 } // end while(d_ptr != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
275 DEBUG_MAIN(("main: Finished.\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
276
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
277 // Cleanup {{{2
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
278 pst_close(&pstfile);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
279 while (f != NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
280 if (f->output != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
281 fclose(f->output);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
282 free(f->name);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
283 free(f->dname);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
284
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
285 head = f->next;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
286 free(f);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
287 f = head;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
288 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
289 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
290 // }}}2
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
291
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
292 return 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
293 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
294 // }}}1
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
295 // void canonicalize_filename(char *fname) {{{1
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
296 // This function will make sure that a filename is in cannonical form. That
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
297 // is, it will replace any slashes, backslashes, or colons with underscores.
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
298 void canonicalize_filename(char *fname) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
299 DEBUG_ENT("canonicalize_filename");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
300 if (fname == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
301 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
302 return;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
303 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
304 while ((fname = strpbrk(fname, "/\\:")) != NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
305 *fname = '_';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
306 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
307 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
308 // }}}1
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
309 // int chr_count(char *str, char x) {{{1
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
310 int chr_count(char *str, char x) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
311 int r = 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
312 if (str == NULL) return 0;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
313 while (*str != '\0') {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
314 if (*str == x)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
315 r++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
316 str++;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
317 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
318 return r;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
319 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
320 // }}}1
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
321 // void debug_print(char *fmt, ...) {{{1
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
322 void debug_print(char *fmt, ...) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
323 // shamlessly stolen from minprintf() in K&R pg. 156
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
324 va_list ap;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
325 char *p, *sval;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
326 void *pval;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
327 int ival;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
328 double dval;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
329 FILE *fp = stderr;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
330
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
331 va_start(ap, fmt);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
332 for(p = fmt; *p; p++) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
333 if (*p != '%') {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
334 fputc(*p, fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
335 continue;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
336 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
337 switch (tolower(*++p)) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
338 case 'd': case 'i':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
339 ival = va_arg(ap, int);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
340 fprintf(fp, "%d", ival);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
341 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
342 case 'f':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
343 dval = va_arg(ap, double);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
344 fprintf(fp, "%f", dval);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
345 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
346 case 's':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
347 for (sval = va_arg(ap, char *); *sval; ++sval)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
348 fputc(*sval, fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
349 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
350 case 'p':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
351 pval = va_arg(ap, void *);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
352 fprintf(fp, "%p", pval);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
353 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
354 case 'x':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
355 ival = va_arg(ap, int);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
356 fprintf(fp, "%#010x", ival);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
357 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
358 default:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
359 fputc(*p, fp);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
360 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
361 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
362 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
363 va_end(ap);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
364 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
365 // }}}1
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
366 // char *rfc2426_escape(char *str) {{{1
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
367 char *rfc2426_escape(char *str) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
368 static char *buf = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
369 char *a, *b;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
370 int y, z;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
371
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
372 DEBUG_ENT("rfc2426_escape");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
373 if (str == NULL) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
374 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
375 return NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
376 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
377
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
378 // calculate space required to escape all the commas, semi-colons, backslashes, and newlines
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
379 y = chr_count(str, ',') + chr_count(str, '\\') + chr_count(str, ';') + chr_count(str, '\n');
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
380 // count how many carriage-returns we have to skip
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
381 z = chr_count(str, '\r');
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
382
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
383 if (y == 0 && z == 0) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
384 // there isn't any work required
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
385 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
386 return str;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
387 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
388
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
389 buf = (char *) realloc( buf, strlen(str) + y - z + 1 );
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
390 for (a = str, b = buf; *a != '\0'; ++a, ++b)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
391 switch (*a) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
392 case ',' : case '\\': case ';' : case '\n':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
393 // insert backslash to escape
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
394 *(b++) = '\\';
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
395 *b = *a;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
396 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
397 case '\r':
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
398 // skip
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
399 break;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
400 default:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
401 *b = *a;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
402 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
403 *b = '\0'; // NUL-terminate the string
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
404
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
405 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
406 return buf;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
407 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
408 // }}}1
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
409 // char *rfc2445_datetime_format(FILETIME *ft) {{{1
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
410 char *rfc2445_datetime_format(FILETIME *ft) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
411 static char* buffer = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
412 struct tm *stm = NULL;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
413 DEBUG_ENT("rfc2445_datetime_format");
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
414 if (buffer == NULL)
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
415 buffer = malloc(30); // should be enough
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
416 stm = fileTimeToStructTM(ft);
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
417 if (strftime(buffer, 30, "%Y%m%dT%H%M%SZ", stm)==0) {
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
418 DEBUG_INFO(("Problem occured formatting date\n"));
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
419 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
420 DEBUG_RET();
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
421 return buffer;
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
422 }
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
423 // }}}1
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
424
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
425 // vim:sw=4 ts=4:
c508ee15dfca switch to automake/autoconf
carl
parents:
diff changeset
426 // vim600: set foldlevel=0 foldmethod=marker: