コード例 #1
0
 def delete(self):
     """Delete a message from the pending queue."""
     if Defaults.PENDING_DELETE_APPEND:
         Util.append_to_file(self.append_address,
                             Defaults.PENDING_DELETE_APPEND)
     if Defaults.DB_PENDING_DELETE_APPEND and Defaults.DB_CONNECTION:
         _username = Defaults.USERNAME.lower()
         _hostname = Defaults.HOSTNAME.lower()
         _recipient = _username + '@' + _hostname
         params = FilterParser.create_sql_params(
             recipient=_recipient, username=_username,
             hostname=_hostname, sender=self.append_address)
         Util.db_insert(Defaults.DB_CONNECTION,
                        Defaults.DB_PENDING_DELETE_APPEND,
                        params)
     Q.delete_message(self.msgid)
コード例 #2
0
 def release(self):
     """Release a message from the pending queue."""
     import Cookie
     if Defaults.PENDING_RELEASE_APPEND:
         Util.append_to_file(self.append_address,
                             Defaults.PENDING_RELEASE_APPEND)
     if Defaults.DB_PENDING_RELEASE_APPEND and Defaults.DB_CONNECTION:
         _username = Defaults.USERNAME.lower()
         _hostname = Defaults.HOSTNAME.lower()
         _recipient = _username + '@' + _hostname
         params = FilterParser.create_sql_params(
             recipient=_recipient, username=_username,
             hostname=_hostname, sender=self.append_address)
         Util.db_insert(Defaults.DB_CONNECTION,
                        Defaults.DB_PENDING_RELEASE_APPEND,
                        params)
     timestamp, pid = self.msgid.split('.')
     # Remove Return-Path: to avoid duplicates.
     del self.msgobj['return-path']
     # Remove X-TMDA-Recipient:
     del self.msgobj['x-tmda-recipient']
     # To avoid a mail loop on re-injection, prepend an ``Old-'' prefix
     # to all existing Delivered-To lines.
     Util.rename_headers(self.msgobj, 'Delivered-To', 'Old-Delivered-To')
     # Add an X-TMDA-Confirm-Done: field to the top of the header for
     # later verification.  This includes a timestamp, pid, and HMAC.
     del self.msgobj['X-TMDA-Confirm-Done']
     self.msgobj['X-TMDA-Confirm-Done'] = Cookie.make_confirm_cookie(timestamp,
                                                                pid, 'done')
     # Add the date when confirmed in a header.
     del self.msgobj['X-TMDA-Released']
     self.msgobj['X-TMDA-Released'] = Util.make_date()
     # For messages released via tmda-cgi, add the IP address and
     # browser info of the releaser for easier tracing.
     if os.environ.has_key('REMOTE_ADDR') and \
             os.environ.has_key('HTTP_USER_AGENT'):
         cgi_header = "%s (%s)" % (os.environ.get('REMOTE_ADDR'),
                                   os.environ.get('HTTP_USER_AGENT'))
         del self.msgobj['X-TMDA-CGI']
         self.msgobj['X-TMDA-CGI'] = cgi_header
     # Reinject the message to the original envelope recipient.
     Util.sendmail(self.show(), self.recipient, self.return_path)
コード例 #3
0
def filter_match(filename, recip, sender=None):
    """Check if the give e-mail addresses match lines in filename."""
    import Defaults
    import FilterParser
    filter = FilterParser.FilterParser(Defaults.DB_CONNECTION)
    filter.read(filename)
    (actions, matchline) = filter.firstmatch(recip, [sender])
    # print the results
    checking_msg = 'Checking ' + filename
    print checking_msg
    print '-' * len(checking_msg)
    if recip:
        print 'To:', recip
    if sender:
        print 'From:', sender
    print '-' * len(checking_msg)
    if actions:
        print 'MATCH:', matchline
    else:
        print 'Sorry, no matching lines.'
コード例 #4
0
 def blacklist(self):
     """Blacklist the message sender."""
     if (Defaults.PENDING_BLACKLIST_APPEND or
         (Defaults.DB_PENDING_BLACKLIST_APPEND and Defaults.DB_CONNECTION)):
         if Defaults.PENDING_BLACKLIST_APPEND:
             Util.append_to_file(self.append_address,
                                 Defaults.PENDING_BLACKLIST_APPEND)
         if Defaults.DB_PENDING_BLACKLIST_APPEND and Defaults.DB_CONNECTION:
             _username = Defaults.USERNAME.lower()
             _hostname = Defaults.HOSTNAME.lower()
             _recipient = _username + '@' + _hostname
             params = FilterParser.create_sql_params(
                 recipient=_recipient, username=_username,
                 hostname=_hostname, sender=self.append_address)
             Util.db_insert(Defaults.DB_CONNECTION,
                            Defaults.DB_PENDING_BLACKLIST_APPEND,
                            params)
     else:
         raise Errors.ConfigError(
             'PENDING_BLACKLIST_APPEND (or DB_CONNECTION+'
             'DB_PENDING_BLACKLIST_APPEND) not defined!')