from .mailaddress import MailAddress
-__version__ = '0.3.1'
+__version__ = '0.4.1'
LOG = logging.getLogger(__name__)
os.path.join(postfix_maps_dir, 'virtual-aliases'),
]
+ default_ignore_aliases = [
+ 'root',
+ ]
+
default_origin = 'pixelpark.com'
re_virtaliases_line = re.compile(r'^([^#\s:]+)\s', re.MULTILINE)
- re_root_address = re.compile(r'^root(?:@.*)?\s*$', re.IGNORECASE)
open_args = {}
if six.PY3:
self.barracuda_base_dn = self.default_barracuda_base_dn
self.virtaliases_files = copy.copy(self.default_virtaliases_files)
self.origin = self.default_origin
+ self.ignore_aliases = copy.copy(self.default_ignore_aliases)
self.existing_aliases = []
self.ldap_aliases = []
self.aliases_to_create = []
self.aliases_to_remove = []
+ self.ignore_aliases_res = []
self._show_simulate_opt = True
cfg_stems='barracuda-sync'
)
+ self._init_ignore_aliases_res()
self.initialized = True
# -------------------------------------------------------------------------
if f not in virtaliases_files:
virtaliases_files.append(f)
+ if 'ignore_aliases' in section:
+ v = section['ignore_aliases']
+ aliases = shlex.split(v)
+ if aliases:
+ for alias in aliases:
+ if alias.startswith('-'):
+ alias = alias[1:]
+ if alias == '':
+ continue
+ if alias in self.ignore_aliases:
+ self.ignore_aliases.remove(alias)
+ elif alias not in self.ignore_aliases:
+ self.ignore_aliases.append(alias)
+
+
if 'base_dn' in section:
v = section['base_dn'].strip()
if v:
os.path.join(self.postfix_maps_dir, 'virtual-aliases'),
]
+ # -------------------------------------------------------------------------
+ def _init_ignore_aliases_res(self):
+
+ LOG.debug("Preparing regexes for aliases to ignore ...")
+ self.ignore_aliases_res = []
+
+ for alias in self.ignore_aliases:
+
+ a = alias.strip()
+ if a == '':
+ continue
+ pattern = r'^' + alias
+ if not MailAddress.valid_address(alias):
+ pattern += r'(?:@' + re.escape(self.origin) + r')?'
+ pattern += r'\s*$'
+ regex = re.compile(pattern, re.IGNORECASE)
+ self.ignore_aliases_res.append(regex)
+
# -------------------------------------------------------------------------
def pre_run(self):
"""
content = fh.read()
aliases = self.re_virtaliases_line.findall(content)
for alias in aliases:
- if self.re_root_address.match(alias):
+ do_add = True
+ for regex in self.ignore_aliases_res:
+ if regex.search(alias):
+ do_add = False
+ break
+ if not do_add:
continue
if alias not in self.existing_aliases:
if self.verbose > 2: