diff --git a/.claude/settings.local.json b/.claude/settings.local.json index caabf9b..af8a53c 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -2,7 +2,11 @@ "permissions": { "allow": [ "Bash(powershell.exe -ExecutionPolicy Bypass -File scripts/Process-MailRules.ps1)", - "Bash(powershell.exe -ExecutionPolicy Bypass -File scripts/Process-MailRules.ps1 -DryRun)" + "Bash(powershell.exe -ExecutionPolicy Bypass -File scripts/Process-MailRules.ps1 -DryRun)", + "Bash(powershell.exe -Command \"Get-ChildItem ''C:\\\\Users\\\\d-chrka\\\\Documents\\\\projects\\\\mail-organizer\\\\logs\\\\protocols\\\\'' -Filter ''run_*.json'' | Select-Object Name\")", + "Bash(powershell.exe -File:*)", + "Bash(node -e:*)", + "Bash(node:*)" ] } } diff --git a/config/rules.json b/config/rules.json index 77c79e0..3ea1481 100644 --- a/config/rules.json +++ b/config/rules.json @@ -52,8 +52,7 @@ "match": { "from": "*@datacenter-group.com", "subject": "Wartungsbericht*", - "hasAttachment": true, - "unreadOnly": false + "hasAttachment": true }, "actions": { @@ -70,6 +69,23 @@ "moveToFolder": "archive" } } + }, + { + "id": "feldmann-fi-rechnung-loeschen", + "enabled": true, + "name": "Feldmann FI-Rechnung Erinnerungen loeschen", + "description": "Automatische Erinnerungen von M. Feldmann zu FI Rechnungen in den Papierkorb verschieben", + + "match": { + "subject": "M. Feldmann: Bitte denken Sie an FI Rechnung*" + }, + + "actions": { + "onSuccess": { + "markAsRead": true, + "moveToFolder": "deleteditems" + } + } } ] } diff --git a/scripts/Generate-ProtocolHtml.ps1 b/scripts/Generate-ProtocolHtml.ps1 new file mode 100644 index 0000000..7e063c8 --- /dev/null +++ b/scripts/Generate-ProtocolHtml.ps1 @@ -0,0 +1,167 @@ +param( + [Parameter(Mandatory)][string]$JsonData, + [Parameter(Mandatory)][string]$OutputPath +) + +# Escape for safe embedding in JS string literal +$escaped = $JsonData -replace '\\', '\\\\' -replace "'", "\\\'" -replace "`r`n", '\n' -replace "`n", '\n' + +$html = @' + +Mail-Organizer Protokoll + +

Mail-Organizer Protokoll

+
+
+
+
+ +'@ + +# Write without BOM +$utf8NoBom = New-Object System.Text.UTF8Encoding $false +[System.IO.File]::WriteAllText($OutputPath, $html, $utf8NoBom) diff --git a/scripts/GraphHelper.psm1 b/scripts/GraphHelper.psm1 index b5a891b..5b9040c 100644 --- a/scripts/GraphHelper.psm1 +++ b/scripts/GraphHelper.psm1 @@ -116,7 +116,7 @@ function Get-MailMessages { ) $user = $Settings.MailboxUser - $endpoint = "/users/$user/messages?`$top=$Top&`$orderby=receivedDateTime desc" + $endpoint = "/users/$user/mailFolders/inbox/messages?`$top=$Top&`$orderby=receivedDateTime desc" $endpoint += "&`$select=id,subject,from,receivedDateTime,categories,hasAttachments,isRead,body" if ($UnreadOnly) { diff --git a/scripts/Process-MailRules.ps1 b/scripts/Process-MailRules.ps1 index b1b4bcf..9f45541 100644 --- a/scripts/Process-MailRules.ps1 +++ b/scripts/Process-MailRules.ps1 @@ -457,4 +457,16 @@ $protocolFile = Join-Path $protocolDir "run_$($runTimestamp.ToString('yyyy-MM-dd $protocol | ConvertTo-Json -Depth 10 | Set-Content -Path $protocolFile -Encoding UTF8 Write-Log "Protokoll geschrieben: $protocolFile" -Level Info +# --- HTML-Gesamtprotokoll generieren --- +$allProtocols = @() +Get-ChildItem -Path $protocolDir -Filter "run_*.json" | Sort-Object Name -Descending | ForEach-Object { + $content = Get-Content $_.FullName -Raw -Encoding UTF8 + $allProtocols += $content +} +$jsonArray = "[" + ($allProtocols -join ",") + "]" + +$htmlFile = Join-Path (Split-Path $protocolDir -Parent) "protocol.html" +& (Join-Path $scriptRoot "Generate-ProtocolHtml.ps1") -JsonData $jsonArray -OutputPath $htmlFile +Write-Log "HTML-Protokoll aktualisiert: $htmlFile" -Level Info + Write-Log "=== Fertig: $totalProcessed E-Mail(s) verarbeitet, $totalAlerts Alert(s), $totalErrors Fehler ==="