예제 #1
0
def set_body_class(payload, body_class):
    "Set the body class attribute to the top tag"
    if body_class:
        payload = local_fromstring(payload)
        payload.attrib['class'] = body_class
        payload = tostring(payload)
    return payload
예제 #2
0
def set_body_class(payload, body_class):
    "Set the body class attribute to the top tag"
    if body_class:
        payload = local_fromstring(payload)
        payload.attrib['class'] = body_class
        payload = tostring(payload)
    return payload
예제 #3
0
def image_fixups(content, msgid, archive, richformat, allowimgs):
    "Replace the CID links stored messages"
    html = local_fromstring(content)
    for element, attribute, link, _ in iterlinks(html):
        if not link.startswith('cid:'):
            if not allowimgs and attribute == 'src':
                element.attrib['src'] = '%simgs/blocked.gif' % media_url()
                element.attrib['title'] = link
                if richformat:
                    if archive:
                        displayurl = url('message-preview-archived-with-imgs',
                                        msgid=msgid)
                    else:
                        displayurl = url('message-preview-with-imgs',
                                        msgid=msgid)
                    flash(ugettext('This message contains external'
                        ' images, which have been blocked. ') +
                        literal(link_to(ugettext('Display images'),
                                displayurl)))
        else:
            imgname = link.replace('cid:', '')
            if archive:
                imgurl = url('messages-preview-archived-img',
                            img=imgname.replace('/', '__xoxo__'),
                            msgid=msgid)
            else:
                imgurl = url('messages-preview-img',
                            img=imgname.replace('/', '__xoxo__'),
                            msgid=msgid)
            element.attrib['src'] = imgurl            
    return tostring(html)
예제 #4
0
def image_fixups(content, msgid, archive, richformat, allowimgs):
    "Replace the CID links stored messages"
    html = local_fromstring(content)
    for element, attribute, link, _ in iterlinks(html):
        if not link.startswith('cid:'):
            if not allowimgs and attribute == 'src':
                element.attrib['src'] = '%simgs/blocked.gif' % media_url()
                element.attrib['title'] = link
                if richformat:
                    if archive:
                        displayurl = url('message-preview-archived-with-imgs',
                                         msgid=msgid)
                    else:
                        displayurl = url('message-preview-with-imgs',
                                         msgid=msgid)
                    flash(
                        ugettext('This message contains external'
                                 ' images, which have been blocked. ') +
                        literal(link_to(ugettext('Display images'),
                                        displayurl)))
        else:
            imgname = link.replace('cid:', '')
            if archive:
                imgurl = url('messages-preview-archived-img',
                             img=imgname.replace('/', '__xoxo__'),
                             msgid=msgid)
            else:
                imgurl = url('messages-preview-img',
                             img=imgname.replace('/', '__xoxo__'),
                             msgid=msgid)
            element.attrib['src'] = imgurl
    return tostring(html)
예제 #5
0
def get_style(msg):
    "Get the styles in a message"
    styles = []
    if msg:
        html = local_fromstring(msg)
        for style in html.xpath('//style'):
            styles.append(style.text or u'')
    return u'\n'.join(styles)
예제 #6
0
def get_body_style(payload, target='#email-html-part'):
    "Get the style attribute of the body tag"
    try:
        html = local_fromstring(payload)
        [body] = html.xpath('//body')
        raw = sanitize_style(body.attrib.get('style', u''))
        body_class = body.attrib.get('class', u'')
        style = "%s {%s}" % (target, raw) if raw else u''
        return style, body_class
    except (ValueError, XMLSyntaxError):
        return None, None
예제 #7
0
def get_body_style(payload, target='#email-html-part'):
    "Get the style attribute of the body tag"
    try:
        html = local_fromstring(payload)
        [body] = html.xpath('//body')
        raw = sanitize_style(body.attrib.get('style', u''))
        body_class = body.attrib.get('class', u'')
        style = "%s {%s}" % (target, raw) if raw else u''
        return style, body_class
    except (ValueError, XMLSyntaxError):
        return None, None
예제 #8
0
def clean_styles(payload):
    "Cleanup styles"
    if not payload:
        return ''

    html = local_fromstring(payload)
    walker = html.getiterator()
    for tag in walker:
        if 'style' in tag.keys():
            newstyle = sanitize_style(tag.get('style'))
            if newstyle:
                tag.set('style', newstyle)
                if XSS_RE.findall(tag.get('style')):
                    tag.attrib.pop('style')
            else:
                tag.attrib.pop('style')
        if tag.tag == 'style':
            tag.drop_tree()
    return tostring(html)
예제 #9
0
def clean_styles(payload):
    "Cleanup styles"
    if not payload:
        return ''

    html = local_fromstring(payload)
    walker = html.getiterator()
    for tag in walker:
        if 'style' in tag.keys():
            newstyle = sanitize_style(tag.get('style'))
            if newstyle:
                tag.set('style', newstyle)
                if XSS_RE.findall(tag.get('style')):
                    tag.attrib.pop('style')
            else:
                tag.attrib.pop('style')
        if tag.tag == 'style':
            tag.drop_tree()
    return tostring(html)
예제 #10
0
def img_fixups(content, queueid, allowimgs, richformat):
    "Replace the CID links in Queued messages"
    html = local_fromstring(content)
    for element, attribute, link, _ in iterlinks(html):
        if not link.startswith('cid:'):
            if not allowimgs and attribute == 'src':
                element.attrib['src'] = '%simgs/blocked.gif' % media_url()
                element.attrib['title'] = link
                if richformat:
                    flash(ugettext('This message contains external '
                    'images, which have been blocked. ') +
                    literal(link_to(ugettext('Display images'),
                    url('queue-preview-with-imgs', queueid=queueid))))
        else:
            imgname = link.replace('cid:', '')
            element.attrib['src'] = url('queue-preview-img',
                                    imgid=imgname.replace('/', '__xoxo__'),
                                    queueid=queueid)
    return tostring(html)
예제 #11
0
def img_fixups(content, queueid, allowimgs, richformat):
    "Replace the CID links in Queued messages"
    html = local_fromstring(content)
    for element, attribute, link, _ in iterlinks(html):
        if not link.startswith('cid:'):
            if not allowimgs and attribute == 'src':
                element.attrib['src'] = '%simgs/blocked.gif' % media_url()
                element.attrib['title'] = link
                if richformat:
                    flash(
                        ugettext('This message contains external '
                                 'images, which have been blocked. ') +
                        literal(
                            link_to(
                                ugettext('Display images'),
                                url('queue-preview-with-imgs',
                                    queueid=queueid))))
        else:
            imgname = link.replace('cid:', '')
            element.attrib['src'] = url('queue-preview-img',
                                        imgid=imgname.replace('/', '__xoxo__'),
                                        queueid=queueid)
    return tostring(html)