paul@48 | 1 | #!/usr/bin/env python |
paul@48 | 2 | |
paul@48 | 3 | """ |
paul@48 | 4 | Interpretation and preparation of iMIP content, together with a content handling |
paul@48 | 5 | mechanism employed by specific recipients. |
paul@146 | 6 | |
paul@146 | 7 | Copyright (C) 2014, 2015 Paul Boddie <paul@boddie.org.uk> |
paul@146 | 8 | |
paul@146 | 9 | This program is free software; you can redistribute it and/or modify it under |
paul@146 | 10 | the terms of the GNU General Public License as published by the Free Software |
paul@146 | 11 | Foundation; either version 3 of the License, or (at your option) any later |
paul@146 | 12 | version. |
paul@146 | 13 | |
paul@146 | 14 | This program is distributed in the hope that it will be useful, but WITHOUT |
paul@146 | 15 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS |
paul@146 | 16 | FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
paul@146 | 17 | details. |
paul@146 | 18 | |
paul@146 | 19 | You should have received a copy of the GNU General Public License along with |
paul@146 | 20 | this program. If not, see <http://www.gnu.org/licenses/>. |
paul@48 | 21 | """ |
paul@48 | 22 | |
paul@152 | 23 | from datetime import datetime, timedelta |
paul@48 | 24 | from email.mime.text import MIMEText |
paul@182 | 25 | from imiptools.config import MANAGER_PATH, MANAGER_URL |
paul@213 | 26 | from imiptools.data import Object, parse_object, \ |
paul@213 | 27 | get_address, get_fragments, \ |
paul@213 | 28 | get_uri, get_value, uri_dict, uri_item |
paul@152 | 29 | from imiptools.dates import * |
paul@76 | 30 | from imiptools.period import have_conflict, insert_period, remove_period |
paul@152 | 31 | from pytz import timezone |
paul@182 | 32 | from socket import gethostname |
paul@75 | 33 | from vRecurrence import get_parameters, get_rule |
paul@48 | 34 | import imip_store |
paul@48 | 35 | |
paul@48 | 36 | try: |
paul@48 | 37 | from cStringIO import StringIO |
paul@48 | 38 | except ImportError: |
paul@48 | 39 | from StringIO import StringIO |
paul@48 | 40 | |
paul@159 | 41 | def is_new_object(old_sequence, new_sequence, old_dtstamp, new_dtstamp, partstat_set): |
paul@159 | 42 | |
paul@159 | 43 | """ |
paul@159 | 44 | Return for the given 'old_sequence' and 'new_sequence', 'old_dtstamp' and |
paul@159 | 45 | 'new_dtstamp', and the 'partstat_set' indication, whether the object |
paul@159 | 46 | providing the new information is really newer than the object providing the |
paul@159 | 47 | old information. |
paul@159 | 48 | """ |
paul@159 | 49 | |
paul@159 | 50 | have_sequence = old_sequence is not None and new_sequence is not None |
paul@159 | 51 | is_same_sequence = have_sequence and int(new_sequence) == int(old_sequence) |
paul@159 | 52 | |
paul@159 | 53 | have_dtstamp = old_dtstamp and new_dtstamp |
paul@159 | 54 | is_old_dtstamp = have_dtstamp and new_dtstamp < old_dtstamp or old_dtstamp and not new_dtstamp |
paul@159 | 55 | |
paul@159 | 56 | is_old_sequence = have_sequence and ( |
paul@159 | 57 | int(new_sequence) < int(old_sequence) or |
paul@159 | 58 | is_same_sequence and is_old_dtstamp |
paul@159 | 59 | ) |
paul@159 | 60 | |
paul@159 | 61 | return is_same_sequence and partstat_set or not is_old_sequence |
paul@159 | 62 | |
paul@75 | 63 | # NOTE: Need to expose the 100 day window for recurring events in the |
paul@75 | 64 | # NOTE: configuration. |
paul@75 | 65 | |
paul@75 | 66 | def get_periods(obj, window_size=100): |
paul@75 | 67 | |
paul@76 | 68 | """ |
paul@76 | 69 | Return periods for the given object 'obj', confining materialised periods |
paul@76 | 70 | to the given 'window_size' in days starting from the present moment. |
paul@76 | 71 | """ |
paul@76 | 72 | |
paul@213 | 73 | dtstart = obj.get_utc_datetime("DTSTART") |
paul@213 | 74 | dtend = obj.get_utc_datetime("DTEND") |
paul@75 | 75 | |
paul@75 | 76 | # NOTE: Need also DURATION support. |
paul@75 | 77 | |
paul@75 | 78 | duration = dtend - dtstart |
paul@75 | 79 | |
paul@75 | 80 | # Recurrence rules create multiple instances to be checked. |
paul@75 | 81 | # Conflicts may only be assessed within a period defined by policy |
paul@75 | 82 | # for the agent, with instances outside that period being considered |
paul@75 | 83 | # unchecked. |
paul@75 | 84 | |
paul@75 | 85 | window_end = datetime.now() + timedelta(window_size) |
paul@75 | 86 | |
paul@75 | 87 | # NOTE: Need also RDATE and EXDATE support. |
paul@75 | 88 | |
paul@213 | 89 | rrule = obj.get_value("RRULE") |
paul@75 | 90 | |
paul@75 | 91 | if rrule: |
paul@75 | 92 | selector = get_rule(dtstart, rrule) |
paul@75 | 93 | parameters = get_parameters(rrule) |
paul@75 | 94 | periods = [] |
paul@75 | 95 | for start in selector.materialise(dtstart, window_end, parameters.get("COUNT"), parameters.get("BYSETPOS")): |
paul@75 | 96 | start = datetime(*start, tzinfo=timezone("UTC")) |
paul@75 | 97 | end = start + duration |
paul@75 | 98 | periods.append((format_datetime(start), format_datetime(end))) |
paul@75 | 99 | else: |
paul@75 | 100 | periods = [(format_datetime(dtstart), format_datetime(dtend))] |
paul@75 | 101 | |
paul@75 | 102 | return periods |
paul@75 | 103 | |
paul@122 | 104 | def remove_from_freebusy(freebusy, attendee, uid, store): |
paul@122 | 105 | |
paul@122 | 106 | """ |
paul@122 | 107 | For the given 'attendee', remove periods from 'freebusy' that are associated |
paul@122 | 108 | with 'uid' in the 'store'. |
paul@122 | 109 | """ |
paul@122 | 110 | |
paul@122 | 111 | remove_period(freebusy, uid) |
paul@122 | 112 | store.set_freebusy(attendee, freebusy) |
paul@122 | 113 | |
paul@168 | 114 | def remove_from_freebusy_for_other(freebusy, user, other, uid, store): |
paul@168 | 115 | |
paul@168 | 116 | """ |
paul@168 | 117 | For the given 'user', remove for the 'other' party periods from 'freebusy' |
paul@168 | 118 | that are associated with 'uid' in the 'store'. |
paul@168 | 119 | """ |
paul@168 | 120 | |
paul@168 | 121 | remove_period(freebusy, uid) |
paul@168 | 122 | store.set_freebusy_for_other(user, freebusy, other) |
paul@168 | 123 | |
paul@168 | 124 | def _update_freebusy(freebusy, periods, transp, uid): |
paul@168 | 125 | |
paul@168 | 126 | """ |
paul@168 | 127 | Update the free/busy details with the given 'periods', 'transp' setting and |
paul@168 | 128 | 'uid'. |
paul@168 | 129 | """ |
paul@168 | 130 | |
paul@168 | 131 | remove_period(freebusy, uid) |
paul@168 | 132 | |
paul@168 | 133 | for start, end in periods: |
paul@168 | 134 | insert_period(freebusy, (start, end, uid, transp)) |
paul@168 | 135 | |
paul@77 | 136 | def update_freebusy(freebusy, attendee, periods, transp, uid, store): |
paul@76 | 137 | |
paul@76 | 138 | """ |
paul@76 | 139 | For the given 'attendee', update the free/busy details with the given |
paul@77 | 140 | 'periods', 'transp' setting and 'uid' in the 'store'. |
paul@76 | 141 | """ |
paul@76 | 142 | |
paul@168 | 143 | _update_freebusy(freebusy, periods, transp, uid) |
paul@168 | 144 | store.set_freebusy(attendee, freebusy) |
paul@168 | 145 | |
paul@168 | 146 | def update_freebusy_for_other(freebusy, user, other, periods, transp, uid, store): |
paul@77 | 147 | |
paul@168 | 148 | """ |
paul@168 | 149 | For the given 'user', update the free/busy details of 'other' with the given |
paul@168 | 150 | 'periods', 'transp' setting and 'uid' in the 'store'. |
paul@168 | 151 | """ |
paul@76 | 152 | |
paul@168 | 153 | _update_freebusy(freebusy, periods, transp, uid) |
paul@168 | 154 | store.set_freebusy_for_other(user, freebusy, other) |
paul@76 | 155 | |
paul@77 | 156 | def can_schedule(freebusy, periods, uid): |
paul@76 | 157 | |
paul@77 | 158 | """ |
paul@77 | 159 | Return whether the 'freebusy' list can accommodate the given 'periods' |
paul@77 | 160 | employing the specified 'uid'. |
paul@77 | 161 | """ |
paul@76 | 162 | |
paul@77 | 163 | for conflict in have_conflict(freebusy, periods, True): |
paul@112 | 164 | start, end, found_uid, found_transp = conflict |
paul@77 | 165 | if found_uid != uid: |
paul@77 | 166 | return False |
paul@76 | 167 | |
paul@77 | 168 | return True |
paul@76 | 169 | |
paul@48 | 170 | # Handler mechanism objects. |
paul@48 | 171 | |
paul@179 | 172 | def handle_itip_part(part, senders, recipient, handlers, messenger): |
paul@48 | 173 | |
paul@48 | 174 | """ |
paul@89 | 175 | Handle the given iTIP 'part' from the given 'senders' for the given |
paul@179 | 176 | 'recipient' using the given 'handlers' and information provided by the |
paul@89 | 177 | given 'messenger'. Return a list of responses, each response being a tuple |
paul@89 | 178 | of the form (is-outgoing, message-part). |
paul@48 | 179 | """ |
paul@48 | 180 | |
paul@48 | 181 | method = part.get_param("method") |
paul@48 | 182 | |
paul@48 | 183 | # Decode the data and parse it. |
paul@48 | 184 | |
paul@48 | 185 | f = StringIO(part.get_payload(decode=True)) |
paul@48 | 186 | |
paul@48 | 187 | itip = parse_object(f, part.get_content_charset(), "VCALENDAR") |
paul@48 | 188 | |
paul@48 | 189 | # Ignore the part if not a calendar object. |
paul@48 | 190 | |
paul@48 | 191 | if not itip: |
paul@48 | 192 | return [] |
paul@48 | 193 | |
paul@48 | 194 | # Require consistency between declared and employed methods. |
paul@48 | 195 | |
paul@48 | 196 | if get_value(itip, "METHOD") == method: |
paul@48 | 197 | |
paul@48 | 198 | # Look for different kinds of sections. |
paul@48 | 199 | |
paul@60 | 200 | all_results = [] |
paul@48 | 201 | |
paul@48 | 202 | for name, cls in handlers: |
paul@213 | 203 | for fragment in get_fragments(itip, name): |
paul@48 | 204 | |
paul@48 | 205 | # Dispatch to a handler and obtain any response. |
paul@48 | 206 | |
paul@213 | 207 | handler = cls(Object(fragment), senders, recipient, messenger) |
paul@182 | 208 | results = methods[method](handler)() |
paul@48 | 209 | |
paul@89 | 210 | # Aggregate responses for a single message. |
paul@48 | 211 | |
paul@182 | 212 | if results: |
paul@182 | 213 | for result in results: |
paul@215 | 214 | outgoing_recipients, part = result |
paul@215 | 215 | all_results.append((outgoing_recipients, part)) |
paul@48 | 216 | |
paul@60 | 217 | return all_results |
paul@48 | 218 | |
paul@60 | 219 | return [] |
paul@48 | 220 | |
paul@182 | 221 | # References to the Web interface. |
paul@182 | 222 | |
paul@182 | 223 | def get_manager_url(): |
paul@182 | 224 | url_base = MANAGER_URL or "http://%s/" % gethostname() |
paul@182 | 225 | return "%s/%s" % (url_base.rstrip("/"), MANAGER_PATH.lstrip("/")) |
paul@182 | 226 | |
paul@182 | 227 | def get_object_url(uid): |
paul@182 | 228 | return "%s/%s" % (get_manager_url().rstrip("/"), uid) |
paul@182 | 229 | |
paul@48 | 230 | class Handler: |
paul@48 | 231 | |
paul@48 | 232 | "General handler support." |
paul@48 | 233 | |
paul@213 | 234 | def __init__(self, obj, senders=None, recipient=None, messenger=None): |
paul@48 | 235 | |
paul@48 | 236 | """ |
paul@213 | 237 | Initialise the handler with the calendar 'obj' and the 'senders' and |
paul@213 | 238 | 'recipient' of the object (if specifically indicated). |
paul@48 | 239 | """ |
paul@48 | 240 | |
paul@213 | 241 | self.obj = obj |
paul@129 | 242 | self.senders = senders and set(map(get_address, senders)) |
paul@179 | 243 | self.recipient = recipient and get_address(recipient) |
paul@89 | 244 | self.messenger = messenger |
paul@48 | 245 | |
paul@213 | 246 | self.uid = self.obj.get_value("UID") |
paul@213 | 247 | self.sequence = self.obj.get_value("SEQUENCE") |
paul@213 | 248 | self.dtstamp = self.obj.get_value("DTSTAMP") |
paul@48 | 249 | |
paul@48 | 250 | self.store = imip_store.FileStore() |
paul@48 | 251 | |
paul@48 | 252 | try: |
paul@48 | 253 | self.publisher = imip_store.FilePublisher() |
paul@48 | 254 | except OSError: |
paul@48 | 255 | self.publisher = None |
paul@48 | 256 | |
paul@182 | 257 | def wrap(self, text, link=True): |
paul@182 | 258 | |
paul@182 | 259 | "Wrap any valid message for passing to the recipient." |
paul@182 | 260 | |
paul@182 | 261 | texts = [] |
paul@182 | 262 | texts.append(text) |
paul@182 | 263 | if link: |
paul@182 | 264 | texts.append("If your mail program cannot handle this " |
paul@182 | 265 | "message, you may view the details here:\n\n%s" % |
paul@182 | 266 | get_object_url(self.uid)) |
paul@182 | 267 | |
paul@215 | 268 | return [(None, MIMEText("\n".join(texts)))] |
paul@182 | 269 | |
paul@70 | 270 | # Access to calendar structures and other data. |
paul@70 | 271 | |
paul@75 | 272 | def get_periods(self): |
paul@213 | 273 | return get_periods(self.obj) |
paul@75 | 274 | |
paul@122 | 275 | def remove_from_freebusy(self, freebusy, attendee): |
paul@122 | 276 | remove_from_freebusy(freebusy, attendee, self.uid, self.store) |
paul@122 | 277 | |
paul@168 | 278 | def remove_from_freebusy_for_other(self, freebusy, user, other): |
paul@168 | 279 | remove_from_freebusy_for_other(freebusy, user, other, self.uid, self.store) |
paul@168 | 280 | |
paul@77 | 281 | def update_freebusy(self, freebusy, attendee, periods): |
paul@213 | 282 | return update_freebusy(freebusy, attendee, periods, self.obj.get_value("TRANSP"), self.uid, self.store) |
paul@77 | 283 | |
paul@168 | 284 | def update_freebusy_for_other(self, freebusy, user, other, periods): |
paul@213 | 285 | return update_freebusy_for_other(freebusy, user, other, periods, self.obj.get_value("TRANSP"), self.uid, self.store) |
paul@168 | 286 | |
paul@77 | 287 | def can_schedule(self, freebusy, periods): |
paul@77 | 288 | return can_schedule(freebusy, periods, self.uid) |
paul@76 | 289 | |
paul@168 | 290 | def filter_by_senders(self, mapping): |
paul@168 | 291 | |
paul@168 | 292 | """ |
paul@168 | 293 | Return a list of items from 'mapping' filtered using sender information. |
paul@168 | 294 | """ |
paul@168 | 295 | |
paul@89 | 296 | if self.senders: |
paul@168 | 297 | |
paul@168 | 298 | # Get a mapping from senders to identities. |
paul@168 | 299 | |
paul@168 | 300 | identities = self.get_sender_identities(mapping) |
paul@168 | 301 | |
paul@168 | 302 | # Find the senders that are valid. |
paul@168 | 303 | |
paul@168 | 304 | senders = map(get_address, identities) |
paul@168 | 305 | valid = self.senders.intersection(senders) |
paul@89 | 306 | |
paul@168 | 307 | # Return the true identities. |
paul@168 | 308 | |
paul@168 | 309 | return [identities[get_uri(address)] for address in valid] |
paul@168 | 310 | else: |
paul@168 | 311 | return mapping |
paul@168 | 312 | |
paul@179 | 313 | def filter_by_recipient(self, mapping): |
paul@168 | 314 | |
paul@168 | 315 | """ |
paul@168 | 316 | Return a list of items from 'mapping' filtered using recipient |
paul@168 | 317 | information. |
paul@168 | 318 | """ |
paul@168 | 319 | |
paul@179 | 320 | if self.recipient: |
paul@179 | 321 | addresses = set(map(get_address, mapping)) |
paul@179 | 322 | return map(get_uri, addresses.intersection([self.recipient])) |
paul@89 | 323 | else: |
paul@168 | 324 | return mapping |
paul@48 | 325 | |
paul@100 | 326 | def require_organiser_and_attendees(self, from_organiser=True): |
paul@51 | 327 | |
paul@51 | 328 | """ |
paul@179 | 329 | Return the organiser and attendees for the current object, filtered for |
paul@179 | 330 | the recipient of interest. Return None if no identities are eligible. |
paul@129 | 331 | |
paul@129 | 332 | Organiser and attendee identities are provided as lower case values. |
paul@51 | 333 | """ |
paul@51 | 334 | |
paul@213 | 335 | attendee_map = uri_dict(self.obj.get_value_map("ATTENDEE")) |
paul@213 | 336 | organiser_item = uri_item(self.obj.get_item("ORGANIZER")) |
paul@48 | 337 | |
paul@168 | 338 | # Only provide details for attendees who sent/receive the message. |
paul@48 | 339 | |
paul@179 | 340 | attendee_filter_fn = from_organiser and self.filter_by_recipient or self.filter_by_senders |
paul@100 | 341 | |
paul@48 | 342 | attendees = {} |
paul@168 | 343 | for attendee in attendee_filter_fn(attendee_map): |
paul@48 | 344 | attendees[attendee] = attendee_map[attendee] |
paul@48 | 345 | |
paul@168 | 346 | if not attendees or not organiser_item: |
paul@168 | 347 | return None |
paul@168 | 348 | |
paul@168 | 349 | # Only provide details for an organiser who sent/receives the message. |
paul@168 | 350 | |
paul@179 | 351 | organiser_filter_fn = from_organiser and self.filter_by_senders or self.filter_by_recipient |
paul@168 | 352 | |
paul@168 | 353 | if not organiser_filter_fn(dict([organiser_item])): |
paul@89 | 354 | return None |
paul@89 | 355 | |
paul@168 | 356 | return organiser_item, attendees |
paul@94 | 357 | |
paul@168 | 358 | def get_sender_identities(self, mapping): |
paul@94 | 359 | |
paul@94 | 360 | """ |
paul@168 | 361 | Return a mapping from actual senders to the identities for which they |
paul@168 | 362 | have provided data, extracting this information from the given |
paul@168 | 363 | 'mapping'. |
paul@94 | 364 | """ |
paul@94 | 365 | |
paul@168 | 366 | senders = {} |
paul@89 | 367 | |
paul@168 | 368 | for value, attr in mapping.items(): |
paul@94 | 369 | sent_by = attr.get("SENT-BY") |
paul@94 | 370 | if sent_by: |
paul@168 | 371 | senders[get_uri(sent_by)] = value |
paul@168 | 372 | else: |
paul@168 | 373 | senders[value] = value |
paul@48 | 374 | |
paul@168 | 375 | return senders |
paul@48 | 376 | |
paul@213 | 377 | def get_object(self, user): |
paul@100 | 378 | |
paul@100 | 379 | """ |
paul@100 | 380 | Return the stored object to which the current object refers for the |
paul@100 | 381 | given 'user' and for the given 'objtype'. |
paul@100 | 382 | """ |
paul@100 | 383 | |
paul@100 | 384 | f = self.store.get_event(user, self.uid) |
paul@213 | 385 | fragment = f and parse_object(f, "utf-8") |
paul@213 | 386 | return fragment and Object(fragment) |
paul@100 | 387 | |
paul@213 | 388 | def have_new_object(self, attendee, obj=None): |
paul@51 | 389 | |
paul@51 | 390 | """ |
paul@213 | 391 | Return whether the current object is new to the 'attendee' (or if the |
paul@213 | 392 | given 'obj' is new). |
paul@51 | 393 | """ |
paul@51 | 394 | |
paul@213 | 395 | obj = obj or self.get_object(attendee) |
paul@51 | 396 | |
paul@51 | 397 | # If found, compare SEQUENCE and potentially DTSTAMP. |
paul@51 | 398 | |
paul@100 | 399 | if obj: |
paul@213 | 400 | sequence = obj.get_value("SEQUENCE") |
paul@213 | 401 | dtstamp = obj.get_value("DTSTAMP") |
paul@51 | 402 | |
paul@100 | 403 | # If the request refers to an older version of the object, ignore |
paul@51 | 404 | # it. |
paul@51 | 405 | |
paul@172 | 406 | return is_new_object(sequence, self.sequence, dtstamp, self.dtstamp, |
paul@172 | 407 | self.is_partstat_updated(obj)) |
paul@51 | 408 | |
paul@51 | 409 | return True |
paul@51 | 410 | |
paul@172 | 411 | def is_partstat_updated(self, obj): |
paul@174 | 412 | |
paul@174 | 413 | """ |
paul@174 | 414 | Return whether the participant status has been updated in the current |
paul@174 | 415 | object in comparison to the given 'obj'. |
paul@174 | 416 | |
paul@174 | 417 | NOTE: Some clients like Claws Mail erase time information from DTSTAMP |
paul@174 | 418 | NOTE: and make it invalid. Thus, such attendance information may also be |
paul@174 | 419 | NOTE: incorporated into any new object assessment. |
paul@174 | 420 | """ |
paul@174 | 421 | |
paul@213 | 422 | old_attendees = obj.get_value_map("ATTENDEE") |
paul@213 | 423 | new_attendees = self.obj.get_value_map("ATTENDEE") |
paul@172 | 424 | |
paul@172 | 425 | for attendee, attr in old_attendees.items(): |
paul@172 | 426 | old_partstat = attr.get("PARTSTAT") |
paul@172 | 427 | new_attr = new_attendees.get(attendee) |
paul@172 | 428 | new_partstat = new_attr and new_attr.get("PARTSTAT") |
paul@172 | 429 | |
paul@172 | 430 | if old_partstat == "NEEDS-ACTION" and new_partstat and \ |
paul@172 | 431 | new_partstat != old_partstat: |
paul@172 | 432 | |
paul@172 | 433 | return True |
paul@172 | 434 | |
paul@172 | 435 | return False |
paul@172 | 436 | |
paul@158 | 437 | def update_dtstamp(self): |
paul@158 | 438 | |
paul@158 | 439 | "Update the DTSTAMP in the current object." |
paul@158 | 440 | |
paul@213 | 441 | dtstamp = self.obj.get_utc_datetime("DTSTAMP") |
paul@158 | 442 | utcnow = to_timezone(datetime.utcnow(), "UTC") |
paul@213 | 443 | self.obj["DTSTAMP"] = [(format_datetime(dtstamp > utcnow and dtstamp or utcnow), {})] |
paul@158 | 444 | |
paul@48 | 445 | # Handler registry. |
paul@48 | 446 | |
paul@48 | 447 | methods = { |
paul@48 | 448 | "ADD" : lambda handler: handler.add, |
paul@48 | 449 | "CANCEL" : lambda handler: handler.cancel, |
paul@48 | 450 | "COUNTER" : lambda handler: handler.counter, |
paul@48 | 451 | "DECLINECOUNTER" : lambda handler: handler.declinecounter, |
paul@48 | 452 | "PUBLISH" : lambda handler: handler.publish, |
paul@48 | 453 | "REFRESH" : lambda handler: handler.refresh, |
paul@48 | 454 | "REPLY" : lambda handler: handler.reply, |
paul@48 | 455 | "REQUEST" : lambda handler: handler.request, |
paul@48 | 456 | } |
paul@48 | 457 | |
paul@48 | 458 | # vim: tabstop=4 expandtab shiftwidth=4 |