5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to deal
7 # in the Software without restriction, including without limitation the rights
8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 # copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 # This file describes a series of rules which must handle a vobject object and
24 # return it to the calling script
26 # The doc string will be presented to the user when run as verbose, so
32 ruleConfig["defaultTZ"] = "UTC"
34 def facebookOrganiser(cal):
35 '''Adds organiser details to the body of facebook calendars.'''
37 if 'prodid' in cal.contents:
38 if not "Facebook" in cal.prodid.value: return cal
40 if 'vevent_list' not in dir(cal):
43 for event in cal.vevent_list:
44 if 'organizer' not in event.contents: continue
46 a = event.organizer.cn_paramlist
47 organizer = "Organised by: " + event.organizer.cn_param + " ("
48 organizer += event.organizer.value.lstrip('MAILTO:') + ")\n\n"
49 event.description.value = organizer + event.description.value
50 except AttributeError:
51 organizer = "Organized by: " + event.organizer.value
52 event.description.value = organizer + "\n\n" + event.description.value
56 '''Marks events public so google calendar doesn't have a sad about them.'''
58 if 'vevent_list' not in dir(cal):
61 for event in cal.vevent_list:
62 if 'class' in event.contents:
63 # Bit of a hack as class is a reserved word in python
64 del event.contents['class']
65 event.add('class').value = "PUBLIC"
69 def dropAttributes(cal):
70 '''Removing unwanted metadata'''
71 if "facebook" in ruleConfig:
72 if ruleConfig["facebook"] == True: return cal
74 if 'vevent_list' not in dir(cal):
77 eventBlacklist = [x.lower() for x in [
79 "X-MICROSOFT-CDO-BUSYSTATUS",
80 "X-MICROSOFT-CDO-IMPORTANCE",
81 "X-MICROSOFT-DISALLOW-COUNTER",
82 "X-MS-OLK-ALLOWEXTERNCHECK",
83 "X-MS-OLK-AUTOSTARTCHECK",
85 "X-MS-OLK-AUTOFILLLOCATION",
91 mainBlacklist = [x.lower() for x in [
99 "X-MS-OLK-APPTSEQTIME",
106 for event in cal.vevent_list:
107 for blacklist in eventBlacklist:
108 if blacklist in event.contents: del event.contents[blacklist]
110 for blkl in mainBlacklist:
111 while blkl in cal.contents: del cal.contents[blkl]
116 '''Replacing multi-value EXDATES with multiple single-value EXDATES'''
117 if "facebook" in ruleConfig:
118 if ruleConfig["facebook"] == True: return cal
120 if 'vevent_list' not in dir(cal):
123 from datetime import datetime
124 from pytz import timezone
126 default = timezone(ruleConfig["defaultTZ"])
128 for event in cal.vevent_list:
129 if 'exdate' not in event.contents: continue
130 dates = event.exdate.value
132 del event.contents['exdate']
135 if isinstance(date, datetime):
136 if date.tzinfo is None: date = date.replace(tzinfo = default)
137 date = date.astimezone(vobject.icalendar.utc)
138 entry = event.add('exdate')
144 '''Removing local timezones in favour of UTC. If the remote calendar specifies a timezone
145 then use it, otherwise assume it's in the user-specified or default values'''
147 if 'vevent_list' not in dir(cal):
150 from datetime import datetime
151 from pytz import timezone
153 default = timezone(ruleConfig["defaultTZ"])
155 for event in cal.vevent_list:
156 dtstart = getattr(event, 'dtstart', None)
157 dtend = getattr(event, 'dtend', None)
159 for i in (dtstart, dtend):
162 if isinstance(dt, datetime):
163 if dt.tzinfo is None: dt = dt.replace(tzinfo = default)
164 i.value = dt.astimezone(vobject.icalendar.utc)
168 def unwantedParams(cal):
169 '''Removing unwanted parameters'''
173 "X-VOBJ-ORIGINAL-TZID",
177 if 'vevent_list' not in dir(cal):
180 for event in cal.vevent_list:
181 for attr in event.contents:
182 attr = getattr(event, attr)
185 while i in attr.params: del attr.params[i]
186 except AttributeError: continue