def _get_listings(self): usecache = self.config.getboolean(self.section,'usecache') listings = None cache = get_default_cache() if usecache: listings = cache.get('listings') if not listings: listings = {} try: session = get_session(self.config.get(self.section,'dbconnection')) listing_types = [(l['name']).decode('utf-8') for l in LISTING_TYPES] result = session.query(UserPref).filter(UserPref.preference.in_(listing_types)).all() for r in result: listing_type = r.preference if not listing_type in listings: listings[listing_type] = {} username = r.username if username.startswith('*@'): # roundcube sauserprefs plugin domain wide scope username = username.lstrip('*@') if not username in listings[listing_type]: listings[listing_type][username] = [] listings[listing_type][username].append(r.value) except Exception as e: self.logger.error('Failed to get listings: %s' % str(e)) if listings and usecache: cache.put('listings', listings) return listings
def enforce_domain(self, to_domain): dbconnection = self.config.get(self.section, 'dbconnection', '').strip() domainlist = self.config.get(self.section, 'domainlist') enforce = False if domainlist.strip() == '': enforce = True elif domainlist.startswith('txt:'): domainfile = domainlist[4:] if self.selective_domain_loader is None: self.selective_domain_loader = FileList(domainfile, lowercase=True) if to_domain in self.selective_domain_loader.get_list(): enforce = True elif domainlist.startswith('sql:') and dbconnection != '': cache = get_default_cache() sqlquery = domainlist[4:] enforce = get_domain_setting(to_domain, dbconnection, sqlquery, cache, self.section, False, self.logger) return enforce
def check_this_domain(self, from_domain): do_check = False selective_sender_domain_file = self.config.get( self.section, 'domain_selective_spf_file', '').strip() if selective_sender_domain_file != '' and os.path.exists( selective_sender_domain_file): if self.selective_domain_loader is None: self.selective_domain_loader = FileList( selective_sender_domain_file, lowercase=True) if from_domain.lower() in self.selective_domain_loader.get_list(): do_check = True if not do_check: dbconnection = self.config.get(self.section, 'dbconnection', '').strip() sqlquery = self.config.get(self.section, 'domain_sql_query') if dbconnection != '' and SQL_EXTENSION_ENABLED: cache = get_default_cache() do_check = get_domain_setting(from_domain, dbconnection, sqlquery, cache, self.section, False, self.logger) elif dbconnection != '' and not SQL_EXTENSION_ENABLED: self.logger.error( 'dbconnection specified but sqlalchemy not available - skipping db lookup' ) return do_check
def check_this_domain(self, from_domain): do_check = False selective_sender_domain_file=self.config.get(self.section,'domain_selective_spf_file','').strip() if selective_sender_domain_file != '' and os.path.exists(selective_sender_domain_file): if self.selective_domain_loader is None: self.selective_domain_loader=FileList(selective_sender_domain_file,lowercase=True) if from_domain.lower() in self.selective_domain_loader.get_list(): do_check = True if not do_check: dbconnection = self.config.get(self.section, 'dbconnection', '').strip() sqlquery = self.config.get(self.section, 'domain_sql_query') if dbconnection!='' and SQL_EXTENSION_ENABLED: cache = get_default_cache() do_check = get_domain_setting(from_domain, dbconnection, sqlquery, cache, self.section, False, self.logger) elif dbconnection!='' and not SQL_EXTENSION_ENABLED: self.logger.error('dbconnection specified but sqlalchemy not available - skipping db lookup') return do_check
def enforce_domain(self, to_domain): dbconnection = self.config.get(self.section,'dbconnection', '').strip() domainlist = self.config.get(self.section,'domainlist') enforce = False if domainlist.strip() == '': enforce = True elif domainlist.startswith('txt:'): domainfile = domainlist[4:] if self.selective_domain_loader is None: self.selective_domain_loader=FileList(domainfile,lowercase=True) if to_domain in self.selective_domain_loader.get_list(): enforce = True elif domainlist.startswith('sql:') and dbconnection != '': cache = get_default_cache() sqlquery = domainlist[4:] enforce = get_domain_setting(to_domain, dbconnection, sqlquery, cache, self.section, False, self.logger) return enforce