comparison src/pst2ldif.cpp @ 79:56fa05fd5271

Patch from Robert Simpson for encryption type 2. Fix the order of testing item types to avoid claiming there are multiple message stores.
author Carl Byington <carl@five-ten-sg.com>
date Fri, 13 Jun 2008 20:47:01 -0700
parents 3cb02cb1e6cd
children b7f456946c5b
comparison
equal deleted inserted replaced
78:535075b4d261 79:56fa05fd5271
122 while (d_ptr) { 122 while (d_ptr) {
123 if (d_ptr->desc) { 123 if (d_ptr->desc) {
124 item = pst_parse_item(&pstfile, d_ptr); 124 item = pst_parse_item(&pstfile, d_ptr);
125 DEBUG_INFO(("item pointer is %p\n", item)); 125 DEBUG_INFO(("item pointer is %p\n", item));
126 if (item) { 126 if (item) {
127 if (item->message_store) {
128 // there should only be one message_store, and we have already done it
129 DIE(("main: A second message_store has been found. Sorry, this must be an error.\n"));
130 }
131
132 if (item->folder && d_ptr->child && strcasecmp(item->file_as, "Deleted Items")) { 127 if (item->folder && d_ptr->child && strcasecmp(item->file_as, "Deleted Items")) {
133 //if this is a non-empty folder other than deleted items, we want to recurse into it 128 //if this is a non-empty folder other than deleted items, we want to recurse into it
134 fprintf(stderr, "entering folder %s\n", item->file_as); 129 fprintf(stderr, "entering folder %s\n", item->file_as);
135 process(d_ptr->child); 130 process(d_ptr->child);
136 } else if (item->contact) { 131
132 } else if (item->contact && (item->type == PST_TYPE_CONTACT)) {
137 // deal with a contact 133 // deal with a contact
138 if (item->type != PST_TYPE_CONTACT) { 134 char cn[1000];
139 DIE(("type should be contact\n")); 135 snprintf(cn, sizeof(cn), "%s %s %s %s",
140 } 136 single(item->contact->display_name_prefix),
141 else if (item->contact == NULL) { // this is an incorrect situation. Inform user 137 single(item->contact->first_name),
142 DIE(("null item contact\n")); 138 single(item->contact->surname),
143 } else { 139 single(item->contact->suffix));
144 char cn[1000]; 140 if (strcmp(cn, " ")) {
145 snprintf(cn, sizeof(cn), "%s %s %s %s", 141 // have a valid cn
146 single(item->contact->display_name_prefix), 142 const char *ucn = unique_string(folded(trim(cn)));
147 single(item->contact->first_name), 143 printf("dn: cn=%s, %s\n", ucn, ldap_base);
148 single(item->contact->surname), 144 printf("cn: %s\n", ucn);
149 single(item->contact->suffix)); 145 if (item->contact->first_name) {
150 if (strcmp(cn, " ")) { 146 snprintf(cn, sizeof(cn), "%s %s",
151 // fprintf(stderr, "\n\n\n"); 147 single(item->contact->display_name_prefix),
152 // fprintf(stderr, "access_method %s\n", item->contact->access_method); 148 single(item->contact->first_name));
153 // fprintf(stderr, "account_name %s\n", item->contact->account_name); 149 printf("givenName: %s\n", trim(cn));
154 // fprintf(stderr, "address1 %s\n", item->contact->address1); 150 }
155 // fprintf(stderr, "address1_desc %s\n", item->contact->address1_desc); 151 if (item->contact->surname) {
156 // fprintf(stderr, "address1_transport %s\n", item->contact->address1_transport); 152 snprintf(cn, sizeof(cn), "%s %s",
157 // fprintf(stderr, "address2 %s\n", item->contact->address2); 153 single(item->contact->surname),
158 // fprintf(stderr, "address2_desc %s\n", item->contact->address2_desc); 154 single(item->contact->suffix));
159 // fprintf(stderr, "address2_transport %s\n", item->contact->address2_transport); 155 printf("sn: %s\n", trim(cn));
160 // fprintf(stderr, "address3 %s\n", item->contact->address3); 156 }
161 // fprintf(stderr, "address3_desc %s\n", item->contact->address3_desc); 157 else if (item->contact->company_name) {
162 // fprintf(stderr, "address3_transport %s\n", item->contact->address3_transport); 158 printf("sn: %s\n", single(item->contact->company_name));
163 // fprintf(stderr, "assistant_name %s\n", item->contact->assistant_name); 159 }
164 // fprintf(stderr, "assistant_phone %s\n", item->contact->assistant_phone); 160 else
165 // fprintf(stderr, "billing_information %s\n", item->contact->billing_information); 161 printf("sn: %s\n", ucn); // use cn as sn if we cannot find something better
166 // fprintf(stderr, "business_address %s\n", item->contact->business_address); 162
167 // fprintf(stderr, "business_city %s\n", item->contact->business_city); 163 if (item->contact->job_title)
168 // fprintf(stderr, "business_country %s\n", item->contact->business_country); 164 printf("personalTitle: %s\n", single(item->contact->job_title));
169 // fprintf(stderr, "business_fax %s\n", item->contact->business_fax); 165 if (item->contact->company_name)
170 // fprintf(stderr, "business_homepage %s\n", item->contact->business_homepage); 166 printf("company: %s\n", single(item->contact->company_name));
171 // fprintf(stderr, "business_phone %s\n", item->contact->business_phone); 167 if (item->contact->address1 && *item->contact->address1)
172 // fprintf(stderr, "business_phone2 %s\n", item->contact->business_phone2); 168 printf("mail: %s\n", single(item->contact->address1));
173 // fprintf(stderr, "business_po_box %s\n", item->contact->business_po_box); 169 if (item->contact->address2 && *item->contact->address2)
174 // fprintf(stderr, "business_postal_code %s\n", item->contact->business_postal_code); 170 printf("mail: %s\n", single(item->contact->address2));
175 // fprintf(stderr, "business_state %s\n", item->contact->business_state); 171 if (item->contact->address3 && *item->contact->address3)
176 // fprintf(stderr, "business_street %s\n", item->contact->business_street); 172 printf("mail: %s\n", single(item->contact->address3));
177 // fprintf(stderr, "callback_phone %s\n", item->contact->callback_phone); 173 if (item->contact->address1a && *item->contact->address1a)
178 // fprintf(stderr, "car_phone %s\n", item->contact->car_phone); 174 printf("mail: %s\n", single(item->contact->address1a));
179 // fprintf(stderr, "company_main_phone %s\n", item->contact->company_main_phone); 175 if (item->contact->address2a && *item->contact->address2a)
180 // fprintf(stderr, "company_name %s\n", item->contact->company_name); 176 printf("mail: %s\n", single(item->contact->address2a));
181 // fprintf(stderr, "computer_name %s\n", item->contact->computer_name); 177 if (item->contact->address3a && *item->contact->address3a)
182 // fprintf(stderr, "customer_id %s\n", item->contact->customer_id); 178 printf("mail: %s\n", single(item->contact->address3a));
183 // fprintf(stderr, "def_postal_address %s\n", item->contact->def_postal_address); 179 if (item->contact->business_address) {
184 // fprintf(stderr, "department %s\n", item->contact->department); 180 if (item->contact->business_po_box)
185 // fprintf(stderr, "display_name_prefix %s\n", item->contact->display_name_prefix); 181 printf("postalAddress: %s\n", single(item->contact->business_po_box));
186 // fprintf(stderr, "first_name %s\n", item->contact->first_name); 182 if (item->contact->business_street)
187 // fprintf(stderr, "followup %s\n", item->contact->followup); 183 multi("postalAddress: %s\n", item->contact->business_street);
188 // fprintf(stderr, "free_busy_address %s\n", item->contact->free_busy_address); 184 if (item->contact->business_city)
189 // fprintf(stderr, "ftp_site %s\n", item->contact->ftp_site); 185 printf("l: %s\n", single(item->contact->business_city));
190 // fprintf(stderr, "fullname %s\n", item->contact->fullname); 186 if (item->contact->business_state)
191 // fprintf(stderr, "gov_id %s\n", item->contact->gov_id); 187 printf("st: %s\n", single(item->contact->business_state));
192 // fprintf(stderr, "hobbies %s\n", item->contact->hobbies); 188 if (item->contact->business_postal_code)
193 // fprintf(stderr, "home_address %s\n", item->contact->home_address); 189 printf("postalCode: %s\n", single(item->contact->business_postal_code));
194 // fprintf(stderr, "home_city %s\n", item->contact->home_city); 190 }
195 // fprintf(stderr, "home_country %s\n", item->contact->home_country); 191 else if (item->contact->home_address) {
196 // fprintf(stderr, "home_fax %s\n", item->contact->home_fax); 192 if (item->contact->home_po_box)
197 // fprintf(stderr, "home_phone %s\n", item->contact->home_phone); 193 printf("postalAddress: %s\n", single(item->contact->home_po_box));
198 // fprintf(stderr, "home_phone2 %s\n", item->contact->home_phone2); 194 if (item->contact->home_street)
199 // fprintf(stderr, "home_po_box %s\n", item->contact->home_po_box); 195 multi("postalAddress: %s\n", item->contact->home_street);
200 // fprintf(stderr, "home_postal_code %s\n", item->contact->home_postal_code); 196 if (item->contact->home_city)
201 // fprintf(stderr, "home_state %s\n", item->contact->home_state); 197 printf("l: %s\n", single(item->contact->home_city));
202 // fprintf(stderr, "home_street %s\n", item->contact->home_street); 198 if (item->contact->home_state)
203 // fprintf(stderr, "initials %s\n", item->contact->initials); 199 printf("st: %s\n", single(item->contact->home_state));
204 // fprintf(stderr, "isdn_phone %s\n", item->contact->isdn_phone); 200 if (item->contact->home_postal_code)
205 // fprintf(stderr, "job_title %s\n", item->contact->job_title); 201 printf("postalCode: %s\n", single(item->contact->home_postal_code));
206 // fprintf(stderr, "keyword %s\n", item->contact->keyword); 202 }
207 // fprintf(stderr, "language %s\n", item->contact->language); 203 else if (item->contact->other_address) {
208 // fprintf(stderr, "location %s\n", item->contact->location); 204 if (item->contact->other_po_box)
209 // fprintf(stderr, "manager_name %s\n", item->contact->manager_name); 205 printf("postalAddress: %s\n", single(item->contact->other_po_box));
210 // fprintf(stderr, "middle_name %s\n", item->contact->middle_name); 206 if (item->contact->other_street)
211 // fprintf(stderr, "mileage %s\n", item->contact->mileage); 207 multi("postalAddress: %s\n", item->contact->other_street);
212 // fprintf(stderr, "mobile_phone %s\n", item->contact->mobile_phone); 208 if (item->contact->other_city)
213 // fprintf(stderr, "nickname %s\n", item->contact->nickname); 209 printf("l: %s\n", single(item->contact->other_city));
214 // fprintf(stderr, "office_loc %s\n", item->contact->office_loc); 210 if (item->contact->other_state)
215 // fprintf(stderr, "org_id %s\n", item->contact->org_id); 211 printf("st: %s\n", single(item->contact->other_state));
216 // fprintf(stderr, "other_address %s\n", item->contact->other_address); 212 if (item->contact->other_postal_code)
217 // fprintf(stderr, "other_city %s\n", item->contact->other_city); 213 printf("postalCode: %s\n", single(item->contact->other_postal_code));
218 // fprintf(stderr, "other_country %s\n", item->contact->other_country); 214 }
219 // fprintf(stderr, "other_phone %s\n", item->contact->other_phone); 215 if (item->contact->business_fax)
220 // fprintf(stderr, "other_po_box %s\n", item->contact->other_po_box); 216 printf("facsimileTelephoneNumber: %s\n", single(item->contact->business_fax));
221 // fprintf(stderr, "other_postal_code %s\n", item->contact->other_postal_code); 217 else if (item->contact->home_fax)
222 // fprintf(stderr, "other_state %s\n", item->contact->other_state); 218 printf("facsimileTelephoneNumber: %s\n", single(item->contact->home_fax));
223 // fprintf(stderr, "other_street %s\n", item->contact->other_street); 219
224 // fprintf(stderr, "pager_phone %s\n", item->contact->pager_phone); 220 if (item->contact->business_phone)
225 // fprintf(stderr, "personal_homepage %s\n", item->contact->personal_homepage); 221 printf("telephoneNumber: %s\n", single(item->contact->business_phone));
226 // fprintf(stderr, "pref_name %s\n", item->contact->pref_name); 222 if (item->contact->home_phone)
227 // fprintf(stderr, "primary_fax %s\n", item->contact->primary_fax); 223 printf("homePhone: %s\n", single(item->contact->home_phone));
228 // fprintf(stderr, "primary_phone %s\n", item->contact->primary_phone); 224
229 // fprintf(stderr, "profession %s\n", item->contact->profession); 225 if (item->contact->car_phone)
230 // fprintf(stderr, "radio_phone %s\n", item->contact->radio_phone); 226 printf("mobile: %s\n", single(item->contact->car_phone));
231 // fprintf(stderr, "spouse_name %s\n", item->contact->spouse_name); 227 else if (item->contact->mobile_phone)
232 // fprintf(stderr, "suffix %s\n", item->contact->suffix); 228 printf("mobile: %s\n", single(item->contact->mobile_phone));
233 // fprintf(stderr, "surname %s\n", item->contact->surname); 229 else if (item->contact->other_phone)
234 // fprintf(stderr, "telex %s\n", item->contact->telex); 230 printf("mobile: %s\n", single(item->contact->other_phone));
235 // fprintf(stderr, "transmittable_display_name %s\n", item->contact->transmittable_display_name); 231
236 // fprintf(stderr, "ttytdd_phone %s\n", item->contact->ttytdd_phone); 232
237 // have a valid cn 233 if (item->comment)
238 const char *ucn = unique_string(folded(trim(cn))); 234 printf("description: %s\n", single(item->comment));
239 printf("dn: cn=%s, %s\n", ucn, ldap_base); 235
240 printf("cn: %s\n", ucn); 236 printf("objectClass: %s\n\n", ldap_class);
241 if (item->contact->first_name) {
242 snprintf(cn, sizeof(cn), "%s %s",
243 single(item->contact->display_name_prefix),
244 single(item->contact->first_name));
245 printf("givenName: %s\n", trim(cn));
246 }
247 if (item->contact->surname) {
248 snprintf(cn, sizeof(cn), "%s %s",
249 single(item->contact->surname),
250 single(item->contact->suffix));
251 printf("sn: %s\n", trim(cn));
252 }
253 else if (item->contact->company_name) {
254 printf("sn: %s\n", single(item->contact->company_name));
255 }
256 else
257 printf("sn: %s\n", ucn); // use cn as sn if we cannot find something better
258
259 if (item->contact->job_title)
260 printf("personalTitle: %s\n", single(item->contact->job_title));
261 if (item->contact->company_name)
262 printf("company: %s\n", single(item->contact->company_name));
263 if (item->contact->address1 && *item->contact->address1)
264 printf("mail: %s\n", single(item->contact->address1));
265 if (item->contact->address2 && *item->contact->address2)
266 printf("mail: %s\n", single(item->contact->address2));
267 if (item->contact->address3 && *item->contact->address3)
268 printf("mail: %s\n", single(item->contact->address3));
269 if (item->contact->address1a && *item->contact->address1a)
270 printf("mail: %s\n", single(item->contact->address1a));
271 if (item->contact->address2a && *item->contact->address2a)
272 printf("mail: %s\n", single(item->contact->address2a));
273 if (item->contact->address3a && *item->contact->address3a)
274 printf("mail: %s\n", single(item->contact->address3a));
275 if (item->contact->business_address) {
276 if (item->contact->business_po_box)
277 printf("postalAddress: %s\n", single(item->contact->business_po_box));
278 if (item->contact->business_street)
279 multi("postalAddress: %s\n", item->contact->business_street);
280 if (item->contact->business_city)
281 printf("l: %s\n", single(item->contact->business_city));
282 if (item->contact->business_state)
283 printf("st: %s\n", single(item->contact->business_state));
284 if (item->contact->business_postal_code)
285 printf("postalCode: %s\n", single(item->contact->business_postal_code));
286 }
287 else if (item->contact->home_address) {
288 if (item->contact->home_po_box)
289 printf("postalAddress: %s\n", single(item->contact->home_po_box));
290 if (item->contact->home_street)
291 multi("postalAddress: %s\n", item->contact->home_street);
292 if (item->contact->home_city)
293 printf("l: %s\n", single(item->contact->home_city));
294 if (item->contact->home_state)
295 printf("st: %s\n", single(item->contact->home_state));
296 if (item->contact->home_postal_code)
297 printf("postalCode: %s\n", single(item->contact->home_postal_code));
298 }
299 else if (item->contact->other_address) {
300 if (item->contact->other_po_box)
301 printf("postalAddress: %s\n", single(item->contact->other_po_box));
302 if (item->contact->other_street)
303 multi("postalAddress: %s\n", item->contact->other_street);
304 if (item->contact->other_city)
305 printf("l: %s\n", single(item->contact->other_city));
306 if (item->contact->other_state)
307 printf("st: %s\n", single(item->contact->other_state));
308 if (item->contact->other_postal_code)
309 printf("postalCode: %s\n", single(item->contact->other_postal_code));
310 }
311 if (item->contact->business_fax)
312 printf("facsimileTelephoneNumber: %s\n", single(item->contact->business_fax));
313 else if (item->contact->home_fax)
314 printf("facsimileTelephoneNumber: %s\n", single(item->contact->home_fax));
315
316 if (item->contact->business_phone)
317 printf("telephoneNumber: %s\n", single(item->contact->business_phone));
318 if (item->contact->home_phone)
319 printf("homePhone: %s\n", single(item->contact->home_phone));
320
321 if (item->contact->car_phone)
322 printf("mobile: %s\n", single(item->contact->car_phone));
323 else if (item->contact->mobile_phone)
324 printf("mobile: %s\n", single(item->contact->mobile_phone));
325 else if (item->contact->other_phone)
326 printf("mobile: %s\n", single(item->contact->other_phone));
327
328
329 if (item->comment)
330 printf("description: %s\n", single(item->comment));
331
332 printf("objectClass: %s\n\n", ldap_class);
333 }
334 } 237 }
335 } 238 }
336 else { 239 else {
337 DEBUG_INFO(("item is not a contact\n")); 240 DEBUG_INFO(("item is not a contact\n"));
338 } 241 }