def _get_pending_list(self, pending_list, queue_name=None):
        list_out = []
        for user_email in pending_list.get_user_emails():
            posts = pending_list.get_posts(user_email)
            user_name = pending_list.get_user_name(user_email) + ' <' + user_email + '>'
            for post in posts:
                header = post['header']
                body = post['body']
                subject = header.get("subject")
                
                try:
                    subject = decode_header(subject)
                except UnicodeDecodeError:
                    subject = subject.decode("utf-8", 'replace')

                postid = post['postid']
                info = dict(user=user_email, user_name=user_name, 
                            email_hash=hmac.new(user_email, digestmod=sha).hexdigest(),
                            subject=subject, body=body, postid=postid,
                            raw_headers=header)
                if queue_name is not None:
                    info['queue_name'] = queue_name
                list_out.append(info)

        return list_out
    def _get_pending_list(self, pending_list, queue_name=None):
        list_out = []
        for user_email in pending_list.get_user_emails():
            posts = pending_list.get_posts(user_email)
            user_name = pending_list.get_user_name(user_email) + ' <' + user_email + '>'
            for post in posts:
                header = post['header']
                body = post['body']
                subject = header.get("subject")
                
                try:
                    subject = decode_header(subject)
                except UnicodeDecodeError:
                    subject = subject.decode("utf-8", 'replace')

                postid = post['postid']
                info = dict(user=user_email, user_name=user_name, 
                            email_hash=hmac.new(user_email, digestmod=sha).hexdigest(),
                            subject=subject, body=body, postid=postid,
                            raw_headers=header)
                if queue_name is not None:
                    info['queue_name'] = queue_name
                list_out.append(info)

        return list_out
    def __init__(self, id, from_addr, subject, date=None, **kwargs):
        from_addr = from_addr.decode("utf-8", "replace")
        self.from_addr = decode_header(email.Header.Header(from_addr))

        subject = subject.decode("utf-8", "replace")
        self.subject = decode_header(email.Header.Header(subject))
        # date is expected to be a DateTime or None
        if not isinstance(date, DateTime):
            self.date = DateTime(date)
        else:
            self.date = date

        sender_name = parseaddr(self.from_addr)[0]

        title_subj = len(self.subject) > 20 and (self.subject[:20] + " ...") or self.subject
        if sender_name:
            self.title = u"%s / %s" % (title_subj, sender_name)
        else:
            self.title = title_subj

        Folder.__init__(self, id)
Beispiel #4
0
    def __init__(self, id, from_addr, subject, date=None, **kwargs):
        from_addr = from_addr.decode('utf-8', 'replace')
        self.from_addr = decode_header(email.Header.Header(from_addr))

        subject = subject.decode('utf-8', 'replace')
        self.subject = decode_header(email.Header.Header(subject))
        # date is expected to be a DateTime or None
        if not isinstance(date, DateTime):
            self.date = DateTime(date)
        else:
            self.date = date

        sender_name = parseaddr(self.from_addr)[0]

        title_subj = len(self.subject) > 20 and (self.subject[:20]+' ...') \
                         or self.subject
        if sender_name:
            self.title = u"%s / %s" % (title_subj, sender_name)
        else:
            self.title= title_subj

        Folder.__init__(self, id)
    def processMail(self):
        # XXX we need to go through pending interfaces ... maybe named adapters?
        # right now we are hard coding the annotations that we are using
        pend_list = self._get_a_s_pending_list()

        message = self.request.get('Mail')
        (header, body) = MailBoxerTools.splitMail(message)

        # get email-address
        sender = decode_header(header.get('from',''))
        (name, email) = MailBoxerTools.parseaddr(sender)
        email = email.encode('ascii', 'replace').lower()

        # get subject
        subject = decode_header(header.get('subject', ''))

        # if the user is already an allowed sender, we don't need to validate
        if IMembershipList(self.context).is_allowed_sender(email):
            return

        # check to see if the pin matches
        policy = getAdapter(self.context, IUserEmailMembershipPolicy)
        fake_request = dict(subject=subject, email=email)
        command_email = policy._get_email_for_pin(fake_request, pend_list)
        
        if not policy._check_pin(fake_request, pend_list):
            mail_sender = ISendMail(self.context)
            mail_sender.user_pin_mismatch(email, name)
            return

        if pend_list.is_pending(command_email):
            self.add_allowed_sender(email)
            pend_list.remove(command_email)
            if email != command_email:
                self._send_pending_posts(command_email)
        else:
            # XXX why are we getting in here?
            pass
Beispiel #6
0
    def processMail(self):
        # XXX we need to go through pending interfaces ... maybe named adapters?
        # right now we are hard coding the annotations that we are using
        pend_list = self._get_a_s_pending_list()

        message = self.request.get('Mail')
        (header, body) = MailBoxerTools.splitMail(message)

        # get email-address
        sender = decode_header(header.get('from', ''))
        (name, email) = MailBoxerTools.parseaddr(sender)
        email = email.encode('ascii', 'replace').lower()

        # get subject
        subject = decode_header(header.get('subject', ''))

        # if the user is already an allowed sender, we don't need to validate
        if IMembershipList(self.context).is_allowed_sender(email):
            return

        # check to see if the pin matches
        policy = getAdapter(self.context, IUserEmailMembershipPolicy)
        fake_request = dict(subject=subject, email=email)
        command_email = policy._get_email_for_pin(fake_request, pend_list)

        if not policy._check_pin(fake_request, pend_list):
            mail_sender = ISendMail(self.context)
            mail_sender.user_pin_mismatch(email, name)
            return

        if pend_list.is_pending(command_email):
            self.add_allowed_sender(email)
            pend_list.remove(command_email)
            if email != command_email:
                self._send_pending_posts(command_email)
        else:
            # XXX why are we getting in here?
            pass
    def adaptMail(self, REQUEST):
        """Adapts an incoming request to a specialized view for handling
        mail if requested."""

        mailString = self.getMailFromRequest(REQUEST)
        (header, body) = splitMail(mailString)

        encoding = getSiteEncoding(self)
        subject = decode_header(str(Header(header.get('subject',''), 
                                           encoding,
                                           errors='replace')))

        command_match = re.search(mail_command_re, subject)
        if command_match:
            command_name = command_match.groups()[0]
            adapter = queryMultiAdapter((self, REQUEST), IMessageHandler,
                                        name=command_name)
            if adapter is not None:
                adapter.processMail()
                return True
        return False
Beispiel #8
0
    def adaptMail(self, REQUEST):
        """Adapts an incoming request to a specialized view for handling
        mail if requested."""

        mailString = self.getMailFromRequest(REQUEST)
        (header, body) = splitMail(mailString)

        encoding = getSiteEncoding(self)
        subject = decode_header(str(Header(header.get('subject',''), 
                                           encoding,
                                           errors='replace')))

        command_match = re.search(mail_command_re, subject)
        if command_match:
            command_name = command_match.groups()[0]
            adapter = queryMultiAdapter((self, REQUEST), IMessageHandler,
                                        name=command_name)
            if adapter is not None:
                adapter.processMail()
                return True
        return False