1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/imiptools/client.py Wed Mar 25 18:04:26 2015 +0100
1.3 @@ -0,0 +1,57 @@
1.4 +#!/usr/bin/env python
1.5 +
1.6 +"""
1.7 +Common calendar client utilities.
1.8 +
1.9 +Copyright (C) 2014, 2015 Paul Boddie <paul@boddie.org.uk>
1.10 +
1.11 +This program is free software; you can redistribute it and/or modify it under
1.12 +the terms of the GNU General Public License as published by the Free Software
1.13 +Foundation; either version 3 of the License, or (at your option) any later
1.14 +version.
1.15 +
1.16 +This program is distributed in the hope that it will be useful, but WITHOUT
1.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.18 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.19 +details.
1.20 +
1.21 +You should have received a copy of the GNU General Public License along with
1.22 +this program. If not, see <http://www.gnu.org/licenses/>.
1.23 +"""
1.24 +
1.25 +from imiptools.data import uri_items
1.26 +
1.27 +def update_attendees(obj, added, removed):
1.28 +
1.29 + """
1.30 + Update the attendees in 'obj' with the given 'added' and 'removed'
1.31 + attendee lists. A list is returned containing the attendees whose
1.32 + attendance should be cancelled.
1.33 + """
1.34 +
1.35 + to_cancel = []
1.36 +
1.37 + if added or removed:
1.38 + attendees = uri_items(obj.get_items("ATTENDEE") or [])
1.39 +
1.40 + if removed:
1.41 + remaining = []
1.42 +
1.43 + for attendee, attendee_attr in attendees:
1.44 + if attendee in removed:
1.45 + if attendee_attr.get("PARTSTAT") in ("ACCEPTED", "TENTATIVE"):
1.46 + to_cancel.append((attendee, attendee_attr))
1.47 + else:
1.48 + remaining.append((attendee, attendee_attr))
1.49 +
1.50 + attendees = remaining
1.51 +
1.52 + if added:
1.53 + for attendee in added:
1.54 + attendees.append((attendee, {"PARTSTAT" : "NEEDS-ACTION", "RSVP" : "TRUE"}))
1.55 +
1.56 + obj["ATTENDEE"] = attendees
1.57 +
1.58 + return to_cancel
1.59 +
1.60 +# vim: tabstop=4 expandtab shiftwidth=4