]> code.citadel.org Git - citadel.git/blobdiff - webcit-ng/static/js/view_mail.js
MAKE K&R CODING STYLE GREAT AGAIN!
[citadel.git] / webcit-ng / static / js / view_mail.js
index 27a34d24552875fe7d0cccedb4e60ec8a17348ac..1dcc07fe030bebf0cf04a6a2b8fd5400a0b0c447 100644 (file)
@@ -13,14 +13,20 @@ var RefreshMailboxInterval;                                                 // We store our refresh timer here
 // Render reply address for a message (FIXME we might want to figure out in-reply-to)
 function reply_addr(msg) {
        if (msg.locl) {
-               return(msg.from);
+               return([msg.from]);
        }
        else {
-               return(msg.from + " <" + msg.rfca + ">");
+               return([msg.from + " <" + msg.rfca + ">"]);
        }
 }
 
 
+// Render the To: recipients for a reply-all operation
+function replyall_to(msg) {
+       return([...reply_addr(msg), ...msg.rcpt]);
+}
+
+
 // Render a message into the mailbox view
 // (We want the message number and the message itself because we need to keep the msgnum for reply purposes)
 function mail_render_one(msgnum, msg, target_div, include_controls) {
@@ -44,13 +50,13 @@ function mail_render_one(msgnum, msg, target_div, include_controls) {
                        + "<span class=\"ctdl-msg-header-buttons\">"            // begin buttons on right side
                
                        + "<span class=\"ctdl-msg-button\">"                    // Reply (mail is always Quoted)
-                       + "<a href=\"javascript:mail_compose(true,'"+msg.wefw+"','"+msgnum+"', reply_addr(msg), '', 'Re: '+msg.subj);\">"
+                       + "<a href=\"javascript:mail_compose(true,'"+msg.wefw+"','"+msgnum+"', reply_addr(msg), [], 'Re: '+msg.subj);\">"
                        + "<i class=\"fa fa-reply\"></i> " 
                        + _("Reply")
                        + "</a></span>"
                
                        + "<span class=\"ctdl-msg-button\">"                    // Reply-All (mail is always Quoted)
-                       + "<a href=\"javascript:mail_compose(true,'"+msg.wefw+"','"+msgnum+"', '', '', 'Re: '+msg.subj);\">"
+                       + "<a href=\"javascript:mail_compose(true,'"+msg.wefw+"','"+msgnum+"', replyall_to(msg), msg.cccc, 'Re: '+msg.subj);\">"
                        + "<i class=\"fa fa-reply-all\"></i> " 
                        + _("ReplyAll")
                        + "</a></span>";
@@ -255,6 +261,38 @@ function render_mailbox_display() {
 
 // Compose a new mail message (called by the Reply button here, or by the dispatcher in views.js)
 function mail_compose(is_quoted, references, quoted_msgnum, m_to, m_cc, m_subject) {
+       console.log("mail_compose()");
+
+       // m_to will be an array of zero or more recipients for the To: field.  Convert it to a string.
+       if (m_to) {
+               m_to = Array.from(new Set(m_to));       // remove dupes
+               m_to_str = "";
+               for (i=0; i<m_to.length; ++i) {
+                       if (i > 0) {
+                               m_to_str += ", ";
+                       }
+                       m_to_str += m_to[i].replaceAll("<", "&lt;").replaceAll(">", "&gt;");
+               }
+       }
+       else {
+               m_to_str = "";
+       }
+
+       // m_to will be an array of zero or more recipients for the Cc: field.  Convert it to a string.
+       if (m_cc) {
+               m_cc = Array.from(new Set(m_cc));       // remove dupes
+               m_cc_str = "";
+               for (i=0; i<m_cc.length; ++i) {
+                       if (i > 0) {
+                               m_cc_str += ", ";
+                       }
+                       m_cc_str += m_cc[i].replaceAll("<", "&lt;").replaceAll(">", "&gt;");
+               }
+       }
+       else {
+               m_cc_str = "";
+       }
+
        quoted_div_name = randomString();
 
        // Make the "Write mail" button disappear.  We're already there!
@@ -276,7 +314,7 @@ function mail_compose(is_quoted, references, quoted_msgnum, m_to, m_cc, m_subjec
                // Visible To: field, plus a box to make the CC/BCC lines appear
                + "<div class=\"ctdl-compose-to-label\">" + _("To:") + "</div>"
                + "<div class=\"ctdl-compose-to-line\">"
-               + "<div class=\"ctdl-compose-to-field\" id=\"ctdl-compose-to-field\" contenteditable=\"true\">" + m_to + "</div>"
+               + "<div class=\"ctdl-compose-to-field\" id=\"ctdl-compose-to-field\" contenteditable=\"true\">" + m_to_str + "</div>"
                + "<div class=\"ctdl-cc-bcc-buttons ctdl-msg-button\" id=\"ctdl-cc-bcc-buttons\" "
                + "onClick=\"make_cc_bcc_visible()\">"
                + _("CC:") + "/" + _("BCC:") + "</div>"
@@ -284,7 +322,7 @@ function mail_compose(is_quoted, references, quoted_msgnum, m_to, m_cc, m_subjec
 
                // CC/BCC
                + "<div class=\"ctdl-compose-cc-label\" id=\"ctdl-compose-cc-label\">" + _("CC:") + "</div>"
-               + "<div class=\"ctdl-compose-cc-field\" id=\"ctdl-compose-cc-field\" contenteditable=\"true\">" + m_cc + "</div>"
+               + "<div class=\"ctdl-compose-cc-field\" id=\"ctdl-compose-cc-field\" contenteditable=\"true\">" + m_cc_str + "</div>"
                + "<div class=\"ctdl-compose-bcc-label\" id=\"ctdl-compose-bcc-label\">" + _("BCC:") + "</div>"
                + "<div class=\"ctdl-compose-bcc-field\" id=\"ctdl-compose-bcc-field\" contenteditable=\"true\"></div>"
 
@@ -305,7 +343,7 @@ function mail_compose(is_quoted, references, quoted_msgnum, m_to, m_cc, m_subjec
 
                // The button bar is a Grid element, and is also a Flexbox container.
                + "<div class=\"ctdl-compose-toolbar\">"
-               + "<span class=\"ctdl-msg-button\" onclick=\"mail_save_message()\"><i class=\"fa fa-paper-plane\" style=\"color:green\"></i> " + _("Send message") + "</span>"
+               + "<span class=\"ctdl-msg-button\" onclick=\"mail_send_message()\"><i class=\"fa fa-paper-plane\" style=\"color:green\"></i> " + _("Send message") + "</span>"
                + "<span class=\"ctdl-msg-button\">" + _("Save to Drafts") + "</span>"
                + "<span class=\"ctdl-msg-button\">" + _("Attachments:") + " 0" + "</span>"
                + "<span class=\"ctdl-msg-button\">" + _("Contacts") + "</span>"
@@ -315,30 +353,37 @@ function mail_compose(is_quoted, references, quoted_msgnum, m_to, m_cc, m_subjec
 
        document.getElementById("ctdl-main").innerHTML = compose_screen;
        mail_display_message(quoted_msgnum, document.getElementById(quoted_div_name), 0);
+       if (m_cc) {
+               document.getElementById("ctdl-compose-cc-label").style.display = "block";
+               document.getElementById("ctdl-compose-cc-field").style.display = "block";
+       }
 }
 
 
 function make_cc_bcc_visible() {
        document.getElementById("ctdl-cc-bcc-buttons").style.display = "none";
-       document.getElementById("ctdl-compose-cc-label").style.display = "block";
-       document.getElementById("ctdl-compose-cc-field").style.display = "block";
        document.getElementById("ctdl-compose-bcc-label").style.display = "block";
        document.getElementById("ctdl-compose-bcc-field").style.display = "block";
 }
 
 
-// Helper function for mail_save_messages() to extract form values.
-// (We have to replace "|" with "!" because "|" is a field separator in the Citadel protocol)
+// Helper function for mail_send_messages() to extract and decode metadata values.
 function msm_field(element_name, separator) {
-       return (document.getElementById(element_name).innerHTML).replaceAll("|",separator);
+       let s1 = document.getElementById(element_name).innerHTML;
+       let s2 = s1.replaceAll("|",separator);  // Replace "|" with "!" because "|" is a field separator in Citadel wire protocol
+       let s3 = decodeURI(s2);
+       let s4 = document.createElement("textarea");    // This One Weird Trick Unescapes All HTML Entities
+       s4.innerHTML = s3;
+       let s5 = s4.value;
+       return(s5);
 }
 
 
 // Save the posted message to the server
-function mail_save_message() {
+function mail_send_message() {
 
        document.body.style.cursor = "wait";
-       url = "/ctdl/r/" + escapeHTMLURI(current_room)
+       let url = "/ctdl/r/" + escapeHTMLURI(current_room)
                + "/dummy_name_for_new_mail"
                + "?wefw="      + msm_field("ctdl_mc_references", "!")                          // references (if present)
                + "&subj="      + msm_field("ctdl-compose-subject-field", " ")                  // subject (if present)