Fix Mail Maildir paths and oCIS auth
Mail: INBOX is a subfolder (INBOX/cur), not the account root. Removed special-case mapping that pointed INBOX to root dir. Files: oCIS user may differ from MCP user (e.g. stefan -> admin). Added _ocis_user() mapping for WebDAV paths and auth. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
+6
-2
@@ -22,8 +22,12 @@ OCIS_CREDS = {u: (d['username'], d['password']) for u, d in _cfg['ocis_users'].i
|
|||||||
mcp = FastMCP("Files", stateless_http=True,
|
mcp = FastMCP("Files", stateless_http=True,
|
||||||
transport_security={"enable_dns_rebinding_protection": False})
|
transport_security={"enable_dns_rebinding_protection": False})
|
||||||
|
|
||||||
|
def _ocis_user(u):
|
||||||
|
c = OCIS_CREDS.get(u)
|
||||||
|
return c[0] if c else u
|
||||||
|
|
||||||
def _auth(u): c = OCIS_CREDS.get(u); return httpx.BasicAuth(c[0], c[1]) if c else None
|
def _auth(u): c = OCIS_CREDS.get(u); return httpx.BasicAuth(c[0], c[1]) if c else None
|
||||||
def _dav(u, p=""): return f"{OCIS}/remote.php/dav/files/{u}/{p.lstrip('/')}"
|
def _dav(u, p=""): return f"{OCIS}/remote.php/dav/files/{_ocis_user(u)}/{p.lstrip('/')}"
|
||||||
|
|
||||||
def _propfind(user, path="", depth=1):
|
def _propfind(user, path="", depth=1):
|
||||||
body = '<?xml version="1.0"?><d:propfind xmlns:d="DAV:"><d:prop><d:resourcetype/><d:displayname/><d:getcontentlength/><d:getlastmodified/><d:getcontenttype/></d:prop></d:propfind>'
|
body = '<?xml version="1.0"?><d:propfind xmlns:d="DAV:"><d:prop><d:resourcetype/><d:displayname/><d:getcontentlength/><d:getlastmodified/><d:getcontenttype/></d:prop></d:propfind>'
|
||||||
@@ -35,7 +39,7 @@ def _parse_pf(xml, user):
|
|||||||
entries = []
|
entries = []
|
||||||
try: root = ET.fromstring(xml)
|
try: root = ET.fromstring(xml)
|
||||||
except: return entries
|
except: return entries
|
||||||
bp = f"/remote.php/dav/files/{user}/"
|
bp = f"/remote.php/dav/files/{_ocis_user(user)}/"
|
||||||
for resp in root.findall("d:response", ns):
|
for resp in root.findall("d:response", ns):
|
||||||
href = resp.findtext("d:href", "", ns) or ""
|
href = resp.findtext("d:href", "", ns) or ""
|
||||||
rel = href.split(bp, 1)[-1].rstrip("/") if bp in href else href.rstrip("/")
|
rel = href.split(bp, 1)[-1].rstrip("/") if bp in href else href.rstrip("/")
|
||||||
|
|||||||
+5
-4
@@ -87,15 +87,16 @@ def _discover_folders(acct_path):
|
|||||||
folders = []
|
folders = []
|
||||||
for entry in sorted(Path(acct_path).rglob("cur")):
|
for entry in sorted(Path(acct_path).rglob("cur")):
|
||||||
rel = str(entry.parent.relative_to(acct_path))
|
rel = str(entry.parent.relative_to(acct_path))
|
||||||
if rel == ".":
|
if rel != "." and rel not in folders:
|
||||||
folders.insert(0, "INBOX")
|
|
||||||
elif rel not in folders:
|
|
||||||
folders.append(rel)
|
folders.append(rel)
|
||||||
|
if "INBOX" in folders:
|
||||||
|
folders.remove("INBOX")
|
||||||
|
folders.insert(0, "INBOX")
|
||||||
return folders
|
return folders
|
||||||
|
|
||||||
|
|
||||||
def _open_folder(acct_path, folder_name):
|
def _open_folder(acct_path, folder_name):
|
||||||
path = acct_path if folder_name == "INBOX" else os.path.join(acct_path, folder_name)
|
path = os.path.join(acct_path, folder_name)
|
||||||
return mailbox.Maildir(path, create=False) if os.path.isdir(path) else None
|
return mailbox.Maildir(path, create=False) if os.path.isdir(path) else None
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user