* remove duplicate function
authorWilfried Göesgens <willi@citadel.org>
Mon, 3 Nov 2008 22:14:24 +0000 (22:14 +0000)
committerWilfried Göesgens <willi@citadel.org>
Mon, 3 Nov 2008 22:14:24 +0000 (22:14 +0000)
* variformat renderer
* fix loop handling

webcit/decode.c
webcit/messages.c
webcit/serv_func.c
webcit/webcit.h

index 4e72f191d924c88c1c5be846e2fc0f0a8916b877..cf64886eeff85ff8ce0c11b7b55157e5493efdf8 100644 (file)
@@ -8,7 +8,7 @@
  *
  * tocode      Target encoding
  * fromcode    Source encoding
- */
+ * /
 iconv_t ctdl_iconv_open(const char *tocode, const char *fromcode)
 {
        iconv_t ic = (iconv_t)(-1) ;
@@ -24,7 +24,7 @@ iconv_t ctdl_iconv_open(const char *tocode, const char *fromcode)
        }
        return(ic);
 }
-
+*/
 
 
 inline char *FindNextEnd (char *bptr)
@@ -83,7 +83,7 @@ void utf8ify_rfc822_string(char *buf) {
                get_preference("default_header_charset", &default_header_charset);
                if ( (strcasecmp(ChrPtr(default_header_charset), "UTF-8")) && 
                     (strcasecmp(ChrPtr(default_header_charset), "us-ascii")) ) {
-                       ic = ctdl_iconv_open("UTF-8", ChrPtr(default_header_charset));
+                       ctdl_iconv_open("UTF-8", ChrPtr(default_header_charset), &ic);
                        if (ic != (iconv_t)(-1) ) {
                                ibuf = malloc(1024);
                                isav = ibuf;
@@ -184,7 +184,7 @@ void utf8ify_rfc822_string(char *buf) {
                        ibuflen = strlen(istr);
                }
 
-               ic = ctdl_iconv_open("UTF-8", charset);
+               ctdl_iconv_open("UTF-8", charset, &ic);
                if (ic != (iconv_t)(-1) ) {
                        obuflen = 1024;
                        obuf = (char *) malloc(obuflen);
index e41b83b6f2fb17dce4ac4ce4840aa3c26425854d..c7cd05a81820542e57eaea845cdd894b779e20ea 100644 (file)
@@ -581,6 +581,7 @@ void examine_content_encoding(message_summary *Msg, StrBuf *HdrLine)
 void examine_content_lengh(message_summary *Msg, StrBuf *HdrLine)
 {
        Msg->MsgBody.length = StrTol(HdrLine);
+       Msg->MsgBody.size_known = 1;
 }
 
 void examine_content_type(message_summary *Msg, StrBuf *HdrLine)
@@ -639,8 +640,10 @@ void tmplput_MAIL_BODY(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *
 void render_MAIL_variformat(wc_mime_attachment *Mime, StrBuf *RawData)
 {
        /* Messages in legacy Citadel variformat get handled thusly... */
-       fmout("JUSTIFY");///todo: this won't work that way.
-       
+       StrBuf *Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
+       FmOut(Target, "JUSTIFY", Mime->Data);
+       FreeStrBuf(&Mime->Data);
+       Mime->Data = Target;
 }
 
 void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData)
@@ -654,7 +657,7 @@ void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData)
        int ConvertIt = 1;
        int bn = 0;
        int bq = 0;
-       int i;
+       int i, n, done = 0;
        long len;
 #ifdef HAVE_ICONV
        iconv_t ic = (iconv_t)(-1) ;
@@ -675,11 +678,11 @@ void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData)
        }
 #endif
 
-       while (StrBufSipLine(Line, Mime->Data, &BufPtr) > 0)
+       while ((n = StrBufSipLine(Line, Mime->Data, &BufPtr), n >= 0) && !done)
        {
+               done = n == 0;
                bq = 0;
                i = 0;
-
                ptr = ChrPtr(Line);
                len = StrLength(Line);
                pte = ptr + len;
@@ -711,7 +714,7 @@ void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData)
                bn = bq;
        }
 
-       for (i = bq; i < bn; i++)                               
+       for (i = 0; i < bn; i++)                                
                StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
 
        StrBufAppendBufPlain(Target, HKEY("</i><br />"), 0);
@@ -722,7 +725,9 @@ void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData)
 #endif
        FreeStrBuf(&Mime->Data);
        Mime->Data = Target;
-
+       FreeStrBuf(&Line);
+       FreeStrBuf(&Line1);
+       FreeStrBuf(&Line2);
 }
 
 void render_MAIL_html(wc_mime_attachment *Mime, StrBuf *RawData)
@@ -741,8 +746,10 @@ void render_MAIL_html(wc_mime_attachment *Mime, StrBuf *RawData)
 void render_MAIL_UNKNOWN(wc_mime_attachment *Mime, StrBuf *RawData)
 {
        /* Unknown weirdness */
-////   wprintf(_("I don't know how to display %s"), Msg->MsgBody->ContentType);
-       wprintf("<br />\n");
+       FlushStrBuf(Mime->Data);
+       StrBufAppendBufPlain(Mime->Data, _("I don't know how to display "), -1, 0);
+       StrBufAppendBuf(Mime->Data, Mime->ContentType, 0);
+       StrBufAppendBufPlain(Mime->Data, HKEY("<br />\n"), 0);
 }
 
 
@@ -1308,7 +1315,7 @@ void read_message(long msgnum, int printable_view, char *section) {
        Token = NewStrBuf();
        Msg = (message_summary *)malloc(sizeof(message_summary));
        memset(Msg, 0, sizeof(message_summary));
-       Msg->MsgBody.length=-1;
+
        while ((StrBuf_ServGetln(Buf)>=0) && !Done) {
                if ( (StrLength(Buf)==3) && 
                    !strcmp(ChrPtr(Buf), "000")) 
@@ -1372,7 +1379,7 @@ void read_message(long msgnum, int printable_view, char *section) {
                        }
                case 2: /* Message Body */
                        
-                       if (Msg->MsgBody.length > 0) {
+                       if (Msg->MsgBody.size_known > 0) {
                                StrBuf_ServGetBLOB(Msg->MsgBody.Data, Msg->MsgBody.length);
                                state ++;
                                        /// todo: check next line, if not 000, append following lines
index aa43d350b84cab3a39fa8947b7e150d53e047e9d..fbaa088d8b583a98fbaeef989f85380eb9eee4da 100644 (file)
@@ -155,6 +155,74 @@ void _fmout(StrBuf *Target, char *align)
        wprintf("</div><br />\n");
 }
 
+void FmOut(StrBuf *Target, char *align, StrBuf *Source)
+{
+       const char *ptr, *pte;
+       const char *BufPtr = NULL;
+       StrBuf *Line = NewStrBuf();
+       StrBuf *Line1 = NewStrBuf();
+       StrBuf *Line2 = NewStrBuf();
+       int bn = 0;
+       int bq = 0;
+       int i, n, done = 0;
+       long len;
+       int intext = 0;
+
+       StrBufAppendPrintf(Target, "<div align=%s>\n", align);
+       while ((n = StrBufSipLine(Line, Source, &BufPtr), n >= 0) && !done)
+       {
+               done = n == 0;
+               bq = 0;
+               i = 0;
+               ptr = ChrPtr(Line);
+               len = StrLength(Line);
+               pte = ptr + len;
+
+               if ((intext == 1) && (isspace(*ptr))) {
+                       StrBufAppendBufPlain(Target, HKEY("<br />"), 0);
+               }
+               intext = 1;
+               if (isspace(*ptr)) while ((ptr < pte) &&
+                      ((*ptr == '>') ||
+                       isspace(*ptr)))
+               {
+                       if (*ptr == '>')
+                               bq++;
+                       ptr ++;
+                       i++;
+               }
+
+               /**
+                * Quoted text should be displayed in italics and in a
+                * different colour.  This code understands Citadel-style
+                * " >" quotes and will convert to <BLOCKQUOTE> tags.
+                */
+               if (i > 0) StrBufCutLeft(Line, i);
+               
+
+               for (i = bn; i < bq; i++)                               
+                       StrBufAppendBufPlain(Target, HKEY("<blockquote>"), 0);
+               for (i = bq; i < bn; i++)                               
+                       StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
+               bn = bq;
+
+               if (StrLength(Line) == 0)
+                       continue;
+               /** Activate embedded URL's */
+               UrlizeText(Line1, Line, Line2);
+
+               StrEscAppend(Target, Line1, NULL, 0, 0);
+
+               StrBufAppendBufPlain(Target, HKEY("\n"), 0);
+       }
+       for (i = 0; i < bn; i++)                                
+               StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
+       StrBufAppendBufPlain(Target, HKEY("</div><br />\n"), 0);
+       FreeStrBuf(&Line);
+       FreeStrBuf(&Line1);
+       FreeStrBuf(&Line2);
+}
+
 
 
 
index e5cc2e905c27a3f894a88c96e7218ed8e7c0850c..5140def263cdaa8d6b469b0e38bf9dd09ea3de18 100644 (file)
@@ -401,6 +401,7 @@ typedef struct _wc_mime_attachment {
        StrBuf *Charset;
        StrBuf *Data;
        size_t length;                     /* length of the mimeatachment */
+       long size_known;
        char content_type[SIZ];    /* the content itself ???*/
        char filename[SIZ];                /* the filename hooked to this content ??? */
        char *data;                /* the data pool; aka this content */
@@ -671,6 +672,7 @@ void who_inner_div(void);
 void ajax_mini_calendar(void);
 void fmout(char *align);
 void _fmout(StrBuf *Targt, char *align);
+void FmOut(StrBuf *Target, char *align, StrBuf *Source);
 void pullquote_fmout(void);
 void wDumpContent(int);