[CalendarServer-changes] [2770] CalendarServer/branches/users/sagen/mailgateway-implicit-2745/ twistedcaldav
source_changes at macosforge.org
source_changes at macosforge.org
Tue Aug 5 10:03:13 PDT 2008
Revision: 2770
http://trac.macosforge.org/projects/calendarserver/changeset/2770
Author: sagen at apple.com
Date: 2008-08-05 10:03:13 -0700 (Tue, 05 Aug 2008)
Log Message:
-----------
Settings are no longer hard-coded
Modified Paths:
--------------
CalendarServer/branches/users/sagen/mailgateway-implicit-2745/twistedcaldav/cluster.py
CalendarServer/branches/users/sagen/mailgateway-implicit-2745/twistedcaldav/config.py
CalendarServer/branches/users/sagen/mailgateway-implicit-2745/twistedcaldav/mail.py
CalendarServer/branches/users/sagen/mailgateway-implicit-2745/twistedcaldav/scheduling/imip.py
Modified: CalendarServer/branches/users/sagen/mailgateway-implicit-2745/twistedcaldav/cluster.py
===================================================================
--- CalendarServer/branches/users/sagen/mailgateway-implicit-2745/twistedcaldav/cluster.py 2008-08-05 00:51:31 UTC (rev 2769)
+++ CalendarServer/branches/users/sagen/mailgateway-implicit-2745/twistedcaldav/cluster.py 2008-08-05 17:03:13 UTC (rev 2770)
@@ -310,8 +310,8 @@
monitor.addProcess('memcached', memcachedArgv, env=parentEnv)
- if (config.MailGateway["Enabled"] and
- config.MailGateway["MailGatewayHost"] == "localhost"):
+ if (config.Scheduling['iMIP']['Enabled'] and
+ config.Scheduling['iMIP']["MailGatewayServer"] == "localhost"):
log.msg("Adding mail gateway service")
mailGatewayArgv = [
Modified: CalendarServer/branches/users/sagen/mailgateway-implicit-2745/twistedcaldav/config.py
===================================================================
--- CalendarServer/branches/users/sagen/mailgateway-implicit-2745/twistedcaldav/config.py 2008-08-05 00:51:31 UTC (rev 2769)
+++ CalendarServer/branches/users/sagen/mailgateway-implicit-2745/twistedcaldav/config.py 2008-08-05 17:03:13 UTC (rev 2770)
@@ -195,14 +195,21 @@
"iMIP": {
"Enabled" : False, # Server-to-iMIP protocol
+ "MailGatewayServer" : "localhost",
+ "MailGatewayPort" : 62311,
"Sending": {
"Server" : "", # SMTP server to relay messages through
- "Port" : 587, # SMTP server port to relay messages through
+ "Port" : 25, # SMTP server port to relay messages through
+ "Address" : "", # 'From' address for server
},
"Receiving": {
"Server" : "", # Server to retrieve email messages from
- "Port" : 0, # Server port to retrieve email messages from
- "Type" : "", # Type of message access server: 'pop3' or 'imap'
+ "UseSSL" : True, # Server to retrieve email messages from
+ "Port" : 995, # Server port to retrieve email messages from
+ "Type" : "pop", # Type of message access server: 'pop' or 'imap'
+ "PollingSeconds" : 60, # How often to fetch mail
+ "Username" : "", # For account receiving email
+ "Password" : "", # For account receiving email
},
"AddressPatterns" : [], # Reg-ex patterns to match iMIP-able calendar user addresses
},
@@ -217,39 +224,6 @@
#
- # Mail Gateway
- #
- "MailGateway" : {
- "Enabled": False,
- "MailGatewayHost" : "localhost",
- "MailGatewayPort" : 62310,
-
- "Services" : [
- {
- "Service" : "twistedcaldav.mail.POP3Service",
- "Enabled" : False,
- "Host" : "", # "pop.host.name"
- "UseSSL" : True,
- "Port" : 995,
- "PollingSeconds" : 60,
- "Username" : "",
- "Password" : "",
- },
- {
- "Service" : "twistedcaldav.mail.IMAP4Service",
- "Enabled" : False,
- "Host" : "", # "imap.host.name"
- "UseSSL" : True,
- "Port" : 993,
- "PollingSeconds" : 60,
- "Username" : "",
- "Password" : "",
- },
- ]
- },
-
-
- #
# Implementation details
#
# The following are specific to how the server is built, and useful
@@ -328,7 +302,6 @@
self.updateDropBox,
self.updateLogLevels,
self.updateThreadPoolSize,
- self.updateMailGateway,
]
def __str__(self):
@@ -520,30 +493,7 @@
configDict = _cleanup(configDict)
self.update(configDict)
- @staticmethod
- def updateMailGateway(self, items):
- #
- # Mail Gateway
- #
- for service in self.MailGateway["Services"]:
- if service["Enabled"]:
- self.MailGateway["Enabled"] = True
- break
- else:
- self.MailGateway["Enabled"] = False
- for service in self.MailGateway["Services"]:
- if (
- service["Service"] in ("twistedcaldav.mail.POP3Service",
- "twistedcaldav.mail.IMAP4Service") and
- service["Enabled"]
- ):
- for key, value in service.iteritems():
- if not value:
- raise ConfigurationError("Invalid %s for %s: %r"
- % (key, service["Service"], value))
-
-
def _mergeData(oldData, newData):
for key, value in newData.iteritems():
if isinstance(value, (dict,)):
Modified: CalendarServer/branches/users/sagen/mailgateway-implicit-2745/twistedcaldav/mail.py
===================================================================
--- CalendarServer/branches/users/sagen/mailgateway-implicit-2745/twistedcaldav/mail.py 2008-08-05 00:51:31 UTC (rev 2769)
+++ CalendarServer/branches/users/sagen/mailgateway-implicit-2745/twistedcaldav/mail.py 2008-08-05 17:03:13 UTC (rev 2770)
@@ -230,9 +230,14 @@
data = str(calendar)
- useSSL = False
- host = "localhost"
- port = 8008
+ if config.SSLPort:
+ useSSL = True
+ port = config.SSLPort
+ else:
+ useSSL = False
+ port = config.HTTPPort
+
+ host = config.ServerHostName
path = "email-inbox"
scheme = "https:" if useSSL else "http:"
url = "%s//%s:%d/%s/" % (scheme, host, port, path)
@@ -361,7 +366,7 @@
# Service
#
-class MailGatewayServiceMaker(object):
+class MailGatewayServiceMaker(LoggingMixIn):
implements(IPlugin, service.IServiceMaker)
tapname = "caldav_mailgateway"
@@ -372,15 +377,25 @@
multiService = service.MultiService()
- mailer = MailHandler()
+ settings = config.Scheduling['iMIP']
+ if settings['Enabled']:
+ mailer = MailHandler()
- for settings in config.MailGateway["Services"]:
- if settings["Enabled"]:
- client = namedClass(settings["Service"])(settings, mailer)
- client.setServiceParent(multiService)
+ mailType = settings['Receiving']['Type']
+ if mailType.lower().startswith('pop'):
+ client = POP3Service(settings['Receiving'], mailer)
+ elif mailType.lower().startswith('imap'):
+ client = IMAP4Service(settings['Receiving'], mailer)
+ else:
+ # TODO: raise error?
+ self.log_error("Invalid iMIP type in configuration: %s" %
+ (mailType,))
+ return multiService
- IScheduleService(mailer).setServiceParent(multiService)
+ client.setServiceParent(multiService)
+ IScheduleService(settings, mailer).setServiceParent(multiService)
+
return multiService
@@ -389,13 +404,14 @@
#
class IScheduleService(service.Service, LoggingMixIn):
- def __init__(self, mailer): # TODO: settings
+ def __init__(self, settings, mailer):
+ self.settings = settings
self.mailer = mailer
root = resource.Resource()
root.putChild('', self.HomePage())
root.putChild('email-inbox', self.IScheduleInbox(mailer))
self.site = server.Site(root)
- self.server = internet.TCPServer(62311, self.site)
+ self.server = internet.TCPServer(settings['MailGatewayPort'], self.site)
def startService(self):
self.server.startService()
@@ -469,8 +485,13 @@
if token is None:
token = self.db.createToken(organizer, attendee)
- calendar.getOrganizerProperty().setValue("mailto:SERVER_ADDRESS+%s at example.com" % (token,))
- # TODO: grab server email address from config
+ settings = config.Scheduling['iMIP']['Sending']
+ fullServerAddress = settings['Address']
+ name, serverAddress = email.utils.parseaddr(fullServerAddress)
+ pre, post = serverAddress.split('@')
+ addressWithToken = "%s+%s@%s" % (pre, token, post)
+ calendar.getOrganizerProperty().setValue("mailto:%s" %
+ (addressWithToken,))
message = self._generateTemplateMessage(calendar)
@@ -480,15 +501,17 @@
if not organizer.startswith("mailto:"):
raise ValueError("ORGANIZER address '%s' must be mailto: for iMIP operation." % (organizer,))
organizer = organizer[7:]
- fromAddr = "SERVER_ADDRESS at example.com"
+ fromAddr = serverAddress
+ toAddr = attendee
message = message.replace("${fromaddress}", fromAddr)
message = message.replace("${replytoaddress}", organizer)
if not attendee.startswith("mailto:"):
raise ValueError("ATTENDEE address '%s' must be mailto: for iMIP operation." % (attendee,))
attendee = attendee[7:]
- sendit = message.replace("${toaddress}", attendee)
- yield sendmail('smtp.example.com', fromAddr, attendee, sendit, port=25)
+ message = message.replace("${toaddress}", attendee)
+ yield sendmail(settings['Server'], fromAddr, toAddr, message,
+ port=settings['Port'])
def _generateTemplateMessage(self, calendar):
@@ -665,11 +688,13 @@
def __init__(self, settings, mailer):
if settings["UseSSL"]:
- self.client = internet.SSLClient(settings["Host"], settings["Port"],
+ self.client = internet.SSLClient(settings["Server"],
+ settings["Port"],
POP3DownloadFactory(settings, mailer),
ssl.ClientContextFactory())
else:
- self.client = internet.TCPClient(settings["Host"], settings["Port"],
+ self.client = internet.TCPClient(settings["Server"],
+ settings["Port"],
POP3DownloadFactory(settings, mailer))
self.mailer = mailer
@@ -770,7 +795,7 @@
# extract the token from the To header
name, addr = email.utils.parseaddr(parsedMessage['To'])
if addr:
- # addr looks like: SERVER_ADDRESS+token at example.com
+ # addr looks like: server_address+token at example.com
try:
pre, post = addr.split('@')
pre, token = pre.split('+')
@@ -806,11 +831,13 @@
def __init__(self, settings, mailer):
if settings["UseSSL"]:
- self.client = internet.SSLClient(settings["Host"], settings["Port"],
+ self.client = internet.SSLClient(settings["Server"],
+ settings["Port"],
IMAP4DownloadFactory(settings, mailer),
ssl.ClientContextFactory())
else:
- self.client = internet.TCPClient(settings["Host"], settings["Port"],
+ self.client = internet.TCPClient(settings["Server"],
+ settings["Port"],
IMAP4DownloadFactory(settings, mailer))
self.mailer = mailer
Modified: CalendarServer/branches/users/sagen/mailgateway-implicit-2745/twistedcaldav/scheduling/imip.py
===================================================================
--- CalendarServer/branches/users/sagen/mailgateway-implicit-2745/twistedcaldav/scheduling/imip.py 2008-08-05 00:51:31 UTC (rev 2769)
+++ CalendarServer/branches/users/sagen/mailgateway-implicit-2745/twistedcaldav/scheduling/imip.py 2008-08-05 17:03:13 UTC (rev 2770)
@@ -95,7 +95,9 @@
if reactor is None:
from twisted.internet import reactor
- url = "http://localhost:62311/email-inbox"
+ mailGatewayServer = config.Scheduling['iMIP']['MailGatewayServer']
+ mailGatewayPort = config.Scheduling['iMIP']['MailGatewayPort']
+ url = "http://%s:%d/email-inbox" % (mailGatewayServer, mailGatewayPort)
headers = {
'Content-Type' : 'text/calendar',
'Originator' : fromAddr,
@@ -103,6 +105,6 @@
}
factory = client.HTTPClientFactory(url, method='POST', headers=headers,
postdata=caldata)
- reactor.connectTCP("localhost", 62311, factory)
+ reactor.connectTCP(mailGatewayServer, mailGatewayPort, factory)
return factory.deferred
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20080805/79758a52/attachment-0001.html
More information about the calendarserver-changes
mailing list