Skip to content

Instantly share code, notes, and snippets.

@MuntashirAkon
Created April 25, 2020 14:26
Show Gist options
  • Save MuntashirAkon/82994e36e9070e4f3f2bc149224d9aab to your computer and use it in GitHub Desktop.
Save MuntashirAkon/82994e36e9070e4f3f2bc149224d9aab to your computer and use it in GitHub Desktop.
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