5 CtxType CTX_MAILSUM = CTX_NONE;
6 CtxType CTX_MIME_ATACH = CTX_NONE;
8 inline void CheckConvertBufs(struct wcsession *WCC)
10 if (WCC->ConvertBuf1 == NULL)
11 WCC->ConvertBuf1 = NewStrBuf();
12 if (WCC->ConvertBuf2 == NULL)
13 WCC->ConvertBuf2 = NewStrBuf();
17 * message index functions
21 void DestroyMimeParts(wc_mime_attachment *Mime)
23 FreeStrBuf(&Mime->Name);
24 FreeStrBuf(&Mime->FileName);
25 FreeStrBuf(&Mime->PartNum);
26 FreeStrBuf(&Mime->Disposition);
27 FreeStrBuf(&Mime->ContentType);
28 FreeStrBuf(&Mime->Charset);
29 FreeStrBuf(&Mime->Data);
32 void DestroyMime(void *vMime)
34 wc_mime_attachment *Mime = (wc_mime_attachment*)vMime;
35 DestroyMimeParts(Mime);
39 void DestroyMessageSummary(void *vMsg)
41 message_summary *Msg = (message_summary*) vMsg;
43 FreeStrBuf(&Msg->from);
45 FreeStrBuf(&Msg->subj);
46 FreeStrBuf(&Msg->reply_inreplyto);
47 FreeStrBuf(&Msg->reply_references);
48 FreeStrBuf(&Msg->cccc);
49 FreeStrBuf(&Msg->ReplyTo);
50 FreeStrBuf(&Msg->hnod);
51 FreeStrBuf(&Msg->AllRcpt);
52 FreeStrBuf(&Msg->Room);
53 FreeStrBuf(&Msg->Rfca);
54 FreeStrBuf(&Msg->OtherNode);
56 DeleteHash(&Msg->Attachments); /* list of Attachments */
57 DeleteHash(&Msg->Submessages);
58 DeleteHash(&Msg->AttachLinks);
59 DeleteHash(&Msg->AllAttach);
65 void RegisterMsgHdr(const char *HeaderName, long HdrNLen, ExamineMsgHeaderFunc evaluator, int type)
68 ev = (headereval*) malloc(sizeof(headereval));
69 ev->evaluator = evaluator;
71 Put(MsgHeaderHandler, HeaderName, HdrNLen, ev, NULL);
74 void RegisterMimeRenderer(const char *HeaderName, long HdrNLen,
75 RenderMimeFunc MimeRenderer,
79 RenderMimeFuncStruct *f;
81 f = (RenderMimeFuncStruct*) malloc(sizeof(RenderMimeFuncStruct));
83 Put(MimeRenderHandler, HeaderName, HdrNLen, f, NULL);
85 RegisterEmbeddableMimeType(HeaderName, HdrNLen, 10000 - Priority);
88 /*----------------------------------------------------------------------------*/
91 * comparator for two longs in descending order.
93 int longcmp_r(const void *s1, const void *s2) {
97 l1 = *(long *)GetSearchPayload(s1);
98 l2 = *(long *)GetSearchPayload(s2);
100 if (l1 > l2) return(-1);
101 if (l1 < l2) return(+1);
106 * comparator for longs; descending order.
108 int qlongcmp_r(const void *s1, const void *s2) {
112 if (l1 > l2) return(-1);
113 if (l1 < l2) return(+1);
119 * comparator for message summary structs by ascending subject.
121 int summcmp_subj(const void *s1, const void *s2) {
122 message_summary *summ1;
123 message_summary *summ2;
125 summ1 = (message_summary *)GetSearchPayload(s1);
126 summ2 = (message_summary *)GetSearchPayload(s2);
127 return strcasecmp(ChrPtr(summ1->subj), ChrPtr(summ2->subj));
131 * comparator for message summary structs by descending subject.
133 int summcmp_rsubj(const void *s1, const void *s2) {
134 message_summary *summ1;
135 message_summary *summ2;
137 summ1 = (message_summary *)GetSearchPayload(s1);
138 summ2 = (message_summary *)GetSearchPayload(s2);
139 return strcasecmp(ChrPtr(summ2->subj), ChrPtr(summ1->subj));
142 * comparator for message summary structs by descending subject.
144 int groupchange_subj(const void *s1, const void *s2) {
145 message_summary *summ1;
146 message_summary *summ2;
148 summ1 = (message_summary *)s1;
149 summ2 = (message_summary *)s2;
150 return ChrPtr(summ2->subj)[0] != ChrPtr(summ1->subj)[0];
154 * comparator for message summary structs by ascending sender.
156 int summcmp_sender(const void *s1, const void *s2) {
157 message_summary *summ1;
158 message_summary *summ2;
160 summ1 = (message_summary *)GetSearchPayload(s1);
161 summ2 = (message_summary *)GetSearchPayload(s2);
162 return strcasecmp(ChrPtr(summ1->from), ChrPtr(summ2->from));
166 * comparator for message summary structs by descending sender.
168 int summcmp_rsender(const void *s1, const void *s2) {
169 message_summary *summ1;
170 message_summary *summ2;
172 summ1 = (message_summary *)GetSearchPayload(s1);
173 summ2 = (message_summary *)GetSearchPayload(s2);
174 return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from));
177 * comparator for message summary structs by descending sender.
179 int groupchange_sender(const void *s1, const void *s2) {
180 message_summary *summ1;
181 message_summary *summ2;
183 summ1 = (message_summary *)s1;
184 summ2 = (message_summary *)s2;
185 return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from)) != 0;
190 * comparator for message summary structs by ascending date.
192 int summcmp_date(const void *s1, const void *s2) {
193 message_summary *summ1;
194 message_summary *summ2;
196 summ1 = (message_summary *)GetSearchPayload(s1);
197 summ2 = (message_summary *)GetSearchPayload(s2);
199 if (summ1->date < summ2->date) return -1;
200 else if (summ1->date > summ2->date) return +1;
205 * comparator for message summary structs by descending date.
207 int summcmp_rdate(const void *s1, const void *s2) {
208 message_summary *summ1;
209 message_summary *summ2;
211 summ1 = (message_summary *)GetSearchPayload(s1);
212 summ2 = (message_summary *)GetSearchPayload(s2);
214 if (summ1->date < summ2->date) return +1;
215 else if (summ1->date > summ2->date) return -1;
220 * comparator for message summary structs by descending date.
222 const long DAYSECONDS = 24 * 60 * 60;
223 int groupchange_date(const void *s1, const void *s2) {
224 message_summary *summ1;
225 message_summary *summ2;
227 summ1 = (message_summary *)s1;
228 summ2 = (message_summary *)s2;
230 return (summ1->date % DAYSECONDS) != (summ2->date %DAYSECONDS);
234 /*----------------------------------------------------------------------------*/
235 /* Don't wanna know... or? */
236 void examine_pref(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
237 void examine_suff(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
238 void examine_path(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
239 void examine_content_encoding(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
241 /* TODO: do we care? */
244 void examine_nhdr(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
247 if (!strncasecmp(ChrPtr(HdrLine), "yes", 8))
250 int Conditional_ANONYMOUS_MESSAGE(StrBuf *Target, WCTemplputParams *TP)
252 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
253 return Msg->nhdr != 0;
256 void examine_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
258 Msg->format_type = StrToi(HdrLine);
262 void examine_from(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
266 CheckConvertBufs(WCC);
267 FreeStrBuf(&Msg->from);
268 Msg->from = NewStrBufPlain(NULL, StrLength(HdrLine));
269 StrBuf_RFC822_2_Utf8(Msg->from,
276 void tmplput_MAIL_SUMM_FROM(StrBuf *Target, WCTemplputParams *TP)
278 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
279 StrBufAppendTemplate(Target, TP, Msg->from, 0);
282 void examine_subj(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
286 CheckConvertBufs(WCC);
287 FreeStrBuf(&Msg->subj);
288 Msg->subj = NewStrBufPlain(NULL, StrLength(HdrLine));
289 StrBuf_RFC822_2_Utf8(Msg->subj,
296 void tmplput_MAIL_SUMM_SUBJECT(StrBuf *Target, WCTemplputParams *TP)
298 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
300 if (TP->Tokens->nParameters == 4)
305 GetTemplateTokenString(Target, TP, 3, &pch, &len);
307 (strstr(ChrPtr(Msg->subj), pch) == NULL))
309 GetTemplateTokenString(Target, TP, 2, &pch, &len);
310 StrBufAppendBufPlain(Target, pch, len, 0);
313 StrBufAppendTemplate(Target, TP, Msg->subj, 0);
315 int Conditional_MAIL_SUMM_SUBJECT(StrBuf *Target, WCTemplputParams *TP)
317 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
320 return StrLength(Msg->subj) > 0;
324 void examine_msgn(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
328 CheckConvertBufs(WCC);
329 FreeStrBuf(&Msg->reply_inreplyto);
330 Msg->reply_inreplyto = NewStrBufPlain(NULL, StrLength(HdrLine));
331 StrBuf_RFC822_2_Utf8(Msg->reply_inreplyto,
338 void tmplput_MAIL_SUMM_INREPLYTO(StrBuf *Target, WCTemplputParams *TP)
340 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
341 StrBufAppendTemplate(Target, TP, Msg->reply_inreplyto, 0);
344 int Conditional_MAIL_SUMM_UNREAD(StrBuf *Target, WCTemplputParams *TP)
346 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
347 return (Msg->Flags & MSGFLAG_READ) != 0;
350 void examine_wefw(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
354 CheckConvertBufs(WCC);
355 FreeStrBuf(&Msg->reply_references);
356 Msg->reply_references = NewStrBufPlain(NULL, StrLength(HdrLine));
357 StrBuf_RFC822_2_Utf8(Msg->reply_references,
364 void tmplput_MAIL_SUMM_REFIDS(StrBuf *Target, WCTemplputParams *TP)
366 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
367 StrBufAppendTemplate(Target, TP, Msg->reply_references, 0);
370 void examine_replyto(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
374 CheckConvertBufs(WCC);
375 FreeStrBuf(&Msg->ReplyTo);
376 Msg->ReplyTo = NewStrBufPlain(NULL, StrLength(HdrLine));
377 StrBuf_RFC822_2_Utf8(Msg->ReplyTo,
383 if (Msg->AllRcpt == NULL)
384 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
385 if (StrLength(Msg->AllRcpt) > 0) {
386 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
388 StrBufAppendBuf(Msg->AllRcpt, Msg->ReplyTo, 0);
390 void tmplput_MAIL_SUMM_REPLYTO(StrBuf *Target, WCTemplputParams *TP)
392 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
393 StrBufAppendTemplate(Target, TP, Msg->ReplyTo, 0);
396 void examine_cccc(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
400 CheckConvertBufs(WCC);
401 FreeStrBuf(&Msg->cccc);
402 Msg->cccc = NewStrBufPlain(NULL, StrLength(HdrLine));
403 StrBuf_RFC822_2_Utf8(Msg->cccc,
409 if (Msg->AllRcpt == NULL)
410 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
411 if (StrLength(Msg->AllRcpt) > 0) {
412 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
414 StrBufAppendBuf(Msg->AllRcpt, Msg->cccc, 0);
416 void tmplput_MAIL_SUMM_CCCC(StrBuf *Target, WCTemplputParams *TP)
418 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
419 StrBufAppendTemplate(Target, TP, Msg->cccc, 0);
423 void examine_room(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
425 if ((StrLength(HdrLine) > 0) &&
426 (strcasecmp(ChrPtr(HdrLine), ChrPtr(WC->CurRoom.name)))) {
427 FreeStrBuf(&Msg->Room);
428 Msg->Room = NewStrBufDup(HdrLine);
431 void tmplput_MAIL_SUMM_ORGROOM(StrBuf *Target, WCTemplputParams *TP)
433 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
434 StrBufAppendTemplate(Target, TP, Msg->Room, 0);
438 void examine_rfca(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
440 FreeStrBuf(&Msg->Rfca);
441 Msg->Rfca = NewStrBufDup(HdrLine);
443 void tmplput_MAIL_SUMM_RFCA(StrBuf *Target, WCTemplputParams *TP)
445 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
446 StrBufAppendTemplate(Target, TP, Msg->Rfca, 0);
448 int Conditional_MAIL_SUMM_RFCA(StrBuf *Target, WCTemplputParams *TP)
450 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
451 return StrLength(Msg->Rfca) > 0;
453 int Conditional_MAIL_SUMM_CCCC(StrBuf *Target, WCTemplputParams *TP)
455 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
456 return StrLength(Msg->cccc) > 0;
458 int Conditional_MAIL_SUMM_REPLYTO(StrBuf *Target, WCTemplputParams *TP)
460 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
461 return StrLength(Msg->ReplyTo) > 0;
464 void examine_node(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
468 if ( (StrLength(HdrLine) > 0) &&
469 ((WC->CurRoom.QRFlags & QR_NETWORK)
470 || ((strcasecmp(ChrPtr(HdrLine), ChrPtr(WCC->serv_info->serv_nodename))
471 && (strcasecmp(ChrPtr(HdrLine), ChrPtr(WCC->serv_info->serv_fqdn))))))) {
472 FreeStrBuf(&Msg->OtherNode);
473 Msg->OtherNode = NewStrBufDup(HdrLine);
476 void tmplput_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP)
478 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
479 StrBufAppendTemplate(Target, TP, Msg->OtherNode, 0);
481 int Conditional_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP)
483 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
484 return StrLength(Msg->OtherNode) > 0;
488 void examine_rcpt(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
492 CheckConvertBufs(WCC);
493 FreeStrBuf(&Msg->to);
494 Msg->to = NewStrBufPlain(NULL, StrLength(HdrLine));
495 StrBuf_RFC822_2_Utf8(Msg->to,
501 if (Msg->AllRcpt == NULL)
502 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
503 if (StrLength(Msg->AllRcpt) > 0) {
504 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
506 StrBufAppendBuf(Msg->AllRcpt, Msg->to, 0);
508 void tmplput_MAIL_SUMM_TO(StrBuf *Target, WCTemplputParams *TP)
510 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
511 StrBufAppendTemplate(Target, TP, Msg->to, 0);
513 int Conditional_MAIL_SUMM_TO(StrBuf *Target, WCTemplputParams *TP)
515 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
516 return StrLength(Msg->to) != 0;
518 int Conditional_MAIL_SUMM_SUBJ(StrBuf *Target, WCTemplputParams *TP)
520 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
521 return StrLength(Msg->subj) != 0;
523 void tmplput_MAIL_SUMM_ALLRCPT(StrBuf *Target, WCTemplputParams *TP)
525 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
526 StrBufAppendTemplate(Target, TP, Msg->AllRcpt, 0);
531 void tmplput_SUMM_COUNT(StrBuf *Target, WCTemplputParams *TP)
533 StrBufAppendPrintf(Target, "%d", GetCount( WC->summ));
536 HashList *iterate_get_mailsumm_All(StrBuf *Target, WCTemplputParams *TP)
540 void examine_time(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
542 Msg->date = StrTol(HdrLine);
545 void tmplput_MAIL_SUMM_DATE_BRIEF(StrBuf *Target, WCTemplputParams *TP)
548 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
549 webcit_fmt_date(datebuf, 64, Msg->date, DATEFMT_BRIEF);
550 StrBufAppendBufPlain(Target, datebuf, -1, 0);
553 void tmplput_MAIL_SUMM_EUID(StrBuf *Target, WCTemplputParams *TP)
555 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
556 StrBufAppendTemplate(Target, TP, Msg->euid, 0);
559 void tmplput_MAIL_SUMM_DATE_FULL(StrBuf *Target, WCTemplputParams *TP)
562 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
563 webcit_fmt_date(datebuf, 64, Msg->date, DATEFMT_FULL);
564 StrBufAppendBufPlain(Target, datebuf, -1, 0);
566 void tmplput_MAIL_SUMM_DATE_NO(StrBuf *Target, WCTemplputParams *TP)
568 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
569 StrBufAppendPrintf(Target, "%ld", Msg->date, 0);
574 void render_MAIL(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
576 const StrBuf *TemplateMime;
578 if (Mime->Data == NULL)
579 Mime->Data = NewStrBufPlain(NULL, Mime->length);
581 FlushStrBuf(Mime->Data);
582 read_message(Mime->Data, HKEY("view_submessage"), Mime->msgnum, Mime->PartNum, &TemplateMime);
584 if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
585 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
586 extract_token(buf, mime_submessages, i, '|', sizeof buf);
587 / ** use printable_view to suppress buttons * /
588 wc_printf("<blockquote>");
589 read_message(Mime->msgnum, 1, ChrPtr(Mime->Section));
590 wc_printf("</blockquote>");
596 void render_MIME_VCard(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
599 if (StrLength(Mime->Data) == 0)
601 if (StrLength(Mime->Data) > 0) {
604 /** If it's my vCard I can edit it */
605 if ( (!strcasecmp(ChrPtr(WCC->CurRoom.name), USERCONFIGROOM))
606 || (!strcasecmp(&(ChrPtr(WCC->CurRoom.name)[11]), USERCONFIGROOM))
607 || (WC->CurRoom.view == VIEW_ADDRESSBOOK)
609 StrBufAppendPrintf(Buf, "<a href=\"edit_vcard?msgnum=%ld?partnum=%s\">",
610 Mime->msgnum, ChrPtr(Mime->PartNum));
611 StrBufAppendPrintf(Buf, "[%s]</a>", _("edit"));
614 /* In all cases, display the full card */
615 display_vcard(Buf, Mime, 0, 1, NULL, -1);
616 FreeStrBuf(&Mime->Data);
622 void render_MIME_ICS(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
624 if (StrLength(Mime->Data) == 0) {
627 if (StrLength(Mime->Data) > 0) {
628 cal_process_attachment(Mime);
634 void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
636 const char *Ptr = NULL;
637 wc_mime_attachment *Mime;
641 CheckConvertBufs(WCC);
642 Mime = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
643 memset(Mime, 0, sizeof(wc_mime_attachment));
644 Mime->msgnum = Msg->msgnum;
647 Mime->Name = NewStrBuf();
648 StrBufExtract_NextToken(Buf, HdrLine, &Ptr, '|');
649 StrBuf_RFC822_2_Utf8(Mime->Name,
655 StrBufTrim(Mime->Name);
657 StrBufExtract_NextToken(Buf, HdrLine, &Ptr, '|');
658 Mime->FileName = NewStrBuf();
659 StrBuf_RFC822_2_Utf8(Mime->FileName,
665 StrBufTrim(Mime->FileName);
667 Mime->PartNum = NewStrBuf();
668 StrBufExtract_NextToken(Mime->PartNum, HdrLine, &Ptr, '|');
669 StrBufTrim(Mime->PartNum);
670 if (strchr(ChrPtr(Mime->PartNum), '.') != NULL)
675 Mime->Disposition = NewStrBuf();
676 StrBufExtract_NextToken(Mime->Disposition, HdrLine, &Ptr, '|');
678 Mime->ContentType = NewStrBuf();
679 StrBufExtract_NextToken(Mime->ContentType, HdrLine, &Ptr, '|');
680 StrBufTrim(Mime->ContentType);
681 StrBufLowerCase(Mime->ContentType);
682 if (!strcmp(ChrPtr(Mime->ContentType), "application/octet-stream")) {
683 StrBufPlain(Mime->ContentType,
684 GuessMimeByFilename(SKEY(Mime->FileName)), -1);
687 Mime->length = StrBufExtractNext_int(HdrLine, &Ptr, '|');
689 StrBufSkip_NTokenS(HdrLine, &Ptr, '|', 1); /* cbid?? */
691 Mime->Charset = NewStrBuf();
692 StrBufExtract_NextToken(Mime->Charset, HdrLine, &Ptr, '|');
695 if ( (StrLength(Mime->FileName) == 0) && (StrLength(Mime->Name) > 0) ) {
696 StrBufAppendBuf(Mime->FileName, Mime->Name, 0);
699 if (StrLength(Msg->PartNum) > 0) {
701 StrBufPrintf(Buf, "%s.%s", ChrPtr(Msg->PartNum), ChrPtr(Mime->PartNum));
707 if (Msg->AllAttach == NULL)
708 Msg->AllAttach = NewHash(1,NULL);
709 Put(Msg->AllAttach, SKEY(Mime->PartNum), Mime, DestroyMime);
714 void evaluate_mime_part(message_summary *Msg, wc_mime_attachment *Mime)
718 /* just print the root-node */
719 if ((Mime->level >= 1) &&
720 GetHash(MimeRenderHandler, SKEY(Mime->ContentType), &vMimeRenderer) &&
721 vMimeRenderer != NULL)
723 Mime->Renderer = (RenderMimeFuncStruct*) vMimeRenderer;
724 if (Msg->Submessages == NULL)
725 Msg->Submessages = NewHash(1,NULL);
726 Put(Msg->Submessages, SKEY(Mime->PartNum), Mime, reference_free_handler);
728 else if ((Mime->level >= 1) &&
729 (!strcasecmp(ChrPtr(Mime->Disposition), "inline"))
730 && (!strncasecmp(ChrPtr(Mime->ContentType), "image/", 6)) ){
731 if (Msg->AttachLinks == NULL)
732 Msg->AttachLinks = NewHash(1,NULL);
733 Put(Msg->AttachLinks, SKEY(Mime->PartNum), Mime, reference_free_handler);
735 else if ((Mime->level >= 1) &&
736 (StrLength(Mime->ContentType) > 0) &&
737 ( (!strcasecmp(ChrPtr(Mime->Disposition), "attachment"))
738 || (!strcasecmp(ChrPtr(Mime->Disposition), "inline"))
739 || (!strcasecmp(ChrPtr(Mime->Disposition), ""))))
741 if (Msg->AttachLinks == NULL)
742 Msg->AttachLinks = NewHash(1,NULL);
743 Put(Msg->AttachLinks, SKEY(Mime->PartNum), Mime, reference_free_handler);
744 if ((strcasecmp(ChrPtr(Mime->ContentType), "application/octet-stream") == 0) &&
745 (StrLength(Mime->FileName) > 0)) {
746 FlushStrBuf(Mime->ContentType);
747 StrBufAppendBufPlain(Mime->ContentType,
748 GuessMimeByFilename(SKEY(Mime->FileName)),
754 void tmplput_MAIL_SUMM_NATTACH(StrBuf *Target, WCTemplputParams *TP)
756 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
757 StrBufAppendPrintf(Target, "%ld", GetCount(Msg->Attachments));
761 void examine_hnod(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
765 CheckConvertBufs(WCC);
766 FreeStrBuf(&Msg->hnod);
767 Msg->hnod = NewStrBufPlain(NULL, StrLength(HdrLine));
768 StrBuf_RFC822_2_Utf8(Msg->hnod,
775 void tmplput_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP)
777 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
778 StrBufAppendTemplate(Target, TP, Msg->hnod, 0);
780 int Conditional_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP)
782 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
783 return StrLength(Msg->hnod) > 0;
788 void examine_text(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
790 if (Msg->MsgBody->Data == NULL)
791 Msg->MsgBody->Data = NewStrBufPlain(NULL, SIZ);
793 FlushStrBuf(Msg->MsgBody->Data);
796 void examine_msg4_partnum(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
798 Msg->MsgBody->PartNum = NewStrBufDup(HdrLine);
799 StrBufTrim(Msg->MsgBody->PartNum);
802 void examine_content_lengh(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
804 Msg->MsgBody->length = StrTol(HdrLine);
805 Msg->MsgBody->size_known = 1;
808 void examine_content_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
818 Msg->MsgBody->ContentType = NewStrBufDup(HdrLine);
819 sem = strchr(ChrPtr(HdrLine), ';');
822 Token = NewStrBufPlain(NULL, StrLength(HdrLine));
823 Value = NewStrBufPlain(NULL, StrLength(HdrLine));
824 len = sem - ChrPtr(HdrLine);
825 StrBufCutAt(Msg->MsgBody->ContentType, len, NULL);
826 while (sem != NULL) {
827 while (isspace(*(sem + 1)))
829 StrBufCutLeft(HdrLine, sem - ChrPtr(HdrLine));
830 sem = strchr(ChrPtr(HdrLine), ';');
832 len = sem - ChrPtr(HdrLine);
834 len = StrLength(HdrLine);
837 StrBufAppendBufPlain(Token, ChrPtr(HdrLine), len, 0);
838 eq = strchr(ChrPtr(Token), '=');
840 len = eq - ChrPtr(Token);
841 StrBufAppendBufPlain(Value, eq + 1, StrLength(Token) - len - 1, 0);
842 StrBufCutAt(Token, len, NULL);
847 if (GetHash(MsgHeaderHandler, SKEY(Token), &vHdr) &&
849 Hdr = (headereval*)vHdr;
850 Hdr->evaluator(Msg, Value, FoundCharset);
852 else syslog(1, "don't know how to handle content type sub-header[%s]\n", ChrPtr(Token));
859 void tmplput_MAIL_SUMM_N(StrBuf *Target, WCTemplputParams *TP)
861 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
862 StrBufAppendPrintf(Target, "%ld", Msg->msgnum);
866 void tmplput_MAIL_SUMM_PERMALINK(StrBuf *Target, WCTemplputParams *TP)
868 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
869 char perma_link[1024];
871 strcpy(perma_link, "/readfwd?go=");
872 urlesc(&perma_link[12], sizeof(perma_link) - 12, (char *)ChrPtr(WC->CurRoom.name) );
873 sprintf(&perma_link[strlen(perma_link)], "?start_reading_at=%ld#%ld", Msg->msgnum, Msg->msgnum);
874 StrBufAppendPrintf(Target, "%s", perma_link);
878 int Conditional_MAIL_MIME_ALL(StrBuf *Target, WCTemplputParams *TP)
880 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
881 return GetCount(Msg->Attachments) > 0;
884 int Conditional_MAIL_MIME_SUBMESSAGES(StrBuf *Target, WCTemplputParams *TP)
886 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
887 return GetCount(Msg->Submessages) > 0;
890 int Conditional_MAIL_MIME_ATTACHLINKS(StrBuf *Target, WCTemplputParams *TP)
892 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
893 return GetCount(Msg->AttachLinks) > 0;
896 int Conditional_MAIL_MIME_ATTACH(StrBuf *Target, WCTemplputParams *TP)
898 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
899 return GetCount(Msg->AllAttach) > 0;
902 void tmplput_QUOTED_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
908 MsgNum = LBstr(TKEY(0));
910 read_message(Buf, HKEY("view_message_replyquote"), MsgNum, NULL, &Mime);
911 StrBufAppendTemplate(Target, TP, Buf, 1);
915 void tmplput_EDIT_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
921 MsgNum = LBstr(TKEY(0));
923 read_message(Buf, HKEY("view_message_edit"), MsgNum, NULL, &Mime);
924 StrBufAppendTemplate(Target, TP, Buf, 1);
928 void tmplput_EDIT_WIKI_BODY(StrBuf *Target, WCTemplputParams *TP)
934 /* Insert the existing content of the wiki page into the editor. But we only want
935 * to do this the first time -- if the user is uploading an attachment we don't want
938 if (!havebstr("attach_button")) {
939 char *wikipage = strdup(bstr("page"));
940 str_wiki_index(wikipage);
941 msgnum = locate_message_by_uid(wikipage);
945 read_message(Buf, HKEY("view_message_wikiedit"), msgnum, NULL, &Mime);
946 StrBufAppendTemplate(Target, TP, Buf, 1);
952 void tmplput_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
954 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
955 StrBufAppendTemplate(Target, TP, Msg->MsgBody->Data, 0);
959 void render_MAIL_variformat(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
961 /* Messages in legacy Citadel variformat get handled thusly... */
962 StrBuf *Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
963 FmOut(Target, "JUSTIFY", Mime->Data);
964 FreeStrBuf(&Mime->Data);
968 void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
970 const char *ptr, *pte;
971 const char *BufPtr = NULL;
985 iconv_t ic = (iconv_t)(-1) ;
988 if ((StrLength(Mime->Data) == 0) && (Mime->length > 0)) {
989 FreeStrBuf(&Mime->Data);
995 if (StrLength(Mime->Charset) != 0)
997 else if (StrLength(FoundCharset) > 0)
999 else if (StrLength(WC->DefaultCharset) > 0)
1000 cs = WC->DefaultCharset;
1004 else if (!strcasecmp(ChrPtr(cs), "utf-8")) {
1007 else if (!strcasecmp(ChrPtr(cs), "us-ascii")) {
1011 ctdl_iconv_open("UTF-8", ChrPtr(cs), &ic);
1012 if (ic == (iconv_t)(-1) ) {
1013 syslog(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
1014 __FILE__, __LINE__, ChrPtr(Mime->Charset), strerror(errno));
1019 Line = NewStrBufPlain(NULL, SIZ);
1020 Line1 = NewStrBufPlain(NULL, SIZ);
1021 Line2 = NewStrBufPlain(NULL, SIZ);
1022 Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
1025 if (StrLength(Mime->Data) > 0)
1028 StrBufSipLine(Line, Mime->Data, &BufPtr);
1032 len = StrLength(Line);
1035 while ((ptr < pte) &&
1044 if (i > 0) StrBufCutLeft(Line, i);
1046 if (StrLength(Line) == 0) {
1049 StrBufAppendBufPlain(Target, HKEY("<tt></tt><br>\n"), 0);
1055 for (i = bn; i < bq; i++)
1056 StrBufAppendBufPlain(Target, HKEY("<blockquote>"), 0);
1057 for (i = bq; i < bn; i++)
1058 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
1061 StrBufConvert(Line, Line1, &ic);
1064 StrBufAppendBufPlain(Target, HKEY("<tt>"), 0);
1065 UrlizeText(Line1, Line, Line2);
1067 StrEscAppend(Target, Line1, NULL, 0, 0);
1068 StrBufAppendBufPlain(Target, HKEY("</tt><br>\n"), 0);
1072 while ((BufPtr != StrBufNOTNULL) &&
1075 if (nEmptyLines > 0)
1076 StrBufCutRight(Target, nEmptyLines * (sizeof ("<tt></tt><br>\n") - 1));
1077 for (i = 0; i < bn; i++)
1078 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
1080 StrBufAppendBufPlain(Target, HKEY("</i><br>"), 0);
1082 if (ic != (iconv_t)(-1) ) {
1087 FreeStrBuf(&Mime->Data);
1088 Mime->Data = Target;
1089 FlushStrBuf(Mime->ContentType);
1090 StrBufAppendBufPlain(Mime->ContentType, HKEY("text/html"), 0);
1091 FlushStrBuf(Mime->Charset);
1092 StrBufAppendBufPlain(Mime->Charset, HKEY("UTF-8"), 0);
1098 void render_MAIL_html(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
1102 if (StrLength(Mime->Data) == 0)
1105 Buf = NewStrBufPlain(NULL, StrLength(Mime->Data));
1107 /* HTML is fun, but we've got to strip it first */
1108 output_html(ChrPtr(Mime->Charset),
1109 (WC->CurRoom.view == VIEW_WIKI ? 1 : 0),
1112 FreeStrBuf(&Mime->Data);
1116 void render_MAIL_UNKNOWN(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
1118 /* Unknown weirdness */
1119 FlushStrBuf(Mime->Data);
1120 StrBufAppendBufPlain(Mime->Data, _("I don't know how to display "), -1, 0);
1121 StrBufAppendBuf(Mime->Data, Mime->ContentType, 0);
1122 StrBufAppendBufPlain(Mime->Data, HKEY("<br>\n"), 0);
1126 HashList *iterate_get_mime_All(StrBuf *Target, WCTemplputParams *TP)
1128 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
1129 return Msg->Attachments;
1131 HashList *iterate_get_mime_Submessages(StrBuf *Target, WCTemplputParams *TP)
1133 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
1134 return Msg->Submessages;
1136 HashList *iterate_get_mime_AttachLinks(StrBuf *Target, WCTemplputParams *TP)
1138 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
1139 return Msg->AttachLinks;
1141 HashList *iterate_get_mime_Attachments(StrBuf *Target, WCTemplputParams *TP)
1143 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
1144 return Msg->AllAttach;
1147 void tmplput_MIME_Name(StrBuf *Target, WCTemplputParams *TP)
1149 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1150 StrBufAppendTemplate(Target, TP, mime->Name, 0);
1153 void tmplput_MIME_FileName(StrBuf *Target, WCTemplputParams *TP)
1155 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1156 StrBufAppendTemplate(Target, TP, mime->FileName, 0);
1159 void tmplput_MIME_PartNum(StrBuf *Target, WCTemplputParams *TP)
1161 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1162 StrBufAppendTemplate(Target, TP, mime->PartNum, 0);
1165 void tmplput_MIME_MsgNum(StrBuf *Target, WCTemplputParams *TP)
1167 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1168 StrBufAppendPrintf(Target, "%ld", mime->msgnum);
1171 void tmplput_MIME_Disposition(StrBuf *Target, WCTemplputParams *TP)
1173 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1174 StrBufAppendTemplate(Target, TP, mime->Disposition, 0);
1177 void tmplput_MIME_ContentType(StrBuf *Target, WCTemplputParams *TP)
1179 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1180 StrBufAppendTemplate(Target, TP, mime->ContentType, 0);
1183 void examine_charset(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
1185 Msg->MsgBody->Charset = NewStrBufDup(HdrLine);
1188 void tmplput_MIME_Charset(StrBuf *Target, WCTemplputParams *TP)
1190 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1191 StrBufAppendTemplate(Target, TP, mime->Charset, 0);
1194 void tmplput_MIME_Data(StrBuf *Target, WCTemplputParams *TP)
1196 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1197 if (mime->Renderer != NULL)
1198 mime->Renderer->f(mime, NULL, NULL);
1199 StrBufAppendTemplate(Target, TP, mime->Data, 0);
1200 /* TODO: check whether we need to load it now? */
1203 void tmplput_MIME_LoadData(StrBuf *Target, WCTemplputParams *TP)
1205 wcsession *WCC = WC;
1206 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1207 wc_mime_attachment *att;
1209 if (( (!strcasecmp(ChrPtr(mime->Disposition), "inline"))||
1210 (!strcasecmp(ChrPtr(mime->Disposition), "attachment"))) &&
1211 (strcasecmp(ChrPtr(mime->ContentType), "application/ms-tnef")!=0))
1216 /* steal this mime part... */
1217 att = malloc(sizeof(wc_mime_attachment));
1218 memcpy(att, mime, sizeof(wc_mime_attachment));
1219 memset(mime, 0, sizeof(wc_mime_attachment));
1221 if (att->Data == NULL)
1224 if (WCC->attachments == NULL)
1225 WCC->attachments = NewHash(1, NULL);
1226 /* And add it to the list. */
1227 n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
1228 Put(WCC->attachments, N, n, att, DestroyMime);
1232 void tmplput_MIME_Length(StrBuf *Target, WCTemplputParams *TP)
1234 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1235 StrBufAppendPrintf(Target, "%ld", mime->length);
1238 HashList *iterate_get_registered_Attachments(StrBuf *Target, WCTemplputParams *TP)
1240 return WC->attachments;
1243 void get_registered_Attachments_Count(StrBuf *Target, WCTemplputParams *TP)
1245 StrBufAppendPrintf(Target, "%ld", GetCount (WC->attachments));
1248 void servcmd_do_search(char *buf, long bufsize)
1250 snprintf(buf, bufsize, "MSGS SEARCH|%s", bstr("query"));
1253 void servcmd_headers(char *buf, long bufsize)
1255 snprintf(buf, bufsize, "MSGS ALL");
1258 void servcmd_readfwd(char *buf, long bufsize)
1260 snprintf(buf, bufsize, "MSGS ALL");
1263 void servcmd_readgt(char *buf, long bufsize)
1265 snprintf(buf, bufsize, "MSGS GT|%s", bstr("gt"));
1268 void servcmd_readlt(char *buf, long bufsize)
1270 snprintf(buf, bufsize, "MSGS LT|%s", bstr("lt"));
1273 void servcmd_readnew(char *buf, long bufsize)
1275 snprintf(buf, bufsize, "MSGS NEW");
1278 void servcmd_readold(char *buf, long bufsize)
1280 snprintf(buf, bufsize, "MSGS OLD");
1284 /* DO NOT REORDER OR REMOVE ANY OF THESE */
1285 readloop_struct rlid[] = {
1286 { {HKEY("do_search")}, servcmd_do_search },
1287 { {HKEY("headers")}, servcmd_headers },
1288 { {HKEY("readfwd")}, servcmd_readfwd },
1289 { {HKEY("readnew")}, servcmd_readnew },
1290 { {HKEY("readold")}, servcmd_readold },
1291 { {HKEY("readgt")}, servcmd_readgt },
1292 { {HKEY("readlt")}, servcmd_readlt }
1296 int ParseMessageListHeaders_Detail(StrBuf *Line,
1298 message_summary *Msg,
1299 StrBuf *ConversionBuffer)
1301 wcsession *WCC = WC;
1305 CheckConvertBufs(WCC);
1307 totallen = StrLength(Line);
1308 Msg->from = NewStrBufPlain(NULL, totallen);
1309 len = StrBufExtract_NextToken(ConversionBuffer, Line, pos, '|');
1311 /* Handle senders with RFC2047 encoding */
1312 StrBuf_RFC822_2_Utf8(Msg->from,
1314 WCC->DefaultCharset,
1321 len = StrBufExtract_NextToken(ConversionBuffer, Line, pos, '|');
1323 ( ((WCC->CurRoom.QRFlags & QR_NETWORK)
1324 || ((strcasecmp(ChrPtr(ConversionBuffer), ChrPtr(WCC->serv_info->serv_nodename))
1325 && (strcasecmp(ChrPtr(ConversionBuffer), ChrPtr(WCC->serv_info->serv_fqdn))))))))
1327 StrBufAppendBufPlain(Msg->from, HKEY(" @ "), 0);
1328 StrBufAppendBuf(Msg->from, ConversionBuffer, 0);
1331 /* Internet address (not used)
1332 * StrBufExtract_token(Msg->inetaddr, Line, 4, '|');
1334 StrBufSkip_NTokenS(Line, pos, '|', 1);
1335 Msg->subj = NewStrBufPlain(NULL, totallen);
1337 FlushStrBuf(ConversionBuffer);
1338 /* we assume the subject is the last parameter inside of the list;
1339 * thus we don't use the tokenizer to fetch it, since it will hick up
1340 * on tokenizer chars inside of the subjects
1341 StrBufExtract_NextToken(ConversionBuffer, Line, pos, '|');
1344 if (*pos != StrBufNOTNULL) {
1345 len = totallen - (*pos - ChrPtr(Line));
1346 StrBufPlain(ConversionBuffer, *pos, len);
1347 *pos = StrBufNOTNULL;
1349 (*(ChrPtr(ConversionBuffer) + len - 1) == '|'))
1350 StrBufCutRight(ConversionBuffer, 1);
1354 StrBufAppendBufPlain(Msg->subj, _("(no subject)"), -1,0);
1356 StrBuf_RFC822_2_Utf8(Msg->subj,
1358 WCC->DefaultCharset,
1368 int mailview_GetParamsGetServerCall(SharedMessageStatus *Stat,
1369 void **ViewSpecific,
1376 DoTemplate(HKEY("msg_listview"),NULL,&NoCtx);
1381 int mailview_Cleanup(void **ViewSpecific)
1383 /* Note: wDumpContent() will output one additional </div> tag. */
1384 /* We ought to move this out into template */
1391 int json_GetParamsGetServerCall(SharedMessageStatus *Stat,
1392 void **ViewSpecific,
1399 Stat->defaultsortorder = 2;
1401 Stat->load_seen = 1;
1402 /* Generally using maxmsgs|startmsg is not required
1403 in mailbox view, but we have a 'safemode' for clients
1404 (*cough* Exploder) that simply can't handle too many */
1405 if (havebstr("maxmsgs")) Stat->maxmsgs = ibstr("maxmsgs");
1406 else Stat->maxmsgs = 9999999;
1407 if (havebstr("startmsg")) Stat->startmsg = lbstr("startmsg");
1408 snprintf(cmd, len, "MSGS %s|%s||1",
1409 (oper == do_search) ? "SEARCH" : "ALL",
1410 (oper == do_search) ? bstr("query") : ""
1415 int json_MessageListHdr(SharedMessageStatus *Stat, void **ViewSpecific)
1417 /* TODO: make a generic function */
1418 hprintf("HTTP/1.1 200 OK\r\n");
1419 hprintf("Content-type: application/json; charset=utf-8\r\n");
1420 hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
1421 hprintf("Connection: close\r\n");
1422 hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
1427 int json_RenderView_or_Tail(SharedMessageStatus *Stat,
1428 void **ViewSpecific,
1431 DoTemplate(HKEY("mailsummary_json"),NULL, NULL);
1436 int json_Cleanup(void **ViewSpecific)
1438 /* Note: wDumpContent() will output one additional </div> tag. */
1439 /* We ought to move this out into template */
1448 InitModule_MSGRENDERERS
1451 RegisterCTX(CTX_MAILSUM);
1452 RegisterCTX(CTX_MIME_ATACH);
1453 RegisterReadLoopHandlerset(
1455 mailview_GetParamsGetServerCall,
1456 NULL, /* TODO: is this right? */
1458 ParseMessageListHeaders_Detail,
1463 RegisterReadLoopHandlerset(
1465 json_GetParamsGetServerCall,
1466 json_MessageListHdr,
1467 NULL, /* TODO: is this right? */
1468 ParseMessageListHeaders_Detail,
1470 json_RenderView_or_Tail,
1473 RegisterSortFunc(HKEY("date"),
1479 RegisterSortFunc(HKEY("subject"),
1485 RegisterSortFunc(HKEY("sender"),
1492 RegisterNamespace("SUMM:COUNT", 0, 0, tmplput_SUMM_COUNT, NULL, CTX_NONE);
1493 /* iterate over all known mails in WC->summ */
1494 RegisterIterator("MAIL:SUMM:MSGS", 0, NULL, iterate_get_mailsumm_All,
1495 NULL,NULL, CTX_MAILSUM, CTX_NONE, IT_NOFLAG);
1497 RegisterNamespace("MAIL:SUMM:EUID", 0, 1, tmplput_MAIL_SUMM_EUID, NULL, CTX_MAILSUM);
1498 RegisterNamespace("MAIL:SUMM:DATEBRIEF", 0, 0, tmplput_MAIL_SUMM_DATE_BRIEF, NULL, CTX_MAILSUM);
1499 RegisterNamespace("MAIL:SUMM:DATEFULL", 0, 0, tmplput_MAIL_SUMM_DATE_FULL, NULL, CTX_MAILSUM);
1500 RegisterNamespace("MAIL:SUMM:DATENO", 0, 0, tmplput_MAIL_SUMM_DATE_NO, NULL, CTX_MAILSUM);
1501 RegisterNamespace("MAIL:SUMM:N", 0, 0, tmplput_MAIL_SUMM_N, NULL, CTX_MAILSUM);
1502 RegisterNamespace("MAIL:SUMM:PERMALINK", 0, 0, tmplput_MAIL_SUMM_PERMALINK, NULL, CTX_MAILSUM);
1503 RegisterNamespace("MAIL:SUMM:FROM", 0, 2, tmplput_MAIL_SUMM_FROM, NULL, CTX_MAILSUM);
1504 RegisterNamespace("MAIL:SUMM:TO", 0, 2, tmplput_MAIL_SUMM_TO, NULL, CTX_MAILSUM);
1505 RegisterNamespace("MAIL:SUMM:SUBJECT", 0, 4, tmplput_MAIL_SUMM_SUBJECT, NULL, CTX_MAILSUM);
1506 RegisterNamespace("MAIL:SUMM:NTATACH", 0, 0, tmplput_MAIL_SUMM_NATTACH, NULL, CTX_MAILSUM);
1507 RegisterNamespace("MAIL:SUMM:CCCC", 0, 2, tmplput_MAIL_SUMM_CCCC, NULL, CTX_MAILSUM);
1508 RegisterNamespace("MAIL:SUMM:REPLYTO", 0, 2, tmplput_MAIL_SUMM_REPLYTO, NULL, CTX_MAILSUM);
1509 RegisterNamespace("MAIL:SUMM:H_NODE", 0, 2, tmplput_MAIL_SUMM_H_NODE, NULL, CTX_MAILSUM);
1510 RegisterNamespace("MAIL:SUMM:ALLRCPT", 0, 2, tmplput_MAIL_SUMM_ALLRCPT, NULL, CTX_MAILSUM);
1511 RegisterNamespace("MAIL:SUMM:ORGROOM", 0, 2, tmplput_MAIL_SUMM_ORGROOM, NULL, CTX_MAILSUM);
1512 RegisterNamespace("MAIL:SUMM:RFCA", 0, 2, tmplput_MAIL_SUMM_RFCA, NULL, CTX_MAILSUM);
1513 RegisterNamespace("MAIL:SUMM:OTHERNODE", 2, 0, tmplput_MAIL_SUMM_OTHERNODE, NULL, CTX_MAILSUM);
1514 RegisterNamespace("MAIL:SUMM:REFIDS", 0, 1, tmplput_MAIL_SUMM_REFIDS, NULL, CTX_MAILSUM);
1515 RegisterNamespace("MAIL:SUMM:INREPLYTO", 0, 2, tmplput_MAIL_SUMM_INREPLYTO, NULL, CTX_MAILSUM);
1516 RegisterNamespace("MAIL:BODY", 0, 2, tmplput_MAIL_BODY, NULL, CTX_MAILSUM);
1517 RegisterNamespace("MAIL:QUOTETEXT", 1, 2, tmplput_QUOTED_MAIL_BODY, NULL, CTX_NONE);
1518 RegisterNamespace("MAIL:EDITTEXT", 1, 2, tmplput_EDIT_MAIL_BODY, NULL, CTX_NONE);
1519 RegisterNamespace("MAIL:EDITWIKI", 1, 2, tmplput_EDIT_WIKI_BODY, NULL, CTX_NONE);
1520 RegisterConditional(HKEY("COND:MAIL:SUMM:RFCA"), 0, Conditional_MAIL_SUMM_RFCA, CTX_MAILSUM);
1521 RegisterConditional(HKEY("COND:MAIL:SUMM:CCCC"), 0, Conditional_MAIL_SUMM_CCCC, CTX_MAILSUM);
1522 RegisterConditional(HKEY("COND:MAIL:SUMM:REPLYTO"), 0, Conditional_MAIL_SUMM_REPLYTO, CTX_MAILSUM);
1523 RegisterConditional(HKEY("COND:MAIL:SUMM:UNREAD"), 0, Conditional_MAIL_SUMM_UNREAD, CTX_MAILSUM);
1524 RegisterConditional(HKEY("COND:MAIL:SUMM:H_NODE"), 0, Conditional_MAIL_SUMM_H_NODE, CTX_MAILSUM);
1525 RegisterConditional(HKEY("COND:MAIL:SUMM:OTHERNODE"), 0, Conditional_MAIL_SUMM_OTHERNODE, CTX_MAILSUM);
1526 RegisterConditional(HKEY("COND:MAIL:SUMM:SUBJECT"), 0, Conditional_MAIL_SUMM_SUBJECT, CTX_MAILSUM);
1527 RegisterConditional(HKEY("COND:MAIL:ANON"), 0, Conditional_ANONYMOUS_MESSAGE, CTX_MAILSUM);
1528 RegisterConditional(HKEY("COND:MAIL:TO"), 0, Conditional_MAIL_SUMM_TO, CTX_MAILSUM);
1529 RegisterConditional(HKEY("COND:MAIL:SUBJ"), 0, Conditional_MAIL_SUMM_SUBJ, CTX_MAILSUM);
1531 /* do we have mimetypes to iterate over? */
1532 RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH"), 0, Conditional_MAIL_MIME_ALL, CTX_MAILSUM);
1533 RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:SUBMESSAGES"), 0, Conditional_MAIL_MIME_SUBMESSAGES, CTX_MAILSUM);
1534 RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:LINKS"), 0, Conditional_MAIL_MIME_ATTACHLINKS, CTX_MAILSUM);
1535 RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:ATT"), 0, Conditional_MAIL_MIME_ATTACH, CTX_MAILSUM);
1536 RegisterIterator("MAIL:MIME:ATTACH", 0, NULL, iterate_get_mime_All,
1537 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1538 RegisterIterator("MAIL:MIME:ATTACH:SUBMESSAGES", 0, NULL, iterate_get_mime_Submessages,
1539 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1540 RegisterIterator("MAIL:MIME:ATTACH:LINKS", 0, NULL, iterate_get_mime_AttachLinks,
1541 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1542 RegisterIterator("MAIL:MIME:ATTACH:ATT", 0, NULL, iterate_get_mime_Attachments,
1543 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1545 /* Parts of a mime attachent */
1546 RegisterNamespace("MAIL:MIME:NAME", 0, 2, tmplput_MIME_Name, NULL, CTX_MIME_ATACH);
1547 RegisterNamespace("MAIL:MIME:FILENAME", 0, 2, tmplput_MIME_FileName, NULL, CTX_MIME_ATACH);
1548 RegisterNamespace("MAIL:MIME:PARTNUM", 0, 2, tmplput_MIME_PartNum, NULL, CTX_MIME_ATACH);
1549 RegisterNamespace("MAIL:MIME:MSGNUM", 0, 2, tmplput_MIME_MsgNum, NULL, CTX_MIME_ATACH);
1550 RegisterNamespace("MAIL:MIME:DISPOSITION", 0, 2, tmplput_MIME_Disposition, NULL, CTX_MIME_ATACH);
1551 RegisterNamespace("MAIL:MIME:CONTENTTYPE", 0, 2, tmplput_MIME_ContentType, NULL, CTX_MIME_ATACH);
1552 RegisterNamespace("MAIL:MIME:CHARSET", 0, 2, tmplput_MIME_Charset, NULL, CTX_MIME_ATACH);
1553 RegisterNamespace("MAIL:MIME:LENGTH", 0, 2, tmplput_MIME_Length, NULL, CTX_MIME_ATACH);
1554 RegisterNamespace("MAIL:MIME:DATA", 0, 2, tmplput_MIME_Data, NULL, CTX_MIME_ATACH);
1555 /* load the actual attachment into WC->attachments; no output!!! */
1556 RegisterNamespace("MAIL:MIME:LOADDATA", 0, 0, tmplput_MIME_LoadData, NULL, CTX_MIME_ATACH);
1558 /* iterate the WC->attachments; use the above tokens for their contents */
1559 RegisterIterator("MSG:ATTACHNAMES", 0, NULL, iterate_get_registered_Attachments,
1560 NULL, NULL, CTX_MIME_ATACH, CTX_NONE, IT_NOFLAG);
1562 RegisterNamespace("MSG:NATTACH", 0, 0, get_registered_Attachments_Count, NULL, CTX_NONE);
1564 /* mime renderers translate an attachment into webcit viewable html text */
1565 RegisterMimeRenderer(HKEY("message/rfc822"), render_MAIL, 0, 150);
1566 RegisterMimeRenderer(HKEY("text/x-vcard"), render_MIME_VCard, 1, 201);
1567 RegisterMimeRenderer(HKEY("text/vcard"), render_MIME_VCard, 1, 200);
1568 RegisterMimeRenderer(HKEY("text/calendar"), render_MIME_ICS, 1, 501);
1569 RegisterMimeRenderer(HKEY("application/ics"), render_MIME_ICS, 1, 500);
1570 RegisterMimeRenderer(HKEY("text/x-citadel-variformat"), render_MAIL_variformat, 1, 2);
1571 RegisterMimeRenderer(HKEY("text/plain"), render_MAIL_text_plain, 1, 3);
1572 RegisterMimeRenderer(HKEY("text"), render_MAIL_text_plain, 1, 1);
1573 RegisterMimeRenderer(HKEY("text/html"), render_MAIL_html, 1, 100);
1574 RegisterMimeRenderer(HKEY(""), render_MAIL_UNKNOWN, 0, 0);
1576 /* these headers are citserver replies to MSG4 and friends. one evaluator for each */
1577 RegisterMsgHdr(HKEY("nhdr"), examine_nhdr, 0);
1578 RegisterMsgHdr(HKEY("type"), examine_type, 0);
1579 RegisterMsgHdr(HKEY("from"), examine_from, 0);
1580 RegisterMsgHdr(HKEY("subj"), examine_subj, 0);
1581 RegisterMsgHdr(HKEY("msgn"), examine_msgn, 0);
1582 RegisterMsgHdr(HKEY("wefw"), examine_wefw, 0);
1583 RegisterMsgHdr(HKEY("cccc"), examine_cccc, 0);
1584 RegisterMsgHdr(HKEY("rep2"), examine_replyto, 0);
1585 RegisterMsgHdr(HKEY("hnod"), examine_hnod, 0);
1586 RegisterMsgHdr(HKEY("room"), examine_room, 0);
1587 RegisterMsgHdr(HKEY("rfca"), examine_rfca, 0);
1588 RegisterMsgHdr(HKEY("node"), examine_node, 0);
1589 RegisterMsgHdr(HKEY("rcpt"), examine_rcpt, 0);
1590 RegisterMsgHdr(HKEY("time"), examine_time, 0);
1591 RegisterMsgHdr(HKEY("part"), examine_mime_part, 0);
1592 RegisterMsgHdr(HKEY("text"), examine_text, 1);
1593 /* these are the content-type headers we get infront of a message; put it into the same hash since it doesn't clash. */
1594 RegisterMsgHdr(HKEY("X-Citadel-MSG4-Partnum"), examine_msg4_partnum, 0);
1595 RegisterMsgHdr(HKEY("Content-type"), examine_content_type, 0);
1596 RegisterMsgHdr(HKEY("Content-length"), examine_content_lengh, 0);
1597 RegisterMsgHdr(HKEY("Content-transfer-encoding"), examine_content_encoding, 0); /* do we care? */
1598 RegisterMsgHdr(HKEY("charset"), examine_charset, 0);
1600 /* Don't care about these... */
1601 RegisterMsgHdr(HKEY("pref"), examine_pref, 0);
1602 RegisterMsgHdr(HKEY("suff"), examine_suff, 0);
1603 RegisterMsgHdr(HKEY("path"), examine_path, 0);
1607 InitModule2_MSGRENDERERS
1610 /* and finalize the anouncement to the server... */
1614 ServerStartModule_MSGRENDERERS
1617 MsgHeaderHandler = NewHash(1, NULL);
1618 MimeRenderHandler = NewHash(1, NULL);
1619 ReadLoopHandler = NewHash(1, NULL);
1623 ServerShutdownModule_MSGRENDERERS
1626 DeleteHash(&MsgHeaderHandler);
1627 DeleteHash(&MimeRenderHandler);
1628 DeleteHash(&ReadLoopHandler);
1634 SessionDestroyModule_MSGRENDERERS
1637 DeleteHash(&sess->attachments);
1638 FreeStrBuf(&sess->ConvertBuf1);
1639 FreeStrBuf(&sess->ConvertBuf2);