Skip to content

Commit adc9e5f

Browse files
Add remove_details option
1 parent 055ed12 commit adc9e5f

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
@@ -42,7 +42,7 @@ def __init__(self, storage: Storage, status: SubStatus):
4242
self.status = status
4343
self._item_cache = {} # type: ignore[var-annotated]
4444

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

@@ -67,6 +67,8 @@ def _store_props(ident: str, props: ItemMetadata) -> None:
6767
# Prefetch items
6868
if prefetch:
6969
async for href, item, etag in self.storage.get_multi(prefetch):
70+
if remove_details:
71+
item = item.without_details()
7072
_store_props(
7173
item.ident,
7274
ItemMetadata(href=href, hash=item.hash, etag=etag),
@@ -105,6 +107,7 @@ async def sync(
105107
force_delete=False,
106108
error_callback=None,
107109
partial_sync="revert",
110+
remove_details: bool=False,
108111
) -> None:
109112
"""Synchronizes two storages.
110113
@@ -146,8 +149,8 @@ async def sync(
146149
a_info = _StorageInfo(storage_a, SubStatus(status, "a"))
147150
b_info = _StorageInfo(storage_b, SubStatus(status, "b"))
148151

149-
a_nonempty = await a_info.prepare_new_status()
150-
b_nonempty = await b_info.prepare_new_status()
152+
a_nonempty = await a_info.prepare_new_status(remove_details=remove_details)
153+
b_nonempty = await b_info.prepare_new_status(remove_details=remove_details)
151154

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

vdirsyncer/vobject.py

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

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

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

0 commit comments

Comments
 (0)