summaryrefslogtreecommitdiffstats
path: root/tests/unit/test-004-icalendar.py
blob: 519599b3269bab406f7426d26a3bbd6cd6bf42ba (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
from email import message_from_string
import icalendar
import unittest


class TestICalendar(unittest.TestCase):

    def test_001_from_message_recurrence(self):
        message = message_from_string("""Received: from localhost (localhost [127.0.0.1])
    by kolab.example.org (Postfix) with ESMTP id 513B942E10
    for <resource-collection-car@example.org>; Fri, 13 Jul 2012 14:54:16 +0200 (CEST)
X-Virus-Scanned: amavisd-new at example.org
X-Spam-Flag: NO
X-Spam-Score: 0.551
X-Spam-Level:
X-Spam-Status: No, score=0.551 tagged_above=-10 required=6.2
    tests=[ALL_TRUSTED=-1, DNS_FROM_RFC_DSN=0.001,
    NORMAL_HTTP_TO_IP=0.001, TVD_RCVD_IP=0.054, TVD_RCVD_IP4=1.495]
    autolearn=no
Received: from kolab.example.org ([127.0.0.1])
    by localhost (kolab.example.org [127.0.0.1]) (amavisd-new, port 10024)
    with ESMTP id KNJgv841fj-1 for <resource-collection-car@example.org>;
    Fri, 13 Jul 2012 14:54:15 +0200 (CEST)
Received: from 192.168.122.228 (localhost [127.0.0.1])
    (Authenticated sender: john.doe@example.org)
    by kolab.example.org (Postfix) with ESMTPSA id 0EBDA42E39
    for <resource-collection-car@example.org>; Fri, 13 Jul 2012 14:54:14 +0200 (CEST)
MIME-Version: 1.0
Content-Type: multipart/mixed;
 boundary="=_c8894dbdb8baeedacae836230e3436fd"
From: "Doe, John" <john.doe@example.org>
Date: Fri, 13 Jul 2012 13:54:14 +0100
Message-ID: <240fe7ae7e139129e9eb95213c1016d7@example.org>
X-Sender: john.doe@example.org
User-Agent: Roundcube Webmail/0.9-0.3.el6.kolab_3.0
To: resource-collection-car@example.org
Subject: "test" has been updated

--=_c8894dbdb8baeedacae836230e3436fd
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8;
 format=flowed

*test*

When: 2012-07-13 10:00 - 11:00 (Europe/London)

Invitees: Doe, John <john.doe@example.org>,=20
resource-collection-car@example.org

Please find attached an iCalendar file with the updated event details which=
=20
you can import to your calendar application.

In case your email client doesn't support iTip requests you can use the=20
following link to either accept or decline this invitation:
http://192.168.122.228/roundcubemail/?_task=3Dcalendar&_t=3D9febd7562df0f5b=
ca7646a7bf6696801a394dd5a.cmVzb3VyY2UtY29sbGVjdGlvbi1jYXJAZXhhbXBsZS5vcmc%3=
D.726d2f&_action=3Dattend
--=_c8894dbdb8baeedacae836230e3436fd
Content-Type: text/calendar; charset=UTF-8; method=REQUEST;
 name=event.ics
Content-Disposition: attachment;
 filename=event.ics
Content-Transfer-Encoding: quoted-printable

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Roundcube Webmail 0.9-0.3.el6.kolab_3.0//NONSGML Calendar//EN
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
UID:626421779C777FBE9C9B85A80D04DDFA-A4BF5BBB9FEAA271
DTSTAMP:20120713T1254140
DTSTART;TZID=3DEurope/London:20120713T100000
DTEND;TZID=3DEurope/London:20120713T110000
SUMMARY:test
DESCRIPTION:test
ORGANIZER;CN=3D"Doe, John":mailto:john.doe@example.org
ATTENDEE;ROLE=3DREQ-PARTICIPANT;PARTSTAT=3DNEEDS-ACTION;RSVP=3DTRUE:mailt=
o:resourc
 e-collection-car@example.org
RRULE:FREQ=3DWEEKLY;INTERVAL=3D1;BYDAY=3DFR
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR

--=_c8894dbdb8baeedacae836230e3436fd--
""")

        self.assertTrue(message.is_multipart())

        itip_methods = ["REQUEST"]

        # Check each part
        for part in message.walk():
            # The iTip part MUST be Content-Type: text/calendar (RFC 6047,
            # section 2.4)
            if part.get_content_type() == "text/calendar":
                if not part.get_param('method') in itip_methods:
                    raise Exception("method not interesting")

                # Get the itip_payload
                itip_payload = part.get_payload(decode=True)

                # Python iCalendar prior to 3.0 uses "from_string".
                if hasattr(icalendar.Calendar, 'from_ical'):
                    cal = icalendar.Calendar.from_ical(itip_payload)
                elif hasattr(icalendar.Calendar, 'from_string'):
                    cal = icalendar.Calendar.from_string(itip_payload)
                # If we can't read it, we're out
                else:
                    return []

    def test_002_from_message(self):
        message = message_from_string("""Received: from localhost (localhost [127.0.0.1])
    by kolab.example.org (Postfix) with ESMTP id 513B942E10
    for <resource-collection-car@example.org>; Fri, 13 Jul 2012 14:54:16 +0200 (CEST)
X-Virus-Scanned: amavisd-new at example.org
X-Spam-Flag: NO
X-Spam-Score: 0.551
X-Spam-Level:
X-Spam-Status: No, score=0.551 tagged_above=-10 required=6.2
    tests=[ALL_TRUSTED=-1, DNS_FROM_RFC_DSN=0.001,
    NORMAL_HTTP_TO_IP=0.001, TVD_RCVD_IP=0.054, TVD_RCVD_IP4=1.495]
    autolearn=no
Received: from kolab.example.org ([127.0.0.1])
    by localhost (kolab.example.org [127.0.0.1]) (amavisd-new, port 10024)
    with ESMTP id KNJgv841fj-1 for <resource-collection-car@example.org>;
    Fri, 13 Jul 2012 14:54:15 +0200 (CEST)
Received: from 192.168.122.228 (localhost [127.0.0.1])
    (Authenticated sender: john.doe@example.org)
    by kolab.example.org (Postfix) with ESMTPSA id 0EBDA42E39
    for <resource-collection-car@example.org>; Fri, 13 Jul 2012 14:54:14 +0200 (CEST)
MIME-Version: 1.0
Content-Type: multipart/mixed;
 boundary="=_c8894dbdb8baeedacae836230e3436fd"
From: "Doe, John" <john.doe@example.org>
Date: Fri, 13 Jul 2012 13:54:14 +0100
Message-ID: <240fe7ae7e139129e9eb95213c1016d7@example.org>
X-Sender: john.doe@example.org
User-Agent: Roundcube Webmail/0.9-0.3.el6.kolab_3.0
To: resource-collection-car@example.org
Subject: "test" has been updated

--=_c8894dbdb8baeedacae836230e3436fd
Content-Transfer-Encoding: quoted-printable
Content-Type: text/plain; charset=UTF-8;
 format=flowed

*test*

When: 2012-07-13 10:00 - 11:00 (Europe/London)

Invitees: Doe, John <john.doe@example.org>,=20
resource-collection-car@example.org

Please find attached an iCalendar file with the updated event details which=
=20
you can import to your calendar application.

In case your email client doesn't support iTip requests you can use the=20
following link to either accept or decline this invitation:
http://192.168.122.228/roundcubemail/?_task=3Dcalendar&_t=3D9febd7562df0f5b=
ca7646a7bf6696801a394dd5a.cmVzb3VyY2UtY29sbGVjdGlvbi1jYXJAZXhhbXBsZS5vcmc%3=
D.726d2f&_action=3Dattend
--=_c8894dbdb8baeedacae836230e3436fd
Content-Type: text/calendar; charset=UTF-8; method=REQUEST;
 name=event.ics
Content-Disposition: attachment;
 filename=event.ics
Content-Transfer-Encoding: quoted-printable

BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Roundcube Webmail 0.9-0.3.el6.kolab_3.0//NONSGML Calendar//EN
CALSCALE:GREGORIAN
METHOD:REQUEST
BEGIN:VEVENT
UID:626421779C777FBE9C9B85A80D04DDFA-A4BF5BBB9FEAA271
DTSTAMP:20120713T1254140
DTSTART;TZID=3DEurope/London:20120713T100000
DTEND;TZID=3DEurope/London:20120713T110000
SUMMARY:test
DESCRIPTION:test
ORGANIZER;CN=3D"Doe, John":mailto:john.doe@example.org
ATTENDEE;ROLE=3DREQ-PARTICIPANT;PARTSTAT=3DNEEDS-ACTION;RSVP=3DTRUE:mailt=
o:resourc
 e-collection-car@example.org
TRANSP:OPAQUE
END:VEVENT
END:VCALENDAR

--=_c8894dbdb8baeedacae836230e3436fd--
""")

        self.assertTrue(message.is_multipart())

        itip_methods = ["REQUEST"]

        # Check each part
        for part in message.walk():
            # The iTip part MUST be Content-Type: text/calendar (RFC 6047,
            # section 2.4)
            if part.get_content_type() == "text/calendar":
                if not part.get_param('method') in itip_methods:
                    raise Exception("method not interesting")

                # Get the itip_payload
                itip_payload = part.get_payload(decode=True)

                # Python iCalendar prior to 3.0 uses "from_string".
                if hasattr(icalendar.Calendar, 'from_ical'):
                    cal = icalendar.Calendar.from_ical(itip_payload)
                elif hasattr(icalendar.Calendar, 'from_string'):
                    cal = icalendar.Calendar.from_string(itip_payload)
                # If we can't read it, we're out
                else:
                    return []