Esempio n. 1
0
def sendmail(toAddr, subject, textPart, htmlPart=None, fromAddr="*****@*****.**", fromName="Flocked-in"):
    if textPart:
        textPart = sanitizer.unescape(textPart, {":": ":"})
    if htmlPart:
        msg = MIMEMultipart("alternative")
        msg.preamble = "This is a multi-part message in MIME format."

        msgText = MIMEText(textPart, _charset="utf8")
        msg.attach(msgText)

        msgText = MIMEText(htmlPart, "html", _charset="utf8")
        msg.attach(msgText)
    else:
        msg = MIMEText(textPart, _charset="utf8")

    msg["Subject"] = sanitizer.unescape(subject, {":": ":"})
    msg["From"] = "%s <%s>" % (fromName, fromAddr)
    msg["To"] = toAddr
    try:
        devMailId = config.get("Devel", "MailId")
        if devMailId:
            toAddr = devMailId
    except:
        pass

    message = msg.as_string()
    host = config.get("SMTP", "Host")
    yield smtp.sendmail(host, fromAddr, toAddr, message)
Esempio n. 2
0
def normalizeText(text, richText=False):
    if not text:
        return text
    if richText:
        text = sanitizer.unescape(text, {"&#58;": ":"})
        return markdown.markdown(text.decode("utf-8", "replace"), safe_mode="escape")
    global _urlRegEx

    def addAnchor(m):
        if m.group(2) == "www.":
            return '<a class="c-link" target="_blank" href="http://%s">%s</a>' % (m.group(0), m.group(0))
        elif m.group(2).startswith("http"):
            return '<a class="c-link" target="_blank" href="%s">%s</a>' % (m.group(0), m.group(0))
        else:
            return m.group(0)

    urlReplaced = _urlRegEx.sub(addAnchor, text)
    return _newLineRegEx.sub("<br/>", urlReplaced).strip().lstrip().replace("\r\n", "<br/>")
Esempio n. 3
0
def richTextToText(text):
    text = sanitizer.unescape(text, {"&#58;": ":"})
    tree = etree.fromstring(
        markdown.markdown(text.decode("utf8", "replace"), safe_mode="escape").encode("utf8", "replace")
    )
    return etree.tostring(tree, method="text", encoding="utf8")
Esempio n. 4
0
def richTextToHtml(text):
    text = sanitizer.unescape(text, {"&#58;": ":"})
    return markdown.markdown(text.decode("utf8", "replace"), safe_mode="escape").encode("utf8", "replace")