thunderbird2docuware/lib/store.js
sylyx 53d3675dc1 Feature: Mail-Format .eml ODER PDF (nicht beides) + konfigurierbares Feld-Mapping
- Dialog/Optionen: mailFormat-Radio (.eml/PDF) + eigener Anhänge-Haken statt
  scope/optPdf; nie mehr eml UND pdf gleichzeitig. Migration storeEml/storePdf.
- Feld-Zuordnung in den Einstellungen editierbar (MAIL_TOKENS/DEFAULT_FIELD_MAP
  in store.js); PREFILL -> TOKEN_FN + effectiveFieldMap/prefillFor.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-16 13:23:39 +02:00

92 lines
3.2 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,
fieldMapping: {}, // DocuWare-Feldname -> Mail-Attribut (Token). Leer = DEFAULT_FIELD_MAP.
};
// 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 };