Exemple #1
0
    def getAutomationIndicators(self, message):
        """Look for headers that indicate automated email.

        If the message appears to be automated rather than written
        by a person, this method returns a mapping containing 'error'.
        Otherwise an empty mapping is returned.
        """
        info = {}
        # Like Mailman, if a message has "Precedence: bulk|junk|list",
        # discard it.  The Precedence header is non-standard, yet
        # widely supported.
        precedence = decode_header(message.get('Precedence', '')).lower()
        if precedence in ('bulk', 'junk', 'list'):
            info['error'] = 'Precedence: %s' % precedence
            return info

        # rfc3834 is the standard way to discard automated responses, but
        # it is not yet widely supported.
        auto_submitted = decode_header(
            message.get('Auto-Submitted', '')).lower()
        if auto_submitted.startswith('auto'):
            info['error'] = 'Auto-Submitted: %s' % auto_submitted
            return info

        subject_lower = decode_header(message.get('Subject', '')).lower()
        if 'autoreply' in subject_lower or 'out of office' in subject_lower:
            info['error'] = 'vacation message'
            return info

        return info
Exemple #2
0
    def getMessageAuthorAndSubject(self, message):
        """Return a mapping describing the author and subject of a message.

        If there is no error, the mapping will contain 'author' (a
        profile ID) and 'subject'.  It will also contain 'from' for
        debugging purposes.

        If an error occurs, the mapping will contain 'error' and
        may contain 'from', 'author', and 'subject'.
        """
        info = {}

        fromaddrs = self.getAddrList(message, 'From')
        if len(fromaddrs) == 0:
            info['error'] = 'missing From:'
            return info

        if len(fromaddrs) > 1:
            info['error'] = 'multiple From:'
            return info

        info['from'] = fromaddrs

        realname, email = fromaddrs[0]

        author = self.getAuthor(email)
        if not author:
            info['error'] = 'author not found'
            return info

        info['author'] = author

        subject = decode_header(message['Subject'])
        if not subject:
            info['error'] = 'missing Subject:'
            return info

        info['subject'] = subject

        return info