コード例 #1
0
ファイル: mailin.py プロジェクト: reebalazs/karl
    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
コード例 #2
0
ファイル: mailin.py プロジェクト: lslaz1/karl
    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
コード例 #3
0
ファイル: filters.py プロジェクト: repoze/repoze.postoffice
 def __call__(self, message):
     for name in message.keys():
         header = '%s: %s' % (name, decode_header(message.get(name)))
         for regexp, compiled in self.regexps:
             if compiled.match(header) is not None:
                 return 'header_regexp: headers match %s' % repr(regexp)
     return None
コード例 #4
0
ファイル: filters.py プロジェクト: py361/repoze.postoffice
 def __call__(self, message):
     for name in message.keys():
         header = '%s: %s' % (name, decode_header(message.get(name)))
         for regexp, compiled in self.regexps:
             if compiled.match(header) is not None:
                 return 'header_regexp: headers match %s' % repr(regexp)
     return None
コード例 #5
0
ファイル: mailin.py プロジェクト: reebalazs/karl
    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
コード例 #6
0
ファイル: mailin.py プロジェクト: lslaz1/karl
    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