mirror of
https://github.com/samsonjs/vdirsyncer.git
synced 2026-03-25 08:55:50 +00:00
parent
6fea4d4201
commit
6ef94e512e
4 changed files with 35 additions and 18 deletions
|
|
@ -25,6 +25,7 @@ fileext = .vcf
|
|||
|
||||
[storage bob_contacts_remote]
|
||||
type = carddav
|
||||
#item_types = VTODO,VEVENT
|
||||
url = https://owncloud.example.com/remote.php/carddav/addressbooks/bob/default/
|
||||
#username = # blabla
|
||||
#password = # blabla
|
||||
|
|
|
|||
|
|
@ -214,11 +214,11 @@ class DavStorage(Storage):
|
|||
)
|
||||
self._check_response(response)
|
||||
|
||||
def list(self):
|
||||
def _list(self, xml):
|
||||
response = self._request(
|
||||
'REPORT',
|
||||
'',
|
||||
data=self.list_xml,
|
||||
data=xml,
|
||||
headers=self._default_headers()
|
||||
)
|
||||
response.raise_for_status()
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ class CaldavStorage(DavStorage):
|
|||
dav_header = 'calendar-access'
|
||||
start_date = None
|
||||
end_date = None
|
||||
item_types = None
|
||||
|
||||
get_multi_template = '''<?xml version="1.0" encoding="utf-8" ?>
|
||||
<C:calendar-multiget xmlns:D="DAV:"
|
||||
|
|
@ -36,12 +37,16 @@ class CaldavStorage(DavStorage):
|
|||
|
||||
get_multi_data_query = '{urn:ietf:params:xml:ns:caldav}calendar-data'
|
||||
|
||||
def __init__(self, start_date=None, end_date=None, **kwargs):
|
||||
def __init__(self, start_date=None, end_date=None,
|
||||
item_types=('VTODO', 'VEVENT'), **kwargs):
|
||||
'''
|
||||
:param start_date: Start date of timerange to show, default -inf.
|
||||
:param end_date: End date of timerange to show, default +inf.
|
||||
'''
|
||||
super(CaldavStorage, self).__init__(**kwargs)
|
||||
if isinstance(item_types, str):
|
||||
item_types = [x.strip() for x in item_types.split(',')]
|
||||
self.item_types = item_types
|
||||
if (start_date is None) != (end_date is None):
|
||||
raise ValueError('If start_date is given, '
|
||||
'end_date has to be given too.')
|
||||
|
|
@ -54,8 +59,9 @@ class CaldavStorage(DavStorage):
|
|||
(eval(end_date, namespace) if isinstance(end_date, str)
|
||||
else end_date)
|
||||
|
||||
@property
|
||||
def list_xml(self):
|
||||
self._list_template = self._get_list_template()
|
||||
|
||||
def _get_list_template(self):
|
||||
data = '''<?xml version="1.0" encoding="utf-8" ?>
|
||||
<C:calendar-query xmlns:D="DAV:"
|
||||
xmlns:C="urn:ietf:params:xml:ns:caldav">
|
||||
|
|
@ -64,7 +70,7 @@ class CaldavStorage(DavStorage):
|
|||
</D:prop>
|
||||
<C:filter>
|
||||
<C:comp-filter name="VCALENDAR">
|
||||
<C:comp-filter name="VTODO">
|
||||
<C:comp-filter name="{component}">
|
||||
{caldavfilter}
|
||||
</C:comp-filter>
|
||||
</C:comp-filter>
|
||||
|
|
@ -72,10 +78,19 @@ class CaldavStorage(DavStorage):
|
|||
</C:calendar-query>'''
|
||||
start = self.start_date
|
||||
end = self.end_date
|
||||
caldavfilter = ''
|
||||
if start is not None and end is not None:
|
||||
start = start.strftime(CALDAV_DT_FORMAT)
|
||||
end = end.strftime(CALDAV_DT_FORMAT)
|
||||
caldavfilter = ('<C:time-range start="{start}" end="{end}"/>'
|
||||
.format(start=start, end=end))
|
||||
return data.format(caldavfilter=caldavfilter)
|
||||
return data.format(caldavfilter='')
|
||||
return data.format(caldavfilter=caldavfilter, component='{item_type}')
|
||||
|
||||
def list(self):
|
||||
hrefs = set()
|
||||
for t in self.item_types:
|
||||
xml = self._list_template.format(item_type=t)
|
||||
for href, etag in self._list(xml):
|
||||
assert href not in hrefs
|
||||
hrefs.add(href)
|
||||
yield href, etag
|
||||
|
|
|
|||
|
|
@ -30,13 +30,14 @@ class CarddavStorage(DavStorage):
|
|||
|
||||
get_multi_data_query = '{urn:ietf:params:xml:ns:carddav}address-data'
|
||||
|
||||
list_xml = '''<?xml version="1.0" encoding="utf-8" ?>
|
||||
<C:addressbook-query xmlns:D="DAV:"
|
||||
xmlns:C="urn:ietf:params:xml:ns:carddav">
|
||||
<D:prop>
|
||||
<D:getetag/>
|
||||
</D:prop>
|
||||
<C:filter>
|
||||
<C:comp-filter name="VCARD"/>
|
||||
</C:filter>
|
||||
</C:addressbook-query>'''
|
||||
def list(self):
|
||||
return self._list('''<?xml version="1.0" encoding="utf-8" ?>
|
||||
<C:addressbook-query xmlns:D="DAV:"
|
||||
xmlns:C="urn:ietf:params:xml:ns:carddav">
|
||||
<D:prop>
|
||||
<D:getetag/>
|
||||
</D:prop>
|
||||
<C:filter>
|
||||
<C:comp-filter name="VCARD"/>
|
||||
</C:filter>
|
||||
</C:addressbook-query>''')
|
||||
|
|
|
|||
Loading…
Reference in a new issue