diff --git a/bin/inspect.php b/bin/inspect.php --- a/bin/inspect.php +++ b/bin/inspect.php @@ -217,6 +217,29 @@ return "Unknown value: $value"; } +function getContentUids($db, $device_id, $folder_id) { + $contentSelect = $db->query( + "SELECT contentid FROM `syncroton_content`" + . " WHERE `device_id` = ? AND `folder_id` = ?", + $device_id, $folder_id + ); + + $contentUids = []; + while ($content = $db->fetch_assoc($contentSelect)) { + $contentUids[] = explode('::', $content['contentid'])[1]; + } + return $contentUids; +} + +function getImapUids($imap, $folder) { + $imap->select($folder); + $index = $imap->search($folder, 'ALL UNDELETED', true); + if (!$index->is_error()) { + return $index->get(); + } + return []; +} + println(""); foreach ($result as $deviceId => $values) { println("Device: $deviceId"); @@ -239,6 +262,29 @@ println(" Last sync: " . ($folder['lastsync'] ?? "None")); println(" Number of syncs: " . ($folder['counter'] ?? "None")); println(" Filter type: " . filterType($folder['lastfiltertype'] ?? null)); + + if ($messageCount != $totalCount && ($modseq == "none" || $modseq == $imapModseq)) { + println(" Issue Detected: The sync state seems to be inconsistent. The device should be fully synced, but the sync counts differ."); + + $contentUids = getContentUids($db, $deviceId, $folderId); + $imapUids = getImapUids($imap, $folder['name']); + + println(" The following messages are on the server, but not the device"); + $entries = array_diff($imapUids, $contentUids); + foreach ($entries as $uid) { + println(" $uid"); + //TODO get details from imap? + } + + println(" The following messages are on the device, but not the server"); + $entries = array_diff($contentUids, $imapUids); + foreach ($entries as $uid) { + println(" $uid"); + //TODO get details from the content part? + } + println(""); + } + println(""); } }