Changeset View
Changeset View
Standalone View
Standalone View
wallace/module_footer.py
Show All 23 Lines | |||||
from email import message_from_file | from email import message_from_file | ||||
from email.encoders import encode_quopri | from email.encoders import encode_quopri | ||||
import modules | import modules | ||||
import pykolab | import pykolab | ||||
from pykolab.translate import _ | from pykolab.translate import _ | ||||
log = pykolab.getLogger('pykolab.wallace') | log = pykolab.getLogger('pykolab.wallace/footer') | ||||
extra_log_params = {'qid': '-'} | |||||
log = pykolab.logger.LoggerAdapter(log, extra_log_params) | |||||
conf = pykolab.getConf() | conf = pykolab.getConf() | ||||
mybasepath = '/var/spool/pykolab/wallace/footer/' | mybasepath = '/var/spool/pykolab/wallace/footer/' | ||||
def __init__(): | def __init__(): | ||||
modules.register('footer', execute, description=description()) | modules.register('footer', execute, description=description()) | ||||
def description(): | def description(): | ||||
return """Append a footer to messages.""" | return """Append a footer to messages.""" | ||||
def set_part_content(part, content): | def set_part_content(part, content): | ||||
# Reset old encoding and use quoted-printable (#5414) | # Reset old encoding and use quoted-printable (#5414) | ||||
del part['Content-Transfer-Encoding'] | del part['Content-Transfer-Encoding'] | ||||
part.set_payload(content) | part.set_payload(content) | ||||
encode_quopri(part) | encode_quopri(part) | ||||
return True | return True | ||||
def execute(*args, **kw): | def execute(*args, **kw): | ||||
global extra_log_params | |||||
# TODO: Test for correct call. | |||||
filepath = args[0] | |||||
extra_log_params['qid'] = os.path.basename(filepath) | |||||
if not os.path.isdir(mybasepath): | if not os.path.isdir(mybasepath): | ||||
os.makedirs(mybasepath) | os.makedirs(mybasepath) | ||||
for stage in ['incoming', 'ACCEPT']: | for stage in ['incoming', 'ACCEPT']: | ||||
if not os.path.isdir(os.path.join(mybasepath, stage)): | if not os.path.isdir(os.path.join(mybasepath, stage)): | ||||
os.makedirs(os.path.join(mybasepath, stage)) | os.makedirs(os.path.join(mybasepath, stage)) | ||||
# TODO: Test for correct call. | |||||
filepath = args[0] | |||||
if 'stage' in kw: | if 'stage' in kw: | ||||
log.debug(_("Issuing callback after processing to stage %s") % (kw['stage']), level=8) | log.debug(_("Issuing callback after processing to stage %s") % (kw['stage']), level=8) | ||||
log.debug(_("Testing cb_action_%s()") % (kw['stage']), level=8) | log.debug(_("Testing cb_action_%s()") % (kw['stage']), level=8) | ||||
if hasattr(modules, 'cb_action_%s' % (kw['stage'])): | if hasattr(modules, 'cb_action_%s' % (kw['stage'])): | ||||
log.debug(_("Attempting to execute cb_action_%s()") % (kw['stage']), level=8) | log.debug(_("Attempting to execute cb_action_%s()") % (kw['stage']), level=8) | ||||
exec('modules.cb_action_%s(%r, %r)' % (kw['stage'],'optout',filepath)) | exec('modules.cb_action_%s(%r, %r)' % (kw['stage'],'optout',filepath)) | ||||
return | return | ||||
▲ Show 20 Lines • Show All 89 Lines • Show Last 20 Lines |