#!/usr/bin/env python2
"""Script to call git_multimail.py

This script is necessary because Submin makes some modifications
in the templates, and it's better not to change the original script
to do so.
"""
import sys

# To check if this hook is up-to-date
HOOK_VERSION = [val hook_version]
LIBDIR = '[val submin_lib_dir]/static/hooks/git'
sys.path.append(LIBDIR)

import git_multimail

git_multimail.FOOTER_TEMPLATE = """\

--
This message was sent by Submin through git_multimail.
To unsubscribe from this commit list, please login to [val http_vhost][val base_url] and change your preferences.
"""
git_multimail.REVISION_FOOTER_TEMPLATE = git_multimail.FOOTER_TEMPLATE

config = git_multimail.Config('multimailhook')

# If no e-mail recipients are configured, no need to continue. So ...
if not config.get('mailinglist'):
	# ... either configure mailinglist ...
	if not config.get('refchangelist') or not config.get('commitlist'):
		# ... or both refchangelist and commitlist.
		raise SystemExit

environment = git_multimail.GenericEnvironment(config=config)
mailer = git_multimail.choose_mailer(config, environment)
git_multimail.run_as_post_receive_hook(environment, mailer)
