Changeset View
Changeset View
Standalone View
Standalone View
tests/unit/test-004-icalendar.py
from email import message_from_string | from email import message_from_string | ||||
import icalendar | import icalendar | ||||
import unittest | import unittest | ||||
class TestICalendar(unittest.TestCase): | class TestICalendar(unittest.TestCase): | ||||
def test_001_from_message_recurrence(self): | def test_001_from_message_recurrence(self): | ||||
message = message_from_string("""Received: from localhost (localhost [127.0.0.1]) | message = message_from_string("""Received: from localhost (localhost [127.0.0.1]) | ||||
by kolab.example.org (Postfix) with ESMTP id 513B942E10 | by kolab.example.org (Postfix) with ESMTP id 513B942E10 | ||||
for <resource-collection-car@example.org>; Fri, 13 Jul 2012 14:54:16 +0200 (CEST) | for <resource-collection-car@example.org>; Fri, 13 Jul 2012 14:54:16 +0200 (CEST) | ||||
Lint: PEP8 E501: line too long (85 > 79 characters) | |||||
X-Virus-Scanned: amavisd-new at example.org | X-Virus-Scanned: amavisd-new at example.org | ||||
X-Spam-Flag: NO | X-Spam-Flag: NO | ||||
X-Spam-Score: 0.551 | X-Spam-Score: 0.551 | ||||
X-Spam-Level: | X-Spam-Level: | ||||
X-Spam-Status: No, score=0.551 tagged_above=-10 required=6.2 | X-Spam-Status: No, score=0.551 tagged_above=-10 required=6.2 | ||||
tests=[ALL_TRUSTED=-1, DNS_FROM_RFC_DSN=0.001, | 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] | NORMAL_HTTP_TO_IP=0.001, TVD_RCVD_IP=0.054, TVD_RCVD_IP4=1.495] | ||||
autolearn=no | autolearn=no | ||||
Received: from kolab.example.org ([127.0.0.1]) | Received: from kolab.example.org ([127.0.0.1]) | ||||
by localhost (kolab.example.org [127.0.0.1]) (amavisd-new, port 10024) | by localhost (kolab.example.org [127.0.0.1]) (amavisd-new, port 10024) | ||||
with ESMTP id KNJgv841fj-1 for <resource-collection-car@example.org>; | with ESMTP id KNJgv841fj-1 for <resource-collection-car@example.org>; | ||||
Fri, 13 Jul 2012 14:54:15 +0200 (CEST) | Fri, 13 Jul 2012 14:54:15 +0200 (CEST) | ||||
Received: from 192.168.122.228 (localhost [127.0.0.1]) | Received: from 192.168.122.228 (localhost [127.0.0.1]) | ||||
(Authenticated sender: john.doe@example.org) | (Authenticated sender: john.doe@example.org) | ||||
by kolab.example.org (Postfix) with ESMTPSA id 0EBDA42E39 | by kolab.example.org (Postfix) with ESMTPSA id 0EBDA42E39 | ||||
for <resource-collection-car@example.org>; Fri, 13 Jul 2012 14:54:14 +0200 (CEST) | for <resource-collection-car@example.org>; Fri, 13 Jul 2012 14:54:14 +0200 (CEST) | ||||
Lint: PEP8 E501 line too long (85 > 79 characters) Lint: PEP8 E501: line too long (85 > 79 characters) | |||||
MIME-Version: 1.0 | MIME-Version: 1.0 | ||||
Content-Type: multipart/mixed; | Content-Type: multipart/mixed; | ||||
boundary="=_c8894dbdb8baeedacae836230e3436fd" | boundary="=_c8894dbdb8baeedacae836230e3436fd" | ||||
From: "Doe, John" <john.doe@example.org> | From: "Doe, John" <john.doe@example.org> | ||||
Date: Fri, 13 Jul 2012 13:54:14 +0100 | Date: Fri, 13 Jul 2012 13:54:14 +0100 | ||||
Message-ID: <240fe7ae7e139129e9eb95213c1016d7@example.org> | Message-ID: <240fe7ae7e139129e9eb95213c1016d7@example.org> | ||||
X-Sender: john.doe@example.org | X-Sender: john.doe@example.org | ||||
User-Agent: Roundcube Webmail/0.9-0.3.el6.kolab_3.0 | User-Agent: Roundcube Webmail/0.9-0.3.el6.kolab_3.0 | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | |||||
END:VEVENT | END:VEVENT | ||||
END:VCALENDAR | END:VCALENDAR | ||||
--=_c8894dbdb8baeedacae836230e3436fd-- | --=_c8894dbdb8baeedacae836230e3436fd-- | ||||
""") | """) | ||||
self.assertTrue(message.is_multipart()) | self.assertTrue(message.is_multipart()) | ||||
itip_methods = [ "REQUEST" ] | itip_methods = ["REQUEST"] | ||||
# Check each part | # Check each part | ||||
for part in message.walk(): | for part in message.walk(): | ||||
# The iTip part MUST be Content-Type: text/calendar (RFC 6047, | # The iTip part MUST be Content-Type: text/calendar (RFC 6047, | ||||
# section 2.4) | # section 2.4) | ||||
if part.get_content_type() == "text/calendar": | if part.get_content_type() == "text/calendar": | ||||
if not part.get_param('method') in itip_methods: | if not part.get_param('method') in itip_methods: | ||||
raise Exception, "method not interesting" | raise Exception("method not interesting") | ||||
# Get the itip_payload | # Get the itip_payload | ||||
itip_payload = part.get_payload(decode=True) | itip_payload = part.get_payload(decode=True) | ||||
# Python iCalendar prior to 3.0 uses "from_string". | # Python iCalendar prior to 3.0 uses "from_string". | ||||
if hasattr(icalendar.Calendar, 'from_ical'): | if hasattr(icalendar.Calendar, 'from_ical'): | ||||
cal = icalendar.Calendar.from_ical(itip_payload) | cal = icalendar.Calendar.from_ical(itip_payload) | ||||
elif hasattr(icalendar.Calendar, 'from_string'): | elif hasattr(icalendar.Calendar, 'from_string'): | ||||
cal = icalendar.Calendar.from_string(itip_payload) | cal = icalendar.Calendar.from_string(itip_payload) | ||||
# If we can't read it, we're out | # If we can't read it, we're out | ||||
else: | else: | ||||
return [] | return [] | ||||
def test_002_from_message(self): | def test_002_from_message(self): | ||||
message = message_from_string("""Received: from localhost (localhost [127.0.0.1]) | message = message_from_string("""Received: from localhost (localhost [127.0.0.1]) | ||||
by kolab.example.org (Postfix) with ESMTP id 513B942E10 | by kolab.example.org (Postfix) with ESMTP id 513B942E10 | ||||
for <resource-collection-car@example.org>; Fri, 13 Jul 2012 14:54:16 +0200 (CEST) | for <resource-collection-car@example.org>; Fri, 13 Jul 2012 14:54:16 +0200 (CEST) | ||||
Lint: PEP8 E501 line too long (85 > 79 characters) Lint: PEP8 E501: line too long (85 > 79 characters) | |||||
X-Virus-Scanned: amavisd-new at example.org | X-Virus-Scanned: amavisd-new at example.org | ||||
X-Spam-Flag: NO | X-Spam-Flag: NO | ||||
X-Spam-Score: 0.551 | X-Spam-Score: 0.551 | ||||
X-Spam-Level: | X-Spam-Level: | ||||
X-Spam-Status: No, score=0.551 tagged_above=-10 required=6.2 | X-Spam-Status: No, score=0.551 tagged_above=-10 required=6.2 | ||||
tests=[ALL_TRUSTED=-1, DNS_FROM_RFC_DSN=0.001, | 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] | NORMAL_HTTP_TO_IP=0.001, TVD_RCVD_IP=0.054, TVD_RCVD_IP4=1.495] | ||||
autolearn=no | autolearn=no | ||||
Received: from kolab.example.org ([127.0.0.1]) | Received: from kolab.example.org ([127.0.0.1]) | ||||
by localhost (kolab.example.org [127.0.0.1]) (amavisd-new, port 10024) | by localhost (kolab.example.org [127.0.0.1]) (amavisd-new, port 10024) | ||||
with ESMTP id KNJgv841fj-1 for <resource-collection-car@example.org>; | with ESMTP id KNJgv841fj-1 for <resource-collection-car@example.org>; | ||||
Fri, 13 Jul 2012 14:54:15 +0200 (CEST) | Fri, 13 Jul 2012 14:54:15 +0200 (CEST) | ||||
Received: from 192.168.122.228 (localhost [127.0.0.1]) | Received: from 192.168.122.228 (localhost [127.0.0.1]) | ||||
(Authenticated sender: john.doe@example.org) | (Authenticated sender: john.doe@example.org) | ||||
by kolab.example.org (Postfix) with ESMTPSA id 0EBDA42E39 | by kolab.example.org (Postfix) with ESMTPSA id 0EBDA42E39 | ||||
for <resource-collection-car@example.org>; Fri, 13 Jul 2012 14:54:14 +0200 (CEST) | for <resource-collection-car@example.org>; Fri, 13 Jul 2012 14:54:14 +0200 (CEST) | ||||
Lint: PEP8 E501 line too long (85 > 79 characters) Lint: PEP8 E501: line too long (85 > 79 characters) | |||||
MIME-Version: 1.0 | MIME-Version: 1.0 | ||||
Content-Type: multipart/mixed; | Content-Type: multipart/mixed; | ||||
boundary="=_c8894dbdb8baeedacae836230e3436fd" | boundary="=_c8894dbdb8baeedacae836230e3436fd" | ||||
From: "Doe, John" <john.doe@example.org> | From: "Doe, John" <john.doe@example.org> | ||||
Date: Fri, 13 Jul 2012 13:54:14 +0100 | Date: Fri, 13 Jul 2012 13:54:14 +0100 | ||||
Message-ID: <240fe7ae7e139129e9eb95213c1016d7@example.org> | Message-ID: <240fe7ae7e139129e9eb95213c1016d7@example.org> | ||||
X-Sender: john.doe@example.org | X-Sender: john.doe@example.org | ||||
User-Agent: Roundcube Webmail/0.9-0.3.el6.kolab_3.0 | User-Agent: Roundcube Webmail/0.9-0.3.el6.kolab_3.0 | ||||
▲ Show 20 Lines • Show All 48 Lines • ▼ Show 20 Lines | |||||
END:VEVENT | END:VEVENT | ||||
END:VCALENDAR | END:VCALENDAR | ||||
--=_c8894dbdb8baeedacae836230e3436fd-- | --=_c8894dbdb8baeedacae836230e3436fd-- | ||||
""") | """) | ||||
self.assertTrue(message.is_multipart()) | self.assertTrue(message.is_multipart()) | ||||
itip_methods = [ "REQUEST" ] | itip_methods = ["REQUEST"] | ||||
# Check each part | # Check each part | ||||
for part in message.walk(): | for part in message.walk(): | ||||
# The iTip part MUST be Content-Type: text/calendar (RFC 6047, | # The iTip part MUST be Content-Type: text/calendar (RFC 6047, | ||||
# section 2.4) | # section 2.4) | ||||
if part.get_content_type() == "text/calendar": | if part.get_content_type() == "text/calendar": | ||||
if not part.get_param('method') in itip_methods: | if not part.get_param('method') in itip_methods: | ||||
raise Exception, "method not interesting" | raise Exception("method not interesting") | ||||
# Get the itip_payload | # Get the itip_payload | ||||
itip_payload = part.get_payload(decode=True) | itip_payload = part.get_payload(decode=True) | ||||
# Python iCalendar prior to 3.0 uses "from_string". | # Python iCalendar prior to 3.0 uses "from_string". | ||||
if hasattr(icalendar.Calendar, 'from_ical'): | if hasattr(icalendar.Calendar, 'from_ical'): | ||||
cal = icalendar.Calendar.from_ical(itip_payload) | cal = icalendar.Calendar.from_ical(itip_payload) | ||||
elif hasattr(icalendar.Calendar, 'from_string'): | elif hasattr(icalendar.Calendar, 'from_string'): | ||||
cal = icalendar.Calendar.from_string(itip_payload) | cal = icalendar.Calendar.from_string(itip_payload) | ||||
# If we can't read it, we're out | # If we can't read it, we're out | ||||
else: | else: | ||||
return [] | return [] |
line too long (85 > 79 characters)