diff --git a/tabellio/icalimport/icalimport.py b/tabellio/icalimport/icalimport.py index e57e7e5..cc157a0 100644 --- a/tabellio/icalimport/icalimport.py +++ b/tabellio/icalimport/icalimport.py @@ -2,16 +2,32 @@ import datetime import urllib2 import vobject +from zope import component + from Products.CMFCore.WorkflowCore import WorkflowException from Products.CMFCore.utils import getToolByName from Products.Five.browser import BrowserView +from plone.registry.interfaces import IRegistry + +from tabellio.config.interfaces import ITabellioSettings class IcalImport(BrowserView): def __call__(self): + self.settings = component.getUtility(IRegistry).forInterface(ITabellioSettings, False) self.plone_utils = getToolByName(self.context, 'plone_utils') self.portal_workflow = getToolByName(self.context, 'portal_workflow') url = self.request.form.get('url') - content = urllib2.urlopen(url).read() + + if self.settings.ical_username: + password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm() + password_mgr.add_password(None, url, + self.settings.ical_username, self.settings.ical_password) + handler = urllib2.HTTPBasicAuthHandler(password_mgr) + opener = urllib2.build_opener(handler) + urlopen = opener.open + else: + urlopen = urllib2.urlopen + content = urlopen(url).read() parsed_cal = vobject.readOne(content) for vevent in parsed_cal.vevent_list: title = vevent.summary.value