1 #!/usr/bin/env python 2 3 """ 4 Handlers for a person for whom scheduling is performed, inspecting outgoing 5 messages to obtain scheduling done externally. 6 """ 7 8 from imiptools.content import Handler, uri_item 9 from vCalendar import to_node 10 11 class PersonHandler(Handler): 12 13 "Handling mechanisms specific to people." 14 15 def _record(self, objtype, from_organiser=True, update_freebusy=False): 16 17 # Get the identity of interest in a usable form. 18 19 identity, attr = uri_item(self.get_item(from_organiser and "ORGANIZER" or "ATTENDEE")) 20 21 # Check for event using UID. 22 23 if not self.have_new_object(identity, objtype): 24 return False 25 26 # Store the object. 27 28 self.store.set_event(identity, self.uid, to_node( 29 {objtype : [(self.details, {})]} 30 )) 31 32 # Update free/busy information. 33 34 if update_freebusy: 35 36 # If newer than any old version, discard old details from the 37 # free/busy record and check for suitability. 38 39 periods = self.get_periods() 40 freebusy = self.store.get_freebusy(identity) or [] 41 42 if from_organiser or attr.get("PARTSTAT") != "DECLINED": 43 self.update_freebusy(freebusy, identity, periods) 44 else: 45 self.remove_from_freebusy(freebusy, identity) 46 47 if self.publisher: 48 self.publisher.set_freebusy(identity, freebusy) 49 50 return True 51 52 class Event(PersonHandler): 53 54 "An event handler." 55 56 def add(self): 57 pass 58 59 def cancel(self): 60 pass 61 62 def counter(self): 63 pass 64 65 def declinecounter(self): 66 pass 67 68 def publish(self): 69 self._record("VEVENT", True, True) 70 71 def refresh(self): 72 self._record("VEVENT", True, True) 73 74 def reply(self): 75 self._record("VEVENT", False, True) 76 77 def request(self): 78 self._record("VEVENT", True, True) 79 80 class Freebusy(PersonHandler): 81 82 "A free/busy handler." 83 84 def publish(self): 85 pass 86 87 def reply(self): 88 pass 89 90 def request(self): 91 pass 92 93 class Journal(PersonHandler): 94 95 "A journal entry handler." 96 97 def add(self): 98 pass 99 100 def cancel(self): 101 pass 102 103 def publish(self): 104 self._record("VJOURNAL", True) 105 106 class Todo(PersonHandler): 107 108 "A to-do item handler." 109 110 def add(self): 111 pass 112 113 def cancel(self): 114 pass 115 116 def counter(self): 117 pass 118 119 def declinecounter(self): 120 pass 121 122 def publish(self): 123 self._record("VTODO", True) 124 125 def refresh(self): 126 self._record("VTODO", True) 127 128 def reply(self): 129 self._record("VTODO", False) 130 131 def request(self): 132 self._record("VTODO", True) 133 134 # Handler registry. 135 136 handlers = [ 137 ("VFREEBUSY", Freebusy), 138 ("VEVENT", Event), 139 ("VTODO", Todo), 140 ("VJOURNAL", Journal), 141 ] 142 143 # vim: tabstop=4 expandtab shiftwidth=4