def sanitize_signature(mapper, connection, target): "clean up signature before storing to DB" uncleantags = ["html", "head", "link", "body", "base"] if target.signature_type == "1" or target.signature_type == 1: target.signature_content = CLEANRE.sub("", target.signature_content) else: cleaner = SignatureCleaner(remove_tags=uncleantags, safe_attrs_only=False) target.signature_content = cleaner.clean_html(target.signature_content)
def sanitize_signature(mapper, connection, target): "clean up signature before storing to DB" uncleantags = ['html', 'head', 'link', 'body', 'base'] if target.signature_type == '1' or target.signature_type == 1: target.signature_content = CLEANRE.sub('', target.signature_content) else: cleaner = SignatureCleaner(remove_tags=uncleantags, safe_attrs_only=False) target.signature_content = cleaner.clean_html(target.signature_content)
def write_html_sig(sigfile, sig, is_domain, logger): "write html sig" cleaner = SignatureCleaner(style=True, remove_tags=UNCLEANTAGS, safe_attrs_only=False) html = cleaner.clean_html(sig.signature_content) html = fragments_fromstring(html)[0] # pylint: disable-msg=W0612 for element, attribute, link, pos in iterlinks(html): if link.startswith('/fm/'): logger.info('Found img link, processing') routemap = make_map(config) routeargs = routemap.match(link) if not routeargs: continue if is_domain: model = DomSigImg else: model = UserSigImg img = Session.query(model)\ .filter(model.id == routeargs['imgid']).one() element.attrib['src'] = 'cid:%s' % img.name imgfile = os.path.join(os.path.dirname(sigfile), img.name) with open(imgfile, 'wb') as handle: handle.write(base64.decodestring(img.image)) logger.info('%s: stored to filesystem at: %s.' % (img.name, imgfile)) sig.image.append(img) if 'link' in locals(): Session.add(sig) Session.commit() # Session.close() with open(sigfile, 'w') as handle: if not sig.signature_content.startswith('--'): handle.write('<br/>--<br/>') handle.write(tostring(html)) logger.info('Finished processing HTML signature: %s' % sigfile)