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