annotate pst2ldif.cpp @ 13:80ae7e5cb562

patches from debian
author carl
date Sun, 19 Feb 2006 14:35:22 -0800
parents 3f627519a92d
children 3f2fedec798c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
1 /*
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
2
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
3 Copyright (c) 2004 Carl Byington - 510 Software Group, released under
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
4 the GPL version 2 or any later version at your choice available at
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
5 http://www.fsf.org/licenses/gpl.txt
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
6
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
7 Based on readpst.c by David Smith
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
8
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
9 */
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
10
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
11 using namespace std;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
12
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
13 #include <stdio.h>
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
14 #include <stdlib.h>
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
15 #include <time.h>
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
16 #include <string.h>
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
17 #include <ctype.h>
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
18 #include <limits.h>
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
19 #include <errno.h>
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
20
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
21 #ifndef _WIN32
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
22 # include <unistd.h>
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
23 # include <sys/stat.h> //mkdir
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
24
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
25 // for reading of directory and clearing in function mk_separate_dir
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
26 # include <sys/types.h>
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
27 # include <dirent.h>
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
28 #else
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
29 # include <direct.h>
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
30 # define chdir _chdir
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
31 # define int32_t __int32
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
32 #endif
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
33
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
34 #ifndef __GNUC__
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
35 # include "XGetopt.h"
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
36 #endif
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
37
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
38 // needed for std c++ collections
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
39 #include <set>
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
40
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
41 extern "C" {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
42 #include "libstrfunc.h" // for base64_encoding
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
43 #include "define.h"
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
44 #include "libpst.h"
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
45 #include "common.h"
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
46 #include "timeconv.h"
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
47 #include "lzfu.h"
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
48 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
49
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
50 #define VERSION "0.2"
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
51
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
52 int32_t usage();
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
53 int32_t version();
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
54 char *my_stristr(char *haystack, char *needle);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
55 char *check_filename(char *fname);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
56 char *single(char *str);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
57 char *folded(char *str);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
58 void multi(char *fmt, char *str);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
59 char *rfc2426_escape(char *str);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
60 int32_t chr_count(char *str, char x);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
61
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
62 char *prog_name;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
63 pst_file pstfile;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
64 char *ldap_base = NULL; // 'o=some.domain.tld, c=US'
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
65 char *ldap_class = NULL; // 'newPerson'
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
66 char *ldap_org = NULL; // 'o=some.domain.tld', computed from ldap_base
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
67
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
68
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
69 ////////////////////////////////////////////////
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
70 // define our ordering
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
71 struct ltstr {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
72 bool operator()(char* s1, char* s2) const {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
73 return strcasecmp(s1, s2) < 0;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
74 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
75 };
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
76 // define our set
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
77 typedef set<char *, ltstr> string_set;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
78 // make a static set to hold the cn values
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
79 static string_set all_strings;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
80
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
81
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
82 ////////////////////////////////////////////////
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
83 // helper to register a string in a string set
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
84 //
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
85 static char* register_string(string_set &s, char *name);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
86 static char* register_string(string_set &s, char *name) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
87 string_set::iterator i = s.find(name);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
88 if (i != s.end()) return *i;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
89 char *x = strdup(name);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
90 s.insert(x);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
91 return x;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
92 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
93
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
94 ////////////////////////////////////////////////
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
95 // register a global string
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
96 //
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
97 static char* register_string(char *name);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
98 static char* register_string(char *name) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
99 return register_string(all_strings, name);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
100 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
101
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
102
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
103 ////////////////////////////////////////////////
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
104 // make a unique string
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
105 //
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
106 static char* unique_string(char *name);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
107 static char* unique_string(char *name) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
108 int unique = 2;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
109 string_set::iterator i = all_strings.find(name);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
110 if (i == all_strings.end()) return register_string(name);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
111 while (true) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
112 char n[strlen(name)+10];
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
113 snprintf(n, sizeof(n), "%s %d", name, unique++);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
114 string_set::iterator i = all_strings.find(n);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
115 if (i == all_strings.end()) return register_string(n);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
116 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
117 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
118
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
119
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
120 ////////////////////////////////////////////////
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
121 // remove leading and trailing blanks
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
122 //
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
123 static char *trim(char *name);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
124 static char *trim(char *name) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
125 char *p;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
126 while (*name == ' ') name++;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
127 p = name + strlen(name) - 1;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
128 while ((p >= name) && (*p == ' ')) *p-- = '\0';
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
129 return name;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
130 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
131
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
132
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
133 static void process(pst_desc_ll *d_ptr);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
134 static void process(pst_desc_ll *d_ptr) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
135 pst_item *item = NULL;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
136 while (d_ptr) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
137 if (d_ptr->desc) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
138 item = (pst_item*)_pst_parse_item(&pstfile, d_ptr);
12
3f627519a92d properly ignore (second block zero) errors. that will just drop some unknown attachments, but the rest of the data is still found
carl
parents: 11
diff changeset
139 DEBUG_INFO(("item pointer is %p\n", item));
11
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
140 if (item) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
141 if (item->message_store) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
142 // there should only be one message_store, and we have already done it
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
143 DIE(("main: A second message_store has been found. Sorry, this must be an error.\n"));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
144 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
145
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
146 if (item->folder && d_ptr->child && strcasecmp(item->file_as, "Deleted Items")) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
147 //if this is a non-empty folder other than deleted items, we want to recurse into it
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
148 fprintf(stderr, "entering folder %s\n", item->file_as);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
149 process(d_ptr->child);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
150 } else if (item->contact) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
151 // deal with a contact
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
152 if (item->type != PST_TYPE_CONTACT) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
153 DIE(("type should be contact\n"));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
154 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
155 else if (item->contact == NULL) { // this is an incorrect situation. Inform user
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
156 DIE(("null item contact\n"));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
157 } else {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
158 char cn[1000];
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
159 snprintf(cn, sizeof(cn), "%s %s %s %s",
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
160 single(item->contact->display_name_prefix),
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
161 single(item->contact->first_name),
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
162 single(item->contact->surname),
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
163 single(item->contact->suffix));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
164 if (strcmp(cn, " ")) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
165 // fprintf(stderr, "\n\n\n");
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
166 // fprintf(stderr, "access_method %s\n", item->contact->access_method);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
167 // fprintf(stderr, "account_name %s\n", item->contact->account_name);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
168 // fprintf(stderr, "address1 %s\n", item->contact->address1);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
169 // fprintf(stderr, "address1_desc %s\n", item->contact->address1_desc);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
170 // fprintf(stderr, "address1_transport %s\n", item->contact->address1_transport);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
171 // fprintf(stderr, "address2 %s\n", item->contact->address2);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
172 // fprintf(stderr, "address2_desc %s\n", item->contact->address2_desc);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
173 // fprintf(stderr, "address2_transport %s\n", item->contact->address2_transport);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
174 // fprintf(stderr, "address3 %s\n", item->contact->address3);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
175 // fprintf(stderr, "address3_desc %s\n", item->contact->address3_desc);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
176 // fprintf(stderr, "address3_transport %s\n", item->contact->address3_transport);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
177 // fprintf(stderr, "assistant_name %s\n", item->contact->assistant_name);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
178 // fprintf(stderr, "assistant_phone %s\n", item->contact->assistant_phone);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
179 // fprintf(stderr, "billing_information %s\n", item->contact->billing_information);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
180 // fprintf(stderr, "business_address %s\n", item->contact->business_address);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
181 // fprintf(stderr, "business_city %s\n", item->contact->business_city);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
182 // fprintf(stderr, "business_country %s\n", item->contact->business_country);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
183 // fprintf(stderr, "business_fax %s\n", item->contact->business_fax);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
184 // fprintf(stderr, "business_homepage %s\n", item->contact->business_homepage);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
185 // fprintf(stderr, "business_phone %s\n", item->contact->business_phone);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
186 // fprintf(stderr, "business_phone2 %s\n", item->contact->business_phone2);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
187 // fprintf(stderr, "business_po_box %s\n", item->contact->business_po_box);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
188 // fprintf(stderr, "business_postal_code %s\n", item->contact->business_postal_code);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
189 // fprintf(stderr, "business_state %s\n", item->contact->business_state);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
190 // fprintf(stderr, "business_street %s\n", item->contact->business_street);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
191 // fprintf(stderr, "callback_phone %s\n", item->contact->callback_phone);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
192 // fprintf(stderr, "car_phone %s\n", item->contact->car_phone);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
193 // fprintf(stderr, "company_main_phone %s\n", item->contact->company_main_phone);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
194 // fprintf(stderr, "company_name %s\n", item->contact->company_name);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
195 // fprintf(stderr, "computer_name %s\n", item->contact->computer_name);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
196 // fprintf(stderr, "customer_id %s\n", item->contact->customer_id);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
197 // fprintf(stderr, "def_postal_address %s\n", item->contact->def_postal_address);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
198 // fprintf(stderr, "department %s\n", item->contact->department);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
199 // fprintf(stderr, "display_name_prefix %s\n", item->contact->display_name_prefix);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
200 // fprintf(stderr, "first_name %s\n", item->contact->first_name);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
201 // fprintf(stderr, "followup %s\n", item->contact->followup);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
202 // fprintf(stderr, "free_busy_address %s\n", item->contact->free_busy_address);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
203 // fprintf(stderr, "ftp_site %s\n", item->contact->ftp_site);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
204 // fprintf(stderr, "fullname %s\n", item->contact->fullname);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
205 // fprintf(stderr, "gov_id %s\n", item->contact->gov_id);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
206 // fprintf(stderr, "hobbies %s\n", item->contact->hobbies);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
207 // fprintf(stderr, "home_address %s\n", item->contact->home_address);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
208 // fprintf(stderr, "home_city %s\n", item->contact->home_city);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
209 // fprintf(stderr, "home_country %s\n", item->contact->home_country);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
210 // fprintf(stderr, "home_fax %s\n", item->contact->home_fax);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
211 // fprintf(stderr, "home_phone %s\n", item->contact->home_phone);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
212 // fprintf(stderr, "home_phone2 %s\n", item->contact->home_phone2);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
213 // fprintf(stderr, "home_po_box %s\n", item->contact->home_po_box);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
214 // fprintf(stderr, "home_postal_code %s\n", item->contact->home_postal_code);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
215 // fprintf(stderr, "home_state %s\n", item->contact->home_state);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
216 // fprintf(stderr, "home_street %s\n", item->contact->home_street);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
217 // fprintf(stderr, "initials %s\n", item->contact->initials);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
218 // fprintf(stderr, "isdn_phone %s\n", item->contact->isdn_phone);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
219 // fprintf(stderr, "job_title %s\n", item->contact->job_title);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
220 // fprintf(stderr, "keyword %s\n", item->contact->keyword);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
221 // fprintf(stderr, "language %s\n", item->contact->language);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
222 // fprintf(stderr, "location %s\n", item->contact->location);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
223 // fprintf(stderr, "manager_name %s\n", item->contact->manager_name);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
224 // fprintf(stderr, "middle_name %s\n", item->contact->middle_name);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
225 // fprintf(stderr, "mileage %s\n", item->contact->mileage);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
226 // fprintf(stderr, "mobile_phone %s\n", item->contact->mobile_phone);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
227 // fprintf(stderr, "nickname %s\n", item->contact->nickname);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
228 // fprintf(stderr, "office_loc %s\n", item->contact->office_loc);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
229 // fprintf(stderr, "org_id %s\n", item->contact->org_id);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
230 // fprintf(stderr, "other_address %s\n", item->contact->other_address);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
231 // fprintf(stderr, "other_city %s\n", item->contact->other_city);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
232 // fprintf(stderr, "other_country %s\n", item->contact->other_country);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
233 // fprintf(stderr, "other_phone %s\n", item->contact->other_phone);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
234 // fprintf(stderr, "other_po_box %s\n", item->contact->other_po_box);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
235 // fprintf(stderr, "other_postal_code %s\n", item->contact->other_postal_code);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
236 // fprintf(stderr, "other_state %s\n", item->contact->other_state);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
237 // fprintf(stderr, "other_street %s\n", item->contact->other_street);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
238 // fprintf(stderr, "pager_phone %s\n", item->contact->pager_phone);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
239 // fprintf(stderr, "personal_homepage %s\n", item->contact->personal_homepage);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
240 // fprintf(stderr, "pref_name %s\n", item->contact->pref_name);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
241 // fprintf(stderr, "primary_fax %s\n", item->contact->primary_fax);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
242 // fprintf(stderr, "primary_phone %s\n", item->contact->primary_phone);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
243 // fprintf(stderr, "profession %s\n", item->contact->profession);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
244 // fprintf(stderr, "radio_phone %s\n", item->contact->radio_phone);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
245 // fprintf(stderr, "spouse_name %s\n", item->contact->spouse_name);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
246 // fprintf(stderr, "suffix %s\n", item->contact->suffix);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
247 // fprintf(stderr, "surname %s\n", item->contact->surname);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
248 // fprintf(stderr, "telex %s\n", item->contact->telex);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
249 // fprintf(stderr, "transmittable_display_name %s\n", item->contact->transmittable_display_name);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
250 // fprintf(stderr, "ttytdd_phone %s\n", item->contact->ttytdd_phone);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
251 // have a valid cn
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
252 char *ucn = unique_string(folded(trim(cn)));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
253 printf("dn: cn=%s, %s\n", ucn, ldap_base);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
254 printf("cn: %s\n", ucn);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
255 if (item->contact->first_name) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
256 snprintf(cn, sizeof(cn), "%s %s",
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
257 single(item->contact->display_name_prefix),
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
258 single(item->contact->first_name));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
259 printf("givenName: %s\n", trim(cn));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
260 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
261 if (item->contact->surname) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
262 snprintf(cn, sizeof(cn), "%s %s",
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
263 single(item->contact->surname),
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
264 single(item->contact->suffix));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
265 printf("sn: %s\n", trim(cn));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
266 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
267 else if (item->contact->company_name) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
268 printf("sn: %s\n", single(item->contact->company_name));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
269 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
270 else
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
271 printf("sn: %s\n", ucn); // use cn as sn if we cannot find something better
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
272
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
273 if (item->contact->job_title)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
274 printf("personalTitle: %s\n", single(item->contact->job_title));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
275 if (item->contact->company_name)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
276 printf("company: %s\n", single(item->contact->company_name));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
277 if (item->contact->address1 && *item->contact->address1)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
278 printf("mail: %s\n", single(item->contact->address1));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
279 if (item->contact->address2 && *item->contact->address2)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
280 printf("mail: %s\n", single(item->contact->address2));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
281 if (item->contact->address3 && *item->contact->address3)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
282 printf("mail: %s\n", single(item->contact->address3));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
283 if (item->contact->address1a && *item->contact->address1a)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
284 printf("mail: %s\n", single(item->contact->address1a));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
285 if (item->contact->address2a && *item->contact->address2a)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
286 printf("mail: %s\n", single(item->contact->address2a));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
287 if (item->contact->address3a && *item->contact->address3a)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
288 printf("mail: %s\n", single(item->contact->address3a));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
289 if (item->contact->business_address) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
290 if (item->contact->business_po_box)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
291 printf("postalAddress: %s\n", single(item->contact->business_po_box));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
292 if (item->contact->business_street)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
293 multi("postalAddress: %s\n", item->contact->business_street);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
294 if (item->contact->business_city)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
295 printf("l: %s\n", single(item->contact->business_city));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
296 if (item->contact->business_state)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
297 printf("st: %s\n", single(item->contact->business_state));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
298 if (item->contact->business_postal_code)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
299 printf("postalCode: %s\n", single(item->contact->business_postal_code));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
300 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
301 else if (item->contact->home_address) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
302 if (item->contact->home_po_box)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
303 printf("postalAddress: %s\n", single(item->contact->home_po_box));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
304 if (item->contact->home_street)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
305 multi("postalAddress: %s\n", item->contact->home_street);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
306 if (item->contact->home_city)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
307 printf("l: %s\n", single(item->contact->home_city));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
308 if (item->contact->home_state)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
309 printf("st: %s\n", single(item->contact->home_state));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
310 if (item->contact->home_postal_code)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
311 printf("postalCode: %s\n", single(item->contact->home_postal_code));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
312 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
313 else if (item->contact->other_address) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
314 if (item->contact->other_po_box)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
315 printf("postalAddress: %s\n", single(item->contact->other_po_box));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
316 if (item->contact->other_street)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
317 multi("postalAddress: %s\n", item->contact->other_street);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
318 if (item->contact->other_city)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
319 printf("l: %s\n", single(item->contact->other_city));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
320 if (item->contact->other_state)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
321 printf("st: %s\n", single(item->contact->other_state));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
322 if (item->contact->other_postal_code)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
323 printf("postalCode: %s\n", single(item->contact->other_postal_code));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
324 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
325 if (item->contact->business_fax)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
326 printf("facsimileTelephoneNumber: %s\n", single(item->contact->business_fax));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
327 else if (item->contact->home_fax)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
328 printf("facsimileTelephoneNumber: %s\n", single(item->contact->home_fax));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
329
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
330 if (item->contact->business_phone)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
331 printf("telephoneNumber: %s\n", single(item->contact->business_phone));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
332 if (item->contact->home_phone)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
333 printf("homePhone: %s\n", single(item->contact->home_phone));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
334
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
335 if (item->contact->car_phone)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
336 printf("mobile: %s\n", single(item->contact->car_phone));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
337 else if (item->contact->mobile_phone)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
338 printf("mobile: %s\n", single(item->contact->mobile_phone));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
339 else if (item->contact->other_phone)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
340 printf("mobile: %s\n", single(item->contact->other_phone));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
341
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
342
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
343 if (item->comment)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
344 printf("description: %s\n", single(item->comment));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
345
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
346 printf("objectClass: %s\n\n", ldap_class);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
347 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
348 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
349 }
12
3f627519a92d properly ignore (second block zero) errors. that will just drop some unknown attachments, but the rest of the data is still found
carl
parents: 11
diff changeset
350 else {
3f627519a92d properly ignore (second block zero) errors. that will just drop some unknown attachments, but the rest of the data is still found
carl
parents: 11
diff changeset
351 DEBUG_INFO(("item is not a contact\n"));
3f627519a92d properly ignore (second block zero) errors. that will just drop some unknown attachments, but the rest of the data is still found
carl
parents: 11
diff changeset
352 }
11
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
353 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
354 _pst_freeItem(item);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
355 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
356 d_ptr = d_ptr->next;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
357 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
358 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
359
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
360
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
361 int main(int argc, char** argv) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
362 pst_desc_ll *d_ptr;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
363 char *fname = NULL;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
364 char *temp = NULL; //temporary char pointer
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
365 char c;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
366 prog_name = argv[0];
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
367 pst_item *item = NULL;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
368
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
369 while ((c = getopt(argc, argv, "b:c:Vh"))!= -1) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
370 switch (c) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
371 case 'b':
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
372 ldap_base = optarg;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
373 temp = strchr(ldap_base, ',');
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
374 if (temp) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
375 *temp = '\0';
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
376 ldap_org = strdup(ldap_base+2); // assume first 2 chars are o=
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
377 *temp = ',';
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
378 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
379 break;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
380 case 'c':
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
381 ldap_class = optarg;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
382 break;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
383 case 'h':
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
384 usage();
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
385 exit(0);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
386 break;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
387 case 'V':
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
388 version();
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
389 exit(0);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
390 break;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
391 default:
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
392 usage();
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
393 exit(1);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
394 break;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
395 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
396 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
397
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
398 if ((argc > optind) && (ldap_base) && (ldap_class) && (ldap_org)) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
399 fname = argv[optind];
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
400 } else {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
401 usage();
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
402 exit(2);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
403 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
404
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
405 DEBUG_INIT("pst2ldif.log");
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
406 DEBUG_REGISTER_CLOSE();
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
407 DEBUG_ENT("main");
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
408 RET_DERROR(pst_open(&pstfile, fname, "r"), 1, ("Error opening File\n"));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
409 RET_DERROR(pst_load_index(&pstfile), 2, ("Index Error\n"));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
410
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
411 pst_load_extended_attributes(&pstfile);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
412
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
413 d_ptr = pstfile.d_head; // first record is main record
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
414 item = (pst_item*)_pst_parse_item(&pstfile, d_ptr);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
415 if (!item || !item->message_store) {
12
3f627519a92d properly ignore (second block zero) errors. that will just drop some unknown attachments, but the rest of the data is still found
carl
parents: 11
diff changeset
416 DEBUG_RET();
11
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
417 DIE(("main: Could not get root record\n"));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
418 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
419
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
420 d_ptr = pst_getTopOfFolders(&pstfile, item);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
421 if (!d_ptr) {
12
3f627519a92d properly ignore (second block zero) errors. that will just drop some unknown attachments, but the rest of the data is still found
carl
parents: 11
diff changeset
422 DEBUG_RET();
11
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
423 DIE(("Top of folders record not found. Cannot continue\n"));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
424 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
425
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
426 _pst_freeItem(item);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
427
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
428 // write the ldap header
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
429 printf("dn: %s\n", ldap_base);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
430 printf("o: %s\n", ldap_org);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
431 printf("objectClass: organization\n\n");
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
432 printf("dn: cn=root, %s\n", ldap_base);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
433 printf("cn: root\n");
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
434 printf("objectClass: %s\n\n", ldap_class);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
435
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
436 process(d_ptr->child); // do the children of TOPF
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
437 pst_close(&pstfile);
12
3f627519a92d properly ignore (second block zero) errors. that will just drop some unknown attachments, but the rest of the data is still found
carl
parents: 11
diff changeset
438 DEBUG_RET();
11
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
439 return 0;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
440 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
441
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
442
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
443 int usage() {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
444 version();
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
445 printf("Usage: %s [OPTIONS] {PST FILENAME}\n", prog_name);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
446 printf("OPTIONS:\n");
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
447 printf("\t-h\t- Help. This screen\n");
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
448 printf("\t-V\t- Version. Display program version\n");
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
449 printf("\t-b ldapbase\t- set the ldap base value\n");
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
450 printf("\t-c class \t- set the class of the ldap objects\n");
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
451 return 0;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
452 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
453
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
454
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
455 int version() {
13
80ae7e5cb562 patches from debian
carl
parents: 12
diff changeset
456 printf("pst2ldif v%s\n", VERSION);
11
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
457 #if BYTE_ORDER == BIG_ENDIAN
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
458 printf("Big Endian implementation being used.\n");
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
459 #elif BYTE_ORDER == LITTLE_ENDIAN
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
460 printf("Little Endian implementation being used.\n");
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
461 #else
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
462 # error "Byte order not supported by this library"
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
463 #endif
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
464 #ifdef __GNUC__
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
465 printf("GCC %d.%d : %s %s\n", __GNUC__, __GNUC_MINOR__, __DATE__, __TIME__);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
466 #endif
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
467 return 0;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
468 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
469
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
470
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
471 // my_stristr varies from strstr in that its searches are case-insensitive
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
472 char * my_stristr(char *haystack, char *needle) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
473 char *x=haystack, *y=needle, *z = NULL;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
474 if (haystack == NULL || needle == NULL)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
475 return NULL;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
476 while (*y != '\0' && *x != '\0') {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
477 if (tolower(*y) == tolower(*x)) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
478 // move y on one
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
479 y++;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
480 if (z == NULL) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
481 z = x; // store first position in haystack where a match is made
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
482 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
483 } else {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
484 y = needle; // reset y to the beginning of the needle
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
485 z = NULL; // reset the haystack storage point
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
486 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
487 x++; // advance the search in the haystack
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
488 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
489 return z;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
490 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
491
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
492
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
493 char *check_filename(char *fname) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
494 char *t = fname;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
495 if (t == NULL) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
496 return fname;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
497 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
498 while ((t = strpbrk(t, "/\\:"))) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
499 // while there are characters in the second string that we don't want
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
500 *t = '_'; //replace them with an underscore
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
501 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
502 return fname;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
503 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
504
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
505
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
506 char *single(char *str) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
507 if (!str) return "";
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
508 char *ret = rfc2426_escape(str);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
509 char *n = strchr(ret, '\n');
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
510 if (n) *n = '\0';
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
511 return ret;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
512 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
513
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
514
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
515 char *folded(char *str) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
516 if (!str) return "";
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
517 char *ret = rfc2426_escape(str);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
518 char *n = ret;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
519 while (n = strchr(n, '\n')) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
520 *n = ' ';
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
521 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
522 n = ret;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
523 while (n = strchr(n, ',')) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
524 *n = ' ';
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
525 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
526 return ret;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
527 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
528
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
529
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
530 void multi(char *fmt, char *str) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
531 if (!str) return;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
532 char *ret = rfc2426_escape(str);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
533 char *n = ret;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
534 while (n = strchr(ret, '\n')) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
535 *n = '\0';
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
536 printf(fmt, ret);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
537 ret = n+1;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
538 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
539 if (*ret) printf(fmt, ret);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
540 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
541
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
542
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
543 char *rfc2426_escape(char *str) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
544 static char* buf = NULL;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
545 char *ret, *a, *b;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
546 int x = 0, y, z;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
547 if (str == NULL)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
548 ret = str;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
549 else {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
550
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
551 // calculate space required to escape all the following characters
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
552 x = strlen(str) +(y=(chr_count(str, ',')*2) + (chr_count(str, '\\')*2) + (chr_count(str, ';')*2) + (chr_count(str, '\n')*2));
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
553 z = chr_count(str, '\r');
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
554 if (y == 0 && z == 0)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
555 // there isn't any extra space required
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
556 ret = str;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
557 else {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
558 buf = (char*) realloc(buf, x+1);
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
559 a = str;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
560 b = buf;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
561 while (*a != '\0') {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
562 switch(*a) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
563 // case ',' :
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
564 case '\\':
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
565 case ';' :
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
566 // case '\n':
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
567 *(b++)='\\';
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
568 *b=*a;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
569 break;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
570 case '\r':
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
571 break;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
572 default:
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
573 *b=*a;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
574 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
575 b++;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
576 a++;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
577 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
578 *b = '\0';
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
579 ret = buf;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
580 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
581 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
582 return ret;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
583 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
584
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
585
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
586 int chr_count(char *str, char x) {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
587 int r = 0;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
588 while (*str != '\0') {
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
589 if (*str == x)
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
590 r++;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
591 str++;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
592 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
593 return r;
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
594 }
bf12a9d4524c more code cleanup
carl
parents: 9
diff changeset
595