]> code.citadel.org Git - citadel.git/blobdiff - webcit/msg_renderers.c
* make readloop long-controlled
[citadel.git] / webcit / msg_renderers.c
index 1fb5739db6e8d5a5a2d2d1125cd343297a527ed3..005288380fe1db905e0835e707f704e524210115 100644 (file)
@@ -68,6 +68,116 @@ void RegisterMimeRenderer(const char *HeaderName, long HdrNLen, RenderMimeFunc M
 
 /*----------------------------------------------------------------------------*/
 
+/*
+ * qsort() compatible function to compare two longs in descending order.
+ */
+int longcmp_r(const void *s1, const void *s2) {
+       long l1;
+       long l2;
+
+       l1 = *(long *)GetSearchPayload(s1);
+       l2 = *(long *)GetSearchPayload(s2);
+
+       if (l1 > l2) return(-1);
+       if (l1 < l2) return(+1);
+       return(0);
+}
+
+/*
+ * qsort() compatible function to compare two longs in descending order.
+ */
+int qlongcmp_r(const void *s1, const void *s2) {
+       long l1 = (long) s1;
+       long l2 = (long) s2;
+
+       if (l1 > l2) return(-1);
+       if (l1 < l2) return(+1);
+       return(0);
+}
+
+/*
+ * qsort() compatible function to compare two message summary structs by ascending subject.
+ */
+int summcmp_subj(const void *s1, const void *s2) {
+       message_summary *summ1;
+       message_summary *summ2;
+       
+       summ1 = (message_summary *)GetSearchPayload(s1);
+       summ2 = (message_summary *)GetSearchPayload(s2);
+       return strcasecmp(ChrPtr(summ1->subj), ChrPtr(summ2->subj));
+}
+
+/*
+ * qsort() compatible function to compare two message summary structs by descending subject.
+ */
+int summcmp_rsubj(const void *s1, const void *s2) {
+       message_summary *summ1;
+       message_summary *summ2;
+       
+       summ1 = (message_summary *)GetSearchPayload(s1);
+       summ2 = (message_summary *)GetSearchPayload(s2);
+       return strcasecmp(ChrPtr(summ2->subj), ChrPtr(summ1->subj));
+}
+
+/*
+ * qsort() compatible function to compare two message summary structs by ascending sender.
+ */
+int summcmp_sender(const void *s1, const void *s2) {
+       message_summary *summ1;
+       message_summary *summ2;
+       
+       summ1 = (message_summary *)GetSearchPayload(s1);
+       summ2 = (message_summary *)GetSearchPayload(s2);
+       return strcasecmp(ChrPtr(summ1->from), ChrPtr(summ2->from));
+}
+
+/*
+ * qsort() compatible function to compare two message summary structs by descending sender.
+ */
+int summcmp_rsender(const void *s1, const void *s2) {
+       message_summary *summ1;
+       message_summary *summ2;
+       
+       summ1 = (message_summary *)GetSearchPayload(s1);
+       summ2 = (message_summary *)GetSearchPayload(s2);
+       return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from));
+}
+
+/*
+ * qsort() compatible function to compare two message summary structs by ascending date.
+ */
+int summcmp_date(const void *s1, const void *s2) {
+       message_summary *summ1;
+       message_summary *summ2;
+       
+       summ1 = (message_summary *)GetSearchPayload(s1);
+       summ2 = (message_summary *)GetSearchPayload(s2);
+
+       if (summ1->date < summ2->date) return -1;
+       else if (summ1->date > summ2->date) return +1;
+       else return 0;
+}
+
+/*
+ * qsort() compatible function to compare two message summary structs by descending date.
+ */
+int summcmp_rdate(const void *s1, const void *s2) {
+       message_summary *summ1;
+       message_summary *summ2;
+       
+       summ1 = (message_summary *)GetSearchPayload(s1);
+       summ2 = (message_summary *)GetSearchPayload(s2);
+
+       if (summ1->date < summ2->date) return +1;
+       else if (summ1->date > summ2->date) return -1;
+       else return 0;
+}
+
+/*----------------------------------------------------------------------------*/
+
+
+
 
 void examine_nhdr(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
 {
@@ -401,7 +511,8 @@ void evaluate_mime_part(message_summary *Msg, wc_mime_attachment *Mime)
                if (Msg->AttachLinks == NULL)
                        Msg->AttachLinks = NewHash(1,NULL);
                Put(Msg->AttachLinks, SKEY(Mime->PartNum), Mime, reference_free_handler);
-               if (strcasecmp(ChrPtr(Mime->ContentType), "application/octet-stream") == 0) {
+               if ((strcasecmp(ChrPtr(Mime->ContentType), "application/octet-stream") == 0) && 
+                   (StrLength(Mime->FileName) > 0)) {
                        FlushStrBuf(Mime->ContentType);
                        StrBufAppendBufPlain(Mime->ContentType,
                                             GuessMimeByFilename(SKEY(Mime->FileName)),
@@ -582,10 +693,11 @@ void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *F
        StrBuf *cs = NULL;
        const char *ptr, *pte;
        const char *BufPtr = NULL;
-       StrBuf *Line = NewStrBuf();
-       StrBuf *Line1 = NewStrBuf();
-       StrBuf *Line2 = NewStrBuf();
-       StrBuf *Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
+       StrBuf *Line;
+       StrBuf *Line1;
+       StrBuf *Line2;
+       StrBuf *Target;
+
        int ConvertIt = 1;
        int bn = 0;
        int bq = 0;
@@ -615,7 +727,7 @@ void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *F
                        cs = FoundCharset;
                else if (StrLength(WC->DefaultCharset) > 0)
                        cs = WC->DefaultCharset;
-               if (cs == 0) {
+               if (cs == NULL) {
                        ConvertIt = 0;
                }
                else {
@@ -627,6 +739,10 @@ void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *F
                }
        }
 #endif
+       Line = NewStrBuf();
+       Line1 = NewStrBuf();
+       Line2 = NewStrBuf();
+       Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
 
        while ((n = StrBufSipLine(Line, Mime->Data, &BufPtr), n >= 0) && !done)
        {
@@ -822,6 +938,44 @@ void tmplput_ATT_FileName(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, vo
 }
 
 
+void servcmd_do_search(char *buf, long bufsize)
+{
+       snprintf(buf, bufsize, "MSGS SEARCH|%s", bstr("query"));
+}
+
+void servcmd_headers(char *buf, long bufsize)
+{
+       snprintf(buf, bufsize, "MSGS ALL");
+}
+
+void servcmd_readfwd(char *buf, long bufsize)
+{
+       snprintf(buf, bufsize, "MSGS ALL");
+}
+
+void servcmd_readnew(char *buf, long bufsize)
+{
+       snprintf(buf, bufsize, "MSGS NEW");
+}
+
+void servcmd_readold(char *buf, long bufsize)
+{
+       snprintf(buf, bufsize, "MSGS OLD");
+}
+
+
+readloop_struct rlid[] = {
+       { {HKEY("do_search")}, servcmd_do_search},
+       { {HKEY("headers")},   servcmd_headers},
+       { {HKEY("readfwd")},   servcmd_readfwd},
+       { {HKEY("readnew")},   servcmd_readnew},
+       { {HKEY("readold")},   servcmd_readold}
+};
+
+
+
+
+               
 
 
 
@@ -830,6 +984,22 @@ void
 InitModule_MSGRENDERERS
 (void)
 {
+       RegisterSortFunc(HKEY("date"), 
+                        NULL, 0,
+                        summcmp_date,
+                        summcmp_rdate,
+                        CTX_MAILSUM);
+       RegisterSortFunc(HKEY("subject"), 
+                        NULL, 0,
+                        summcmp_subj,
+                        summcmp_rsubj,
+                        CTX_MAILSUM);
+       RegisterSortFunc(HKEY("sender"),
+                        NULL, 0,
+                        summcmp_sender,
+                        summcmp_rsender,
+                        CTX_MAILSUM);
+
        RegisterNamespace("MAIL:SUMM:DATESTR", 0, 0, tmplput_MAIL_SUMM_DATE_STR, CTX_MAILSUM);
        RegisterNamespace("MAIL:SUMM:DATENO",  0, 0, tmplput_MAIL_SUMM_DATE_NO,  CTX_MAILSUM);
        RegisterNamespace("MAIL:SUMM:N",       0, 0, tmplput_MAIL_SUMM_N,        CTX_MAILSUM);