Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert mmssms.db to QKSMS compatible json file
<?php
if(!isset($argv[1])){
echo "USAGE: ${argv[0]} <mmssms.db file>\n";
exit(1);
}
$db_file = $argv[1];
$db = new SQLite3($db_file);
$stmt = $db->prepare("SELECT * FROM sms");
$res = $stmt->execute();
$qksms = [];
while($arr = $res->fetchArray(SQLITE3_ASSOC)){
$out = [
'type' => (int) $arr['type'],
'address' => $arr['address'],
'date' => (int) $arr['date'],
'dateSent' => (int) $arr['date_sent'],
'read' => (bool) $arr['read'],
'status' => (int) $arr['status'],
'body' => $arr['body'],
'protocol' => (int) $arr['protocol'],
'locked' => (bool) $arr['locked'],
'subId' => $arr['sim_id'] == 2 ? 1:2
];
array_push($qksms, $out);
}
echo json_encode([
'messageCount' => count($qksms),
'messages' => $qksms
], JSON_PRETTY_PRINT) . "\n";
exit(0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment