[CalendarServer-changes] [10855] CalendarServer/branches/users/sagen/testing/twistedcaldav/ scheduling/imip
source_changes at macosforge.org
source_changes at macosforge.org
Tue Mar 5 15:29:47 PST 2013
Revision: 10855
http://trac.calendarserver.org//changeset/10855
Author: sagen at apple.com
Date: 2013-03-05 15:29:47 -0800 (Tue, 05 Mar 2013)
Log Message:
-----------
Re-remove imip icon code and fix language support
Modified Paths:
--------------
CalendarServer/branches/users/sagen/testing/twistedcaldav/scheduling/imip/outbound.py
CalendarServer/branches/users/sagen/testing/twistedcaldav/scheduling/imip/test/test_outbound.py
Removed Paths:
-------------
CalendarServer/branches/users/sagen/testing/twistedcaldav/scheduling/imip/resource.py
Modified: CalendarServer/branches/users/sagen/testing/twistedcaldav/scheduling/imip/outbound.py
===================================================================
--- CalendarServer/branches/users/sagen/testing/twistedcaldav/scheduling/imip/outbound.py 2013-03-05 21:53:50 UTC (rev 10854)
+++ CalendarServer/branches/users/sagen/testing/twistedcaldav/scheduling/imip/outbound.py 2013-03-05 23:29:47 UTC (rev 10855)
@@ -23,7 +23,6 @@
from cStringIO import StringIO
import os
-from email.mime.image import MIMEImage
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import email.utils
@@ -39,7 +38,7 @@
from twisted.web.template import XMLString, TEMPLATE_NAMESPACE, Element, renderer, flattenString, tags
from twistedcaldav.config import config
from twistedcaldav.ical import Component
-from twistedcaldav.localization import translationTo, _
+from twistedcaldav.localization import translationTo, _, getLanguage
from twistedcaldav.scheduling.cuaddress import normalizeCUAddr
from twistedcaldav.scheduling.imip.smtpsender import SMTPSender
from txdav.common.datastore.sql_tables import schema
@@ -81,7 +80,7 @@
smtpSender = SMTPSender(settings.Username, settings.Password,
settings.UseSSL, settings.Server, settings.Port)
cls.mailSender = MailSender(settings.Address,
- settings.SuppressionDays, smtpSender=smtpSender)
+ settings.SuppressionDays, smtpSender, getLanguage(config))
return cls.mailSender
@inlineCallbacks
@@ -302,15 +301,15 @@
Generates outbound IMIP messages and sends them.
"""
- def __init__(self, address, suppressionDays, smtpSender):
+ def __init__(self, address, suppressionDays, smtpSender, language):
self.address = address
self.suppressionDays = suppressionDays
self.smtpSender = smtpSender
+ self.language = language
@inlineCallbacks
- def outbound(self, txn, originator, recipient, calendar, language='en',
- onlyAfter=None):
+ def outbound(self, txn, originator, recipient, calendar, onlyAfter=None):
"""
Generates and sends an outbound IMIP message.
@@ -473,7 +472,7 @@
msgId, message = self.generateEmail(inviteState, calendar, orgEmail,
orgCN, attendees, formattedFrom, addressWithToken, recipient,
- language=language)
+ language=self.language)
try:
success = (yield self.smtpSender.sendMessage(fromAddr, toAddr,
@@ -484,32 +483,6 @@
returnValue(False)
- def getIconPath(self, details, canceled, language='en'):
- iconDir = config.Scheduling.iMIP.MailIconsDirectory.rstrip("/")
-
- if canceled:
- iconName = "canceled.png"
- iconPath = os.path.join(iconDir, iconName)
- if os.path.exists(iconPath):
- return iconPath
- else:
- return None
-
- else:
- month = int(details['month'])
- day = int(details['day'])
- with translationTo(language) as trans:
- monthName = trans.monthAbbreviation(month)
- iconName = "%02d.png" % (day,)
- iconPath = os.path.join(iconDir, monthName.encode("utf-8"), iconName)
- if not os.path.exists(iconPath):
- # Try the generic (numeric) version
- iconPath = os.path.join(iconDir, "%02d" % (month,), iconName)
- if not os.path.exists(iconPath):
- return None
- return iconPath
-
-
def generateEmail(self, inviteState, calendar, orgEmail, orgCN,
attendees, fromAddress, replyToAddress, toAddress,
language='en'):
@@ -562,18 +535,16 @@
details = self.getEventDetails(calendar, language=language)
canceled = (calendar.propertyValue("METHOD") == "CANCEL")
- iconPath = self.getIconPath(details, canceled, language=language)
subjectFormat, labels = localizedLabels(language, canceled, inviteState)
details.update(labels)
details['subject'] = subjectFormat % {'summary' : details['summary']}
- details['iconName'] = iconName = "calicon.png"
plainText = self.renderPlainText(details, (orgCN, orgEmail),
attendees, canceled)
- [addIcon, htmlText] = self.renderHTML(details, (orgCN, orgEmail),
+ htmlText = self.renderHTML(details, (orgCN, orgEmail),
attendees, canceled)
msg = MIMEMultipart()
@@ -599,19 +570,6 @@
msgHtml = MIMEText(htmlText, "html", "UTF-8")
msgHtmlRelated.attach(msgHtml)
- # an image for html version
- if addIcon and iconPath != None and os.path.exists(iconPath):
-
- with open(iconPath) as iconFile:
- msgIcon = MIMEImage(iconFile.read(),
- _subtype='png;x-apple-mail-type=stationery;name="%s"' %
- (iconName,))
-
- msgIcon.add_header("Content-ID", "<%s>" % (iconName,))
- msgIcon.add_header("Content-Disposition", "inline;filename=%s" %
- (iconName,))
- msgHtmlRelated.attach(msgIcon)
-
calendarText = str(calendar)
# the icalendar attachment
self.log_debug("Mail gateway sending calendar body: %s"
@@ -663,10 +621,7 @@
Render HTML message part based on invitation details and a flag
indicating whether the message is a cancellation.
- @return: a 2-tuple of (should add icon (C{bool}), html text (C{str},
- representing utf-8 encoded bytes)). The first element indicates
- whether the MIME generator needs to add a C{cid:} icon image part to
- satisfy the HTML links.
+ @return: html text (C{str}, representing utf-8 encoded bytes)).
"""
orgCN, orgEmail = organizer
@@ -727,13 +682,9 @@
textCollector = []
flattenString(None, EmailElement()).addCallback(textCollector.append)
htmlText = textCollector[0]
+ return htmlText
- # If the template refers to an icon in a cid: link, it needs to be added
- # in the MIME.
- addIcon = (htmlTemplate.find("cid:%(iconName)s") != -1)
- return (addIcon, htmlText)
-
def getEventDetails(self, calendar, language='en'):
"""
Create a dictionary mapping slot names - specifically: summary,
Deleted: CalendarServer/branches/users/sagen/testing/twistedcaldav/scheduling/imip/resource.py
===================================================================
--- CalendarServer/branches/users/sagen/testing/twistedcaldav/scheduling/imip/resource.py 2013-03-05 21:53:50 UTC (rev 10854)
+++ CalendarServer/branches/users/sagen/testing/twistedcaldav/scheduling/imip/resource.py 2013-03-05 23:29:47 UTC (rev 10855)
@@ -1,223 +0,0 @@
-##
-# Copyright (c) 2005-2013 Apple Inc. All rights reserved.
-#
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-##
-
-from twext.python.log import Logger
-from twext.web2 import responsecode
-from twext.web2.dav.noneprops import NonePropertyStore
-from twext.web2.http import Response, HTTPError
-from twext.web2.http_headers import MimeType
-from twisted.internet.defer import succeed, inlineCallbacks, returnValue
-from twistedcaldav import caldavxml
-from twistedcaldav.config import config
-from twistedcaldav.directory.util import transactionFromRequest
-from twistedcaldav.ical import Component
-from twistedcaldav.localization import getLanguage
-from twistedcaldav.resource import CalDAVResource
-from twistedcaldav.scheduling.caldav.resource import deliverSchedulePrivilegeSet
-from twistedcaldav.scheduling.imip.scheduler import IMIPScheduler
-from txdav.xml import element as davxml
-
-__all__ = [
- "IMIPInboxResource",
- "IMIPReplyInboxResource",
- "IMIPInvitationInboxResource",
-]
-
-log = Logger()
-
-class IMIPInboxResource(CalDAVResource):
- """
- IMIP-delivery Inbox resource.
-
- Extends L{DAVResource} to provide IMIP delivery functionality.
- """
-
- def __init__(self, parent, store):
- """
- @param parent: the parent resource of this one.
- @param store: the store to use for transactions.
- """
- assert parent is not None
-
- CalDAVResource.__init__(
- self, principalCollections=parent.principalCollections()
- )
-
- self.parent = parent
- self._newStore = store
-
-
- def accessControlList(self, request, inheritance=True,
- expanding=False, inherited_aces=None):
-
- if not hasattr(self, "iMIPACL"):
- guid = config.Scheduling.iMIP.GUID
- self.iMIPACL = davxml.ACL(
- davxml.ACE(
- davxml.Principal(
- davxml.HRef.fromString("/principals/__uids__/%s/"
- % (guid,))
- ),
- davxml.Grant(
- davxml.Privilege(caldavxml.ScheduleDeliver()),
- ),
- ),
- )
-
- return succeed(self.iMIPACL)
-
-
- def resourceType(self):
- return davxml.ResourceType.ischeduleinbox
-
-
- def contentType(self):
- return MimeType.fromString("text/html; charset=utf-8")
-
-
- def isCollection(self):
- return False
-
-
- def isCalendarCollection(self):
- return False
-
-
- def isPseudoCalendarCollection(self):
- return False
-
-
- def deadProperties(self):
- if not hasattr(self, "_dead_properties"):
- self._dead_properties = NonePropertyStore(self)
- return self._dead_properties
-
-
- def etag(self):
- return succeed(None)
-
-
- def checkPreconditions(self, request):
- return None
-
-
- def render(self, request):
- output = """<html>
-<head>
-<title>IMIP Delivery Resource</title>
-</head>
-<body>
-<h1>IMIP Delivery Resource.</h1>
-</body
-</html>"""
-
- response = Response(200, {}, output)
- response.headers.setHeader("content-type", MimeType("text", "html"))
- return response
-
- ##
- # File
- ##
-
-
- def createSimilarFile(self, path):
- log.err("Attempt to create clone %r of resource %r" % (path, self))
- raise HTTPError(responsecode.NOT_FOUND)
-
- ##
- # ACL
- ##
-
-
- def defaultAccessControlList(self):
- privs = (
- davxml.Privilege(davxml.Read()),
- davxml.Privilege(caldavxml.ScheduleDeliver()),
- )
- if config.Scheduling.CalDAV.OldDraftCompatibility:
- privs += (davxml.Privilege(caldavxml.Schedule()),)
- return davxml.ACL(
- # DAV:Read, CalDAV:schedule-deliver for all principals (includes
- # anonymous)
- davxml.ACE(
- davxml.Principal(davxml.All()),
- davxml.Grant(*privs),
- davxml.Protected(),
- ),
- )
-
-
- def supportedPrivileges(self, request):
- return succeed(deliverSchedulePrivilegeSet)
-
-
-
-class IMIPReplyInboxResource(IMIPInboxResource):
-
- def renderHTTP(self, request):
- """
- Set up a transaction which will be used and committed by implicit
- scheduling.
- """
- self.transaction = transactionFromRequest(request, self._newStore)
- return super(IMIPReplyInboxResource, self).renderHTTP(request, self.transaction)
-
-
- @inlineCallbacks
- def http_POST(self, request):
- """
- The IMIP reply POST method (inbound)
- """
-
- # Check authentication and access controls
- yield self.authorize(request, (caldavxml.ScheduleDeliver(),))
-
- # Inject using the IMIPScheduler.
- scheduler = IMIPScheduler(request, self)
-
- # Do the POST processing treating this as a non-local schedule
- result = (yield scheduler.doSchedulingViaPOST(self.transaction, use_request_headers=True))
- returnValue(result.response())
-
-
-
-class IMIPInvitationInboxResource(IMIPInboxResource):
-
- def __init__(self, parent, store, mailer):
- super(IMIPInvitationInboxResource, self).__init__(parent, store)
- self.mailer = mailer
-
-
- @inlineCallbacks
- def http_POST(self, request):
- """
- The IMIP invitation POST method (outbound)
- """
-
- # Check authentication and access controls
- yield self.authorize(request, (caldavxml.ScheduleDeliver(),))
-
- # Compute token, add to db, generate email and send it
- calendar = (yield Component.fromIStream(request.stream))
- originator = request.headers.getRawHeaders("originator")[0]
- recipient = request.headers.getRawHeaders("recipient")[0]
- language = getLanguage(config)
-
- if not (yield self.mailer.outbound(originator,
- recipient, calendar, language=language)):
- returnValue(Response(code=responsecode.BAD_REQUEST))
-
- returnValue(Response(code=responsecode.OK))
Modified: CalendarServer/branches/users/sagen/testing/twistedcaldav/scheduling/imip/test/test_outbound.py
===================================================================
--- CalendarServer/branches/users/sagen/testing/twistedcaldav/scheduling/imip/test/test_outbound.py 2013-03-05 21:53:50 UTC (rev 10854)
+++ CalendarServer/branches/users/sagen/testing/twistedcaldav/scheduling/imip/test/test_outbound.py 2013-03-05 23:29:47 UTC (rev 10855)
@@ -93,7 +93,8 @@
augment.AugmentXMLDB(xmlFiles=(augmentsFile.path,)),
}
)
- self.sender = MailSender("server at example.com", 7, DummySMTPSender())
+ self.sender = MailSender("server at example.com", 7, DummySMTPSender(),
+ language="en")
def _getSender(ignored):
return self.sender
@@ -103,7 +104,6 @@
self.store.queuer.callWithNewProposals(self._proposalCallback)
def _proposalCallback(self, wp):
- # print("New proposal", wp)
self.wp = wp
@inlineCallbacks
@@ -271,7 +271,6 @@
inputOriginator,
inputRecipient,
Component.fromString(inputCalendar.replace("\n", "\r\n")),
- language="ja",
onlyAfter=PyCalendarDateTime(2010, 1, 1, 0, 0, 0)
)
yield txn.commit()
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20130305/17214c44/attachment-0001.html>
More information about the calendarserver-changes
mailing list