feat: target running Outlook PWA instance directly via app-id shortcut

This commit is contained in:
kdeterme 2026-09-04 09:36:27 +02:00
parent 946cbcae91
commit a1f8b4412e

View file

@ -29,6 +29,10 @@ import webbrowser
from pathlib import Path
import re
from typing import Optional
def find_chromium_cmd() -> list:
"""Détecte la commande Chromium disponible pour ouvrir la session PWA sous Ubuntu."""
candidates = [
@ -40,11 +44,26 @@ def find_chromium_cmd() -> list:
]
for cmd in candidates:
if shutil.which(cmd):
# Vérifier si on peut ajouter le profil Default
return [cmd, "--profile-directory=Default"]
return []
def find_pwa_app_id() -> Optional[str]:
"""Recherche l'App-ID de la PWA Outlook dans ~/.local/share/applications/"""
app_dir = Path.home() / ".local" / "share" / "applications"
if app_dir.exists():
for desktop_file in app_dir.glob("*outlook*.desktop"):
try:
content = desktop_file.read_text(encoding="utf-8")
match = re.search(r"--app-id=([a-zA-Z0-9]+)", content)
if match:
return match.group(1)
except Exception:
continue
# Fallback sur l'App ID standard Outlook PWA Chromium
return "eoficlgicibekocmfdomjbfnjmehnhcd"
def create_eml_draft(to_email: str, subject: str, body: str, output_path: Path):
"""Génère un fichier .eml standard marqué comme brouillon (X-Unsent: 1)."""
msg = email.message.EmailMessage()
@ -152,7 +171,12 @@ def main():
# Mode PWA (Défaut)
chromium_cmd = find_chromium_cmd()
if chromium_cmd:
pwa_app_id = find_pwa_app_id()
if chromium_cmd and pwa_app_id:
print(f"Session PWA Outlook détectée (App ID : {pwa_app_id})")
print("Les brouillons vont être envoyés directement dans votre fenêtre Outlook ouverte.")
elif chromium_cmd:
print(f"Navigateur détecté pour la session PWA : {' '.join(chromium_cmd)}")
else:
print("Utilisation du navigateur système par défaut.")
@ -193,8 +217,16 @@ def main():
else:
if chromium_cmd:
try:
if pwa_app_id:
cmd = chromium_cmd + [
f"--app-id={pwa_app_id}",
f"--app-launch-url-for-shortcuts-menu-item={deeplink}",
]
else:
cmd = chromium_cmd + [deeplink]
subprocess.Popen(
chromium_cmd + [deeplink],
cmd,
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
)
@ -203,7 +235,7 @@ def main():
else:
webbrowser.open(deeplink)
print(" -> Brouillon ouvert dans Outlook !")
print(" -> Brouillon ouvert dans votre fenêtre Outlook !")
if not args.step and idx < len(drafts) and not args.dry_run:
time.sleep(args.delay)