Skip to content
This repository was archived by the owner on Nov 22, 2026. It is now read-only.
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion ui/components/SettingsPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Quickshell.Io
import qs.Commons
import qs.Ui
import "../message/Direction.js" as Direction
import "../message/Message.js" as Message
import "../settings/Appearance.js" as Appearance
import "../message/Html.js" as Html

Expand Down Expand Up @@ -180,9 +181,17 @@ Column {
importFailed = true
return
}
// Invariant: The engine refuses HTML over 256 K UTF-16 units, and a UTF-8 byte yields at most one unit for every
// three bytes, so a larger file is refused here before the JavaScript decoder spends time on it.
if (kind === "html" && Number(result.size || String(result.data || "").length * 3 / 4) > 3 * 256 * 1024) {
importing = false
importNote = "That file is too large for a signature"
importFailed = true
return
}
var accountId = importingAccountId
service.backend.call("message.signatureImport", { kind: kind,
data: kind === "html" ? Qt.atob(String(result.data || "")) : String(result.data || "")
data: kind === "html" ? Message.decodeBase64Url(String(result.data || "")) : String(result.data || "")
}, function(imported, error) {
root.importing = false
if (error || !imported) {
Expand Down
8 changes: 2 additions & 6 deletions ui/message/Message.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,15 +85,11 @@ function bytesToLatin1(bytes) {
return out
}

// Invariant: Qt.atob returns decoded QString text; decoding it again as byte values corrupts non-ASCII text.
// Invariant: Decodes base64 or base64url bytes as UTF-8 in JavaScript, not with Qt.atob, whose string form Qt has
// deprecated; QML and the Node tests then share one decoder, and malformed bytes fall back as bytesToUtf8 says.
function decodeBase64Url(text) {
var input = String(text || "")
if (input === "") return ""
if (typeof Qt !== "undefined" && typeof Qt.atob === "function") {
try {
return Qt.atob(input.replace(/-/g, "+").replace(/_/g, "/"))
} catch (parseError) {}
}
return bytesToUtf8(base64ToBytes(input))
}

Expand Down
4 changes: 3 additions & 1 deletion ui/tests/qml/tst_message_base64.qml
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ Item {



function test_qt_atob_result_is_not_decoded_a_second_time() {
function test_base64_decodes_utf8_text_once() {
compare(Message.decodeBase64Url("QWxleCDDoCBsJ8OpY29sZQ=="), "Alex à l'école")
compare(Message.decodeBase64Url("8J+Ygg"), "\ud83d\ude02")
compare(Message.decodeBase64Url("PHA-w6k8L3A-"), "<p>é</p>")
}

function test_encoded_display_text_cannot_route_a_reply() {
Expand Down
19 changes: 19 additions & 0 deletions ui/tests/qml/tst_signature_import_lifecycle.qml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,25 @@ Item {
compare(page.importFailed, true)
compare(page.importNote, "That image cannot be safely displayed")
}
function test_html_import_sends_decoded_utf8_text() {
page.importSignature()
fakeService.pickerCallback({ok: true, paths: ["/synthetic/signature.html"]})
fakeBackend.callback({ok: true, mimeType: "text/html", filename: "signature.html", size: 9,
data: "PHA+w6k8L3A+"}, null)
compare(fakeBackend.method, "message.signatureImport")
compare(fakeBackend.params.kind, "html")
compare(fakeBackend.params.data, "<p>\u00e9</p>")
}
function test_oversized_html_import_is_refused_before_decoding() {
page.importSignature()
fakeService.pickerCallback({ok: true, paths: ["/synthetic/signature.html"]})
fakeBackend.callback({ok: true, mimeType: "text/html", filename: "signature.html",
size: 3 * 256 * 1024 + 1, data: "PHA+w6k8L3A+"}, null)
compare(fakeBackend.method, "attachment.read")
compare(page.importing, false)
compare(page.importFailed, true)
compare(page.importNote, "That file is too large for a signature")
}
function test_picker_completion_keeps_the_original_account() {
page.importSignature()
page.selectSignatureAccount("b@example.net")
Expand Down
19 changes: 19 additions & 0 deletions ui/tests/test_message.js
Original file line number Diff line number Diff line change
Expand Up @@ -1235,4 +1235,23 @@ assert.strictEqual(message.composeBody("\n\n", ""), "")
assert.strictEqual(message.draftFields({ replyTo: { email: "team@example.com" }, to: [] }, "x").replyTo, "team@example.com")
assert.strictEqual(message.draftFields({ replyTo: { email: "" }, to: [] }, "x").replyTo, "")

// Invariant: production code decodes base64 in JavaScript; Qt has deprecated the string form of Qt.atob.
{
const fs = require("fs")
const path = require("path")
const repository = path.join(__dirname, "..", "..")
const offenders = []
const visit = directory => {
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
const full = path.join(directory, entry.name)
if (entry.isDirectory()) { if (entry.name !== "tests") visit(full); continue }
if (!/\.(qml|js)$/.test(entry.name)) continue
if (/\bQt\.atob\s*\(/.test(fs.readFileSync(full, "utf8"))) offenders.push(path.relative(repository, full))
}
}
visit(path.join(repository, "ui"))
visit(path.join(repository, "app", "qml"))
assert.deepStrictEqual(offenders, [], "Qt.atob is deprecated in Qt 6.12; decode with Message.decodeBase64Url")
}

console.log("test_message.js ok")
Loading