3 #include "wvstringlist.h"
15 void get_evo_uri_from_eit_key(WvStringParm eit_key
, WvStringParm storage_owner
, WvString
&evo_uri
)
17 WvStringList eit_folder_keys
;
18 eit_folder_keys
.split(eit_key
, ".");
21 if (eit_folder_keys
.count() < 2)
24 WvString owner
= eit_folder_keys
.popstr();
25 if (strcmp(storage_owner
.cstr(), owner
.cstr()) != 0)
26 evo_uri
.append("/Public Folders/%s", owner
);
28 WvStringList::Iter
folder_key(eit_folder_keys
);
31 for(;folder_key
.next();)
33 evo_uri
.append("/%s", folder_key());
38 void get_physical_path_from_evo_uri(WvStringParm evo_uri
, WvString
&path
, WvString
&subfolders_path
)
43 path
.append("%s/evolution/local/", g_get_home_dir());
46 dirs
.split((evo_uri
.cstr()+1), "/");
50 path
.append(dirs
.popstr());
51 WvStringList::Iter
dir(dirs
);
56 subfolders_path
= path
;
57 subfolders_path
.append("/subfolders");
58 path
.append("/subfolders/%s", dir());
62 bool eitpath_is_local(WvStringParm path
, WvStringParm owner
)
64 return !strncmp(path
, owner
, owner
.len());
67 WvString
convert_eitpath_to_evopath(WvStringParm eitpath
, WvStringParm owner
)
69 WvLog
log("convert_eitpath_to_evopath");
71 dirs
.split(eitpath
, ".");
74 WvStringList::Iter
i(dirs
);
75 //assert(dirs.count() > 1);
77 if (dirs
.count() <= 1)
86 evopath
.append("/Public Folders/%s", i());
88 while (i
.next()) // skip folder owner
97 WvString
convert_evopath_to_eitpath(WvStringParm evopath
, WvStringParm owner
)
99 // FIXME: What to do with folder names with '.' in them?
101 dirs
.split(evopath
, "/");
103 WvString
eitpath("");
104 WvStringList::Iter
i(dirs
);
109 if (i() == "Public Folders")
115 eitpath
.append("%s.%s", owner
, i());
129 void destroy_dir(WvStringParm path
)
131 // FIXME: We might actually want to do some error checking here and warn
132 // the user if things are going badly here. These operations should never
133 // fail normally though.. and if they do, the worst that can happen is that
134 // the user won't be able to create a folder.. whopdee doo
136 DIR *dir
= opendir(path
.cstr());
137 if(dir
== NULL
) // nothing to do, can't access dir (probably 'cause it's already gone)
140 struct dirent
*current
= readdir(dir
);
143 // The following 10 lines of code are from the friendly hackers @ Ximian
145 if(current
->d_name
[0] == '.')
147 if(current
->d_name
[1] == '\0' ||
148 (current
->d_name
[1] == '.' && current
->d_name
[2] == '\0'))
150 current
= readdir(dir
);
155 WvString
full_path("%s/%s", path
, current
->d_name
);
157 stat(full_path
.cstr(), &buf
);
158 unlink(full_path
.cstr());
159 current
= readdir(dir
);
163 rmdir(path
.cstr()); // this will vonly succeed when it should