* abstract sorting algorithms. abstraction layer so far used in the message view.
[citadel.git] / webcit / msg_renderers.c
1 /*----------------------------------------------------------------------------*/
2 #include "webcit.h"
3 #include "webserver.h"
4
5 /**
6  * message index functions
7  */
8
9 void DestroyMimeParts(wc_mime_attachment *Mime)
10 {
11         FreeStrBuf(&Mime->Name);
12         FreeStrBuf(&Mime->FileName);
13         FreeStrBuf(&Mime->PartNum);
14         FreeStrBuf(&Mime->Disposition);
15         FreeStrBuf(&Mime->ContentType);
16         FreeStrBuf(&Mime->Charset);
17         FreeStrBuf(&Mime->Data);
18 }
19
20 void DestroyMime(void *vMime)
21 {
22         wc_mime_attachment *Mime = (wc_mime_attachment*)vMime;
23         DestroyMimeParts(Mime);
24         free(Mime);
25 }
26
27 void DestroyMessageSummary(void *vMsg)
28 {
29         message_summary *Msg = (message_summary*) vMsg;
30
31         FreeStrBuf(&Msg->from);
32         FreeStrBuf(&Msg->to);
33         FreeStrBuf(&Msg->subj);
34         FreeStrBuf(&Msg->reply_inreplyto);
35         FreeStrBuf(&Msg->reply_references);
36         FreeStrBuf(&Msg->cccc);
37         FreeStrBuf(&Msg->hnod);
38         FreeStrBuf(&Msg->AllRcpt);
39         FreeStrBuf(&Msg->Room);
40         FreeStrBuf(&Msg->Rfca);
41         FreeStrBuf(&Msg->OtherNode);
42
43         FreeStrBuf(&Msg->reply_to);
44
45         DeleteHash(&Msg->Attachments);  /**< list of Accachments */
46         DeleteHash(&Msg->Submessages);
47         DeleteHash(&Msg->AttachLinks);
48         DeleteHash(&Msg->AllAttach);
49         free(Msg);
50 }
51
52
53
54 void RegisterMsgHdr(const char *HeaderName, long HdrNLen, ExamineMsgHeaderFunc evaluator, int type)
55 {
56         headereval *ev;
57         ev = (headereval*) malloc(sizeof(headereval));
58         ev->evaluator = evaluator;
59         ev->Type = type;
60         Put(MsgHeaderHandler, HeaderName, HdrNLen, ev, NULL);
61 }
62
63 void RegisterMimeRenderer(const char *HeaderName, long HdrNLen, RenderMimeFunc MimeRenderer)
64 {
65         Put(MimeRenderHandler, HeaderName, HdrNLen, MimeRenderer, reference_free_handler);
66         
67 }
68
69 /*----------------------------------------------------------------------------*/
70
71 /*
72  * qsort() compatible function to compare two longs in descending order.
73  */
74 int longcmp_r(const void *s1, const void *s2) {
75         long l1;
76         long l2;
77
78         l1 = *(long *)GetSearchPayload(s1);
79         l2 = *(long *)GetSearchPayload(s2);
80
81         if (l1 > l2) return(-1);
82         if (l1 < l2) return(+1);
83         return(0);
84 }
85
86 /*
87  * qsort() compatible function to compare two longs in descending order.
88  */
89 int qlongcmp_r(const void *s1, const void *s2) {
90         long l1 = (long) s1;
91         long l2 = (long) s2;
92
93         if (l1 > l2) return(-1);
94         if (l1 < l2) return(+1);
95         return(0);
96 }
97
98  
99 /*
100  * qsort() compatible function to compare two message summary structs by ascending subject.
101  */
102 int summcmp_subj(const void *s1, const void *s2) {
103         message_summary *summ1;
104         message_summary *summ2;
105         
106         summ1 = (message_summary *)GetSearchPayload(s1);
107         summ2 = (message_summary *)GetSearchPayload(s2);
108         return strcasecmp(ChrPtr(summ1->subj), ChrPtr(summ2->subj));
109 }
110
111 /*
112  * qsort() compatible function to compare two message summary structs by descending subject.
113  */
114 int summcmp_rsubj(const void *s1, const void *s2) {
115         message_summary *summ1;
116         message_summary *summ2;
117         
118         summ1 = (message_summary *)GetSearchPayload(s1);
119         summ2 = (message_summary *)GetSearchPayload(s2);
120         return strcasecmp(ChrPtr(summ2->subj), ChrPtr(summ1->subj));
121 }
122
123 /*
124  * qsort() compatible function to compare two message summary structs by ascending sender.
125  */
126 int summcmp_sender(const void *s1, const void *s2) {
127         message_summary *summ1;
128         message_summary *summ2;
129         
130         summ1 = (message_summary *)GetSearchPayload(s1);
131         summ2 = (message_summary *)GetSearchPayload(s2);
132         return strcasecmp(ChrPtr(summ1->from), ChrPtr(summ2->from));
133 }
134
135 /*
136  * qsort() compatible function to compare two message summary structs by descending sender.
137  */
138 int summcmp_rsender(const void *s1, const void *s2) {
139         message_summary *summ1;
140         message_summary *summ2;
141         
142         summ1 = (message_summary *)GetSearchPayload(s1);
143         summ2 = (message_summary *)GetSearchPayload(s2);
144         return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from));
145 }
146
147 /*
148  * qsort() compatible function to compare two message summary structs by ascending date.
149  */
150 int summcmp_date(const void *s1, const void *s2) {
151         message_summary *summ1;
152         message_summary *summ2;
153         
154         summ1 = (message_summary *)GetSearchPayload(s1);
155         summ2 = (message_summary *)GetSearchPayload(s2);
156
157         if (summ1->date < summ2->date) return -1;
158         else if (summ1->date > summ2->date) return +1;
159         else return 0;
160 }
161
162 /*
163  * qsort() compatible function to compare two message summary structs by descending date.
164  */
165 int summcmp_rdate(const void *s1, const void *s2) {
166         message_summary *summ1;
167         message_summary *summ2;
168         
169         summ1 = (message_summary *)GetSearchPayload(s1);
170         summ2 = (message_summary *)GetSearchPayload(s2);
171
172         if (summ1->date < summ2->date) return +1;
173         else if (summ1->date > summ2->date) return -1;
174         else return 0;
175 }
176
177 /*----------------------------------------------------------------------------*/
178
179
180
181
182 void examine_nhdr(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
183 {
184         Msg->nhdr = 0;
185         if (!strncasecmp(ChrPtr(HdrLine), "yes", 8))
186                 Msg->nhdr = 1;
187 }
188 int Conditional_ANONYMOUS_MESSAGE(WCTemplateToken *Tokens, void *Context, int ContextType)
189 {
190         message_summary *Msg = (message_summary*) Context;
191         return Msg->nhdr != 0;
192 }
193
194
195 void examine_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
196 {
197         Msg->format_type = StrToi(HdrLine);
198                         
199 }
200
201 void examine_from(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
202 {
203         FreeStrBuf(&Msg->from);
204         Msg->from = NewStrBufPlain(NULL, StrLength(HdrLine));
205         StrBuf_RFC822_to_Utf8(Msg->from, HdrLine, WC->DefaultCharset, FoundCharset);
206 }
207 void tmplput_MAIL_SUMM_FROM(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
208 {
209         message_summary *Msg = (message_summary*) Context;
210         StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Msg->from, 0);
211 }
212
213
214
215 void examine_subj(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
216 {
217         FreeStrBuf(&Msg->subj);
218         Msg->subj = NewStrBufPlain(NULL, StrLength(HdrLine));
219         StrBuf_RFC822_to_Utf8(Msg->subj, HdrLine, WC->DefaultCharset, FoundCharset);
220 }
221 void tmplput_MAIL_SUMM_SUBJECT(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
222 {/////TODO: Fwd: and RE: filter!!
223         message_summary *Msg = (message_summary*) Context;
224         StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Msg->subj, 0);
225 }
226
227
228 void examine_msgn(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
229 {
230         FreeStrBuf(&Msg->reply_inreplyto);
231         Msg->reply_inreplyto = NewStrBufPlain(NULL, StrLength(HdrLine));
232         StrBuf_RFC822_to_Utf8(Msg->reply_inreplyto, HdrLine, WC->DefaultCharset, FoundCharset);
233 }
234 void tmplput_MAIL_SUMM_INREPLYTO(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
235 {
236         message_summary *Msg = (message_summary*) Context;
237         StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Msg->reply_inreplyto, 0);
238 }
239
240 int Conditional_MAIL_SUMM_UNREAD(WCTemplateToken *Tokens, void *Context, int ContextType)
241 {
242         message_summary *Msg = (message_summary*) Context;
243         return Msg->is_new != 0;
244 }
245
246 void examine_wefw(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
247 {
248         FreeStrBuf(&Msg->reply_references);
249         Msg->reply_references = NewStrBufPlain(NULL, StrLength(HdrLine));
250         StrBuf_RFC822_to_Utf8(Msg->reply_references, HdrLine, WC->DefaultCharset, FoundCharset);
251 }
252 void tmplput_MAIL_SUMM_REFIDS(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
253 {
254         message_summary *Msg = (message_summary*) Context;
255         StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Msg->reply_references, 0);
256 }
257
258
259 void examine_cccc(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
260 {
261         FreeStrBuf(&Msg->cccc);
262         Msg->cccc = NewStrBufPlain(NULL, StrLength(HdrLine));
263         StrBuf_RFC822_to_Utf8(Msg->cccc, HdrLine, WC->DefaultCharset, FoundCharset);
264         if (Msg->AllRcpt == NULL)
265                 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
266         if (StrLength(Msg->AllRcpt) > 0) {
267                 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
268         }
269         StrBufAppendBuf(Msg->AllRcpt, Msg->cccc, 0);
270 }
271 void tmplput_MAIL_SUMM_CCCC(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
272 {
273         message_summary *Msg = (message_summary*) Context;
274         StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Msg->cccc, 0);
275 }
276
277
278
279
280 void examine_room(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
281 {
282         if ((StrLength(HdrLine) > 0) &&
283             (strcasecmp(ChrPtr(HdrLine), WC->wc_roomname))) {
284                 FreeStrBuf(&Msg->Room);
285                 Msg->Room = NewStrBufDup(HdrLine);              
286         }
287 }
288 void tmplput_MAIL_SUMM_ORGROOM(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
289 {
290         message_summary *Msg = (message_summary*) Context;
291         StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Msg->Room, 0);
292 }
293
294
295 void examine_rfca(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
296 {
297         FreeStrBuf(&Msg->Rfca);
298         Msg->Rfca = NewStrBufDup(HdrLine);
299 }
300 void tmplput_MAIL_SUMM_RFCA(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
301 {
302         message_summary *Msg = (message_summary*) Context;
303         StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Msg->Rfca, 0);
304 }
305 int Conditional_MAIL_SUMM_RFCA(WCTemplateToken *Tokens, void *Context, int ContextType)
306 {
307         message_summary *Msg = (message_summary*) Context;
308         return StrLength(Msg->Rfca) > 0;
309 }
310
311 void examine_node(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
312 {
313         if ( (StrLength(HdrLine) > 0) &&
314              ((WC->room_flags & QR_NETWORK)
315               || ((strcasecmp(ChrPtr(HdrLine), serv_info.serv_nodename)
316                    && (strcasecmp(ChrPtr(HdrLine), serv_info.serv_fqdn)))))) {
317                 FreeStrBuf(&Msg->OtherNode);
318                 Msg->OtherNode = NewStrBufDup(HdrLine);
319         }
320 }
321 void tmplput_MAIL_SUMM_OTHERNODE(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
322 {
323         message_summary *Msg = (message_summary*) Context;
324         StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Msg->OtherNode, 0);
325 }
326 int Conditional_MAIL_SUMM_OTHERNODE(WCTemplateToken *Tokens, void *Context, int ContextType)
327 {
328         message_summary *Msg = (message_summary*) Context;
329         return StrLength(Msg->OtherNode) > 0;
330 }
331
332
333 void examine_rcpt(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
334 {
335         FreeStrBuf(&Msg->to);
336         Msg->to = NewStrBufPlain(NULL, StrLength(HdrLine));
337         StrBuf_RFC822_to_Utf8(Msg->to, HdrLine, WC->DefaultCharset, FoundCharset);
338         if (Msg->AllRcpt == NULL)
339                 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
340         if (StrLength(Msg->AllRcpt) > 0) {
341                 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
342         }
343         StrBufAppendBuf(Msg->AllRcpt, Msg->to, 0);
344 }
345 void tmplput_MAIL_SUMM_TO(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
346 {
347         message_summary *Msg = (message_summary*) Context;
348         StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Msg->to, 0);
349 }
350 void tmplput_MAIL_SUMM_ALLRCPT(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
351 {
352         message_summary *Msg = (message_summary*) Context;
353         StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Msg->AllRcpt, 0);
354 }
355
356
357
358 void examine_time(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
359 {
360         Msg->date = StrTol(HdrLine);
361 }
362 void tmplput_MAIL_SUMM_DATE_STR(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
363 {
364         char datebuf[64];
365         message_summary *Msg = (message_summary*) Context;
366         webcit_fmt_date(datebuf, Msg->date, 1);
367         StrBufAppendBufPlain(Target, datebuf, -1, 0);
368 }
369 void tmplput_MAIL_SUMM_DATE_NO(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
370 {
371         message_summary *Msg = (message_summary*) Context;
372         StrBufAppendPrintf(Target, "%ld", Msg->date, 0);
373 }
374
375
376
377 void render_MAIL(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
378 {
379         Mime->Data = NewStrBufPlain(NULL, Mime->length);
380         read_message(Mime->Data, HKEY("view_submessage"), Mime->msgnum, 0, Mime->PartNum);
381 /*
382         if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
383                 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
384                         extract_token(buf, mime_submessages, i, '|', sizeof buf);
385                         /** use printable_view to suppress buttons * /
386                         wprintf("<blockquote>");
387                         read_message(Mime->msgnum, 1, ChrPtr(Mime->Section));
388                         wprintf("</blockquote>");
389                 }
390         }
391 */
392 }
393
394 void render_MIME_VCard(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
395 {
396         MimeLoadData(Mime);
397         if (StrLength(Mime->Data) > 0) {
398                 StrBuf *Buf;
399                 Buf = NewStrBuf();
400                 /** If it's my vCard I can edit it */
401                 if (    (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
402                         || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
403                         || (WC->wc_view == VIEW_ADDRESSBOOK)
404                         ) {
405                         StrBufAppendPrintf(Buf, "<a href=\"edit_vcard?msgnum=%ld&partnum=%s\">",
406                                 Mime->msgnum, ChrPtr(Mime->PartNum));
407                         StrBufAppendPrintf(Buf, "[%s]</a>", _("edit"));
408                 }
409
410                 /* In all cases, display the full card */
411                 display_vcard(Buf, ChrPtr(Mime->Data), 0, 1, NULL, Mime->msgnum);
412                 FreeStrBuf(&Mime->Data);
413                 Mime->Data = Buf;
414         }
415
416 }
417 void render_MIME_ICS(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
418 {
419         MimeLoadData(Mime);
420         if (StrLength(Mime->Data) > 0) {
421                 cal_process_attachment(Mime);
422         }
423 }
424
425
426
427 void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
428 {
429         wc_mime_attachment *Mime;
430         StrBuf *Buf;
431         
432         Mime = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
433         memset(Mime, 0, sizeof(wc_mime_attachment));
434         Mime->msgnum = Msg->msgnum;
435         Buf = NewStrBuf();
436
437         Mime->Name = NewStrBuf();
438         StrBufExtract_token(Buf, HdrLine, 0, '|');
439         StrBuf_RFC822_to_Utf8(Mime->Name, Buf, WC->DefaultCharset, FoundCharset);
440         StrBufTrim(Mime->Name);
441
442         StrBufExtract_token(Buf, HdrLine, 1, '|');
443         Mime->FileName = NewStrBuf();
444         StrBuf_RFC822_to_Utf8(Mime->FileName, Buf, WC->DefaultCharset, FoundCharset);
445         StrBufTrim(Mime->FileName);
446
447         Mime->PartNum = NewStrBuf();
448         StrBufExtract_token(Mime->PartNum, HdrLine, 2, '|');
449         StrBufTrim(Mime->PartNum);
450         if (strchr(ChrPtr(Mime->PartNum), '.') != NULL)
451                 Mime->level = 2;
452         else
453                 Mime->level = 1;
454
455         Mime->Disposition = NewStrBuf();
456         StrBufExtract_token(Mime->Disposition, HdrLine, 3, '|');
457
458         Mime->ContentType = NewStrBuf();
459         StrBufExtract_token(Mime->ContentType, HdrLine, 4, '|');
460         StrBufTrim(Mime->ContentType);
461         StrBufLowerCase(Mime->ContentType);
462
463         Mime->length = StrBufExtract_int(HdrLine, 5, '|');
464
465         if ( (StrLength(Mime->FileName) == 0) && (StrLength(Mime->Name) > 0) ) {
466                 StrBufAppendBuf(Mime->FileName, Mime->Name, 0);
467         }
468
469         if (StrLength(Msg->PartNum) > 0) {
470                 StrBuf *tmp;
471                 StrBufPrintf(Buf, "%s.%s", ChrPtr(Msg->PartNum), ChrPtr(Mime->PartNum));
472                 tmp = Mime->PartNum;
473                 Mime->PartNum = Buf;
474                 Buf = tmp;
475         }
476
477         if (Msg->AllAttach == NULL)
478                 Msg->AllAttach = NewHash(1,NULL);
479         Put(Msg->AllAttach, SKEY(Mime->PartNum), Mime, DestroyMime);
480         FreeStrBuf(&Buf);
481 }
482
483
484 void evaluate_mime_part(message_summary *Msg, wc_mime_attachment *Mime)
485 {
486         void *vMimeRenderer;
487
488         /* just print the root-node */
489         if ((Mime->level == 1) &&
490             GetHash(MimeRenderHandler, SKEY(Mime->ContentType), &vMimeRenderer) &&
491             vMimeRenderer != NULL)
492         {
493                 Mime->Renderer = (RenderMimeFunc) vMimeRenderer;
494                 if (Msg->Submessages == NULL)
495                         Msg->Submessages = NewHash(1,NULL);
496                 Put(Msg->Submessages, SKEY(Mime->PartNum), Mime, reference_free_handler);
497         }
498         else if ((Mime->level == 1) &&
499                  (!strcasecmp(ChrPtr(Mime->Disposition), "inline"))
500                  && (!strncasecmp(ChrPtr(Mime->ContentType), "image/", 6)) ){
501                 if (Msg->AttachLinks == NULL)
502                         Msg->AttachLinks = NewHash(1,NULL);
503                 Put(Msg->AttachLinks, SKEY(Mime->PartNum), Mime, reference_free_handler);
504         }
505         else if ((Mime->level == 1) &&
506                  (StrLength(Mime->ContentType) > 0) &&
507                   ( (!strcasecmp(ChrPtr(Mime->Disposition), "attachment")) 
508                     || (!strcasecmp(ChrPtr(Mime->Disposition), "inline"))
509                     || (!strcasecmp(ChrPtr(Mime->Disposition), ""))))
510         {               
511                 if (Msg->AttachLinks == NULL)
512                         Msg->AttachLinks = NewHash(1,NULL);
513                 Put(Msg->AttachLinks, SKEY(Mime->PartNum), Mime, reference_free_handler);
514                 if ((strcasecmp(ChrPtr(Mime->ContentType), "application/octet-stream") == 0) && 
515                     (StrLength(Mime->FileName) > 0)) {
516                         FlushStrBuf(Mime->ContentType);
517                         StrBufAppendBufPlain(Mime->ContentType,
518                                              GuessMimeByFilename(SKEY(Mime->FileName)),
519                                              -1, 0);
520                 }
521         }
522 }
523
524 void tmplput_MAIL_SUMM_NATTACH(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
525 {
526         message_summary *Msg = (message_summary*) Context;
527         StrBufAppendPrintf(Target, "%ld", GetCount(Msg->Attachments));
528 }
529
530
531
532
533
534
535
536 void examine_hnod(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
537 {
538         FreeStrBuf(&Msg->hnod);
539         Msg->hnod = NewStrBufPlain(NULL, StrLength(HdrLine));
540         StrBuf_RFC822_to_Utf8(Msg->hnod, HdrLine, WC->DefaultCharset, FoundCharset);
541 }
542 void tmplput_MAIL_SUMM_H_NODE(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
543 {
544         message_summary *Msg = (message_summary*) Context;
545         StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Msg->hnod, 0);
546 }
547 int Conditional_MAIL_SUMM_H_NODE(WCTemplateToken *Tokens, void *Context, int ContextType)
548 {
549         message_summary *Msg = (message_summary*) Context;
550         return StrLength(Msg->hnod) > 0;
551 }
552
553
554
555 void examine_text(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
556 {
557         Msg->MsgBody->Data = NewStrBuf();
558 }
559
560 void examine_msg4_partnum(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
561 {
562         Msg->MsgBody->PartNum = NewStrBufDup(HdrLine);
563         StrBufTrim(Msg->MsgBody->PartNum);/////TODO: striplt == trim?
564 }
565
566 void examine_content_encoding(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
567 {
568 ////TODO: do we care?
569 }
570
571 void examine_content_lengh(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
572 {
573         Msg->MsgBody->length = StrTol(HdrLine);
574         Msg->MsgBody->size_known = 1;
575 }
576
577 void examine_content_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
578 {
579         void *vHdr;
580         headereval *Hdr;
581         StrBuf *Token;
582         StrBuf *Value;
583         const char* sem;
584         const char *eq;
585         int len;
586         StrBufTrim(HdrLine);
587         Msg->MsgBody->ContentType = NewStrBufDup(HdrLine);
588         sem = strchr(ChrPtr(HdrLine), ';');
589
590         if (sem != NULL) {
591                 Token = NewStrBufPlain(NULL, StrLength(HdrLine));
592                 Value = NewStrBufPlain(NULL, StrLength(HdrLine));
593                 len = sem - ChrPtr(HdrLine);
594                 StrBufCutAt(Msg->MsgBody->ContentType, len, NULL);
595                 while (sem != NULL) {
596                         while (isspace(*(sem + 1)))
597                                 sem ++;
598                         StrBufCutLeft(HdrLine, sem - ChrPtr(HdrLine));
599                         sem = strchr(ChrPtr(HdrLine), ';');
600                         if (sem != NULL)
601                                 len = sem - ChrPtr(HdrLine);
602                         else
603                                 len = StrLength(HdrLine);
604                         FlushStrBuf(Token);
605                         FlushStrBuf(Value);
606                         StrBufAppendBufPlain(Token, ChrPtr(HdrLine), len, 0);
607                         eq = strchr(ChrPtr(Token), '=');
608                         if (eq != NULL) {
609                                 len = eq - ChrPtr(Token);
610                                 StrBufAppendBufPlain(Value, eq + 1, StrLength(Token) - len - 1, 0); 
611                                 StrBufCutAt(Token, len, NULL);
612                                 StrBufTrim(Value);
613                         }
614                         StrBufTrim(Token);
615
616                         if (GetHash(MsgHeaderHandler, SKEY(Token), &vHdr) &&
617                             (vHdr != NULL)) {
618                                 Hdr = (headereval*)vHdr;
619                                 Hdr->evaluator(Msg, Value, FoundCharset);
620                         }
621                         else lprintf(1, "don't know how to handle content type sub-header[%s]\n", ChrPtr(Token));
622                 }
623                 FreeStrBuf(&Token);
624                 FreeStrBuf(&Value);
625         }
626 }
627
628 void tmplput_MAIL_SUMM_N(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
629 {
630         message_summary *Msg = (message_summary*) Context;
631         StrBufAppendPrintf(Target, "%ld", Msg->msgnum);
632 }
633
634
635
636 int Conditional_MAIL_MIME_ALL(WCTemplateToken *Tokens, void *Context, int ContextType)
637 {
638         message_summary *Msg = (message_summary*) Context;
639         return GetCount(Msg->Attachments) > 0;
640 }
641
642 int Conditional_MAIL_MIME_SUBMESSAGES(WCTemplateToken *Tokens, void *Context, int ContextType)
643 {
644         message_summary *Msg = (message_summary*) Context;
645         return GetCount(Msg->Submessages) > 0;
646 }
647
648 int Conditional_MAIL_MIME_ATTACHLINKS(WCTemplateToken *Tokens, void *Context, int ContextType)
649 {
650         message_summary *Msg = (message_summary*) Context;
651         return GetCount(Msg->AttachLinks) > 0;
652 }
653
654 int Conditional_MAIL_MIME_ATTACH(WCTemplateToken *Tokens, void *Context, int ContextType)
655 {
656         message_summary *Msg = (message_summary*) Context;
657         return GetCount(Msg->AllAttach) > 0;
658 }
659
660
661
662 /*----------------------------------------------------------------------------*/
663 void tmplput_QUOTED_MAIL_BODY(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
664 {
665         long MsgNum;
666         StrBuf *Buf;
667
668         MsgNum = LBstr(Tokens->Params[0]->Start, Tokens->Params[0]->len);
669         Buf = NewStrBuf();
670         read_message(Buf, HKEY("view_message_replyquote"), MsgNum, 0, NULL);
671         StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Buf, 1);
672         FreeStrBuf(&Buf);
673 }
674
675 void tmplput_MAIL_BODY(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
676 {
677         message_summary *Msg = (message_summary*) Context;
678         StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, Msg->MsgBody->Data, 0);
679 }
680
681
682 void render_MAIL_variformat(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
683 {
684         /* Messages in legacy Citadel variformat get handled thusly... */
685         StrBuf *Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
686         FmOut(Target, "JUSTIFY", Mime->Data);
687         FreeStrBuf(&Mime->Data);
688         Mime->Data = Target;
689 }
690
691 void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
692 {
693         StrBuf *cs = NULL;
694         const char *ptr, *pte;
695         const char *BufPtr = NULL;
696         StrBuf *Line;
697         StrBuf *Line1;
698         StrBuf *Line2;
699         StrBuf *Target;
700
701         int ConvertIt = 1;
702         int bn = 0;
703         int bq = 0;
704         int i, n, done = 0;
705         long len;
706 #ifdef HAVE_ICONV
707         iconv_t ic = (iconv_t)(-1) ;
708 #endif
709
710         if ((StrLength(Mime->Data) == 0) && (Mime->length > 0)) {
711                 FreeStrBuf(&Mime->Data);
712                 Mime->Data = NewStrBufPlain(NULL, Mime->length);
713                 if (!read_message(Mime->Data, HKEY("view_submessage"), Mime->msgnum, 0, Mime->PartNum))
714                         return;
715         }
716
717         /* Boring old 80-column fixed format text gets handled this way... */
718         if ((strcasecmp(ChrPtr(Mime->Charset), "us-ascii") == 0) &&
719             (strcasecmp(ChrPtr(Mime->Charset), "UTF-8") == 0))
720                 ConvertIt = 0;
721
722 #ifdef HAVE_ICONV
723         if (ConvertIt) {
724                 if (StrLength(Mime->Charset) != 0)
725                         cs = Mime->Charset;
726                 else if (StrLength(FoundCharset) > 0)
727                         cs = FoundCharset;
728                 else if (StrLength(WC->DefaultCharset) > 0)
729                         cs = WC->DefaultCharset;
730                 if (cs == NULL) {
731                         ConvertIt = 0;
732                 }
733                 else {
734                         ctdl_iconv_open("UTF-8", ChrPtr(cs), &ic);
735                         if (ic == (iconv_t)(-1) ) {
736                                 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
737                                         __FILE__, __LINE__, ChrPtr(Mime->Charset), strerror(errno));
738                         }
739                 }
740         }
741 #endif
742         Line = NewStrBuf();
743         Line1 = NewStrBuf();
744         Line2 = NewStrBuf();
745         Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
746
747         while ((n = StrBufSipLine(Line, Mime->Data, &BufPtr), n >= 0) && !done)
748         {
749                 done = n == 0;
750                 bq = 0;
751                 i = 0;
752                 ptr = ChrPtr(Line);
753                 len = StrLength(Line);
754                 pte = ptr + len;
755                 
756                 while ((ptr < pte) &&
757                        ((*ptr == '>') ||
758                         isspace(*ptr)))
759                 {
760                         if (*ptr == '>')
761                                 bq++;
762                         ptr ++;
763                         i++;
764                 }
765                 if (i > 0) StrBufCutLeft(Line, i);
766                 
767                 if (StrLength(Line) == 0)
768                         continue;
769
770                 for (i = bn; i < bq; i++)                               
771                         StrBufAppendBufPlain(Target, HKEY("<blockquote>"), 0);
772                 for (i = bq; i < bn; i++)                               
773                         StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
774
775                 if (ConvertIt == 1) {
776                         StrBufConvert(Line, Line1, &ic);
777                 }
778
779                 StrBufAppendBufPlain(Target, HKEY("<tt>"), 0);
780                 UrlizeText(Line1, Line, Line2);
781
782                 StrEscAppend(Target, Line1, NULL, 0, 0);
783                 StrBufAppendBufPlain(Target, HKEY("</tt><br />\n"), 0);
784                 bn = bq;
785         }
786
787         for (i = 0; i < bn; i++)                                
788                 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
789
790         StrBufAppendBufPlain(Target, HKEY("</i><br />"), 0);
791 #ifdef HAVE_ICONV
792         if (ic != (iconv_t)(-1) ) {
793                 iconv_close(ic);
794         }
795 #endif
796         FreeStrBuf(&Mime->Data);
797         Mime->Data = Target;
798         FreeStrBuf(&Line);
799         FreeStrBuf(&Line1);
800         FreeStrBuf(&Line2);
801 }
802
803 void render_MAIL_html(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
804 {
805         StrBuf *Buf;
806         /* HTML is fun, but we've got to strip it first */
807         if (StrLength(Mime->Data) == 0)
808                 return;
809
810         Buf = NewStrBufPlain(NULL, StrLength(Mime->Data));
811
812         output_html(ChrPtr(Mime->Charset), 
813                     (WC->wc_view == VIEW_WIKI ? 1 : 0), 
814                     StrToi(Mime->PartNum), 
815                     Mime->Data, Buf);
816         FreeStrBuf(&Mime->Data);
817         Mime->Data = Buf;
818 }
819
820 void render_MAIL_UNKNOWN(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
821 {
822         /* Unknown weirdness */
823         FlushStrBuf(Mime->Data);
824         StrBufAppendBufPlain(Mime->Data, _("I don't know how to display "), -1, 0);
825         StrBufAppendBuf(Mime->Data, Mime->ContentType, 0);
826         StrBufAppendBufPlain(Mime->Data, HKEY("<br />\n"), 0);
827 }
828
829
830
831
832
833
834 HashList *iterate_get_mime_All(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
835 {
836         message_summary *Msg = (message_summary*) Context;
837         return Msg->Attachments;
838 }
839 HashList *iterate_get_mime_Submessages(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
840 {
841         message_summary *Msg = (message_summary*) Context;
842         return Msg->Submessages;
843 }
844 HashList *iterate_get_mime_AttachLinks(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
845 {
846         message_summary *Msg = (message_summary*) Context;
847         return Msg->AttachLinks;
848 }
849 HashList *iterate_get_mime_Attachments(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
850 {
851         message_summary *Msg = (message_summary*) Context;
852         return Msg->AllAttach;
853 }
854
855 void tmplput_MIME_Name(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
856 {
857         wc_mime_attachment *mime = (wc_mime_attachment*) Context;
858         StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, mime->Name, 0);
859 }
860
861 void tmplput_MIME_FileName(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
862 {
863         wc_mime_attachment *mime = (wc_mime_attachment*) Context;
864         StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, mime->FileName, 0);
865 }
866
867 void tmplput_MIME_PartNum(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
868 {
869         wc_mime_attachment *mime = (wc_mime_attachment*) Context;
870         StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, mime->PartNum, 0);
871 }
872
873 void tmplput_MIME_MsgNum(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
874 {
875         wc_mime_attachment *mime = (wc_mime_attachment*) Context;
876         StrBufAppendPrintf(Target, "%ld", mime->msgnum);
877 }
878
879 void tmplput_MIME_Disposition(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
880 {
881         wc_mime_attachment *mime = (wc_mime_attachment*) Context;
882         StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, mime->Disposition, 0);
883 }
884
885 void tmplput_MIME_ContentType(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
886 {
887         wc_mime_attachment *mime = (wc_mime_attachment*) Context;
888         StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, mime->ContentType, 0);
889 }
890
891 void examine_charset(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
892 {
893         Msg->MsgBody->Charset = NewStrBufDup(HdrLine);
894 }
895
896 void tmplput_MIME_Charset(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
897 {
898         wc_mime_attachment *mime = (wc_mime_attachment*) Context;
899         StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, mime->Charset, 0);
900 }
901
902 void tmplput_MIME_Data(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
903 {
904         wc_mime_attachment *mime = (wc_mime_attachment*) Context;
905         if (mime->Renderer != NULL)
906                 mime->Renderer(mime, NULL, NULL);
907         StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, mime->Data, 0);
908  /// TODO: check whether we need to load it now?
909 }
910
911 void tmplput_MIME_Length(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
912 {
913         wc_mime_attachment *mime = (wc_mime_attachment*) Context;
914         StrBufAppendPrintf(Target, "%ld", mime->length);
915 }
916
917 HashList *iterate_get_registered_Attachments(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
918 {
919         return WC->attachments;
920 }
921
922 void tmplput_ATT_Length(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
923 {
924         wc_attachment *att = (wc_attachment*) Context;
925         StrBufAppendPrintf(Target, "%ld", att->length);
926 }
927
928 void tmplput_ATT_Contenttype(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
929 {
930         wc_attachment *att = (wc_attachment*) Context;
931         StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, att->content_type, 0);
932 }
933
934 void tmplput_ATT_FileName(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
935 {
936         wc_attachment *att = (wc_attachment*) Context;
937         StrBufAppendTemplate(Target, nArgs, Tokens, Context, ContextType, att->filename, 0);
938 }
939
940
941
942
943 void 
944 InitModule_MSGRENDERERS
945 (void)
946 {
947         RegisterSortFunc(HKEY("date"), 
948                          NULL, 0,
949                          summcmp_date,
950                          summcmp_rdate,
951                          CTX_MAILSUM);
952         RegisterSortFunc(HKEY("subject"), 
953                          NULL, 0,
954                          summcmp_subj,
955                          summcmp_rsubj,
956                          CTX_MAILSUM);
957         RegisterSortFunc(HKEY("sender"),
958                          NULL, 0,
959                          summcmp_sender,
960                          summcmp_rsender,
961                          CTX_MAILSUM);
962
963         RegisterNamespace("MAIL:SUMM:DATESTR", 0, 0, tmplput_MAIL_SUMM_DATE_STR, CTX_MAILSUM);
964         RegisterNamespace("MAIL:SUMM:DATENO",  0, 0, tmplput_MAIL_SUMM_DATE_NO,  CTX_MAILSUM);
965         RegisterNamespace("MAIL:SUMM:N",       0, 0, tmplput_MAIL_SUMM_N,        CTX_MAILSUM);
966         RegisterNamespace("MAIL:SUMM:FROM",    0, 2, tmplput_MAIL_SUMM_FROM,     CTX_MAILSUM);
967         RegisterNamespace("MAIL:SUMM:TO",      0, 2, tmplput_MAIL_SUMM_TO,       CTX_MAILSUM);
968         RegisterNamespace("MAIL:SUMM:SUBJECT", 0, 4, tmplput_MAIL_SUMM_SUBJECT,  CTX_MAILSUM);
969         RegisterNamespace("MAIL:SUMM:NTATACH", 0, 0, tmplput_MAIL_SUMM_NATTACH,  CTX_MAILSUM);
970         RegisterNamespace("MAIL:SUMM:CCCC", 0, 2, tmplput_MAIL_SUMM_CCCC,  CTX_MAILSUM);
971         RegisterNamespace("MAIL:SUMM:H_NODE", 0, 2, tmplput_MAIL_SUMM_H_NODE,  CTX_MAILSUM);
972         RegisterNamespace("MAIL:SUMM:ALLRCPT", 0, 2, tmplput_MAIL_SUMM_ALLRCPT,  CTX_MAILSUM);
973         RegisterNamespace("MAIL:SUMM:ORGROOM", 0, 2, tmplput_MAIL_SUMM_ORGROOM,  CTX_MAILSUM);
974         RegisterNamespace("MAIL:SUMM:RFCA", 0, 2, tmplput_MAIL_SUMM_RFCA,  CTX_MAILSUM);
975         RegisterNamespace("MAIL:SUMM:OTHERNODE", 2, 0, tmplput_MAIL_SUMM_OTHERNODE,  CTX_MAILSUM);
976         RegisterNamespace("MAIL:SUMM:REFIDS", 0, 0, tmplput_MAIL_SUMM_REFIDS,  CTX_MAILSUM);
977         RegisterNamespace("MAIL:SUMM:INREPLYTO", 0, 2, tmplput_MAIL_SUMM_INREPLYTO,  CTX_MAILSUM);
978         RegisterNamespace("MAIL:BODY", 0, 2, tmplput_MAIL_BODY,  CTX_MAILSUM);
979         RegisterNamespace("MAIL:QUOTETEXT", 1, 2, tmplput_QUOTED_MAIL_BODY,  CTX_NONE);
980         RegisterNamespace("ATT:SIZE", 0, 1, tmplput_ATT_Length, CTX_ATT);
981         RegisterNamespace("ATT:TYPE", 0, 1, tmplput_ATT_Contenttype, CTX_ATT);
982         RegisterNamespace("ATT:FILENAME", 0, 1, tmplput_ATT_FileName, CTX_ATT);
983
984         RegisterConditional(HKEY("MAIL:SUMM:RFCA"), 0, Conditional_MAIL_SUMM_RFCA,  CTX_MAILSUM);
985         RegisterConditional(HKEY("COND:MAIL:SUMM:UNREAD"), 0, Conditional_MAIL_SUMM_UNREAD, CTX_MAILSUM);
986         RegisterConditional(HKEY("COND:MAIL:SUMM:H_NODE"), 0, Conditional_MAIL_SUMM_H_NODE, CTX_MAILSUM);
987         RegisterConditional(HKEY("COND:MAIL:SUMM:OTHERNODE"), 0, Conditional_MAIL_SUMM_OTHERNODE, CTX_MAILSUM);
988         RegisterConditional(HKEY("COND:MAIL:ANON"), 0, Conditional_ANONYMOUS_MESSAGE, CTX_MAILSUM);
989
990         RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH"), 0, Conditional_MAIL_MIME_ALL, CTX_MAILSUM);
991         RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:SUBMESSAGES"), 0, Conditional_MAIL_MIME_SUBMESSAGES, CTX_MAILSUM);
992         RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:LINKS"), 0, Conditional_MAIL_MIME_ATTACHLINKS, CTX_MAILSUM);
993         RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:ATT"), 0, Conditional_MAIL_MIME_ATTACH, CTX_MAILSUM);
994
995         RegisterIterator("MAIL:MIME:ATTACH", 0, NULL, iterate_get_mime_All, 
996                          NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM);
997         RegisterIterator("MAIL:MIME:ATTACH:SUBMESSAGES", 0, NULL, iterate_get_mime_Submessages, 
998                          NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM);
999         RegisterIterator("MAIL:MIME:ATTACH:LINKS", 0, NULL, iterate_get_mime_AttachLinks, 
1000                          NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM);
1001         RegisterIterator("MAIL:MIME:ATTACH:ATT", 0, NULL, iterate_get_mime_Attachments, 
1002                          NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM);
1003
1004         RegisterNamespace("MAIL:MIME:NAME", 0, 2, tmplput_MIME_Name, CTX_MIME_ATACH);
1005         RegisterNamespace("MAIL:MIME:FILENAME", 0, 2, tmplput_MIME_FileName, CTX_MIME_ATACH);
1006         RegisterNamespace("MAIL:MIME:PARTNUM", 0, 2, tmplput_MIME_PartNum, CTX_MIME_ATACH);
1007         RegisterNamespace("MAIL:MIME:MSGNUM", 0, 2, tmplput_MIME_MsgNum, CTX_MIME_ATACH);
1008         RegisterNamespace("MAIL:MIME:DISPOSITION", 0, 2, tmplput_MIME_Disposition, CTX_MIME_ATACH);
1009         RegisterNamespace("MAIL:MIME:CONTENTTYPE", 0, 2, tmplput_MIME_ContentType, CTX_MIME_ATACH);
1010         RegisterNamespace("MAIL:MIME:CHARSET", 0, 2, tmplput_MIME_Charset, CTX_MIME_ATACH);
1011         RegisterNamespace("MAIL:MIME:LENGTH", 0, 2, tmplput_MIME_Length, CTX_MIME_ATACH);
1012         RegisterNamespace("MAIL:MIME:DATA", 0, 2, tmplput_MIME_Data, CTX_MIME_ATACH);
1013
1014         RegisterIterator("MSG:ATTACHNAMES", 0, NULL, iterate_get_registered_Attachments, 
1015                          NULL, NULL, CTX_ATT, CTX_NONE);
1016
1017         RegisterMimeRenderer(HKEY("message/rfc822"), render_MAIL);
1018         RegisterMimeRenderer(HKEY("text/x-vcard"), render_MIME_VCard);
1019         RegisterMimeRenderer(HKEY("text/vcard"), render_MIME_VCard);
1020         RegisterMimeRenderer(HKEY("text/calendar"), render_MIME_ICS);
1021         RegisterMimeRenderer(HKEY("application/ics"), render_MIME_ICS);
1022
1023         RegisterMimeRenderer(HKEY("text/x-citadel-variformat"), render_MAIL_variformat);
1024         RegisterMimeRenderer(HKEY("text/plain"), render_MAIL_text_plain);
1025         RegisterMimeRenderer(HKEY("text"), render_MAIL_text_plain);
1026         RegisterMimeRenderer(HKEY("text/html"), render_MAIL_html);
1027         RegisterMimeRenderer(HKEY(""), render_MAIL_UNKNOWN);
1028
1029         RegisterMsgHdr(HKEY("nhdr"), examine_nhdr, 0);
1030         RegisterMsgHdr(HKEY("type"), examine_type, 0);
1031         RegisterMsgHdr(HKEY("from"), examine_from, 0);
1032         RegisterMsgHdr(HKEY("subj"), examine_subj, 0);
1033         RegisterMsgHdr(HKEY("msgn"), examine_msgn, 0);
1034         RegisterMsgHdr(HKEY("wefw"), examine_wefw, 0);
1035         RegisterMsgHdr(HKEY("cccc"), examine_cccc, 0);
1036         RegisterMsgHdr(HKEY("hnod"), examine_hnod, 0);
1037         RegisterMsgHdr(HKEY("room"), examine_room, 0);
1038         RegisterMsgHdr(HKEY("rfca"), examine_rfca, 0);
1039         RegisterMsgHdr(HKEY("node"), examine_node, 0);
1040         RegisterMsgHdr(HKEY("rcpt"), examine_rcpt, 0);
1041         RegisterMsgHdr(HKEY("time"), examine_time, 0);
1042         RegisterMsgHdr(HKEY("part"), examine_mime_part, 0);
1043         RegisterMsgHdr(HKEY("text"), examine_text, 1);
1044         RegisterMsgHdr(HKEY("X-Citadel-MSG4-Partnum"), examine_msg4_partnum, 0);
1045         RegisterMsgHdr(HKEY("Content-type"), examine_content_type, 0);
1046         RegisterMsgHdr(HKEY("Content-length"), examine_content_lengh, 0);
1047         RegisterMsgHdr(HKEY("Content-transfer-encoding"), examine_content_encoding, 0);
1048         RegisterMsgHdr(HKEY("charset"), examine_charset, 0);
1049 }