Back to index

webcit  8.12-dfsg
msg_renderers.c
Go to the documentation of this file.
00001 #include "webcit.h"
00002 #include "webserver.h"
00003 #include "dav.h"
00004 
00005 
00006 
00007 inline void CheckConvertBufs(struct wcsession *WCC)
00008 {
00009        if (WCC->ConvertBuf1 == NULL)
00010               WCC->ConvertBuf1 = NewStrBuf();
00011        if (WCC->ConvertBuf2 == NULL)
00012               WCC->ConvertBuf2 = NewStrBuf();
00013 }
00014 
00015 /*
00016  * message index functions
00017  */
00018 
00019 
00020 void DestroyMimeParts(wc_mime_attachment *Mime)
00021 {
00022        FreeStrBuf(&Mime->Name);
00023        FreeStrBuf(&Mime->FileName);
00024        FreeStrBuf(&Mime->PartNum);
00025        FreeStrBuf(&Mime->Disposition);
00026        FreeStrBuf(&Mime->ContentType);
00027        FreeStrBuf(&Mime->Charset);
00028        FreeStrBuf(&Mime->Data);
00029 }
00030 
00031 void DestroyMime(void *vMime)
00032 {
00033        wc_mime_attachment *Mime = (wc_mime_attachment*)vMime;
00034        DestroyMimeParts(Mime);
00035        free(Mime);
00036 }
00037 
00038 void DestroyMessageSummary(void *vMsg)
00039 {
00040        message_summary *Msg = (message_summary*) vMsg;
00041 
00042        FreeStrBuf(&Msg->from);
00043        FreeStrBuf(&Msg->to);
00044        FreeStrBuf(&Msg->subj);
00045        FreeStrBuf(&Msg->reply_inreplyto);
00046        FreeStrBuf(&Msg->reply_references);
00047        FreeStrBuf(&Msg->cccc);
00048        FreeStrBuf(&Msg->hnod);
00049        FreeStrBuf(&Msg->AllRcpt);
00050        FreeStrBuf(&Msg->Room);
00051        FreeStrBuf(&Msg->Rfca);
00052        FreeStrBuf(&Msg->OtherNode);
00053 
00054        DeleteHash(&Msg->Attachments);     /* list of Attachments */
00055        DeleteHash(&Msg->Submessages);
00056        DeleteHash(&Msg->AttachLinks);
00057        DeleteHash(&Msg->AllAttach);
00058        free(Msg);
00059 }
00060 
00061 
00062 
00063 void RegisterMsgHdr(const char *HeaderName, long HdrNLen, ExamineMsgHeaderFunc evaluator, int type)
00064 {
00065        headereval *ev;
00066        ev = (headereval*) malloc(sizeof(headereval));
00067        ev->evaluator = evaluator;
00068        ev->Type = type;
00069        Put(MsgHeaderHandler, HeaderName, HdrNLen, ev, NULL);
00070 }
00071 
00072 void RegisterMimeRenderer(const char *HeaderName, long HdrNLen, 
00073                        RenderMimeFunc MimeRenderer,
00074                        int InlineRenderable,
00075                        int Priority)
00076 {
00077        RenderMimeFuncStruct *f;
00078 
00079        f = (RenderMimeFuncStruct*) malloc(sizeof(RenderMimeFuncStruct));
00080        f->f = MimeRenderer;
00081        Put(MimeRenderHandler, HeaderName, HdrNLen, f, NULL);
00082        if (InlineRenderable)
00083               RegisterEmbeddableMimeType(HeaderName, HdrNLen, 10000 - Priority);
00084 }
00085 
00086 /*----------------------------------------------------------------------------*/
00087 
00088 /*
00089  *  comparator for two longs in descending order.
00090  */
00091 int longcmp_r(const void *s1, const void *s2) {
00092        long l1;
00093        long l2;
00094 
00095        l1 = *(long *)GetSearchPayload(s1);
00096        l2 = *(long *)GetSearchPayload(s2);
00097 
00098        if (l1 > l2) return(-1);
00099        if (l1 < l2) return(+1);
00100        return(0);
00101 }
00102 
00103 /*
00104  *  comparator for longs; descending order.
00105  */
00106 int qlongcmp_r(const void *s1, const void *s2) {
00107        long l1 = (long) s1;
00108        long l2 = (long) s2;
00109 
00110        if (l1 > l2) return(-1);
00111        if (l1 < l2) return(+1);
00112        return(0);
00113 }
00114 
00115  
00116 /*
00117  * comparator for message summary structs by ascending subject.
00118  */
00119 int summcmp_subj(const void *s1, const void *s2) {
00120        message_summary *summ1;
00121        message_summary *summ2;
00122        
00123        summ1 = (message_summary *)GetSearchPayload(s1);
00124        summ2 = (message_summary *)GetSearchPayload(s2);
00125        return strcasecmp(ChrPtr(summ1->subj), ChrPtr(summ2->subj));
00126 }
00127 
00128 /*
00129  * comparator for message summary structs by descending subject.
00130  */
00131 int summcmp_rsubj(const void *s1, const void *s2) {
00132        message_summary *summ1;
00133        message_summary *summ2;
00134        
00135        summ1 = (message_summary *)GetSearchPayload(s1);
00136        summ2 = (message_summary *)GetSearchPayload(s2);
00137        return strcasecmp(ChrPtr(summ2->subj), ChrPtr(summ1->subj));
00138 }
00139 /*
00140  * comparator for message summary structs by descending subject.
00141  */
00142 int groupchange_subj(const void *s1, const void *s2) {
00143        message_summary *summ1;
00144        message_summary *summ2;
00145        
00146        summ1 = (message_summary *)s1;
00147        summ2 = (message_summary *)s2;
00148        return ChrPtr(summ2->subj)[0] != ChrPtr(summ1->subj)[0];
00149 }
00150 
00151 /*
00152  * comparator for message summary structs by ascending sender.
00153  */
00154 int summcmp_sender(const void *s1, const void *s2) {
00155        message_summary *summ1;
00156        message_summary *summ2;
00157        
00158        summ1 = (message_summary *)GetSearchPayload(s1);
00159        summ2 = (message_summary *)GetSearchPayload(s2);
00160        return strcasecmp(ChrPtr(summ1->from), ChrPtr(summ2->from));
00161 }
00162 
00163 /*
00164  * comparator for message summary structs by descending sender.
00165  */
00166 int summcmp_rsender(const void *s1, const void *s2) {
00167        message_summary *summ1;
00168        message_summary *summ2;
00169        
00170        summ1 = (message_summary *)GetSearchPayload(s1);
00171        summ2 = (message_summary *)GetSearchPayload(s2);
00172        return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from));
00173 }
00174 /*
00175  * comparator for message summary structs by descending sender.
00176  */
00177 int groupchange_sender(const void *s1, const void *s2) {
00178        message_summary *summ1;
00179        message_summary *summ2;
00180        
00181        summ1 = (message_summary *)s1;
00182        summ2 = (message_summary *)s2;
00183        return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from)) != 0;
00184 
00185 }
00186 
00187 /*
00188  * comparator for message summary structs by ascending date.
00189  */
00190 int summcmp_date(const void *s1, const void *s2) {
00191        message_summary *summ1;
00192        message_summary *summ2;
00193        
00194        summ1 = (message_summary *)GetSearchPayload(s1);
00195        summ2 = (message_summary *)GetSearchPayload(s2);
00196 
00197        if (summ1->date < summ2->date) return -1;
00198        else if (summ1->date > summ2->date) return +1;
00199        else return 0;
00200 }
00201 
00202 /*
00203  * comparator for message summary structs by descending date.
00204  */
00205 int summcmp_rdate(const void *s1, const void *s2) {
00206        message_summary *summ1;
00207        message_summary *summ2;
00208        
00209        summ1 = (message_summary *)GetSearchPayload(s1);
00210        summ2 = (message_summary *)GetSearchPayload(s2);
00211 
00212        if (summ1->date < summ2->date) return +1;
00213        else if (summ1->date > summ2->date) return -1;
00214        else return 0;
00215 }
00216 
00217 /*
00218  * comparator for message summary structs by descending date.
00219  */
00220 const long DAYSECONDS = 24 * 60 * 60;
00221 int groupchange_date(const void *s1, const void *s2) {
00222        message_summary *summ1;
00223        message_summary *summ2;
00224        
00225        summ1 = (message_summary *)s1;
00226        summ2 = (message_summary *)s2;
00227 
00228        return (summ1->date % DAYSECONDS) != (summ2->date %DAYSECONDS);
00229 }
00230 
00231 
00232 /*----------------------------------------------------------------------------*/
00233 /* Don't wanna know... or? */
00234 void examine_pref(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
00235 void examine_suff(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
00236 void examine_path(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
00237 void examine_content_encoding(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
00238 {
00239 /* TODO: do we care? */
00240 }
00241 
00242 void examine_nhdr(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
00243 {
00244        Msg->nhdr = 0;
00245        if (!strncasecmp(ChrPtr(HdrLine), "yes", 8))
00246               Msg->nhdr = 1;
00247 }
00248 int Conditional_ANONYMOUS_MESSAGE(StrBuf *Target, WCTemplputParams *TP)
00249 {
00250        message_summary *Msg = (message_summary*) CTX;
00251        return Msg->nhdr != 0;
00252 }
00253 
00254 void examine_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
00255 {
00256        Msg->format_type = StrToi(HdrLine);
00257                      
00258 }
00259 
00260 void examine_from(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
00261 {
00262        wcsession *WCC = WC;
00263 
00264        CheckConvertBufs(WCC);
00265        FreeStrBuf(&Msg->from);
00266        Msg->from = NewStrBufPlain(NULL, StrLength(HdrLine));
00267        StrBuf_RFC822_2_Utf8(Msg->from, 
00268                           HdrLine, 
00269                           WCC->DefaultCharset, 
00270                           FoundCharset,
00271                           WCC->ConvertBuf1,
00272                           WCC->ConvertBuf2);
00273 }
00274 void tmplput_MAIL_SUMM_FROM(StrBuf *Target, WCTemplputParams *TP)
00275 {
00276        message_summary *Msg = (message_summary*) CTX;
00277        StrBufAppendTemplate(Target, TP, Msg->from, 0);
00278 }
00279 
00280 void examine_subj(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
00281 {
00282        wcsession *WCC = WC;
00283 
00284        CheckConvertBufs(WCC);
00285        FreeStrBuf(&Msg->subj);
00286        Msg->subj = NewStrBufPlain(NULL, StrLength(HdrLine));
00287        StrBuf_RFC822_2_Utf8(Msg->subj, 
00288                           HdrLine, 
00289                           WCC->DefaultCharset, 
00290                           FoundCharset,
00291                           WCC->ConvertBuf1,
00292                           WCC->ConvertBuf2);
00293 }
00294 void tmplput_MAIL_SUMM_SUBJECT(StrBuf *Target, WCTemplputParams *TP)
00295 {
00296        message_summary *Msg = (message_summary*) CTX;
00297 
00298        if (TP->Tokens->nParameters == 4)
00299        {
00300               const char *pch;
00301               long len;
00302               
00303               GetTemplateTokenString(Target, TP, 3, &pch, &len);
00304               if ((len > 0)&&
00305                   (strstr(ChrPtr(Msg->subj), pch) == NULL))
00306               {
00307                      GetTemplateTokenString(Target, TP, 2, &pch, &len);
00308                      StrBufAppendBufPlain(Target, pch, len, 0);
00309               }
00310        }
00311        StrBufAppendTemplate(Target, TP, Msg->subj, 0);
00312 }
00313 int Conditional_MAIL_SUMM_SUBJECT(StrBuf *Target, WCTemplputParams *TP)
00314 {
00315        message_summary *Msg = (message_summary*) CTX;
00316 
00317 
00318        return StrLength(Msg->subj) > 0;
00319 }
00320 
00321 
00322 void examine_msgn(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
00323 {
00324        wcsession *WCC = WC;
00325 
00326        CheckConvertBufs(WCC);
00327        FreeStrBuf(&Msg->reply_inreplyto);
00328        Msg->reply_inreplyto = NewStrBufPlain(NULL, StrLength(HdrLine));
00329        StrBuf_RFC822_2_Utf8(Msg->reply_inreplyto, 
00330                           HdrLine, 
00331                           WCC->DefaultCharset,
00332                           FoundCharset,
00333                           WCC->ConvertBuf1,
00334                           WCC->ConvertBuf2);
00335 }
00336 void tmplput_MAIL_SUMM_INREPLYTO(StrBuf *Target, WCTemplputParams *TP)
00337 {
00338        message_summary *Msg = (message_summary*) CTX;
00339        StrBufAppendTemplate(Target, TP, Msg->reply_inreplyto, 0);
00340 }
00341 
00342 int Conditional_MAIL_SUMM_UNREAD(StrBuf *Target, WCTemplputParams *TP)
00343 {
00344        message_summary *Msg = (message_summary*) CTX;
00345        return (Msg->Flags & MSGFLAG_READ) != 0;
00346 }
00347 
00348 void examine_wefw(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
00349 {
00350        wcsession *WCC = WC;
00351 
00352        CheckConvertBufs(WCC);
00353        FreeStrBuf(&Msg->reply_references);
00354        Msg->reply_references = NewStrBufPlain(NULL, StrLength(HdrLine));
00355        StrBuf_RFC822_2_Utf8(Msg->reply_references, 
00356                           HdrLine, 
00357                           WCC->DefaultCharset, 
00358                           FoundCharset,
00359                           WCC->ConvertBuf1,
00360                           WCC->ConvertBuf2);
00361 }
00362 void tmplput_MAIL_SUMM_REFIDS(StrBuf *Target, WCTemplputParams *TP)
00363 {
00364        message_summary *Msg = (message_summary*) CTX;
00365        StrBufAppendTemplate(Target, TP, Msg->reply_references, 0);
00366 }
00367 
00368 
00369 void examine_cccc(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
00370 {
00371        wcsession *WCC = WC;
00372 
00373        CheckConvertBufs(WCC);
00374        FreeStrBuf(&Msg->cccc);
00375        Msg->cccc = NewStrBufPlain(NULL, StrLength(HdrLine));
00376        StrBuf_RFC822_2_Utf8(Msg->cccc, 
00377                           HdrLine, 
00378                           WCC->DefaultCharset, 
00379                           FoundCharset,
00380                           WCC->ConvertBuf1,
00381                           WCC->ConvertBuf2);
00382        if (Msg->AllRcpt == NULL)
00383               Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
00384        if (StrLength(Msg->AllRcpt) > 0) {
00385               StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
00386        }
00387        StrBufAppendBuf(Msg->AllRcpt, Msg->cccc, 0);
00388 }
00389 void tmplput_MAIL_SUMM_CCCC(StrBuf *Target, WCTemplputParams *TP)
00390 {
00391        message_summary *Msg = (message_summary*) CTX;
00392        StrBufAppendTemplate(Target, TP, Msg->cccc, 0);
00393 }
00394 
00395 
00396 void examine_room(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
00397 {
00398        if ((StrLength(HdrLine) > 0) &&
00399            (strcasecmp(ChrPtr(HdrLine), ChrPtr(WC->CurRoom.name)))) {
00400               FreeStrBuf(&Msg->Room);
00401               Msg->Room = NewStrBufDup(HdrLine);        
00402        }
00403 }
00404 void tmplput_MAIL_SUMM_ORGROOM(StrBuf *Target, WCTemplputParams *TP)
00405 {
00406        message_summary *Msg = (message_summary*) CTX;
00407        StrBufAppendTemplate(Target, TP, Msg->Room, 0);
00408 }
00409 
00410 
00411 void examine_rfca(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
00412 {
00413        FreeStrBuf(&Msg->Rfca);
00414        Msg->Rfca = NewStrBufDup(HdrLine);
00415 }
00416 void tmplput_MAIL_SUMM_RFCA(StrBuf *Target, WCTemplputParams *TP)
00417 {
00418        message_summary *Msg = (message_summary*) CTX;
00419        StrBufAppendTemplate(Target, TP, Msg->Rfca, 0);
00420 }
00421 int Conditional_MAIL_SUMM_RFCA(StrBuf *Target, WCTemplputParams *TP)
00422 {
00423        message_summary *Msg = (message_summary*) CTX;
00424        return StrLength(Msg->Rfca) > 0;
00425 }
00426 int Conditional_MAIL_SUMM_CCCC(StrBuf *Target, WCTemplputParams *TP)
00427 {
00428        message_summary *Msg = (message_summary*) CTX;
00429        return StrLength(Msg->cccc) > 0;
00430 }
00431 
00432 void examine_node(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
00433 {
00434        wcsession *WCC = WC;
00435 
00436        if ( (StrLength(HdrLine) > 0) &&
00437             ((WC->CurRoom.QRFlags & QR_NETWORK)
00438              || ((strcasecmp(ChrPtr(HdrLine), ChrPtr(WCC->serv_info->serv_nodename))
00439                  && (strcasecmp(ChrPtr(HdrLine), ChrPtr(WCC->serv_info->serv_fqdn))))))) {
00440               FreeStrBuf(&Msg->OtherNode);
00441               Msg->OtherNode = NewStrBufDup(HdrLine);
00442        }
00443 }
00444 void tmplput_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP)
00445 {
00446        message_summary *Msg = (message_summary*) CTX;
00447        StrBufAppendTemplate(Target, TP, Msg->OtherNode, 0);
00448 }
00449 int Conditional_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP)
00450 {
00451        message_summary *Msg = (message_summary*) CTX;
00452        return StrLength(Msg->OtherNode) > 0;
00453 }
00454 
00455 
00456 void examine_rcpt(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
00457 {
00458        wcsession *WCC = WC;
00459 
00460        CheckConvertBufs(WCC);
00461        FreeStrBuf(&Msg->to);
00462        Msg->to = NewStrBufPlain(NULL, StrLength(HdrLine));
00463        StrBuf_RFC822_2_Utf8(Msg->to, 
00464                           HdrLine, 
00465                           WCC->DefaultCharset, 
00466                           FoundCharset,
00467                           WCC->ConvertBuf1,
00468                           WCC->ConvertBuf2);
00469        if (Msg->AllRcpt == NULL)
00470               Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
00471        if (StrLength(Msg->AllRcpt) > 0) {
00472               StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
00473        }
00474        StrBufAppendBuf(Msg->AllRcpt, Msg->to, 0);
00475 }
00476 void tmplput_MAIL_SUMM_TO(StrBuf *Target, WCTemplputParams *TP)
00477 {
00478        message_summary *Msg = (message_summary*) CTX;
00479        StrBufAppendTemplate(Target, TP, Msg->to, 0);
00480 }
00481 int Conditional_MAIL_SUMM_TO(StrBuf *Target, WCTemplputParams *TP) 
00482 {
00483        message_summary *Msg = (message_summary*) CTX;
00484        return StrLength(Msg->to) != 0;
00485 }
00486 int Conditional_MAIL_SUMM_SUBJ(StrBuf *Target, WCTemplputParams *TP) 
00487 {
00488        message_summary *Msg = (message_summary*) CTX;
00489        return StrLength(Msg->subj) != 0;
00490 }
00491 void tmplput_MAIL_SUMM_ALLRCPT(StrBuf *Target, WCTemplputParams *TP)
00492 {
00493        message_summary *Msg = (message_summary*) CTX;
00494        StrBufAppendTemplate(Target, TP, Msg->AllRcpt, 0);
00495 }
00496 
00497 
00498 
00499 void tmplput_SUMM_COUNT(StrBuf *Target, WCTemplputParams *TP)
00500 {
00501        StrBufAppendPrintf(Target, "%d", GetCount( WC->summ));
00502 }
00503 
00504 HashList *iterate_get_mailsumm_All(StrBuf *Target, WCTemplputParams *TP)
00505 {
00506        return WC->summ;
00507 }
00508 void examine_time(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
00509 {
00510        Msg->date = StrTol(HdrLine);
00511 }
00512 
00513 void tmplput_MAIL_SUMM_DATE_BRIEF(StrBuf *Target, WCTemplputParams *TP)
00514 {
00515        char datebuf[64];
00516        message_summary *Msg = (message_summary*) CTX;
00517        webcit_fmt_date(datebuf, 64, Msg->date, DATEFMT_BRIEF);
00518        StrBufAppendBufPlain(Target, datebuf, -1, 0);
00519 }
00520 
00521 void tmplput_MAIL_SUMM_EUID(StrBuf *Target, WCTemplputParams *TP)
00522 {
00523        message_summary *Msg = (message_summary*) CTX;
00524        StrBufAppendTemplate(Target, TP, Msg->euid, 0);
00525 }
00526 
00527 void tmplput_MAIL_SUMM_DATE_FULL(StrBuf *Target, WCTemplputParams *TP)
00528 {
00529        char datebuf[64];
00530        message_summary *Msg = (message_summary*) CTX;
00531        webcit_fmt_date(datebuf, 64, Msg->date, DATEFMT_FULL);
00532        StrBufAppendBufPlain(Target, datebuf, -1, 0);
00533 }
00534 void tmplput_MAIL_SUMM_DATE_NO(StrBuf *Target, WCTemplputParams *TP)
00535 {
00536        message_summary *Msg = (message_summary*) CTX;
00537        StrBufAppendPrintf(Target, "%ld", Msg->date, 0);
00538 }
00539 
00540 
00541 
00542 void render_MAIL(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
00543 {
00544        const StrBuf *TemplateMime;
00545 
00546        if (Mime->Data == NULL) 
00547               Mime->Data = NewStrBufPlain(NULL, Mime->length);
00548        else 
00549               FlushStrBuf(Mime->Data);
00550        read_message(Mime->Data, HKEY("view_submessage"), Mime->msgnum, Mime->PartNum, &TemplateMime);
00551 /*
00552        if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
00553               for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
00554                      extract_token(buf, mime_submessages, i, '|', sizeof buf);
00555                      / ** use printable_view to suppress buttons * /
00556                      wc_printf("<blockquote>");
00557                      read_message(Mime->msgnum, 1, ChrPtr(Mime->Section));
00558                      wc_printf("</blockquote>");
00559               }
00560        }
00561 */
00562 }
00563 
00564 void render_MIME_VCard(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
00565 {
00566        wcsession *WCC = WC;
00567        if (StrLength(Mime->Data) == 0)
00568               MimeLoadData(Mime);
00569        if (StrLength(Mime->Data) > 0) {
00570               StrBuf *Buf;
00571               Buf = NewStrBuf();
00573               if (   (!strcasecmp(ChrPtr(WCC->CurRoom.name), USERCONFIGROOM))
00574                      || (!strcasecmp(&(ChrPtr(WCC->CurRoom.name)[11]), USERCONFIGROOM))
00575                      || (WC->CurRoom.view == VIEW_ADDRESSBOOK)
00576                      ) {
00577                      StrBufAppendPrintf(Buf, "<a href=\"edit_vcard?msgnum=%ld?partnum=%s\">",
00578                             Mime->msgnum, ChrPtr(Mime->PartNum));
00579                      StrBufAppendPrintf(Buf, "[%s]</a>", _("edit"));
00580               }
00581 
00582               /* In all cases, display the full card */
00583               display_vcard(Buf, Mime, 0, 1, NULL, -1);
00584               FreeStrBuf(&Mime->Data);
00585               Mime->Data = Buf;
00586        }
00587 
00588 }
00589 
00590 void render_MIME_VNote(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
00591 {
00592        if (StrLength(Mime->Data) == 0)
00593               MimeLoadData(Mime);
00594        if (StrLength(Mime->Data) > 0) {
00595               struct vnote *v;
00596               StrBuf *Buf;
00597               char *vcard;
00598 
00599               Buf = NewStrBuf();
00600               vcard = SmashStrBuf(&Mime->Data);
00601               v = vnote_new_from_str(vcard);
00602               free (vcard);
00603               if (v) {
00604                      WCTemplputParams TP;
00605                      
00606                      memset(&TP, 0, sizeof(WCTemplputParams));
00607                      TP.Filter.ContextType = CTX_VNOTE;
00608                      TP.Context = v;
00609                      DoTemplate(HKEY("mail_vnoteitem"),
00610                                Buf, &TP);
00611                      
00612                      vnote_free(v);
00613                      Mime->Data = Buf;
00614               }
00615               else {
00616                      if (Mime->Data == NULL)
00617                             Mime->Data = NewStrBuf();
00618                      else
00619                             FlushStrBuf(Mime->Data);
00620               }
00621        }
00622 }
00623 
00624 void render_MIME_ICS(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
00625 {
00626        if (StrLength(Mime->Data) == 0) {
00627               MimeLoadData(Mime);
00628        }
00629        if (StrLength(Mime->Data) > 0) {
00630               cal_process_attachment(Mime);
00631        }
00632 }
00633 
00634 
00635 
00636 void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
00637 {
00638        const char *Ptr = NULL;
00639        wc_mime_attachment *Mime;
00640        StrBuf *Buf;
00641        wcsession *WCC = WC;
00642 
00643        CheckConvertBufs(WCC);      
00644        Mime = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
00645        memset(Mime, 0, sizeof(wc_mime_attachment));
00646        Mime->msgnum = Msg->msgnum;
00647        Buf = NewStrBuf();
00648 
00649        Mime->Name = NewStrBuf();
00650        StrBufExtract_NextToken(Buf, HdrLine, &Ptr, '|');
00651        StrBuf_RFC822_2_Utf8(Mime->Name, 
00652                           Buf, 
00653                           WCC->DefaultCharset, 
00654                           FoundCharset,
00655                           WCC->ConvertBuf1,
00656                           WCC->ConvertBuf2);
00657        StrBufTrim(Mime->Name);
00658 
00659        StrBufExtract_NextToken(Buf, HdrLine, &Ptr, '|');
00660        Mime->FileName = NewStrBuf();
00661        StrBuf_RFC822_2_Utf8(Mime->FileName, 
00662                           Buf, 
00663                           WCC->DefaultCharset, 
00664                           FoundCharset,
00665                           WCC->ConvertBuf1,
00666                           WCC->ConvertBuf2);
00667        StrBufTrim(Mime->FileName);
00668 
00669        Mime->PartNum = NewStrBuf();
00670        StrBufExtract_NextToken(Mime->PartNum, HdrLine, &Ptr, '|');
00671        StrBufTrim(Mime->PartNum);
00672        if (strchr(ChrPtr(Mime->PartNum), '.') != NULL) 
00673               Mime->level = 2;
00674        else
00675               Mime->level = 1;
00676 
00677        Mime->Disposition = NewStrBuf();
00678        StrBufExtract_NextToken(Mime->Disposition, HdrLine, &Ptr, '|');
00679 
00680        Mime->ContentType = NewStrBuf();
00681        StrBufExtract_NextToken(Mime->ContentType, HdrLine, &Ptr, '|');
00682        StrBufTrim(Mime->ContentType);
00683        StrBufLowerCase(Mime->ContentType);
00684        if (!strcmp(ChrPtr(Mime->ContentType), "application/octet-stream")) {
00685               StrBufPlain(Mime->ContentType, 
00686                          GuessMimeByFilename(SKEY(Mime->FileName)), -1);
00687        }
00688 
00689        Mime->length = StrBufExtractNext_int(HdrLine, &Ptr, '|');
00690 
00691        StrBufSkip_NTokenS(HdrLine, &Ptr, '|', 1);  /* cbid?? */
00692 
00693        Mime->Charset = NewStrBuf();
00694        StrBufExtract_NextToken(Mime->Charset, HdrLine, &Ptr, '|');
00695 
00696 
00697        if ( (StrLength(Mime->FileName) == 0) && (StrLength(Mime->Name) > 0) ) {
00698               StrBufAppendBuf(Mime->FileName, Mime->Name, 0);
00699        }
00700 
00701        if (StrLength(Msg->PartNum) > 0) {
00702               StrBuf *tmp;
00703               StrBufPrintf(Buf, "%s.%s", ChrPtr(Msg->PartNum), ChrPtr(Mime->PartNum));
00704               tmp = Mime->PartNum;
00705               Mime->PartNum = Buf;
00706               Buf = tmp;
00707        }
00708 
00709        if (Msg->AllAttach == NULL)
00710               Msg->AllAttach = NewHash(1,NULL);
00711        Put(Msg->AllAttach, SKEY(Mime->PartNum), Mime, DestroyMime);
00712        FreeStrBuf(&Buf);
00713 }
00714 
00715 
00716 void evaluate_mime_part(message_summary *Msg, wc_mime_attachment *Mime)
00717 {
00718        void *vMimeRenderer;
00719 
00720        /* just print the root-node */
00721        if ((Mime->level >= 1) &&
00722            GetHash(MimeRenderHandler, SKEY(Mime->ContentType), &vMimeRenderer) &&
00723            vMimeRenderer != NULL)
00724        {
00725               Mime->Renderer = (RenderMimeFuncStruct*) vMimeRenderer;
00726               if (Msg->Submessages == NULL)
00727                      Msg->Submessages = NewHash(1,NULL);
00728               Put(Msg->Submessages, SKEY(Mime->PartNum), Mime, reference_free_handler);
00729        }
00730        else if ((Mime->level >= 1) &&
00731                (!strcasecmp(ChrPtr(Mime->Disposition), "inline"))
00732                && (!strncasecmp(ChrPtr(Mime->ContentType), "image/", 6)) ){
00733               if (Msg->AttachLinks == NULL)
00734                      Msg->AttachLinks = NewHash(1,NULL);
00735               Put(Msg->AttachLinks, SKEY(Mime->PartNum), Mime, reference_free_handler);
00736        }
00737        else if ((Mime->level >= 1) &&
00738                (StrLength(Mime->ContentType) > 0) &&
00739                 ( (!strcasecmp(ChrPtr(Mime->Disposition), "attachment")) 
00740                   || (!strcasecmp(ChrPtr(Mime->Disposition), "inline"))
00741                   || (!strcasecmp(ChrPtr(Mime->Disposition), ""))))
00742        {             
00743               if (Msg->AttachLinks == NULL)
00744                      Msg->AttachLinks = NewHash(1,NULL);
00745               Put(Msg->AttachLinks, SKEY(Mime->PartNum), Mime, reference_free_handler);
00746               if ((strcasecmp(ChrPtr(Mime->ContentType), "application/octet-stream") == 0) && 
00747                   (StrLength(Mime->FileName) > 0)) {
00748                      FlushStrBuf(Mime->ContentType);
00749                      StrBufAppendBufPlain(Mime->ContentType,
00750                                         GuessMimeByFilename(SKEY(Mime->FileName)),
00751                                         -1, 0);
00752               }
00753        }
00754 }
00755 
00756 void tmplput_MAIL_SUMM_NATTACH(StrBuf *Target, WCTemplputParams *TP)
00757 {
00758        message_summary *Msg = (message_summary*) CTX;
00759        StrBufAppendPrintf(Target, "%ld", GetCount(Msg->Attachments));
00760 }
00761 
00762 
00763 void examine_hnod(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
00764 {
00765        wcsession *WCC = WC;
00766 
00767        CheckConvertBufs(WCC);
00768        FreeStrBuf(&Msg->hnod);
00769        Msg->hnod = NewStrBufPlain(NULL, StrLength(HdrLine));
00770        StrBuf_RFC822_2_Utf8(Msg->hnod, 
00771                           HdrLine, 
00772                           WCC->DefaultCharset, 
00773                           FoundCharset,
00774                           WCC->ConvertBuf1,
00775                           WCC->ConvertBuf2);
00776 }
00777 void tmplput_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP)
00778 {
00779        message_summary *Msg = (message_summary*) CTX;
00780        StrBufAppendTemplate(Target, TP, Msg->hnod, 0);
00781 }
00782 int Conditional_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP)
00783 {
00784        message_summary *Msg = (message_summary*) CTX;
00785        return StrLength(Msg->hnod) > 0;
00786 }
00787 
00788 
00789 
00790 void examine_text(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
00791 {
00792        if (Msg->MsgBody->Data == NULL)
00793               Msg->MsgBody->Data = NewStrBufPlain(NULL, SIZ);
00794        else
00795               FlushStrBuf(Msg->MsgBody->Data);
00796 }
00797 
00798 void examine_msg4_partnum(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
00799 {
00800        Msg->MsgBody->PartNum = NewStrBufDup(HdrLine);
00801        StrBufTrim(Msg->MsgBody->PartNum);
00802 }
00803 
00804 void examine_content_lengh(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
00805 {
00806        Msg->MsgBody->length = StrTol(HdrLine);
00807        Msg->MsgBody->size_known = 1;
00808 }
00809 
00810 void examine_content_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
00811 {
00812        void *vHdr;
00813        headereval *Hdr;
00814        StrBuf *Token;
00815        StrBuf *Value;
00816        const char* sem;
00817        const char *eq;
00818        int len;
00819        StrBufTrim(HdrLine);
00820        Msg->MsgBody->ContentType = NewStrBufDup(HdrLine);
00821        sem = strchr(ChrPtr(HdrLine), ';');
00822 
00823        if (sem != NULL) {
00824               Token = NewStrBufPlain(NULL, StrLength(HdrLine));
00825               Value = NewStrBufPlain(NULL, StrLength(HdrLine));
00826               len = sem - ChrPtr(HdrLine);
00827               StrBufCutAt(Msg->MsgBody->ContentType, len, NULL);
00828               while (sem != NULL) {
00829                      while (isspace(*(sem + 1)))
00830                             sem ++;
00831                      StrBufCutLeft(HdrLine, sem - ChrPtr(HdrLine));
00832                      sem = strchr(ChrPtr(HdrLine), ';');
00833                      if (sem != NULL)
00834                             len = sem - ChrPtr(HdrLine);
00835                      else
00836                             len = StrLength(HdrLine);
00837                      FlushStrBuf(Token);
00838                      FlushStrBuf(Value);
00839                      StrBufAppendBufPlain(Token, ChrPtr(HdrLine), len, 0);
00840                      eq = strchr(ChrPtr(Token), '=');
00841                      if (eq != NULL) {
00842                             len = eq - ChrPtr(Token);
00843                             StrBufAppendBufPlain(Value, eq + 1, StrLength(Token) - len - 1, 0); 
00844                             StrBufCutAt(Token, len, NULL);
00845                             StrBufTrim(Value);
00846                      }
00847                      StrBufTrim(Token);
00848 
00849                      if (GetHash(MsgHeaderHandler, SKEY(Token), &vHdr) &&
00850                          (vHdr != NULL)) {
00851                             Hdr = (headereval*)vHdr;
00852                             Hdr->evaluator(Msg, Value, FoundCharset);
00853                      }
00854                      else syslog(1, "don't know how to handle content type sub-header[%s]\n", ChrPtr(Token));
00855               }
00856               FreeStrBuf(&Token);
00857               FreeStrBuf(&Value);
00858        }
00859 }
00860 
00861 void tmplput_MAIL_SUMM_N(StrBuf *Target, WCTemplputParams *TP)
00862 {
00863        message_summary *Msg = (message_summary*) CTX;
00864        StrBufAppendPrintf(Target, "%ld", Msg->msgnum);
00865 }
00866 
00867 
00868 void tmplput_MAIL_SUMM_PERMALINK(StrBuf *Target, WCTemplputParams *TP)
00869 {
00870        message_summary *Msg = (message_summary*) CTX;
00871        char perma_link[1024];
00872 
00873        strcpy(perma_link, "/readfwd?go=");
00874        urlesc(&perma_link[12], sizeof(perma_link) - 12, (char *)ChrPtr(WC->CurRoom.name) );
00875        sprintf(&perma_link[strlen(perma_link)], "?start_reading_at=%ld#%ld", Msg->msgnum, Msg->msgnum);
00876        StrBufAppendPrintf(Target, "%s", perma_link);
00877 }
00878 
00879 
00880 int Conditional_MAIL_MIME_ALL(StrBuf *Target, WCTemplputParams *TP)
00881 {
00882        message_summary *Msg = (message_summary*) CTX;
00883        return GetCount(Msg->Attachments) > 0;
00884 }
00885 
00886 int Conditional_MAIL_MIME_SUBMESSAGES(StrBuf *Target, WCTemplputParams *TP)
00887 {
00888        message_summary *Msg = (message_summary*) CTX;
00889        return GetCount(Msg->Submessages) > 0;
00890 }
00891 
00892 int Conditional_MAIL_MIME_ATTACHLINKS(StrBuf *Target, WCTemplputParams *TP)
00893 {
00894        message_summary *Msg = (message_summary*) CTX;
00895        return GetCount(Msg->AttachLinks) > 0;
00896 }
00897 
00898 int Conditional_MAIL_MIME_ATTACH(StrBuf *Target, WCTemplputParams *TP)
00899 {
00900        message_summary *Msg = (message_summary*) CTX;
00901        return GetCount(Msg->AllAttach) > 0;
00902 }
00903 
00904 void tmplput_QUOTED_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
00905 {
00906        const StrBuf *Mime;
00907         long MsgNum;
00908        StrBuf *Buf;
00909 
00910        MsgNum = LBstr(TKEY(0));
00911        Buf = NewStrBuf();
00912        read_message(Buf, HKEY("view_message_replyquote"), MsgNum, NULL, &Mime);
00913        StrBufAppendTemplate(Target, TP, Buf, 1);
00914        FreeStrBuf(&Buf);
00915 }
00916 
00917 void tmplput_EDIT_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
00918 {
00919        const StrBuf *Mime;
00920         long MsgNum;
00921        StrBuf *Buf;
00922 
00923        MsgNum = LBstr(TKEY(0));
00924        Buf = NewStrBuf();
00925        read_message(Buf, HKEY("view_message_edit"), MsgNum, NULL, &Mime);
00926        StrBufAppendTemplate(Target, TP, Buf, 1);
00927        FreeStrBuf(&Buf);
00928 }
00929 
00930 void tmplput_EDIT_WIKI_BODY(StrBuf *Target, WCTemplputParams *TP)
00931 {
00932        const StrBuf *Mime;
00933         long msgnum;
00934        StrBuf *Buf;
00935 
00936        /* Insert the existing content of the wiki page into the editor.  But we only want
00937         * to do this the first time -- if the user is uploading an attachment we don't want
00938         * to do it again.
00939         */
00940        if (!havebstr("attach_button")) {
00941               char *wikipage = strdup(bstr("page"));
00942               str_wiki_index(wikipage);
00943               msgnum = locate_message_by_uid(wikipage);
00944               free(wikipage);
00945               if (msgnum >= 0L) {
00946                      Buf = NewStrBuf();
00947                      read_message(Buf, HKEY("view_message_wikiedit"), msgnum, NULL, &Mime);
00948                      StrBufAppendTemplate(Target, TP, Buf, 1);
00949                      FreeStrBuf(&Buf);
00950               }
00951        }
00952 }
00953 
00954 void tmplput_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
00955 {
00956        message_summary *Msg = (message_summary*) CTX;
00957        StrBufAppendTemplate(Target, TP, Msg->MsgBody->Data, 0);
00958 }
00959 
00960 
00961 void render_MAIL_variformat(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
00962 {
00963        /* Messages in legacy Citadel variformat get handled thusly... */
00964        StrBuf *Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
00965        FmOut(Target, "JUSTIFY", Mime->Data);
00966        FreeStrBuf(&Mime->Data);
00967        Mime->Data = Target;
00968 }
00969 
00970 void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
00971 {
00972        const char *ptr, *pte;
00973        const char *BufPtr = NULL;
00974        StrBuf *Line;
00975        StrBuf *Line1;
00976        StrBuf *Line2;
00977        StrBuf *Target;
00978        long Linecount;
00979        long nEmptyLines;
00980        int bn = 0;
00981        int bq = 0;
00982        int i;
00983        long len;
00984 #ifdef HAVE_ICONV
00985        StrBuf *cs = NULL;
00986        int ConvertIt = 1;
00987        iconv_t ic = (iconv_t)(-1) ;
00988 #endif
00989 
00990        if ((StrLength(Mime->Data) == 0) && (Mime->length > 0)) {
00991               FreeStrBuf(&Mime->Data);
00992               MimeLoadData(Mime);
00993        }
00994 
00995 #ifdef HAVE_ICONV
00996        if (ConvertIt) {
00997               if (StrLength(Mime->Charset) != 0)
00998                      cs = Mime->Charset;
00999               else if (StrLength(FoundCharset) > 0)
01000                      cs = FoundCharset;
01001               else if (StrLength(WC->DefaultCharset) > 0)
01002                      cs = WC->DefaultCharset;
01003               if (cs == NULL) {
01004                      ConvertIt = 0;
01005               }
01006               else if (!strcasecmp(ChrPtr(cs), "utf-8")) {
01007                      ConvertIt = 0;
01008               }
01009               else if (!strcasecmp(ChrPtr(cs), "us-ascii")) {
01010                      ConvertIt = 0;
01011               }
01012               else {
01013                      ctdl_iconv_open("UTF-8", ChrPtr(cs), &ic);
01014                      if (ic == (iconv_t)(-1) ) {
01015                             syslog(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
01016                                    __FILE__, __LINE__, ChrPtr(Mime->Charset), strerror(errno));
01017                      }
01018               }
01019        }
01020 #endif
01021        Line = NewStrBufPlain(NULL, SIZ);
01022        Line1 = NewStrBufPlain(NULL, SIZ);
01023        Line2 = NewStrBufPlain(NULL, SIZ);
01024        Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
01025        Linecount = 0;
01026        nEmptyLines = 0;
01027        if (StrLength(Mime->Data) > 0) 
01028               do 
01029               {
01030                      StrBufSipLine(Line, Mime->Data, &BufPtr);
01031                      bq = 0;
01032                      i = 0;
01033                      ptr = ChrPtr(Line);
01034                      len = StrLength(Line);
01035                      pte = ptr + len;
01036               
01037                      while ((ptr < pte) &&
01038                             ((*ptr == '>') ||
01039                             isspace(*ptr)))
01040                      {
01041                             if (*ptr == '>')
01042                                    bq++;
01043                             ptr ++;
01044                             i++;
01045                      }
01046                      if (i > 0) StrBufCutLeft(Line, i);
01047               
01048                      if (StrLength(Line) == 0) {
01049                             if (Linecount == 0)
01050                                    continue;
01051                             StrBufAppendBufPlain(Target, HKEY("<tt></tt><br>\n"), 0);
01052 
01053                             nEmptyLines ++;
01054                             continue;
01055                      }
01056                      nEmptyLines = 0;
01057                      for (i = bn; i < bq; i++)                        
01058                             StrBufAppendBufPlain(Target, HKEY("<blockquote>"), 0);
01059                      for (i = bq; i < bn; i++)                        
01060                             StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
01061 #ifdef HAVE_ICONV
01062                      if (ConvertIt) {
01063                             StrBufConvert(Line, Line1, &ic);
01064                      }
01065 #endif
01066                      StrBufAppendBufPlain(Target, HKEY("<tt>"), 0);
01067                      UrlizeText(Line1, Line, Line2);
01068 
01069                      StrEscAppend(Target, Line1, NULL, 0, 0);
01070                      StrBufAppendBufPlain(Target, HKEY("</tt><br>\n"), 0);
01071                      bn = bq;
01072                      Linecount ++;
01073               }
01074        while ((BufPtr != StrBufNOTNULL) &&
01075               (BufPtr != NULL));
01076 
01077        if (nEmptyLines > 0)
01078               StrBufCutRight(Target, nEmptyLines * (sizeof ("<tt></tt><br>\n") - 1));
01079        for (i = 0; i < bn; i++)                         
01080               StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
01081 
01082        StrBufAppendBufPlain(Target, HKEY("</i><br>"), 0);
01083 #ifdef HAVE_ICONV
01084        if (ic != (iconv_t)(-1) ) {
01085               iconv_close(ic);
01086        }
01087 #endif
01088 
01089        FreeStrBuf(&Mime->Data);
01090        Mime->Data = Target;
01091        FlushStrBuf(Mime->ContentType);
01092        StrBufAppendBufPlain(Mime->ContentType, HKEY("text/html"), 0);
01093        FlushStrBuf(Mime->Charset);
01094        StrBufAppendBufPlain(Mime->Charset, HKEY("UTF-8"), 0);
01095        FreeStrBuf(&Line);
01096        FreeStrBuf(&Line1);
01097        FreeStrBuf(&Line2);
01098 }
01099 
01100 void render_MAIL_html(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
01101 {
01102        StrBuf *Buf;
01103 
01104        if (StrLength(Mime->Data) == 0)
01105               return;
01106 
01107        Buf = NewStrBufPlain(NULL, StrLength(Mime->Data));
01108 
01109        /* HTML is fun, but we've got to strip it first */
01110        output_html(ChrPtr(Mime->Charset), 
01111                   (WC->CurRoom.view == VIEW_WIKI ? 1 : 0), 
01112                   Mime->msgnum,
01113                   Mime->Data, Buf);
01114        FreeStrBuf(&Mime->Data);
01115        Mime->Data = Buf;
01116 }
01117 
01118 void render_MAIL_UNKNOWN(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
01119 {
01120        /* Unknown weirdness */
01121        FlushStrBuf(Mime->Data);
01122        StrBufAppendBufPlain(Mime->Data, _("I don't know how to display "), -1, 0);
01123        StrBufAppendBuf(Mime->Data, Mime->ContentType, 0);
01124        StrBufAppendBufPlain(Mime->Data, HKEY("<br>\n"), 0);
01125 }
01126 
01127 
01128 HashList *iterate_get_mime_All(StrBuf *Target, WCTemplputParams *TP)
01129 {
01130        message_summary *Msg = (message_summary*) CTX;
01131        return Msg->Attachments;
01132 }
01133 HashList *iterate_get_mime_Submessages(StrBuf *Target, WCTemplputParams *TP)
01134 {
01135        message_summary *Msg = (message_summary*) CTX;
01136        return Msg->Submessages;
01137 }
01138 HashList *iterate_get_mime_AttachLinks(StrBuf *Target, WCTemplputParams *TP)
01139 {
01140        message_summary *Msg = (message_summary*) CTX;
01141        return Msg->AttachLinks;
01142 }
01143 HashList *iterate_get_mime_Attachments(StrBuf *Target, WCTemplputParams *TP)
01144 {
01145        message_summary *Msg = (message_summary*) CTX;
01146        return Msg->AllAttach;
01147 }
01148 
01149 void tmplput_MIME_Name(StrBuf *Target, WCTemplputParams *TP)
01150 {
01151        wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
01152        StrBufAppendTemplate(Target, TP, mime->Name, 0);
01153 }
01154 
01155 void tmplput_MIME_FileName(StrBuf *Target, WCTemplputParams *TP)
01156 {
01157        wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
01158        StrBufAppendTemplate(Target, TP, mime->FileName, 0);
01159 }
01160 
01161 void tmplput_MIME_PartNum(StrBuf *Target, WCTemplputParams *TP)
01162 {
01163        wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
01164        StrBufAppendTemplate(Target, TP, mime->PartNum, 0);
01165 }
01166 
01167 void tmplput_MIME_MsgNum(StrBuf *Target, WCTemplputParams *TP)
01168 {
01169        wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
01170        StrBufAppendPrintf(Target, "%ld", mime->msgnum);
01171 }
01172 
01173 void tmplput_MIME_Disposition(StrBuf *Target, WCTemplputParams *TP)
01174 {
01175        wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
01176        StrBufAppendTemplate(Target, TP, mime->Disposition, 0);
01177 }
01178 
01179 void tmplput_MIME_ContentType(StrBuf *Target, WCTemplputParams *TP)
01180 {
01181        wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
01182        StrBufAppendTemplate(Target, TP, mime->ContentType, 0);
01183 }
01184 
01185 void examine_charset(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
01186 {
01187        Msg->MsgBody->Charset = NewStrBufDup(HdrLine);
01188 }
01189 
01190 void tmplput_MIME_Charset(StrBuf *Target, WCTemplputParams *TP)
01191 {
01192        wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
01193        StrBufAppendTemplate(Target, TP, mime->Charset, 0);
01194 }
01195 
01196 void tmplput_MIME_Data(StrBuf *Target, WCTemplputParams *TP)
01197 {
01198        wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
01199        if (mime->Renderer != NULL)
01200               mime->Renderer->f(mime, NULL, NULL);
01201        StrBufAppendTemplate(Target, TP, mime->Data, 0);
01202        /* TODO: check whether we need to load it now? */
01203 }
01204 
01205 void tmplput_MIME_LoadData(StrBuf *Target, WCTemplputParams *TP)
01206 {
01207        wcsession *WCC = WC; 
01208        wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
01209        wc_mime_attachment *att;
01210        
01211        if (( (!strcasecmp(ChrPtr(mime->Disposition), "inline"))||
01212              (!strcasecmp(ChrPtr(mime->Disposition), "attachment"))) && 
01213            (strcasecmp(ChrPtr(mime->ContentType), "application/ms-tnef")!=0))
01214        {
01215               
01216               int n;
01217               char N[64];
01218               /* steal this mime part... */
01219               att = malloc(sizeof(wc_mime_attachment));
01220               memcpy(att, mime, sizeof(wc_mime_attachment));
01221               memset(mime, 0, sizeof(wc_mime_attachment));
01222 
01223               if (att->Data == NULL) 
01224                      MimeLoadData(att);
01225 
01226               if (WCC->attachments == NULL)
01227                      WCC->attachments = NewHash(1, NULL);
01228               /* And add it to the list. */
01229               n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
01230               Put(WCC->attachments, N, n, att, DestroyMime);
01231        }
01232 }
01233 
01234 void tmplput_MIME_Length(StrBuf *Target, WCTemplputParams *TP)
01235 {
01236        wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
01237        StrBufAppendPrintf(Target, "%ld", mime->length);
01238 }
01239 
01240 HashList *iterate_get_registered_Attachments(StrBuf *Target, WCTemplputParams *TP)
01241 {
01242        return WC->attachments;
01243 }
01244 
01245 void get_registered_Attachments_Count(StrBuf *Target, WCTemplputParams *TP)
01246 {
01247        StrBufAppendPrintf(Target, "%ld", GetCount (WC->attachments));
01248 }
01249 
01250 void servcmd_do_search(char *buf, long bufsize)
01251 {
01252        snprintf(buf, bufsize, "MSGS SEARCH|%s", bstr("query"));
01253 }
01254 
01255 void servcmd_headers(char *buf, long bufsize)
01256 {
01257        snprintf(buf, bufsize, "MSGS ALL");
01258 }
01259 
01260 void servcmd_readfwd(char *buf, long bufsize)
01261 {
01262        snprintf(buf, bufsize, "MSGS ALL");
01263 }
01264 
01265 void servcmd_readgt(char *buf, long bufsize)
01266 {
01267        snprintf(buf, bufsize, "MSGS GT|%s", bstr("gt"));
01268 }
01269 
01270 void servcmd_readlt(char *buf, long bufsize)
01271 {
01272        snprintf(buf, bufsize, "MSGS LT|%s", bstr("lt"));
01273 }
01274 
01275 void servcmd_readnew(char *buf, long bufsize)
01276 {
01277        snprintf(buf, bufsize, "MSGS NEW");
01278 }
01279 
01280 void servcmd_readold(char *buf, long bufsize)
01281 {
01282        snprintf(buf, bufsize, "MSGS OLD");
01283 }
01284 
01285 
01286 /* DO NOT REORDER OR REMOVE ANY OF THESE */
01287 readloop_struct rlid[] = {
01288        { {HKEY("do_search")},      servcmd_do_search    },
01289        { {HKEY("headers")}, servcmd_headers             },
01290        { {HKEY("readfwd")}, servcmd_readfwd             },
01291        { {HKEY("readnew")}, servcmd_readnew             },
01292        { {HKEY("readold")}, servcmd_readold             },
01293        { {HKEY("readgt")},  servcmd_readgt              },
01294        { {HKEY("readlt")},  servcmd_readlt              }
01295 };
01296 
01297 
01298 int ParseMessageListHeaders_Detail(StrBuf *Line, 
01299                                const char **pos, 
01300                                message_summary *Msg, 
01301                                StrBuf *ConversionBuffer)
01302 {
01303        wcsession *WCC = WC;
01304        long len;
01305        long totallen;
01306 
01307        CheckConvertBufs(WCC);
01308 
01309        totallen = StrLength(Line);
01310        Msg->from = NewStrBufPlain(NULL, totallen);
01311        len = StrBufExtract_NextToken(ConversionBuffer, Line, pos, '|');
01312        if (len > 0) {
01313               /* Handle senders with RFC2047 encoding */
01314               StrBuf_RFC822_2_Utf8(Msg->from, 
01315                                  ConversionBuffer, 
01316                                  WCC->DefaultCharset, 
01317                                  NULL, 
01318                                  WCC->ConvertBuf1,
01319                                  WCC->ConvertBuf2);
01320        }
01321                      
01322        /* node name */
01323        len = StrBufExtract_NextToken(ConversionBuffer, Line, pos, '|');
01324        if ((len > 0 ) &&
01325            ( ((WCC->CurRoom.QRFlags & QR_NETWORK)
01326               || ((strcasecmp(ChrPtr(ConversionBuffer), ChrPtr(WCC->serv_info->serv_nodename))
01327                   && (strcasecmp(ChrPtr(ConversionBuffer), ChrPtr(WCC->serv_info->serv_fqdn))))))))
01328        {
01329               StrBufAppendBufPlain(Msg->from, HKEY(" @ "), 0);
01330               StrBufAppendBuf(Msg->from, ConversionBuffer, 0);
01331        }
01332 
01333        /* Internet address (not used)
01334         *     StrBufExtract_token(Msg->inetaddr, Line, 4, '|');
01335         */
01336        StrBufSkip_NTokenS(Line, pos, '|', 1);
01337        Msg->subj = NewStrBufPlain(NULL, totallen);
01338 
01339        FlushStrBuf(ConversionBuffer);
01340        /* we assume the subject is the last parameter inside of the list; 
01341         * thus we don't use the tokenizer to fetch it, since it will hick up 
01342         * on tokenizer chars inside of the subjects
01343        StrBufExtract_NextToken(ConversionBuffer,  Line, pos, '|');
01344        */
01345        len = 0;
01346        if (*pos != StrBufNOTNULL) {
01347               len = totallen - (*pos - ChrPtr(Line));
01348               StrBufPlain(ConversionBuffer, *pos, len);
01349               *pos = StrBufNOTNULL;
01350               if ((len > 0) &&
01351                   (*(ChrPtr(ConversionBuffer) + len - 1) == '|'))
01352                      StrBufCutRight(ConversionBuffer, 1);
01353        }
01354 
01355        if (len == 0)
01356               StrBufAppendBufPlain(Msg->subj, _("(no subject)"), -1,0);
01357        else {
01358               StrBuf_RFC822_2_Utf8(Msg->subj, 
01359                                  ConversionBuffer, 
01360                                  WCC->DefaultCharset, 
01361                                  NULL,
01362                                  WCC->ConvertBuf1,
01363                                  WCC->ConvertBuf2);
01364        }
01365 
01366        return 1;
01367 }
01368 
01369 
01370 int mailview_GetParamsGetServerCall(SharedMessageStatus *Stat, 
01371                                 void **ViewSpecific, 
01372                                 long oper, 
01373                                 char *cmd, 
01374                                 long len,
01375                                 char *filter,
01376                                 long flen)
01377 {
01378        DoTemplate(HKEY("msg_listview"),NULL,&NoCtx);
01379 
01380        return 200;
01381 }
01382 
01383 int mailview_Cleanup(void **ViewSpecific)
01384 {
01385        /* Note: wDumpContent() will output one additional </div> tag. */
01386        /* We ought to move this out into template */
01387        wDumpContent(1);
01388 
01389        return 0;
01390 }
01391 
01392 
01393 int json_GetParamsGetServerCall(SharedMessageStatus *Stat, 
01394                             void **ViewSpecific, 
01395                             long oper, 
01396                             char *cmd, 
01397                             long len,
01398                             char *filter,
01399                             long flen)
01400 {
01401        Stat->defaultsortorder = 2;
01402        Stat->sortit = 1;
01403        Stat->load_seen = 1;
01404        /* Generally using maxmsgs|startmsg is not required
01405           in mailbox view, but we have a 'safemode' for clients
01406           (*cough* Exploder) that simply can't handle too many */
01407        if (havebstr("maxmsgs"))  Stat->maxmsgs  = ibstr("maxmsgs");
01408        else                      Stat->maxmsgs  = 9999999;
01409        if (havebstr("startmsg")) Stat->startmsg = lbstr("startmsg");
01410        snprintf(cmd, len, "MSGS %s|%s||1",
01411                (oper == do_search) ? "SEARCH" : "ALL",
01412                (oper == do_search) ? bstr("query") : ""
01413               );
01414 
01415        return 200;
01416 }
01417 int json_MessageListHdr(SharedMessageStatus *Stat, void **ViewSpecific) 
01418 {
01419        /* TODO: make a generic function */
01420        hprintf("HTTP/1.1 200 OK\r\n");
01421        hprintf("Content-type: application/json; charset=utf-8\r\n");
01422        hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
01423        hprintf("Connection: close\r\n");
01424        hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
01425        begin_burst();
01426        return 0;
01427 }
01428 
01429 int json_RenderView_or_Tail(SharedMessageStatus *Stat, 
01430                          void **ViewSpecific, 
01431                          long oper)
01432 {
01433        WCTemplputParams SubTP;
01434 
01435        memset(&SubTP, 0, sizeof(WCTemplputParams));
01436        DoTemplate(HKEY("mailsummary_json"),NULL, &SubTP);
01437        
01438        return 0;
01439 }
01440 
01441 int json_Cleanup(void **ViewSpecific)
01442 {
01443        /* Note: wDumpContent() will output one additional </div> tag. */
01444        /* We ought to move this out into template */
01445        end_burst();
01446 
01447        return 0;
01448 }
01449 
01450 
01451 
01452 void 
01453 InitModule_MSGRENDERERS
01454 (void)
01455 {
01456        RegisterReadLoopHandlerset(
01457               VIEW_MAILBOX,
01458               mailview_GetParamsGetServerCall,
01459               NULL, /* TODO: is this right? */
01460               NULL,
01461               ParseMessageListHeaders_Detail,
01462               NULL,
01463               NULL,
01464               mailview_Cleanup);
01465 
01466        RegisterReadLoopHandlerset(
01467               VIEW_JSON_LIST,
01468               json_GetParamsGetServerCall,
01469               json_MessageListHdr,
01470               NULL, /* TODO: is this right? */
01471               ParseMessageListHeaders_Detail,
01472               NULL,
01473               json_RenderView_or_Tail,
01474               json_Cleanup);
01475 
01476        RegisterSortFunc(HKEY("date"), 
01477                       NULL, 0,
01478                       summcmp_date,
01479                       summcmp_rdate,
01480                       groupchange_date,
01481                       CTX_MAILSUM);
01482        RegisterSortFunc(HKEY("subject"), 
01483                       NULL, 0,
01484                       summcmp_subj,
01485                       summcmp_rsubj,
01486                       groupchange_subj,
01487                       CTX_MAILSUM);
01488        RegisterSortFunc(HKEY("sender"),
01489                       NULL, 0,
01490                       summcmp_sender,
01491                       summcmp_rsender,
01492                       groupchange_sender,
01493                       CTX_MAILSUM);
01494 
01495        RegisterNamespace("SUMM:COUNT", 0, 0, tmplput_SUMM_COUNT, NULL, CTX_NONE);
01496        /* iterate over all known mails in WC->summ */
01497        RegisterIterator("MAIL:SUMM:MSGS", 0, NULL, iterate_get_mailsumm_All,
01498                       NULL,NULL, CTX_MAILSUM, CTX_NONE, IT_NOFLAG);
01499 
01500        RegisterNamespace("MAIL:SUMM:EUID", 0, 1, tmplput_MAIL_SUMM_EUID, NULL, CTX_MAILSUM);
01501        RegisterNamespace("MAIL:SUMM:DATEBRIEF", 0, 0, tmplput_MAIL_SUMM_DATE_BRIEF, NULL, CTX_MAILSUM);
01502        RegisterNamespace("MAIL:SUMM:DATEFULL", 0, 0, tmplput_MAIL_SUMM_DATE_FULL, NULL, CTX_MAILSUM);
01503        RegisterNamespace("MAIL:SUMM:DATENO",  0, 0, tmplput_MAIL_SUMM_DATE_NO,  NULL, CTX_MAILSUM);
01504        RegisterNamespace("MAIL:SUMM:N",       0, 0, tmplput_MAIL_SUMM_N,        NULL, CTX_MAILSUM);
01505        RegisterNamespace("MAIL:SUMM:PERMALINK", 0, 0, tmplput_MAIL_SUMM_PERMALINK, NULL, CTX_MAILSUM);
01506        RegisterNamespace("MAIL:SUMM:FROM",    0, 2, tmplput_MAIL_SUMM_FROM,     NULL, CTX_MAILSUM);
01507        RegisterNamespace("MAIL:SUMM:TO",      0, 2, tmplput_MAIL_SUMM_TO,       NULL, CTX_MAILSUM);
01508        RegisterNamespace("MAIL:SUMM:SUBJECT", 0, 4, tmplput_MAIL_SUMM_SUBJECT,  NULL, CTX_MAILSUM);
01509        RegisterNamespace("MAIL:SUMM:NTATACH", 0, 0, tmplput_MAIL_SUMM_NATTACH,  NULL, CTX_MAILSUM);
01510        RegisterNamespace("MAIL:SUMM:CCCC", 0, 2, tmplput_MAIL_SUMM_CCCC, NULL, CTX_MAILSUM);
01511        RegisterNamespace("MAIL:SUMM:H_NODE", 0, 2, tmplput_MAIL_SUMM_H_NODE,  NULL, CTX_MAILSUM);
01512        RegisterNamespace("MAIL:SUMM:ALLRCPT", 0, 2, tmplput_MAIL_SUMM_ALLRCPT,  NULL, CTX_MAILSUM);
01513        RegisterNamespace("MAIL:SUMM:ORGROOM", 0, 2, tmplput_MAIL_SUMM_ORGROOM,  NULL, CTX_MAILSUM);
01514        RegisterNamespace("MAIL:SUMM:RFCA", 0, 2, tmplput_MAIL_SUMM_RFCA, NULL, CTX_MAILSUM);
01515        RegisterNamespace("MAIL:SUMM:OTHERNODE", 2, 0, tmplput_MAIL_SUMM_OTHERNODE,  NULL, CTX_MAILSUM);
01516        RegisterNamespace("MAIL:SUMM:REFIDS", 0, 1, tmplput_MAIL_SUMM_REFIDS,  NULL, CTX_MAILSUM);
01517        RegisterNamespace("MAIL:SUMM:INREPLYTO", 0, 2, tmplput_MAIL_SUMM_INREPLYTO,  NULL, CTX_MAILSUM);
01518        RegisterNamespace("MAIL:BODY", 0, 2, tmplput_MAIL_BODY,  NULL, CTX_MAILSUM);
01519        RegisterNamespace("MAIL:QUOTETEXT", 1, 2, tmplput_QUOTED_MAIL_BODY,  NULL, CTX_NONE);
01520        RegisterNamespace("MAIL:EDITTEXT", 1, 2, tmplput_EDIT_MAIL_BODY,  NULL, CTX_NONE);
01521        RegisterNamespace("MAIL:EDITWIKI", 1, 2, tmplput_EDIT_WIKI_BODY,  NULL, CTX_NONE);
01522        RegisterConditional(HKEY("COND:MAIL:SUMM:RFCA"), 0, Conditional_MAIL_SUMM_RFCA,  CTX_MAILSUM);
01523        RegisterConditional(HKEY("COND:MAIL:SUMM:CCCC"), 0, Conditional_MAIL_SUMM_CCCC,  CTX_MAILSUM);
01524        RegisterConditional(HKEY("COND:MAIL:SUMM:UNREAD"), 0, Conditional_MAIL_SUMM_UNREAD, CTX_MAILSUM);
01525        RegisterConditional(HKEY("COND:MAIL:SUMM:H_NODE"), 0, Conditional_MAIL_SUMM_H_NODE, CTX_MAILSUM);
01526        RegisterConditional(HKEY("COND:MAIL:SUMM:OTHERNODE"), 0, Conditional_MAIL_SUMM_OTHERNODE, CTX_MAILSUM);
01527        RegisterConditional(HKEY("COND:MAIL:SUMM:SUBJECT"), 0, Conditional_MAIL_SUMM_SUBJECT, CTX_MAILSUM);
01528        RegisterConditional(HKEY("COND:MAIL:ANON"), 0, Conditional_ANONYMOUS_MESSAGE, CTX_MAILSUM);
01529        RegisterConditional(HKEY("COND:MAIL:TO"), 0, Conditional_MAIL_SUMM_TO, CTX_MAILSUM);       
01530        RegisterConditional(HKEY("COND:MAIL:SUBJ"), 0, Conditional_MAIL_SUMM_SUBJ, CTX_MAILSUM);   
01531 
01532        /* do we have mimetypes to iterate over? */
01533        RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH"), 0, Conditional_MAIL_MIME_ALL, CTX_MAILSUM);
01534        RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:SUBMESSAGES"), 0, Conditional_MAIL_MIME_SUBMESSAGES, CTX_MAILSUM);
01535        RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:LINKS"), 0, Conditional_MAIL_MIME_ATTACHLINKS, CTX_MAILSUM);
01536        RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:ATT"), 0, Conditional_MAIL_MIME_ATTACH, CTX_MAILSUM);
01537        RegisterIterator("MAIL:MIME:ATTACH", 0, NULL, iterate_get_mime_All, 
01538                       NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
01539        RegisterIterator("MAIL:MIME:ATTACH:SUBMESSAGES", 0, NULL, iterate_get_mime_Submessages, 
01540                       NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
01541        RegisterIterator("MAIL:MIME:ATTACH:LINKS", 0, NULL, iterate_get_mime_AttachLinks, 
01542                       NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
01543        RegisterIterator("MAIL:MIME:ATTACH:ATT", 0, NULL, iterate_get_mime_Attachments, 
01544                       NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
01545 
01546        /* Parts of a mime attachent */
01547        RegisterNamespace("MAIL:MIME:NAME", 0, 2, tmplput_MIME_Name, NULL, CTX_MIME_ATACH);
01548        RegisterNamespace("MAIL:MIME:FILENAME", 0, 2, tmplput_MIME_FileName, NULL, CTX_MIME_ATACH);
01549        RegisterNamespace("MAIL:MIME:PARTNUM", 0, 2, tmplput_MIME_PartNum, NULL, CTX_MIME_ATACH);
01550        RegisterNamespace("MAIL:MIME:MSGNUM", 0, 2, tmplput_MIME_MsgNum, NULL, CTX_MIME_ATACH);
01551        RegisterNamespace("MAIL:MIME:DISPOSITION", 0, 2, tmplput_MIME_Disposition, NULL, CTX_MIME_ATACH);
01552        RegisterNamespace("MAIL:MIME:CONTENTTYPE", 0, 2, tmplput_MIME_ContentType, NULL, CTX_MIME_ATACH);
01553        RegisterNamespace("MAIL:MIME:CHARSET", 0, 2, tmplput_MIME_Charset, NULL, CTX_MIME_ATACH);
01554        RegisterNamespace("MAIL:MIME:LENGTH", 0, 2, tmplput_MIME_Length, NULL, CTX_MIME_ATACH);
01555        RegisterNamespace("MAIL:MIME:DATA", 0, 2, tmplput_MIME_Data, NULL, CTX_MIME_ATACH);
01556        /* load the actual attachment into WC->attachments; no output!!! */
01557        RegisterNamespace("MAIL:MIME:LOADDATA", 0, 0, tmplput_MIME_LoadData, NULL, CTX_MIME_ATACH);
01558 
01559        /* iterate the WC->attachments; use the above tokens for their contents */
01560        RegisterIterator("MSG:ATTACHNAMES", 0, NULL, iterate_get_registered_Attachments, 
01561                       NULL, NULL, CTX_MIME_ATACH, CTX_NONE, IT_NOFLAG);
01562 
01563        RegisterNamespace("MSG:NATTACH", 0, 0, get_registered_Attachments_Count,  NULL, CTX_NONE);
01564 
01565        /* mime renderers translate an attachment into webcit viewable html text */
01566        RegisterMimeRenderer(HKEY("message/rfc822"), render_MAIL, 0, 150);
01567        RegisterMimeRenderer(HKEY("text/vnote"), render_MIME_VNote, 1, 300);
01568        RegisterMimeRenderer(HKEY("text/x-vcard"), render_MIME_VCard, 1, 201);
01569        RegisterMimeRenderer(HKEY("text/vcard"), render_MIME_VCard, 1, 200);
01570        RegisterMimeRenderer(HKEY("text/calendar"), render_MIME_ICS, 1, 501);
01571        RegisterMimeRenderer(HKEY("application/ics"), render_MIME_ICS, 1, 500);
01572        RegisterMimeRenderer(HKEY("text/x-citadel-variformat"), render_MAIL_variformat, 1, 2);
01573        RegisterMimeRenderer(HKEY("text/plain"), render_MAIL_text_plain, 1, 3);
01574        RegisterMimeRenderer(HKEY("text"), render_MAIL_text_plain, 1, 1);
01575        RegisterMimeRenderer(HKEY("text/html"), render_MAIL_html, 1, 100);
01576        RegisterMimeRenderer(HKEY(""), render_MAIL_UNKNOWN, 0, 0);
01577 
01578        /* these headers are citserver replies to MSG4 and friends. one evaluator for each */
01579        RegisterMsgHdr(HKEY("nhdr"), examine_nhdr, 0);
01580        RegisterMsgHdr(HKEY("type"), examine_type, 0);
01581        RegisterMsgHdr(HKEY("from"), examine_from, 0);
01582        RegisterMsgHdr(HKEY("subj"), examine_subj, 0);
01583        RegisterMsgHdr(HKEY("msgn"), examine_msgn, 0);
01584        RegisterMsgHdr(HKEY("wefw"), examine_wefw, 0);
01585        RegisterMsgHdr(HKEY("cccc"), examine_cccc, 0);
01586        RegisterMsgHdr(HKEY("hnod"), examine_hnod, 0);
01587        RegisterMsgHdr(HKEY("room"), examine_room, 0);
01588        RegisterMsgHdr(HKEY("rfca"), examine_rfca, 0);
01589        RegisterMsgHdr(HKEY("node"), examine_node, 0);
01590        RegisterMsgHdr(HKEY("rcpt"), examine_rcpt, 0);
01591        RegisterMsgHdr(HKEY("time"), examine_time, 0);
01592        RegisterMsgHdr(HKEY("part"), examine_mime_part, 0);
01593        RegisterMsgHdr(HKEY("text"), examine_text, 1);
01594        /* these are the content-type headers we get infront of a message; put it into the same hash since it doesn't clash. */
01595        RegisterMsgHdr(HKEY("X-Citadel-MSG4-Partnum"), examine_msg4_partnum, 0);
01596        RegisterMsgHdr(HKEY("Content-type"), examine_content_type, 0);
01597        RegisterMsgHdr(HKEY("Content-length"), examine_content_lengh, 0);
01598        RegisterMsgHdr(HKEY("Content-transfer-encoding"), examine_content_encoding, 0); /* do we care? */
01599        RegisterMsgHdr(HKEY("charset"), examine_charset, 0);
01600 
01601        /* Don't care about these... */
01602        RegisterMsgHdr(HKEY("pref"), examine_pref, 0);
01603        RegisterMsgHdr(HKEY("suff"), examine_suff, 0);
01604        RegisterMsgHdr(HKEY("path"), examine_path, 0);
01605 }
01606 
01607 void 
01608 InitModule2_MSGRENDERERS
01609 (void)
01610 {
01611        /* and finalize the anouncement to the server... */
01612        CreateMimeStr();
01613 }
01614 void 
01615 ServerStartModule_MSGRENDERERS
01616 (void)
01617 {
01618        MsgHeaderHandler = NewHash(1, NULL);
01619        MimeRenderHandler = NewHash(1, NULL);
01620        ReadLoopHandler = NewHash(1, NULL);
01621 }
01622 
01623 void 
01624 ServerShutdownModule_MSGRENDERERS
01625 (void)
01626 {
01627        DeleteHash(&MsgHeaderHandler);
01628        DeleteHash(&MimeRenderHandler);
01629        DeleteHash(&ReadLoopHandler);
01630 }
01631 
01632 
01633 
01634 void 
01635 SessionDestroyModule_MSGRENDERERS
01636 (wcsession *sess)
01637 {
01638        DeleteHash(&sess->attachments);
01639        FreeStrBuf(&sess->ConvertBuf1);
01640        FreeStrBuf(&sess->ConvertBuf2);
01641 }