0
  5   ˆl–Ü4ý( ©¤ýÔâ€jàCp-)‹Fÿ�þB gôŒ�±¶_çÂƒh¹ÁÀ¿      1
  5   ˆl–äY>”Êi?u8 EpOÜJbÑ¿�þZh«8à žFÐüÿÃƒ@/ÂÁÀ N    The Debian stable security team does not provide security support for
certain configurations known to be inherently insecure. This includes
the interpreter itself, extensions, and user scripts written in the PHP
language. Most specifically, but not exclusively, the security team will
not provide support for the following.

 * Security issues which are caused by careless programming, such as:
   - extracting a tar file without first checking the contents;
   - using unserialize() on untrusted data;
   - relying on a specific value of short_open_tag.

 * Vulnerabilities involving any kind of open_basedir violation, as
   this feature is not considered a security model either by us or by
   PHP upstream.

 * Any "works as expected" vulnerabilities, such as "user can cause
   PHP to crash by writing a malicious PHP script", unless such
   vulnerabilities involve some kind of higher-level DoS or privilege
   escalation that would not otherwise be available.

PHP upstream has published a statement regarding their view on security
and the PHP interpreter:
http://www.php.net/security-note.php
  N   ˆl–Ü4ý( ©¤ýÔâ€jàž¸Ë*bÑ¿‘äÇò 8àFÊ0¹üÿÄƒh¹Ãa–Ü4ý( ©¤ýÔâ€jàž¸Ë*bÑ¿Â      0
  C   	ˆl–ß=¿J¥2ÛB‚ „ �pM\ŠbÑ¿�þZu—–l¬‘ñÊðc üÿÆ„Âd_Å_ŠI|¥�+Wé3ž¯ÀÄ ?÷     	# This file is part of Radicale - CalDAV and CardDAV server
# Copyright Â© 2008 Nicolas Kandel
# Copyright Â© 2008 Pascal Halter
# Copyright Â© 2014 Jean-Marc Martins
# Copyright Â© 2008-2017 Guillaume Ayoub
# Copyright Â© 2017-2018 Unrud <unrud@outlook.com>
#
# This library is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Radicale.  If not, see <http://www.gnu.org/licenses/>.

"""
Module for address books and calendar entries (see ``Item``).

"""

import binascii
import contextlib
import math
import os
import re
from datetime import datetime, timedelta
from hashlib import sha256
from itertools import chain
from typing import (Any, Callable, List, MutableMapping, Optional, Sequence,
                    Tuple)

import vobject

from radicale import storage  # noqa:F401
from radicale import pathutils
from radicale.item import filter as radicale_filter
from radicale.log import logger


def read_components(s: str) -> List[vobject.base.Component]:
    """Wrapper for vobject.readComponents"""
    # Workaround for bug in InfCloud
    # PHOTO is a data URI
    s = re.sub(r"^(PHOTO(?:;[^:\r\n]*)?;ENCODING=b(?:;[^:\r\n]*)?:)"
               r"data:[^;,\r\n]*;base64,", r"\1", s,
               flags=re.MULTILINE | re.IGNORECASE)
    return list(vobject.readComponents(s))


def predict_tag_of_parent_collection(
        vobject_items: Sequence[vobject.base.Component]) -> Optional[str]:
    """Returns the predicted tag or `None`"""
    if len(vobject_items) != 1:
        return None
    if vobject_items[0].name == "VCALENDAR":
        return "VCALENDAR"
    if vobject_items[0].name in ("VCARD", "VLIST"):
        return "VADDRESSBOOK"
    return None


def predict_tag_of_whole_collection(
        vobject_items: Sequence[vobject.base.Component],
        fallback_tag: Optional[str] = None) -> Optional[str]:
    """Returns the predicted tag or `fallback_tag`"""
    if vobject_items and vobject_items[0].name == "VCALENDAR":
        return "VCALENDAR"
    if vobject_items and vobject_items[0].name in ("VCARD", "VLIST"):
        return "VADDRESSBOOK"
    if not fallback_tag and not vobject_items:
        # Maybe an empty address book
    