thunderbird2docuware/lib/store.js
sylyx 81964c76d3 Mapping: feste Werte ({const}) + Teilen via JSON-Copy/Paste und Pull von raw-JSON-URL (mappingUrl)
- prefillFor löst Token-String ODER {const:...} auf; Options-Editor mit
  'Fester Wert'-Option + Konstanten-Eingabe.
- Feld-Zuordnung: JSON exportieren/anwenden/kopieren, von URL laden (Gitea/GitHub raw).
- Fix: zwei Statustexte mit ASCII-Quote in " gehärtet.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-16 15:01:37 +02:00

95 lines
3.3 KiB
JavaScript
Raw 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;
},
async set(partial) {
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;
},
/** 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 };