def inbound(self): msg = self.msg() settings = getUtility(IRegistry).forInterface(IMailSettings) if settings.unwrap_mail: # if we find an attached mail, use this instead of the whole one msg = utils.unwrap_attached_msg(msg) user = self.get_user() sm = getSecurityManager() newSecurityManager(self.request, user) try: destination = self.get_destination() createMailInContainer(destination, msg.as_string()) except Unauthorized: raise exceptions.PermissionDenied(self.msg(), user) except ValueError: raise exceptions.DisallowedSubobjectType(self.msg(), user) finally: setSecurityManager(sm)
def inbound(self): msg = self.msg() settings = getUtility(IRegistry).forInterface(IMailSettings) if settings.unwrap_mail: # if we find an attached mail, use this instead of the whole one msg = utils.unwrap_attached_msg(msg) user = self.get_user() sm = getSecurityManager() newSecurityManager(self.request, user) try: destination = self.get_destination() createMailInContainer(destination, msg.as_string()) except Unauthorized: log.warn('User %r is not allowed to create mail ' 'in %r' % (user, destination)) raise exceptions.PermissionDenied(self.msg(), user) except ValueError: # ValueError can also be caused by non-intid destination address if 'destination' in locals(): log.warn('Attempt to create mail in %r' % destination) raise exceptions.DisallowedSubobjectType(self.msg(), user) finally: setSecurityManager(sm)
def test_unwrap_attached_msg(self): msg = utils.unwrap_attached_msg(self.msg_fwd_attachment) self.assertEquals(msg.get('Subject'), 'Lorem Ipsum')