7 inline void CheckConvertBufs(struct wcsession *WCC)
9 if (WCC->ConvertBuf1 == NULL)
10 WCC->ConvertBuf1 = NewStrBuf();
11 if (WCC->ConvertBuf2 == NULL)
12 WCC->ConvertBuf2 = NewStrBuf();
16 * message index functions
20 void DestroyMimeParts(wc_mime_attachment *Mime)
22 FreeStrBuf(&Mime->Name);
23 FreeStrBuf(&Mime->FileName);
24 FreeStrBuf(&Mime->PartNum);
25 FreeStrBuf(&Mime->Disposition);
26 FreeStrBuf(&Mime->ContentType);
27 FreeStrBuf(&Mime->Charset);
28 FreeStrBuf(&Mime->Data);
31 void DestroyMime(void *vMime)
33 wc_mime_attachment *Mime = (wc_mime_attachment*)vMime;
34 DestroyMimeParts(Mime);
38 void DestroyMessageSummary(void *vMsg)
40 message_summary *Msg = (message_summary*) vMsg;
42 FreeStrBuf(&Msg->from);
44 FreeStrBuf(&Msg->subj);
45 FreeStrBuf(&Msg->reply_inreplyto);
46 FreeStrBuf(&Msg->reply_references);
47 FreeStrBuf(&Msg->cccc);
48 FreeStrBuf(&Msg->hnod);
49 FreeStrBuf(&Msg->AllRcpt);
50 FreeStrBuf(&Msg->Room);
51 FreeStrBuf(&Msg->Rfca);
52 FreeStrBuf(&Msg->OtherNode);
54 DeleteHash(&Msg->Attachments); /* list of Attachments */
55 DeleteHash(&Msg->Submessages);
56 DeleteHash(&Msg->AttachLinks);
57 DeleteHash(&Msg->AllAttach);
63 void RegisterMsgHdr(const char *HeaderName, long HdrNLen, ExamineMsgHeaderFunc evaluator, int type)
66 ev = (headereval*) malloc(sizeof(headereval));
67 ev->evaluator = evaluator;
69 Put(MsgHeaderHandler, HeaderName, HdrNLen, ev, NULL);
72 void RegisterMimeRenderer(const char *HeaderName, long HdrNLen,
73 RenderMimeFunc MimeRenderer,
77 RenderMimeFuncStruct *f;
79 f = (RenderMimeFuncStruct*) malloc(sizeof(RenderMimeFuncStruct));
81 Put(MimeRenderHandler, HeaderName, HdrNLen, f, NULL);
83 RegisterEmbeddableMimeType(HeaderName, HdrNLen, 10000 - Priority);
86 /*----------------------------------------------------------------------------*/
89 * comparator for two longs in descending order.
91 int longcmp_r(const void *s1, const void *s2) {
95 l1 = *(long *)GetSearchPayload(s1);
96 l2 = *(long *)GetSearchPayload(s2);
98 if (l1 > l2) return(-1);
99 if (l1 < l2) return(+1);
104 * comparator for longs; descending order.
106 int qlongcmp_r(const void *s1, const void *s2) {
110 if (l1 > l2) return(-1);
111 if (l1 < l2) return(+1);
117 * comparator for message summary structs by ascending subject.
119 int summcmp_subj(const void *s1, const void *s2) {
120 message_summary *summ1;
121 message_summary *summ2;
123 summ1 = (message_summary *)GetSearchPayload(s1);
124 summ2 = (message_summary *)GetSearchPayload(s2);
125 return strcasecmp(ChrPtr(summ1->subj), ChrPtr(summ2->subj));
129 * comparator for message summary structs by descending subject.
131 int summcmp_rsubj(const void *s1, const void *s2) {
132 message_summary *summ1;
133 message_summary *summ2;
135 summ1 = (message_summary *)GetSearchPayload(s1);
136 summ2 = (message_summary *)GetSearchPayload(s2);
137 return strcasecmp(ChrPtr(summ2->subj), ChrPtr(summ1->subj));
140 * comparator for message summary structs by descending subject.
142 int groupchange_subj(const void *s1, const void *s2) {
143 message_summary *summ1;
144 message_summary *summ2;
146 summ1 = (message_summary *)s1;
147 summ2 = (message_summary *)s2;
148 return ChrPtr(summ2->subj)[0] != ChrPtr(summ1->subj)[0];
152 * comparator for message summary structs by ascending sender.
154 int summcmp_sender(const void *s1, const void *s2) {
155 message_summary *summ1;
156 message_summary *summ2;
158 summ1 = (message_summary *)GetSearchPayload(s1);
159 summ2 = (message_summary *)GetSearchPayload(s2);
160 return strcasecmp(ChrPtr(summ1->from), ChrPtr(summ2->from));
164 * comparator for message summary structs by descending sender.
166 int summcmp_rsender(const void *s1, const void *s2) {
167 message_summary *summ1;
168 message_summary *summ2;
170 summ1 = (message_summary *)GetSearchPayload(s1);
171 summ2 = (message_summary *)GetSearchPayload(s2);
172 return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from));
175 * comparator for message summary structs by descending sender.
177 int groupchange_sender(const void *s1, const void *s2) {
178 message_summary *summ1;
179 message_summary *summ2;
181 summ1 = (message_summary *)s1;
182 summ2 = (message_summary *)s2;
183 return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from)) != 0;
188 * comparator for message summary structs by ascending date.
190 int summcmp_date(const void *s1, const void *s2) {
191 message_summary *summ1;
192 message_summary *summ2;
194 summ1 = (message_summary *)GetSearchPayload(s1);
195 summ2 = (message_summary *)GetSearchPayload(s2);
197 if (summ1->date < summ2->date) return -1;
198 else if (summ1->date > summ2->date) return +1;
203 * comparator for message summary structs by descending date.
205 int summcmp_rdate(const void *s1, const void *s2) {
206 message_summary *summ1;
207 message_summary *summ2;
209 summ1 = (message_summary *)GetSearchPayload(s1);
210 summ2 = (message_summary *)GetSearchPayload(s2);
212 if (summ1->date < summ2->date) return +1;
213 else if (summ1->date > summ2->date) return -1;
218 * comparator for message summary structs by descending date.
220 const long DAYSECONDS = 24 * 60 * 60;
221 int groupchange_date(const void *s1, const void *s2) {
222 message_summary *summ1;
223 message_summary *summ2;
225 summ1 = (message_summary *)s1;
226 summ2 = (message_summary *)s2;
228 return (summ1->date % DAYSECONDS) != (summ2->date %DAYSECONDS);
232 /*----------------------------------------------------------------------------*/
233 /* Don't wanna know... or? */
234 void examine_pref(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
235 void examine_suff(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
236 void examine_path(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
237 void examine_content_encoding(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
239 /* TODO: do we care? */
242 void examine_nhdr(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
245 if (!strncasecmp(ChrPtr(HdrLine), "yes", 8))
248 int Conditional_ANONYMOUS_MESSAGE(StrBuf *Target, WCTemplputParams *TP)
250 message_summary *Msg = (message_summary*) CTX;
251 return Msg->nhdr != 0;
254 void examine_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
256 Msg->format_type = StrToi(HdrLine);
260 void examine_from(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
264 CheckConvertBufs(WCC);
265 FreeStrBuf(&Msg->from);
266 Msg->from = NewStrBufPlain(NULL, StrLength(HdrLine));
267 StrBuf_RFC822_2_Utf8(Msg->from,
274 void tmplput_MAIL_SUMM_FROM(StrBuf *Target, WCTemplputParams *TP)
276 message_summary *Msg = (message_summary*) CTX;
277 StrBufAppendTemplate(Target, TP, Msg->from, 0);
280 void examine_subj(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
284 CheckConvertBufs(WCC);
285 FreeStrBuf(&Msg->subj);
286 Msg->subj = NewStrBufPlain(NULL, StrLength(HdrLine));
287 StrBuf_RFC822_2_Utf8(Msg->subj,
294 void tmplput_MAIL_SUMM_SUBJECT(StrBuf *Target, WCTemplputParams *TP)
296 message_summary *Msg = (message_summary*) CTX;
298 if (TP->Tokens->nParameters == 4)
303 GetTemplateTokenString(Target, TP, 3, &pch, &len);
305 (strstr(ChrPtr(Msg->subj), pch) == NULL))
307 GetTemplateTokenString(Target, TP, 2, &pch, &len);
308 StrBufAppendBufPlain(Target, pch, len, 0);
311 StrBufAppendTemplate(Target, TP, Msg->subj, 0);
313 int Conditional_MAIL_SUMM_SUBJECT(StrBuf *Target, WCTemplputParams *TP)
315 message_summary *Msg = (message_summary*) CTX;
318 return StrLength(Msg->subj) > 0;
322 void examine_msgn(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
326 CheckConvertBufs(WCC);
327 FreeStrBuf(&Msg->reply_inreplyto);
328 Msg->reply_inreplyto = NewStrBufPlain(NULL, StrLength(HdrLine));
329 StrBuf_RFC822_2_Utf8(Msg->reply_inreplyto,
336 void tmplput_MAIL_SUMM_INREPLYTO(StrBuf *Target, WCTemplputParams *TP)
338 message_summary *Msg = (message_summary*) CTX;
339 StrBufAppendTemplate(Target, TP, Msg->reply_inreplyto, 0);
342 int Conditional_MAIL_SUMM_UNREAD(StrBuf *Target, WCTemplputParams *TP)
344 message_summary *Msg = (message_summary*) CTX;
345 return (Msg->Flags & MSGFLAG_READ) != 0;
348 void examine_wefw(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
352 CheckConvertBufs(WCC);
353 FreeStrBuf(&Msg->reply_references);
354 Msg->reply_references = NewStrBufPlain(NULL, StrLength(HdrLine));
355 StrBuf_RFC822_2_Utf8(Msg->reply_references,
362 void tmplput_MAIL_SUMM_REFIDS(StrBuf *Target, WCTemplputParams *TP)
364 message_summary *Msg = (message_summary*) CTX;
365 StrBufAppendTemplate(Target, TP, Msg->reply_references, 0);
369 void examine_cccc(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
373 CheckConvertBufs(WCC);
374 FreeStrBuf(&Msg->cccc);
375 Msg->cccc = NewStrBufPlain(NULL, StrLength(HdrLine));
376 StrBuf_RFC822_2_Utf8(Msg->cccc,
382 if (Msg->AllRcpt == NULL)
383 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
384 if (StrLength(Msg->AllRcpt) > 0) {
385 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
387 StrBufAppendBuf(Msg->AllRcpt, Msg->cccc, 0);
389 void tmplput_MAIL_SUMM_CCCC(StrBuf *Target, WCTemplputParams *TP)
391 message_summary *Msg = (message_summary*) CTX;
392 StrBufAppendTemplate(Target, TP, Msg->cccc, 0);
396 void examine_room(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
398 if ((StrLength(HdrLine) > 0) &&
399 (strcasecmp(ChrPtr(HdrLine), ChrPtr(WC->CurRoom.name)))) {
400 FreeStrBuf(&Msg->Room);
401 Msg->Room = NewStrBufDup(HdrLine);
404 void tmplput_MAIL_SUMM_ORGROOM(StrBuf *Target, WCTemplputParams *TP)
406 message_summary *Msg = (message_summary*) CTX;
407 StrBufAppendTemplate(Target, TP, Msg->Room, 0);
411 void examine_rfca(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
413 FreeStrBuf(&Msg->Rfca);
414 Msg->Rfca = NewStrBufDup(HdrLine);
416 void tmplput_MAIL_SUMM_RFCA(StrBuf *Target, WCTemplputParams *TP)
418 message_summary *Msg = (message_summary*) CTX;
419 StrBufAppendTemplate(Target, TP, Msg->Rfca, 0);
421 int Conditional_MAIL_SUMM_RFCA(StrBuf *Target, WCTemplputParams *TP)
423 message_summary *Msg = (message_summary*) CTX;
424 return StrLength(Msg->Rfca) > 0;
426 int Conditional_MAIL_SUMM_CCCC(StrBuf *Target, WCTemplputParams *TP)
428 message_summary *Msg = (message_summary*) CTX;
429 return StrLength(Msg->cccc) > 0;
432 void examine_node(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
436 if ( (StrLength(HdrLine) > 0) &&
437 ((WC->CurRoom.QRFlags & QR_NETWORK)
438 || ((strcasecmp(ChrPtr(HdrLine), ChrPtr(WCC->serv_info->serv_nodename))
439 && (strcasecmp(ChrPtr(HdrLine), ChrPtr(WCC->serv_info->serv_fqdn))))))) {
440 FreeStrBuf(&Msg->OtherNode);
441 Msg->OtherNode = NewStrBufDup(HdrLine);
444 void tmplput_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP)
446 message_summary *Msg = (message_summary*) CTX;
447 StrBufAppendTemplate(Target, TP, Msg->OtherNode, 0);
449 int Conditional_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP)
451 message_summary *Msg = (message_summary*) CTX;
452 return StrLength(Msg->OtherNode) > 0;
456 void examine_rcpt(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
460 CheckConvertBufs(WCC);
461 FreeStrBuf(&Msg->to);
462 Msg->to = NewStrBufPlain(NULL, StrLength(HdrLine));
463 StrBuf_RFC822_2_Utf8(Msg->to,
469 if (Msg->AllRcpt == NULL)
470 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
471 if (StrLength(Msg->AllRcpt) > 0) {
472 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
474 StrBufAppendBuf(Msg->AllRcpt, Msg->to, 0);
476 void tmplput_MAIL_SUMM_TO(StrBuf *Target, WCTemplputParams *TP)
478 message_summary *Msg = (message_summary*) CTX;
479 StrBufAppendTemplate(Target, TP, Msg->to, 0);
481 int Conditional_MAIL_SUMM_TO(StrBuf *Target, WCTemplputParams *TP)
483 message_summary *Msg = (message_summary*) CTX;
484 return StrLength(Msg->to) != 0;
486 int Conditional_MAIL_SUMM_SUBJ(StrBuf *Target, WCTemplputParams *TP)
488 message_summary *Msg = (message_summary*) CTX;
489 return StrLength(Msg->subj) != 0;
491 void tmplput_MAIL_SUMM_ALLRCPT(StrBuf *Target, WCTemplputParams *TP)
493 message_summary *Msg = (message_summary*) CTX;
494 StrBufAppendTemplate(Target, TP, Msg->AllRcpt, 0);
499 void tmplput_SUMM_COUNT(StrBuf *Target, WCTemplputParams *TP)
501 StrBufAppendPrintf(Target, "%d", GetCount( WC->summ));
504 HashList *iterate_get_mailsumm_All(StrBuf *Target, WCTemplputParams *TP)
508 void examine_time(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
510 Msg->date = StrTol(HdrLine);
513 void tmplput_MAIL_SUMM_DATE_BRIEF(StrBuf *Target, WCTemplputParams *TP)
516 message_summary *Msg = (message_summary*) CTX;
517 webcit_fmt_date(datebuf, 64, Msg->date, DATEFMT_BRIEF);
518 StrBufAppendBufPlain(Target, datebuf, -1, 0);
521 void tmplput_MAIL_SUMM_EUID(StrBuf *Target, WCTemplputParams *TP)
523 message_summary *Msg = (message_summary*) CTX;
524 StrBufAppendTemplate(Target, TP, Msg->euid, 0);
527 void tmplput_MAIL_SUMM_DATE_FULL(StrBuf *Target, WCTemplputParams *TP)
530 message_summary *Msg = (message_summary*) CTX;
531 webcit_fmt_date(datebuf, 64, Msg->date, DATEFMT_FULL);
532 StrBufAppendBufPlain(Target, datebuf, -1, 0);
534 void tmplput_MAIL_SUMM_DATE_NO(StrBuf *Target, WCTemplputParams *TP)
536 message_summary *Msg = (message_summary*) CTX;
537 StrBufAppendPrintf(Target, "%ld", Msg->date, 0);
542 void render_MAIL(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
544 const StrBuf *TemplateMime;
546 if (Mime->Data == NULL)
547 Mime->Data = NewStrBufPlain(NULL, Mime->length);
549 FlushStrBuf(Mime->Data);
550 read_message(Mime->Data, HKEY("view_submessage"), Mime->msgnum, Mime->PartNum, &TemplateMime);
552 if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
553 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
554 extract_token(buf, mime_submessages, i, '|', sizeof buf);
555 / ** use printable_view to suppress buttons * /
556 wc_printf("<blockquote>");
557 read_message(Mime->msgnum, 1, ChrPtr(Mime->Section));
558 wc_printf("</blockquote>");
564 void render_MIME_VCard(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
567 if (StrLength(Mime->Data) == 0)
569 if (StrLength(Mime->Data) > 0) {
572 /** If it's my vCard I can edit it */
573 if ( (!strcasecmp(ChrPtr(WCC->CurRoom.name), USERCONFIGROOM))
574 || (!strcasecmp(&(ChrPtr(WCC->CurRoom.name)[11]), USERCONFIGROOM))
575 || (WC->CurRoom.view == VIEW_ADDRESSBOOK)
577 StrBufAppendPrintf(Buf, "<a href=\"edit_vcard?msgnum=%ld?partnum=%s\">",
578 Mime->msgnum, ChrPtr(Mime->PartNum));
579 StrBufAppendPrintf(Buf, "[%s]</a>", _("edit"));
582 /* In all cases, display the full card */
583 display_vcard(Buf, Mime, 0, 1, NULL, -1);
584 FreeStrBuf(&Mime->Data);
590 void render_MIME_VNote(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
592 if (StrLength(Mime->Data) == 0)
594 if (StrLength(Mime->Data) > 0) {
600 vcard = SmashStrBuf(&Mime->Data);
601 v = vnote_new_from_str(vcard);
606 memset(&TP, 0, sizeof(WCTemplputParams));
607 TP.Filter.ContextType = CTX_VNOTE;
609 DoTemplate(HKEY("mail_vnoteitem"),
616 if (Mime->Data == NULL)
617 Mime->Data = NewStrBuf();
619 FlushStrBuf(Mime->Data);
624 void render_MIME_ICS(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
626 if (StrLength(Mime->Data) == 0) {
629 if (StrLength(Mime->Data) > 0) {
630 cal_process_attachment(Mime);
636 void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
638 const char *Ptr = NULL;
639 wc_mime_attachment *Mime;
643 CheckConvertBufs(WCC);
644 Mime = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
645 memset(Mime, 0, sizeof(wc_mime_attachment));
646 Mime->msgnum = Msg->msgnum;
649 Mime->Name = NewStrBuf();
650 StrBufExtract_NextToken(Buf, HdrLine, &Ptr, '|');
651 StrBuf_RFC822_2_Utf8(Mime->Name,
657 StrBufTrim(Mime->Name);
659 StrBufExtract_NextToken(Buf, HdrLine, &Ptr, '|');
660 Mime->FileName = NewStrBuf();
661 StrBuf_RFC822_2_Utf8(Mime->FileName,
667 StrBufTrim(Mime->FileName);
669 Mime->PartNum = NewStrBuf();
670 StrBufExtract_NextToken(Mime->PartNum, HdrLine, &Ptr, '|');
671 StrBufTrim(Mime->PartNum);
672 if (strchr(ChrPtr(Mime->PartNum), '.') != NULL)
677 Mime->Disposition = NewStrBuf();
678 StrBufExtract_NextToken(Mime->Disposition, HdrLine, &Ptr, '|');
680 Mime->ContentType = NewStrBuf();
681 StrBufExtract_NextToken(Mime->ContentType, HdrLine, &Ptr, '|');
682 StrBufTrim(Mime->ContentType);
683 StrBufLowerCase(Mime->ContentType);
684 if (!strcmp(ChrPtr(Mime->ContentType), "application/octet-stream")) {
685 StrBufPlain(Mime->ContentType,
686 GuessMimeByFilename(SKEY(Mime->FileName)), -1);
689 Mime->length = StrBufExtractNext_int(HdrLine, &Ptr, '|');
691 StrBufSkip_NTokenS(HdrLine, &Ptr, '|', 1); /* cbid?? */
693 Mime->Charset = NewStrBuf();
694 StrBufExtract_NextToken(Mime->Charset, HdrLine, &Ptr, '|');
697 if ( (StrLength(Mime->FileName) == 0) && (StrLength(Mime->Name) > 0) ) {
698 StrBufAppendBuf(Mime->FileName, Mime->Name, 0);
701 if (StrLength(Msg->PartNum) > 0) {
703 StrBufPrintf(Buf, "%s.%s", ChrPtr(Msg->PartNum), ChrPtr(Mime->PartNum));
709 if (Msg->AllAttach == NULL)
710 Msg->AllAttach = NewHash(1,NULL);
711 Put(Msg->AllAttach, SKEY(Mime->PartNum), Mime, DestroyMime);
716 void evaluate_mime_part(message_summary *Msg, wc_mime_attachment *Mime)
720 /* just print the root-node */
721 if ((Mime->level >= 1) &&
722 GetHash(MimeRenderHandler, SKEY(Mime->ContentType), &vMimeRenderer) &&
723 vMimeRenderer != NULL)
725 Mime->Renderer = (RenderMimeFuncStruct*) vMimeRenderer;
726 if (Msg->Submessages == NULL)
727 Msg->Submessages = NewHash(1,NULL);
728 Put(Msg->Submessages, SKEY(Mime->PartNum), Mime, reference_free_handler);
730 else if ((Mime->level >= 1) &&
731 (!strcasecmp(ChrPtr(Mime->Disposition), "inline"))
732 && (!strncasecmp(ChrPtr(Mime->ContentType), "image/", 6)) ){
733 if (Msg->AttachLinks == NULL)
734 Msg->AttachLinks = NewHash(1,NULL);
735 Put(Msg->AttachLinks, SKEY(Mime->PartNum), Mime, reference_free_handler);
737 else if ((Mime->level >= 1) &&
738 (StrLength(Mime->ContentType) > 0) &&
739 ( (!strcasecmp(ChrPtr(Mime->Disposition), "attachment"))
740 || (!strcasecmp(ChrPtr(Mime->Disposition), "inline"))
741 || (!strcasecmp(ChrPtr(Mime->Disposition), ""))))
743 if (Msg->AttachLinks == NULL)
744 Msg->AttachLinks = NewHash(1,NULL);
745 Put(Msg->AttachLinks, SKEY(Mime->PartNum), Mime, reference_free_handler);
746 if ((strcasecmp(ChrPtr(Mime->ContentType), "application/octet-stream") == 0) &&
747 (StrLength(Mime->FileName) > 0)) {
748 FlushStrBuf(Mime->ContentType);
749 StrBufAppendBufPlain(Mime->ContentType,
750 GuessMimeByFilename(SKEY(Mime->FileName)),
756 void tmplput_MAIL_SUMM_NATTACH(StrBuf *Target, WCTemplputParams *TP)
758 message_summary *Msg = (message_summary*) CTX;
759 StrBufAppendPrintf(Target, "%ld", GetCount(Msg->Attachments));
763 void examine_hnod(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
767 CheckConvertBufs(WCC);
768 FreeStrBuf(&Msg->hnod);
769 Msg->hnod = NewStrBufPlain(NULL, StrLength(HdrLine));
770 StrBuf_RFC822_2_Utf8(Msg->hnod,
777 void tmplput_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP)
779 message_summary *Msg = (message_summary*) CTX;
780 StrBufAppendTemplate(Target, TP, Msg->hnod, 0);
782 int Conditional_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP)
784 message_summary *Msg = (message_summary*) CTX;
785 return StrLength(Msg->hnod) > 0;
790 void examine_text(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
792 if (Msg->MsgBody->Data == NULL)
793 Msg->MsgBody->Data = NewStrBufPlain(NULL, SIZ);
795 FlushStrBuf(Msg->MsgBody->Data);
798 void examine_msg4_partnum(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
800 Msg->MsgBody->PartNum = NewStrBufDup(HdrLine);
801 StrBufTrim(Msg->MsgBody->PartNum);
804 void examine_content_lengh(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
806 Msg->MsgBody->length = StrTol(HdrLine);
807 Msg->MsgBody->size_known = 1;
810 void examine_content_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
820 Msg->MsgBody->ContentType = NewStrBufDup(HdrLine);
821 sem = strchr(ChrPtr(HdrLine), ';');
824 Token = NewStrBufPlain(NULL, StrLength(HdrLine));
825 Value = NewStrBufPlain(NULL, StrLength(HdrLine));
826 len = sem - ChrPtr(HdrLine);
827 StrBufCutAt(Msg->MsgBody->ContentType, len, NULL);
828 while (sem != NULL) {
829 while (isspace(*(sem + 1)))
831 StrBufCutLeft(HdrLine, sem - ChrPtr(HdrLine));
832 sem = strchr(ChrPtr(HdrLine), ';');
834 len = sem - ChrPtr(HdrLine);
836 len = StrLength(HdrLine);
839 StrBufAppendBufPlain(Token, ChrPtr(HdrLine), len, 0);
840 eq = strchr(ChrPtr(Token), '=');
842 len = eq - ChrPtr(Token);
843 StrBufAppendBufPlain(Value, eq + 1, StrLength(Token) - len - 1, 0);
844 StrBufCutAt(Token, len, NULL);
849 if (GetHash(MsgHeaderHandler, SKEY(Token), &vHdr) &&
851 Hdr = (headereval*)vHdr;
852 Hdr->evaluator(Msg, Value, FoundCharset);
854 else syslog(1, "don't know how to handle content type sub-header[%s]\n", ChrPtr(Token));
861 void tmplput_MAIL_SUMM_N(StrBuf *Target, WCTemplputParams *TP)
863 message_summary *Msg = (message_summary*) CTX;
864 StrBufAppendPrintf(Target, "%ld", Msg->msgnum);
868 void tmplput_MAIL_SUMM_PERMALINK(StrBuf *Target, WCTemplputParams *TP)
870 message_summary *Msg = (message_summary*) CTX;
871 char perma_link[1024];
873 strcpy(perma_link, "/readfwd?go=");
874 urlesc(&perma_link[12], sizeof(perma_link) - 12, (char *)ChrPtr(WC->CurRoom.name) );
875 sprintf(&perma_link[strlen(perma_link)], "?start_reading_at=%ld#%ld", Msg->msgnum, Msg->msgnum);
876 StrBufAppendPrintf(Target, "%s", perma_link);
880 int Conditional_MAIL_MIME_ALL(StrBuf *Target, WCTemplputParams *TP)
882 message_summary *Msg = (message_summary*) CTX;
883 return GetCount(Msg->Attachments) > 0;
886 int Conditional_MAIL_MIME_SUBMESSAGES(StrBuf *Target, WCTemplputParams *TP)
888 message_summary *Msg = (message_summary*) CTX;
889 return GetCount(Msg->Submessages) > 0;
892 int Conditional_MAIL_MIME_ATTACHLINKS(StrBuf *Target, WCTemplputParams *TP)
894 message_summary *Msg = (message_summary*) CTX;
895 return GetCount(Msg->AttachLinks) > 0;
898 int Conditional_MAIL_MIME_ATTACH(StrBuf *Target, WCTemplputParams *TP)
900 message_summary *Msg = (message_summary*) CTX;
901 return GetCount(Msg->AllAttach) > 0;
904 void tmplput_QUOTED_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
910 MsgNum = LBstr(TKEY(0));
912 read_message(Buf, HKEY("view_message_replyquote"), MsgNum, NULL, &Mime);
913 StrBufAppendTemplate(Target, TP, Buf, 1);
917 void tmplput_EDIT_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
923 MsgNum = LBstr(TKEY(0));
925 read_message(Buf, HKEY("view_message_edit"), MsgNum, NULL, &Mime);
926 StrBufAppendTemplate(Target, TP, Buf, 1);
930 void tmplput_EDIT_WIKI_BODY(StrBuf *Target, WCTemplputParams *TP)
936 /* Insert the existing content of the wiki page into the editor. But we only want
937 * to do this the first time -- if the user is uploading an attachment we don't want
940 if (!havebstr("attach_button")) {
941 char *wikipage = strdup(bstr("page"));
942 str_wiki_index(wikipage);
943 msgnum = locate_message_by_uid(wikipage);
947 read_message(Buf, HKEY("view_message_wikiedit"), msgnum, NULL, &Mime);
948 StrBufAppendTemplate(Target, TP, Buf, 1);
954 void tmplput_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
956 message_summary *Msg = (message_summary*) CTX;
957 StrBufAppendTemplate(Target, TP, Msg->MsgBody->Data, 0);
961 void render_MAIL_variformat(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
963 /* Messages in legacy Citadel variformat get handled thusly... */
964 StrBuf *Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
965 FmOut(Target, "JUSTIFY", Mime->Data);
966 FreeStrBuf(&Mime->Data);
970 void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
972 const char *ptr, *pte;
973 const char *BufPtr = NULL;
987 iconv_t ic = (iconv_t)(-1) ;
990 if ((StrLength(Mime->Data) == 0) && (Mime->length > 0)) {
991 FreeStrBuf(&Mime->Data);
997 if (StrLength(Mime->Charset) != 0)
999 else if (StrLength(FoundCharset) > 0)
1001 else if (StrLength(WC->DefaultCharset) > 0)
1002 cs = WC->DefaultCharset;
1006 else if (!strcasecmp(ChrPtr(cs), "utf-8")) {
1009 else if (!strcasecmp(ChrPtr(cs), "us-ascii")) {
1013 ctdl_iconv_open("UTF-8", ChrPtr(cs), &ic);
1014 if (ic == (iconv_t)(-1) ) {
1015 syslog(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
1016 __FILE__, __LINE__, ChrPtr(Mime->Charset), strerror(errno));
1021 Line = NewStrBufPlain(NULL, SIZ);
1022 Line1 = NewStrBufPlain(NULL, SIZ);
1023 Line2 = NewStrBufPlain(NULL, SIZ);
1024 Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
1027 if (StrLength(Mime->Data) > 0)
1030 StrBufSipLine(Line, Mime->Data, &BufPtr);
1034 len = StrLength(Line);
1037 while ((ptr < pte) &&
1046 if (i > 0) StrBufCutLeft(Line, i);
1048 if (StrLength(Line) == 0) {
1051 StrBufAppendBufPlain(Target, HKEY("<tt></tt><br>\n"), 0);
1057 for (i = bn; i < bq; i++)
1058 StrBufAppendBufPlain(Target, HKEY("<blockquote>"), 0);
1059 for (i = bq; i < bn; i++)
1060 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
1063 StrBufConvert(Line, Line1, &ic);
1066 StrBufAppendBufPlain(Target, HKEY("<tt>"), 0);
1067 UrlizeText(Line1, Line, Line2);
1069 StrEscAppend(Target, Line1, NULL, 0, 0);
1070 StrBufAppendBufPlain(Target, HKEY("</tt><br>\n"), 0);
1074 while ((BufPtr != StrBufNOTNULL) &&
1077 if (nEmptyLines > 0)
1078 StrBufCutRight(Target, nEmptyLines * (sizeof ("<tt></tt><br>\n") - 1));
1079 for (i = 0; i < bn; i++)
1080 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
1082 StrBufAppendBufPlain(Target, HKEY("</i><br>"), 0);
1084 if (ic != (iconv_t)(-1) ) {
1089 FreeStrBuf(&Mime->Data);
1090 Mime->Data = Target;
1091 FlushStrBuf(Mime->ContentType);
1092 StrBufAppendBufPlain(Mime->ContentType, HKEY("text/html"), 0);
1093 FlushStrBuf(Mime->Charset);
1094 StrBufAppendBufPlain(Mime->Charset, HKEY("UTF-8"), 0);
1100 void render_MAIL_html(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
1104 if (StrLength(Mime->Data) == 0)
1107 Buf = NewStrBufPlain(NULL, StrLength(Mime->Data));
1109 /* HTML is fun, but we've got to strip it first */
1110 output_html(ChrPtr(Mime->Charset),
1111 (WC->CurRoom.view == VIEW_WIKI ? 1 : 0),
1114 FreeStrBuf(&Mime->Data);
1118 void render_MAIL_UNKNOWN(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
1120 /* Unknown weirdness */
1121 FlushStrBuf(Mime->Data);
1122 StrBufAppendBufPlain(Mime->Data, _("I don't know how to display "), -1, 0);
1123 StrBufAppendBuf(Mime->Data, Mime->ContentType, 0);
1124 StrBufAppendBufPlain(Mime->Data, HKEY("<br>\n"), 0);
1128 HashList *iterate_get_mime_All(StrBuf *Target, WCTemplputParams *TP)
1130 message_summary *Msg = (message_summary*) CTX;
1131 return Msg->Attachments;
1133 HashList *iterate_get_mime_Submessages(StrBuf *Target, WCTemplputParams *TP)
1135 message_summary *Msg = (message_summary*) CTX;
1136 return Msg->Submessages;
1138 HashList *iterate_get_mime_AttachLinks(StrBuf *Target, WCTemplputParams *TP)
1140 message_summary *Msg = (message_summary*) CTX;
1141 return Msg->AttachLinks;
1143 HashList *iterate_get_mime_Attachments(StrBuf *Target, WCTemplputParams *TP)
1145 message_summary *Msg = (message_summary*) CTX;
1146 return Msg->AllAttach;
1149 void tmplput_MIME_Name(StrBuf *Target, WCTemplputParams *TP)
1151 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
1152 StrBufAppendTemplate(Target, TP, mime->Name, 0);
1155 void tmplput_MIME_FileName(StrBuf *Target, WCTemplputParams *TP)
1157 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
1158 StrBufAppendTemplate(Target, TP, mime->FileName, 0);
1161 void tmplput_MIME_PartNum(StrBuf *Target, WCTemplputParams *TP)
1163 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
1164 StrBufAppendTemplate(Target, TP, mime->PartNum, 0);
1167 void tmplput_MIME_MsgNum(StrBuf *Target, WCTemplputParams *TP)
1169 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
1170 StrBufAppendPrintf(Target, "%ld", mime->msgnum);
1173 void tmplput_MIME_Disposition(StrBuf *Target, WCTemplputParams *TP)
1175 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
1176 StrBufAppendTemplate(Target, TP, mime->Disposition, 0);
1179 void tmplput_MIME_ContentType(StrBuf *Target, WCTemplputParams *TP)
1181 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
1182 StrBufAppendTemplate(Target, TP, mime->ContentType, 0);
1185 void examine_charset(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
1187 Msg->MsgBody->Charset = NewStrBufDup(HdrLine);
1190 void tmplput_MIME_Charset(StrBuf *Target, WCTemplputParams *TP)
1192 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
1193 StrBufAppendTemplate(Target, TP, mime->Charset, 0);
1196 void tmplput_MIME_Data(StrBuf *Target, WCTemplputParams *TP)
1198 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
1199 if (mime->Renderer != NULL)
1200 mime->Renderer->f(mime, NULL, NULL);
1201 StrBufAppendTemplate(Target, TP, mime->Data, 0);
1202 /* TODO: check whether we need to load it now? */
1205 void tmplput_MIME_LoadData(StrBuf *Target, WCTemplputParams *TP)
1207 wcsession *WCC = WC;
1208 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
1209 wc_mime_attachment *att;
1211 if (( (!strcasecmp(ChrPtr(mime->Disposition), "inline"))||
1212 (!strcasecmp(ChrPtr(mime->Disposition), "attachment"))) &&
1213 (strcasecmp(ChrPtr(mime->ContentType), "application/ms-tnef")!=0))
1218 /* steal this mime part... */
1219 att = malloc(sizeof(wc_mime_attachment));
1220 memcpy(att, mime, sizeof(wc_mime_attachment));
1221 memset(mime, 0, sizeof(wc_mime_attachment));
1223 if (att->Data == NULL)
1226 if (WCC->attachments == NULL)
1227 WCC->attachments = NewHash(1, NULL);
1228 /* And add it to the list. */
1229 n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
1230 Put(WCC->attachments, N, n, att, DestroyMime);
1234 void tmplput_MIME_Length(StrBuf *Target, WCTemplputParams *TP)
1236 wc_mime_attachment *mime = (wc_mime_attachment*) CTX;
1237 StrBufAppendPrintf(Target, "%ld", mime->length);
1240 HashList *iterate_get_registered_Attachments(StrBuf *Target, WCTemplputParams *TP)
1242 return WC->attachments;
1245 void get_registered_Attachments_Count(StrBuf *Target, WCTemplputParams *TP)
1247 StrBufAppendPrintf(Target, "%ld", GetCount (WC->attachments));
1250 void servcmd_do_search(char *buf, long bufsize)
1252 snprintf(buf, bufsize, "MSGS SEARCH|%s", bstr("query"));
1255 void servcmd_headers(char *buf, long bufsize)
1257 snprintf(buf, bufsize, "MSGS ALL");
1260 void servcmd_readfwd(char *buf, long bufsize)
1262 snprintf(buf, bufsize, "MSGS ALL");
1265 void servcmd_readgt(char *buf, long bufsize)
1267 snprintf(buf, bufsize, "MSGS GT|%s", bstr("gt"));
1270 void servcmd_readlt(char *buf, long bufsize)
1272 snprintf(buf, bufsize, "MSGS LT|%s", bstr("lt"));
1275 void servcmd_readnew(char *buf, long bufsize)
1277 snprintf(buf, bufsize, "MSGS NEW");
1280 void servcmd_readold(char *buf, long bufsize)
1282 snprintf(buf, bufsize, "MSGS OLD");
1286 /* DO NOT REORDER OR REMOVE ANY OF THESE */
1287 readloop_struct rlid[] = {
1288 { {HKEY("do_search")}, servcmd_do_search },
1289 { {HKEY("headers")}, servcmd_headers },
1290 { {HKEY("readfwd")}, servcmd_readfwd },
1291 { {HKEY("readnew")}, servcmd_readnew },
1292 { {HKEY("readold")}, servcmd_readold },
1293 { {HKEY("readgt")}, servcmd_readgt },
1294 { {HKEY("readlt")}, servcmd_readlt }
1298 int ParseMessageListHeaders_Detail(StrBuf *Line,
1300 message_summary *Msg,
1301 StrBuf *ConversionBuffer)
1303 wcsession *WCC = WC;
1307 CheckConvertBufs(WCC);
1309 totallen = StrLength(Line);
1310 Msg->from = NewStrBufPlain(NULL, totallen);
1311 len = StrBufExtract_NextToken(ConversionBuffer, Line, pos, '|');
1313 /* Handle senders with RFC2047 encoding */
1314 StrBuf_RFC822_2_Utf8(Msg->from,
1316 WCC->DefaultCharset,
1323 len = StrBufExtract_NextToken(ConversionBuffer, Line, pos, '|');
1325 ( ((WCC->CurRoom.QRFlags & QR_NETWORK)
1326 || ((strcasecmp(ChrPtr(ConversionBuffer), ChrPtr(WCC->serv_info->serv_nodename))
1327 && (strcasecmp(ChrPtr(ConversionBuffer), ChrPtr(WCC->serv_info->serv_fqdn))))))))
1329 StrBufAppendBufPlain(Msg->from, HKEY(" @ "), 0);
1330 StrBufAppendBuf(Msg->from, ConversionBuffer, 0);
1333 /* Internet address (not used)
1334 * StrBufExtract_token(Msg->inetaddr, Line, 4, '|');
1336 StrBufSkip_NTokenS(Line, pos, '|', 1);
1337 Msg->subj = NewStrBufPlain(NULL, totallen);
1339 FlushStrBuf(ConversionBuffer);
1340 /* we assume the subject is the last parameter inside of the list;
1341 * thus we don't use the tokenizer to fetch it, since it will hick up
1342 * on tokenizer chars inside of the subjects
1343 StrBufExtract_NextToken(ConversionBuffer, Line, pos, '|');
1346 if (*pos != StrBufNOTNULL) {
1347 len = totallen - (*pos - ChrPtr(Line));
1348 StrBufPlain(ConversionBuffer, *pos, len);
1349 *pos = StrBufNOTNULL;
1351 (*(ChrPtr(ConversionBuffer) + len - 1) == '|'))
1352 StrBufCutRight(ConversionBuffer, 1);
1356 StrBufAppendBufPlain(Msg->subj, _("(no subject)"), -1,0);
1358 StrBuf_RFC822_2_Utf8(Msg->subj,
1360 WCC->DefaultCharset,
1370 int mailview_GetParamsGetServerCall(SharedMessageStatus *Stat,
1371 void **ViewSpecific,
1378 DoTemplate(HKEY("msg_listview"),NULL,&NoCtx);
1383 int mailview_Cleanup(void **ViewSpecific)
1385 /* Note: wDumpContent() will output one additional </div> tag. */
1386 /* We ought to move this out into template */
1393 int json_GetParamsGetServerCall(SharedMessageStatus *Stat,
1394 void **ViewSpecific,
1401 Stat->defaultsortorder = 2;
1403 Stat->load_seen = 1;
1404 /* Generally using maxmsgs|startmsg is not required
1405 in mailbox view, but we have a 'safemode' for clients
1406 (*cough* Exploder) that simply can't handle too many */
1407 if (havebstr("maxmsgs")) Stat->maxmsgs = ibstr("maxmsgs");
1408 else Stat->maxmsgs = 9999999;
1409 if (havebstr("startmsg")) Stat->startmsg = lbstr("startmsg");
1410 snprintf(cmd, len, "MSGS %s|%s||1",
1411 (oper == do_search) ? "SEARCH" : "ALL",
1412 (oper == do_search) ? bstr("query") : ""
1417 int json_MessageListHdr(SharedMessageStatus *Stat, void **ViewSpecific)
1419 /* TODO: make a generic function */
1420 hprintf("HTTP/1.1 200 OK\r\n");
1421 hprintf("Content-type: application/json; charset=utf-8\r\n");
1422 hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
1423 hprintf("Connection: close\r\n");
1424 hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
1429 int json_RenderView_or_Tail(SharedMessageStatus *Stat,
1430 void **ViewSpecific,
1433 WCTemplputParams SubTP;
1435 memset(&SubTP, 0, sizeof(WCTemplputParams));
1436 DoTemplate(HKEY("mailsummary_json"),NULL, &SubTP);
1441 int json_Cleanup(void **ViewSpecific)
1443 /* Note: wDumpContent() will output one additional </div> tag. */
1444 /* We ought to move this out into template */
1453 InitModule_MSGRENDERERS
1456 RegisterReadLoopHandlerset(
1458 mailview_GetParamsGetServerCall,
1459 NULL, /* TODO: is this right? */
1461 ParseMessageListHeaders_Detail,
1466 RegisterReadLoopHandlerset(
1468 json_GetParamsGetServerCall,
1469 json_MessageListHdr,
1470 NULL, /* TODO: is this right? */
1471 ParseMessageListHeaders_Detail,
1473 json_RenderView_or_Tail,
1476 RegisterSortFunc(HKEY("date"),
1482 RegisterSortFunc(HKEY("subject"),
1488 RegisterSortFunc(HKEY("sender"),
1495 RegisterNamespace("SUMM:COUNT", 0, 0, tmplput_SUMM_COUNT, NULL, CTX_NONE);
1496 /* iterate over all known mails in WC->summ */
1497 RegisterIterator("MAIL:SUMM:MSGS", 0, NULL, iterate_get_mailsumm_All,
1498 NULL,NULL, CTX_MAILSUM, CTX_NONE, IT_NOFLAG);
1500 RegisterNamespace("MAIL:SUMM:EUID", 0, 1, tmplput_MAIL_SUMM_EUID, NULL, CTX_MAILSUM);
1501 RegisterNamespace("MAIL:SUMM:DATEBRIEF", 0, 0, tmplput_MAIL_SUMM_DATE_BRIEF, NULL, CTX_MAILSUM);
1502 RegisterNamespace("MAIL:SUMM:DATEFULL", 0, 0, tmplput_MAIL_SUMM_DATE_FULL, NULL, CTX_MAILSUM);
1503 RegisterNamespace("MAIL:SUMM:DATENO", 0, 0, tmplput_MAIL_SUMM_DATE_NO, NULL, CTX_MAILSUM);
1504 RegisterNamespace("MAIL:SUMM:N", 0, 0, tmplput_MAIL_SUMM_N, NULL, CTX_MAILSUM);
1505 RegisterNamespace("MAIL:SUMM:PERMALINK", 0, 0, tmplput_MAIL_SUMM_PERMALINK, NULL, CTX_MAILSUM);
1506 RegisterNamespace("MAIL:SUMM:FROM", 0, 2, tmplput_MAIL_SUMM_FROM, NULL, CTX_MAILSUM);
1507 RegisterNamespace("MAIL:SUMM:TO", 0, 2, tmplput_MAIL_SUMM_TO, NULL, CTX_MAILSUM);
1508 RegisterNamespace("MAIL:SUMM:SUBJECT", 0, 4, tmplput_MAIL_SUMM_SUBJECT, NULL, CTX_MAILSUM);
1509 RegisterNamespace("MAIL:SUMM:NTATACH", 0, 0, tmplput_MAIL_SUMM_NATTACH, NULL, CTX_MAILSUM);
1510 RegisterNamespace("MAIL:SUMM:CCCC", 0, 2, tmplput_MAIL_SUMM_CCCC, NULL, CTX_MAILSUM);
1511 RegisterNamespace("MAIL:SUMM:H_NODE", 0, 2, tmplput_MAIL_SUMM_H_NODE, NULL, CTX_MAILSUM);
1512 RegisterNamespace("MAIL:SUMM:ALLRCPT", 0, 2, tmplput_MAIL_SUMM_ALLRCPT, NULL, CTX_MAILSUM);
1513 RegisterNamespace("MAIL:SUMM:ORGROOM", 0, 2, tmplput_MAIL_SUMM_ORGROOM, NULL, CTX_MAILSUM);
1514 RegisterNamespace("MAIL:SUMM:RFCA", 0, 2, tmplput_MAIL_SUMM_RFCA, NULL, CTX_MAILSUM);
1515 RegisterNamespace("MAIL:SUMM:OTHERNODE", 2, 0, tmplput_MAIL_SUMM_OTHERNODE, NULL, CTX_MAILSUM);
1516 RegisterNamespace("MAIL:SUMM:REFIDS", 0, 1, tmplput_MAIL_SUMM_REFIDS, NULL, CTX_MAILSUM);
1517 RegisterNamespace("MAIL:SUMM:INREPLYTO", 0, 2, tmplput_MAIL_SUMM_INREPLYTO, NULL, CTX_MAILSUM);
1518 RegisterNamespace("MAIL:BODY", 0, 2, tmplput_MAIL_BODY, NULL, CTX_MAILSUM);
1519 RegisterNamespace("MAIL:QUOTETEXT", 1, 2, tmplput_QUOTED_MAIL_BODY, NULL, CTX_NONE);
1520 RegisterNamespace("MAIL:EDITTEXT", 1, 2, tmplput_EDIT_MAIL_BODY, NULL, CTX_NONE);
1521 RegisterNamespace("MAIL:EDITWIKI", 1, 2, tmplput_EDIT_WIKI_BODY, NULL, CTX_NONE);
1522 RegisterConditional(HKEY("COND:MAIL:SUMM:RFCA"), 0, Conditional_MAIL_SUMM_RFCA, CTX_MAILSUM);
1523 RegisterConditional(HKEY("COND:MAIL:SUMM:CCCC"), 0, Conditional_MAIL_SUMM_CCCC, CTX_MAILSUM);
1524 RegisterConditional(HKEY("COND:MAIL:SUMM:UNREAD"), 0, Conditional_MAIL_SUMM_UNREAD, CTX_MAILSUM);
1525 RegisterConditional(HKEY("COND:MAIL:SUMM:H_NODE"), 0, Conditional_MAIL_SUMM_H_NODE, CTX_MAILSUM);
1526 RegisterConditional(HKEY("COND:MAIL:SUMM:OTHERNODE"), 0, Conditional_MAIL_SUMM_OTHERNODE, CTX_MAILSUM);
1527 RegisterConditional(HKEY("COND:MAIL:SUMM:SUBJECT"), 0, Conditional_MAIL_SUMM_SUBJECT, CTX_MAILSUM);
1528 RegisterConditional(HKEY("COND:MAIL:ANON"), 0, Conditional_ANONYMOUS_MESSAGE, CTX_MAILSUM);
1529 RegisterConditional(HKEY("COND:MAIL:TO"), 0, Conditional_MAIL_SUMM_TO, CTX_MAILSUM);
1530 RegisterConditional(HKEY("COND:MAIL:SUBJ"), 0, Conditional_MAIL_SUMM_SUBJ, CTX_MAILSUM);
1532 /* do we have mimetypes to iterate over? */
1533 RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH"), 0, Conditional_MAIL_MIME_ALL, CTX_MAILSUM);
1534 RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:SUBMESSAGES"), 0, Conditional_MAIL_MIME_SUBMESSAGES, CTX_MAILSUM);
1535 RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:LINKS"), 0, Conditional_MAIL_MIME_ATTACHLINKS, CTX_MAILSUM);
1536 RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:ATT"), 0, Conditional_MAIL_MIME_ATTACH, CTX_MAILSUM);
1537 RegisterIterator("MAIL:MIME:ATTACH", 0, NULL, iterate_get_mime_All,
1538 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1539 RegisterIterator("MAIL:MIME:ATTACH:SUBMESSAGES", 0, NULL, iterate_get_mime_Submessages,
1540 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1541 RegisterIterator("MAIL:MIME:ATTACH:LINKS", 0, NULL, iterate_get_mime_AttachLinks,
1542 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1543 RegisterIterator("MAIL:MIME:ATTACH:ATT", 0, NULL, iterate_get_mime_Attachments,
1544 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1546 /* Parts of a mime attachent */
1547 RegisterNamespace("MAIL:MIME:NAME", 0, 2, tmplput_MIME_Name, NULL, CTX_MIME_ATACH);
1548 RegisterNamespace("MAIL:MIME:FILENAME", 0, 2, tmplput_MIME_FileName, NULL, CTX_MIME_ATACH);
1549 RegisterNamespace("MAIL:MIME:PARTNUM", 0, 2, tmplput_MIME_PartNum, NULL, CTX_MIME_ATACH);
1550 RegisterNamespace("MAIL:MIME:MSGNUM", 0, 2, tmplput_MIME_MsgNum, NULL, CTX_MIME_ATACH);
1551 RegisterNamespace("MAIL:MIME:DISPOSITION", 0, 2, tmplput_MIME_Disposition, NULL, CTX_MIME_ATACH);
1552 RegisterNamespace("MAIL:MIME:CONTENTTYPE", 0, 2, tmplput_MIME_ContentType, NULL, CTX_MIME_ATACH);
1553 RegisterNamespace("MAIL:MIME:CHARSET", 0, 2, tmplput_MIME_Charset, NULL, CTX_MIME_ATACH);
1554 RegisterNamespace("MAIL:MIME:LENGTH", 0, 2, tmplput_MIME_Length, NULL, CTX_MIME_ATACH);
1555 RegisterNamespace("MAIL:MIME:DATA", 0, 2, tmplput_MIME_Data, NULL, CTX_MIME_ATACH);
1556 /* load the actual attachment into WC->attachments; no output!!! */
1557 RegisterNamespace("MAIL:MIME:LOADDATA", 0, 0, tmplput_MIME_LoadData, NULL, CTX_MIME_ATACH);
1559 /* iterate the WC->attachments; use the above tokens for their contents */
1560 RegisterIterator("MSG:ATTACHNAMES", 0, NULL, iterate_get_registered_Attachments,
1561 NULL, NULL, CTX_MIME_ATACH, CTX_NONE, IT_NOFLAG);
1563 RegisterNamespace("MSG:NATTACH", 0, 0, get_registered_Attachments_Count, NULL, CTX_NONE);
1565 /* mime renderers translate an attachment into webcit viewable html text */
1566 RegisterMimeRenderer(HKEY("message/rfc822"), render_MAIL, 0, 150);
1567 RegisterMimeRenderer(HKEY("text/vnote"), render_MIME_VNote, 1, 300);
1568 RegisterMimeRenderer(HKEY("text/x-vcard"), render_MIME_VCard, 1, 201);
1569 RegisterMimeRenderer(HKEY("text/vcard"), render_MIME_VCard, 1, 200);
1570 RegisterMimeRenderer(HKEY("text/calendar"), render_MIME_ICS, 1, 501);
1571 RegisterMimeRenderer(HKEY("application/ics"), render_MIME_ICS, 1, 500);
1572 RegisterMimeRenderer(HKEY("text/x-citadel-variformat"), render_MAIL_variformat, 1, 2);
1573 RegisterMimeRenderer(HKEY("text/plain"), render_MAIL_text_plain, 1, 3);
1574 RegisterMimeRenderer(HKEY("text"), render_MAIL_text_plain, 1, 1);
1575 RegisterMimeRenderer(HKEY("text/html"), render_MAIL_html, 1, 100);
1576 RegisterMimeRenderer(HKEY(""), render_MAIL_UNKNOWN, 0, 0);
1578 /* these headers are citserver replies to MSG4 and friends. one evaluator for each */
1579 RegisterMsgHdr(HKEY("nhdr"), examine_nhdr, 0);
1580 RegisterMsgHdr(HKEY("type"), examine_type, 0);
1581 RegisterMsgHdr(HKEY("from"), examine_from, 0);
1582 RegisterMsgHdr(HKEY("subj"), examine_subj, 0);
1583 RegisterMsgHdr(HKEY("msgn"), examine_msgn, 0);
1584 RegisterMsgHdr(HKEY("wefw"), examine_wefw, 0);
1585 RegisterMsgHdr(HKEY("cccc"), examine_cccc, 0);
1586 RegisterMsgHdr(HKEY("hnod"), examine_hnod, 0);
1587 RegisterMsgHdr(HKEY("room"), examine_room, 0);
1588 RegisterMsgHdr(HKEY("rfca"), examine_rfca, 0);
1589 RegisterMsgHdr(HKEY("node"), examine_node, 0);
1590 RegisterMsgHdr(HKEY("rcpt"), examine_rcpt, 0);
1591 RegisterMsgHdr(HKEY("time"), examine_time, 0);
1592 RegisterMsgHdr(HKEY("part"), examine_mime_part, 0);
1593 RegisterMsgHdr(HKEY("text"), examine_text, 1);
1594 /* these are the content-type headers we get infront of a message; put it into the same hash since it doesn't clash. */
1595 RegisterMsgHdr(HKEY("X-Citadel-MSG4-Partnum"), examine_msg4_partnum, 0);
1596 RegisterMsgHdr(HKEY("Content-type"), examine_content_type, 0);
1597 RegisterMsgHdr(HKEY("Content-length"), examine_content_lengh, 0);
1598 RegisterMsgHdr(HKEY("Content-transfer-encoding"), examine_content_encoding, 0); /* do we care? */
1599 RegisterMsgHdr(HKEY("charset"), examine_charset, 0);
1601 /* Don't care about these... */
1602 RegisterMsgHdr(HKEY("pref"), examine_pref, 0);
1603 RegisterMsgHdr(HKEY("suff"), examine_suff, 0);
1604 RegisterMsgHdr(HKEY("path"), examine_path, 0);
1608 InitModule2_MSGRENDERERS
1611 /* and finalize the anouncement to the server... */
1615 ServerStartModule_MSGRENDERERS
1618 MsgHeaderHandler = NewHash(1, NULL);
1619 MimeRenderHandler = NewHash(1, NULL);
1620 ReadLoopHandler = NewHash(1, NULL);
1624 ServerShutdownModule_MSGRENDERERS
1627 DeleteHash(&MsgHeaderHandler);
1628 DeleteHash(&MimeRenderHandler);
1629 DeleteHash(&ReadLoopHandler);
1635 SessionDestroyModule_MSGRENDERERS
1638 DeleteHash(&sess->attachments);
1639 FreeStrBuf(&sess->ConvertBuf1);
1640 FreeStrBuf(&sess->ConvertBuf2);