Files
mcp-home/tests/testdata/gen_maildir.py
T
Stefan Lohmaier 5f3181b162 test: umfangreiche Testdaten (alle Dateitypen + Mail-Anhaenge)
- oCIS /testdata/: Bilder (jpg/png/webp/bmp/gif/tiff/svg), Audio (mp3/ogg/m4a/
  flac/wav), Video (mp4), PDFs (Text + Scan), Office (docx/xlsx/pptx), Text/Daten
  (md/txt/csv/json/xml/yaml/html/py/vcf/ics), Archive (zip/tar.gz).
- Maildir: Mails mit diversen Anhaengen (PDF/Bild/Word/Excel/MP3/MP4/PPTX/ZIP).
- TestFileTypes: read_file je Typ -> Content-Typ pruefen (image/text/resource).
- Generatoren tests/testdata/gen_testfiles.py + gen_maildir.py + upload_ocis.sh.
68 Tests gruen (vorher 54). Doku in MCPTEST.md.
2026-06-19 07:56:08 +02:00

57 lines
3.0 KiB
Python

import mailbox, os, shutil
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.base import MIMEBase
from email.mime.image import MIMEImage
from email.mime.audio import MIMEAudio
from email import encoders
BASE="/opt/mcp-servers/tests/testdata/maildir"
SRC="/tmp/mcptest-files"
if os.path.isdir(BASE): shutil.rmtree(BASE)
def add(acct, folder, msg):
path=os.path.join(BASE,acct,folder); os.makedirs(os.path.dirname(path),exist_ok=True)
mailbox.Maildir(path,create=True).add(msg)
def simple(frm,to,subj,body):
m=MIMEText(body,"plain","utf-8"); m["From"]=frm; m["To"]=to; m["Subject"]=subj
m["Date"]="Mon, 16 Jun 2026 09:00:00 +0200"; return m
def attach(part, fn):
p=os.path.join(SRC,fn); data=open(p,"rb").read()
part.add_header("Content-Disposition","attachment",filename=fn)
return part
def mail_with(frm,subj,body,files,date="Tue, 17 Jun 2026 10:00:00 +0200"):
m=MIMEMultipart(); m["From"]=frm; m["To"]="mcptest@local"; m["Subject"]=subj; m["Date"]=date
m.attach(MIMEText(body,"plain","utf-8"))
for fn in files:
data=open(os.path.join(SRC,fn),"rb").read()
part=MIMEBase("application","octet-stream"); part.set_payload(data); encoders.encode_base64(part)
part.add_header("Content-Disposition","attachment",filename=fn)
m.attach(part)
return m
# Basis-Mails (Suche/Read)
add("mcp-test-mail","INBOX", simple("test@example.com","mcptest@local","Willkommen","Hallo, dies ist eine Testnachricht fuer stefan zum Suchen."))
add("mcp-test-mail","Sent", simple("mcptest@local","kunde@example.com","Re: Angebot","Danke fuer Ihre Anfrage."))
add("mcp-test-empty","INBOX",simple("noreply@example.com","mcptest@local","Newsletter","Nichts besonderes hier."))
# Mails mit Anhaengen (verschiedene Typen)
add("mcp-test-mail","INBOX", mail_with("billing@example.com","Ihre Rechnung Juni 2026","Im Anhang die Rechnung (Text-PDF) und der Scan (Bild-PDF).",["document.pdf","scanned.pdf"]))
add("mcp-test-mail","INBOX", mail_with("foto@example.com","Fotos vom Wochenende","Anbei zwei Bilder.",["photo.jpg","screenshot.png"]))
add("mcp-test-mail","INBOX", mail_with("buero@example.com","Quartalsbericht Q2","Bericht (Word) und Zahlen (Excel) anbei.",["report.docx","budget.xlsx"]))
add("mcp-test-mail","INBOX", mail_with("voice@example.com","Sprachnachricht","Kurze Audionachricht im Anhang.",["tone.mp3"]))
add("mcp-test-mail","INBOX", mail_with("projekt@example.com","Projektdateien","Archiv und Notizen.",["archive.zip","notes.txt","data.csv"]))
add("mcp-test-mail","INBOX", mail_with("media@example.com","Praesentation + Clip","Folien und ein kurzes Video.",["slides.pptx","clip.mp4"]))
# new -> cur
for r,d,f in os.walk(BASE):
if r.endswith("new"):
for x in list(f):
os.rename(os.path.join(r,x), os.path.join(os.path.dirname(r),"cur",x+":2,S"))
print("Maildir neu gebaut.")
for r,d,f in os.walk(BASE):
if r.endswith("cur"): print(f" {r.replace(BASE+'/',''):30} {len(f)} msgs")