]> code.citadel.org Git - citadel.git/blobdiff - webcit/messages.c
* sample aproach to use the citadel commandline client html renderer to create a...
[citadel.git] / webcit / messages.c
index dd520d289cf0c62800351d0005b0954eac1face8..2bf9619c1fca4ff5a9cd74444ca17534959f9537 100644 (file)
@@ -8,9 +8,9 @@
  */
 /*@{*/
 #include "webcit.h"
-#include "vcard.h"
 #include "webserver.h"
 #include "groupdav.h"
+#include "html.h"
 
 #define SUBJ_COL_WIDTH_PCT             50      /**< Mailbox view column width */
 #define SENDER_COL_WIDTH_PCT           30      /**< Mailbox view column width */
@@ -61,7 +61,7 @@ iconv_t ctdl_iconv_open(const char *tocode, const char *fromcode)
  * \param buf the stringbuffer to process
  */
 void utf8ify_rfc822_string(char *buf) {
-       char *start, *end;
+       char *start, *end, *next, *nextend, *ptr;
        char newbuf[1024];
        char charset[128];
        char encoding[16];
@@ -74,7 +74,7 @@ void utf8ify_rfc822_string(char *buf) {
        char *isav;                     /**< Saved pointer to input buffer */
        char *osav;                     /**< Saved pointer to output buffer */
        int passes = 0;
-       int i, len;
+       int i, len, delta;
        int illegal_non_rfc2047_encoding = 0;
 
        /** Sometimes, badly formed messages contain strings which were simply
@@ -113,6 +113,54 @@ void utf8ify_rfc822_string(char *buf) {
                }
        }
 
+       /* pre evaluate the first pair */
+       nextend = end = NULL;
+       len = strlen(buf);
+       start = strstr(buf, "=?");
+       if (start != NULL)
+               end = strstr(start, "?=");
+
+       while ((start != NULL) && (end != NULL))
+       {
+               next = strstr(end, "=?");
+               if (next != NULL)
+                       nextend = strstr(next, "?=");
+               if (nextend == NULL)
+                       next = NULL;
+
+               /* did we find two partitions */
+               if ((next != NULL) && 
+                   ((next - end) > 2))
+               {
+                       ptr = end + 2;
+                       while ((ptr < next) && 
+                              (isspace(*ptr) ||
+                               (*ptr == '\r') ||
+                               (*ptr == '\n') || 
+                               (*ptr == '\t')))
+                               ptr ++;
+                       /* did we find a gab just filled with blanks? */
+                       if (ptr == next)
+                       {
+                               memmove (end + 2,
+                                        next,
+                                        len - (next - start));
+
+                               /* now terminate the gab at the end */
+                               delta = (next - end) - 2;
+                               len -= delta;
+                               buf[len] = '\0';
+
+                               /* move next to its new location. */
+                               next -= delta;
+                               nextend -= delta;
+                       }
+               }
+               /* our next-pair is our new first pair now. */
+               start = next;
+               end = nextend;
+       }
+
        /** Now we handle foreign character sets properly encoded
         *  in RFC2047 format.
         */
@@ -210,7 +258,7 @@ void utf8ify_rfc822_string(char *buf) {
  * \param      maxlen          Maximum size of target buffer.
  * \param      source          Source string to be encoded.
  */
-void rfc2047encode(char *target, int maxlen, char *source)
+void webcit_rfc2047encode(char *target, int maxlen, char *source)
 {
        int need_to_encode = 0;
        int i, len;
@@ -446,7 +494,12 @@ void display_parsed_vcard(struct vCard *v, int full) {
                        }
                        
                        len = strlen(v->prop[i].value);
-       
+                       /* if we have some untagged QP, detect it here. */
+                       if (!is_qp && (strstr(v->prop[i].value, "=?")!=NULL))
+#ifdef HAVE_ICONV
+                               utf8ify_rfc822_string(v->prop[i].value);
+#endif
+
                        if (is_qp) {
                                // %ff can become 6 bytes in utf8 
                                thisvalue = malloc(len * 2 + 3); 
@@ -492,16 +545,20 @@ void display_parsed_vcard(struct vCard *v, int full) {
                        }
        
                        else if (!strcasecmp(firsttoken, "email")) {
+                               size_t len;
                                if (!IsEmptyStr(mailto)) strcat(mailto, "<br />");
-                               long len;
                                strcat(mailto,
                                        "<a href=\"display_enter"
                                        "?force_room=_MAIL_?recp=");
 
-                               urlesc(&mailto[strlen(mailto)], fullname);
-                               urlesc(&mailto[strlen(mailto)], " <");
-                               urlesc(&mailto[strlen(mailto)], thisvalue);
-                               urlesc(&mailto[strlen(mailto)], ">");
+                               len = strlen(mailto);
+                               urlesc(&mailto[len], SIZ - len,  fullname);
+                               len = strlen(mailto);
+                               urlesc(&mailto[len], SIZ - len, " <");
+                               len = strlen(mailto);
+                               urlesc(&mailto[len], SIZ - len, thisvalue);
+                               len = strlen(mailto);
+                               urlesc(&mailto[len], SIZ - len, ">");
 
                                strcat(mailto, "\">");
                                len = strlen(mailto);
@@ -630,6 +687,9 @@ void display_vcard(char *vcard_source, char alpha, int full, char *storename) {
 
        name = vcard_get_prop(v, "n", 1, 0, 0);
        if (name != NULL) {
+#ifdef HAVE_ICONV
+               utf8ify_rfc822_string(name);
+#endif
                strcpy(buf, name);
                this_alpha = buf[0];
        }
@@ -654,41 +714,42 @@ struct attach_link {
 };
 
 
-/**
- * \brief I wanna SEE that message!  
- * \param msgnum the citadel number of the message to display
- * \param printable_view are we doing a print view?
- * \param section Optional for encapsulated message/rfc822 submessage)
+/*
+ * I wanna SEE that message!
+ *
+ * msgnum              Message number to display
+ * printable_view      Nonzero to display a printable view
+ * section             Optional for encapsulated message/rfc822 submessage
  */
 void read_message(long msgnum, int printable_view, char *section) {
        char buf[SIZ];
-       char mime_partnum[256];
-       char mime_name[256];
-       char mime_filename[256];
-       char escaped_mime_filename[256];
-       char mime_content_type[256];
-       char mime_charset[256];
-       char mime_disposition[256];
+       char mime_partnum[256] = "";
+       char mime_name[256] = "";
+       char mime_filename[256] = "";
+       char escaped_mime_filename[256] = "";
+       char mime_content_type[256] = "";
+       char mime_charset[256] = "";
+       char mime_disposition[256] = "";
        int mime_length;
        struct attach_link *attach_links = NULL;
        int num_attach_links = 0;
-       char mime_submessages[256];
-       char m_subject[256];
-       char m_cc[1024];
-       char from[256];
-       char node[256];
-       char rfca[256];
-       char reply_to[512];
-       char reply_all[4096];
-       char now[64];
+       char mime_submessages[256] = "";
+       char m_subject[256] = "";
+       char m_cc[1024] = "";
+       char from[256] = "";
+       char node[256] = "";
+       char rfca[256] = "";
+       char reply_to[512] = "";
+       char reply_all[4096] = "";
+       char now[64] = "";
        int format_type = 0;
        int nhdr = 0;
        int bq = 0;
        int i = 0;
-       char vcard_partnum[256];
-       char cal_partnum[256];
+       char vcard_partnum[256] = "";
+       char cal_partnum[256] = "";
        char *part_source = NULL;
-       char msg4_partnum[32];
+       char msg4_partnum[32] = "";
 #ifdef HAVE_ICONV
        iconv_t ic = (iconv_t)(-1) ;
        char *ibuf;                /**< Buffer of characters to be converted */
@@ -698,13 +759,6 @@ void read_message(long msgnum, int printable_view, char *section) {
        char *osav;                /**< Saved pointer to output buffer       */
 #endif
 
-       strcpy(from, "");
-       strcpy(node, "");
-       strcpy(rfca, "");
-       strcpy(reply_to, "");
-       strcpy(reply_all, "");
-       strcpy(vcard_partnum, "");
-       strcpy(cal_partnum, "");
        strcpy(mime_content_type, "text/plain");
        strcpy(mime_charset, "us-ascii");
        strcpy(mime_submessages, "");
@@ -813,7 +867,7 @@ void read_message(long msgnum, int printable_view, char *section) {
                        wprintf(" ");
                }
                if (!strncasecmp(buf, "time=", 5)) {
-                       fmt_date(now, atol(&buf[5]), 0);
+                       webcit_fmt_date(now, atol(&buf[5]), 0);
                        wprintf("<span>");
                        wprintf("%s ", now);
                        wprintf("</span>");
@@ -858,7 +912,7 @@ void read_message(long msgnum, int printable_view, char *section) {
                                attach_links = realloc(attach_links,
                                        (num_attach_links*sizeof(struct attach_link)));
                                safestrncpy(attach_links[num_attach_links-1].partnum, mime_partnum, 32);
-                               urlesc(escaped_mime_filename, mime_filename);
+                               urlesc(escaped_mime_filename, 265, mime_filename);
                                snprintf(attach_links[num_attach_links-1].html, 1024,
                                        "<img src=\"static/diskette_24x.gif\" "
                                        "border=0 align=middle>\n"
@@ -884,7 +938,8 @@ void read_message(long msgnum, int printable_view, char *section) {
                                strcpy(vcard_partnum, mime_partnum);
                        }
 
-                       if (!strcasecmp(mime_content_type, "text/calendar")) {
+                       if (  (!strcasecmp(mime_content_type, "text/calendar"))
+                          || (!strcasecmp(mime_content_type, "application/ics")) ) {
                                strcpy(cal_partnum, mime_partnum);
                        }
 
@@ -1038,9 +1093,7 @@ void read_message(long msgnum, int printable_view, char *section) {
        strcpy(mime_content_type, "text/plain");
        while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
                if (!strcmp(buf, "000")) {
-                       wprintf("<i>");
-                       wprintf(_("unexpected end of message"));
-                       wprintf(" (2)</i><br /><br />\n");
+                       /* This is not necessarily an error condition.  See bug #226. */
                        goto ENDBODY;
                }
                if (!strncasecmp(buf, "X-Citadel-MSG4-Partnum:", 23)) {
@@ -1150,7 +1203,8 @@ void read_message(long msgnum, int printable_view, char *section) {
                while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
        }
 
-       /** If there are attached submessages, display them now... */
+ENDBODY:       /* If there are attached submessages, display them now... */
+
        if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
                for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
                        extract_token(buf, mime_submessages, i, '|', sizeof buf);
@@ -1206,7 +1260,6 @@ void read_message(long msgnum, int printable_view, char *section) {
                part_source = NULL;
        }
 
-ENDBODY:
        wprintf("</div>\n");
 
        /** end everythingamundo table */
@@ -1331,6 +1384,7 @@ void pullquote_message(long msgnum, int forward_attachments, int include_headers
        char from[256];
        char node[256];
        char rfca[256];
+       char to[256];
        char reply_to[512];
        char now[256];
        int format_type = 0;
@@ -1415,10 +1469,14 @@ void pullquote_message(long msgnum, int forward_attachments, int include_headers
                        }
                        if (!strncasecmp(buf, "rcpt=", 5)) {
                                wprintf(_("to "));
-                               wprintf("%s ", &buf[5]);
+                               strcpy(to, &buf[5]);
+#ifdef HAVE_ICONV
+                               utf8ify_rfc822_string(to);
+#endif
+                               wprintf("%s ", to);
                        }
                        if (!strncasecmp(buf, "time=", 5)) {
-                               fmt_date(now, atol(&buf[5]), 0);
+                               webcit_fmt_date(now, atol(&buf[5]), 0);
                                wprintf("%s ", now);
                        }
                }
@@ -1651,7 +1709,8 @@ void display_summarized(int num) {
        );
 
        wprintf("<td width=%d%%>", SUBJ_COL_WIDTH_PCT);
-       escputs(WC->summ[num].subj);
+
+       escputs(WC->summ[num].subj);//////////////////////////////////TODO: QP DECODE
        wprintf("</td>");
 
        wprintf("<td width=%d%%>", SENDER_COL_WIDTH_PCT);
@@ -1659,7 +1718,7 @@ void display_summarized(int num) {
        wprintf("</td>");
 
        wprintf("<td width=%d%%>", DATE_PLUS_BUTTONS_WIDTH_PCT);
-       fmt_date(datebuf, WC->summ[num].date, 1);       /* brief */
+       webcit_fmt_date(datebuf, WC->summ[num].date, 1);        /* brief */
        escputs(datebuf);
        wprintf("</td>");
 
@@ -2004,17 +2063,21 @@ int load_msg_ptrs(char *servcmd, int with_headers)
                                safestrncpy(WC->summ[nummsgs-1].subj,
                                        _("(no subject)"), sizeof WC->summ[nummsgs-1].subj);
                                if (!IsEmptyStr(fullname)) {
+#ifdef HAVE_ICONV
+                               /** Handle senders with RFC2047 encoding */
+                                       utf8ify_rfc822_string(fullname);
+#endif
                                        safestrncpy(WC->summ[nummsgs-1].from,
                                                fullname, sizeof WC->summ[nummsgs-1].from);
                                }
                                if (!IsEmptyStr(subject)) {
-                               safestrncpy(WC->summ[nummsgs-1].subj, subject,
-                                       sizeof WC->summ[nummsgs-1].subj);
-                               }
 #ifdef HAVE_ICONV
                                /** Handle subjects with RFC2047 encoding */
-                               utf8ify_rfc822_string(WC->summ[nummsgs-1].subj);
+                                       utf8ify_rfc822_string(subject);
 #endif
+                                       safestrncpy(WC->summ[nummsgs-1].subj, subject,
+                                                   sizeof WC->summ[nummsgs-1].subj);
+                               }
                                if (strlen(WC->summ[nummsgs-1].subj) > 75) {
                                        strcpy(&WC->summ[nummsgs-1].subj[72], "...");
                                }
@@ -2284,7 +2347,7 @@ void readloop(char *oper)
         * new messages.
         */
        strcpy(old_msgs, "");
-       if (is_summary) {
+       if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR)){
                serv_puts("GTSN");
                serv_getln(buf, sizeof buf);
                if (buf[0] == '2') {
@@ -2296,7 +2359,7 @@ void readloop(char *oper)
 
        if (WCC->wc_default_view == VIEW_CALENDAR) {            /**< calendar */
                is_calendar = 1;
-               strcpy(cmd, "MSGS ALL");
+               strcpy(cmd, "MSGS ALL|||1");
                maxmsgs = 32767;
        }
        if (WCC->wc_default_view == VIEW_TASKS) {               /**< tasks */
@@ -2333,7 +2396,7 @@ void readloop(char *oper)
                goto DONE;
        }
 
-       if (is_summary) {
+       if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR)){
                for (a = 0; a < nummsgs; ++a) {
                        /** Are you a new message, or an old message? */
                        if (is_summary) {
@@ -2474,7 +2537,7 @@ void readloop(char *oper)
         */
        if (is_bbview) {
                /** begin bbview scroller */
-               wprintf("<form name=\"msgomatictop\" class=\"selector_top\" >");
+               wprintf("<form name=\"msgomatictop\" class=\"selector_top\" > \n <p>");
                wprintf(_("Reading #"), lowest_displayed, highest_displayed);
 
                wprintf("<select name=\"whichones\" size=\"1\" "
@@ -2548,7 +2611,7 @@ void readloop(char *oper)
                wprintf(_("newest to oldest"));
                wprintf("\n");
        
-               wprintf("</select></form>\n");
+               wprintf("</p></form>\n");
                /** end bbview scroller */
        }
 
@@ -2559,7 +2622,6 @@ void readloop(char *oper)
 
 
 
-
        for (a = 0; a < nummsgs; ++a) {
                if ((WCC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
 
@@ -2577,13 +2639,13 @@ void readloop(char *oper)
                                addrbook[num_ab-1].ab_msgnum = WCC->msgarr[a];
                        }
                        else if (is_calendar) {
-                               display_calendar(WCC->msgarr[a]);
+                               display_calendar(WCC->msgarr[a], WCC->summ[a].is_new);
                        }
                        else if (is_tasks) {
-                               display_task(WCC->msgarr[a]);
+                               display_task(WCC->msgarr[a], WCC->summ[a].is_new);
                        }
                        else if (is_notes) {
-                               display_note(WCC->msgarr[a]);
+                               display_note(WCC->msgarr[a], WCC->summ[a].is_new);
                        }
                        else {
                                if (displayed_msgs == NULL) {
@@ -2646,7 +2708,7 @@ void readloop(char *oper)
         */
        if (is_bbview) {
                /** begin bbview scroller */
-               wprintf("<form name=\"msgomatic\" class=\"selector_bottom\" >");
+               wprintf("<form name=\"msgomatic\" class=\"selector_bottom\" > \n <p>");
                wprintf(_("Reading #"), lowest_displayed, highest_displayed);
 
                wprintf("<select name=\"whichones\" size=\"1\" "
@@ -2719,7 +2781,7 @@ void readloop(char *oper)
                wprintf(_("newest to oldest"));
                wprintf("\n");
 
-               wprintf("</form>\n");
+               wprintf("</p></form>\n");
                /** end bbview scroller */
        }
        
@@ -2794,6 +2856,7 @@ void post_mime_to_server(void) {
        static int seq = 0;
        struct wc_attachment *att;
        char *encoded;
+       char *txtmail;
        size_t encoded_length;
        size_t encoded_strlen;
 
@@ -2806,7 +2869,7 @@ void post_mime_to_server(void) {
                is_multipart = 1;
        }
 
-       if (is_multipart) {
+//     if (is_multipart) {
                sprintf(boundary, "Citadel--Multipart--%s--%04x--%04x",
                        serv_info.serv_fqdn,
                        getpid(),
@@ -2814,11 +2877,15 @@ void post_mime_to_server(void) {
                );
 
                /** Remember, serv_printf() appends an extra newline */
-               serv_printf("Content-type: multipart/mixed; "
-                       "boundary=\"%s\"\n", boundary);
+               if (is_multipart)
+                       serv_printf("Content-type: multipart/mixed; "
+                                   "boundary=\"%s\"\n", boundary);
+               else
+                       serv_printf("Content-type: multipart/alternative; "
+                                   "boundary=\"%s\"\n", boundary);
                serv_printf("This is a multipart message in MIME format.\n");
                serv_printf("--%s", boundary);
-       }
+//     }
 
        serv_puts("Content-type: text/html; charset=utf-8");
        serv_puts("Content-Transfer-Encoding: quoted-printable");
@@ -2826,6 +2893,16 @@ void post_mime_to_server(void) {
        serv_puts("<html><body>\r\n");
        text_to_server_qp(bstr("msgtext"));     /** Transmit message in quoted-printable encoding */
        serv_puts("</body></html>\r\n");
+
+       serv_puts("Content-type: text/plain; charset=utf-8");
+       serv_puts("Content-Transfer-Encoding: quoted-printable");
+       serv_puts("");
+
+       txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
+       text_to_server_qp(txtmail);     /** Transmit message in quoted-printable encoding */
+       free(txtmail);
+       if (!is_multipart)
+           serv_printf("--%s", boundary);
        
        if (is_multipart) {
 
@@ -2835,7 +2912,7 @@ void post_mime_to_server(void) {
                        encoded_length = ((att->length * 150) / 100);
                        encoded = malloc(encoded_length);
                        if (encoded == NULL) break;
-                       encoded_strlen = CtdlEncodeBase64(&encoded, att->data, att->length, &encoded_length, 1);
+                       encoded_strlen = CtdlEncodeBase64(encoded, att->data, att->length, 1);
 
                        serv_printf("--%s", boundary);
                        serv_printf("Content-type: %s", att->content_type);
@@ -2875,6 +2952,10 @@ void post_message(void)
        int is_anonymous = 0;
        char *display_name;
 
+       if (!IsEmptyStr(bstr("force_room"))) {
+               gotoroom(bstr("force_room"));
+       }
+
        display_name = bstr("display_name");
        if (!strcmp(display_name, "__ANONYMOUS__")) {
                display_name = "";
@@ -2936,7 +3017,7 @@ void post_message(void)
                        _("Automatically cancelled because you have already "
                        "saved this message."));
        } else {
-               rfc2047encode(encoded_subject, sizeof encoded_subject, bstr("subject"));
+               webcit_rfc2047encode(encoded_subject, sizeof encoded_subject, bstr("subject"));
                sprintf(buf, "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s",
                        bstr("recp"),
                        is_anonymous,
@@ -3122,6 +3203,9 @@ void display_enter(void)
        }
        wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
        wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%ld\">\n", WC->nonce);
+       wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
+       escputs(WC->wc_roomname);
+       wprintf("\">\n");
 
        /** submit or cancel buttons */
         wprintf("<p class=\"send_edit_msg\">");
@@ -3139,7 +3223,7 @@ void display_enter(void)
 
        wprintf("<img src=\"static/newmess3_24x.gif\" class=\"imgedit\">");
        wprintf("  ");  /** header bar */
-       fmt_date(buf, now, 0);
+       webcit_fmt_date(buf, now, 0);
        wprintf("%s", buf);
        wprintf("\n");  /** header bar */
 
@@ -3203,12 +3287,22 @@ void display_enter(void)
        wprintf("</td></tr>");
 
        if (recipient_required) {
-
+               char *ccraw;
+               char *copy;
+               size_t len;
                wprintf("<tr><th><label for=\"recp_id\"> ");
                wprintf(_("To:"));
                wprintf("</label></th>"
                        "<td><input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
-               escputs(bstr("recp"));
+               ccraw = bstr("recp");
+               len = strlen(ccraw);
+               copy = (char*) malloc(len * 2 + 1);
+               memcpy(copy, ccraw, len + 1); 
+#ifdef HAVE_ICONV
+               utf8ify_rfc822_string(copy);
+#endif
+               escputs(copy);
+               free(copy);
                wprintf("\" size=45 maxlength=1000 />");
                wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
                wprintf("</td><td rowspan=\"3\" align=\"left\" valign=\"top\">");
@@ -3230,7 +3324,15 @@ void display_enter(void)
                wprintf(_("CC:"));
                wprintf("</label></th>"
                        "<td><input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
-               escputs(bstr("cc"));
+               ccraw = bstr("cc");
+               len = strlen(ccraw);
+               copy = (char*) malloc(len * 2 + 1);
+               memcpy(copy, ccraw, len + 1); 
+#ifdef HAVE_ICONV
+               utf8ify_rfc822_string(copy);
+#endif
+               escputs(copy);
+               free(copy);
                wprintf("\" size=45 maxlength=1000 />");
                wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
                wprintf("</td></tr>");
@@ -3239,7 +3341,15 @@ void display_enter(void)
                wprintf(_("BCC:"));
                wprintf("</label></th>"
                        "<td><input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
-               escputs(bstr("bcc"));
+               ccraw = bstr("bcc");
+               len = strlen(ccraw);
+               copy = (char*) malloc(len * 2 + 1);
+               memcpy(copy, ccraw, len + 1); 
+#ifdef HAVE_ICONV
+               utf8ify_rfc822_string(copy);
+#endif
+               escputs(copy);
+               free(copy);
                wprintf("\" size=45 maxlength=1000 />");
                wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
                wprintf("</td></tr>");
@@ -3261,7 +3371,7 @@ void display_enter(void)
        }
        wprintf("</label></th>"
                "<td colspan=\"2\">"
-               "<input type=\"text\" name=\"subject\" id=\"subject_id\" value=\" ");
+               "<input type=\"text\" name=\"subject\" id=\"subject_id\" value=\"");
        escputs(bstr("subject"));
        wprintf("\" size=45 maxlength=70>\n");
        wprintf("</td></tr>");
@@ -3334,8 +3444,12 @@ void display_enter(void)
                }
        }
 
-       wprintf("</textarea>");
+       wprintf("</textarea>\n");
 
+       /** Make sure we only insert our signature once */
+       /** We don't care if it was there or not before, it needs to be there now. */
+       wprintf("<input type=\"hidden\" name=\"sig_inserted\" value=\"yes\">\n");
+       
        /**
         * The following template embeds the TinyMCE richedit control, and automatically
         * transforms the textarea into a richedit textarea.
@@ -3366,11 +3480,6 @@ void display_enter(void)
        wprintf("</div>");      /* End of "attachment buttons" div */
 
 
-       /** Make sure we only insert our signature once */
-       if (strcmp(bstr("sig_inserted"), "yes")) {
-               wprintf("<input type=\"hidden\" name=\"sig_inserted\" value=\"yes\">\n");
-       }
-       
        wprintf("</td></tr></table>");
        
        wprintf("</form>\n");