From: Wilfried Göesgens Date: Sun, 2 Nov 2008 23:14:27 +0000 (+0000) Subject: * plain mail renderer X-Git-Tag: v7.86~1826 X-Git-Url: https://code.citadel.org/?p=citadel.git;a=commitdiff_plain;h=e1cfdc9ced08ba38ac79b4bb998c6e8c35cdc167 * plain mail renderer --- diff --git a/webcit/html2html.c b/webcit/html2html.c index 4c3f7b6b2..6a5932da2 100644 --- a/webcit/html2html.c +++ b/webcit/html2html.c @@ -241,7 +241,7 @@ void output_html(const char *supplied_charset, int treat_as_wiki, int msgnum, St && (strcasecmp(charset, "")) ) { lprintf(9, "Converting %s to UTF-8\n", charset); - ic = ctdl_iconv_open("UTF-8", charset); + ctdl_iconv_open("UTF-8", charset, &ic); if (ic == (iconv_t)(-1) ) { lprintf(5, "%s:%d iconv_open() failed: %s\n", __FILE__, __LINE__, strerror(errno)); diff --git a/webcit/messages.c b/webcit/messages.c index 5cf8d6b89..5d4ecc6bd 100644 --- a/webcit/messages.c +++ b/webcit/messages.c @@ -645,77 +645,78 @@ void render_MAIL_variformat(wc_mime_attachment *Mime, StrBuf *RawData) void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData) { - /* Boring old 80-column fixed format text gets handled this way... * / + const char *ptr, *pte; + const char *BufPtr = NULL; + StrBuf *Line = NewStrBuf(); + StrBuf *Line1 = NewStrBuf(); + StrBuf *Line2 = NewStrBuf(); + StrBuf *Target = NewStrBufPlain(NULL, StrLength(Mime->Data)); + int ConvertIt = 1; + int bn = 0; + int bq = 0; + int i; + long len; #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 - / * Set up a character set conversion if we need to (and if we can) * / + if ((strcasecmp(ChrPtr(Mime->Charset), "us-ascii") == 0) && + (strcasecmp(ChrPtr(Mime->Charset), "UTF-8") == 0)) + ConvertIt = 0; + #ifdef HAVE_ICONV - if (strchr(mime_charset, ';')) strcpy(strchr(mime_charset, ';'), ""); - if ( (strcasecmp(mime_charset, "us-ascii")) - && (strcasecmp(mime_charset, "UTF-8")) - && (strcasecmp(mime_charset, "")) - ) { - ic = ctdl_iconv_open("UTF-8", mime_charset); + if (ConvertIt) { + ctdl_iconv_open("UTF-8", ChrPtr(Mime->Charset), &ic); if (ic == (iconv_t)(-1) ) { lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n", - __FILE__, __LINE__, mime_charset, strerror(errno)); + __FILE__, __LINE__, ChrPtr(Mime->Charset), strerror(errno)); } } #endif - buf [0] = '\0'; - while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { - int len; - len = strlen(buf); - if ((len > 0) && buf[len-1] == '\n') buf[--len] = 0; - if ((len > 0) && buf[len-1] == '\r') buf[--len] = 0; + while (StrBufSipLine(Line, Mime->Data, &BufPtr) > 0) + { + bq = 0; + i = 0; + + ptr = ChrPtr(Line); + len = StrLength(Line); + pte = ptr + len; -#ifdef HAVE_ICONV - if (ic != (iconv_t)(-1) ) { - ibuf = buf; - ibuflen = strlen(ibuf); - obuflen = SIZ; - obuf = (char *) malloc(obuflen); - osav = obuf; - iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen); - osav[SIZ-obuflen] = 0; - safestrncpy(buf, osav, sizeof buf); - free(osav); - } -#endif + while ((ptr < pte) && + ((*ptr == '>') || + isspace(*ptr))) + { + if (*ptr == '>') + bq++; + ptr ++; + i++; + } + if (i > 0) StrBufCutLeft(Line, i); + for (i = bn; i < bq; i++) + StrBufAppendBufPlain(Target, HKEY("
"), 0); + for (i = bq; i < bn; i++) + StrBufAppendBufPlain(Target, HKEY("
"), 0); - len = strlen(buf); - while ((!IsEmptyStr(buf)) && (isspace(buf[len-1]))) - buf[--len] = 0; - if ((bq == 0) && - ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) { - wprintf("
"); - bq = 1; - } else if ((bq == 1) && - (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) { - wprintf("
"); - bq = 0; - } - wprintf(""); - url(buf, sizeof(buf)); - escputs(buf); - wprintf("
\n"); - } - wprintf("
") + StrBufAppendBufPlain(Target, HKEY(""), 0); + UrlizeText(Line1, Line, Line2); + + StrEscAppend(Target, Line1, NULL, 0, 0); + StrBufAppendBufPlain(Target, HKEY("
\n"), 0); + bn = bq; + + } + + /* Boring old 80-column fixed format text gets handled this way... */ + StrBufAppendBufPlain(Target, HKEY("
"), 0); #ifdef HAVE_ICONV if (ic != (iconv_t)(-1) ) { iconv_close(ic); } #endif -; - */ + FreeStrBuf(&Mime->Data); + Mime->Data = Target; + } void render_MAIL_html(wc_mime_attachment *Mime, StrBuf *RawData) @@ -723,7 +724,10 @@ void render_MAIL_html(wc_mime_attachment *Mime, StrBuf *RawData) StrBuf *Buf; /* HTML is fun, but we've got to strip it first */ Buf = NewStrBufPlain(NULL, StrLength(Mime->Data)); - output_html(ChrPtr(Mime->Charset), (WC->wc_view == VIEW_WIKI ? 1 : 0), Mime->PartNum, Mime->Data, Buf); + output_html(ChrPtr(Mime->Charset), + (WC->wc_view == VIEW_WIKI ? 1 : 0), + StrToi(Mime->PartNum), + Mime->Data, Buf); FreeStrBuf(&Mime->Data); Mime->Data = Buf; } @@ -745,6 +749,63 @@ void render_MAIL_UNKNOWN(wc_mime_attachment *Mime, StrBuf *RawData) * Look for URL's embedded in a buffer and make them linkable. We use a * target window in order to keep the Citadel session in its own window. */ +void UrlizeText(StrBuf* Target, StrBuf *Source, StrBuf *WrkBuf) +{ + int len, UrlLen, Offset, TrailerLen; + const char *start, *end, *pos; + + FlushStrBuf(Target); + + start = NULL; + len = StrLength(Source); + end = ChrPtr(Source) + len; + for (pos = ChrPtr(Source); (pos < end) && (start == NULL); ++pos) { + if (!strncasecmp(pos, "http://", 7)) + start = pos; + if (!strncasecmp(pos, "ftp://", 6)) + start = pos; + } + + if (start == NULL) { + StrBufAppendBuf(Target, Source, 0); + return; + } + FlushStrBuf(WrkBuf); + + for (pos = ChrPtr(Source) + len; pos > start; --pos) { + if ( (!isprint(*pos)) + || (isspace(*pos)) + || (*pos == '{') + || (*pos == '}') + || (*pos == '|') + || (*pos == '\\') + || (*pos == '^') + || (*pos == '[') + || (*pos == ']') + || (*pos == '`') + || (*pos == '<') + || (*pos == '>') + || (*pos == '(') + || (*pos == ')') + ) { + end = pos; + } + } + + UrlLen = end - start; + StrBufAppendBufPlain(WrkBuf, start, UrlLen, 0); + + Offset = start - ChrPtr(Source); + if (Offset != 0) + StrBufAppendBufPlain(Target, ChrPtr(Source), Offset, 0); + StrBufAppendPrintf(Target, "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c", + LB, QU, ChrPtr(WrkBuf), QU, QU, TARGET, + QU, RB, ChrPtr(WrkBuf), LB, RB); + + TrailerLen = len - (end - start); + if (TrailerLen > 0) + StrBufAppendBufPlain(Target, end, TrailerLen, 0); +} void url(char *buf, size_t bufsize) { int len, UrlLen, Offset, TrailerLen, outpos; @@ -1322,6 +1383,15 @@ void read_message(long msgnum, int printable_view, char *section) { } } + + if (GetHash(MimeRenderHandler, SKEY(Msg->MsgBody.ContentType), &vHdr) && + (vHdr != NULL)) { + RenderMimeFunc Render; + Render = (RenderMimeFunc)vHdr; + Render(&Msg->MsgBody, NULL); + } + + if (StrLength(Msg->reply_references)> 0) { /* Trim down excessively long lists of thread references. We eliminate the * second one in the list so that the thread root remains intact. @@ -1747,7 +1817,7 @@ void pullquote_message(long msgnum, int forward_attachments, int include_headers && (strcasecmp(mime_charset, "UTF-8")) && (strcasecmp(mime_charset, "")) ) { - ic = ctdl_iconv_open("UTF-8", mime_charset); + ctdl_iconv_open("UTF-8", mime_charset, &ic); if (ic == (iconv_t)(-1) ) { lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n", __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno)); diff --git a/webcit/rss.c b/webcit/rss.c index 0a88ca2a8..d17fe3896 100644 --- a/webcit/rss.c +++ b/webcit/rss.c @@ -254,7 +254,7 @@ void display_rss(char *roomname, StrBuf *request_method) /** Set up a character set conversion if we need to */ #ifdef HAVE_ICONV if (strcasecmp(charset, "us-ascii") && strcasecmp(charset, "utf-8") && strcasecmp(charset, "") ) { - ic = ctdl_iconv_open("UTF-8", charset); + ctdl_iconv_open("UTF-8", charset, &ic); if (ic == (iconv_t)(-1)) { lprintf(5, "%s:%d iconv_open() failed: %s\n", __FILE__, __LINE__, strerror(errno)); diff --git a/webcit/webcit.h b/webcit/webcit.h index abcfb13cb..e5cc2e905 100644 --- a/webcit/webcit.h +++ b/webcit/webcit.h @@ -731,6 +731,7 @@ void print_menu_box(char* Title, char *Class, int nLines, ...); long stresc(char *target, long tSize, char *strbuf, int nbsp, int nolinebreaks); void escputs(char *strbuf); void url(char *buf, size_t bufsize); +void UrlizeText(StrBuf* Target, StrBuf *Source, StrBuf *WrkBuf); void escputs1(char *strbuf, int nbsp, int nolinebreaks); void msgesc(char *target, size_t tlen, char *strbuf); void msgescputs(char *strbuf); @@ -915,10 +916,6 @@ int fetch_http(char *url, char *target_buf, int maxbytes); int is_mobile_ua(char *user_agent); -#ifdef HAVE_ICONV -iconv_t ctdl_iconv_open(const char *tocode, const char *fromcode); -#endif - void embed_room_banner(char *, int); /* navbar types that can be passed to embed_room_banner */