annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
6b1b602514db Initial revision
carl
parents:
diff changeset
1 /***
6b1b602514db Initial revision
carl
parents:
diff changeset
2 * readpst.c
6b1b602514db Initial revision
carl
parents:
diff changeset
3 * Part of the LibPST project
6b1b602514db Initial revision
carl
parents:
diff changeset
4 * Written by David Smith
6b1b602514db Initial revision
carl
parents:
diff changeset
5 * dave.s@earthcorp.com
6b1b602514db Initial revision
carl
parents:
diff changeset
6 */
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
7 // Includes {{{1
0
6b1b602514db Initial revision
carl
parents:
diff changeset
8 #include <stdio.h>
6b1b602514db Initial revision
carl
parents:
diff changeset
9 #include <stdlib.h>
6b1b602514db Initial revision
carl
parents:
diff changeset
10 #include <time.h>
6b1b602514db Initial revision
carl
parents:
diff changeset
11 #include <string.h>
6b1b602514db Initial revision
carl
parents:
diff changeset
12 #include <ctype.h>
6b1b602514db Initial revision
carl
parents:
diff changeset
13 #include <limits.h>
6b1b602514db Initial revision
carl
parents:
diff changeset
14 #include <errno.h>
6b1b602514db Initial revision
carl
parents:
diff changeset
15
6b1b602514db Initial revision
carl
parents:
diff changeset
16 #ifndef _WIN32
6b1b602514db Initial revision
carl
parents:
diff changeset
17 # include <unistd.h>
6b1b602514db Initial revision
carl
parents:
diff changeset
18 # include <sys/stat.h> //mkdir
6b1b602514db Initial revision
carl
parents:
diff changeset
19
6b1b602514db Initial revision
carl
parents:
diff changeset
20 // for reading of directory and clearing in function mk_seperate_dir
6b1b602514db Initial revision
carl
parents:
diff changeset
21 # include <sys/types.h>
6b1b602514db Initial revision
carl
parents:
diff changeset
22 # include <dirent.h>
6b1b602514db Initial revision
carl
parents:
diff changeset
23 #else
6b1b602514db Initial revision
carl
parents:
diff changeset
24 # include <direct.h>
6b1b602514db Initial revision
carl
parents:
diff changeset
25 # define chdir _chdir
6b1b602514db Initial revision
carl
parents:
diff changeset
26 # define int32_t __int32
6b1b602514db Initial revision
carl
parents:
diff changeset
27 #endif
6b1b602514db Initial revision
carl
parents:
diff changeset
28
6b1b602514db Initial revision
carl
parents:
diff changeset
29 #ifndef __GNUC__
6b1b602514db Initial revision
carl
parents:
diff changeset
30 # include "XGetopt.h"
6b1b602514db Initial revision
carl
parents:
diff changeset
31 #endif
6b1b602514db Initial revision
carl
parents:
diff changeset
32
6b1b602514db Initial revision
carl
parents:
diff changeset
33 #include "libstrfunc.h" // for base64_encoding
6b1b602514db Initial revision
carl
parents:
diff changeset
34
6b1b602514db Initial revision
carl
parents:
diff changeset
35 #include "define.h"
6b1b602514db Initial revision
carl
parents:
diff changeset
36 #include "libpst.h"
6b1b602514db Initial revision
carl
parents:
diff changeset
37 #include "common.h"
6b1b602514db Initial revision
carl
parents:
diff changeset
38 #include "timeconv.h"
6b1b602514db Initial revision
carl
parents:
diff changeset
39 #include "lzfu.h"
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
40 // }}}1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
41 // Defines {{{1
0
6b1b602514db Initial revision
carl
parents:
diff changeset
42 #define OUTPUT_TEMPLATE "%s"
6b1b602514db Initial revision
carl
parents:
diff changeset
43 #define OUTPUT_KMAIL_DIR_TEMPLATE ".%s.directory"
6b1b602514db Initial revision
carl
parents:
diff changeset
44 #define KMAIL_INDEX ".%s.index"
6b1b602514db Initial revision
carl
parents:
diff changeset
45
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
46 #define VERSION "0.5.1"
0
6b1b602514db Initial revision
carl
parents:
diff changeset
47 // max size of the c_time char*. It will store the date of the email
6b1b602514db Initial revision
carl
parents:
diff changeset
48 #define C_TIME_SIZE 500
6b1b602514db Initial revision
carl
parents:
diff changeset
49 #define PERM_DIRS 0777
6b1b602514db Initial revision
carl
parents:
diff changeset
50
6b1b602514db Initial revision
carl
parents:
diff changeset
51 // macro used for creating directories
6b1b602514db Initial revision
carl
parents:
diff changeset
52 #ifndef WIN32
6b1b602514db Initial revision
carl
parents:
diff changeset
53 #define D_MKDIR(x) mkdir(x, PERM_DIRS)
6b1b602514db Initial revision
carl
parents:
diff changeset
54 #else
6b1b602514db Initial revision
carl
parents:
diff changeset
55 #define D_MKDIR(x) mkdir(x)
6b1b602514db Initial revision
carl
parents:
diff changeset
56 #endif
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
57 // }}}1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
58 // struct file_ll {{{1
0
6b1b602514db Initial revision
carl
parents:
diff changeset
59 struct file_ll {
6b1b602514db Initial revision
carl
parents:
diff changeset
60 char *name;
6b1b602514db Initial revision
carl
parents:
diff changeset
61 char *dname;
6b1b602514db Initial revision
carl
parents:
diff changeset
62 FILE * output;
6b1b602514db Initial revision
carl
parents:
diff changeset
63 int32_t stored_count;
6b1b602514db Initial revision
carl
parents:
diff changeset
64 int32_t email_count;
6b1b602514db Initial revision
carl
parents:
diff changeset
65 int32_t skip_count;
6b1b602514db Initial revision
carl
parents:
diff changeset
66 int32_t type;
6b1b602514db Initial revision
carl
parents:
diff changeset
67 struct file_ll *next;
6b1b602514db Initial revision
carl
parents:
diff changeset
68 };
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
69 // }}}1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
70 // Function Declarations {{{1
0
6b1b602514db Initial revision
carl
parents:
diff changeset
71 void write_email_body(FILE *f, char *body);
6b1b602514db Initial revision
carl
parents:
diff changeset
72 char *removeCR (char *c);
6b1b602514db Initial revision
carl
parents:
diff changeset
73 int32_t usage();
6b1b602514db Initial revision
carl
parents:
diff changeset
74 int32_t version();
6b1b602514db Initial revision
carl
parents:
diff changeset
75 char *mk_kmail_dir(char*);
6b1b602514db Initial revision
carl
parents:
diff changeset
76 int32_t close_kmail_dir();
6b1b602514db Initial revision
carl
parents:
diff changeset
77 char *mk_recurse_dir(char*);
6b1b602514db Initial revision
carl
parents:
diff changeset
78 int32_t close_recurse_dir();
6b1b602514db Initial revision
carl
parents:
diff changeset
79 char *mk_seperate_dir(char *dir, int overwrite);
6b1b602514db Initial revision
carl
parents:
diff changeset
80 int32_t close_seperate_dir();
6b1b602514db Initial revision
carl
parents:
diff changeset
81 int32_t mk_seperate_file(struct file_ll *f);
6b1b602514db Initial revision
carl
parents:
diff changeset
82 char *my_stristr(char *haystack, char *needle);
6b1b602514db Initial revision
carl
parents:
diff changeset
83 char *check_filename(char *fname);
6b1b602514db Initial revision
carl
parents:
diff changeset
84 char *rfc2426_escape(char *str);
6b1b602514db Initial revision
carl
parents:
diff changeset
85 int32_t chr_count(char *str, char x);
6b1b602514db Initial revision
carl
parents:
diff changeset
86 char *rfc2425_datetime_format(FILETIME *ft);
6b1b602514db Initial revision
carl
parents:
diff changeset
87 char *rfc2445_datetime_format(FILETIME *ft);
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
88 char *skip_header_prologue(char *headers);
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
89 // }}}1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
90 // Global Variables {{{1
0
6b1b602514db Initial revision
carl
parents:
diff changeset
91 char *prog_name;
6b1b602514db Initial revision
carl
parents:
diff changeset
92 char *output_dir = ".";
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
93 char *kmail_chdir = NULL;
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
94 // }}}1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
95 // More Defines {{{1
0
6b1b602514db Initial revision
carl
parents:
diff changeset
96 // Normal mode just creates mbox format files in the current directory. Each file is named
6b1b602514db Initial revision
carl
parents:
diff changeset
97 // the same as the folder's name that it represents
6b1b602514db Initial revision
carl
parents:
diff changeset
98 #define MODE_NORMAL 0
6b1b602514db Initial revision
carl
parents:
diff changeset
99 // KMail mode creates a directory structure suitable for being used directly
6b1b602514db Initial revision
carl
parents:
diff changeset
100 // by the KMail application
6b1b602514db Initial revision
carl
parents:
diff changeset
101 #define MODE_KMAIL 1
6b1b602514db Initial revision
carl
parents:
diff changeset
102 // recurse mode creates a directory structure like the PST file. Each directory
6b1b602514db Initial revision
carl
parents:
diff changeset
103 // contains only one file which stores the emails in mbox format.
6b1b602514db Initial revision
carl
parents:
diff changeset
104 #define MODE_RECURSE 2
6b1b602514db Initial revision
carl
parents:
diff changeset
105 // seperate mode is similar directory structure to RECURSE. The emails are stored in
6b1b602514db Initial revision
carl
parents:
diff changeset
106 // seperate files, numbering from 1 upward. Attachments belonging to the emails are
6b1b602514db Initial revision
carl
parents:
diff changeset
107 // saved as email_no-filename (e.g. 1-samplefile.doc or 000001-Attachment2.zip)
6b1b602514db Initial revision
carl
parents:
diff changeset
108 #define MODE_SEPERATE 3
6b1b602514db Initial revision
carl
parents:
diff changeset
109
6b1b602514db Initial revision
carl
parents:
diff changeset
110
6b1b602514db Initial revision
carl
parents:
diff changeset
111 // Output Normal just prints the standard information about what is going on
6b1b602514db Initial revision
carl
parents:
diff changeset
112 #define OUTPUT_NORMAL 0
6b1b602514db Initial revision
carl
parents:
diff changeset
113 // Output Quiet is provided so that only errors are printed
6b1b602514db Initial revision
carl
parents:
diff changeset
114 #define OUTPUT_QUIET 1
6b1b602514db Initial revision
carl
parents:
diff changeset
115
6b1b602514db Initial revision
carl
parents:
diff changeset
116 // default mime-type for attachments that have a null mime-type
6b1b602514db Initial revision
carl
parents:
diff changeset
117 #define MIME_TYPE_DEFAULT "application/octet-stream"
6b1b602514db Initial revision
carl
parents:
diff changeset
118
6b1b602514db Initial revision
carl
parents:
diff changeset
119
6b1b602514db Initial revision
carl
parents:
diff changeset
120 // output mode for contacts
6b1b602514db Initial revision
carl
parents:
diff changeset
121 #define CMODE_VCARD 0
6b1b602514db Initial revision
carl
parents:
diff changeset
122 #define CMODE_LIST 1
6b1b602514db Initial revision
carl
parents:
diff changeset
123
6b1b602514db Initial revision
carl
parents:
diff changeset
124 // output settings for RTF bodies
6b1b602514db Initial revision
carl
parents:
diff changeset
125 // filename for the attachment
6b1b602514db Initial revision
carl
parents:
diff changeset
126 #define RTF_ATTACH_NAME "rtf-body.rtf"
6b1b602514db Initial revision
carl
parents:
diff changeset
127 // mime type for the attachment
6b1b602514db Initial revision
carl
parents:
diff changeset
128 #define RTF_ATTACH_TYPE "application/rtf"
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
129 // }}}1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
130 // int main(int argc, char** argv) {{{1
0
6b1b602514db Initial revision
carl
parents:
diff changeset
131 int main(int argc, char** argv) {
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
132 // declarations {{{2
0
6b1b602514db Initial revision
carl
parents:
diff changeset
133 pst_item *item = NULL;
6b1b602514db Initial revision
carl
parents:
diff changeset
134 pst_file pstfile;
6b1b602514db Initial revision
carl
parents:
diff changeset
135 pst_desc_ll *d_ptr;
6b1b602514db Initial revision
carl
parents:
diff changeset
136 char * fname = NULL;
6b1b602514db Initial revision
carl
parents:
diff changeset
137 time_t em_time;
6b1b602514db Initial revision
carl
parents:
diff changeset
138 char * c_time, *d_log=NULL;
6b1b602514db Initial revision
carl
parents:
diff changeset
139 int c,x;
6b1b602514db Initial revision
carl
parents:
diff changeset
140 int mode = MODE_NORMAL;
6b1b602514db Initial revision
carl
parents:
diff changeset
141 int output_mode = OUTPUT_NORMAL;
6b1b602514db Initial revision
carl
parents:
diff changeset
142 int contact_mode = CMODE_VCARD;
6b1b602514db Initial revision
carl
parents:
diff changeset
143 int overwrite = 0;
6b1b602514db Initial revision
carl
parents:
diff changeset
144 int base64_body = 0;
6b1b602514db Initial revision
carl
parents:
diff changeset
145 // int encrypt = 0;
6b1b602514db Initial revision
carl
parents:
diff changeset
146 FILE *fp;
6b1b602514db Initial revision
carl
parents:
diff changeset
147 char *enc; // base64 encoded attachment
6b1b602514db Initial revision
carl
parents:
diff changeset
148 char *boundary = NULL, *b1, *b2; // the boundary marker between multipart sections
6b1b602514db Initial revision
carl
parents:
diff changeset
149 char *temp = NULL; //temporary char pointer
6b1b602514db Initial revision
carl
parents:
diff changeset
150 int attach_num = 0;
6b1b602514db Initial revision
carl
parents:
diff changeset
151 int skip_child = 0;
6b1b602514db Initial revision
carl
parents:
diff changeset
152 struct file_ll *f, *head;
6b1b602514db Initial revision
carl
parents:
diff changeset
153 prog_name = argv[0];
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
154 // }}}2
0
6b1b602514db Initial revision
carl
parents:
diff changeset
155
6b1b602514db Initial revision
carl
parents:
diff changeset
156 while ((c = getopt(argc, argv, "d:hko:qrSVwc:"))!= -1) {
6b1b602514db Initial revision
carl
parents:
diff changeset
157 switch (c) {
6b1b602514db Initial revision
carl
parents:
diff changeset
158 case 'c':
6b1b602514db Initial revision
carl
parents:
diff changeset
159 if (optarg!=NULL && optarg[0]=='v')
6b1b602514db Initial revision
carl
parents:
diff changeset
160 contact_mode=CMODE_VCARD;
6b1b602514db Initial revision
carl
parents:
diff changeset
161 else if (optarg!=NULL && optarg[0]=='l')
6b1b602514db Initial revision
carl
parents:
diff changeset
162 contact_mode=CMODE_LIST;
6b1b602514db Initial revision
carl
parents:
diff changeset
163 else {
6b1b602514db Initial revision
carl
parents:
diff changeset
164 usage();
6b1b602514db Initial revision
carl
parents:
diff changeset
165 exit(0);
6b1b602514db Initial revision
carl
parents:
diff changeset
166 }
6b1b602514db Initial revision
carl
parents:
diff changeset
167 break;
6b1b602514db Initial revision
carl
parents:
diff changeset
168 case 'd':
6b1b602514db Initial revision
carl
parents:
diff changeset
169 d_log = optarg;
6b1b602514db Initial revision
carl
parents:
diff changeset
170 break;
6b1b602514db Initial revision
carl
parents:
diff changeset
171 case 'h':
6b1b602514db Initial revision
carl
parents:
diff changeset
172 usage();
6b1b602514db Initial revision
carl
parents:
diff changeset
173 exit(0);
6b1b602514db Initial revision
carl
parents:
diff changeset
174 break;
6b1b602514db Initial revision
carl
parents:
diff changeset
175 case 'V':
6b1b602514db Initial revision
carl
parents:
diff changeset
176 version();
6b1b602514db Initial revision
carl
parents:
diff changeset
177 exit(0);
6b1b602514db Initial revision
carl
parents:
diff changeset
178 break;
6b1b602514db Initial revision
carl
parents:
diff changeset
179 case 'k':
6b1b602514db Initial revision
carl
parents:
diff changeset
180 mode = MODE_KMAIL;
6b1b602514db Initial revision
carl
parents:
diff changeset
181 break;
6b1b602514db Initial revision
carl
parents:
diff changeset
182 case 'o':
6b1b602514db Initial revision
carl
parents:
diff changeset
183 output_dir = optarg;
6b1b602514db Initial revision
carl
parents:
diff changeset
184 break;
6b1b602514db Initial revision
carl
parents:
diff changeset
185 case 'q':
6b1b602514db Initial revision
carl
parents:
diff changeset
186 output_mode = OUTPUT_QUIET;
6b1b602514db Initial revision
carl
parents:
diff changeset
187 break;
6b1b602514db Initial revision
carl
parents:
diff changeset
188 case 'r':
6b1b602514db Initial revision
carl
parents:
diff changeset
189 mode = MODE_RECURSE;
6b1b602514db Initial revision
carl
parents:
diff changeset
190 break;
6b1b602514db Initial revision
carl
parents:
diff changeset
191 case 'S':
6b1b602514db Initial revision
carl
parents:
diff changeset
192 mode = MODE_SEPERATE;
6b1b602514db Initial revision
carl
parents:
diff changeset
193 break;
6b1b602514db Initial revision
carl
parents:
diff changeset
194 case 'w':
6b1b602514db Initial revision
carl
parents:
diff changeset
195 overwrite = 1;
6b1b602514db Initial revision
carl
parents:
diff changeset
196 break;
6b1b602514db Initial revision
carl
parents:
diff changeset
197 default:
6b1b602514db Initial revision
carl
parents:
diff changeset
198 usage();
6b1b602514db Initial revision
carl
parents:
diff changeset
199 exit(1);
6b1b602514db Initial revision
carl
parents:
diff changeset
200 break;
6b1b602514db Initial revision
carl
parents:
diff changeset
201 }
6b1b602514db Initial revision
carl
parents:
diff changeset
202 }
6b1b602514db Initial revision
carl
parents:
diff changeset
203
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
204 #ifdef DEBUG_ALL
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
205 // initialize log file
0
6b1b602514db Initial revision
carl
parents:
diff changeset
206 if (d_log == NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
207 d_log = "readpst.log";
6b1b602514db Initial revision
carl
parents:
diff changeset
208 DEBUG_INIT(d_log);
6b1b602514db Initial revision
carl
parents:
diff changeset
209 DEBUG_REGISTER_CLOSE();
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
210 #endif // defined DEBUG_ALL
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
211
0
6b1b602514db Initial revision
carl
parents:
diff changeset
212 DEBUG_ENT("main");
6b1b602514db Initial revision
carl
parents:
diff changeset
213
6b1b602514db Initial revision
carl
parents:
diff changeset
214 if (argc > optind) {
6b1b602514db Initial revision
carl
parents:
diff changeset
215 fname = argv[optind];
6b1b602514db Initial revision
carl
parents:
diff changeset
216 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
217 usage();
6b1b602514db Initial revision
carl
parents:
diff changeset
218 exit(2);
6b1b602514db Initial revision
carl
parents:
diff changeset
219 }
6b1b602514db Initial revision
carl
parents:
diff changeset
220
6b1b602514db Initial revision
carl
parents:
diff changeset
221 if (output_mode != OUTPUT_QUIET) printf("Opening PST file and indexes...\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
222
6b1b602514db Initial revision
carl
parents:
diff changeset
223 DEBUG_MAIN(("main: Opening PST file '%s'\n", fname));
6b1b602514db Initial revision
carl
parents:
diff changeset
224 RET_DERROR(pst_open(&pstfile, fname, "r"), 1, ("Error opening File\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
225 DEBUG_MAIN(("main: Loading Indexes\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
226 RET_DERROR(pst_load_index(&pstfile), 2, ("Index Error\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
227 DEBUG_MAIN(("processing file items\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
228
6b1b602514db Initial revision
carl
parents:
diff changeset
229 pst_load_extended_attributes(&pstfile);
6b1b602514db Initial revision
carl
parents:
diff changeset
230
6b1b602514db Initial revision
carl
parents:
diff changeset
231 if (chdir(output_dir)) {
6b1b602514db Initial revision
carl
parents:
diff changeset
232 x = errno;
6b1b602514db Initial revision
carl
parents:
diff changeset
233 pst_close(&pstfile);
6b1b602514db Initial revision
carl
parents:
diff changeset
234 DIE(("main: Cannot change to output dir %s: %s\n", output_dir, strerror(x)));
6b1b602514db Initial revision
carl
parents:
diff changeset
235 }
6b1b602514db Initial revision
carl
parents:
diff changeset
236
6b1b602514db Initial revision
carl
parents:
diff changeset
237 if (output_mode != OUTPUT_QUIET) printf("About to start processing first record...\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
238
6b1b602514db Initial revision
carl
parents:
diff changeset
239 d_ptr = pstfile.d_head; // first record is main record
6b1b602514db Initial revision
carl
parents:
diff changeset
240 if ((item = _pst_parse_item(&pstfile, d_ptr)) == NULL || item->message_store == NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
241 DIE(("main: Could not get root record\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
242 }
6b1b602514db Initial revision
carl
parents:
diff changeset
243
6b1b602514db Initial revision
carl
parents:
diff changeset
244 // default the file_as to the same as the main filename if it doesn't exist
6b1b602514db Initial revision
carl
parents:
diff changeset
245 if (item->file_as == NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
246 if ((temp = strrchr(fname, '/')) == NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
247 if ((temp = strrchr(fname, '\\')) == NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
248 temp = fname;
6b1b602514db Initial revision
carl
parents:
diff changeset
249 else
6b1b602514db Initial revision
carl
parents:
diff changeset
250 temp++; // get past the "\\"
6b1b602514db Initial revision
carl
parents:
diff changeset
251 else
6b1b602514db Initial revision
carl
parents:
diff changeset
252 temp++; // get past the "/"
6b1b602514db Initial revision
carl
parents:
diff changeset
253 item->file_as = (char*)xmalloc(strlen(temp)+1);
6b1b602514db Initial revision
carl
parents:
diff changeset
254 strcpy(item->file_as, temp);
6b1b602514db Initial revision
carl
parents:
diff changeset
255 DEBUG_MAIN(("file_as was blank, so am using %s\n", item->file_as));
6b1b602514db Initial revision
carl
parents:
diff changeset
256 }
6b1b602514db Initial revision
carl
parents:
diff changeset
257 DEBUG_MAIN(("main: Root Folder Name: %s\n", item->file_as));
6b1b602514db Initial revision
carl
parents:
diff changeset
258
6b1b602514db Initial revision
carl
parents:
diff changeset
259
6b1b602514db Initial revision
carl
parents:
diff changeset
260 f = (struct file_ll*) malloc(sizeof(struct file_ll));
6b1b602514db Initial revision
carl
parents:
diff changeset
261 memset(f, 0, sizeof(struct file_ll));
6b1b602514db Initial revision
carl
parents:
diff changeset
262 f->email_count = 0;
6b1b602514db Initial revision
carl
parents:
diff changeset
263 f->skip_count = 0;
6b1b602514db Initial revision
carl
parents:
diff changeset
264 f->next = NULL;
6b1b602514db Initial revision
carl
parents:
diff changeset
265 head = f;
6b1b602514db Initial revision
carl
parents:
diff changeset
266 if (mode == MODE_KMAIL)
6b1b602514db Initial revision
carl
parents:
diff changeset
267 f->name = mk_kmail_dir(item->file_as);
6b1b602514db Initial revision
carl
parents:
diff changeset
268 else if (mode == MODE_RECURSE)
6b1b602514db Initial revision
carl
parents:
diff changeset
269 f->name = mk_recurse_dir(item->file_as);
6b1b602514db Initial revision
carl
parents:
diff changeset
270 else if (mode == MODE_SEPERATE) {
6b1b602514db Initial revision
carl
parents:
diff changeset
271 // do similar stuff to recurse here.
6b1b602514db Initial revision
carl
parents:
diff changeset
272 mk_seperate_dir(item->file_as, overwrite);
6b1b602514db Initial revision
carl
parents:
diff changeset
273 f->name = (char*) xmalloc(10);
6b1b602514db Initial revision
carl
parents:
diff changeset
274 sprintf(f->name, "%09i", f->email_count);
6b1b602514db Initial revision
carl
parents:
diff changeset
275 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
276 f->name = (char*) malloc(strlen(item->file_as)+strlen(OUTPUT_TEMPLATE)+1);
6b1b602514db Initial revision
carl
parents:
diff changeset
277 sprintf(f->name, OUTPUT_TEMPLATE, item->file_as);
6b1b602514db Initial revision
carl
parents:
diff changeset
278 }
6b1b602514db Initial revision
carl
parents:
diff changeset
279
6b1b602514db Initial revision
carl
parents:
diff changeset
280 f->dname = (char*) malloc(strlen(item->file_as)+1);
6b1b602514db Initial revision
carl
parents:
diff changeset
281 strcpy(f->dname, item->file_as);
6b1b602514db Initial revision
carl
parents:
diff changeset
282
6b1b602514db Initial revision
carl
parents:
diff changeset
283 if (overwrite != 1 && mode != MODE_SEPERATE) {
6b1b602514db Initial revision
carl
parents:
diff changeset
284 // if overwrite is set to 1 we keep the existing name and don't modify anything
6b1b602514db Initial revision
carl
parents:
diff changeset
285 // we don't want to go changing the file name of the SEPERATE items
6b1b602514db Initial revision
carl
parents:
diff changeset
286 temp = (char*) malloc (strlen(f->name)+10); //enough room for 10 digits
6b1b602514db Initial revision
carl
parents:
diff changeset
287 sprintf(temp, "%s", f->name);
6b1b602514db Initial revision
carl
parents:
diff changeset
288 temp = check_filename(temp);
6b1b602514db Initial revision
carl
parents:
diff changeset
289 x = 0;
6b1b602514db Initial revision
carl
parents:
diff changeset
290 while ((f->output = fopen(temp, "r")) != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
291 DEBUG_MAIN(("main: need to increase filename cause one already exists with that name\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
292 DEBUG_MAIN(("main: - increasing it to %s%d\n", f->name, x));
6b1b602514db Initial revision
carl
parents:
diff changeset
293 x++;
6b1b602514db Initial revision
carl
parents:
diff changeset
294 sprintf(temp, "%s%08d", f->name, x);
6b1b602514db Initial revision
carl
parents:
diff changeset
295 DEBUG_MAIN(("main: - trying \"%s\"\n", temp));
6b1b602514db Initial revision
carl
parents:
diff changeset
296 if (x == 99999999) {
6b1b602514db Initial revision
carl
parents:
diff changeset
297 DIE(("main: Why can I not create a folder %s? I have tried %i extensions...\n", f->name, x));
6b1b602514db Initial revision
carl
parents:
diff changeset
298 }
6b1b602514db Initial revision
carl
parents:
diff changeset
299 fclose(f->output);
6b1b602514db Initial revision
carl
parents:
diff changeset
300 }
6b1b602514db Initial revision
carl
parents:
diff changeset
301 if (x > 0) { //then the f->name should change
6b1b602514db Initial revision
carl
parents:
diff changeset
302 free (f->name);
6b1b602514db Initial revision
carl
parents:
diff changeset
303 f->name = temp;
6b1b602514db Initial revision
carl
parents:
diff changeset
304 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
305 free (temp);
6b1b602514db Initial revision
carl
parents:
diff changeset
306 }
6b1b602514db Initial revision
carl
parents:
diff changeset
307 }
6b1b602514db Initial revision
carl
parents:
diff changeset
308 if (mode != MODE_SEPERATE) {
6b1b602514db Initial revision
carl
parents:
diff changeset
309 f->name = check_filename(f->name);
6b1b602514db Initial revision
carl
parents:
diff changeset
310 if ((f->output = fopen(f->name, "w")) == NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
311 DIE(("main: Could not open file \"%s\" for write\n", f->name));
6b1b602514db Initial revision
carl
parents:
diff changeset
312 }
6b1b602514db Initial revision
carl
parents:
diff changeset
313 }
6b1b602514db Initial revision
carl
parents:
diff changeset
314 f->type = item->type;
6b1b602514db Initial revision
carl
parents:
diff changeset
315
6b1b602514db Initial revision
carl
parents:
diff changeset
316 if ((d_ptr = pst_getTopOfFolders(&pstfile, item)) == NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
317 DIE(("Top of folders record not found. Cannot continue\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
318 }
6b1b602514db Initial revision
carl
parents:
diff changeset
319
6b1b602514db Initial revision
carl
parents:
diff changeset
320 if (item){
6b1b602514db Initial revision
carl
parents:
diff changeset
321 _pst_freeItem(item);
6b1b602514db Initial revision
carl
parents:
diff changeset
322 item = NULL;
6b1b602514db Initial revision
carl
parents:
diff changeset
323 }
6b1b602514db Initial revision
carl
parents:
diff changeset
324
6b1b602514db Initial revision
carl
parents:
diff changeset
325 /* if ((item = _pst_parse_item(&pstfile, d_ptr)) == NULL || item->folder == NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
326 DEBUG_MAIN(("main: Could not get \"Top Of Personal Folder\" record\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
327 return -2;
6b1b602514db Initial revision
carl
parents:
diff changeset
328 }*/
6b1b602514db Initial revision
carl
parents:
diff changeset
329 d_ptr = d_ptr->child; // do the children of TOPF
6b1b602514db Initial revision
carl
parents:
diff changeset
330
6b1b602514db Initial revision
carl
parents:
diff changeset
331 if (output_mode != OUTPUT_QUIET) printf("Processing items...\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
332
6b1b602514db Initial revision
carl
parents:
diff changeset
333 DEBUG_MAIN(("main: About to do email stuff\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
334 while (d_ptr != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
335 DEBUG_MAIN(("main: New item record\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
336 if (d_ptr->desc == NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
337 DEBUG_WARN(("main: ERROR ?? item's desc record is NULL\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
338 f->skip_count++;
6b1b602514db Initial revision
carl
parents:
diff changeset
339 goto check_parent;
6b1b602514db Initial revision
carl
parents:
diff changeset
340 }
6b1b602514db Initial revision
carl
parents:
diff changeset
341 DEBUG_MAIN(("main: Desc Email ID %#x [d_ptr->id = %#x]\n", d_ptr->desc->id, d_ptr->id));
6b1b602514db Initial revision
carl
parents:
diff changeset
342
6b1b602514db Initial revision
carl
parents:
diff changeset
343 item = _pst_parse_item(&pstfile, d_ptr);
6b1b602514db Initial revision
carl
parents:
diff changeset
344 DEBUG_MAIN(("main: About to process item\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
345 if (item != NULL && item->email != NULL && item->email->subject != NULL &&
6b1b602514db Initial revision
carl
parents:
diff changeset
346 item->email->subject->subj != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
347 // DEBUG_EMAIL(("item->email->subject = %p\n", item->email->subject));
6b1b602514db Initial revision
carl
parents:
diff changeset
348 // DEBUG_EMAIL(("item->email->subject->subj = %p\n", item->email->subject->subj));
6b1b602514db Initial revision
carl
parents:
diff changeset
349 }
6b1b602514db Initial revision
carl
parents:
diff changeset
350 if (item != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
351 if (item->message_store != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
352 // there should only be one message_store, and we have already done it
6b1b602514db Initial revision
carl
parents:
diff changeset
353 DIE(("main: A second message_store has been found. Sorry, this must be an error.\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
354 }
6b1b602514db Initial revision
carl
parents:
diff changeset
355
6b1b602514db Initial revision
carl
parents:
diff changeset
356
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
357 if (item->folder != NULL) {
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
358 // Process Folder item {{{2
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
359 // if this is a folder, we want to recurse into it
0
6b1b602514db Initial revision
carl
parents:
diff changeset
360 if (output_mode != OUTPUT_QUIET) printf("Processing Folder \"%s\"\n", item->file_as);
6b1b602514db Initial revision
carl
parents:
diff changeset
361 // f->email_count++;
6b1b602514db Initial revision
carl
parents:
diff changeset
362 DEBUG_MAIN(("main: I think I may try to go into folder \"%s\"\n", item->file_as));
6b1b602514db Initial revision
carl
parents:
diff changeset
363 f = (struct file_ll*) malloc(sizeof(struct file_ll));
6b1b602514db Initial revision
carl
parents:
diff changeset
364 memset(f, 0, sizeof(struct file_ll));
6b1b602514db Initial revision
carl
parents:
diff changeset
365
6b1b602514db Initial revision
carl
parents:
diff changeset
366 f->next = head;
6b1b602514db Initial revision
carl
parents:
diff changeset
367 f->email_count = 0;
6b1b602514db Initial revision
carl
parents:
diff changeset
368 f->type = item->type;
6b1b602514db Initial revision
carl
parents:
diff changeset
369 f->stored_count = item->folder->email_count;
6b1b602514db Initial revision
carl
parents:
diff changeset
370 head = f;
6b1b602514db Initial revision
carl
parents:
diff changeset
371
6b1b602514db Initial revision
carl
parents:
diff changeset
372 temp = item->file_as;
6b1b602514db Initial revision
carl
parents:
diff changeset
373 temp = check_filename(temp);
6b1b602514db Initial revision
carl
parents:
diff changeset
374
6b1b602514db Initial revision
carl
parents:
diff changeset
375 if (mode == MODE_KMAIL)
6b1b602514db Initial revision
carl
parents:
diff changeset
376 f->name = mk_kmail_dir(item->file_as); //create directory and form filename
6b1b602514db Initial revision
carl
parents:
diff changeset
377 else if (mode == MODE_RECURSE)
6b1b602514db Initial revision
carl
parents:
diff changeset
378 f->name = mk_recurse_dir(item->file_as);
6b1b602514db Initial revision
carl
parents:
diff changeset
379 else if (mode == MODE_SEPERATE) {
6b1b602514db Initial revision
carl
parents:
diff changeset
380 // do similar stuff to recurse here.
6b1b602514db Initial revision
carl
parents:
diff changeset
381 mk_seperate_dir(item->file_as, overwrite);
6b1b602514db Initial revision
carl
parents:
diff changeset
382 f->name = (char*) xmalloc(10);
6b1b602514db Initial revision
carl
parents:
diff changeset
383 memset(f->name, 0, 10);
6b1b602514db Initial revision
carl
parents:
diff changeset
384 // sprintf(f->name, "%09i", f->email_count);
6b1b602514db Initial revision
carl
parents:
diff changeset
385 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
386 f->name = (char*) xmalloc(strlen(item->file_as)+strlen(OUTPUT_TEMPLATE+1));
6b1b602514db Initial revision
carl
parents:
diff changeset
387 sprintf(f->name, OUTPUT_TEMPLATE, item->file_as);
6b1b602514db Initial revision
carl
parents:
diff changeset
388 }
6b1b602514db Initial revision
carl
parents:
diff changeset
389
6b1b602514db Initial revision
carl
parents:
diff changeset
390 f->dname = (char*) xmalloc(strlen(item->file_as)+1);
6b1b602514db Initial revision
carl
parents:
diff changeset
391 strcpy(f->dname, item->file_as);
6b1b602514db Initial revision
carl
parents:
diff changeset
392
6b1b602514db Initial revision
carl
parents:
diff changeset
393 if (overwrite != 1) {
6b1b602514db Initial revision
carl
parents:
diff changeset
394 temp = (char*) xmalloc (strlen(f->name)+10); //enough room for 10 digits
6b1b602514db Initial revision
carl
parents:
diff changeset
395 sprintf(temp, "%s", f->name);
6b1b602514db Initial revision
carl
parents:
diff changeset
396 x = 0;
6b1b602514db Initial revision
carl
parents:
diff changeset
397 temp = check_filename(temp);
6b1b602514db Initial revision
carl
parents:
diff changeset
398 while ((f->output = fopen(temp, "r")) != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
399 DEBUG_MAIN(("main: need to increase filename cause one already exists with that name\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
400 DEBUG_MAIN(("main: - increasing it to %s%d\n", f->name, x));
6b1b602514db Initial revision
carl
parents:
diff changeset
401 x++;
6b1b602514db Initial revision
carl
parents:
diff changeset
402 sprintf(temp, "%s%08d", f->name, x);
6b1b602514db Initial revision
carl
parents:
diff changeset
403 DEBUG_MAIN(("main: - trying \"%s\"\n", f->name));
6b1b602514db Initial revision
carl
parents:
diff changeset
404 if (x == 99999999) {
6b1b602514db Initial revision
carl
parents:
diff changeset
405 DIE(("main: Why can I not create a folder %s? I have tried %i extensions...\n", f->name, x));
6b1b602514db Initial revision
carl
parents:
diff changeset
406 }
6b1b602514db Initial revision
carl
parents:
diff changeset
407 fclose(f->output);
6b1b602514db Initial revision
carl
parents:
diff changeset
408 }
6b1b602514db Initial revision
carl
parents:
diff changeset
409 if (x > 0) { //then the f->name should change
6b1b602514db Initial revision
carl
parents:
diff changeset
410 free (f->name);
6b1b602514db Initial revision
carl
parents:
diff changeset
411 f->name = temp;
6b1b602514db Initial revision
carl
parents:
diff changeset
412 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
413 free(temp);
6b1b602514db Initial revision
carl
parents:
diff changeset
414 }
6b1b602514db Initial revision
carl
parents:
diff changeset
415 }
6b1b602514db Initial revision
carl
parents:
diff changeset
416
6b1b602514db Initial revision
carl
parents:
diff changeset
417 DEBUG_MAIN(("main: f->name = %s\nitem->folder_name = %s\n", f->name, item->file_as));
6b1b602514db Initial revision
carl
parents:
diff changeset
418 if (mode != MODE_SEPERATE) {
6b1b602514db Initial revision
carl
parents:
diff changeset
419 f->name = check_filename(f->name);
6b1b602514db Initial revision
carl
parents:
diff changeset
420 if ((f->output = fopen(f->name, "w")) == NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
421 DIE(("main: Could not open file \"%s\" for write\n", f->name));
6b1b602514db Initial revision
carl
parents:
diff changeset
422 }
6b1b602514db Initial revision
carl
parents:
diff changeset
423 }
6b1b602514db Initial revision
carl
parents:
diff changeset
424 if (d_ptr->child != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
425 d_ptr = d_ptr->child;
6b1b602514db Initial revision
carl
parents:
diff changeset
426 skip_child = 1;
6b1b602514db Initial revision
carl
parents:
diff changeset
427 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
428 DEBUG_MAIN(("main: Folder has NO children. Creating directory, and closing again\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
429 if (output_mode != OUTPUT_QUIET)
6b1b602514db Initial revision
carl
parents:
diff changeset
430 printf("\tNo items to process in folder \"%s\", should have been %i\n", f->dname, f->stored_count);
6b1b602514db Initial revision
carl
parents:
diff changeset
431 head = f->next;
6b1b602514db Initial revision
carl
parents:
diff changeset
432 if (f->output != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
433 fclose(f->output);
6b1b602514db Initial revision
carl
parents:
diff changeset
434 if (mode == MODE_KMAIL)
6b1b602514db Initial revision
carl
parents:
diff changeset
435 close_kmail_dir();
6b1b602514db Initial revision
carl
parents:
diff changeset
436 else if (mode == MODE_RECURSE)
6b1b602514db Initial revision
carl
parents:
diff changeset
437 close_recurse_dir();
6b1b602514db Initial revision
carl
parents:
diff changeset
438 else if (mode == MODE_SEPERATE)
6b1b602514db Initial revision
carl
parents:
diff changeset
439 close_seperate_dir();
6b1b602514db Initial revision
carl
parents:
diff changeset
440 free(f->dname);
6b1b602514db Initial revision
carl
parents:
diff changeset
441 free(f->name);
6b1b602514db Initial revision
carl
parents:
diff changeset
442 free(f);
6b1b602514db Initial revision
carl
parents:
diff changeset
443
6b1b602514db Initial revision
carl
parents:
diff changeset
444 f = head;
6b1b602514db Initial revision
carl
parents:
diff changeset
445 }
6b1b602514db Initial revision
carl
parents:
diff changeset
446 _pst_freeItem(item);
6b1b602514db Initial revision
carl
parents:
diff changeset
447 item = NULL; // just for the odd situations!
6b1b602514db Initial revision
carl
parents:
diff changeset
448 goto check_parent;
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
449 // }}}2
0
6b1b602514db Initial revision
carl
parents:
diff changeset
450 } else if (item->contact != NULL) {
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
451 // Process Contact item {{{2
0
6b1b602514db Initial revision
carl
parents:
diff changeset
452 // deal with a contact
6b1b602514db Initial revision
carl
parents:
diff changeset
453 // write them to the file, one per line in this format
6b1b602514db Initial revision
carl
parents:
diff changeset
454 // Desc Name <email@address>\n
6b1b602514db Initial revision
carl
parents:
diff changeset
455 if (mode == MODE_SEPERATE) {
6b1b602514db Initial revision
carl
parents:
diff changeset
456 mk_seperate_file(f);
6b1b602514db Initial revision
carl
parents:
diff changeset
457 }
6b1b602514db Initial revision
carl
parents:
diff changeset
458 f->email_count++;
6b1b602514db Initial revision
carl
parents:
diff changeset
459
6b1b602514db Initial revision
carl
parents:
diff changeset
460 DEBUG_MAIN(("main: Processing Contact\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
461 if (f->type != PST_TYPE_CONTACT) {
6b1b602514db Initial revision
carl
parents:
diff changeset
462 DEBUG_MAIN(("main: I have a contact, but the folder isn't a contacts folder. "
6b1b602514db Initial revision
carl
parents:
diff changeset
463 "Will process anyway\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
464 }
6b1b602514db Initial revision
carl
parents:
diff changeset
465 if (item->type != PST_TYPE_CONTACT) {
6b1b602514db Initial revision
carl
parents:
diff changeset
466 DEBUG_MAIN(("main: I have an item that has contact info, but doesn't say that"
6b1b602514db Initial revision
carl
parents:
diff changeset
467 " it is a contact. Type is \"%s\"\n", item->ascii_type));
6b1b602514db Initial revision
carl
parents:
diff changeset
468 DEBUG_MAIN(("main: Processing anyway\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
469 }
6b1b602514db Initial revision
carl
parents:
diff changeset
470 if (item->contact == NULL) { // this is an incorrect situation. Inform user
6b1b602514db Initial revision
carl
parents:
diff changeset
471 DEBUG_MAIN(("main: ERROR. This contact has not been fully parsed. one of the pre-requisties is NULL\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
472 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
473 if (contact_mode == CMODE_VCARD) {
6b1b602514db Initial revision
carl
parents:
diff changeset
474 // the specification I am following is (hopefully) RFC2426 vCard Mime Directory Profile
6b1b602514db Initial revision
carl
parents:
diff changeset
475 fprintf(f->output, "BEGIN:VCARD\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
476 fprintf(f->output, "FN:%s\n", rfc2426_escape(item->contact->fullname));
6b1b602514db Initial revision
carl
parents:
diff changeset
477 fprintf(f->output, "N:%s;%s;%s;%s;%s\n",
6b1b602514db Initial revision
carl
parents:
diff changeset
478 rfc2426_escape((item->contact->surname==NULL?"":item->contact->surname)),
6b1b602514db Initial revision
carl
parents:
diff changeset
479 rfc2426_escape((item->contact->first_name==NULL?"":item->contact->first_name)),
6b1b602514db Initial revision
carl
parents:
diff changeset
480 rfc2426_escape((item->contact->middle_name==NULL?"":item->contact->middle_name)),
6b1b602514db Initial revision
carl
parents:
diff changeset
481 rfc2426_escape((item->contact->display_name_prefix==NULL?"":item->contact->display_name_prefix)),
6b1b602514db Initial revision
carl
parents:
diff changeset
482 rfc2426_escape((item->contact->suffix==NULL?"":item->contact->suffix)));
6b1b602514db Initial revision
carl
parents:
diff changeset
483 if (item->contact->nickname != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
484 fprintf(f->output, "NICKNAME:%s\n", rfc2426_escape(item->contact->nickname));
6b1b602514db Initial revision
carl
parents:
diff changeset
485 if (item->contact->address1 != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
486 fprintf(f->output, "EMAIL:%s\n", rfc2426_escape(item->contact->address1));
6b1b602514db Initial revision
carl
parents:
diff changeset
487 if (item->contact->address2 != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
488 fprintf(f->output, "EMAIL:%s\n", rfc2426_escape(item->contact->address2));
6b1b602514db Initial revision
carl
parents:
diff changeset
489 if (item->contact->address3 != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
490 fprintf(f->output, "EMAIL:%s\n", rfc2426_escape(item->contact->address3));
6b1b602514db Initial revision
carl
parents:
diff changeset
491 if (item->contact->birthday != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
492 fprintf(f->output, "BDAY:%s\n", rfc2425_datetime_format(item->contact->birthday));
6b1b602514db Initial revision
carl
parents:
diff changeset
493 if (item->contact->home_address != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
494 fprintf(f->output, "ADR;TYPE=home:%s;%s;%s;%s;%s;%s;%s\n",
6b1b602514db Initial revision
carl
parents:
diff changeset
495 rfc2426_escape((item->contact->home_po_box!=NULL?item->contact->home_po_box:"")),
6b1b602514db Initial revision
carl
parents:
diff changeset
496 "", // extended Address
6b1b602514db Initial revision
carl
parents:
diff changeset
497 rfc2426_escape((item->contact->home_street!=NULL?item->contact->home_street:"")),
6b1b602514db Initial revision
carl
parents:
diff changeset
498 rfc2426_escape((item->contact->home_city!=NULL?item->contact->home_city:"")),
6b1b602514db Initial revision
carl
parents:
diff changeset
499 rfc2426_escape((item->contact->home_state!=NULL?item->contact->home_state:"")),
6b1b602514db Initial revision
carl
parents:
diff changeset
500 rfc2426_escape((item->contact->home_postal_code!=NULL?item->contact->home_postal_code:"")),
6b1b602514db Initial revision
carl
parents:
diff changeset
501 rfc2426_escape((item->contact->home_country!=NULL?item->contact->home_country:"")));
6b1b602514db Initial revision
carl
parents:
diff changeset
502 fprintf(f->output, "LABEL;TYPE=home:%s\n", rfc2426_escape(item->contact->home_address));
6b1b602514db Initial revision
carl
parents:
diff changeset
503 }
6b1b602514db Initial revision
carl
parents:
diff changeset
504 if (item->contact->business_address != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
505 fprintf(f->output, "ADR;TYPE=work:%s;%s;%s;%s;%s;%s;%s\n",
6b1b602514db Initial revision
carl
parents:
diff changeset
506 rfc2426_escape((item->contact->business_po_box!=NULL?item->contact->business_po_box:"")),
6b1b602514db Initial revision
carl
parents:
diff changeset
507 "", // extended Address
6b1b602514db Initial revision
carl
parents:
diff changeset
508 rfc2426_escape((item->contact->business_street!=NULL?item->contact->business_street:"")),
6b1b602514db Initial revision
carl
parents:
diff changeset
509 rfc2426_escape((item->contact->business_city!=NULL?item->contact->business_city:"")),
6b1b602514db Initial revision
carl
parents:
diff changeset
510 rfc2426_escape((item->contact->business_state!=NULL?item->contact->business_state:"")),
6b1b602514db Initial revision
carl
parents:
diff changeset
511 rfc2426_escape((item->contact->business_postal_code!=NULL?item->contact->business_postal_code:"")),
6b1b602514db Initial revision
carl
parents:
diff changeset
512 rfc2426_escape((item->contact->business_country!=NULL?item->contact->business_country:"")));
6b1b602514db Initial revision
carl
parents:
diff changeset
513 fprintf(f->output, "LABEL;TYPE=work:%s\n", rfc2426_escape(item->contact->business_address));
6b1b602514db Initial revision
carl
parents:
diff changeset
514 }
6b1b602514db Initial revision
carl
parents:
diff changeset
515 if (item->contact->other_address != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
516 fprintf(f->output, "ADR;TYPE=postal:%s;%s;%s;%s;%s;%s;%s\n",
6b1b602514db Initial revision
carl
parents:
diff changeset
517 rfc2426_escape((item->contact->other_po_box!=NULL?item->contact->business_po_box:"")),
6b1b602514db Initial revision
carl
parents:
diff changeset
518 "", // extended Address
6b1b602514db Initial revision
carl
parents:
diff changeset
519 rfc2426_escape((item->contact->other_street!=NULL?item->contact->other_street:"")),
6b1b602514db Initial revision
carl
parents:
diff changeset
520 rfc2426_escape((item->contact->other_city!=NULL?item->contact->other_city:"")),
6b1b602514db Initial revision
carl
parents:
diff changeset
521 rfc2426_escape((item->contact->other_state!=NULL?item->contact->other_state:"")),
6b1b602514db Initial revision
carl
parents:
diff changeset
522 rfc2426_escape((item->contact->other_postal_code!=NULL?item->contact->other_postal_code:"")),
6b1b602514db Initial revision
carl
parents:
diff changeset
523 rfc2426_escape((item->contact->other_country!=NULL?item->contact->other_country:"")));
6b1b602514db Initial revision
carl
parents:
diff changeset
524 fprintf(f->output, "ADR;TYPE=postal:%s\n", rfc2426_escape(item->contact->other_address));
6b1b602514db Initial revision
carl
parents:
diff changeset
525 }
6b1b602514db Initial revision
carl
parents:
diff changeset
526 if (item->contact->business_fax != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
527 fprintf(f->output, "TEL;TYPE=work,fax:%s\n", rfc2426_escape(item->contact->business_fax));
6b1b602514db Initial revision
carl
parents:
diff changeset
528 if (item->contact->business_phone != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
529 fprintf(f->output, "TEL;TYPE=work,voice:%s\n", rfc2426_escape(item->contact->business_phone));
6b1b602514db Initial revision
carl
parents:
diff changeset
530 if (item->contact->business_phone2 != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
531 fprintf(f->output, "TEL;TYPE=work,voice:%s\n", rfc2426_escape(item->contact->business_phone2));
6b1b602514db Initial revision
carl
parents:
diff changeset
532 if (item->contact->car_phone != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
533 fprintf(f->output, "TEL;TYPE=car,voice:%s\n", rfc2426_escape(item->contact->car_phone));
6b1b602514db Initial revision
carl
parents:
diff changeset
534 if (item->contact->home_fax != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
535 fprintf(f->output, "TEL;TYPE=home,fax:%s\n", rfc2426_escape(item->contact->home_fax));
6b1b602514db Initial revision
carl
parents:
diff changeset
536 if (item->contact->home_phone != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
537 fprintf(f->output, "TEL;TYPE=home,voice:%s\n", rfc2426_escape(item->contact->home_phone));
6b1b602514db Initial revision
carl
parents:
diff changeset
538 if (item->contact->home_phone2 != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
539 fprintf(f->output, "TEL;TYPE=home,voice:%s\n", rfc2426_escape(item->contact->home_phone2));
6b1b602514db Initial revision
carl
parents:
diff changeset
540 if (item->contact->isdn_phone != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
541 fprintf(f->output, "TEL;TYPE=isdn:%s\n", rfc2426_escape(item->contact->isdn_phone));
6b1b602514db Initial revision
carl
parents:
diff changeset
542 if (item->contact->mobile_phone != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
543 fprintf(f->output, "TEL;TYPE=cell,voice:%s\n", rfc2426_escape(item->contact->mobile_phone));
6b1b602514db Initial revision
carl
parents:
diff changeset
544 if (item->contact->other_phone != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
545 fprintf(f->output, "TEL;TYPE=msg:%s\n", rfc2426_escape(item->contact->other_phone));
6b1b602514db Initial revision
carl
parents:
diff changeset
546 if (item->contact->pager_phone != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
547 fprintf(f->output, "TEL;TYPE=pager:%s\n", rfc2426_escape(item->contact->pager_phone));
6b1b602514db Initial revision
carl
parents:
diff changeset
548 if (item->contact->primary_fax != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
549 fprintf(f->output, "TEL;TYPE=fax,pref:%s\n", rfc2426_escape(item->contact->primary_fax));
6b1b602514db Initial revision
carl
parents:
diff changeset
550 if (item->contact->primary_phone != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
551 fprintf(f->output, "TEL;TYPE=phone,pref:%s\n", rfc2426_escape(item->contact->primary_phone));
6b1b602514db Initial revision
carl
parents:
diff changeset
552 if (item->contact->radio_phone != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
553 fprintf(f->output, "TEL;TYPE=pcs:%s\n", rfc2426_escape(item->contact->radio_phone));
6b1b602514db Initial revision
carl
parents:
diff changeset
554 if (item->contact->telex != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
555 fprintf(f->output, "TEL;TYPE=bbs:%s\n", rfc2426_escape(item->contact->telex));
6b1b602514db Initial revision
carl
parents:
diff changeset
556 if (item->contact->job_title != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
557 fprintf(f->output, "TITLE:%s\n", rfc2426_escape(item->contact->job_title));
6b1b602514db Initial revision
carl
parents:
diff changeset
558 if (item->contact->profession != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
559 fprintf(f->output, "ROLE:%s\n", rfc2426_escape(item->contact->profession));
6b1b602514db Initial revision
carl
parents:
diff changeset
560 if (item->contact->assistant_name != NULL || item->contact->assistant_phone != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
561 fprintf(f->output, "AGENT:BEGIN:VCARD\\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
562 if (item->contact->assistant_name != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
563 fprintf(f->output, "FN:%s\\n", rfc2426_escape(item->contact->assistant_name));
6b1b602514db Initial revision
carl
parents:
diff changeset
564 if (item->contact->assistant_phone != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
565 fprintf(f->output, "TEL:%s\\n", rfc2426_escape(item->contact->assistant_phone));
6b1b602514db Initial revision
carl
parents:
diff changeset
566 fprintf(f->output, "END:VCARD\\n\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
567 }
6b1b602514db Initial revision
carl
parents:
diff changeset
568 if (item->contact->company_name != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
569 fprintf(f->output, "ORG:%s\n", rfc2426_escape(item->contact->company_name));
6b1b602514db Initial revision
carl
parents:
diff changeset
570 if (item->comment != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
571 fprintf(f->output, "NOTE:%s\n", rfc2426_escape(item->comment));
6b1b602514db Initial revision
carl
parents:
diff changeset
572
6b1b602514db Initial revision
carl
parents:
diff changeset
573 fprintf(f->output, "VERSION: 3.0\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
574 fprintf(f->output, "END:VCARD\n\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
575 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
576 fprintf(f->output, "%s <%s>\n", item->contact->fullname, item->contact->address1);
6b1b602514db Initial revision
carl
parents:
diff changeset
577 }
6b1b602514db Initial revision
carl
parents:
diff changeset
578 }
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
579 // }}}2
0
6b1b602514db Initial revision
carl
parents:
diff changeset
580 } else if (item->email != NULL &&
6b1b602514db Initial revision
carl
parents:
diff changeset
581 (item->type == PST_TYPE_NOTE || item->type == PST_TYPE_REPORT)) {
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
582 // Process Email item {{{2
0
6b1b602514db Initial revision
carl
parents:
diff changeset
583 if (mode == MODE_SEPERATE) {
6b1b602514db Initial revision
carl
parents:
diff changeset
584 mk_seperate_file(f);
6b1b602514db Initial revision
carl
parents:
diff changeset
585 }
6b1b602514db Initial revision
carl
parents:
diff changeset
586
6b1b602514db Initial revision
carl
parents:
diff changeset
587 f->email_count++;
6b1b602514db Initial revision
carl
parents:
diff changeset
588
6b1b602514db Initial revision
carl
parents:
diff changeset
589 DEBUG_MAIN(("main: seen an email\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
590
6b1b602514db Initial revision
carl
parents:
diff changeset
591 // convert the sent date if it exists, or set it to a fixed date
6b1b602514db Initial revision
carl
parents:
diff changeset
592 if (item->email->sent_date != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
593 em_time = fileTimeToUnixTime(item->email->sent_date, 0);
6b1b602514db Initial revision
carl
parents:
diff changeset
594 c_time = ctime(&em_time);
6b1b602514db Initial revision
carl
parents:
diff changeset
595 if (c_time != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
596 c_time[strlen(c_time)-1] = '\0'; //remove end \n
6b1b602514db Initial revision
carl
parents:
diff changeset
597 else
6b1b602514db Initial revision
carl
parents:
diff changeset
598 c_time = "Fri Dec 28 12:06:21 2001";
6b1b602514db Initial revision
carl
parents:
diff changeset
599 } else
6b1b602514db Initial revision
carl
parents:
diff changeset
600 c_time= "Fri Dec 28 12:06:21 2001";
6b1b602514db Initial revision
carl
parents:
diff changeset
601
6b1b602514db Initial revision
carl
parents:
diff changeset
602 // if the boundary is still set from the previous run, then free it
6b1b602514db Initial revision
carl
parents:
diff changeset
603 if (boundary != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
604 free (boundary);
6b1b602514db Initial revision
carl
parents:
diff changeset
605 boundary = NULL;
6b1b602514db Initial revision
carl
parents:
diff changeset
606 }
6b1b602514db Initial revision
carl
parents:
diff changeset
607
6b1b602514db Initial revision
carl
parents:
diff changeset
608 // we will always look at the header to discover some stuff
6b1b602514db Initial revision
carl
parents:
diff changeset
609 if (item->email->header != NULL ) {
6b1b602514db Initial revision
carl
parents:
diff changeset
610 // see if there is a boundary variable there
6b1b602514db Initial revision
carl
parents:
diff changeset
611 // this search MUST be made case insensitive (DONE).
6b1b602514db Initial revision
carl
parents:
diff changeset
612 // Also, some check to find out if we
6b1b602514db Initial revision
carl
parents:
diff changeset
613 // are looking at the boundary associated with content-type, and that the content
6b1b602514db Initial revision
carl
parents:
diff changeset
614 // type really is "multipart"
6b1b602514db Initial revision
carl
parents:
diff changeset
615 if ((b2 = my_stristr(item->email->header, "boundary=")) != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
616 b2 += strlen("boundary="); // move boundary to first char of marker
6b1b602514db Initial revision
carl
parents:
diff changeset
617
6b1b602514db Initial revision
carl
parents:
diff changeset
618 if (*b2 == '"') {
6b1b602514db Initial revision
carl
parents:
diff changeset
619 b2++;
6b1b602514db Initial revision
carl
parents:
diff changeset
620 b1 = strchr(b2, '"'); // find terminating quote
6b1b602514db Initial revision
carl
parents:
diff changeset
621 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
622 b1 = b2;
6b1b602514db Initial revision
carl
parents:
diff changeset
623 while (isgraph(*b1)) // find first char that isn't part of boundary
6b1b602514db Initial revision
carl
parents:
diff changeset
624 b1++;
6b1b602514db Initial revision
carl
parents:
diff changeset
625 }
6b1b602514db Initial revision
carl
parents:
diff changeset
626
6b1b602514db Initial revision
carl
parents:
diff changeset
627 boundary = malloc ((b1-b2)+1); //malloc that length
6b1b602514db Initial revision
carl
parents:
diff changeset
628 memset (boundary, 0, (b1-b2)+1); // blank it
6b1b602514db Initial revision
carl
parents:
diff changeset
629 strncpy(boundary, b2, b1-b2); // copy boundary to another variable
6b1b602514db Initial revision
carl
parents:
diff changeset
630 b1 = b2 = boundary;
6b1b602514db Initial revision
carl
parents:
diff changeset
631 while (*b2 != '\0') { // remove any CRs and Tabs
6b1b602514db Initial revision
carl
parents:
diff changeset
632 if (*b2 != '\n' && *b2 != '\r' && *b2 != '\t') {
6b1b602514db Initial revision
carl
parents:
diff changeset
633 *b1 = *b2;
6b1b602514db Initial revision
carl
parents:
diff changeset
634 b1++;
6b1b602514db Initial revision
carl
parents:
diff changeset
635 }
6b1b602514db Initial revision
carl
parents:
diff changeset
636 b2++;
6b1b602514db Initial revision
carl
parents:
diff changeset
637 }
6b1b602514db Initial revision
carl
parents:
diff changeset
638 *b1 = '\0';
6b1b602514db Initial revision
carl
parents:
diff changeset
639
6b1b602514db Initial revision
carl
parents:
diff changeset
640 DEBUG_MAIN(("main: Found boundary of - %s\n", boundary));
6b1b602514db Initial revision
carl
parents:
diff changeset
641 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
642
6b1b602514db Initial revision
carl
parents:
diff changeset
643 DEBUG_MAIN(("main: boundary not found in header\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
644 }
6b1b602514db Initial revision
carl
parents:
diff changeset
645
6b1b602514db Initial revision
carl
parents:
diff changeset
646 // also possible to set 7bit encoding detection here.
6b1b602514db Initial revision
carl
parents:
diff changeset
647 if ((b2 = my_stristr(item->email->header, "Content-Transfer-Encoding:")) != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
648 if ((b2 = strchr(b2, ':')) != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
649 b2++; // skip to the : at the end of the string
6b1b602514db Initial revision
carl
parents:
diff changeset
650
6b1b602514db Initial revision
carl
parents:
diff changeset
651 while (*b2 == ' ' || *b2 == '\t')
6b1b602514db Initial revision
carl
parents:
diff changeset
652 b2++;
6b1b602514db Initial revision
carl
parents:
diff changeset
653 if (pst_strincmp(b2, "base64", 6)==0) {
6b1b602514db Initial revision
carl
parents:
diff changeset
654 DEBUG_MAIN(("body is base64 encoded\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
655 base64_body = 1;
6b1b602514db Initial revision
carl
parents:
diff changeset
656 }
6b1b602514db Initial revision
carl
parents:
diff changeset
657 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
658 DEBUG_WARN(("found a ':' during the my_stristr, but not after that..\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
659 }
6b1b602514db Initial revision
carl
parents:
diff changeset
660 }
6b1b602514db Initial revision
carl
parents:
diff changeset
661
6b1b602514db Initial revision
carl
parents:
diff changeset
662 }
6b1b602514db Initial revision
carl
parents:
diff changeset
663 if (boundary == NULL && (item->attach ||(item->email->body && item->email->htmlbody)
6b1b602514db Initial revision
carl
parents:
diff changeset
664 || item->email->rtf_compressed || item->email->encrypted_body
6b1b602514db Initial revision
carl
parents:
diff changeset
665 || item->email->encrypted_htmlbody)) {
6b1b602514db Initial revision
carl
parents:
diff changeset
666 // we need to create a boundary here.
6b1b602514db Initial revision
carl
parents:
diff changeset
667 DEBUG_EMAIL(("main: must create own boundary. oh dear.\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
668 boundary = malloc(50 * sizeof(char)); // allow 50 chars for boundary
6b1b602514db Initial revision
carl
parents:
diff changeset
669 boundary[0] = '\0';
6b1b602514db Initial revision
carl
parents:
diff changeset
670 sprintf(boundary, "--boundary-LibPST-iamunique-%i_-_-", rand());
6b1b602514db Initial revision
carl
parents:
diff changeset
671 DEBUG_EMAIL(("main: created boundary is %s\n", boundary));
6b1b602514db Initial revision
carl
parents:
diff changeset
672 }
6b1b602514db Initial revision
carl
parents:
diff changeset
673
6b1b602514db Initial revision
carl
parents:
diff changeset
674 DEBUG_MAIN(("main: About to print Header\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
675
6b1b602514db Initial revision
carl
parents:
diff changeset
676 if (item != NULL && item->email != NULL && item->email->subject != NULL &&
6b1b602514db Initial revision
carl
parents:
diff changeset
677 item->email->subject->subj != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
678 DEBUG_EMAIL(("item->email->subject->subj = %p\n", item->email->subject->subj));
6b1b602514db Initial revision
carl
parents:
diff changeset
679 }
6b1b602514db Initial revision
carl
parents:
diff changeset
680 if (item->email->header != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
681 // some of the headers we get from the file are not properly defined.
6b1b602514db Initial revision
carl
parents:
diff changeset
682 // they can contain some email stuff too. We will cut off the header
6b1b602514db Initial revision
carl
parents:
diff changeset
683 // when we see a \n\n or \r\n\r\n
6b1b602514db Initial revision
carl
parents:
diff changeset
684
6b1b602514db Initial revision
carl
parents:
diff changeset
685 removeCR(item->email->header);
6b1b602514db Initial revision
carl
parents:
diff changeset
686
6b1b602514db Initial revision
carl
parents:
diff changeset
687 temp = strstr(item->email->header, "\n\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
688
6b1b602514db Initial revision
carl
parents:
diff changeset
689 if (temp != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
690 DEBUG_MAIN(("main: Found body text in header\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
691 temp += 2; // get past the \n\n
6b1b602514db Initial revision
carl
parents:
diff changeset
692 *temp = '\0';
6b1b602514db Initial revision
carl
parents:
diff changeset
693 }
6b1b602514db Initial revision
carl
parents:
diff changeset
694
6b1b602514db Initial revision
carl
parents:
diff changeset
695 if (mode != MODE_SEPERATE) {
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
696 char *soh = NULL; // real start of headers.
0
6b1b602514db Initial revision
carl
parents:
diff changeset
697 // don't put rubbish in if we are doing seperate
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
698 fprintf(f->output, "From \"%s\" %s\n", item->email->outlook_sender_name, c_time);
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
699 soh = skip_header_prologue(item->email->header);
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
700 fprintf(f->output, "%s\n\n", soh);
0
6b1b602514db Initial revision
carl
parents:
diff changeset
701 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
702 fprintf(f->output, "%s\n", item->email->header);
6b1b602514db Initial revision
carl
parents:
diff changeset
703 }
6b1b602514db Initial revision
carl
parents:
diff changeset
704 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
705 //make up our own header!
6b1b602514db Initial revision
carl
parents:
diff changeset
706 if (mode != MODE_SEPERATE) {
6b1b602514db Initial revision
carl
parents:
diff changeset
707 // don't want this first line for this mode
6b1b602514db Initial revision
carl
parents:
diff changeset
708 if (item->email->outlook_sender_name != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
709 temp = item->email->outlook_sender_name;
6b1b602514db Initial revision
carl
parents:
diff changeset
710 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
711 temp = "(readpst_null)";
6b1b602514db Initial revision
carl
parents:
diff changeset
712 }
6b1b602514db Initial revision
carl
parents:
diff changeset
713 fprintf(f->output, "From \"%s\" %s\n", temp, c_time);
6b1b602514db Initial revision
carl
parents:
diff changeset
714 }
6b1b602514db Initial revision
carl
parents:
diff changeset
715 if ((temp = item->email->outlook_sender) == NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
716 temp = "";
6b1b602514db Initial revision
carl
parents:
diff changeset
717 fprintf(f->output, "From: \"%s\" <%s>\n", item->email->outlook_sender_name, temp);
6b1b602514db Initial revision
carl
parents:
diff changeset
718 if (item->email->subject != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
719 fprintf(f->output, "Subject: %s\n", item->email->subject->subj);
6b1b602514db Initial revision
carl
parents:
diff changeset
720 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
721 fprintf(f->output, "Subject: \n");
6b1b602514db Initial revision
carl
parents:
diff changeset
722 }
6b1b602514db Initial revision
carl
parents:
diff changeset
723 fprintf(f->output, "To: %s\n", item->email->sentto_address);
6b1b602514db Initial revision
carl
parents:
diff changeset
724 if (item->email->cc_address != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
725 fprintf(f->output, "CC: %s\n", item->email->cc_address);
6b1b602514db Initial revision
carl
parents:
diff changeset
726 }
6b1b602514db Initial revision
carl
parents:
diff changeset
727 if (item->email->sent_date != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
728 c_time = (char*) xmalloc(C_TIME_SIZE);
6b1b602514db Initial revision
carl
parents:
diff changeset
729 strftime(c_time, C_TIME_SIZE, "%a, %d %b %Y %H:%M:%S %z", gmtime(&em_time));
6b1b602514db Initial revision
carl
parents:
diff changeset
730 fprintf(f->output, "Date: %s\n", c_time);
6b1b602514db Initial revision
carl
parents:
diff changeset
731 free(c_time);
6b1b602514db Initial revision
carl
parents:
diff changeset
732 }
6b1b602514db Initial revision
carl
parents:
diff changeset
733
6b1b602514db Initial revision
carl
parents:
diff changeset
734 fprintf(f->output, "MIME-Version: 1.0\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
735 if (item->attach != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
736 // write the boundary stuff if we have attachments
6b1b602514db Initial revision
carl
parents:
diff changeset
737 fprintf(f->output, "Content-type: multipart/mixed;\n\tboundary=\"%s\"\n",
6b1b602514db Initial revision
carl
parents:
diff changeset
738 boundary);
6b1b602514db Initial revision
carl
parents:
diff changeset
739 } else if (item->email->htmlbody && item->email->body) {
6b1b602514db Initial revision
carl
parents:
diff changeset
740 // else if we have an html and text body then tell it so
6b1b602514db Initial revision
carl
parents:
diff changeset
741 fprintf(f->output, "Content-type: multipart/alternate;\n\tboundary=\"%s\"\n",
6b1b602514db Initial revision
carl
parents:
diff changeset
742 boundary);
6b1b602514db Initial revision
carl
parents:
diff changeset
743 } else if (item->email->htmlbody) {
6b1b602514db Initial revision
carl
parents:
diff changeset
744 fprintf(f->output, "Content-type: text/html\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
745 }
6b1b602514db Initial revision
carl
parents:
diff changeset
746 fprintf(f->output, "\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
747 }
6b1b602514db Initial revision
carl
parents:
diff changeset
748
6b1b602514db Initial revision
carl
parents:
diff changeset
749
6b1b602514db Initial revision
carl
parents:
diff changeset
750 DEBUG_MAIN(("main: About to print Body\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
751
6b1b602514db Initial revision
carl
parents:
diff changeset
752 if (item->email->body != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
753 if (boundary) {
6b1b602514db Initial revision
carl
parents:
diff changeset
754 fprintf(f->output, "\n--%s\n", boundary);
6b1b602514db Initial revision
carl
parents:
diff changeset
755 fprintf(f->output, "Content-type: text/plain\n\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
756 if (base64_body)
6b1b602514db Initial revision
carl
parents:
diff changeset
757 fprintf(f->output, "Content-Transfer-Encoding: base64\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
758 }
6b1b602514db Initial revision
carl
parents:
diff changeset
759 removeCR(item->email->body);
6b1b602514db Initial revision
carl
parents:
diff changeset
760 if (base64_body)
6b1b602514db Initial revision
carl
parents:
diff changeset
761 write_email_body(f->output, base64_encode(item->email->body,
6b1b602514db Initial revision
carl
parents:
diff changeset
762 strlen(item->email->body)));
6b1b602514db Initial revision
carl
parents:
diff changeset
763 else
6b1b602514db Initial revision
carl
parents:
diff changeset
764 write_email_body(f->output, item->email->body);
6b1b602514db Initial revision
carl
parents:
diff changeset
765 }
6b1b602514db Initial revision
carl
parents:
diff changeset
766
6b1b602514db Initial revision
carl
parents:
diff changeset
767 if (item->email->htmlbody != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
768 if (boundary) {
6b1b602514db Initial revision
carl
parents:
diff changeset
769 fprintf(f->output, "\n--%s\n", boundary);
6b1b602514db Initial revision
carl
parents:
diff changeset
770 fprintf(f->output, "Content-type: text/html\n\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
771 if (base64_body)
6b1b602514db Initial revision
carl
parents:
diff changeset
772 fprintf(f->output, "Content-Transfer-Encoding: base64\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
773 }
6b1b602514db Initial revision
carl
parents:
diff changeset
774 removeCR(item->email->htmlbody);
6b1b602514db Initial revision
carl
parents:
diff changeset
775 if (base64_body)
6b1b602514db Initial revision
carl
parents:
diff changeset
776 write_email_body(f->output, base64_encode(item->email->htmlbody,
6b1b602514db Initial revision
carl
parents:
diff changeset
777 strlen(item->email->htmlbody)));
6b1b602514db Initial revision
carl
parents:
diff changeset
778 else
6b1b602514db Initial revision
carl
parents:
diff changeset
779 write_email_body(f->output, item->email->htmlbody);
6b1b602514db Initial revision
carl
parents:
diff changeset
780 }
6b1b602514db Initial revision
carl
parents:
diff changeset
781
6b1b602514db Initial revision
carl
parents:
diff changeset
782 attach_num = 0;
6b1b602514db Initial revision
carl
parents:
diff changeset
783
6b1b602514db Initial revision
carl
parents:
diff changeset
784 if (item->email->rtf_compressed != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
785 DEBUG_MAIN(("Adding RTF body as attachment\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
786 item->current_attach = (pst_item_attach*)xmalloc(sizeof(pst_item_attach));
6b1b602514db Initial revision
carl
parents:
diff changeset
787 memset(item->current_attach, 0, sizeof(pst_item_attach));
6b1b602514db Initial revision
carl
parents:
diff changeset
788 item->current_attach->next = item->attach;
6b1b602514db Initial revision
carl
parents:
diff changeset
789 item->attach = item->current_attach;
6b1b602514db Initial revision
carl
parents:
diff changeset
790 item->current_attach->data = lzfu_decompress(item->email->rtf_compressed);
6b1b602514db Initial revision
carl
parents:
diff changeset
791 item->current_attach->filename2 = xmalloc(strlen(RTF_ATTACH_NAME)+2);
6b1b602514db Initial revision
carl
parents:
diff changeset
792 strcpy(item->current_attach->filename2, RTF_ATTACH_NAME);
6b1b602514db Initial revision
carl
parents:
diff changeset
793 item->current_attach->mimetype = xmalloc(strlen(RTF_ATTACH_TYPE)+2);
6b1b602514db Initial revision
carl
parents:
diff changeset
794 strcpy(item->current_attach->mimetype, RTF_ATTACH_TYPE);
6b1b602514db Initial revision
carl
parents:
diff changeset
795 memcpy(&(item->current_attach->size), item->email->rtf_compressed+sizeof(int32_t), sizeof(int32_t));
6b1b602514db Initial revision
carl
parents:
diff changeset
796 LE32_CPU(item->current_attach->size);
6b1b602514db Initial revision
carl
parents:
diff changeset
797 // item->email->rtf_compressed = ;
6b1b602514db Initial revision
carl
parents:
diff changeset
798 // attach_num++;
6b1b602514db Initial revision
carl
parents:
diff changeset
799 }
6b1b602514db Initial revision
carl
parents:
diff changeset
800 if (item->email->encrypted_body || item->email->encrypted_htmlbody) {
6b1b602514db Initial revision
carl
parents:
diff changeset
801 // if either the body or htmlbody is encrypted, add them as attachments
6b1b602514db Initial revision
carl
parents:
diff changeset
802 if (item->email->encrypted_body) {
6b1b602514db Initial revision
carl
parents:
diff changeset
803 DEBUG_MAIN(("Adding Encrypted Body as attachment\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
804 item->current_attach = (pst_item_attach*) xmalloc(sizeof(pst_item_attach));
6b1b602514db Initial revision
carl
parents:
diff changeset
805 memset(item->current_attach, 0, sizeof(pst_item_attach));
6b1b602514db Initial revision
carl
parents:
diff changeset
806 item->current_attach->next = item->attach;
6b1b602514db Initial revision
carl
parents:
diff changeset
807 item->attach = item->current_attach;
6b1b602514db Initial revision
carl
parents:
diff changeset
808
6b1b602514db Initial revision
carl
parents:
diff changeset
809 item->current_attach->data = item->email->encrypted_body;
6b1b602514db Initial revision
carl
parents:
diff changeset
810 item->current_attach->size = item->email->encrypted_body_size;
6b1b602514db Initial revision
carl
parents:
diff changeset
811 item->email->encrypted_body = NULL;
6b1b602514db Initial revision
carl
parents:
diff changeset
812 }
6b1b602514db Initial revision
carl
parents:
diff changeset
813 if (item->email->encrypted_htmlbody) {
6b1b602514db Initial revision
carl
parents:
diff changeset
814 DEBUG_MAIN(("Adding encrypted HTML body as attachment\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
815 item->current_attach = (pst_item_attach*) xmalloc(sizeof(pst_item_attach));
6b1b602514db Initial revision
carl
parents:
diff changeset
816 memset(item->current_attach, 0, sizeof(pst_item_attach));
6b1b602514db Initial revision
carl
parents:
diff changeset
817 item->current_attach->next = item->attach;
6b1b602514db Initial revision
carl
parents:
diff changeset
818 item->attach = item->current_attach;
6b1b602514db Initial revision
carl
parents:
diff changeset
819
6b1b602514db Initial revision
carl
parents:
diff changeset
820 item->current_attach->data = item->email->encrypted_htmlbody;
6b1b602514db Initial revision
carl
parents:
diff changeset
821 item->current_attach->size = item->email->encrypted_htmlbody_size;
6b1b602514db Initial revision
carl
parents:
diff changeset
822 item->email->encrypted_htmlbody = NULL;
6b1b602514db Initial revision
carl
parents:
diff changeset
823 }
6b1b602514db Initial revision
carl
parents:
diff changeset
824 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");
6b1b602514db Initial revision
carl
parents:
diff changeset
825 }
6b1b602514db Initial revision
carl
parents:
diff changeset
826 base64_body = 0;
6b1b602514db Initial revision
carl
parents:
diff changeset
827 // attachments
6b1b602514db Initial revision
carl
parents:
diff changeset
828 item->current_attach = item->attach;
6b1b602514db Initial revision
carl
parents:
diff changeset
829 while (item->current_attach != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
830 DEBUG_MAIN(("main: Attempting Attachment encoding\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
831 if (item->current_attach->data == NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
832 DEBUG_MAIN(("main: Data of attachment is NULL!. Size is supposed to be %i\n", item->current_attach->size));
6b1b602514db Initial revision
carl
parents:
diff changeset
833 }
6b1b602514db Initial revision
carl
parents:
diff changeset
834 if (mode == MODE_SEPERATE) {
6b1b602514db Initial revision
carl
parents:
diff changeset
835 f->name = check_filename(f->name);
6b1b602514db Initial revision
carl
parents:
diff changeset
836 if (item->current_attach->filename2 == NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
837 temp = xmalloc(strlen(f->name)+15);
6b1b602514db Initial revision
carl
parents:
diff changeset
838 sprintf(temp, "%s-attach%i", f->name, attach_num);
6b1b602514db Initial revision
carl
parents:
diff changeset
839 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
840 temp = xmalloc(strlen(f->name)+strlen(item->current_attach->filename2)+15);
6b1b602514db Initial revision
carl
parents:
diff changeset
841 fp = NULL; x=0;
6b1b602514db Initial revision
carl
parents:
diff changeset
842 do {
6b1b602514db Initial revision
carl
parents:
diff changeset
843 if (fp != NULL) fclose(fp);
6b1b602514db Initial revision
carl
parents:
diff changeset
844 if (x == 0)
6b1b602514db Initial revision
carl
parents:
diff changeset
845 sprintf(temp, "%s-%s", f->name, item->current_attach->filename2);
6b1b602514db Initial revision
carl
parents:
diff changeset
846 else
6b1b602514db Initial revision
carl
parents:
diff changeset
847 sprintf(temp, "%s-%s-%i", f->name, item->current_attach->filename2, x);
6b1b602514db Initial revision
carl
parents:
diff changeset
848 } while ((fp = fopen(temp, "r"))!=NULL && ++x < 99999999);
6b1b602514db Initial revision
carl
parents:
diff changeset
849 if (x > 99999999) {
6b1b602514db Initial revision
carl
parents:
diff changeset
850 DIE(("error finding attachment name. exhausted possibilities to %s\n", temp));
6b1b602514db Initial revision
carl
parents:
diff changeset
851 }
6b1b602514db Initial revision
carl
parents:
diff changeset
852 }
6b1b602514db Initial revision
carl
parents:
diff changeset
853 DEBUG_MAIN(("main: Saving attachment to %s\n", temp));
6b1b602514db Initial revision
carl
parents:
diff changeset
854 if ((fp = fopen(temp, "w")) == NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
855 WARN(("main: Cannot open attachment save file \"%s\"\n", temp));
6b1b602514db Initial revision
carl
parents:
diff changeset
856 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
857 if (item->current_attach->data != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
858 fwrite(item->current_attach->data, 1, item->current_attach->size, fp);
6b1b602514db Initial revision
carl
parents:
diff changeset
859 else {
6b1b602514db Initial revision
carl
parents:
diff changeset
860 pst_attach_to_file(&pstfile, item->current_attach, fp);
6b1b602514db Initial revision
carl
parents:
diff changeset
861 }
6b1b602514db Initial revision
carl
parents:
diff changeset
862 fclose(fp);
6b1b602514db Initial revision
carl
parents:
diff changeset
863 }
6b1b602514db Initial revision
carl
parents:
diff changeset
864 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
865 DEBUG_MAIN(("main: Attachment Size is %i\n", item->current_attach->size));
6b1b602514db Initial revision
carl
parents:
diff changeset
866 DEBUG_MAIN(("main: Attachment Pointer is %p\n", item->current_attach->data));
6b1b602514db Initial revision
carl
parents:
diff changeset
867 if (item->current_attach->data != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
868 if ((enc = base64_encode (item->current_attach->data, item->current_attach->size)) == NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
869 DEBUG_MAIN(("main: ERROR base64_encode returned NULL. Must have failed\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
870 item->current_attach = item->current_attach->next;
6b1b602514db Initial revision
carl
parents:
diff changeset
871 continue;
6b1b602514db Initial revision
carl
parents:
diff changeset
872 }
6b1b602514db Initial revision
carl
parents:
diff changeset
873 }
6b1b602514db Initial revision
carl
parents:
diff changeset
874 if (boundary) {
6b1b602514db Initial revision
carl
parents:
diff changeset
875 fprintf(f->output, "\n--%s\n", boundary);
6b1b602514db Initial revision
carl
parents:
diff changeset
876 if (item->current_attach->mimetype == NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
877 fprintf(f->output, "Content-type: %s\n", MIME_TYPE_DEFAULT);
6b1b602514db Initial revision
carl
parents:
diff changeset
878 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
879 fprintf(f->output, "Content-type: %s\n", item->current_attach->mimetype);
6b1b602514db Initial revision
carl
parents:
diff changeset
880 }
6b1b602514db Initial revision
carl
parents:
diff changeset
881 fprintf(f->output, "Content-transfer-encoding: base64\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
882 if (item->current_attach->filename2 == NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
883 fprintf(f->output, "Content-Disposition: inline\n\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
884 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
885 fprintf(f->output, "Content-Disposition: attachment; filename=\"%s\"\n\n",
6b1b602514db Initial revision
carl
parents:
diff changeset
886 item->current_attach->filename2);
6b1b602514db Initial revision
carl
parents:
diff changeset
887 }
6b1b602514db Initial revision
carl
parents:
diff changeset
888 }
6b1b602514db Initial revision
carl
parents:
diff changeset
889 if (item->current_attach->data != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
890 fwrite(enc, 1, strlen(enc), f->output);
6b1b602514db Initial revision
carl
parents:
diff changeset
891 DEBUG_MAIN(("Attachment Size after encoding is %i\n", strlen(enc)));
6b1b602514db Initial revision
carl
parents:
diff changeset
892 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
893 pst_attach_to_file_base64(&pstfile, item->current_attach, f->output);
6b1b602514db Initial revision
carl
parents:
diff changeset
894 }
6b1b602514db Initial revision
carl
parents:
diff changeset
895 fprintf(f->output, "\n\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
896 }
6b1b602514db Initial revision
carl
parents:
diff changeset
897 item->current_attach = item->current_attach->next;
6b1b602514db Initial revision
carl
parents:
diff changeset
898 attach_num++;
6b1b602514db Initial revision
carl
parents:
diff changeset
899 }
6b1b602514db Initial revision
carl
parents:
diff changeset
900 if (mode != MODE_SEPERATE) {
6b1b602514db Initial revision
carl
parents:
diff changeset
901 DEBUG_MAIN(("main: Writing buffer between emails\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
902 if (boundary)
6b1b602514db Initial revision
carl
parents:
diff changeset
903 fprintf(f->output, "\n--%s--\n", boundary);
6b1b602514db Initial revision
carl
parents:
diff changeset
904 fprintf(f->output, "\n\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
905 }
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
906 // }}}2
0
6b1b602514db Initial revision
carl
parents:
diff changeset
907 } else if (item->type == PST_TYPE_JOURNAL) {
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
908 // Process Journal item {{{2
0
6b1b602514db Initial revision
carl
parents:
diff changeset
909 // deal with journal items
6b1b602514db Initial revision
carl
parents:
diff changeset
910 if (mode == MODE_SEPERATE) {
6b1b602514db Initial revision
carl
parents:
diff changeset
911 mk_seperate_file(f);
6b1b602514db Initial revision
carl
parents:
diff changeset
912 }
6b1b602514db Initial revision
carl
parents:
diff changeset
913 f->email_count++;
6b1b602514db Initial revision
carl
parents:
diff changeset
914
6b1b602514db Initial revision
carl
parents:
diff changeset
915 DEBUG_MAIN(("main: Processing Journal Entry\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
916 if (f->type != PST_TYPE_JOURNAL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
917 DEBUG_MAIN(("main: I have a journal entry, but folder isn't specified as a journal type. Processing...\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
918 }
6b1b602514db Initial revision
carl
parents:
diff changeset
919
6b1b602514db Initial revision
carl
parents:
diff changeset
920 /* if (item->type != PST_TYPE_JOURNAL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
921 DEBUG_MAIN(("main: I have an item with journal info, but it's type is \"%s\" \n. Processing...\n",
6b1b602514db Initial revision
carl
parents:
diff changeset
922 item->ascii_type));
6b1b602514db Initial revision
carl
parents:
diff changeset
923 }*/
6b1b602514db Initial revision
carl
parents:
diff changeset
924 fprintf(f->output, "BEGIN:VJOURNAL\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
925 if (item->email->subject != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
926 fprintf(f->output, "SUMMARY:%s\n", rfc2426_escape(item->email->subject->subj));
6b1b602514db Initial revision
carl
parents:
diff changeset
927 if (item->email->body != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
928 fprintf(f->output, "DESCRIPTION:%s\n", rfc2426_escape(item->email->body));
6b1b602514db Initial revision
carl
parents:
diff changeset
929 if (item->journal->start != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
930 fprintf(f->output, "DTSTART;VALUE=DATE-TIME:%s\n", rfc2445_datetime_format(item->journal->start));
6b1b602514db Initial revision
carl
parents:
diff changeset
931 fprintf(f->output, "END:VJOURNAL\n\n");
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
932 // }}}2
0
6b1b602514db Initial revision
carl
parents:
diff changeset
933 } else if (item->type == PST_TYPE_APPOINTMENT) {
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
934 // Process Calendar Appointment item {{{2
0
6b1b602514db Initial revision
carl
parents:
diff changeset
935 // deal with Calendar appointments
6b1b602514db Initial revision
carl
parents:
diff changeset
936 if (mode == MODE_SEPERATE) {
6b1b602514db Initial revision
carl
parents:
diff changeset
937 mk_seperate_file(f);
6b1b602514db Initial revision
carl
parents:
diff changeset
938 }
6b1b602514db Initial revision
carl
parents:
diff changeset
939 f->email_count++;
6b1b602514db Initial revision
carl
parents:
diff changeset
940
6b1b602514db Initial revision
carl
parents:
diff changeset
941 DEBUG_MAIN(("main: Processing Appointment Entry\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
942 if (f->type != PST_TYPE_APPOINTMENT) {
6b1b602514db Initial revision
carl
parents:
diff changeset
943 DEBUG_MAIN(("main: I have an appointment, but folder isn't specified as an appointment type. Processing...\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
944 }
6b1b602514db Initial revision
carl
parents:
diff changeset
945 fprintf(f->output, "BEGIN:VEVENT\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
946 if (item->create_date != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
947 fprintf(f->output, "CREATED:%s\n", rfc2445_datetime_format(item->create_date));
6b1b602514db Initial revision
carl
parents:
diff changeset
948 if (item->modify_date != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
949 fprintf(f->output, "LAST-MOD:%s\n", rfc2445_datetime_format(item->modify_date));
6b1b602514db Initial revision
carl
parents:
diff changeset
950 if (item->email != NULL && item->email->subject != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
951 fprintf(f->output, "SUMMARY:%s\n", rfc2426_escape(item->email->subject->subj));
6b1b602514db Initial revision
carl
parents:
diff changeset
952 if (item->email != NULL && item->email->body != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
953 fprintf(f->output, "DESCRIPTION:%s\n", rfc2426_escape(item->email->body));
6b1b602514db Initial revision
carl
parents:
diff changeset
954 if (item->appointment != NULL && item->appointment->start != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
955 fprintf(f->output, "DTSTART;VALUE=DATE-TIME:%s\n", rfc2445_datetime_format(item->appointment->start));
6b1b602514db Initial revision
carl
parents:
diff changeset
956 if (item->appointment != NULL && item->appointment->end != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
957 fprintf(f->output, "DTEND;VALUE=DATE-TIME:%s\n", rfc2445_datetime_format(item->appointment->end));
6b1b602514db Initial revision
carl
parents:
diff changeset
958 if (item->appointment != NULL && item->appointment->location != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
959 fprintf(f->output, "LOCATION:%s\n", rfc2426_escape(item->appointment->location));
6b1b602514db Initial revision
carl
parents:
diff changeset
960 if (item->appointment != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
961 switch (item->appointment->showas) {
6b1b602514db Initial revision
carl
parents:
diff changeset
962 case PST_FREEBUSY_TENTATIVE:
6b1b602514db Initial revision
carl
parents:
diff changeset
963 fprintf(f->output, "STATUS:TENTATIVE\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
964 break;
6b1b602514db Initial revision
carl
parents:
diff changeset
965 case PST_FREEBUSY_FREE:
6b1b602514db Initial revision
carl
parents:
diff changeset
966 // mark as transparent and as confirmed
6b1b602514db Initial revision
carl
parents:
diff changeset
967 fprintf(f->output, "TRANSP:TRANSPARENT\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
968 case PST_FREEBUSY_BUSY:
6b1b602514db Initial revision
carl
parents:
diff changeset
969 case PST_FREEBUSY_OUT_OF_OFFICE:
6b1b602514db Initial revision
carl
parents:
diff changeset
970 fprintf(f->output, "STATUS:CONFIRMED\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
971 break;
6b1b602514db Initial revision
carl
parents:
diff changeset
972 }
6b1b602514db Initial revision
carl
parents:
diff changeset
973 switch (item->appointment->label) {
6b1b602514db Initial revision
carl
parents:
diff changeset
974 case PST_APP_LABEL_NONE:
6b1b602514db Initial revision
carl
parents:
diff changeset
975 fprintf(f->output, "CATEGORIES:NONE\n"); break;
6b1b602514db Initial revision
carl
parents:
diff changeset
976 case PST_APP_LABEL_IMPORTANT:
6b1b602514db Initial revision
carl
parents:
diff changeset
977 fprintf(f->output, "CATEGORIES:IMPORTANT\n"); break;
6b1b602514db Initial revision
carl
parents:
diff changeset
978 case PST_APP_LABEL_BUSINESS:
6b1b602514db Initial revision
carl
parents:
diff changeset
979 fprintf(f->output, "CATEGORIES:BUSINESS\n"); break;
6b1b602514db Initial revision
carl
parents:
diff changeset
980 case PST_APP_LABEL_PERSONAL:
6b1b602514db Initial revision
carl
parents:
diff changeset
981 fprintf(f->output, "CATEGORIES:PERSONAL\n"); break;
6b1b602514db Initial revision
carl
parents:
diff changeset
982 case PST_APP_LABEL_VACATION:
6b1b602514db Initial revision
carl
parents:
diff changeset
983 fprintf(f->output, "CATEGORIES:VACATION\n"); break;
6b1b602514db Initial revision
carl
parents:
diff changeset
984 case PST_APP_LABEL_MUST_ATTEND:
6b1b602514db Initial revision
carl
parents:
diff changeset
985 fprintf(f->output, "CATEGORIES:MUST-ATTEND\n"); break;
6b1b602514db Initial revision
carl
parents:
diff changeset
986 case PST_APP_LABEL_TRAVEL_REQ:
6b1b602514db Initial revision
carl
parents:
diff changeset
987 fprintf(f->output, "CATEGORIES:TRAVEL-REQUIRED\n"); break;
6b1b602514db Initial revision
carl
parents:
diff changeset
988 case PST_APP_LABEL_NEEDS_PREP:
6b1b602514db Initial revision
carl
parents:
diff changeset
989 fprintf(f->output, "CATEGORIES:NEEDS-PREPARATION\n"); break;
6b1b602514db Initial revision
carl
parents:
diff changeset
990 case PST_APP_LABEL_BIRTHDAY:
6b1b602514db Initial revision
carl
parents:
diff changeset
991 fprintf(f->output, "CATEGORIES:BIRTHDAY\n"); break;
6b1b602514db Initial revision
carl
parents:
diff changeset
992 case PST_APP_LABEL_ANNIVERSARY:
6b1b602514db Initial revision
carl
parents:
diff changeset
993 fprintf(f->output, "CATEGORIES:ANNIVERSARY\n"); break;
6b1b602514db Initial revision
carl
parents:
diff changeset
994 case PST_APP_LABEL_PHONE_CALL:
6b1b602514db Initial revision
carl
parents:
diff changeset
995 fprintf(f->output, "CATEGORIES:PHONE-CALL\n"); break;
6b1b602514db Initial revision
carl
parents:
diff changeset
996 }
6b1b602514db Initial revision
carl
parents:
diff changeset
997 }
6b1b602514db Initial revision
carl
parents:
diff changeset
998 fprintf(f->output, "END:VEVENT\n\n");
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
999 // }}}2
0
6b1b602514db Initial revision
carl
parents:
diff changeset
1000 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
1001 f->skip_count++;
6b1b602514db Initial revision
carl
parents:
diff changeset
1002 DEBUG_MAIN(("main: Unknown item type. %i. Ascii1=\"%s\"\n",
6b1b602514db Initial revision
carl
parents:
diff changeset
1003 item->type, item->ascii_type));
6b1b602514db Initial revision
carl
parents:
diff changeset
1004 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1005 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
1006 f->skip_count++;
6b1b602514db Initial revision
carl
parents:
diff changeset
1007 DEBUG_MAIN(("main: A NULL item was seen\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
1008 }
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1009
0
6b1b602514db Initial revision
carl
parents:
diff changeset
1010 DEBUG_MAIN(("main: Going to next d_ptr\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
1011 if (boundary) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1012 free(boundary);
6b1b602514db Initial revision
carl
parents:
diff changeset
1013 boundary = NULL;
6b1b602514db Initial revision
carl
parents:
diff changeset
1014 }
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1015
0
6b1b602514db Initial revision
carl
parents:
diff changeset
1016 check_parent:
6b1b602514db Initial revision
carl
parents:
diff changeset
1017 // _pst_freeItem(item);
6b1b602514db Initial revision
carl
parents:
diff changeset
1018 while (!skip_child && d_ptr->next == NULL && d_ptr->parent != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1019 DEBUG_MAIN(("main: Going to Parent\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
1020 head = f->next;
6b1b602514db Initial revision
carl
parents:
diff changeset
1021 if (f->output != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
1022 fclose(f->output);
6b1b602514db Initial revision
carl
parents:
diff changeset
1023 DEBUG_MAIN(("main: Email Count for folder %s is %i\n", f->dname, f->email_count));
6b1b602514db Initial revision
carl
parents:
diff changeset
1024 if (output_mode != OUTPUT_QUIET)
6b1b602514db Initial revision
carl
parents:
diff changeset
1025 printf("\t\"%s\" - %i items done, skipped %i, should have been %i\n",
6b1b602514db Initial revision
carl
parents:
diff changeset
1026 f->dname, f->email_count, f->skip_count, f->stored_count);
6b1b602514db Initial revision
carl
parents:
diff changeset
1027 if (mode == MODE_KMAIL)
6b1b602514db Initial revision
carl
parents:
diff changeset
1028 close_kmail_dir();
6b1b602514db Initial revision
carl
parents:
diff changeset
1029 else if (mode == MODE_RECURSE)
6b1b602514db Initial revision
carl
parents:
diff changeset
1030 close_recurse_dir();
6b1b602514db Initial revision
carl
parents:
diff changeset
1031 else if (mode == MODE_SEPERATE)
6b1b602514db Initial revision
carl
parents:
diff changeset
1032 close_seperate_dir();
6b1b602514db Initial revision
carl
parents:
diff changeset
1033 free(f->name);
6b1b602514db Initial revision
carl
parents:
diff changeset
1034 free(f->dname);
6b1b602514db Initial revision
carl
parents:
diff changeset
1035 free(f);
6b1b602514db Initial revision
carl
parents:
diff changeset
1036 f = head;
6b1b602514db Initial revision
carl
parents:
diff changeset
1037 if (head == NULL) { //we can't go higher. Must be at start?
6b1b602514db Initial revision
carl
parents:
diff changeset
1038 DEBUG_MAIN(("main: We are now trying to go above the highest level. We must be finished\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
1039 break; //from main while loop
6b1b602514db Initial revision
carl
parents:
diff changeset
1040 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1041 d_ptr = d_ptr->parent;
6b1b602514db Initial revision
carl
parents:
diff changeset
1042 skip_child = 0;
6b1b602514db Initial revision
carl
parents:
diff changeset
1043 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1044
6b1b602514db Initial revision
carl
parents:
diff changeset
1045 if (item != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1046 DEBUG_MAIN(("main: Freeing memory used by item\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
1047 _pst_freeItem(item);
6b1b602514db Initial revision
carl
parents:
diff changeset
1048 item = NULL;
6b1b602514db Initial revision
carl
parents:
diff changeset
1049 }
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1050
0
6b1b602514db Initial revision
carl
parents:
diff changeset
1051 if (!skip_child)
6b1b602514db Initial revision
carl
parents:
diff changeset
1052 d_ptr = d_ptr->next;
6b1b602514db Initial revision
carl
parents:
diff changeset
1053 else
6b1b602514db Initial revision
carl
parents:
diff changeset
1054 skip_child = 0;
6b1b602514db Initial revision
carl
parents:
diff changeset
1055
6b1b602514db Initial revision
carl
parents:
diff changeset
1056 if (d_ptr == NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1057 DEBUG_MAIN(("main: d_ptr is now NULL\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
1058 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1059 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1060 if (output_mode != OUTPUT_QUIET) printf("Finished.\n");
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1061 DEBUG_MAIN(("main: Finished.\n"));
0
6b1b602514db Initial revision
carl
parents:
diff changeset
1062
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1063 // Cleanup {{{2
0
6b1b602514db Initial revision
carl
parents:
diff changeset
1064 pst_close(&pstfile);
6b1b602514db Initial revision
carl
parents:
diff changeset
1065 // fclose(pstfile.fp);
6b1b602514db Initial revision
carl
parents:
diff changeset
1066 while (f != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1067 if (f->output != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
1068 fclose(f->output);
6b1b602514db Initial revision
carl
parents:
diff changeset
1069 free(f->name);
6b1b602514db Initial revision
carl
parents:
diff changeset
1070 free(f->dname);
6b1b602514db Initial revision
carl
parents:
diff changeset
1071
6b1b602514db Initial revision
carl
parents:
diff changeset
1072 if (mode == MODE_KMAIL)
6b1b602514db Initial revision
carl
parents:
diff changeset
1073 close_kmail_dir();
6b1b602514db Initial revision
carl
parents:
diff changeset
1074 else if (mode == MODE_RECURSE)
6b1b602514db Initial revision
carl
parents:
diff changeset
1075 close_recurse_dir();
6b1b602514db Initial revision
carl
parents:
diff changeset
1076 else if (mode == MODE_SEPERATE)
6b1b602514db Initial revision
carl
parents:
diff changeset
1077 // DO SOMETHING HERE
6b1b602514db Initial revision
carl
parents:
diff changeset
1078 ;
6b1b602514db Initial revision
carl
parents:
diff changeset
1079 head = f->next;
6b1b602514db Initial revision
carl
parents:
diff changeset
1080 free (f);
6b1b602514db Initial revision
carl
parents:
diff changeset
1081 f = head;
6b1b602514db Initial revision
carl
parents:
diff changeset
1082 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1083
6b1b602514db Initial revision
carl
parents:
diff changeset
1084 DEBUG_RET();
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1085 // }}}2
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1086
0
6b1b602514db Initial revision
carl
parents:
diff changeset
1087 return 0;
6b1b602514db Initial revision
carl
parents:
diff changeset
1088 }
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1089 // }}}1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1090 // void write_email_body(FILE *f, char *body) {{{1
0
6b1b602514db Initial revision
carl
parents:
diff changeset
1091 void write_email_body(FILE *f, char *body) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1092 char *n = body;
6b1b602514db Initial revision
carl
parents:
diff changeset
1093 // DEBUG_MAIN(("write_email_body(): \"%s\"\n", body));
6b1b602514db Initial revision
carl
parents:
diff changeset
1094 DEBUG_ENT("write_email_body");
6b1b602514db Initial revision
carl
parents:
diff changeset
1095 while (n != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1096 if (strncmp(body, "From ", 5) == 0)
6b1b602514db Initial revision
carl
parents:
diff changeset
1097 fprintf(f, ">");
6b1b602514db Initial revision
carl
parents:
diff changeset
1098 if ((n = strchr(body, '\n'))) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1099 n++;
6b1b602514db Initial revision
carl
parents:
diff changeset
1100 fwrite(body, n-body, 1, f); //write just a line
6b1b602514db Initial revision
carl
parents:
diff changeset
1101
6b1b602514db Initial revision
carl
parents:
diff changeset
1102 body = n;
6b1b602514db Initial revision
carl
parents:
diff changeset
1103 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1104 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1105 fwrite(body, strlen(body), 1, f);
6b1b602514db Initial revision
carl
parents:
diff changeset
1106 DEBUG_RET();
6b1b602514db Initial revision
carl
parents:
diff changeset
1107 }
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1108 // }}}1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1109 // char *removeCR (char *c) {{{1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1110 char *removeCR (char *c) {
0
6b1b602514db Initial revision
carl
parents:
diff changeset
1111 // converts /r/n to /n
6b1b602514db Initial revision
carl
parents:
diff changeset
1112 char *a, *b;
6b1b602514db Initial revision
carl
parents:
diff changeset
1113 DEBUG_ENT("removeCR");
6b1b602514db Initial revision
carl
parents:
diff changeset
1114 a = b = c;
6b1b602514db Initial revision
carl
parents:
diff changeset
1115 while (*a != '\0') {
6b1b602514db Initial revision
carl
parents:
diff changeset
1116 *b = *a;
6b1b602514db Initial revision
carl
parents:
diff changeset
1117 if (*a != '\r')
6b1b602514db Initial revision
carl
parents:
diff changeset
1118 b++;
6b1b602514db Initial revision
carl
parents:
diff changeset
1119 a++;
6b1b602514db Initial revision
carl
parents:
diff changeset
1120 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1121 *b = '\0';
6b1b602514db Initial revision
carl
parents:
diff changeset
1122 DEBUG_RET();
6b1b602514db Initial revision
carl
parents:
diff changeset
1123 return c;
6b1b602514db Initial revision
carl
parents:
diff changeset
1124 }
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1125 // }}}1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1126 // int usage() {{{1
0
6b1b602514db Initial revision
carl
parents:
diff changeset
1127 int usage() {
6b1b602514db Initial revision
carl
parents:
diff changeset
1128 DEBUG_ENT("usage");
6b1b602514db Initial revision
carl
parents:
diff changeset
1129 version();
6b1b602514db Initial revision
carl
parents:
diff changeset
1130 printf("Usage: %s [OPTIONS] {PST FILENAME}\n", prog_name);
6b1b602514db Initial revision
carl
parents:
diff changeset
1131 printf("OPTIONS:\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
1132 printf("\t-c[v|l]\t- Set the Contact output mode. -cv = VCard, -cl = EMail list\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
1133 printf("\t-d\t- Debug to file. This is a binary log. Use readlog to print it\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
1134 printf("\t-h\t- Help. This screen\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
1135 printf("\t-k\t- KMail. Output in kmail format\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
1136 printf("\t-o\t- Output Dir. Directory to write files to. CWD is changed *after* opening pst file\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
1137 printf("\t-q\t- Quiet. Only print error messages\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
1138 printf("\t-r\t- Recursive. Output in a recursive format\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
1139 printf("\t-S\t- Seperate. Write emails in the seperate format\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
1140 printf("\t-V\t- Version. Display program version\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
1141 printf("\t-w\t- Overwrite any output mbox files\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
1142 DEBUG_RET();
6b1b602514db Initial revision
carl
parents:
diff changeset
1143 return 0;
6b1b602514db Initial revision
carl
parents:
diff changeset
1144 }
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1145 // }}}1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1146 // int version() {{{1
0
6b1b602514db Initial revision
carl
parents:
diff changeset
1147 int version() {
6b1b602514db Initial revision
carl
parents:
diff changeset
1148 DEBUG_ENT("version");
6b1b602514db Initial revision
carl
parents:
diff changeset
1149 printf("ReadPST v%s implementing LibPST v%s\n", VERSION, PST_VERSION);
6b1b602514db Initial revision
carl
parents:
diff changeset
1150 #if BYTE_ORDER == BIG_ENDIAN
6b1b602514db Initial revision
carl
parents:
diff changeset
1151 printf("Big Endian implementation being used.\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
1152 #elif BYTE_ORDER == LITTLE_ENDIAN
6b1b602514db Initial revision
carl
parents:
diff changeset
1153 printf("Little Endian implementation being used.\n");
6b1b602514db Initial revision
carl
parents:
diff changeset
1154 #else
6b1b602514db Initial revision
carl
parents:
diff changeset
1155 # error "Byte order not supported by this library"
6b1b602514db Initial revision
carl
parents:
diff changeset
1156 #endif
6b1b602514db Initial revision
carl
parents:
diff changeset
1157 #ifdef __GNUC__
6b1b602514db Initial revision
carl
parents:
diff changeset
1158 printf("GCC %d.%d : %s %s\n", __GNUC__, __GNUC_MINOR__, __DATE__, __TIME__);
6b1b602514db Initial revision
carl
parents:
diff changeset
1159 #endif
6b1b602514db Initial revision
carl
parents:
diff changeset
1160 DEBUG_RET();
6b1b602514db Initial revision
carl
parents:
diff changeset
1161 return 0;
6b1b602514db Initial revision
carl
parents:
diff changeset
1162 }
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1163 // }}}1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1164 // char *mk_kmail_dir(char *fname) {{{1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1165 char *mk_kmail_dir(char *fname) {
0
6b1b602514db Initial revision
carl
parents:
diff changeset
1166 //change to that directory
6b1b602514db Initial revision
carl
parents:
diff changeset
1167 //make a directory based on OUTPUT_KMAIL_DIR_TEMPLATE
6b1b602514db Initial revision
carl
parents:
diff changeset
1168 //allocate space for OUTPUT_TEMPLATE and form a char* with fname
6b1b602514db Initial revision
carl
parents:
diff changeset
1169 //return that value
6b1b602514db Initial revision
carl
parents:
diff changeset
1170 char *dir, *out_name, *index;
6b1b602514db Initial revision
carl
parents:
diff changeset
1171 int x;
6b1b602514db Initial revision
carl
parents:
diff changeset
1172 DEBUG_ENT("mk_kmail_dir");
6b1b602514db Initial revision
carl
parents:
diff changeset
1173 if (kmail_chdir != NULL && chdir(kmail_chdir)) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1174 x = errno;
6b1b602514db Initial revision
carl
parents:
diff changeset
1175 DIE(("mk_kmail_dir: Cannot change to directory %s: %s\n", kmail_chdir, strerror(x)));
6b1b602514db Initial revision
carl
parents:
diff changeset
1176 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1177 dir = malloc(strlen(fname)+strlen(OUTPUT_KMAIL_DIR_TEMPLATE)+1);
6b1b602514db Initial revision
carl
parents:
diff changeset
1178 sprintf(dir, OUTPUT_KMAIL_DIR_TEMPLATE, fname);
6b1b602514db Initial revision
carl
parents:
diff changeset
1179 dir = check_filename(dir);
6b1b602514db Initial revision
carl
parents:
diff changeset
1180 if (D_MKDIR(dir)) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1181 //error occured
6b1b602514db Initial revision
carl
parents:
diff changeset
1182 if (errno != EEXIST) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1183 x = errno;
6b1b602514db Initial revision
carl
parents:
diff changeset
1184 DIE(("mk_kmail_dir: Cannot create directory %s: %s\n", dir, strerror(x)));
6b1b602514db Initial revision
carl
parents:
diff changeset
1185 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1186 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1187 kmail_chdir = realloc(kmail_chdir, strlen(dir)+1);
6b1b602514db Initial revision
carl
parents:
diff changeset
1188 strcpy(kmail_chdir, dir);
6b1b602514db Initial revision
carl
parents:
diff changeset
1189 free (dir);
6b1b602514db Initial revision
carl
parents:
diff changeset
1190
6b1b602514db Initial revision
carl
parents:
diff changeset
1191 //we should remove any existing indexes created by KMail, cause they might be different now
6b1b602514db Initial revision
carl
parents:
diff changeset
1192 index = malloc(strlen(fname)+strlen(KMAIL_INDEX)+1);
6b1b602514db Initial revision
carl
parents:
diff changeset
1193 sprintf(index, KMAIL_INDEX, fname);
6b1b602514db Initial revision
carl
parents:
diff changeset
1194 unlink(index);
6b1b602514db Initial revision
carl
parents:
diff changeset
1195 free(index);
6b1b602514db Initial revision
carl
parents:
diff changeset
1196
6b1b602514db Initial revision
carl
parents:
diff changeset
1197 out_name = malloc(strlen(fname)+strlen(OUTPUT_TEMPLATE)+1);
6b1b602514db Initial revision
carl
parents:
diff changeset
1198 sprintf(out_name, OUTPUT_TEMPLATE, fname);
6b1b602514db Initial revision
carl
parents:
diff changeset
1199 DEBUG_RET();
6b1b602514db Initial revision
carl
parents:
diff changeset
1200 return out_name;
6b1b602514db Initial revision
carl
parents:
diff changeset
1201 }
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1202 // }}}1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1203 // int close_kmail_dir() {{{1
0
6b1b602514db Initial revision
carl
parents:
diff changeset
1204 int close_kmail_dir() {
6b1b602514db Initial revision
carl
parents:
diff changeset
1205 // change ..
6b1b602514db Initial revision
carl
parents:
diff changeset
1206 int x;
6b1b602514db Initial revision
carl
parents:
diff changeset
1207 DEBUG_ENT("close_kmail_dir");
6b1b602514db Initial revision
carl
parents:
diff changeset
1208 if (kmail_chdir != NULL) { //only free kmail_chdir if not NULL. do not change directory
6b1b602514db Initial revision
carl
parents:
diff changeset
1209 free(kmail_chdir);
6b1b602514db Initial revision
carl
parents:
diff changeset
1210 kmail_chdir = NULL;
6b1b602514db Initial revision
carl
parents:
diff changeset
1211 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
1212 if (chdir("..")) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1213 x = errno;
6b1b602514db Initial revision
carl
parents:
diff changeset
1214 DIE(("close_kmail_dir: Cannot move up dir (..): %s\n", strerror(x)));
6b1b602514db Initial revision
carl
parents:
diff changeset
1215 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1216 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1217 DEBUG_RET();
6b1b602514db Initial revision
carl
parents:
diff changeset
1218 return 0;
6b1b602514db Initial revision
carl
parents:
diff changeset
1219 }
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1220 // }}}1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1221 // char *mk_recurse_dir(char *dir) {{{1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1222 // this will create a directory by that name, then make an mbox file inside
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1223 // that dir. any subsequent dirs will be created by name, and they will
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1224 // contain mbox files
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1225 char *mk_recurse_dir(char *dir) {
0
6b1b602514db Initial revision
carl
parents:
diff changeset
1226 int x;
6b1b602514db Initial revision
carl
parents:
diff changeset
1227 char *out_name;
6b1b602514db Initial revision
carl
parents:
diff changeset
1228 DEBUG_ENT("mk_recurse_dir");
6b1b602514db Initial revision
carl
parents:
diff changeset
1229 dir = check_filename(dir);
6b1b602514db Initial revision
carl
parents:
diff changeset
1230 if (D_MKDIR (dir)) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1231 if (errno != EEXIST) { // not an error because it exists
6b1b602514db Initial revision
carl
parents:
diff changeset
1232 x = errno;
6b1b602514db Initial revision
carl
parents:
diff changeset
1233 DIE(("mk_recurse_dir: Cannot create directory %s: %s\n", dir, strerror(x)));
6b1b602514db Initial revision
carl
parents:
diff changeset
1234 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1235 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1236 if (chdir (dir)) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1237 x = errno;
6b1b602514db Initial revision
carl
parents:
diff changeset
1238 DIE(("mk_recurse_dir: Cannot change to directory %s: %s\n", dir, strerror(x)));
6b1b602514db Initial revision
carl
parents:
diff changeset
1239 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1240 out_name = malloc(strlen("mbox")+1);
6b1b602514db Initial revision
carl
parents:
diff changeset
1241 strcpy(out_name, "mbox");
6b1b602514db Initial revision
carl
parents:
diff changeset
1242 DEBUG_RET();
6b1b602514db Initial revision
carl
parents:
diff changeset
1243 return out_name;
6b1b602514db Initial revision
carl
parents:
diff changeset
1244 }
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1245 // }}}1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1246 // int close_recurse_dir() {{{1
0
6b1b602514db Initial revision
carl
parents:
diff changeset
1247 int close_recurse_dir() {
6b1b602514db Initial revision
carl
parents:
diff changeset
1248 int x;
6b1b602514db Initial revision
carl
parents:
diff changeset
1249 DEBUG_ENT("close_recurse_dir");
6b1b602514db Initial revision
carl
parents:
diff changeset
1250 if (chdir("..")) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1251 x = errno;
6b1b602514db Initial revision
carl
parents:
diff changeset
1252 DIE(("close_recurse_dir: Cannot go up dir (..): %s\n", strerror(x)));
6b1b602514db Initial revision
carl
parents:
diff changeset
1253 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1254 DEBUG_RET();
6b1b602514db Initial revision
carl
parents:
diff changeset
1255 return 0;
6b1b602514db Initial revision
carl
parents:
diff changeset
1256 }
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1257 // }}}1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1258 // char *mk_seperate_dir(char *dir, int overwrite) {{{1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1259 char *mk_seperate_dir(char *dir, int overwrite) {
0
6b1b602514db Initial revision
carl
parents:
diff changeset
1260 #if !defined(WIN32) && !defined(__CYGWIN__)
6b1b602514db Initial revision
carl
parents:
diff changeset
1261 DIR * sdir = NULL;
6b1b602514db Initial revision
carl
parents:
diff changeset
1262 struct dirent *dirent = NULL;
6b1b602514db Initial revision
carl
parents:
diff changeset
1263 struct stat *filestat = xmalloc(sizeof(struct stat));
6b1b602514db Initial revision
carl
parents:
diff changeset
1264 #endif
6b1b602514db Initial revision
carl
parents:
diff changeset
1265
6b1b602514db Initial revision
carl
parents:
diff changeset
1266 char *dir_name = NULL;
6b1b602514db Initial revision
carl
parents:
diff changeset
1267 int x = 0, y = 0;
6b1b602514db Initial revision
carl
parents:
diff changeset
1268 DEBUG_ENT("mk_seperate_dir");
6b1b602514db Initial revision
carl
parents:
diff changeset
1269 /*#if defined(WIN32) || defined(__CYGWIN__)
6b1b602514db Initial revision
carl
parents:
diff changeset
1270 DIE(("mk_seperate_dir: Win32 applications cannot use this function yet.\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
1271 #endif*/
6b1b602514db Initial revision
carl
parents:
diff changeset
1272
6b1b602514db Initial revision
carl
parents:
diff changeset
1273 dir_name = xmalloc(strlen(dir)+10);
6b1b602514db Initial revision
carl
parents:
diff changeset
1274
6b1b602514db Initial revision
carl
parents:
diff changeset
1275 do {
6b1b602514db Initial revision
carl
parents:
diff changeset
1276 if (y == 0)
6b1b602514db Initial revision
carl
parents:
diff changeset
1277 sprintf(dir_name, "%s", dir);
6b1b602514db Initial revision
carl
parents:
diff changeset
1278 else
6b1b602514db Initial revision
carl
parents:
diff changeset
1279 sprintf(dir_name, "%s%09i", dir, y); // enough for 9 digits allocated above
6b1b602514db Initial revision
carl
parents:
diff changeset
1280
6b1b602514db Initial revision
carl
parents:
diff changeset
1281 dir_name = check_filename(dir_name);
6b1b602514db Initial revision
carl
parents:
diff changeset
1282 DEBUG_MAIN(("mk_seperate_dir: about to try creating %s\n", dir_name));
6b1b602514db Initial revision
carl
parents:
diff changeset
1283 if (D_MKDIR(dir_name)) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1284 if (errno != EEXIST) { // if there is an error, and it doesn't already exist
6b1b602514db Initial revision
carl
parents:
diff changeset
1285 x = errno;
6b1b602514db Initial revision
carl
parents:
diff changeset
1286 DIE(("mk_seperate_dir: Cannot create directory %s: %s\n", dir, strerror(x)));
6b1b602514db Initial revision
carl
parents:
diff changeset
1287 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1288 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
1289 break;
6b1b602514db Initial revision
carl
parents:
diff changeset
1290 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1291 y++;
6b1b602514db Initial revision
carl
parents:
diff changeset
1292 } while (overwrite == 0);
6b1b602514db Initial revision
carl
parents:
diff changeset
1293
6b1b602514db Initial revision
carl
parents:
diff changeset
1294 if (chdir (dir_name)) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1295 x = errno;
6b1b602514db Initial revision
carl
parents:
diff changeset
1296 DIE(("mk_recurse_dir: Cannot change to directory %s: %s\n", dir, strerror(x)));
6b1b602514db Initial revision
carl
parents:
diff changeset
1297 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1298
6b1b602514db Initial revision
carl
parents:
diff changeset
1299 if (overwrite) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1300 // we should probably delete all files from this directory
6b1b602514db Initial revision
carl
parents:
diff changeset
1301 #if !defined(WIN32) && !defined(__CYGWIN__)
6b1b602514db Initial revision
carl
parents:
diff changeset
1302 if ((sdir = opendir("./")) == NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1303 WARN(("mk_seperate_dir: Cannot open dir \"%s\" for deletion of old contents\n", "./"));
6b1b602514db Initial revision
carl
parents:
diff changeset
1304 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
1305 while ((dirent = readdir(sdir)) != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1306 if (lstat(dirent->d_name, filestat) != -1)
6b1b602514db Initial revision
carl
parents:
diff changeset
1307 if (S_ISREG(filestat->st_mode)) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1308 if (unlink(dirent->d_name)) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1309 y = errno;
6b1b602514db Initial revision
carl
parents:
diff changeset
1310 DIE(("mk_seperate_dir: unlink returned error on file %s: %s\n", dirent->d_name, strerror(y)));
6b1b602514db Initial revision
carl
parents:
diff changeset
1311 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1312 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1313 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1314 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1315 #endif
6b1b602514db Initial revision
carl
parents:
diff changeset
1316 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1317
6b1b602514db Initial revision
carl
parents:
diff changeset
1318 // overwrite will never change during this function, it is just there so that
6b1b602514db Initial revision
carl
parents:
diff changeset
1319 // if overwrite is set, we only go through this loop once.
6b1b602514db Initial revision
carl
parents:
diff changeset
1320
6b1b602514db Initial revision
carl
parents:
diff changeset
1321 // we don't return a filename here cause it isn't necessary.
6b1b602514db Initial revision
carl
parents:
diff changeset
1322 DEBUG_RET();
6b1b602514db Initial revision
carl
parents:
diff changeset
1323 return NULL;
6b1b602514db Initial revision
carl
parents:
diff changeset
1324 }
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1325 // }}}1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1326 // int close_seperate_dir() {{{1
0
6b1b602514db Initial revision
carl
parents:
diff changeset
1327 int close_seperate_dir() {
6b1b602514db Initial revision
carl
parents:
diff changeset
1328 int x;
6b1b602514db Initial revision
carl
parents:
diff changeset
1329 DEBUG_ENT("close_seperate_dir");
6b1b602514db Initial revision
carl
parents:
diff changeset
1330 if (chdir("..")) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1331 x = errno;
6b1b602514db Initial revision
carl
parents:
diff changeset
1332 DIE(("close_seperate_dir: Cannot go up dir (..): %s\n", strerror(x)));
6b1b602514db Initial revision
carl
parents:
diff changeset
1333 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1334 DEBUG_RET();
6b1b602514db Initial revision
carl
parents:
diff changeset
1335 return 0;
6b1b602514db Initial revision
carl
parents:
diff changeset
1336 }
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1337 // }}}1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1338 // int mk_seperate_file(struct file_ll *f) {{{1
0
6b1b602514db Initial revision
carl
parents:
diff changeset
1339 int mk_seperate_file(struct file_ll *f) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1340 DEBUG_ENT("mk_seperate_file");
6b1b602514db Initial revision
carl
parents:
diff changeset
1341 DEBUG_MAIN(("mk_seperate_file: opening next file to save email\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
1342 if (f->email_count > 999999999) { // bigger than nine 9's
6b1b602514db Initial revision
carl
parents:
diff changeset
1343 DIE(("mk_seperate_file: The number of emails in this folder has become too high to handle"));
6b1b602514db Initial revision
carl
parents:
diff changeset
1344 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1345 sprintf(f->name, "%09i", f->email_count);
6b1b602514db Initial revision
carl
parents:
diff changeset
1346 if (f->output != NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
1347 fclose(f->output);
6b1b602514db Initial revision
carl
parents:
diff changeset
1348 f->output = NULL;
6b1b602514db Initial revision
carl
parents:
diff changeset
1349 f->name = check_filename(f->name);
6b1b602514db Initial revision
carl
parents:
diff changeset
1350 if ((f->output = fopen(f->name, "w")) == NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1351 DIE(("mk_seperate_file: Cannot open file to save email \"%s\"\n", f->name));
6b1b602514db Initial revision
carl
parents:
diff changeset
1352 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1353 DEBUG_RET();
6b1b602514db Initial revision
carl
parents:
diff changeset
1354 return 0;
6b1b602514db Initial revision
carl
parents:
diff changeset
1355 }
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1356 // }}}1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1357 // char *my_stristr(char *haystack, char *needle) {{{1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1358 char *my_stristr(char *haystack, char *needle) {
0
6b1b602514db Initial revision
carl
parents:
diff changeset
1359 // my_stristr varies from strstr in that its searches are case-insensitive
6b1b602514db Initial revision
carl
parents:
diff changeset
1360 char *x=haystack, *y=needle, *z = NULL;
6b1b602514db Initial revision
carl
parents:
diff changeset
1361 DEBUG_ENT("my_stristr");
6b1b602514db Initial revision
carl
parents:
diff changeset
1362 if (haystack == NULL || needle == NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
1363 return NULL;
6b1b602514db Initial revision
carl
parents:
diff changeset
1364 while (*y != '\0' && *x != '\0') {
6b1b602514db Initial revision
carl
parents:
diff changeset
1365 if (tolower(*y) == tolower(*x)) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1366 // move y on one
6b1b602514db Initial revision
carl
parents:
diff changeset
1367 y++;
6b1b602514db Initial revision
carl
parents:
diff changeset
1368 if (z == NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1369 z = x; // store first position in haystack where a match is made
6b1b602514db Initial revision
carl
parents:
diff changeset
1370 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1371 } else {
6b1b602514db Initial revision
carl
parents:
diff changeset
1372 y = needle; // reset y to the beginning of the needle
6b1b602514db Initial revision
carl
parents:
diff changeset
1373 z = NULL; // reset the haystack storage point
6b1b602514db Initial revision
carl
parents:
diff changeset
1374 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1375 x++; // advance the search in the haystack
6b1b602514db Initial revision
carl
parents:
diff changeset
1376 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1377 DEBUG_RET();
6b1b602514db Initial revision
carl
parents:
diff changeset
1378 return z;
6b1b602514db Initial revision
carl
parents:
diff changeset
1379 }
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1380 // }}}1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1381 // char *check_filename(char *fname) {{{1
0
6b1b602514db Initial revision
carl
parents:
diff changeset
1382 char *check_filename(char *fname) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1383 char *t = fname;
6b1b602514db Initial revision
carl
parents:
diff changeset
1384 DEBUG_ENT("check_filename");
6b1b602514db Initial revision
carl
parents:
diff changeset
1385 if (t == NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1386 DEBUG_RET();
6b1b602514db Initial revision
carl
parents:
diff changeset
1387 return fname;
6b1b602514db Initial revision
carl
parents:
diff changeset
1388 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1389 while ((t = strpbrk(t, "/\\:")) != NULL) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1390 // while there are characters in the second string that we don't want
6b1b602514db Initial revision
carl
parents:
diff changeset
1391 *t = '_'; //replace them with an underscore
6b1b602514db Initial revision
carl
parents:
diff changeset
1392 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1393 DEBUG_RET();
6b1b602514db Initial revision
carl
parents:
diff changeset
1394 return fname;
6b1b602514db Initial revision
carl
parents:
diff changeset
1395 }
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1396 // }}}1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1397 // char *rfc2426_escape(char *str) {{{1
0
6b1b602514db Initial revision
carl
parents:
diff changeset
1398 char *rfc2426_escape(char *str) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1399 static char* buf = NULL;
6b1b602514db Initial revision
carl
parents:
diff changeset
1400 char *ret, *a, *b;
6b1b602514db Initial revision
carl
parents:
diff changeset
1401 int x = 0, y, z;
6b1b602514db Initial revision
carl
parents:
diff changeset
1402 DEBUG_ENT("rfc2426_escape");
6b1b602514db Initial revision
carl
parents:
diff changeset
1403 if (str == NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
1404 ret = str;
6b1b602514db Initial revision
carl
parents:
diff changeset
1405 else {
6b1b602514db Initial revision
carl
parents:
diff changeset
1406
6b1b602514db Initial revision
carl
parents:
diff changeset
1407 // calculate space required to escape all the following characters
6b1b602514db Initial revision
carl
parents:
diff changeset
1408 x = strlen(str) +(y=(chr_count(str, ',')*2) + (chr_count(str, '\\')*2) + (chr_count(str, ';')*2) + (chr_count(str, '\n')*2));
6b1b602514db Initial revision
carl
parents:
diff changeset
1409 z = chr_count(str, '\r');
6b1b602514db Initial revision
carl
parents:
diff changeset
1410 if (y == 0 && z == 0)
6b1b602514db Initial revision
carl
parents:
diff changeset
1411 // there isn't any extra space required
6b1b602514db Initial revision
carl
parents:
diff changeset
1412 ret = str;
6b1b602514db Initial revision
carl
parents:
diff changeset
1413 else {
6b1b602514db Initial revision
carl
parents:
diff changeset
1414 buf = (char*) realloc(buf, x+1);
6b1b602514db Initial revision
carl
parents:
diff changeset
1415 a = str;
6b1b602514db Initial revision
carl
parents:
diff changeset
1416 b = buf;
6b1b602514db Initial revision
carl
parents:
diff changeset
1417 while (*a != '\0') {
6b1b602514db Initial revision
carl
parents:
diff changeset
1418 switch(*a) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1419 case ',' :
6b1b602514db Initial revision
carl
parents:
diff changeset
1420 case '\\':
6b1b602514db Initial revision
carl
parents:
diff changeset
1421 case ';' :
6b1b602514db Initial revision
carl
parents:
diff changeset
1422 case '\n':
6b1b602514db Initial revision
carl
parents:
diff changeset
1423 *(b++)='\\';
6b1b602514db Initial revision
carl
parents:
diff changeset
1424 *b=*a;
6b1b602514db Initial revision
carl
parents:
diff changeset
1425 break;
6b1b602514db Initial revision
carl
parents:
diff changeset
1426 case '\r':
6b1b602514db Initial revision
carl
parents:
diff changeset
1427 break;
6b1b602514db Initial revision
carl
parents:
diff changeset
1428 default:
6b1b602514db Initial revision
carl
parents:
diff changeset
1429 *b=*a;
6b1b602514db Initial revision
carl
parents:
diff changeset
1430 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1431 b++;
6b1b602514db Initial revision
carl
parents:
diff changeset
1432 a++;
6b1b602514db Initial revision
carl
parents:
diff changeset
1433 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1434 *b = '\0';
6b1b602514db Initial revision
carl
parents:
diff changeset
1435 ret = buf;
6b1b602514db Initial revision
carl
parents:
diff changeset
1436 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1437 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1438 DEBUG_RET();
6b1b602514db Initial revision
carl
parents:
diff changeset
1439 return ret;
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1440 }
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1441 // }}}1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1442 // int chr_count(char *str, char x) {{{1
0
6b1b602514db Initial revision
carl
parents:
diff changeset
1443 int chr_count(char *str, char x) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1444 int r = 0;
6b1b602514db Initial revision
carl
parents:
diff changeset
1445 while (*str != '\0') {
6b1b602514db Initial revision
carl
parents:
diff changeset
1446 if (*str == x)
6b1b602514db Initial revision
carl
parents:
diff changeset
1447 r++;
6b1b602514db Initial revision
carl
parents:
diff changeset
1448 str++;
6b1b602514db Initial revision
carl
parents:
diff changeset
1449 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1450 return r;
6b1b602514db Initial revision
carl
parents:
diff changeset
1451 }
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1452 // }}}1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1453 // char *rfc2425_datetime_format(FILETIME *ft) {{{1
0
6b1b602514db Initial revision
carl
parents:
diff changeset
1454 char *rfc2425_datetime_format(FILETIME *ft) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1455 static char * buffer = NULL;
6b1b602514db Initial revision
carl
parents:
diff changeset
1456 struct tm *stm = NULL;
6b1b602514db Initial revision
carl
parents:
diff changeset
1457 DEBUG_ENT("rfc2425_datetime_format");
6b1b602514db Initial revision
carl
parents:
diff changeset
1458 if (buffer == NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
1459 buffer = malloc(30); // should be enough for the date as defined below
6b1b602514db Initial revision
carl
parents:
diff changeset
1460
6b1b602514db Initial revision
carl
parents:
diff changeset
1461 stm = fileTimeToStructTM(ft);
6b1b602514db Initial revision
carl
parents:
diff changeset
1462 //Year[4]-Month[2]-Day[2] Hour[2]:Min[2]:Sec[2]
6b1b602514db Initial revision
carl
parents:
diff changeset
1463 if (strftime(buffer, 30, "%Y-%m-%dT%H:%M:%SZ", stm)==0) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1464 DEBUG_INFO(("Problem occured formatting date\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
1465 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1466 DEBUG_RET();
6b1b602514db Initial revision
carl
parents:
diff changeset
1467 return buffer;
6b1b602514db Initial revision
carl
parents:
diff changeset
1468 }
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1469 // }}}1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1470 // char *rfc2445_datetime_format(FILETIME *ft) {{{1
0
6b1b602514db Initial revision
carl
parents:
diff changeset
1471 char *rfc2445_datetime_format(FILETIME *ft) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1472 static char* buffer = NULL;
6b1b602514db Initial revision
carl
parents:
diff changeset
1473 struct tm *stm = NULL;
6b1b602514db Initial revision
carl
parents:
diff changeset
1474 DEBUG_ENT("rfc2445_datetime_format");
6b1b602514db Initial revision
carl
parents:
diff changeset
1475 if (buffer == NULL)
6b1b602514db Initial revision
carl
parents:
diff changeset
1476 buffer = malloc(30); // should be enough
6b1b602514db Initial revision
carl
parents:
diff changeset
1477 stm = fileTimeToStructTM(ft);
6b1b602514db Initial revision
carl
parents:
diff changeset
1478 if (strftime(buffer, 30, "%Y%m%dT%H%M%SZ", stm)==0) {
6b1b602514db Initial revision
carl
parents:
diff changeset
1479 DEBUG_INFO(("Problem occured formatting date\n"));
6b1b602514db Initial revision
carl
parents:
diff changeset
1480 }
6b1b602514db Initial revision
carl
parents:
diff changeset
1481 DEBUG_RET();
6b1b602514db Initial revision
carl
parents:
diff changeset
1482 return buffer;
6b1b602514db Initial revision
carl
parents:
diff changeset
1483 }
1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1484 // }}}1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1485 // char *skip_header_prologue(char *headers) {{{1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1486 // The sole purpose of this function is to bypass the pseudo-header prologue
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1487 // that Microsoft Outlook inserts at the beginning of the internet email
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1488 // headers for emails stored in their "Personal Folders" files.
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1489 char *skip_header_prologue(char *headers) {
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1490 const char *bad = "Microsoft Mail Internet Headers";
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1491
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1492 if ( strncmp(headers, bad, strlen(bad)) == 0 ) {
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1493 // Found the offensive header prologue
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1494 char *pc;
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1495
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1496 pc = strchr(headers, '\n');
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1497 return pc + 1;
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1498 }
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1499
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1500 return headers;
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1501 }
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1502 // }}}1
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1503
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1504 // vim:sw=4 ts=4:
43e8802f08c5 imported from debian 0.5.1
carl
parents: 0
diff changeset
1505 // vim600: set foldlevel=0 foldmethod=marker: