* Doxygen groups. Sorted the files into groups. so now we have a nice structure
[citadel.git] / webcit / messages.c
index 23a1e2ef6c3725c24c31ff6152ec7c5d76b2c8c5..454e5420f65c611953e89ebce2f207eecfdd6811 100644 (file)
@@ -3,6 +3,7 @@
  */
 /**
  * \defgroup MsgDisp Functions which deal with the fetching and displaying of messages.
+ * \ingroup WebcitDisplayItems
  *
  */
 /*@{*/
@@ -11,9 +12,9 @@
 #include "webserver.h"
 #include "groupdav.h"
 
-#define SUBJ_COL_WIDTH_PCT                 50 /**< ??? */
-#define SENDER_COL_WIDTH_PCT           30 /**< ??? */
-#define DATE_PLUS_BUTTONS_WIDTH_PCT    20 /**< ??? */
+#define SUBJ_COL_WIDTH_PCT             50      /**< Mailbox view column width */
+#define SENDER_COL_WIDTH_PCT           30      /**< Mailbox view column width */
+#define DATE_PLUS_BUTTONS_WIDTH_PCT    20      /**< Mailbox view column width */
 
 /**
  * Address book entry (keep it short and sweet, it's just a quickie lookup
@@ -21,7 +22,7 @@
  */
 struct addrbookent {
        char ab_name[64]; /**< name string */
-       long ab_msgnum;   /**< number in the citadel???? */
+       long ab_msgnum;   /**< message number of address book entry */
 };
 
 
@@ -942,7 +943,7 @@ void read_message(long msgnum, int printable_view, char *section) {
 
        else /** HTML is fun, but we've got to strip it first */
        if (!strcasecmp(mime_content_type, "text/html")) {
-               output_html(mime_charset);
+               output_html(mime_charset, (WC->wc_view == VIEW_WIKI ? 1 : 0));
        }
 
        /** Unknown weirdness */
@@ -1025,7 +1026,8 @@ ENDBODY:
 /**
  * \brief Unadorned HTML output of an individual message, suitable
  * for placing in a hidden iframe, for printing, or whatever
- * \param msgnum_as_string the message to embed???
+ *
+ * \param msgnum_as_string Message number, as a string instead of as a long int
  */
 void embed_message(char *msgnum_as_string) {
        long msgnum = 0L;
@@ -1039,7 +1041,8 @@ void embed_message(char *msgnum_as_string) {
 
 /**
  * \brief Printable view of a message
- * \param msgnum_as_string the message to print??? 
+ *
+ * \param msgnum_as_string Message number, as a string instead of as a long int
  */
 void print_message(char *msgnum_as_string) {
        long msgnum = 0L;
@@ -1068,7 +1071,8 @@ void print_message(char *msgnum_as_string) {
 
 /**
  * \brief Display a message's headers
- * \param msgnum_as_string the message headers to print???
+ *
+ * \param msgnum_as_string Message number, as a string instead of as a long int
  */
 void display_headers(char *msgnum_as_string) {
        long msgnum = 0L;
@@ -1098,15 +1102,16 @@ void display_headers(char *msgnum_as_string) {
 
 /**
  * \brief Read message in simple, JavaScript-embeddable form for 'forward'
- * or 'reply quoted' operations.
+ *        or 'reply quoted' operations.
  *
  * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
  *       in this function.  Doing so would throw a JavaScript error in the
  *       'supplied text' argument to the editor.
- * \param msgnum the citadel message number
- * \param forward_attachments atachment to forward???
+ *
+ * \param msgnum Message number of the message we want to quote
+ * \param forward_attachments Nonzero if we want attachments to be forwarded
  */
-void pullquote_message(long msgnum, int forward_attachments) {
+void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
        char buf[SIZ];
        char mime_partnum[256];
        char mime_filename[256];
@@ -1160,57 +1165,59 @@ void pullquote_message(long msgnum, int forward_attachments) {
                        wprintf(_("unexpected end of message"));
                        return;
                }
-               if (!strncasecmp(buf, "nhdr=yes", 8))
-                       nhdr = 1;
-               if (nhdr == 1)
-                       buf[0] = '_';
-               if (!strncasecmp(buf, "type=", 5))
-                       format_type = atoi(&buf[5]);
-               if (!strncasecmp(buf, "from=", 5)) {
-                       strcpy(from, &buf[5]);
-                       wprintf(_("from "));
+               if (include_headers) {
+                       if (!strncasecmp(buf, "nhdr=yes", 8))
+                               nhdr = 1;
+                       if (nhdr == 1)
+                               buf[0] = '_';
+                       if (!strncasecmp(buf, "type=", 5))
+                               format_type = atoi(&buf[5]);
+                       if (!strncasecmp(buf, "from=", 5)) {
+                               strcpy(from, &buf[5]);
+                               wprintf(_("from "));
 #ifdef HAVE_ICONV
-                       utf8ify_rfc822_string(from);
+                               utf8ify_rfc822_string(from);
 #endif
-                       msgescputs(from);
-               }
-               if (!strncasecmp(buf, "subj=", 5)) {
-                       strcpy(m_subject, &buf[5]);
-               }
-               if ((!strncasecmp(buf, "hnod=", 5))
-                   && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
-                       wprintf("(%s) ", &buf[5]);
-               }
-               if ((!strncasecmp(buf, "room=", 5))
-                   && (strcasecmp(&buf[5], WC->wc_roomname))
-                   && (strlen(&buf[5])>0) ) {
-                       wprintf(_("in "));
-                       wprintf("%s&gt; ", &buf[5]);
-               }
-               if (!strncasecmp(buf, "rfca=", 5)) {
-                       strcpy(rfca, &buf[5]);
-                       wprintf("&lt;");
-                       msgescputs(rfca);
-                       wprintf("&gt; ");
-               }
-
-               if (!strncasecmp(buf, "node=", 5)) {
-                       strcpy(node, &buf[5]);
-                       if ( ((WC->room_flags & QR_NETWORK)
-                       || ((strcasecmp(&buf[5], serv_info.serv_nodename)
-                       && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
-                       && (strlen(rfca)==0)
-                       ) {
-                               wprintf("@%s ", &buf[5]);
+                               msgescputs(from);
+                       }
+                       if (!strncasecmp(buf, "subj=", 5)) {
+                               strcpy(m_subject, &buf[5]);
+                       }
+                       if ((!strncasecmp(buf, "hnod=", 5))
+                           && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
+                               wprintf("(%s) ", &buf[5]);
+                       }
+                       if ((!strncasecmp(buf, "room=", 5))
+                           && (strcasecmp(&buf[5], WC->wc_roomname))
+                           && (strlen(&buf[5])>0) ) {
+                               wprintf(_("in "));
+                               wprintf("%s&gt; ", &buf[5]);
+                       }
+                       if (!strncasecmp(buf, "rfca=", 5)) {
+                               strcpy(rfca, &buf[5]);
+                               wprintf("&lt;");
+                               msgescputs(rfca);
+                               wprintf("&gt; ");
+                       }
+       
+                       if (!strncasecmp(buf, "node=", 5)) {
+                               strcpy(node, &buf[5]);
+                               if ( ((WC->room_flags & QR_NETWORK)
+                               || ((strcasecmp(&buf[5], serv_info.serv_nodename)
+                               && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
+                               && (strlen(rfca)==0)
+                               ) {
+                                       wprintf("@%s ", &buf[5]);
+                               }
+                       }
+                       if (!strncasecmp(buf, "rcpt=", 5)) {
+                               wprintf(_("to "));
+                               wprintf("%s ", &buf[5]);
+                       }
+                       if (!strncasecmp(buf, "time=", 5)) {
+                               fmt_date(now, atol(&buf[5]), 0);
+                               wprintf("%s ", now);
                        }
-               }
-               if (!strncasecmp(buf, "rcpt=", 5)) {
-                       wprintf(_("to "));
-                       wprintf("%s ", &buf[5]);
-               }
-               if (!strncasecmp(buf, "time=", 5)) {
-                       fmt_date(now, atol(&buf[5]), 0);
-                       wprintf("%s ", now);
                }
 
                /**
@@ -1226,23 +1233,25 @@ void pullquote_message(long msgnum, int forward_attachments) {
 
        }
 
-       wprintf("<br>");
+       if (include_headers) {
+               wprintf("<br>");
 
 #ifdef HAVE_ICONV
-       utf8ify_rfc822_string(m_subject);
+               utf8ify_rfc822_string(m_subject);
 #endif
-       if (strlen(m_subject) > 0) {
-               wprintf(_("Subject:"));
-               wprintf(" ");
-               msgescputs(m_subject);
+               if (strlen(m_subject) > 0) {
+                       wprintf(_("Subject:"));
+                       wprintf(" ");
+                       msgescputs(m_subject);
+                       wprintf("<br />");
+               }
+
+               /**
+                * Begin body
+                */
                wprintf("<br />");
        }
 
-       /**
-        * Begin body
-        */
-       wprintf("<br>");
-
        /**
         * Learn the content type
         */
@@ -1330,6 +1339,7 @@ void pullquote_message(long msgnum, int forward_attachments) {
        /** HTML just gets escaped and stuffed back into the editor */
        else if (!strcasecmp(mime_content_type, "text/html")) {
                while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
+                       strcat(buf, "\n");
                        msgescputs(buf);
                }
        }
@@ -1400,8 +1410,9 @@ ENDBODY:
 }
 
 /**
- * \brief display sumarized item???
- * \param num hom many? which???
+ * \brief Display one row in the mailbox summary view
+ *
+ * \param num The row number to be displayed
  */
 void display_summarized(int num) {
        char datebuf[64];
@@ -1800,9 +1811,10 @@ int load_msg_ptrs(char *servcmd, int with_headers)
 }
 
 /**
- * \brief compare what????
- * \param s1 first thing to compare 
- * \param s2 second thing to compare
+ * \brief qsort() compatible function to compare two longs in descending order.
+ *
+ * \param s1 first number to compare 
+ * \param s2 second number to compare
  */
 int longcmp_r(const void *s1, const void *s2) {
        long l1;
@@ -1818,9 +1830,10 @@ int longcmp_r(const void *s1, const void *s2) {
 
  
 /**
- * \brief compare what????
- * \param s1 first thing to compare 
- * \param s2 second thing to compare
+ * \brief qsort() compatible function to compare two message summary structs by ascending subject.
+ *
+ * \param s1 first item to compare 
+ * \param s2 second item to compare
  */
 int summcmp_subj(const void *s1, const void *s2) {
        struct message_summary *summ1;
@@ -1832,9 +1845,10 @@ int summcmp_subj(const void *s1, const void *s2) {
 }
 
 /**
- * \brief compare what????
- * \param s1 first thing to compare 
- * \param s2 second thing to compare
+ * \brief qsort() compatible function to compare two message summary structs by descending subject.
+ *
+ * \param s1 first item to compare 
+ * \param s2 second item to compare
  */
 int summcmp_rsubj(const void *s1, const void *s2) {
        struct message_summary *summ1;
@@ -1846,9 +1860,10 @@ int summcmp_rsubj(const void *s1, const void *s2) {
 }
 
 /**
- * \brief compare what????
- * \param s1 first thing to compare 
- * \param s2 second thing to compare
+ * \brief qsort() compatible function to compare two message summary structs by ascending sender.
+ *
+ * \param s1 first item to compare 
+ * \param s2 second item to compare
  */
 int summcmp_sender(const void *s1, const void *s2) {
        struct message_summary *summ1;
@@ -1860,9 +1875,10 @@ int summcmp_sender(const void *s1, const void *s2) {
 }
 
 /**
- * \brief compare what????
- * \param s1 first thing to compare 
- * \param s2 second thing to compare
+ * \brief qsort() compatible function to compare two message summary structs by descending sender.
+ *
+ * \param s1 first item to compare 
+ * \param s2 second item to compare
  */
 int summcmp_rsender(const void *s1, const void *s2) {
        struct message_summary *summ1;
@@ -1874,9 +1890,10 @@ int summcmp_rsender(const void *s1, const void *s2) {
 }
 
 /**
- * \brief compare what????
- * \param s1 first thing to compare 
- * \param s2 second thing to compare
+ * \brief qsort() compatible function to compare two message summary structs by ascending date.
+ *
+ * \param s1 first item to compare 
+ * \param s2 second item to compare
  */
 int summcmp_date(const void *s1, const void *s2) {
        struct message_summary *summ1;
@@ -1891,9 +1908,10 @@ int summcmp_date(const void *s1, const void *s2) {
 }
 
 /**
- * \brief compare what????
- * \param s1 first thing to compare 
- * \param s2 second thing to compare
+ * \brief qsort() compatible function to compare two message summary structs by descending date.
+ *
+ * \param s1 first item to compare 
+ * \param s2 second item to compare
  */
 int summcmp_rdate(const void *s1, const void *s2) {
        struct message_summary *summ1;
@@ -1907,9 +1925,12 @@ int summcmp_rdate(const void *s1, const void *s2) {
        else return 0;
 }
 
+
+
 /**
  * \brief command loop for reading messages
- * \param oper what???
+ *
+ * \param oper Set to "readnew" or "readold" or "readfwd" or "headers"
  */
 void readloop(char *oper)
 {
@@ -2182,6 +2203,11 @@ void readloop(char *oper)
                );
        }
 
+       if (is_notes) {
+               wprintf("<div align=center>%s</div>\n", _("Click on any note to edit it."));
+               wprintf("<div id=\"new_notes_here\"></div>\n");
+       }
+
        for (a = 0; a < nummsgs; ++a) {
                if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
 
@@ -2527,12 +2553,13 @@ void post_message(void)
                        _("Automatically cancelled because you have already "
                        "saved this message."));
        } else {
-               sprintf(buf, "ENT0 1|%s|%d|4|%s|||%s|%s",
+               sprintf(buf, "ENT0 1|%s|%d|4|%s|||%s|%s|%s",
                        bstr("recp"),
                        is_anonymous,
                        bstr("subject"),
                        bstr("cc"),
-                       bstr("bcc")
+                       bstr("bcc"),
+                       bstr("wikipage")
                );
                serv_puts(buf);
                serv_getln(buf, sizeof buf);
@@ -2556,7 +2583,27 @@ void post_message(void)
        }
 
        free_attachments(WC);
-       readloop("readnew");
+
+       /**
+        *  We may have been supplied with instructions regarding the location
+        *  to which we must return after posting.  If found, go there.
+        */
+       if (strlen(bstr("return_to")) > 0) {
+               http_redirect(bstr("return_to"));
+       }
+       /**
+        *  If we were editing a page in a wiki room, go to that page now.
+        */
+       else if (strlen(bstr("wikipage")) > 0) {
+               snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
+               http_redirect(buf);
+       }
+       /**
+        *  Otherwise, just go to the "read messages" loop.
+        */
+       else {
+               readloop("readnew");
+       }
 }
 
 
@@ -2575,6 +2622,7 @@ void display_enter(void)
        int recipient_bad = 0;
        int i;
        int is_anonymous = 0;
+       long existing_page = (-1L);
 
        if (strlen(bstr("force_room")) > 0) {
                gotoroom(bstr("force_room"));
@@ -2638,7 +2686,8 @@ void display_enter(void)
 
        /** Now check our actual recipients if there are any */
        if (recipient_required) {
-               sprintf(buf, "ENT0 0|%s|%d|0||||%s|%s", bstr("recp"), is_anonymous, bstr("cc"), bstr("bcc"));
+               sprintf(buf, "ENT0 0|%s|%d|0||||%s|%s|%s", bstr("recp"), is_anonymous,
+                       bstr("cc"), bstr("bcc"), bstr("wikipage"));
                serv_puts(buf);
                serv_getln(buf, sizeof buf);
 
@@ -2671,11 +2720,18 @@ void display_enter(void)
        stresc(&buf[strlen(buf)], WC->wc_roomname, 1, 1);
 
        /** begin message entry screen */
-       wprintf("<form enctype=\"multipart/form-data\" "
-               "method=\"POST\" action=\"post\" "
+       wprintf("<form "
+               "enctype=\"multipart/form-data\" "
+               "method=\"POST\" "
+               "accept-charset=\"UTF-8\" "
+               "action=\"post\" "
                "name=\"enterform\""
                ">\n");
        wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
+       if (WC->wc_view == VIEW_WIKI) {
+               wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
+       }
+       wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
 
        wprintf("<img src=\"static/newmess3_24x.gif\" align=middle alt=\" \">");
        wprintf("%s\n", buf);   /** header bar */
@@ -2762,17 +2818,27 @@ void display_enter(void)
                wprintf("<br><div align=center><i>");
                wprintf(_("--- forwarded message ---"));
                wprintf("</i></div><br>");
-               pullquote_message(atol(bstr("fwdquote")), 1);
+               pullquote_message(atol(bstr("fwdquote")), 1, 1);
        }
 
        /** If we're replying quoted, insert the quote here... */
        else if (atol(bstr("replyquote")) > 0L) {
                wprintf("<br>"
                        "<blockquote>");
-               pullquote_message(atol(bstr("replyquote")), 0);
+               pullquote_message(atol(bstr("replyquote")), 0, 1);
                wprintf("</blockquote>\n\n");
        }
 
+       /** If we're editing a wiki page, insert the existing page here... */
+       else if (WC->wc_view == VIEW_WIKI) {
+               safestrncpy(buf, bstr("wikipage"), sizeof buf);
+               str_wiki_index(buf);
+               existing_page = locate_message_by_uid(buf);
+               if (existing_page >= 0L) {
+                       pullquote_message(existing_page, 1, 0);
+               }
+       }
+
        /** Insert our signature if appropriate... */
        if ( (WC->is_mailbox) && (strcmp(bstr("sig_inserted"), "yes")) ) {
                get_preference("use_sig", buf, sizeof buf);