1.1 --- a/imiptools/handlers/common.py Sun Sep 13 17:09:56 2015 +0200
1.2 +++ b/imiptools/handlers/common.py Sun Sep 13 17:11:12 2015 +0200
1.3 @@ -79,6 +79,37 @@
1.4 self.obj.get_datetime("DTSTART") and
1.5 (self.obj.get_datetime("DTEND") or self.obj.get_duration("DURATION")))
1.6
1.7 + def will_refresh(self):
1.8 +
1.9 + """
1.10 + Indicate whether a REFRESH message should be used to respond to an ADD
1.11 + message.
1.12 + """
1.13 +
1.14 + return not self.get_stored_object_version() or self.get_add_method_response() == "refresh"
1.15 +
1.16 + def make_refresh(self):
1.17 +
1.18 + "Make a REFRESH message."
1.19 +
1.20 + organiser = get_uri(self.obj.get_value("ORGANIZER"))
1.21 + attendees = uri_dict(self.obj.get_value_map("ATTENDEE"))
1.22 +
1.23 + # Add SENT-BY details to the recipient's attributes.
1.24 +
1.25 + attendee_attr = attendees[self.user]
1.26 + self.update_sender(attendee_attr)
1.27 +
1.28 + # Make a new object with a minimal property selection.
1.29 +
1.30 + obj = self.obj.copy()
1.31 + obj.preserve(("ORGANIZER", "DTSTAMP", "UID", "RECURRENCE-ID"))
1.32 + obj["ATTENDEE"] = [(self.user, attendee_attr)]
1.33 +
1.34 + # Send a REFRESH message in response.
1.35 +
1.36 + self.add_result("REFRESH", [get_address(organiser)], obj.to_part("REFRESH"))
1.37 +
1.38 def update_event_in_freebusy(self, for_organiser=True):
1.39
1.40 """
2.1 --- a/imiptools/handlers/person.py Sun Sep 13 17:09:56 2015 +0200
2.2 +++ b/imiptools/handlers/person.py Sun Sep 13 17:11:12 2015 +0200
2.3 @@ -45,24 +45,8 @@
2.4
2.5 # Request details where configured, doing so for unknown objects anyway.
2.6
2.7 - refreshing = not self.get_stored_object_version() or self.get_add_method_response() == "refresh"
2.8 -
2.9 - if refreshing:
2.10 -
2.11 - # Add SENT-BY details to the recipient's attributes.
2.12 -
2.13 - attendee_attr = attendees[self.user]
2.14 - self.update_sender(attendee_attr)
2.15 -
2.16 - # Make a new object with a minimal property selection.
2.17 -
2.18 - obj = self.obj.copy()
2.19 - obj.preserve(("ORGANIZER", "DTSTAMP", "UID", "RECURRENCE-ID"))
2.20 - obj["ATTENDEE"] = [(self.user, attendee_attr)]
2.21 -
2.22 - # Send a REFRESH message in response.
2.23 -
2.24 - self.add_result("REFRESH", [get_address(organiser)], obj.to_part("REFRESH"))
2.25 + if self.will_refresh():
2.26 + self.make_refresh()
2.27
2.28 # Record the event as a recurrence of the parent object.
2.29
2.30 @@ -74,7 +58,7 @@
2.31
2.32 # Stop if requesting the full event.
2.33
2.34 - if refreshing:
2.35 + if self.will_refresh():
2.36 return
2.37
2.38 # Set the additional occurrence.
3.1 --- a/imiptools/handlers/resource.py Sun Sep 13 17:09:56 2015 +0200
3.2 +++ b/imiptools/handlers/resource.py Sun Sep 13 17:11:12 2015 +0200
3.3 @@ -19,7 +19,7 @@
3.4 this program. If not, see <http://www.gnu.org/licenses/>.
3.5 """
3.6
3.7 -from imiptools.data import get_address, to_part
3.8 +from imiptools.data import get_address, to_part, uri_dict
3.9 from imiptools.dates import ValidityError
3.10 from imiptools.handlers import Handler
3.11 from imiptools.handlers.common import CommonFreebusy, CommonEvent
3.12 @@ -58,17 +58,16 @@
3.13 This does not request a response concerning participation, apparently.
3.14 """
3.15
3.16 - # Ignore unknown objects.
3.17 - # NOTE: We could issue a REFRESH to get such objects.
3.18 + # Request details where configured, doing so for unknown objects anyway.
3.19
3.20 - if not self.get_stored_object_version():
3.21 + if self.will_refresh():
3.22 + self.make_refresh()
3.23 return
3.24
3.25 # Record the event as a recurrence of the parent object.
3.26
3.27 self.update_recurrenceid()
3.28 - event = self.obj.to_node()
3.29 - self.store.set_event(self.user, self.uid, self.recurrenceid, event)
3.30 + self.store.set_event(self.user, self.uid, self.recurrenceid, self.obj.to_node())
3.31
3.32 # Update free/busy information.
3.33
3.34 @@ -79,7 +78,7 @@
3.35 "Attempt to schedule the current object for the current user."
3.36
3.37 method = "REPLY"
3.38 - attendee_attr = self.obj.get_value_map("ATTENDEE")[self.user]
3.39 + attendee_attr = uri_dict(self.obj.get_value_map("ATTENDEE"))[self.user]
3.40
3.41 # Check any constraints on the request.
3.42
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
4.2 +++ b/tests/templates/event-add-recurring.txt Sun Sep 13 17:11:12 2015 +0200
4.3 @@ -0,0 +1,34 @@
4.4 +Content-Type: multipart/alternative; boundary="===============0047278175=="
4.5 +MIME-Version: 1.0
4.6 +From: paul.boddie@example.com
4.7 +To: resource-room-confroom@example.com
4.8 +Subject: Invitation!
4.9 +
4.10 +--===============0047278175==
4.11 +Content-Type: text/plain; charset="us-ascii"
4.12 +MIME-Version: 1.0
4.13 +Content-Transfer-Encoding: 7bit
4.14 +
4.15 +This message contains an event.
4.16 +
4.17 +--===============0047278175==
4.18 +MIME-Version: 1.0
4.19 +Content-Transfer-Encoding: 7bit
4.20 +Content-Type: text/calendar; charset="us-ascii"; method="ADD"
4.21 +
4.22 +BEGIN:VCALENDAR
4.23 +PRODID:-//imip-agent/test//EN
4.24 +METHOD:ADD
4.25 +VERSION:2.0
4.26 +BEGIN:VEVENT
4.27 +ORGANIZER:mailto:paul.boddie@example.com
4.28 +ATTENDEE;RSVP=TRUE:mailto:resource-room-confroom@example.com
4.29 +DTSTAMP:20141009T182400Z
4.30 +DTSTART;TZID=Europe/Oslo:20150109T100000
4.31 +DTEND;TZID=Europe/Oslo:20150109T110000
4.32 +SUMMARY:Recurring event
4.33 +UID:event3@example.com
4.34 +END:VEVENT
4.35 +END:VCALENDAR
4.36 +
4.37 +--===============0047278175==--
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/tests/test_resource_invitation_add.sh Sun Sep 13 17:11:12 2015 +0200
5.3 @@ -0,0 +1,129 @@
5.4 +#!/bin/sh
5.5 +
5.6 +THIS_DIR=`dirname $0`
5.7 +
5.8 +TEMPLATES="$THIS_DIR/templates"
5.9 +PERSON_SCRIPT="$THIS_DIR/../imip_person.py"
5.10 +RESOURCE_SCRIPT="$THIS_DIR/../imip_resource.py"
5.11 +SHOWMAIL="$THIS_DIR/../tools/showmail.py"
5.12 +STORE=/tmp/store
5.13 +STATIC=/tmp/static
5.14 +PREFS=/tmp/prefs
5.15 +ARGS="-S $STORE -P $STATIC -p $PREFS -d"
5.16 +USER="mailto:resource-room-confroom@example.com"
5.17 +SENDER="mailto:paul.boddie@example.com"
5.18 +FBFILE="$STORE/$USER/freebusy"
5.19 +FBSENDERFILE="$STORE/$SENDER/freebusy"
5.20 +FBSENDEROTHERFILE="$STORE/$SENDER/freebusy-other/$USER"
5.21 +TAB=`printf '\t'`
5.22 +
5.23 +OUTGOING_SCRIPT="$THIS_DIR/../imip_person_outgoing.py"
5.24 +
5.25 +ERROR=err.tmp
5.26 +
5.27 +rm -r $STORE
5.28 +rm -r $STATIC
5.29 +rm -r $PREFS
5.30 +rm $ERROR
5.31 +rm out*.tmp
5.32 +
5.33 +mkdir -p "$PREFS/$USER"
5.34 +echo 'Europe/Oslo' > "$PREFS/$USER/TZID"
5.35 +echo 'share' > "$PREFS/$USER/freebusy_sharing"
5.36 +
5.37 +mkdir -p "$PREFS/$SENDER"
5.38 +echo 'Europe/Oslo' > "$PREFS/$SENDER/TZID"
5.39 +echo 'always' > "$PREFS/$SENDER/event_refreshing"
5.40 +
5.41 +# Publish an event, testing registration in the outgoing handler.
5.42 +
5.43 +"$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-request-recurring.txt" 2>> $ERROR
5.44 +
5.45 + grep -q "^20141212T090000Z${TAB}20141212T100000Z" "$FBSENDERFILE" \
5.46 +&& echo "Success" \
5.47 +|| echo "Failed"
5.48 +
5.49 +# Present the request to the recipient.
5.50 +
5.51 + "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-request-recurring.txt" 2>> $ERROR \
5.52 +| "$SHOWMAIL" \
5.53 +> out1.tmp
5.54 +
5.55 + grep -q 'METHOD:REPLY' out1.tmp \
5.56 +&& echo "Success" \
5.57 +|| echo "Failed"
5.58 +
5.59 + grep -q "^20141212T090000Z${TAB}20141212T100000Z" "$FBFILE" \
5.60 +&& echo "Success" \
5.61 +|| echo "Failed"
5.62 +
5.63 +# Present the response to the sender.
5.64 +
5.65 + "$PERSON_SCRIPT" $ARGS < out1.tmp 2>> $ERROR \
5.66 +| "$SHOWMAIL" \
5.67 +> out2.tmp
5.68 +
5.69 + grep -q "^20141212T090000Z${TAB}20141212T100000Z" "$FBSENDEROTHERFILE" \
5.70 +&& echo "Success" \
5.71 +|| echo "Failed"
5.72 +
5.73 +# Attempt to add an occurrence to the event.
5.74 +
5.75 +"$OUTGOING_SCRIPT" $ARGS < "$TEMPLATES/event-add-recurring.txt" 2>> $ERROR
5.76 +
5.77 + grep -q "^20141212T090000Z${TAB}20141212T100000Z" "$FBSENDERFILE" \
5.78 +&& grep -q "^20150109T090000Z${TAB}20150109T100000Z" "$FBSENDERFILE" \
5.79 +&& echo "Success" \
5.80 +|| echo "Failed"
5.81 +
5.82 +# Present the request to the recipient.
5.83 +
5.84 + "$RESOURCE_SCRIPT" $ARGS < "$TEMPLATES/event-add-recurring.txt" 2>> $ERROR \
5.85 +| "$SHOWMAIL" \
5.86 +> out3.tmp
5.87 +
5.88 + grep -q 'METHOD:REFRESH' out3.tmp \
5.89 +&& echo "Success" \
5.90 +|| echo "Failed"
5.91 +
5.92 + grep -q "^20141212T090000Z${TAB}20141212T100000Z" "$FBFILE" \
5.93 +&& ! grep -q "^20150109T090000Z${TAB}20150109T100000Z" "$FBFILE" \
5.94 +&& echo "Success" \
5.95 +|| echo "Failed"
5.96 +
5.97 +# Present the refresh message to the organiser.
5.98 +
5.99 + "$PERSON_SCRIPT" $ARGS < out3.tmp 2>> $ERROR \
5.100 +| "$SHOWMAIL" \
5.101 +> out4.tmp
5.102 +
5.103 + grep -q 'METHOD:REQUEST' out4.tmp \
5.104 +&& echo "Success" \
5.105 +|| echo "Failed"
5.106 +
5.107 +# Present the request to the recipient.
5.108 +
5.109 + "$RESOURCE_SCRIPT" $ARGS < out4.tmp 2>> $ERROR \
5.110 +| tee out5r.tmp \
5.111 +| "$SHOWMAIL" \
5.112 +> out5.tmp
5.113 +
5.114 + grep -q 'METHOD:REPLY' out5.tmp \
5.115 +&& echo "Success" \
5.116 +|| echo "Failed"
5.117 +
5.118 + grep -q "^20141212T090000Z${TAB}20141212T100000Z" "$FBFILE" \
5.119 +&& grep -q "^20150109T090000Z${TAB}20150109T100000Z" "$FBFILE" \
5.120 +&& echo "Success" \
5.121 +|| echo "Failed"
5.122 +
5.123 +# Present the response to the sender.
5.124 +
5.125 + "$PERSON_SCRIPT" $ARGS < out5r.tmp 2>> $ERROR \
5.126 +| "$SHOWMAIL" \
5.127 +> out6.tmp
5.128 +
5.129 + grep -q "^20141212T090000Z${TAB}20141212T100000Z" "$FBSENDEROTHERFILE" \
5.130 +&& grep -q "^20150109T090000Z${TAB}20150109T100000Z" "$FBSENDEROTHERFILE" \
5.131 +&& echo "Success" \
5.132 +|| echo "Failed"