예제 #1
0
파일: htgen.py 프로젝트: shelt/tmail
def compose(wfile, inreplyto=None, is_reply_all=False):
    inreplyto_msg = None
    recips_replyall = None
    recips_replyto = None
    recip_sender = None
    # Reply elements
    if inreplyto:
        inreplyto_msg = email.message_from_string(database.get_message(inreplyto))
    if inreplyto_msg is not None:
        # Convert ["sam shelton <*****@*****.**>"] to ["*****@*****.**"] for to, cc, and from fields
        cc = [email.utils.parseaddr(field)[1] for field in (inreplyto_msg.get("Cc") or "").split(",")]
        to = [email.utils.parseaddr(field)[1] for field in (inreplyto_msg.get("To") or "").split(",")] #TODO remove self email from recips
        replyto = [email.utils.parseaddr(field)[1] for field in inreplyto_msg.get("Reply-To").split(",")]
        fr = email.utils.parseaddr(inreplyto_msg.get("From"))[1]
        # Merge lists for use in script element
        recips_replyall = list(set(cc) | set(to) | set((fr,)))
        recips_replyto = list(set(replyto))
        recip_sender = [fr] # No need to convert it to set; it's duplicate-free.
    else:
        inreplyto = None # Tell the parser that it isn't a reply
    
    # Accounts
    accounts = []
    for account in database.get_account_list():
        acc_dict = {"address":account[0], "name":account[1]}
        acc_dict["default"] = account[0] == DEFAULT_SENDER
        accounts.append(acc_dict)
    html = temp_compose.render(inreplyto=inreplyto,
                              is_reply_all=is_reply_all,
                              recips_replyall=recips_replyall,
                              recips_replyto=recips_replyto,
                              recip_sender=recip_sender,
                              accounts=accounts)
    wfile.write(html.encode("UTF-8"))
예제 #2
0
파일: htgen-old.py 프로젝트: shelt/tmail
def get_compose_content(sender, inreplyto, replyall_enabled):  # note sender is unused; see todo
    html = ""
    # Add reply header
    inreplyto_msg = None
    if inreplyto:
        inreplyto_msg = email.message_from_string(database.get_message(inreplyto))
    if inreplyto_msg is not None:
        # Convert ["sam shelton <*****@*****.**>"] to ["*****@*****.**"] for to, cc, and from fields
        cc = [email.utils.parseaddr(field)[1] for field in inreplyto_msg.get("Cc").split(",")]
        to = [
            email.utils.parseaddr(field)[1] for field in inreplyto_msg.get("To").split(",")
        ]  # TODO remove self email from recips
        replyto = [email.utils.parseaddr(field)[1] for field in inreplyto_msg.get("Reply-To").split(",")]
        fr = email.utils.parseaddr(inreplyto_msg.get("From"))[1]
        # Merge lists for use in script element
        recips_replyall = set(cc) | set(to) | set((fr,))
        recips_replyto = set(replyto)
        recip_sender = [fr]  # No need to convert it to set; it's duplicate-free.

        html += INREPLYTO_HEADER_TEMPLATE.format(inreplyto=inreplyto)
        html += """
            <fieldset id="replymode-fieldset" class="replymode">
                <div>
                    <label class="selected">
                      Reply-to
                      <input name="replymode" onclick="radioChange(this);setToList(recips_replyto);" type="radio" value="reply_to" />
                    </label>
                    <label>
                      Sender
                      <input name="replymode" onclick="radioChange(this);setToList(recip_sender);" type="radio" value="sender" />
                    </label>
                    <label>
                      Reply-All
                      <input name="replymode" onclick="radioChange(this);setToList(recips_replyall);" type="radio" value="reply_all" />
                    </label>
                </div>
            </fieldset>
            <script>
                var recips_replyall = {recips_replyall};
                var recips_replyto = {recips_replyto};
                var recip_sender = {recip_sender};
                if ({replyall_enabled})
            </script>
        """.format(
            recips_replyall=list(recips_replyall), recips_replyto=list(recips_replyto), recip_sender=recip_sender
        )
    # note the end of above if inreplyto block
    html += """
    <ol id="recips" class="recips">
    </ol>
    <input type="text" name="addrecip" class="addrecip" onkeypress="addRecip(this);">
    {from_account}
    <script>
    """.format(
        from_account=get_accounts_dropdown()
    )
    return html
예제 #3
0
파일: htgen.py 프로젝트: shelt/tmail
def get_thread_message(msgid):
    result = database.get_message(msgid, mark_read=True)
    if result is None:
        return None
    parsed = email.message_from_string(result)
    msg = {}
    msg['subj']      = escape(parsed.get("Subject"))
    msg['msgid']     = escape(parsed.get("Message-ID"))
    msg['sender']    = escape(parsed.get("From"))
    msg['recip']     = escape(parsed.get("To"))
    msg['date']      = escape(parsed.get("Date"))
    msg['cc']        = escape(parsed.get("Cc"))
    msg['bcc']       = escape(parsed.get("Bcc"))
    msg['inreplyto'] = escape(parsed.get("In-Reply-To"))
    
    if msg['recip'] is not None: msg['recip'] = msg['recip'].replace(",","<br>")
    if msg['cc'] is not None: msg['cc'] = msg['cc'].replace(",","<br>")
    if msg['bcc'] is not None: msg['bcc'] = msg['bcc'].replace(",","<br>")

    (body,attachments) = get_message_body(parsed)
    body = escape(body)
    msg['attachments'] = attachments
    
    # Hide quoted text #
    # Text should be quoted if it starts with a "> ", or
    # if the line above or below it does (because some mail
    # clients are bad at word wrapping)
    lines = body.splitlines()
    i = 0
    already_quoting = False
    last_quoted_line = None
    for i in range(len(lines)):
        if lines[i].startswith("&gt; "):
            last_quoted_line = i
            if not already_quoting:
                lines[i] = '\n<input type="checkbox" class="showquote"><div class="quote">\n' + lines[i]
                already_quoting = True
            elif (i - last_quoted_line) > 1:
                lines[i] = lines[i] + '\n</div"><\n'
                already_quoting = False
    body = "\n".join(lines)
        
    msg['body'] = body
    
    return msg
예제 #4
0
파일: htgen-old.py 프로젝트: shelt/tmail
def get_thread_message(msgid):
    msg = email.message_from_string(database.get_message(msgid, mark_read=True))
    if not msg:
        return (THREADMESSAGE_404_TEMPLATE.format(msgid=escape(msgid)), None)
    subj = escape(msg.get("Subject"))
    msgid = escape(msg.get("Message-ID"))
    sender = escape(msg.get("From"))
    recip = escape(msg.get("To")).replace(",", "<br>")
    date = escape(msg.get("Date"))
    cc = escape(msg.get("Cc")).replace(",", "<br>")
    bcc = escape(msg.get("Bcc")).replace(",", "<br>")
    inreplyto = escape(msg.get("In-Reply-To"))

    (body, attachments) = get_message_body(msg)

    body = escape(body)
    # Hide quoted text
    # Text should be quoted if it starts with a "> ", or
    # if the line above or below it does (because some mail
    # clients are bad at word wrapping)
    lines = body.splitlines()
    i = 0
    already_quoting = False
    last_quoted_line = None
    for i in range(len(lines)):
        if lines[i].startswith("&gt; "):
            last_quoted_line = i
            if not already_quoting:
                lines[i] = '\n<input type="checkbox" class="showquote"><div class="quote">\n' + lines[i]
                already_quoting = True
            elif (i - last_quoted_line) > 1:
                lines[i] = lines[i] + '\n</div"><\n'
                already_quoting = False
    body = "\n".join(lines)

    msg_html = """
            <li class="threadmessage">
                <div class="threadmessage">
                    <table class="infobox">
                        <tr class="info "id="subject-{msgid}">
                            <td class="prefix">Subj:</td>
                            <td class="value" style="font-weight:bold;">{subj}</td>
                        </tr>
                        <tr class="info "id="msgid-{msgid}" style="display:none;">
                            <td class="prefix">ID:</td>
                            <td class="value">{msgid}</td>
                        </tr>
                        <tr class="info "id="sender-{msgid}">
                            <td class="prefix">From:</td>
                            <td class="value">{sender}</td>
                        </tr>
                        <tr class="info "id="recipient-{msgid}">
                            <td class="prefix">To:</td>
                            <td class="value">{recip}</td>
                        </tr>
                        <tr class="info "id="date-{msgid}">
                            <td class="prefix">Date:</td>
                            <td class="value">{date}</td>
                        </tr>
                        <tr class="info "id="cc-{msgid}" style="display:none;">
                            <td class="prefix">CC:</td>
                            <td class="value">{cc}</td>
                        </tr>
                        <tr class="info "id="bcc-{msgid}" style="display:none;">
                            <td class="prefix">BCC:</td>
                            <td class="value">{bcc}</td>
                        </tr>
                    </table>
                    <div class="extended-toggle" onclick="toggleExtended('{msgid}');">Full details</div>
                    <div class="body">{body}</div>
                    <div class="attachments">{attachments}</div>
                </div>
            </li>""".format(
        subj=subj,
        msgid=msgid,
        sender=sender,
        recip=recip,
        date=date,
        cc=cc,
        bcc=bcc,
        inreplyto=inreplyto,
        body=body,
        attachments=attachments,
    )
    return (msg_html, unescape(inreplyto))