コード例 #1
0
ファイル: utils.py プロジェクト: syslabcom/slc.mailrouter
def store_name(context, name):
    errors = {}
    storage = queryUtility(IFriendlyNameStorage)
    target = IUUID(context)
    if not name:
        errors.update({"name": _(u"You must provide a friendly name.")})
    elif not re.match(r"^[a-zA-Z0-9_./-]+$", name):
        errors.update({"name": _(u"Forbidden characters in friendly name. " "Allowed characters: a-zA-Z0-9_./-")})
    if not errors:
        existing = storage.get(name)
        if existing and not existing == target:
            errors.update({"name": _(u"This name is already in use.")})
        else:
            storage.remove(target)  # No effect if target isn't mapped
            storage.add(target, name)

    return errors
コード例 #2
0
    def deliver(self, msg, user, recipient):
        logger.info(
            'MailToFolderRouter called with message %s from %s to %s' %
            (msg.get('Message-ID'), user.getProperty('email'), recipient))
        local_part = recipient.split('@')[0].lower()

        assert len(local_part) <= 50, \
            "local_part must have a reasonable length"

        # Find the right context. Do that by looking up local_part
        # in our local friendly-name storage, and if not found, check
        # if it looks like a uid. Then look up the uid.
        storage = queryUtility(IFriendlyNameStorage)
        uid = storage.get(local_part, None)
        if uid is None and UIDRE.match(local_part) is not None:
            uid = local_part

        if uid is None:
            # local_part is not a uid and is not mapped onto a folder,
            # this is not something we can handle.
            return False

        # Drop privileges to the right user
        self.acl_users = getToolByName(self.site, 'acl_users')
        newSecurityManager(None, user.__of__(self.acl_users))
        context = api.content.get(UID=uid)
        if not context:
            raise NotFoundError(_("Folder not found"))

        if not IFolderish.providedBy(context):
            raise NotFoundError(
                _("Target %s is not a folder" % context.getId()))

        result = False

        # Check permissions
        if not getSecurityManager().checkPermission('Add portal content',
                                                    context):
            raise PermissionError(
                _("%s has insufficient privileges on %s" %
                  (user.getProperty('email'), context.getId())))

        # Defer actual work to an adapter
        result = IMailImportAdapter(context).add(msg)

        return result
コード例 #3
0
ファイル: utils.py プロジェクト: syslabcom/slc.mailrouter
    def deliver(self, msg, user, recipient):
        logger.info(
            "MailToFolderRouter called with message %s from %s to %s"
            % (msg.get("Message-ID"), user.getProperty("email"), recipient)
        )
        local_part = recipient.split("@")[0].lower()

        assert len(local_part) <= 50, "local_part must have a reasonable length"

        # Find the right context. Do that by looking up local_part
        # in our local friendly-name storage, and if not found, check
        # if it looks like a uid. Then look up the uid.
        storage = queryUtility(IFriendlyNameStorage)
        uid = storage.get(local_part, None)
        if uid is None and UIDRE.match(local_part) is not None:
            uid = local_part

        if uid is None:
            # local_part is not a uid and is not mapped onto a folder,
            # this is not something we can handle.
            return False

        # Drop privileges to the right user
        self.acl_users = getToolByName(self.site, "acl_users")
        newSecurityManager(None, user.__of__(self.acl_users))
        context = api.content.get(UID=uid)
        if not context:
            raise NotFoundError(_("Folder not found"))

        if not IFolderish.providedBy(context):
            raise NotFoundError(_("Target %s is not a folder" % context.getId()))

        result = False

        # Check permissions
        if not getSecurityManager().checkPermission("Add portal content", context):
            raise PermissionError(
                _("%s has insufficient privileges on %s" % (user.getProperty("email"), context.getId()))
            )

        # Defer actual work to an adapter
        result = IMailImportAdapter(context).add(msg)

        return result
コード例 #4
0
    def __call__(self):
        errors = {}
        if self.request.get('form.submitted', None) is not None:
            errors = store_name(self.context, self.request.get('name', ''))

        self.request['errors'] = errors
        if not errors and 'redirect' in self.request:
            IStatusMessage(self.request).add(_(u"Mail route enabled."))
            return self.request.RESPONSE.redirect(self.request['redirect'])
        return self.addtemplate()
コード例 #5
0
    def __call__(self):
        errors = {}
        if self.request.get('form.submitted', None) is not None:
            errors = store_name(self.context, self.request.get('name', ''))

        self.request['errors'] = errors
        if not errors and 'redirect' in self.request:
            IStatusMessage(self.request).add(_(u"Mail route enabled."))
            return self.request.RESPONSE.redirect(self.request['redirect'])
        return self.addtemplate()
コード例 #6
0
def store_name(context, name):
    errors = {}
    storage = queryUtility(IFriendlyNameStorage)
    target = IUUID(context)
    if not name:
        errors.update({'name': _(u'You must provide a friendly name.')})
    elif not re.match(r'^[a-zA-Z0-9_./-]+$', name):
        errors.update({
            'name':
            _(u'Forbidden characters in friendly name. '
              'Allowed characters: a-zA-Z0-9_./-')
        })
    if not errors:
        existing = storage.get(name)
        if existing and not existing == target:
            errors.update({'name': _(u'This name is already in use.')})
        else:
            storage.remove(target)  # No effect if target isn't mapped
            storage.add(target, name)

    return errors
コード例 #7
0
ファイル: utils.py プロジェクト: syslabcom/slc.mailrouter
    def __call__(self, site, msg):
        self.site = site
        self.acl_users = getToolByName(site, "acl_users")

        sender_from = msg.get("From")
        sender_return_path = msg.get("Return-Path")

        sender_from = email.Utils.parseaddr(sender_from)[1]
        sender_return_path = email.Utils.parseaddr(sender_return_path)[1]
        recipient = email.Utils.parseaddr(msg.get("X-Original-To"))[1]

        if not recipient:
            logger.info("BaseMailRouter could not identify a recipient." + "No X-Original-To header found.")
        user = get_user_by_email(sender_return_path)
        if not user:
            user = get_user_by_email(sender_from)
        if not user:
            raise PermissionError(_("No permitted sender address: %s, %s" % (sender_return_path, sender_from)))

        return self.deliver(msg, user, recipient)
コード例 #8
0
    def __call__(self, site, msg):
        self.site = site
        self.acl_users = getToolByName(site, 'acl_users')

        sender_from = msg.get('From')
        sender_return_path = msg.get('Return-Path')

        sender_from = email.Utils.parseaddr(sender_from)[1]
        sender_return_path = email.Utils.parseaddr(sender_return_path)[1]
        recipient = email.Utils.parseaddr(
            msg.get('X-Original-To', msg.get('To')))[1]

        if not recipient:
            logger.info('BaseMailRouter could not identify a recipient.' +
                        'No X-Original-To header found.')
        user = get_user_by_email(sender_return_path)
        if not user:
            user = get_user_by_email(sender_from)
        if not user:
            raise PermissionError(
                _("No permitted sender address: %s, %s" %
                  (sender_return_path, sender_from)))

        return self.deliver(msg, user, recipient)