z230
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
"""_find_kpc_attachments_v0.py — DOČASNÉ: najde e-maily s .kpc přílohou a vypíše obsah."""
|
||||
import sys, base64
|
||||
sys.stdout.reconfigure(encoding="utf-8")
|
||||
import msal, requests
|
||||
|
||||
TENANT="7d269944-37a4-43a1-8140-c7517dc426e9"; CID="4b222bfd-78c9-4239-a53f-43006b3ed07f"
|
||||
SECRET="Txg8Q~MjhocuopxsJyJBhPmDfMxZ2r5WpTFj1dfk"
|
||||
mailbox = sys.argv[1] if len(sys.argv) > 1 else "vladimir.buzalka@buzalka.cz"
|
||||
BASE=f"https://graph.microsoft.com/v1.0/users/{mailbox}"
|
||||
|
||||
app=msal.ConfidentialClientApplication(CID,authority=f"https://login.microsoftonline.com/{TENANT}",client_credential=SECRET)
|
||||
tok=app.acquire_token_for_client(scopes=["https://graph.microsoft.com/.default"])
|
||||
H={"Authorization":f"Bearer {tok['access_token']}"}
|
||||
HS=dict(H); HS["ConsistencyLevel"]="eventual"
|
||||
|
||||
# hledej e-maily zmiňující kpc (subject/body/příloha)
|
||||
r=requests.get(f"{BASE}/messages",headers=HS,params={
|
||||
"$search":'"kpc"',"$top":50,
|
||||
"$select":"id,subject,from,receivedDateTime,hasAttachments"},timeout=40)
|
||||
if not r.ok:
|
||||
print("search ERR",r.status_code,r.text[:300]); sys.exit(1)
|
||||
msgs=[m for m in r.json().get("value",[]) if m.get("hasAttachments")]
|
||||
print(f"[{mailbox}] e-mailů (search kpc) s přílohou: {len(msgs)}\n")
|
||||
|
||||
found=0
|
||||
for m in msgs:
|
||||
ra=requests.get(f"{BASE}/messages/{m['id']}/attachments",headers=H,
|
||||
params={"$select":"id,name,size,contentType"},timeout=30)
|
||||
if not ra.ok: continue
|
||||
for a in ra.json().get("value",[]):
|
||||
if (a.get("name","") or "").lower().endswith(".kpc"):
|
||||
found+=1
|
||||
frm=m.get("from",{}).get("emailAddress",{}).get("address","")
|
||||
print("="*78)
|
||||
print(f"e-mail: {m.get('receivedDateTime','')[:10]} | od {frm} | {m.get('subject','')[:60]}")
|
||||
print(f"příloha: {a.get('name')} ({a.get('size')} B)")
|
||||
full=requests.get(f"{BASE}/messages/{m['id']}/attachments/{a['id']}",headers=H,timeout=30).json()
|
||||
cb=full.get("contentBytes")
|
||||
if cb:
|
||||
raw=base64.b64decode(cb)
|
||||
for enc in ("cp1250","utf-8","latin-1"):
|
||||
try: txt=raw.decode(enc); break
|
||||
except: txt=None
|
||||
print("--- OBSAH ---")
|
||||
print(txt if txt else repr(raw[:400]))
|
||||
print(f"\nCelkem .kpc příloh: {found}")
|
||||
Reference in New Issue
Block a user