<?xml version="1.0" encoding="UTF-8"?>
<OfficeApp
  xmlns="http://schemas.microsoft.com/office/appforoffice/1.1"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0"
  xsi:type="MailApp">

  <!-- Production: outlook.priviq.ai | Dev: localhost:3000

       DIESES MANIFEST IST KEINE KOPIE DER ANDEREN DREI. Wer es als solche
       behandelt, baut ein Add-in, das Outlook kommentarlos nicht lädt.
       Verifiziert gegen Microsoft Learn, Punkt für Punkt:

       1. ANDERER TYP. Excel/Word/PowerPoint sind xsi:type="TaskPaneApp",
          Outlook ist xsi:type="MailApp". Microsoft ausdrücklich („Office
          Add-ins with the add-in only manifest"): „It isn't possible for an
          add-in only manifest to apply to more than one type: Mail, Task pane,
          or Content." Ein gemeinsames Manifest für Outlook und Excel kann es
          also gar nicht geben — der Grund ist hier ein anderer als bei Word und
          PowerPoint (dort war es die Requirement-Set-Kreuzung), das Ergebnis
          dasselbe: ein eigenes Manifest.

       2. <Requirements> IST PFLICHT. Bei allen anderen Typen optional; bei
          MailApp verlangt „Specify Office applications and API requirements"
          ausdrücklich einen <Requirements>-Block mit der Mindestversion des
          Mailbox-Sets. Das Set heisst `Mailbox`, NICHT `OutlookApi`.

       3. <FormSettings> UND <Rule> SIND PFLICHT und existieren bei TaskPaneApp
          überhaupt nicht (Tabelle „Required elements", Spalte Mail).
          Umgekehrt ist <DefaultSettings> bei MailApp NICHT erlaubt — seine
          Rolle übernimmt <FormSettings>. `scripts/verify-host-manifests.mjs`
          prüft beide Richtungen.

       4. ANDERE VERSIONOVERRIDES. Namensraum
          .../office/mailappversionoverrides statt .../taskpaneappversionoverrides,
          <Host xsi:type="MailHost"> statt "Workbook"/"Document"/"Presentation",
          und ein VersionOverridesV1_1 muss als LETZTES Kind eines
          VersionOverridesV1_0 verschachtelt sein („Version overrides in the
          manifest"). Das innere erbt NICHTS vom äusseren — deshalb sind Hosts
          und Resources unten vollständig wiederholt, nicht aus Versehen.

       DIE ELEMENTREIHENFOLGE IST BINDEND. Microsoft Learn („How to find the
       proper order of manifest elements") gibt für MailApp vor:
       Id, Version, ProviderName, DefaultLocale, DisplayName, Description,
       IconUrl, HighResolutionIconUrl, SupportUrl, AppDomains, Hosts,
       Requirements, FormSettings, Permissions, Rule, VersionOverrides.
       Ein Element an der falschen Stelle macht das Manifest ungültig, und die
       Fehlermeldung des Validators lautet dann irreführend „not a valid child
       of" — als wäre das Element am falschen Elternteil. -->

  <!-- STABIL HALTEN. Excel ist …0001, Word …0002, PowerPoint …0003,
       Outlook ist …0004. Die Id ist der Primärschlüssel jeder Installation:
       sie zu ändern behandelt Office als völlig neue App und bricht jede
       bestehende Installation. Bei Aktualisierungen NUR <Version> erhöhen. -->
  <Id>a1b2c3d4-e5f6-7890-abcd-ef1234560004</Id>
  <Version>1.0.0.0</Version>
  <ProviderName>Priviq AI GmbH</ProviderName>
  <DefaultLocale>de-DE</DefaultLocale>
  <DisplayName DefaultValue="Priviq Outlook Agent">
    <Override Locale="en-US" Value="Priviq Outlook Agent" />
  </DisplayName>
  <Description DefaultValue="KI-gestützte E-Mail-Arbeit — DSGVO-konform, gehostet in Deutschland">
    <Override Locale="en-US" Value="AI-powered email work — GDPR-compliant, hosted in Germany" />
  </Description>
  <IconUrl DefaultValue="https://outlook.priviq.ai/assets/priviq-logo-32.png" />
  <HighResolutionIconUrl DefaultValue="https://outlook.priviq.ai/assets/priviq-logo-64.png" />
  <SupportUrl DefaultValue="https://priviq.ai/support">
    <Override Locale="en-US" Value="https://priviq.ai/en/support" />
  </SupportUrl>

  <!-- agent.priviq.ai bedient sowohl die Agent-API als auch den Supabase-Proxy
       unter /supabase/*, ist also die einzige Backend-Herkunft des Panes. -->
  <AppDomains>
    <AppDomain>https://outlook.priviq.ai</AppDomain>
    <AppDomain>https://agent.priviq.ai</AppDomain>
  </AppDomains>

  <Hosts>
    <Host Name="Mailbox" />
  </Hosts>

  <!-- Mailbox 1.5 — und die Begründung ist eine ANDERE als bei den drei
       Task-Pane-Manifesten, wo die Untergrenze aus den Werkzeugen folgt.

       DIE WERKZEUGE BRAUCHEN NUR 1.3:
         · body.getAsync / body.setAsync        → 1.3  (read_mail_body, insert_text)
         · body.setSelectedDataAsync            → 1.1  (insert_text an der Marke)
         · body.getTypeAsync                    → 1.1  (Format vor dem Schreiben)
         · displayReplyForm / displayReplyAllForm → 1.1 (draft_reply)
         · subject/to/cc, im Verfassen-Modus getAsync → 1.1
         · item.attachments (Lesemodus)         → 1.1
         · dateTimeCreated                      → 1.1

       1.5 KOMMT AUS DEM MANIFEST SELBST. Microsoft Learn („VersionOverrides 1.0
       element in the manifest file for a mail add-in") ordnet dem äusseren
       VersionOverrides Mailbox 1.3 zu, WENN es allein steht — und Mailbox 1.5,
       sobald ein VersionOverridesV1_1 darin verschachtelt ist. Die Seite zu
       „VersionOverrides 1.1 element … for a mail add-in" nennt Mailbox 1.5
       ebenfalls direkt. Das V1_1-Schema unten ist also der Grund, und die
       Untergrenze ist damit so hoch wie nötig und nicht höher: 1.5 ist ab
       Outlook 2016 und in jedem Microsoft-365-Postfach vorhanden.

       WAS BEWUSST NICHT GEFORDERT WIRD: 1.8 für `getAttachmentsAsync`
       (Anhänge eines ENTWURFS). Dafür die Untergrenze zu heben hiesse, Hosts
       auszuschliessen, auf denen alles andere einwandfrei liefe. Der Executor
       prüft stattdessen zur Laufzeit mit `isSetSupported('Mailbox','1.8')` und
       scheitert dort ehrlich, statt eine leere Anhangsliste zu behaupten. -->
  <Requirements>
    <Sets>
      <Set Name="Mailbox" MinVersion="1.5" />
    </Sets>
  </Requirements>

  <!-- <FormSettings> ist bei MailApp Pflicht und ersetzt <DefaultSettings>.
       Microsoft: „Because the <FormSettings> element is required for manifest
       validation, it must be defined in all mail add-ins, including those that
       support Mailbox requirement set 1.3 or later. <FormSettings> is ignored
       when your manifest contains a VersionOverrides element."

       Es ist hier also totes Gewicht für JEDEN Host, den wir tatsächlich
       bedienen — und trotzdem nicht weglassbar, weil das Manifest sonst nicht
       einmal validiert. Beide Formen sind aufgeführt: ItemRead für die
       geöffnete Nachricht, ItemEdit für den Entwurf. Nur eine davon zu nennen
       hiesse, den halben Funktionsumfang auf alten Clients stillzulegen. -->
  <FormSettings>
    <Form xsi:type="ItemRead">
      <DesktopSettings>
        <SourceLocation DefaultValue="https://outlook.priviq.ai/taskpane.html" />
        <RequestedHeight>350</RequestedHeight>
      </DesktopSettings>
    </Form>
    <Form xsi:type="ItemEdit">
      <DesktopSettings>
        <SourceLocation DefaultValue="https://outlook.priviq.ai/taskpane.html" />
      </DesktopSettings>
    </Form>
  </FormSettings>

  <!-- ReadWriteItem, NICHT ReadWriteMailbox — die Berechtigungsstufe ist hier
       eine Produktentscheidung, keine Formalie.

       Microsoft („Understanding Outlook add-in permissions") staffelt vier
       Stufen. `ReadWriteItem` erlaubt, alle Eigenschaften des GERADE
       geöffneten Elements zu lesen und zu schreiben — genau der Umfang, den
       insert_text und draft_reply brauchen. `ReadWriteMailbox` erlaubte
       zusätzlich `makeEwsRequestAsync` und damit Zugriff auf das GESAMTE
       Postfach: jeden Ordner, jede Nachricht, auch die, die der Nutzer nie
       geöffnet hat.

       Genau diese Stufe wäre nötig, um `read_conversation` zu bauen (die
       EWS-Operation GetConversationItems). Sie wird bewusst NICHT angefordert.
       Ein Werkzeug, das eine Liste von Betreffzeilen liefert, rechtfertigt
       keinen Vollzugriff auf das Postfach einer Kanzlei — und der Nutzer sähe
       diese Stufe bei der Installation und müsste ihr zustimmen. Das Werkzeug
       fehlt deshalb; die Begründung steht ausführlich in
       `src/taskpane/types/outlook.types.ts`. -->
  <Permissions>ReadWriteItem</Permissions>

  <!-- <Rule> ist bei MailApp Pflicht und legt fest, WANN das Add-in überhaupt
       aktiviert wird. Es gibt kein Gegenstück bei TaskPaneApp.

       FormType="ReadOrEdit" deckt beide Modi ab. Microsoft
       („Troubleshoot Outlook contextual add-in activation"): Verfassen-Add-ins
       lassen sich ausschliesslich über ItemIs-Regeln mit FormType `Edit` oder
       `ReadOrEdit` aktivieren — ein reines `Read` hätte den Verfassen-Modus
       still ausgeschlossen, und `insert_text` wäre nie aufrufbar gewesen.

       Beide ItemType-Werte, weil der Schema-Extraktor beide behandelt:
       `Message` umfasst E-Mails sowie Besprechungsanfragen und -antworten,
       `Appointment` die Kalendereinträge. -->
  <Rule xsi:type="RuleCollection" Mode="Or">
    <Rule xsi:type="ItemIs" ItemType="Message" FormType="ReadOrEdit" />
    <Rule xsi:type="ItemIs" ItemType="Appointment" FormType="ReadOrEdit" />
  </Rule>

  <VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides" xsi:type="VersionOverridesV1_0">
    <Hosts>
      <!-- xsi:type="MailHost" ist die VersionOverrides-Schreibweise für
           Outlook; im Basis-Manifest heisst derselbe Host Name="Mailbox".
           Dieselbe Asymmetrie wie bei Word (Document/Document) und PowerPoint
           (Presentation/Presentation) — nur dass die beiden Namen hier
           tatsächlich verschieden sind. -->
      <Host xsi:type="MailHost">
        <DesktopFormFactor>
          <!-- ZWEI Erweiterungspunkte, weil Outlook Lese- und Verfassen-Modus
               getrennt bedient. Nur MessageReadCommandSurface zu nennen wäre
               der häufige Halbbau: das Pane erschiene beim Lesen und wäre beim
               Antworten unauffindbar — obwohl `insert_text` genau dort wirkt. -->
          <ExtensionPoint xsi:type="MessageReadCommandSurface">
            <OfficeTab id="TabDefault">
              <Group id="PriviqGroupRead">
                <Label resid="PriviqGroup.Label" />
                <Control xsi:type="Button" id="PriviqReadButton">
                  <Label resid="TaskpaneButton.Label" />
                  <Supertip>
                    <Title resid="TaskpaneButton.Label" />
                    <Description resid="TaskpaneButton.Tooltip" />
                  </Supertip>
                  <Icon>
                    <bt:Image size="16" resid="Icon.16x16" />
                    <bt:Image size="32" resid="Icon.32x32" />
                    <bt:Image size="80" resid="Icon.80x80" />
                  </Icon>
                  <Action xsi:type="ShowTaskpane">
                    <SourceLocation resid="Taskpane.Url" />
                  </Action>
                </Control>
              </Group>
            </OfficeTab>
          </ExtensionPoint>

          <ExtensionPoint xsi:type="MessageComposeCommandSurface">
            <OfficeTab id="TabDefault">
              <Group id="PriviqGroupCompose">
                <Label resid="PriviqGroup.Label" />
                <Control xsi:type="Button" id="PriviqComposeButton">
                  <Label resid="TaskpaneButton.Label" />
                  <Supertip>
                    <Title resid="TaskpaneButton.Label" />
                    <Description resid="TaskpaneButton.Tooltip" />
                  </Supertip>
                  <Icon>
                    <bt:Image size="16" resid="Icon.16x16" />
                    <bt:Image size="32" resid="Icon.32x32" />
                    <bt:Image size="80" resid="Icon.80x80" />
                  </Icon>
                  <Action xsi:type="ShowTaskpane">
                    <SourceLocation resid="Taskpane.Url" />
                  </Action>
                </Control>
              </Group>
            </OfficeTab>
          </ExtensionPoint>
        </DesktopFormFactor>
      </Host>
    </Hosts>

    <Resources>
      <bt:Images>
        <bt:Image id="Icon.16x16" DefaultValue="https://outlook.priviq.ai/assets/priviq-logo-16.png" />
        <bt:Image id="Icon.32x32" DefaultValue="https://outlook.priviq.ai/assets/priviq-logo-32.png" />
        <bt:Image id="Icon.80x80" DefaultValue="https://outlook.priviq.ai/assets/priviq-logo-80.png" />
      </bt:Images>
      <bt:Urls>
        <bt:Url id="Taskpane.Url" DefaultValue="https://outlook.priviq.ai/taskpane.html">
          <bt:Override Locale="en-US" Value="https://outlook.priviq.ai/taskpane.html" />
        </bt:Url>
      </bt:Urls>
      <bt:ShortStrings>
        <bt:String id="PriviqGroup.Label" DefaultValue="Priviq AI">
          <bt:Override Locale="en-US" Value="Priviq AI" />
        </bt:String>
        <bt:String id="TaskpaneButton.Label" DefaultValue="Outlook-Agent">
          <bt:Override Locale="en-US" Value="Outlook Agent" />
        </bt:String>
      </bt:ShortStrings>
      <bt:LongStrings>
        <bt:String id="TaskpaneButton.Tooltip" DefaultValue="Öffne den Priviq Outlook Agent für die Arbeit an dieser Nachricht">
          <bt:Override Locale="en-US" Value="Open the Priviq Outlook Agent to work on this message" />
        </bt:String>
      </bt:LongStrings>
    </Resources>

    <!-- VersionOverridesV1_1 als LETZTES Kind des V1_0 — die von Microsoft
         vorgeschriebene Verschachtelung, nicht eine Geschmacksfrage:
         „when a mail VersionOverrides with version 1.1 is used, it must be the
         last child of a parent VersionOverrides of type 1.0".

         DER INHALT IST WIEDERHOLT, NICHT GEERBT. Microsoft: „The child
         VersionOverrides element doesn't inherit any values from the parent."
         Wer hier kürzt, bekommt auf jedem Client, der V1_1 versteht — also auf
         jedem aktuellen —, ein Add-in ohne Schaltfläche.

         WOFÜR ÜBERHAUPT V1_1: es ist das Schema, das anheftbare Panes
         (SupportsPinning), den Mobil-Formfaktor und die neueren
         Erweiterungspunkte trägt. Es jetzt zu setzen kostet diese Wiederholung
         und erspart später eine Manifest-Änderung — und eine Manifest-Änderung
         kostet laut Root-CLAUDE.md einen Admin-Zyklus von 24–72 Stunden. -->
    <VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides/1.1" xsi:type="VersionOverridesV1_1">
      <Hosts>
        <Host xsi:type="MailHost">
          <DesktopFormFactor>
            <ExtensionPoint xsi:type="MessageReadCommandSurface">
              <OfficeTab id="TabDefault">
                <Group id="PriviqGroupRead">
                  <Label resid="PriviqGroup.Label" />
                  <Control xsi:type="Button" id="PriviqReadButton">
                    <Label resid="TaskpaneButton.Label" />
                    <Supertip>
                      <Title resid="TaskpaneButton.Label" />
                      <Description resid="TaskpaneButton.Tooltip" />
                    </Supertip>
                    <Icon>
                      <bt:Image size="16" resid="Icon.16x16" />
                      <bt:Image size="32" resid="Icon.32x32" />
                      <bt:Image size="80" resid="Icon.80x80" />
                    </Icon>
                    <Action xsi:type="ShowTaskpane">
                      <SourceLocation resid="Taskpane.Url" />
                      <!-- Das Pane bleibt beim Wechsel der Nachricht offen.
                           SupportsPinning ist Mailbox 1.5 — also genau die
                           Untergrenze, die dieses Manifest ohnehin fordert, und
                           damit gratis.

                           DAS HAT EINE FOLGE FÜR DEN CODE, und sie ist der
                           Grund, warum `holeMailElement()` `null` sauber
                           behandelt: bei einem angehefteten Pane KANN
                           `Office.context.mailbox.item` null sein, wenn der
                           Nutzer die Auswahl aufhebt. Microsoft nennt genau
                           diesen Fall bei `Office.Mailbox.item`. -->
                      <SupportsPinning>true</SupportsPinning>
                    </Action>
                  </Control>
                </Group>
              </OfficeTab>
            </ExtensionPoint>

            <ExtensionPoint xsi:type="MessageComposeCommandSurface">
              <OfficeTab id="TabDefault">
                <Group id="PriviqGroupCompose">
                  <Label resid="PriviqGroup.Label" />
                  <Control xsi:type="Button" id="PriviqComposeButton">
                    <Label resid="TaskpaneButton.Label" />
                    <Supertip>
                      <Title resid="TaskpaneButton.Label" />
                      <Description resid="TaskpaneButton.Tooltip" />
                    </Supertip>
                    <Icon>
                      <bt:Image size="16" resid="Icon.16x16" />
                      <bt:Image size="32" resid="Icon.32x32" />
                      <bt:Image size="80" resid="Icon.80x80" />
                    </Icon>
                    <Action xsi:type="ShowTaskpane">
                      <SourceLocation resid="Taskpane.Url" />
                    </Action>
                  </Control>
                </Group>
              </OfficeTab>
            </ExtensionPoint>
          </DesktopFormFactor>
        </Host>
      </Hosts>

      <Resources>
        <bt:Images>
          <bt:Image id="Icon.16x16" DefaultValue="https://outlook.priviq.ai/assets/priviq-logo-16.png" />
          <bt:Image id="Icon.32x32" DefaultValue="https://outlook.priviq.ai/assets/priviq-logo-32.png" />
          <bt:Image id="Icon.80x80" DefaultValue="https://outlook.priviq.ai/assets/priviq-logo-80.png" />
        </bt:Images>
        <bt:Urls>
          <bt:Url id="Taskpane.Url" DefaultValue="https://outlook.priviq.ai/taskpane.html">
            <bt:Override Locale="en-US" Value="https://outlook.priviq.ai/taskpane.html" />
          </bt:Url>
        </bt:Urls>
        <bt:ShortStrings>
          <bt:String id="PriviqGroup.Label" DefaultValue="Priviq AI">
            <bt:Override Locale="en-US" Value="Priviq AI" />
          </bt:String>
          <bt:String id="TaskpaneButton.Label" DefaultValue="Outlook-Agent">
            <bt:Override Locale="en-US" Value="Outlook Agent" />
          </bt:String>
        </bt:ShortStrings>
        <bt:LongStrings>
          <bt:String id="TaskpaneButton.Tooltip" DefaultValue="Öffne den Priviq Outlook Agent für die Arbeit an dieser Nachricht">
            <bt:Override Locale="en-US" Value="Open the Priviq Outlook Agent to work on this message" />
          </bt:String>
        </bt:LongStrings>
      </Resources>
    </VersionOverrides>
  </VersionOverrides>
</OfficeApp>
