Skip to content

Commit 2e6a213

Browse files
Add remove_details option
1 parent 82fd03b commit 2e6a213

File tree

4 files changed

+42
-6
lines changed

4 files changed

+42
-6
lines changed

vdirsyncer/cli/config.py

+3
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,9 @@ def __init__(self, full_config: Config, name: str, options: dict[str, str]):
237237
options.pop("conflict_resolution", None)
238238
)
239239

240+
self.required_attendee = options.pop("required_attendee", None)
241+
self.remove_details = options.pop("remove_details", False)
242+
240243
try:
241244
self.collections = options.pop("collections")
242245
except KeyError:

vdirsyncer/cli/tasks.py

+1
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ def error_callback(e):
7979
force_delete=force_delete,
8080
error_callback=error_callback,
8181
partial_sync=pair.partial_sync,
82+
remove_details=pair.remove_details,
8283
)
8384

8485
if sync_failed:

vdirsyncer/sync/__init__.py

+6-3
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ def __init__(self, storage: Storage, status: SubStatus):
4141
self.status = status
4242
self._item_cache = {} # type: ignore[var-annotated]
4343

44-
async def prepare_new_status(self) -> bool:
44+
async def prepare_new_status(self, remove_details: bool = False) -> bool:
4545
storage_nonempty = False
4646
prefetch = []
4747

@@ -66,6 +66,8 @@ def _store_props(ident: str, props: ItemMetadata) -> None:
6666
# Prefetch items
6767
if prefetch:
6868
async for href, item, etag in self.storage.get_multi(prefetch):
69+
if remove_details:
70+
item = item.without_details()
6971
_store_props(
7072
item.ident,
7173
ItemMetadata(href=href, hash=item.hash, etag=etag),
@@ -104,6 +106,7 @@ async def sync(
104106
force_delete=False,
105107
error_callback=None,
106108
partial_sync="revert",
109+
remove_details: bool=False,
107110
) -> None:
108111
"""Synchronizes two storages.
109112
@@ -145,8 +148,8 @@ async def sync(
145148
a_info = _StorageInfo(storage_a, SubStatus(status, "a"))
146149
b_info = _StorageInfo(storage_b, SubStatus(status, "b"))
147150

148-
a_nonempty = await a_info.prepare_new_status()
149-
b_nonempty = await b_info.prepare_new_status()
151+
a_nonempty = await a_info.prepare_new_status(remove_details=remove_details)
152+
b_nonempty = await b_info.prepare_new_status(remove_details=remove_details)
150153

151154
if status_nonempty and not force_delete:
152155
if a_nonempty and not b_nonempty:

vdirsyncer/vobject.py

+32-3
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,35 @@ def with_uid(self, new_uid):
5858

5959
return Item("\r\n".join(parsed.dump_lines()))
6060

61+
def without_details(self):
62+
"""Returns a minimal version of this item.
63+
64+
Filters out data to reduce content size and hide private details:
65+
* Description
66+
* Location
67+
* Organizer
68+
* Attendees list
69+
* Redundant timezone data (actual timezone of event is preserved)
70+
"""
71+
parsed = _Component.parse(self.raw)
72+
stack = [parsed]
73+
while stack:
74+
component = stack.pop()
75+
76+
component.subcomponents = [
77+
subcomp for subcomp
78+
in component.subcomponents
79+
if subcomp.name != "VTIMEZONE"
80+
]
81+
for field in ["DESCRIPTION", "ORGANIZER", "ATTENDEE", "LOCATION"]:
82+
# Repeatedly delete because some fields can appear multiple times
83+
while field in component:
84+
del component[field]
85+
86+
stack.extend(component.subcomponents)
87+
88+
return Item("\r\n".join(parsed.dump_lines()))
89+
6190
@cached_property
6291
def raw(self):
6392
"""Raw content of the item, as unicode string.
@@ -241,9 +270,9 @@ class _Component:
241270
Raw outline of the components.
242271
243272
Vdirsyncer's operations on iCalendar and VCard objects are limited to
244-
retrieving the UID and splitting larger files into items. Consequently this
245-
parser is very lazy, with the downside that manipulation of item properties
246-
are extremely costly.
273+
retrieving the UID, removing fields, and splitting larger files into items.
274+
Consequently this parser is very lazy, with the downside that manipulation
275+
of item properties are extremely costly.
247276
248277
Other features:
249278

0 commit comments

Comments
 (0)