thunderbird2docuware/lib/store.js
sylyx 589c0018a9 Fixes: XSS-Schutz, Datums-Zeitzone, Multi-Retry, Settings-Race, http-Warnung
- dialog.js: Anhang-Liste per DOM-API statt innerHTML (kein HTML-Inject über
  angreiferkontrollierte Anhang-Namen); Feldname-Selektoren via CSS.escape,
  datalist-id bereinigt; Datums-Eingabe lokal statt UTC (kein Off-by-one);
  bereits abgelegte Mails bei Retry überspringen (keine Dubletten)
- docuware.js: Datumsfelder auf lokalen Kalendertag normalisieren (UTC-Mitternacht)
- store.js: Settings.set serialisiert (kein read-modify-write Race)
- options.js: Warnung bei unverschlüsseltem http://-Server
- mail.js: ungenutzten Parameter aus _direction entfernt

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-17 13:43:59 +02:00

105 lines
3.8 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// Einstellungen lesen/schreiben (browser.storage.local).
// Wichtig: Das Passwort wird NICHT gespeichert. Es wird beim Login einmalig
// abgefragt, daraus ein OAuth-Token geholt und sofort verworfen (siehe auth.js
// + background.js). In storage.local liegen nur unkritische Daten.
const DEFAULTS = {
serverUrl: "", // z.B. https://docuware.example.com (ohne /DocuWare/Platform)
organization: "",
username: "",
defaultCabinetId: "",
dialogByCabinet: {}, // gemerkter Ablagedialog je Schrank: { [cabinetId]: dialogId }
mailFormat: "eml", // E-Mail wird als "eml" ODER "pdf" abgelegt (nie beides)
storeAttachments: true,
tagOnSuccess: true,
// DocuWare-Feldname -> Wert: entweder ein Mail-Token ("subject") ODER ein fester
// Wert ({ const: "NEU" }). Leer = DEFAULT_FIELD_MAP.
fieldMapping: {},
mappingUrl: "", // optional: raw-JSON-URL (Gitea/GitHub) zum Nachladen des Mappings.
};
// Mögliche Mail-Attribute für die Vorbefüllung (Token + Anzeigename).
// Wird von dialog.js (Werte aus meta) und options.js (Mapping-Editor) genutzt.
const MAIL_TOKENS = [
{ key: "senderEmail", label: "Absender E-Mail" },
{ key: "senderName", label: "Absender Name" },
{ key: "to", label: "Empfänger (An)" },
{ key: "cc", label: "CC" },
{ key: "bcc", label: "BCC" },
{ key: "subject", label: "Betreff" },
{ key: "body", label: "Text (Body)" },
{ key: "date", label: "Datum" },
{ key: "direction", label: "Richtung (Ein-/Ausgang)" },
{ key: "size", label: "Größe (Bytes)" },
{ key: "account", label: "Konto" },
];
// Standard-Zuordnung DocuWare-Feldname -> Mail-Token. Greift, solange der Nutzer
// in den Einstellungen kein eigenes fieldMapping gespeichert hat.
const DEFAULT_FIELD_MAP = {
EML_SENDER: "senderEmail",
EML_SENDER_DISPLAYNAME: "senderName",
EML_SENDER_NAME: "senderName",
EML_RECEIVER: "to",
EML_CC: "cc",
EML_BCC: "bcc",
EML_SUBJECT: "subject",
DOC_SUBJECT: "subject",
EML_BODY: "body",
EML_SENDINGDATE: "date",
EML_DISPLAYDATE: "date",
EML_RECEIVINGDATE: "date",
EML_DIRECTION: "direction",
EML_SIZE: "size",
EML_ACCOUNT: "account",
DOC_DATE: "date",
SUBJECT: "subject",
BETREFF: "subject",
EMAIL: "senderEmail",
E_MAIL: "senderEmail",
DATE: "date",
DATUM: "date",
};
const Settings = {
async get() {
const stored = await browser.storage.local.get("settings");
const raw = stored.settings || {};
const s = { ...DEFAULTS, ...raw };
// Migration: altes storeEml/storePdf -> mailFormat (einmalig, nicht persistiert).
if (raw.mailFormat === undefined && raw.storePdf && !raw.storeEml) {
s.mailFormat = "pdf";
}
return s;
},
// Laufende Schreibkette: serialisiert parallele set()-Aufrufe, damit zwei fast
// gleichzeitige Writes (z.B. Schrankwahl + Format-Umschalten) sich nicht beim
// read-modify-write gegenseitig überschreiben.
_writeQueue: Promise.resolve(),
async set(partial) {
const run = async () => {
const current = await this.get();
const next = { ...current, ...partial };
// Sicherheitsnetz: Passwort darf NIE persistiert werden (z.B. aus Alt-Importen).
delete next.password;
await browser.storage.local.set({ settings: next });
return next;
};
const p = this._writeQueue.then(run, run);
this._writeQueue = p.catch(() => {}); // Fehler bricht die Kette nicht ab
return p;
},
/** Basis-URL der Platform-API ohne abschließenden Slash. */
platformUrl(settings) {
const base = (settings.serverUrl || "").replace(/\/+$/, "");
if (!base) throw new Error("Keine DocuWare-Server-URL konfiguriert.");
return `${base}/DocuWare/Platform`;
},
};
if (typeof module !== "undefined")
module.exports = { Settings, DEFAULTS, MAIL_TOKENS, DEFAULT_FIELD_MAP };