| 2816 | } |
| 2817 | |
| 2818 | function extractAttributedBodyText(hex) { |
| 2819 | if (!hex) return ""; |
| 2820 | const buffer = Buffer.from(String(hex), "hex"); |
| 2821 | const marker = Buffer.from("NSString", "utf8"); |
| 2822 | const markerIndex = buffer.indexOf(marker); |
| 2823 | if (markerIndex === -1) return ""; |
| 2824 | const plusIndex = buffer.indexOf(0x2b, markerIndex + marker.length); |
| 2825 | if (plusIndex === -1 || plusIndex + 1 >= buffer.length) return ""; |
| 2826 | const length = buffer[plusIndex + 1]; |
| 2827 | if (length <= 0 || plusIndex + 2 + length > buffer.length) return ""; |
| 2828 | return buffer.subarray(plusIndex + 2, plusIndex + 2 + length).toString("utf8").trim(); |
| 2829 | } |
| 2830 | |
| 2831 | async function initializeIMessageCursor() { |
| 2832 | const rows = await sqliteJson("select coalesce(max(ROWID), 0) as rowid from message;"); |