Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3c38a1a6cc | |||
| ba0b79de64 | |||
| 60bd3163a9 | |||
| a3a3ac1dcc | |||
| 9d58a1a113 |
+1
-1
@@ -2,7 +2,7 @@
|
||||
; Erfordert Inno Setup 6.x (https://jrsoftware.org/isinfo.php)
|
||||
|
||||
#define MyAppName "Starface Outlook Sync"
|
||||
#define MyAppVersion "0.0.0.7"
|
||||
#define MyAppVersion "0.0.0.10"
|
||||
#define MyAppPublisher "HackerSoft - Hacker-Net Telekommunikation"
|
||||
#define MyAppURL "https://www.hacker-net.de"
|
||||
#define MyAppExeName "StarfaceOutlookSync.exe"
|
||||
|
||||
@@ -153,6 +153,32 @@ namespace StarfaceOutlookSync.Services
|
||||
}
|
||||
}
|
||||
|
||||
private dynamic FindFolderByPath(dynamic folder, string targetPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
string currentPath = folder.FolderPath;
|
||||
if (currentPath == targetPath)
|
||||
return folder;
|
||||
|
||||
var subs = folder.Folders;
|
||||
for (int i = 1; i <= (int)subs.Count; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
var sub = subs[i];
|
||||
var match = FindFolderByPath(sub, targetPath);
|
||||
if (match != null) return match;
|
||||
Marshal.ReleaseComObject(sub);
|
||||
}
|
||||
catch { }
|
||||
}
|
||||
Marshal.ReleaseComObject(subs);
|
||||
}
|
||||
catch { }
|
||||
return null;
|
||||
}
|
||||
|
||||
private dynamic GetFolderByPath(string folderPath)
|
||||
{
|
||||
var app = GetOutlookApp();
|
||||
@@ -163,51 +189,69 @@ namespace StarfaceOutlookSync.Services
|
||||
|
||||
try
|
||||
{
|
||||
var parts = folderPath.Split(new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
dynamic current = null;
|
||||
|
||||
// Versuch 1: Alle Kontaktordner durchsuchen und per FolderPath matchen
|
||||
var stores = ns.Stores;
|
||||
for (int i = 1; i <= (int)stores.Count; i++)
|
||||
{
|
||||
var store = stores[i];
|
||||
var root = store.GetRootFolder();
|
||||
string rootName = root.Name;
|
||||
|
||||
if (rootName == parts[0])
|
||||
try
|
||||
{
|
||||
current = root;
|
||||
break;
|
||||
var store = stores[i];
|
||||
var root = store.GetRootFolder();
|
||||
var match = FindFolderByPath(root, folderPath);
|
||||
if (match != null)
|
||||
{
|
||||
Marshal.ReleaseComObject(stores);
|
||||
return match;
|
||||
}
|
||||
Marshal.ReleaseComObject(root);
|
||||
Marshal.ReleaseComObject(store);
|
||||
}
|
||||
Marshal.ReleaseComObject(root);
|
||||
Marshal.ReleaseComObject(store);
|
||||
catch { }
|
||||
}
|
||||
Marshal.ReleaseComObject(stores);
|
||||
|
||||
if (current == null)
|
||||
return ns.GetDefaultFolder(OlFolderContacts);
|
||||
|
||||
for (int i = 1; i < parts.Length; i++)
|
||||
// Versuch 2: Namespace.Folders direkt navigieren
|
||||
var parts = folderPath.Split(new[] { '\\' }, StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length >= 1)
|
||||
{
|
||||
bool found = false;
|
||||
var subFolders = current.Folders;
|
||||
for (int j = 1; j <= (int)subFolders.Count; j++)
|
||||
var topFolders = ns.Folders;
|
||||
for (int i = 1; i <= (int)topFolders.Count; i++)
|
||||
{
|
||||
var sub = subFolders[j];
|
||||
if ((string)sub.Name == parts[i])
|
||||
var topFolder = topFolders[i];
|
||||
if ((string)topFolder.Name == parts[0])
|
||||
{
|
||||
current = sub;
|
||||
found = true;
|
||||
break;
|
||||
dynamic current = topFolder;
|
||||
for (int p = 1; p < parts.Length; p++)
|
||||
{
|
||||
bool found = false;
|
||||
var subs = current.Folders;
|
||||
for (int j = 1; j <= (int)subs.Count; j++)
|
||||
{
|
||||
var sub = subs[j];
|
||||
if ((string)sub.Name == parts[p])
|
||||
{
|
||||
current = sub;
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
Marshal.ReleaseComObject(sub);
|
||||
}
|
||||
Marshal.ReleaseComObject(subs);
|
||||
if (!found) { current = null; break; }
|
||||
}
|
||||
if (current != null)
|
||||
{
|
||||
Marshal.ReleaseComObject(topFolders);
|
||||
return current;
|
||||
}
|
||||
}
|
||||
Marshal.ReleaseComObject(sub);
|
||||
Marshal.ReleaseComObject(topFolder);
|
||||
}
|
||||
Marshal.ReleaseComObject(subFolders);
|
||||
|
||||
if (!found)
|
||||
return ns.GetDefaultFolder(OlFolderContacts);
|
||||
Marshal.ReleaseComObject(topFolders);
|
||||
}
|
||||
|
||||
return current;
|
||||
System.Diagnostics.Debug.WriteLine($"Folder not found by path: {folderPath}, using default");
|
||||
return ns.GetDefaultFolder(OlFolderContacts);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -221,24 +265,51 @@ namespace StarfaceOutlookSync.Services
|
||||
try
|
||||
{
|
||||
var folder = GetFolderByPath(folderPath);
|
||||
var items = folder.Items;
|
||||
System.Diagnostics.Debug.WriteLine($"Reading contacts from: {(string)folder.FolderPath}");
|
||||
|
||||
for (int i = 1; i <= (int)items.Count; i++)
|
||||
var items = folder.Items;
|
||||
int count = (int)items.Count;
|
||||
System.Diagnostics.Debug.WriteLine($"Items count: {count}");
|
||||
|
||||
for (int i = 1; i <= count; i++)
|
||||
{
|
||||
dynamic item = null;
|
||||
try
|
||||
{
|
||||
item = items[i];
|
||||
// Nur ContactItems verarbeiten (Class = 40 = olContact)
|
||||
if ((int)item.Class == 40)
|
||||
int itemClass = -1;
|
||||
try { itemClass = (int)item.Class; } catch { }
|
||||
|
||||
// olContact = 40, aber manche Kontakte melden Class anders
|
||||
// Versuch einfach die Kontakt-Felder zu lesen
|
||||
if (itemClass == 40)
|
||||
{
|
||||
contacts.Add(MapFromOutlook(item));
|
||||
}
|
||||
else
|
||||
{
|
||||
// Fallback: Pruefen ob es trotzdem ein Kontakt ist
|
||||
try
|
||||
{
|
||||
string eid = item.EntryID;
|
||||
string fn = item.FirstName;
|
||||
string ln = item.LastName;
|
||||
// Hat Kontakt-Felder -> ist ein Kontakt
|
||||
contacts.Add(MapFromOutlook(item));
|
||||
}
|
||||
catch
|
||||
{
|
||||
// Kein Kontakt, ueberspringen
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"Error reading item {i}: {ex.Message}");
|
||||
}
|
||||
catch { }
|
||||
finally
|
||||
{
|
||||
if (item != null) Marshal.ReleaseComObject(item);
|
||||
if (item != null) try { Marshal.ReleaseComObject(item); } catch { }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -155,11 +155,14 @@ namespace StarfaceOutlookSync.Services
|
||||
return books;
|
||||
}
|
||||
|
||||
public event Action<string> OnDebug;
|
||||
|
||||
public async Task<List<UnifiedContact>> GetContactsAsync(StarfaceAddressBook book)
|
||||
{
|
||||
var contacts = new List<UnifiedContact>();
|
||||
int page = 0;
|
||||
const int pageSize = 200;
|
||||
bool firstPage = true;
|
||||
|
||||
while (true)
|
||||
{
|
||||
@@ -172,9 +175,47 @@ namespace StarfaceOutlookSync.Services
|
||||
var resp = await _http.GetAsync($"{_baseUrl}/contacts?{query}");
|
||||
if (!resp.IsSuccessStatusCode) break;
|
||||
|
||||
var array = JArray.Parse(await resp.Content.ReadAsStringAsync());
|
||||
var body = await resp.Content.ReadAsStringAsync();
|
||||
JArray array;
|
||||
|
||||
// Die API gibt je nach Version ein Array oder ein Objekt mit "items" zurueck
|
||||
var token = JToken.Parse(body);
|
||||
if (token is JArray directArray)
|
||||
{
|
||||
array = directArray;
|
||||
}
|
||||
else if (token is JObject obj)
|
||||
{
|
||||
// Versuche gaengige Felder: items, contacts, data, results
|
||||
array = (obj["items"] ?? obj["contacts"] ?? obj["data"] ?? obj["results"]) as JArray;
|
||||
if (array == null)
|
||||
{
|
||||
// Einzelnes Kontakt-Objekt? Dann in Array wrappen
|
||||
if (obj["id"] != null && obj["blocks"] != null)
|
||||
{
|
||||
array = new JArray { obj };
|
||||
}
|
||||
else
|
||||
{
|
||||
System.Diagnostics.Debug.WriteLine($"Unerwartete Starface-Antwort: {body.Substring(0, Math.Min(200, body.Length))}");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
if (array.Count == 0) break;
|
||||
|
||||
// Ersten Kontakt als Debug-Info loggen
|
||||
if (firstPage && array.Count > 0)
|
||||
{
|
||||
OnDebug?.Invoke($"Starface API Rohdaten (1. Kontakt):\n{array[0].ToString(Formatting.Indented)}");
|
||||
firstPage = false;
|
||||
}
|
||||
|
||||
foreach (var item in array)
|
||||
contacts.Add(MapFromStarface(item));
|
||||
|
||||
|
||||
@@ -53,6 +53,7 @@ namespace StarfaceOutlookSync.Services
|
||||
Log("Verbinde mit Starface...");
|
||||
using (var starface = new StarfaceApiClient(profile.StarfaceConnection))
|
||||
{
|
||||
starface.OnDebug += (msg) => Log(msg);
|
||||
var loginOk = await starface.LoginAsync();
|
||||
if (!loginOk)
|
||||
{
|
||||
|
||||
@@ -7,9 +7,9 @@
|
||||
<AssemblyTitle>Starface Outlook Sync</AssemblyTitle>
|
||||
<Company>HackerSoft - Hacker-Net Telekommunikation</Company>
|
||||
<Product>Starface Outlook Sync</Product>
|
||||
<Version>0.0.0.7</Version>
|
||||
<AssemblyVersion>0.0.0.7</AssemblyVersion>
|
||||
<FileVersion>0.0.0.7</FileVersion>
|
||||
<Version>0.0.0.10</Version>
|
||||
<AssemblyVersion>0.0.0.10</AssemblyVersion>
|
||||
<FileVersion>0.0.0.10</FileVersion>
|
||||
<Description>Synchronisiert Outlook-Kontakte mit Starface Telefonanlage</Description>
|
||||
<Copyright>Stefan Hacker - HackerSoft</Copyright>
|
||||
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace StarfaceOutlookSync.UI
|
||||
|
||||
var lblVersion = new Label
|
||||
{
|
||||
Text = "Version 0.0.0.7",
|
||||
Text = "Version 0.0.0.10",
|
||||
Left = 0, Top = 56, Width = 340, Height = 20,
|
||||
TextAlign = ContentAlignment.MiddleCenter,
|
||||
ForeColor = Color.Gray
|
||||
|
||||
Reference in New Issue
Block a user