feat: filter WebDAV files by creation/modified date instead of folders

Use PROPFIND creationdate with getlastmodified fallback so min year 2025 applies by file date, not folder names.
This commit is contained in:
1sonhador committed 2026-07-02 23:13:31 +01:00
1 parent 1617be3aee
commit d561de7d02
4 files changed
+102 -33

No files matched your search

+28 -8
View File
@@ -2,12 +2,14 @@
from forwarder.webdav.client import (
WebdavConfig,
WebdavFile,
_parse_propfind_response,
build_webdav_root,
get_webdav_message_key,
normalize_webdav_folder_path,
parse_webdav_message_key,
webdav_path_matches_min_year,
webdav_file_matches_min_year,
webdav_file_reference_date,
)
PROPFIND_SAMPLE = b"""<?xml version="1.0" encoding="utf-8"?>
@@ -26,6 +28,7 @@ PROPFIND_SAMPLE = b"""<?xml version="1.0" encoding="utf-8"?>
<D:prop>
<D:getetag>"abc123"</D:getetag>
<D:getlastmodified>Mon, 01 Jan 2024 10:00:00 GMT</D:getlastmodified>
<D:creationdate>2024-01-01T10:00:00Z</D:creationdate>
<D:getcontentlength>12345</D:getcontentlength>
<D:resourcetype/>
</D:prop>
@@ -36,6 +39,7 @@ PROPFIND_SAMPLE = b"""<?xml version="1.0" encoding="utf-8"?>
<D:propstat>
<D:prop>
<D:getetag>"def456"</D:getetag>
<D:getlastmodified>Mon, 15 Jun 2025 12:00:00 GMT</D:getlastmodified>
<D:getcontentlength>999</D:getcontentlength>
<D:resourcetype/>
</D:prop>
@@ -72,13 +76,25 @@ def test_webdav_message_key_roundtrip():
assert parse_webdav_message_key("imap:123") is None
def test_webdav_path_matches_min_year():
assert webdav_path_matches_min_year("2025/invoice.pdf", 2025)
assert webdav_path_matches_min_year("Faturas/2026/08/a.pdf", 2025)
assert webdav_path_matches_min_year("Faturas/2027/future.pdf", 2025)
assert not webdav_path_matches_min_year("Faturas/2024/old.pdf", 2025)
assert not webdav_path_matches_min_year("misc/file.pdf", 2025)
assert webdav_path_matches_min_year("2024/old.pdf", None)
def _sample_file(*, modified: str = "", created: str = "", path: str = "a.pdf") -> WebdavFile:
return WebdavFile(
relative_path=path,
name="a.pdf",
href="/a.pdf",
etag="1",
modified=modified,
created=created,
size=100,
)
def test_webdav_file_matches_min_year_by_creation_date():
old = _sample_file(created="2024-06-01T10:00:00Z", modified="Mon, 01 Jan 2026 10:00:00 GMT")
assert webdav_file_reference_date(old).year == 2024
assert not webdav_file_matches_min_year(old, 2025)
recent = _sample_file(modified="Mon, 15 Jun 2025 12:00:00 GMT")
assert webdav_file_matches_min_year(recent, 2025)
def test_parse_propfind_response():
@@ -90,3 +106,7 @@ def test_parse_propfind_response():
assert invoice.relative_path == "invoice.pdf"
assert invoice.etag == "abc123"
assert invoice.size == 12345
assert invoice.created == "2024-01-01T10:00:00Z"
assert not webdav_file_matches_min_year(invoice, 2025)
photo = next(item for item in files if item.name == "photo.jpg")
assert webdav_file_matches_min_year(photo, 2025)