From: Art Cancro Date: Mon, 12 Sep 2005 04:08:05 +0000 (+0000) Subject: * Built an initial version of the "forward message" function. It works X-Git-Tag: v7.86~4669 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=09d2f87d1e3d99f163620e95ba2c70ad409b118a;p=citadel.git * Built an initial version of the "forward message" function. It works perfectly on the message text now, but we cannot consider it finished until it also forwards attachments. --- diff --git a/webcit/ChangeLog b/webcit/ChangeLog index 7e417e863..31b23c822 100644 --- a/webcit/ChangeLog +++ b/webcit/ChangeLog @@ -1,4 +1,9 @@ $Log$ +Revision 621.38 2005/09/12 04:08:05 ajc +* Built an initial version of the "forward message" function. It works + perfectly on the message text now, but we cannot consider it finished + until it also forwards attachments. + Revision 621.37 2005/09/10 03:23:05 ajc * Determined where to insert a "Forward" button and the functionality it implements. In order to complete this function we will need a @@ -2934,3 +2939,4 @@ Sun Dec 6 19:50:55 EST 1998 Art Cancro 1998-12-03 Nathan Bryant * webserver.c: warning fix + diff --git a/webcit/auth.c b/webcit/auth.c index c86e276b0..075e1da9c 100644 --- a/webcit/auth.c +++ b/webcit/auth.c @@ -229,7 +229,7 @@ void do_logout(void) if (WC->serv_sock >= 0) { if (buf[0] == '1') { - fmout(NULL, "CENTER"); + fmout("CENTER"); } else { wprintf("Goodbye\n"); } @@ -406,7 +406,7 @@ void display_changepw(void) serv_puts("MESG changepw"); serv_getln(buf, sizeof buf); if (buf[0] == '1') { - fmout(NULL, "CENTER"); + fmout("CENTER"); } wprintf("
\n"); diff --git a/webcit/messages.c b/webcit/messages.c index 7edd03239..b60e72b0c 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -566,7 +566,7 @@ void read_message(long msgnum, int suppress_buttons) { && (strcasecmp(&buf[5], WC->wc_roomname)) && (strlen(&buf[5])>0) ) { wprintf(_("in ")); - wprintf("%s> ", &buf[5]); + wprintf("%s> ", &buf[5]); } if (!strncasecmp(buf, "rfca=", 5)) { strcpy(rfca, &buf[5]); @@ -685,14 +685,13 @@ void read_message(long msgnum, int suppress_buttons) { urlescputs(m_subject); wprintf("\">[%s] ", _("Reply")); - /* Forward (FIXME uncomment when this is done) + /* Forward */ if (WC->wc_view == VIEW_MAILBOX) { wprintf("[%s] ", _("Forward")); } - */ if (WC->is_room_aide) { /* Move */ @@ -759,11 +758,12 @@ void read_message(long msgnum, int suppress_buttons) { /* Messages in legacy Citadel variformat get handled thusly... */ if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) { - fmout(NULL, "JUSTIFY"); + fmout("JUSTIFY"); } /* Boring old 80-column fixed format text gets handled this way... */ - else if (!strcasecmp(mime_content_type, "text/plain")) { + else if ( (!strcasecmp(mime_content_type, "text/plain")) + || (!strcasecmp(mime_content_type, "text")) ) { while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0; if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0; @@ -932,6 +932,263 @@ void embed_message(void) { +/* + * Read message in simple, JavaScript-embeddable form for 'forward' + * 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. + */ +void pullquote_message(long msgnum) { + char buf[SIZ]; + char mime_partnum[256]; + char mime_filename[256]; + char mime_content_type[256]; + char mime_charset[256]; + char mime_disposition[256]; + int mime_length; + char mime_http[SIZ]; + char m_subject[256]; + char from[256]; + char node[256]; + char rfca[256]; + char reply_to[512]; + char now[256]; + int format_type = 0; + int nhdr = 0; + int bq = 0; + int i = 0; + char vcard_partnum[256]; + char cal_partnum[256]; + char *part_source = NULL; +#ifdef HAVE_ICONV + iconv_t ic = (iconv_t)(-1) ; + char *ibuf; /* Buffer of characters to be converted */ + char *obuf; /* Buffer for converted characters */ + size_t ibuflen; /* Length of input buffer */ + size_t obuflen; /* Length of output buffer */ + char *osav; /* Saved pointer to output buffer */ +#endif + + strcpy(from, ""); + strcpy(node, ""); + strcpy(rfca, ""); + strcpy(reply_to, ""); + strcpy(vcard_partnum, ""); + strcpy(cal_partnum, ""); + strcpy(mime_http, ""); + strcpy(mime_content_type, "text/plain"); + strcpy(mime_charset, "us-ascii"); + + serv_printf("MSG4 %ld", msgnum); + serv_getln(buf, sizeof buf); + if (buf[0] != '1') { + wprintf(_("ERROR:")); + wprintf("%s
", &buf[4]); + return; + } + + strcpy(m_subject, ""); + + while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) { + if (!strcmp(buf, "000")) { + 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 ")); +#ifdef HAVE_ICONV + utf8ify_rfc822_string(from); +#endif + escputs(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> ", &buf[5]); + } + if (!strncasecmp(buf, "rfca=", 5)) { + strcpy(rfca, &buf[5]); + wprintf("<"); + escputs(rfca); + wprintf("> "); + } + + 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, "part=", 5)) { + /* + * FIXME + * + * We must forward the attachments. This is to be done + * by downloading each attachment of the original + * message and inserting it into the new message's + * attachment chain. + */ + } + + } + + wprintf("
"); + +#ifdef HAVE_ICONV + utf8ify_rfc822_string(m_subject); +#endif + if (strlen(m_subject) > 0) { + wprintf(_("Subject:")); + wprintf(" %s
", m_subject); + } + + /* + * Begin body + */ + wprintf("
"); + + /* + * Learn the content type + */ + strcpy(mime_content_type, "text/plain"); + while (serv_getln(buf, sizeof buf), (strlen(buf) > 0)) { + if (!strcmp(buf, "000")) { + wprintf(_("unexpected end of message")); + goto ENDBODY; + } + if (!strncasecmp(buf, "Content-type: ", 14)) { + safestrncpy(mime_content_type, &buf[14], + sizeof(mime_content_type)); + for (i=0; i 0) && (isspace(buf[strlen(buf) - 1]))) + buf[strlen(buf) - 1] = 0; + if ((bq == 0) && + ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) { + wprintf("
"); + bq = 1; + } else if ((bq == 1) && + (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) { + wprintf("
"); + bq = 0; + } + wprintf(""); + url(buf); + escputs(buf); + wprintf("
"); + } + wprintf("
"); + } + + /* 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")) { + msgescputs(buf); + } + } + + /* Unknown weirdness ... don't know how to handle this content type */ + else { + while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { } + } + + if (part_source) { + free(part_source); + part_source = NULL; + } + +ENDBODY: + /* end of body handler */ +#ifdef HAVE_ICONV + if (ic != (iconv_t)(-1) ) { + iconv_close(ic); + } +#endif +} + + + + + + void display_summarized(int num) { char datebuf[64]; @@ -2135,7 +2392,8 @@ void display_enter(void) "writeRichText('msgtext', '"); msgescputs(bstr("msgtext")); if (atol(bstr("pullquote")) > 0L) { - wprintf("FIXME pullquote=%s", bstr("pullquote")); + wprintf("
--- original message ---

"); + pullquote_message(atol(bstr("pullquote"))); } wprintf("', '96%%', '200', true, false); \n" "
\n"); diff --git a/webcit/paging.c b/webcit/paging.c index 8b66a6eab..c244070b2 100644 --- a/webcit/paging.c +++ b/webcit/paging.c @@ -162,7 +162,7 @@ void page_popup(void) wprintf(_("Instant message from ")); escputs(pagefrom); wprintf(""); - fmout(NULL, "LEFT"); + fmout("LEFT"); wprintf("" "\n"); wDumpContent(1); diff --git a/webcit/serv_func.c b/webcit/serv_func.c index 3eb0375eb..2fc570fe4 100644 --- a/webcit/serv_func.c +++ b/webcit/serv_func.c @@ -89,32 +89,17 @@ void get_serv_info(char *browser_host, char *user_agent) /* - * Function to spit out Citadel variformat text in HTML - * If fp is non-null, it is considered to be the file handle to read the - * text from. Otherwise, text is read from the server. + * Read Citadel variformat text and spit it out as HTML. */ -void fmout(FILE *fp, char *align) +void fmout(char *align) { - int intext = 0; int bq = 0; char buf[SIZ]; wprintf("
\n", align); - while (1) { - if (fp == NULL) - serv_getln(buf, sizeof buf); - if (fp != NULL) { - if (fgets(buf, SIZ, fp) == NULL) - safestrncpy(buf, "000", sizeof buf); - buf[strlen(buf) - 1] = 0; - } - if (!strcmp(buf, "000")) { - if (bq == 1) - wprintf(""); - wprintf("

\n"); - return; - } + while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { + if ((intext == 1) && (isspace(buf[0]))) { wprintf("
"); } @@ -140,6 +125,52 @@ void fmout(FILE *fp, char *align) escputs(buf); wprintf("\n"); } + if (bq == 1) { + wprintf(""); + } + wprintf("
\n"); +} + + + + +/* + * Read Citadel variformat text and spit it out as HTML in a form + * suitable for embedding in another message (forward/quote). + * (NO LINEBREAKS ALLOWED HERE!) + */ +void pullquote_fmout(void) { + int intext = 0; + int bq = 0; + char buf[SIZ]; + + while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { + + if ((intext == 1) && (isspace(buf[0]))) { + wprintf("
"); + } + intext = 1; + + /* Quoted text should be displayed in italics and in a + * different colour. This code understands Citadel-style + * " >" quotes and will convert to
tags. + */ + if ((bq == 0) && (!strncmp(buf, " >", 2))) { + wprintf("
"); + bq = 1; + } else if ((bq == 1) && (strncmp(buf, " >", 2))) { + wprintf("
"); + bq = 0; + } + if ((bq == 1) && (!strncmp(buf, " >", 2))) { + strcpy(buf, &buf[2]); + } + + msgescputs(buf); + } + if (bq == 1) { + wprintf(""); + } } diff --git a/webcit/subst.c b/webcit/subst.c index ac73e327f..60e96c633 100644 --- a/webcit/subst.c +++ b/webcit/subst.c @@ -103,7 +103,7 @@ void pvo_do_cmd(char *servcmd) { wprintf("%s\n", &buf[4]); break; case '1': - fmout(NULL, "CENTER"); + fmout("CENTER"); break; case '4': wprintf("%s\n", &buf[4]); diff --git a/webcit/userlist.c b/webcit/userlist.c index 1836e03c5..788c6c93b 100644 --- a/webcit/userlist.c +++ b/webcit/userlist.c @@ -144,7 +144,7 @@ void showuser(void) serv_printf("RBIO %s", who); serv_getln(buf, sizeof buf); if (buf[0] == '1') { - fmout(NULL, "JUSTIFY"); + fmout("JUSTIFY"); } wprintf("