1 // This module handles the view for "mailbox" rooms.
3 // Copyright (c) 2016-2023 by the citadel.org team
5 // This program is open source software. Use, duplication, or
6 // disclosure are subject to the GNU General Public License v3.
9 var displayed_message = 0; // ID of message currently being displayed
10 var RefreshMailboxInterval; // We store our refresh timer here
11 var highest_mailnum; // This is used to detect newly arrived mail
12 var newmail_notify = {
13 NO : 0, // do not perform new mail notifications
14 YES : 1 // yes, perform new mail notifications
16 var num_attachments = 0; // number of attachments in current composed msg
17 var uploads_in_progress = 0;
20 // This is the async back end for mail_delete_selected()
21 mail_delete_func = async(table, row) => {
22 let m = parseInt(row["id"].substring(12)); // derive msgnum from row id
24 if (is_trash_folder) {
25 response = await fetch(
26 "/ctdl/r/" + escapeHTMLURI(current_room) + "/" + m,
28 method: "DELETE" // If this is the Trash folder, delete permanently
33 response = await fetch(
34 "/ctdl/r/" + escapeHTMLURI(current_room) + "/" + m,
36 method: "MOVE", // Otherwise, move to the Trash folder
37 headers: { "Destination" : "/ctdl/r/_TRASH_" }
42 if (response.ok) { // If the server accepted the delete, blank out the message div
43 table.deleteRow(row.rowIndex);
44 if (m == displayed_message) {
45 document.getElementById("ctdl-mailbox-reading-pane").innerHTML = "";
46 displayed_message = 0;
52 // Delete the selected messages (can be activated by mouse click or keypress)
53 function mail_delete_selected() {
54 let table = document.getElementById("ctdl-onscreen-mailbox");
56 for (i=0; row=table.rows[i]; ++i) {
57 if (row.classList.contains("ctdl-mail-selected")) {
58 mail_delete_func(table, row);
64 // Handler function for keypresses detected while the mail view is displayed. Mainly for deleting messages.
65 function mail_keypress(event) {
67 // If the "ctdl-mailbox-pane" no longer exists, the user has navigated to a different part of the site,
68 // so cancel the event listener.
70 document.getElementById("ctdl-mailbox-pane").innerHTML;
73 document.removeEventListener("keydown", mail_keypress);
77 const key = event.key.toLowerCase();
78 if (key == "delete") {
79 mail_delete_selected();
85 // Handler function for dragging email messages to other folders
86 function mail_dragstart(event) {
89 let table = document.getElementById("ctdl-onscreen-mailbox");
90 let messages_being_dragged = [] ;
92 if (event.target.classList.contains("ctdl-mail-selected")) {
93 // The row being dragged IS selected. See if any OTHER rows are selected, and they will come along for the ride.
94 for (i=1; row=table.rows[i]; ++i) {
95 if (row.classList.contains("ctdl-mail-selected")) {
97 messages_being_dragged.push(row.id); // Tell the clipboard what's being moved.
102 // The row being dragged is NOT selected. It will be dragged on its own, ignoring the selected rows.
104 messages_being_dragged.push(event.target.id); // Tell the clipboard what's being moved.
107 // Set the custom drag image to an envelope + number of messages being dragged
108 d = document.getElementById("ctdl_draggo");
109 d.innerHTML = "<font size='+2'><i class='fa fa-envelope' style='color: red'></i> " + count + "</font>"
110 event.dataTransfer.setDragImage(d, 0, 0);
111 event.dataTransfer.setData("text", messages_being_dragged);
115 // Render reply address for a message (FIXME figure out how to deal with "reply-to:")
116 function reply_addr(msg) {
118 //return([msg.from]);
121 return([msg.from + " <" + msg.rfca + ">"]);
126 // Render the To: recipients for a reply-all operation
127 function replyall_to(msg) {
128 return([...reply_addr(msg), ...msg.rcpt]);
132 // Render a message into the mailbox view
133 // (We want the message number and the message itself because we need to keep the msgnum for reply purposes)
134 function mail_render_one(msgnum, msg, target_div, include_controls) {
138 "<div class=\"ctdl-mmsg-wrapper\">" // begin message wrapper
141 if (include_controls) { // omit controls if this is a pull quote
143 render_userpic(msg.from) // user avatar
144 + "<div class=\"ctdl-mmsg-content\">" // begin content
145 + "<div class=\"ctdl-msg-header\">" // begin header
146 + "<span class=\"ctdl-msg-header-info\">" // begin header info on left side
147 + render_msg_author(msg, views.VIEW_MAILBOX)
148 + "<span class=\"ctdl-msgdate\">"
149 + string_timestamp(msg.time,0)
150 + "</span>" // end msgdate
151 + "</span>" // end header info on left side
152 + "<span class=\"ctdl-msg-header-buttons\">" // begin buttons on right side
154 + "<span class=\"ctdl-msg-button\">" // Reply (mail is always Quoted)
155 + "<a href=\"javascript:mail_compose(true,'"+msg.wefw+"','"+msgnum+"', reply_addr(msg), [], 'Re: '+msg.subj);\">"
156 + "<i class=\"fa fa-reply\"></i> "
160 + "<span class=\"ctdl-msg-button\">" // Reply-All (mail is always Quoted)
161 + "<a href=\"javascript:mail_compose(true,'"+msg.wefw+"','"+msgnum+"', replyall_to(msg), msg.cccc, 'Re: '+msg.subj);\">"
162 + "<i class=\"fa fa-reply-all\"></i> "
166 if (can_delete_messages) {
168 "<span class=\"ctdl-msg-button\">"
169 + "<a href=\"javascript:forum_delete_message('"+div+"','"+msg.msgnum+"');\">"
170 + "<i class=\"fa fa-trash\"></i> "
176 "</span>"; // end buttons on right side
178 // Display the To: recipients, if any are present
180 outmsg += "<br><span>" + _("To:") + " ";
181 for (let r=0; r<msg.rcpt.length; ++r) {
185 outmsg += escapeHTML(msg.rcpt[r]);
190 // Display the Cc: recipients, if any are present
192 outmsg += "<br><span>" + _("Cc:") + " ";
193 for (let r=0; r<msg.cccc.length; ++r) {
197 outmsg += escapeHTML(msg.cccc[r]);
202 // Display a subject line, but only if the message has a subject (internal Citadel messages often don't)
205 "<br><span class=\"ctdl-msgsubject\">" + msg.subj + "</span>";
209 "</div>"; // end header
212 // Display attachments, if any are present
214 let display_attachments = 0;
215 for (let r=0; r<msg.part.length; ++r) {
216 if (msg.part[r].disp == "attachment") {
217 if (display_attachments == 0) {
220 display_attachments += 1;
222 + "<a href=\"/ctdl/r/" + escapeHTMLURI(current_room) + "/" + msgnum + "/" + msg.part[r].partnum + "/" + escapeHTMLURI(msg.part[r].filename) + "\" target=\"_blank\">"
223 + "<i class=\"fa fa-paperclip\"></i> " + msg.part[r].partnum + ": " + msg.part[r].filename
224 + " (" + msg.part[r].len + " " + _("bytes") + ")"
229 if (display_attachments > 0) {
230 outmsg += "</ul><br>";
236 "<div class=\"ctdl-msg-body\" id=\"" + div + "_body\">" // begin body
238 + "</div>" // end body
239 + "</div>" // end content
240 + "</div>" // end wrapper
244 outmsg = "<div class=\"ctdl-mmsg-wrapper\">" + err.message + "</div>";
247 target_div.innerHTML = outmsg;
251 // display an individual message (note: this wants an actual div object, not a string containing the name of a div)
252 function mail_display_message(msgnum, target_div, include_controls) {
253 url = "/ctdl/r/" + escapeHTMLURI(current_room) + "/" + msgnum + "/json";
254 mail_fetch_msg = async() => {
255 response = await fetch(url);
256 msg = await(response.json());
258 mail_render_one(msgnum, msg, target_div, include_controls);
265 // A message has been selected...
266 function click_message(event, msgnum) {
267 var table = document.getElementById("ctdl-onscreen-mailbox");
270 // ctrl + click = toggle an individual message without changing existing selection
272 document.getElementById("ctdl-msgsum-" + msgnum).classList.toggle("ctdl-mail-selected");
275 // shift + click = select a range of messages (start with row 1 because row 0 is the header)
276 else if (event.shiftKey) {
277 for (i=1; row=table.rows[i]; ++i) {
278 m = parseInt(row["id"].substring(12)); // derive msgnum from row id
280 ((msgnum >= displayed_message) && (m >= displayed_message) && (m <= msgnum))
281 || ((msgnum <= displayed_message) && (m <= displayed_message) && (m >= msgnum))
283 row.classList.add("ctdl-mail-selected");
286 row.classList.remove("ctdl-mail-selected");
291 // click + no modifiers = select one message and unselect all others (start with row 1 because row 0 is the header)
293 for (i=1; row=table.rows[i]; ++i) {
294 if (row["id"] == "ctdl-msgsum-" + msgnum) {
295 row.classList.add("ctdl-mail-selected");
298 row.classList.remove("ctdl-mail-selected");
303 // display the message if it isn't already displayed
304 if (displayed_message != msgnum) {
305 displayed_message = msgnum;
306 mail_display_message(msgnum, document.getElementById("ctdl-mailbox-reading-pane"), 1);
311 // render one row in the mailbox table (this could be called from one of several places)
312 function mail_render_row(msg, is_selected) {
314 + "id=\"ctdl-msgsum-" + msg["msgnum"] + "\" "
315 + (is_selected ? "class=\"ctdl-mail-selected\" " : "")
316 + "onClick=\"click_message(event," + msg["msgnum"] + ");\""
317 + "onselectstart=\"return false;\" "
318 + "draggable=\"true\" "
319 + "ondragstart=\"mail_dragstart(event)\" "
321 + "<td class=\"ctdl-mail-subject\">" + msg["subject"] + "</td>"
322 + "<td class=\"ctdl-mail-sender\">" + msg["author"] + "</td>"
323 + "<td class=\"ctdl-mail-date\">" + string_timestamp(msg["time"],1) + "</td>"
324 + "<td class=\"ctdl-mail-msgnum\">" + msg["msgnum"] + "</td>"
330 // RENDERER FOR THIS VIEW
331 function view_render_mail() {
332 // Put the "enter new message" button into the topbar
333 document.getElementById("ctdl-newmsg-button").innerHTML = "<i class=\"fa fa-edit\"></i>" + _("Write mail");
334 document.getElementById("ctdl-newmsg-button").style.display = "block";
336 // Put the "delete message(s)" button into the topbar
337 let d = document.getElementById("ctdl-delete-button");
338 d.innerHTML = "<i class=\"fa fa-trash\"></i>" + _("Delete");
339 d.style.display = "block";
340 //d.addEventListener("click", mail_delete_selected);
342 document.getElementById("ctdl-main").innerHTML
343 = "<div id=\"ctdl-mailbox-grid-container\" class=\"ctdl-mailbox-grid-container\">"
344 + "<div id=\"ctdl-mailbox-pane\" class=\"ctdl-mailbox-pane\"></div>"
345 + "<div id=\"ctdl-mailbox-reading-pane\" class=\"ctdl-mailbox-reading-pane\"></div>"
349 highest_mailnum = 0; // Keep track of highest message number to track newly arrived messages
350 render_mailbox_display(newmail_notify.NO);
351 try { // if this was already set up, clear it so there aren't multiple
352 clearInterval(RefreshMailboxInterval);
356 RefreshMailboxInterval = setInterval(refresh_mail_display, 10000);
360 // Refresh the mailbox, either for the first time or whenever needed
361 function refresh_mail_display() {
362 // If the "ctdl-mailbox-pane" no longer exists, the user has navigated to a different part of the site,
363 // so cancel the refresh.
365 document.getElementById("ctdl-mailbox-pane").innerHTML;
368 clearInterval(RefreshMailboxInterval);
372 // Ask the server if the room has been written to since our last look at it.
373 url = "/ctdl/r/" + escapeHTMLURI(current_room) + "/stat";
374 fetch_stat = async() => {
375 response = await fetch(url);
376 stat = await(response.json());
377 if (stat.room_mtime > room_mtime) { // FIXME commented out to force refreshes
378 room_mtime = stat.room_mtime;
379 render_mailbox_display(newmail_notify.YES);
386 // This is where the rendering of the message list in the mailbox view is performed.
387 // Set notify to newmail_notify.NO or newmail_notify.YES depending on whether we are interested in the arrival of new messages.
388 function render_mailbox_display(notify) {
390 url = "/ctdl/r/" + escapeHTMLURI(current_room) + "/mailbox";
391 fetch_mailbox = async() => {
392 response = await fetch(url);
393 msgs = await(response.json());
395 var previously_selected = [];
396 var oldtable = document.getElementById("ctdl-onscreen-mailbox");
399 // If one or more messages was already selected, remember them so we can re-select them
400 if ( (displayed_message > 0) && (oldtable) ) {
401 for (i=0; row=oldtable.rows[i]; ++i) {
402 if (row.classList.contains("ctdl-mail-selected")) {
403 previously_selected.push(parseInt(row["id"].substring(12)));
408 // begin rendering the mailbox table
409 box = "<table id=\"ctdl-onscreen-mailbox\" class=\"ctdl-mailbox-table\" width=100%><tr>"
410 + "<th>" + _("Subject") + "</th>"
411 + "<th>" + _("Sender") + "</th>"
412 + "<th>" + _("Date") + "</th>"
416 for (let i=0; i<msgs.length; ++i) {
417 let m = parseInt(msgs[i].msgnum);
418 let s = (previously_selected.includes(m));
419 box += mail_render_row(msgs[i], s);
420 if (m > highest_mailnum) {
426 document.getElementById("ctdl-mailbox-pane").innerHTML = box;
427 document.addEventListener("keydown", mail_keypress);
434 // Compose a new mail message (called by the Reply button here, or by the dispatcher in views.js)
435 function mail_compose(is_quoted, references, quoted_msgnum, m_to, m_cc, m_subject) {
436 // m_to will be an array of zero or more recipients for the To: field. Convert it to a string.
438 m_to = Array.from(new Set(m_to)); // remove dupes
440 for (i=0; i<m_to.length; ++i) {
444 m_to_str += m_to[i].replaceAll("<", "<").replaceAll(">", ">");
451 // m_to will be an array of zero or more recipients for the Cc: field. Convert it to a string.
453 m_cc = Array.from(new Set(m_cc)); // remove dupes
455 for (i=0; i<m_cc.length; ++i) {
459 m_cc_str += m_cc[i].replaceAll("<", "<").replaceAll(">", ">");
466 quoted_div_name = randomString();
468 // Make the "Write mail" button disappear. We're already there!
469 document.getElementById("ctdl-newmsg-button").style.display = "none";
471 // is_quoted true or false depending on whether the user selected "reply quoted" (is this appropriate for mail?)
472 // references list of references, be sure to use this in a reply
473 // msgid if a reply, the msgid of the most recent message in the chain, the one to which we are replying
475 // Now display the screen. (Yes, I combined regular strings + template literals. I just learned template literals. Converting to all template literals would be fine.)
477 // Hidden values that we are storing right here in the document tree for later
478 "<input id=\"ctdl_mc_is_quoted\" style=\"display:none\" value=\"" + is_quoted + "\"></input>"
479 + "<input id=\"ctdl_mc_references\" style=\"display:none\" value=\"" + references + "\"></input>"
481 // Header fields, the composition window, and the button bar are arranged using a Grid layout.
482 + "<div id=\"ctdl-compose-mail\" class=\"ctdl-compose-mail\">"
484 // Visible To: field, plus a box to make the CC/BCC lines appear
485 + "<div class=\"ctdl-compose-to-label\">" + _("To:") + "</div>"
486 + "<div class=\"ctdl-compose-to-line\">"
487 + "<div class=\"ctdl-compose-to-field\" id=\"ctdl-compose-to-field\" contenteditable=\"true\">" + m_to_str + "</div>"
488 + "<div class=\"ctdl-cc-bcc-buttons ctdl-msg-button\" id=\"ctdl-cc-bcc-buttons\" "
489 + "onClick=\"make_cc_bcc_visible()\">"
490 + _("CC:") + "/" + _("BCC:") + "</div>"
494 + "<div class=\"ctdl-compose-cc-label\" id=\"ctdl-compose-cc-label\">" + _("CC:") + "</div>"
495 + "<div class=\"ctdl-compose-cc-field\" id=\"ctdl-compose-cc-field\" contenteditable=\"true\">" + m_cc_str + "</div>"
496 + "<div class=\"ctdl-compose-bcc-label\" id=\"ctdl-compose-bcc-label\">" + _("BCC:") + "</div>"
497 + "<div class=\"ctdl-compose-bcc-field\" id=\"ctdl-compose-bcc-field\" contenteditable=\"true\"></div>"
499 // Visible subject field
500 + "<div class=\"ctdl-compose-subject-label\">" + _("Subject:") + "</div>"
501 + "<div class=\"ctdl-compose-subject-field\" id=\"ctdl-compose-subject-field\" contenteditable=\"true\">" + m_subject + "</div>"
503 // Message composition box
504 + "<div class=\"ctdl-compose-message-box\" id=\"ctdl-editor-body\" contenteditable=\"true\">"
508 compose_screen += "<br><br><blockquote><div id=\"" + quoted_div_name + "\"></div></blockquote>";
511 // The button bar is a Grid element, and is also a Flexbox container.
514 <div class="ctdl-compose-toolbar">
515 <span class="ctdl-msg-button" onclick="mail_send_message()"><i class="fa fa-paper-plane" style="color:green"></i> ${_("Send message")} </span>
516 <span class="ctdl-msg-button"> ${_("Save to Drafts")} </span>
517 <span class="ctdl-msg-button" onClick="show_or_hide_attachments()"><i class="fa fa-paperclip" style="color:grey"></i> ${_("Attachments:")} <span id="ctdl_num_attachments"> ${num_attachments} </span></span>
518 <span class="ctdl-msg-button"> ${_("Contacts")} </span>
519 <span class="ctdl-msg-button" onClick="document.getElementById('ctdl-upload').style.display='none';gotoroom(current_room)"><i class="fa fa-trash" style="color:red"></i> ${_("Cancel")} </span>
523 document.getElementById("ctdl-main").innerHTML = compose_screen;
524 mail_display_message(quoted_msgnum, document.getElementById(quoted_div_name), 0);
526 document.getElementById("ctdl-compose-cc-label").style.display = "block";
527 document.getElementById("ctdl-compose-cc-field").style.display = "block";
530 activate_uploads("ctdl-editor-body");
534 // Turn the specified div into a place where we can upload. (Note: permanently changes the drag-and-drop behavior of that div.)
535 function activate_uploads(parent_div) {
536 document.getElementById(parent_div).innerHTML += `
537 <div class="ctdl-upload" id="ctdl-upload">
538 <div id="ctdl_attachments_title" class="ctdl-compose-attachments-title">
539 <div><h1><i class="fa fa-paperclip" style="color:grey"></i>` + _("Attachments:") + ` <span id="num_attachments">` + num_attachments + `</span></h1></div>
540 <div><h1><i class="fas fa-window-close" style="color:red" onClick="show_or_hide_attachments()"></i></h1></div>
543 <ul id="ctdl-upload_list">
544 <li>uploaded file</li>
545 <li>another uploaded file</li>
546 <li>philez and warez</li>
549 <div id="drop-area" class="ctdl-upload-drop-area">
550 <form class="my-form">
551 <p>${_("Drop files here to upload")}</p>
552 <input type="file" id="fileElem" multiple accept="*/*" onChange="handle_upload_files(this.files)">
558 // activate drag and drop (shamelessly swiped from https://www.smashingmagazine.com/2018/01/drag-drop-file-uploader-vanilla-js/ )
559 //let dropArea = document.getElementById("ctdl-upload");
560 let dropArea = document.getElementById(parent_div);
561 ;['dragenter', 'dragover', 'dragleave', 'drop'].forEach(eventName => {
562 dropArea.addEventListener(eventName, upload_prevent_defaults, false)
564 ;["dragenter", "dragover"].forEach(eventName => {
565 dropArea.addEventListener(eventName, upload_highlight, false)
567 ;['dragleave', 'drop'].forEach(eventName => {
568 dropArea.addEventListener(eventName, upload_unhighlight, false)
570 dropArea.addEventListener('drop', upload_handle_drop, false);
574 // prevent drag and drop events from propagating up through the DOM
575 function upload_prevent_defaults(e) {
581 function upload_handle_drop(e) {
582 let dt = e.dataTransfer;
583 let files = dt.files;
584 handle_upload_files(files);
588 function handle_upload_files(files) {
589 ([...files]).forEach(upload_file)
593 function upload_file(file) {
594 var url = '/ctdl/a/upload';
595 var xhr = new XMLHttpRequest();
596 var formData = new FormData();
597 xhr.open('POST', url, true);
599 xhr.addEventListener('readystatechange', function(e) {
600 console.log("readyState: " + xhr.readyState);
601 if (xhr.readyState == 4 && xhr.status == 200) {
602 num_attachments += 1;
603 document.getElementById("num_attachments").innerHTML = num_attachments;
605 // remove the "uploading in progress" message
606 let li = document.getElementById("ctdl_uploading_" + uploads_in_progress.toString());
607 li.parentNode.removeChild(li);
608 uploads_in_progress -= 1;
611 console.log("response: " + xhr.response);
612 console.log("responseText: " + xhr.responseText);
614 else if (xhr.readyState == 4 && xhr.status != 200) {
615 // remove the "uploading in progress" message (there was an error, so just let it disappear)
616 let li = document.getElementById("ctdl_uploading_" + uploads_in_progress.toString());
617 li.parentNode.removeChild(li);
618 uploads_in_progress -= 1;
622 formData.append('file', file);
624 uploads_in_progress += 1;
626 // Make an "uploading in progress" message appear in the uploads list!
627 progress = document.createElement("li");
628 progress.setAttribute("id", "ctdl_uploading_" + uploads_in_progress.toString());
629 progress.innerHTML = `<img src="/ctdl/s/images/throbber.gif" /> ` + _("Processing dropped files...");
630 document.getElementById("ctdl-upload_list").appendChild(progress);
634 function upload_highlight(e) {
635 let dropArea = document.getElementById("ctdl-upload");
636 dropArea.classList.add('highlight')
638 document.getElementById("ctdl-upload").style.display = "block"; /* also make it appear */
641 function upload_unhighlight(e) {
642 let dropArea = document.getElementById("ctdl-upload");
643 dropArea.classList.remove('highlight')
647 // Show or hide the attachments window in the composer
648 function show_or_hide_attachments() {
650 if (document.getElementById("ctdl-upload").style.display == "block") {
651 document.getElementById("ctdl-upload").style.display = "none"; /* turn it off */
654 document.getElementById("ctdl-upload").style.display = "block"; /* turn it on */
659 // Called when the user clicks the button to make the hidden "CC" and "BCC" lines appear.
660 // It is also called automatically during a Reply when CC is pre-populated.
661 function make_cc_bcc_visible() {
662 document.getElementById("ctdl-cc-bcc-buttons").style.display = "none";
663 document.getElementById("ctdl-compose-bcc-label").style.display = "block";
664 document.getElementById("ctdl-compose-bcc-field").style.display = "block";
668 // Helper function for mail_send_messages() to extract and decode metadata values.
669 function msm_field(element_name, separator) {
670 let s1 = document.getElementById(element_name).innerHTML;
671 let s2 = s1.replaceAll("|",separator); // Replace "|" with "!" because "|" is a field separator in Citadel
672 let s3 = decodeURI(s2);
673 let s4 = document.createElement("textarea"); // This One Weird Trick Unescapes All HTML Entities
680 // Save the posted message to the server
681 function mail_send_message() {
683 document.body.style.cursor = "wait";
684 let url = "/ctdl/r/" + escapeHTMLURI(current_room)
685 + "/dummy_name_for_new_mail"
686 + "?wefw=" + msm_field("ctdl_mc_references", "!") // references (if present)
687 + "&subj=" + msm_field("ctdl-compose-subject-field", " ") // subject (if present)
688 + "&mailto=" + msm_field("ctdl-compose-to-field", ",") // To: (required)
689 + "&mailcc=" + msm_field("ctdl-compose-cc-field", ",") // Cc: (if present)
690 + "&mailbcc=" + msm_field("ctdl-compose-bcc-field", ",") // Bcc: (if present)
692 boundary = randomString();
694 "--" + boundary + "\r\n"
695 + "Content-type: text/html\r\n"
696 + "Content-transfer-encoding: quoted-printable\r\n"
698 + quoted_printable_encode(
699 "<html><body>" + document.getElementById("ctdl-editor-body").innerHTML + "</body></html>"
701 + "--" + boundary + "--\r\n"
704 var request = new XMLHttpRequest();
705 request.open("PUT", url, true);
706 request.setRequestHeader("Content-type", "multipart/mixed; boundary=\"" + boundary + "\"");
707 request.onreadystatechange = function() {
708 if (request.readyState == 4) {
709 document.body.style.cursor = "default";
710 if (Math.trunc(request.status / 100) == 2) {
711 headers = request.getAllResponseHeaders().split("\n");
712 for (var i in headers) {
713 if (headers[i].startsWith("etag: ")) {
714 new_msg_num = headers[i].split(" ")[1];
718 // After saving the message, go back to the mailbox view.
719 gotoroom(current_room);
723 error_message = request.responseText;
724 if (error_message.length == 0) {
725 error_message = _("An error has occurred.");
727 alert(error_message); // editor remains open
731 request.send(body_text);