5 CtxType CTX_MAILSUM = CTX_NONE;
6 CtxType CTX_MIME_ATACH = CTX_NONE;
8 static 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->EnvTo);
55 FreeStrBuf(&Msg->OtherNode);
57 DeleteHash(&Msg->Attachments); /* list of Attachments */
58 DeleteHash(&Msg->Submessages);
59 DeleteHash(&Msg->AttachLinks);
60 DeleteHash(&Msg->AllAttach);
66 void RegisterMsgHdr(const char *HeaderName, long HdrNLen, ExamineMsgHeaderFunc evaluator, int type)
69 ev = (headereval*) malloc(sizeof(headereval));
70 ev->evaluator = evaluator;
72 Put(MsgHeaderHandler, HeaderName, HdrNLen, ev, NULL);
75 void RegisterMimeRenderer(const char *HeaderName, long HdrNLen,
76 RenderMimeFunc MimeRenderer,
80 RenderMimeFuncStruct *f;
82 f = (RenderMimeFuncStruct*) malloc(sizeof(RenderMimeFuncStruct));
84 Put(MimeRenderHandler, HeaderName, HdrNLen, f, NULL);
86 RegisterEmbeddableMimeType(HeaderName, HdrNLen, 10000 - Priority);
89 /*----------------------------------------------------------------------------*/
92 * comparator for two longs in descending order.
94 int longcmp_r(const void *s1, const void *s2) {
98 l1 = *(long *)GetSearchPayload(s1);
99 l2 = *(long *)GetSearchPayload(s2);
101 if (l1 > l2) return(-1);
102 if (l1 < l2) return(+1);
107 * comparator for longs; descending order.
109 int qlongcmp_r(const void *s1, const void *s2) {
113 if (l1 > l2) return(-1);
114 if (l1 < l2) return(+1);
120 * comparator for message summary structs by ascending subject.
122 int summcmp_subj(const void *s1, const void *s2) {
123 message_summary *summ1;
124 message_summary *summ2;
126 summ1 = (message_summary *)GetSearchPayload(s1);
127 summ2 = (message_summary *)GetSearchPayload(s2);
128 return strcasecmp(ChrPtr(summ1->subj), ChrPtr(summ2->subj));
132 * comparator for message summary structs by descending subject.
134 int summcmp_rsubj(const void *s1, const void *s2) {
135 message_summary *summ1;
136 message_summary *summ2;
138 summ1 = (message_summary *)GetSearchPayload(s1);
139 summ2 = (message_summary *)GetSearchPayload(s2);
140 return strcasecmp(ChrPtr(summ2->subj), ChrPtr(summ1->subj));
143 * comparator for message summary structs by descending subject.
145 int groupchange_subj(const void *s1, const void *s2) {
146 message_summary *summ1;
147 message_summary *summ2;
149 summ1 = (message_summary *)s1;
150 summ2 = (message_summary *)s2;
151 return ChrPtr(summ2->subj)[0] != ChrPtr(summ1->subj)[0];
155 * comparator for message summary structs by ascending sender.
157 int summcmp_sender(const void *s1, const void *s2) {
158 message_summary *summ1;
159 message_summary *summ2;
161 summ1 = (message_summary *)GetSearchPayload(s1);
162 summ2 = (message_summary *)GetSearchPayload(s2);
163 return strcasecmp(ChrPtr(summ1->from), ChrPtr(summ2->from));
167 * comparator for message summary structs by descending sender.
169 int summcmp_rsender(const void *s1, const void *s2) {
170 message_summary *summ1;
171 message_summary *summ2;
173 summ1 = (message_summary *)GetSearchPayload(s1);
174 summ2 = (message_summary *)GetSearchPayload(s2);
175 return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from));
178 * comparator for message summary structs by descending sender.
180 int groupchange_sender(const void *s1, const void *s2) {
181 message_summary *summ1;
182 message_summary *summ2;
184 summ1 = (message_summary *)s1;
185 summ2 = (message_summary *)s2;
186 return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from)) != 0;
191 * comparator for message summary structs by ascending date.
193 int summcmp_date(const void *s1, const void *s2) {
194 message_summary *summ1;
195 message_summary *summ2;
197 summ1 = (message_summary *)GetSearchPayload(s1);
198 summ2 = (message_summary *)GetSearchPayload(s2);
200 if (summ1->date < summ2->date) return -1;
201 else if (summ1->date > summ2->date) return +1;
206 * comparator for message summary structs by descending date.
208 int summcmp_rdate(const void *s1, const void *s2) {
209 message_summary *summ1;
210 message_summary *summ2;
212 summ1 = (message_summary *)GetSearchPayload(s1);
213 summ2 = (message_summary *)GetSearchPayload(s2);
215 if (summ1->date < summ2->date) return +1;
216 else if (summ1->date > summ2->date) return -1;
221 * comparator for message summary structs by descending date.
223 const long DAYSECONDS = 24 * 60 * 60;
224 int groupchange_date(const void *s1, const void *s2) {
225 message_summary *summ1;
226 message_summary *summ2;
228 summ1 = (message_summary *)s1;
229 summ2 = (message_summary *)s2;
231 return (summ1->date % DAYSECONDS) != (summ2->date %DAYSECONDS);
235 /*----------------------------------------------------------------------------*/
236 /* Don't wanna know... or? */
237 void examine_pref(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
238 void examine_suff(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
239 void examine_path(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset) {return;}
240 void examine_content_encoding(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
242 /* TODO: do we care? */
245 void examine_nhdr(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
248 if (!strncasecmp(ChrPtr(HdrLine), "yes", 8))
251 int Conditional_ANONYMOUS_MESSAGE(StrBuf *Target, WCTemplputParams *TP)
253 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
254 return Msg->nhdr != 0;
257 void examine_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
259 Msg->format_type = StrToi(HdrLine);
263 void examine_from(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
267 CheckConvertBufs(WCC);
268 FreeStrBuf(&Msg->from);
269 Msg->from = NewStrBufPlain(NULL, StrLength(HdrLine));
270 StrBuf_RFC822_2_Utf8(Msg->from,
277 void tmplput_MAIL_SUMM_FROM(StrBuf *Target, WCTemplputParams *TP)
279 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
280 StrBufAppendTemplate(Target, TP, Msg->from, 0);
283 void examine_subj(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
287 CheckConvertBufs(WCC);
288 FreeStrBuf(&Msg->subj);
289 Msg->subj = NewStrBufPlain(NULL, StrLength(HdrLine));
290 StrBuf_RFC822_2_Utf8(Msg->subj,
297 void tmplput_MAIL_SUMM_SUBJECT(StrBuf *Target, WCTemplputParams *TP)
299 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
301 if (TP->Tokens->nParameters == 4)
306 GetTemplateTokenString(Target, TP, 3, &pch, &len);
308 (strstr(ChrPtr(Msg->subj), pch) == NULL))
310 GetTemplateTokenString(Target, TP, 2, &pch, &len);
311 StrBufAppendBufPlain(Target, pch, len, 0);
314 StrBufAppendTemplate(Target, TP, Msg->subj, 0);
316 int Conditional_MAIL_SUMM_SUBJECT(StrBuf *Target, WCTemplputParams *TP)
318 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
321 return StrLength(Msg->subj) > 0;
325 void examine_msgn(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
329 CheckConvertBufs(WCC);
330 FreeStrBuf(&Msg->reply_inreplyto);
331 Msg->reply_inreplyto = NewStrBufPlain(NULL, StrLength(HdrLine));
332 Msg->reply_inreplyto_hash = ThreadIdHash(HdrLine);
333 StrBuf_RFC822_2_Utf8(Msg->reply_inreplyto,
340 void tmplput_MAIL_SUMM_INREPLYTO(StrBuf *Target, WCTemplputParams *TP)
342 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
343 StrBufAppendTemplate(Target, TP, Msg->reply_inreplyto, 0);
346 int Conditional_MAIL_SUMM_UNREAD(StrBuf *Target, WCTemplputParams *TP)
348 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
349 return (Msg->Flags & MSGFLAG_READ) != 0;
352 void examine_wefw(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
356 CheckConvertBufs(WCC);
357 FreeStrBuf(&Msg->reply_references);
358 Msg->reply_references = NewStrBufPlain(NULL, StrLength(HdrLine));
359 Msg->reply_references_hash = ThreadIdHash(HdrLine);
360 StrBuf_RFC822_2_Utf8(Msg->reply_references,
367 void tmplput_MAIL_SUMM_REFIDS(StrBuf *Target, WCTemplputParams *TP)
369 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
370 StrBufAppendTemplate(Target, TP, Msg->reply_references, 0);
373 void examine_replyto(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
377 CheckConvertBufs(WCC);
378 FreeStrBuf(&Msg->ReplyTo);
379 Msg->ReplyTo = NewStrBufPlain(NULL, StrLength(HdrLine));
380 StrBuf_RFC822_2_Utf8(Msg->ReplyTo,
386 if (Msg->AllRcpt == NULL)
387 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
388 if (StrLength(Msg->AllRcpt) > 0) {
389 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
391 StrBufAppendBuf(Msg->AllRcpt, Msg->ReplyTo, 0);
393 void tmplput_MAIL_SUMM_REPLYTO(StrBuf *Target, WCTemplputParams *TP)
395 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
396 StrBufAppendTemplate(Target, TP, Msg->ReplyTo, 0);
399 void examine_cccc(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
403 CheckConvertBufs(WCC);
404 FreeStrBuf(&Msg->cccc);
405 Msg->cccc = NewStrBufPlain(NULL, StrLength(HdrLine));
406 StrBuf_RFC822_2_Utf8(Msg->cccc,
412 if (Msg->AllRcpt == NULL)
413 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
414 if (StrLength(Msg->AllRcpt) > 0) {
415 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
417 StrBufAppendBuf(Msg->AllRcpt, Msg->cccc, 0);
419 void tmplput_MAIL_SUMM_CCCC(StrBuf *Target, WCTemplputParams *TP)
421 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
422 StrBufAppendTemplate(Target, TP, Msg->cccc, 0);
426 void examine_room(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
428 if ((StrLength(HdrLine) > 0) &&
429 (strcasecmp(ChrPtr(HdrLine), ChrPtr(WC->CurRoom.name)))) {
430 FreeStrBuf(&Msg->Room);
431 Msg->Room = NewStrBufDup(HdrLine);
434 void tmplput_MAIL_SUMM_ORGROOM(StrBuf *Target, WCTemplputParams *TP)
436 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
437 StrBufAppendTemplate(Target, TP, Msg->Room, 0);
441 void examine_rfca(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
443 FreeStrBuf(&Msg->Rfca);
444 Msg->Rfca = NewStrBufDup(HdrLine);
446 void tmplput_MAIL_SUMM_RFCA(StrBuf *Target, WCTemplputParams *TP)
448 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
449 StrBufAppendTemplate(Target, TP, Msg->Rfca, 0);
451 int Conditional_MAIL_SUMM_RFCA(StrBuf *Target, WCTemplputParams *TP)
453 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
454 return StrLength(Msg->Rfca) > 0;
456 int Conditional_MAIL_SUMM_CCCC(StrBuf *Target, WCTemplputParams *TP)
458 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
459 return StrLength(Msg->cccc) > 0;
461 int Conditional_MAIL_SUMM_REPLYTO(StrBuf *Target, WCTemplputParams *TP)
463 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
464 return StrLength(Msg->ReplyTo) > 0;
467 void examine_node(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
471 if ( (StrLength(HdrLine) > 0) &&
472 ((WC->CurRoom.QRFlags & QR_NETWORK)
473 || ((strcasecmp(ChrPtr(HdrLine), ChrPtr(WCC->serv_info->serv_nodename))
474 && (strcasecmp(ChrPtr(HdrLine), ChrPtr(WCC->serv_info->serv_fqdn))))))) {
475 FreeStrBuf(&Msg->OtherNode);
476 Msg->OtherNode = NewStrBufDup(HdrLine);
479 void tmplput_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP)
481 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
482 StrBufAppendTemplate(Target, TP, Msg->OtherNode, 0);
484 int Conditional_MAIL_SUMM_OTHERNODE(StrBuf *Target, WCTemplputParams *TP)
486 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
487 return StrLength(Msg->OtherNode) > 0;
490 void examine_nvto(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
494 CheckConvertBufs(WCC);
495 FreeStrBuf(&Msg->EnvTo);
496 Msg->EnvTo = NewStrBufPlain(NULL, StrLength(HdrLine));
497 StrBuf_RFC822_2_Utf8(Msg->EnvTo,
506 void examine_rcpt(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
510 CheckConvertBufs(WCC);
511 FreeStrBuf(&Msg->to);
512 Msg->to = NewStrBufPlain(NULL, StrLength(HdrLine));
513 StrBuf_RFC822_2_Utf8(Msg->to,
519 if (Msg->AllRcpt == NULL)
520 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
521 if (StrLength(Msg->AllRcpt) > 0) {
522 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
524 StrBufAppendBuf(Msg->AllRcpt, Msg->to, 0);
526 void tmplput_MAIL_SUMM_TO(StrBuf *Target, WCTemplputParams *TP)
528 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
529 StrBufAppendTemplate(Target, TP, Msg->to, 0);
531 int Conditional_MAIL_SUMM_TO(StrBuf *Target, WCTemplputParams *TP)
533 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
534 return StrLength(Msg->to) != 0;
536 int Conditional_MAIL_SUMM_SUBJ(StrBuf *Target, WCTemplputParams *TP)
538 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
539 return StrLength(Msg->subj) != 0;
541 void tmplput_MAIL_SUMM_ALLRCPT(StrBuf *Target, WCTemplputParams *TP)
543 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
544 StrBufAppendTemplate(Target, TP, Msg->AllRcpt, 0);
549 void tmplput_SUMM_COUNT(StrBuf *Target, WCTemplputParams *TP)
551 StrBufAppendPrintf(Target, "%d", GetCount( WC->summ));
554 HashList *iterate_get_mailsumm_All(StrBuf *Target, WCTemplputParams *TP)
558 void examine_time(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
560 Msg->date = StrTol(HdrLine);
563 void tmplput_MAIL_SUMM_DATE_BRIEF(StrBuf *Target, WCTemplputParams *TP)
566 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
567 webcit_fmt_date(datebuf, 64, Msg->date, DATEFMT_BRIEF);
568 StrBufAppendBufPlain(Target, datebuf, -1, 0);
571 void tmplput_MAIL_SUMM_EUID(StrBuf *Target, WCTemplputParams *TP)
573 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
574 StrBufAppendTemplate(Target, TP, Msg->euid, 0);
577 void tmplput_MAIL_SUMM_DATE_FULL(StrBuf *Target, WCTemplputParams *TP)
580 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
581 webcit_fmt_date(datebuf, 64, Msg->date, DATEFMT_FULL);
582 StrBufAppendBufPlain(Target, datebuf, -1, 0);
584 void tmplput_MAIL_SUMM_DATE_NO(StrBuf *Target, WCTemplputParams *TP)
586 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
587 StrBufAppendPrintf(Target, "%ld", Msg->date, 0);
592 void render_MAIL(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
594 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
595 const StrBuf *TemplateMime;
597 if (Mime->Data == NULL)
598 Mime->Data = NewStrBufPlain(NULL, Mime->length);
600 FlushStrBuf(Mime->Data);
601 read_message(Mime->Data, HKEY("view_submessage"), Mime->msgnum, Mime->PartNum, &TemplateMime);
603 if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
604 for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
605 extract_token(buf, mime_submessages, i, '|', sizeof buf);
606 / ** use printable_view to suppress buttons * /
607 wc_printf("<blockquote>");
608 read_message(Mime->msgnum, 1, ChrPtr(Mime->Section));
609 wc_printf("</blockquote>");
615 void render_MIME_VCard(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
617 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
619 if (StrLength(Mime->Data) == 0)
621 if (StrLength(Mime->Data) > 0) {
624 /** If it's my vCard I can edit it */
625 if ( (!strcasecmp(ChrPtr(WCC->CurRoom.name), USERCONFIGROOM))
626 || (!strcasecmp(&(ChrPtr(WCC->CurRoom.name)[11]), USERCONFIGROOM))
627 || (WC->CurRoom.view == VIEW_ADDRESSBOOK)
629 StrBufAppendPrintf(Buf, "<a href=\"edit_vcard?msgnum=%ld?partnum=%s\">",
630 Mime->msgnum, ChrPtr(Mime->PartNum));
631 StrBufAppendPrintf(Buf, "[%s]</a>", _("edit"));
634 /* In all cases, display the full card */
635 display_vcard(Buf, Mime, 0, 1, NULL, -1);
636 FreeStrBuf(&Mime->Data);
642 void render_MIME_ICS(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
644 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
645 if (StrLength(Mime->Data) == 0) {
648 if (StrLength(Mime->Data) > 0) {
649 cal_process_attachment(Mime);
655 void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
657 const char *Ptr = NULL;
658 wc_mime_attachment *Mime;
662 CheckConvertBufs(WCC);
663 Mime = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
664 memset(Mime, 0, sizeof(wc_mime_attachment));
665 Mime->msgnum = Msg->msgnum;
668 Mime->Name = NewStrBuf();
669 StrBufExtract_NextToken(Buf, HdrLine, &Ptr, '|');
670 StrBuf_RFC822_2_Utf8(Mime->Name,
676 StrBufTrim(Mime->Name);
678 StrBufExtract_NextToken(Buf, HdrLine, &Ptr, '|');
679 Mime->FileName = NewStrBuf();
680 StrBuf_RFC822_2_Utf8(Mime->FileName,
686 StrBufTrim(Mime->FileName);
688 Mime->PartNum = NewStrBuf();
689 StrBufExtract_NextToken(Mime->PartNum, HdrLine, &Ptr, '|');
690 StrBufTrim(Mime->PartNum);
691 if (strchr(ChrPtr(Mime->PartNum), '.') != NULL)
696 Mime->Disposition = NewStrBuf();
697 StrBufExtract_NextToken(Mime->Disposition, HdrLine, &Ptr, '|');
699 Mime->ContentType = NewStrBuf();
700 StrBufExtract_NextToken(Mime->ContentType, HdrLine, &Ptr, '|');
701 StrBufTrim(Mime->ContentType);
702 StrBufLowerCase(Mime->ContentType);
703 if (!strcmp(ChrPtr(Mime->ContentType), "application/octet-stream")) {
704 StrBufPlain(Mime->ContentType,
705 GuessMimeByFilename(SKEY(Mime->FileName)), -1);
708 Mime->length = StrBufExtractNext_int(HdrLine, &Ptr, '|');
710 StrBufSkip_NTokenS(HdrLine, &Ptr, '|', 1); /* cbid?? */
712 Mime->Charset = NewStrBuf();
713 StrBufExtract_NextToken(Mime->Charset, HdrLine, &Ptr, '|');
716 if ( (StrLength(Mime->FileName) == 0) && (StrLength(Mime->Name) > 0) ) {
717 StrBufAppendBuf(Mime->FileName, Mime->Name, 0);
720 if (StrLength(Msg->PartNum) > 0) {
722 StrBufPrintf(Buf, "%s.%s", ChrPtr(Msg->PartNum), ChrPtr(Mime->PartNum));
728 if (Msg->AllAttach == NULL)
729 Msg->AllAttach = NewHash(1,NULL);
730 Put(Msg->AllAttach, SKEY(Mime->PartNum), Mime, DestroyMime);
735 void evaluate_mime_part(StrBuf *Target, WCTemplputParams *TP)
737 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
738 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
741 /* just print the root-node */
742 if ((Mime->level >= 1) &&
743 GetHash(MimeRenderHandler, SKEY(Mime->ContentType), &vMimeRenderer) &&
744 vMimeRenderer != NULL)
746 Mime->Renderer = (RenderMimeFuncStruct*) vMimeRenderer;
747 if (Msg->Submessages == NULL)
748 Msg->Submessages = NewHash(1,NULL);
749 Put(Msg->Submessages, SKEY(Mime->PartNum), Mime, reference_free_handler);
751 else if ((Mime->level >= 1) &&
752 (!strcasecmp(ChrPtr(Mime->Disposition), "inline"))
753 && (!strncasecmp(ChrPtr(Mime->ContentType), "image/", 6)) ){
754 if (Msg->AttachLinks == NULL)
755 Msg->AttachLinks = NewHash(1,NULL);
756 Put(Msg->AttachLinks, SKEY(Mime->PartNum), Mime, reference_free_handler);
758 else if ((Mime->level >= 1) &&
759 (StrLength(Mime->ContentType) > 0) &&
760 ( (!strcasecmp(ChrPtr(Mime->Disposition), "attachment"))
761 || (!strcasecmp(ChrPtr(Mime->Disposition), "inline"))
762 || (!strcasecmp(ChrPtr(Mime->Disposition), ""))))
764 if (Msg->AttachLinks == NULL)
765 Msg->AttachLinks = NewHash(1,NULL);
766 Put(Msg->AttachLinks, SKEY(Mime->PartNum), Mime, reference_free_handler);
767 if ((strcasecmp(ChrPtr(Mime->ContentType), "application/octet-stream") == 0) &&
768 (StrLength(Mime->FileName) > 0)) {
769 FlushStrBuf(Mime->ContentType);
770 StrBufAppendBufPlain(Mime->ContentType,
771 GuessMimeByFilename(SKEY(Mime->FileName)),
777 void tmplput_MAIL_SUMM_NATTACH(StrBuf *Target, WCTemplputParams *TP)
779 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
780 StrBufAppendPrintf(Target, "%ld", GetCount(Msg->Attachments));
784 void examine_hnod(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
788 CheckConvertBufs(WCC);
789 FreeStrBuf(&Msg->hnod);
790 Msg->hnod = NewStrBufPlain(NULL, StrLength(HdrLine));
791 StrBuf_RFC822_2_Utf8(Msg->hnod,
798 void tmplput_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP)
800 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
801 StrBufAppendTemplate(Target, TP, Msg->hnod, 0);
803 int Conditional_MAIL_SUMM_H_NODE(StrBuf *Target, WCTemplputParams *TP)
805 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
806 return StrLength(Msg->hnod) > 0;
811 void examine_text(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
813 if (Msg->MsgBody->Data == NULL)
814 Msg->MsgBody->Data = NewStrBufPlain(NULL, SIZ);
816 FlushStrBuf(Msg->MsgBody->Data);
819 void examine_msg4_partnum(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
821 Msg->MsgBody->PartNum = NewStrBufDup(HdrLine);
822 StrBufTrim(Msg->MsgBody->PartNum);
825 void examine_content_lengh(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
827 Msg->MsgBody->length = StrTol(HdrLine);
828 Msg->MsgBody->size_known = 1;
831 void examine_content_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
841 Msg->MsgBody->ContentType = NewStrBufDup(HdrLine);
842 sem = strchr(ChrPtr(HdrLine), ';');
845 Token = NewStrBufPlain(NULL, StrLength(HdrLine));
846 Value = NewStrBufPlain(NULL, StrLength(HdrLine));
847 len = sem - ChrPtr(HdrLine);
848 StrBufCutAt(Msg->MsgBody->ContentType, len, NULL);
849 while (sem != NULL) {
850 while (isspace(*(sem + 1)))
852 StrBufCutLeft(HdrLine, sem - ChrPtr(HdrLine));
853 sem = strchr(ChrPtr(HdrLine), ';');
855 len = sem - ChrPtr(HdrLine);
857 len = StrLength(HdrLine);
860 StrBufAppendBufPlain(Token, ChrPtr(HdrLine), len, 0);
861 eq = strchr(ChrPtr(Token), '=');
863 len = eq - ChrPtr(Token);
864 StrBufAppendBufPlain(Value, eq + 1, StrLength(Token) - len - 1, 0);
865 StrBufCutAt(Token, len, NULL);
870 if (GetHash(MsgHeaderHandler, SKEY(Token), &vHdr) &&
872 Hdr = (headereval*)vHdr;
873 Hdr->evaluator(Msg, Value, FoundCharset);
875 else syslog(LOG_WARNING, "don't know how to handle content type sub-header[%s]\n", ChrPtr(Token));
883 int ReadOneMessageSummary(message_summary *Msg, StrBuf *FoundCharset, StrBuf *Buf)
892 serv_printf("MSG0 %ld|1", Msg->msgnum); /* ask for headers only */
894 StrBuf_ServGetln(Buf);
895 if (GetServerStatus(Buf, NULL) != 1) {
899 while (len = StrBuf_ServGetln(Buf),
902 strcmp(ChrPtr(Buf), "000")))
905 ebuf = strchr(ChrPtr(Buf), '=');
908 if (GetHash(MsgHeaderHandler, buf, nBuf, &vHdr) &&
910 Hdr = (headereval*)vHdr;
911 StrBufCutLeft(Buf, nBuf + 1);
912 Hdr->evaluator(Msg, Buf, FoundCharset);
914 else syslog(LOG_INFO, "Don't know how to handle Message Headerline [%s]", ChrPtr(Buf));
919 void tmplput_MAIL_SUMM_N(StrBuf *Target, WCTemplputParams *TP)
921 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
922 StrBufAppendPrintf(Target, "%ld", Msg->msgnum);
926 void tmplput_MAIL_SUMM_PERMALINK(StrBuf *Target, WCTemplputParams *TP)
928 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
929 char perma_link[1024];
931 strcpy(perma_link, "/readfwd?go=");
932 urlesc(&perma_link[12], sizeof(perma_link) - 12, (char *)ChrPtr(WC->CurRoom.name) );
933 sprintf(&perma_link[strlen(perma_link)], "?start_reading_at=%ld#%ld", Msg->msgnum, Msg->msgnum);
934 StrBufAppendPrintf(Target, "%s", perma_link);
938 int Conditional_MAIL_MIME_ALL(StrBuf *Target, WCTemplputParams *TP)
940 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
941 return GetCount(Msg->Attachments) > 0;
944 int Conditional_MAIL_MIME_SUBMESSAGES(StrBuf *Target, WCTemplputParams *TP)
946 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
947 return GetCount(Msg->Submessages) > 0;
950 int Conditional_MAIL_MIME_ATTACHLINKS(StrBuf *Target, WCTemplputParams *TP)
952 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
953 return GetCount(Msg->AttachLinks) > 0;
956 int Conditional_MAIL_MIME_ATTACH(StrBuf *Target, WCTemplputParams *TP)
958 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
959 return GetCount(Msg->AllAttach) > 0;
962 void tmplput_QUOTED_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
968 MsgNum = LBstr(TKEY(0));
970 read_message(Buf, HKEY("view_message_replyquote"), MsgNum, NULL, &Mime);
971 StrBufAppendTemplate(Target, TP, Buf, 1);
975 void tmplput_EDIT_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
981 MsgNum = LBstr(TKEY(0));
983 read_message(Buf, HKEY("view_message_edit"), MsgNum, NULL, &Mime);
984 StrBufAppendTemplate(Target, TP, Buf, 1);
988 void tmplput_EDIT_WIKI_BODY(StrBuf *Target, WCTemplputParams *TP)
994 /* Insert the existing content of the wiki page into the editor. But we only want
995 * to do this the first time -- if the user is uploading an attachment we don't want
998 if (!havebstr("attach_button")) {
999 char *wikipage = strdup(bstr("page"));
1000 putbstr("format", NewStrBufPlain(HKEY("plain")));
1001 str_wiki_index(wikipage);
1002 msgnum = locate_message_by_uid(wikipage);
1006 read_message(Buf, HKEY("view_message_wikiedit"), msgnum, NULL, &Mime);
1007 StrBufAppendTemplate(Target, TP, Buf, 1);
1013 void tmplput_MAIL_BODY(StrBuf *Target, WCTemplputParams *TP)
1015 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
1016 StrBufAppendTemplate(Target, TP, Msg->MsgBody->Data, 0);
1020 void render_MAIL_variformat(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
1022 /* Messages in legacy Citadel variformat get handled thusly... */
1023 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
1024 StrBuf *TTarget = NewStrBufPlain(NULL, StrLength(Mime->Data));
1025 FmOut(TTarget, "JUSTIFY", Mime->Data);
1026 FreeStrBuf(&Mime->Data);
1027 Mime->Data = TTarget;
1030 void render_MAIL_text_plain(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
1032 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
1033 const char *ptr, *pte;
1034 const char *BufPtr = NULL;
1048 iconv_t ic = (iconv_t)(-1) ;
1051 if ((StrLength(Mime->Data) == 0) && (Mime->length > 0)) {
1052 FreeStrBuf(&Mime->Data);
1058 if (StrLength(Mime->Charset) != 0)
1060 else if (StrLength(FoundCharset) > 0)
1062 else if (StrLength(WC->DefaultCharset) > 0)
1063 cs = WC->DefaultCharset;
1067 else if (!strcasecmp(ChrPtr(cs), "utf-8")) {
1070 else if (!strcasecmp(ChrPtr(cs), "us-ascii")) {
1074 ctdl_iconv_open("UTF-8", ChrPtr(cs), &ic);
1075 if (ic == (iconv_t)(-1) ) {
1076 syslog(LOG_WARNING, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
1077 __FILE__, __LINE__, ChrPtr(Mime->Charset), strerror(errno));
1082 Line = NewStrBufPlain(NULL, SIZ);
1083 Line1 = NewStrBufPlain(NULL, SIZ);
1084 Line2 = NewStrBufPlain(NULL, SIZ);
1085 TTarget = NewStrBufPlain(NULL, StrLength(Mime->Data));
1088 if (StrLength(Mime->Data) > 0)
1091 StrBufSipLine(Line, Mime->Data, &BufPtr);
1095 len = StrLength(Line);
1098 while ((ptr < pte) &&
1107 if (i > 0) StrBufCutLeft(Line, i);
1109 if (StrLength(Line) == 0) {
1112 StrBufAppendBufPlain(TTarget, HKEY("<tt></tt><br>\n"), 0);
1118 for (i = bn; i < bq; i++)
1119 StrBufAppendBufPlain(TTarget, HKEY("<blockquote>"), 0);
1120 for (i = bq; i < bn; i++)
1121 StrBufAppendBufPlain(TTarget, HKEY("</blockquote>"), 0);
1124 StrBufConvert(Line, Line1, &ic);
1127 StrBufAppendBufPlain(TTarget, HKEY("<tt>"), 0);
1128 UrlizeText(Line1, Line, Line2);
1130 StrEscAppend(TTarget, Line1, NULL, 0, 0);
1131 StrBufAppendBufPlain(TTarget, HKEY("</tt><br>\n"), 0);
1135 while ((BufPtr != StrBufNOTNULL) &&
1138 if (nEmptyLines > 0)
1139 StrBufCutRight(TTarget, nEmptyLines * (sizeof ("<tt></tt><br>\n") - 1));
1140 for (i = 0; i < bn; i++)
1141 StrBufAppendBufPlain(TTarget, HKEY("</blockquote>"), 0);
1143 StrBufAppendBufPlain(TTarget, HKEY("</i><br>"), 0);
1145 if (ic != (iconv_t)(-1) ) {
1150 FreeStrBuf(&Mime->Data);
1151 Mime->Data = TTarget;
1152 FlushStrBuf(Mime->ContentType);
1153 StrBufAppendBufPlain(Mime->ContentType, HKEY("text/html"), 0);
1154 FlushStrBuf(Mime->Charset);
1155 StrBufAppendBufPlain(Mime->Charset, HKEY("UTF-8"), 0);
1161 void render_MAIL_html(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
1163 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
1166 if (StrLength(Mime->Data) == 0)
1169 Buf = NewStrBufPlain(NULL, StrLength(Mime->Data));
1171 /* HTML is fun, but we've got to strip it first */
1172 output_html(ChrPtr(Mime->Charset),
1173 (WC->CurRoom.view == VIEW_WIKI ? 1 : 0),
1176 FreeStrBuf(&Mime->Data);
1180 #ifdef HAVE_MARKDOWN
1182 char * MarkdownHandleURL(const char* SourceURL, const int len, void* something)
1187 void render_MAIL_markdown(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
1190 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
1192 char *md_as_html = NULL;
1195 if (StrLength(Mime->Data) == 0)
1198 format = bstr("format");
1200 if ((format == NULL) ||
1201 strcmp(format, "plain"))
1203 doc = mkd_string(ChrPtr(Mime->Data), StrLength(Mime->Data), 0);
1204 mkd_basename(doc, "/wiki?page=");
1205 mkd_compile(doc, 0);
1206 if (mkd_document(doc, &md_as_html) != EOF) {
1207 FreeStrBuf(&Mime->Data);
1208 Mime->Data = NewStrBufPlain(md_as_html, -1);
1210 // free(md_as_html);
1216 void render_MAIL_UNKNOWN(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
1218 wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
1219 /* Unknown weirdness */
1220 FlushStrBuf(Mime->Data);
1221 StrBufAppendBufPlain(Mime->Data, _("I don't know how to display "), -1, 0);
1222 StrBufAppendBuf(Mime->Data, Mime->ContentType, 0);
1223 StrBufAppendBufPlain(Mime->Data, HKEY("<br>\n"), 0);
1227 HashList *iterate_get_mime_All(StrBuf *Target, WCTemplputParams *TP)
1229 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
1230 return Msg->Attachments;
1232 HashList *iterate_get_mime_Submessages(StrBuf *Target, WCTemplputParams *TP)
1234 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
1235 return Msg->Submessages;
1237 HashList *iterate_get_mime_AttachLinks(StrBuf *Target, WCTemplputParams *TP)
1239 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
1240 return Msg->AttachLinks;
1242 HashList *iterate_get_mime_Attachments(StrBuf *Target, WCTemplputParams *TP)
1244 message_summary *Msg = (message_summary*) CTX(CTX_MAILSUM);
1245 return Msg->AllAttach;
1248 void tmplput_MIME_Name(StrBuf *Target, WCTemplputParams *TP)
1250 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1251 StrBufAppendTemplate(Target, TP, mime->Name, 0);
1254 void tmplput_MIME_FileName(StrBuf *Target, WCTemplputParams *TP)
1256 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1257 StrBufAppendTemplate(Target, TP, mime->FileName, 0);
1260 void tmplput_MIME_PartNum(StrBuf *Target, WCTemplputParams *TP)
1262 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1263 StrBufAppendTemplate(Target, TP, mime->PartNum, 0);
1266 void tmplput_MIME_MsgNum(StrBuf *Target, WCTemplputParams *TP)
1268 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1269 StrBufAppendPrintf(Target, "%ld", mime->msgnum);
1272 void tmplput_MIME_Disposition(StrBuf *Target, WCTemplputParams *TP)
1274 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1275 StrBufAppendTemplate(Target, TP, mime->Disposition, 0);
1278 void tmplput_MIME_ContentType(StrBuf *Target, WCTemplputParams *TP)
1280 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1281 StrBufAppendTemplate(Target, TP, mime->ContentType, 0);
1284 void examine_charset(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
1286 Msg->MsgBody->Charset = NewStrBufDup(HdrLine);
1289 void tmplput_MIME_Charset(StrBuf *Target, WCTemplputParams *TP)
1291 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1292 StrBufAppendTemplate(Target, TP, mime->Charset, 0);
1295 void tmplput_MIME_Data(StrBuf *Target, WCTemplputParams *TP)
1297 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1298 if (mime->Renderer != NULL)
1299 mime->Renderer->f(Target, TP, NULL);
1300 StrBufAppendTemplate(Target, TP, mime->Data, 0);
1301 /* TODO: check whether we need to load it now? */
1304 void tmplput_MIME_LoadData(StrBuf *Target, WCTemplputParams *TP)
1306 wcsession *WCC = WC;
1307 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1308 wc_mime_attachment *att;
1310 if (( (!strcasecmp(ChrPtr(mime->Disposition), "inline"))||
1311 (!strcasecmp(ChrPtr(mime->Disposition), "attachment"))) &&
1312 (strcasecmp(ChrPtr(mime->ContentType), "application/ms-tnef")!=0))
1317 /* steal this mime part... */
1318 att = malloc(sizeof(wc_mime_attachment));
1319 memcpy(att, mime, sizeof(wc_mime_attachment));
1320 memset(mime, 0, sizeof(wc_mime_attachment));
1322 if (att->Data == NULL)
1325 if (WCC->attachments == NULL)
1326 WCC->attachments = NewHash(1, NULL);
1327 /* And add it to the list. */
1328 n = snprintf(N, sizeof N, "%d", GetCount(WCC->attachments) + 1);
1329 Put(WCC->attachments, N, n, att, DestroyMime);
1333 void tmplput_MIME_Length(StrBuf *Target, WCTemplputParams *TP)
1335 wc_mime_attachment *mime = (wc_mime_attachment*) CTX(CTX_MIME_ATACH);
1336 StrBufAppendPrintf(Target, "%ld", mime->length);
1339 HashList *iterate_get_registered_Attachments(StrBuf *Target, WCTemplputParams *TP)
1341 return WC->attachments;
1344 void get_registered_Attachments_Count(StrBuf *Target, WCTemplputParams *TP)
1346 StrBufAppendPrintf(Target, "%ld", GetCount (WC->attachments));
1349 void servcmd_do_search(char *buf, long bufsize)
1351 snprintf(buf, bufsize, "MSGS SEARCH|%s", bstr("query"));
1354 void servcmd_headers(char *buf, long bufsize)
1356 snprintf(buf, bufsize, "MSGS ALL");
1359 void servcmd_readfwd(char *buf, long bufsize)
1361 snprintf(buf, bufsize, "MSGS ALL");
1364 void servcmd_readgt(char *buf, long bufsize)
1366 snprintf(buf, bufsize, "MSGS GT|%s", bstr("gt"));
1369 void servcmd_readlt(char *buf, long bufsize)
1371 snprintf(buf, bufsize, "MSGS LT|%s", bstr("lt"));
1374 void servcmd_readnew(char *buf, long bufsize)
1376 snprintf(buf, bufsize, "MSGS NEW");
1379 void servcmd_readold(char *buf, long bufsize)
1381 snprintf(buf, bufsize, "MSGS OLD");
1385 /* DO NOT REORDER OR REMOVE ANY OF THESE */
1386 readloop_struct rlid[] = {
1387 { {HKEY("do_search")}, servcmd_do_search },
1388 { {HKEY("headers")}, servcmd_headers },
1389 { {HKEY("readfwd")}, servcmd_readfwd },
1390 { {HKEY("readnew")}, servcmd_readnew },
1391 { {HKEY("readold")}, servcmd_readold },
1392 { {HKEY("readgt")}, servcmd_readgt },
1393 { {HKEY("readlt")}, servcmd_readlt }
1397 int ParseMessageListHeaders_Detail(StrBuf *Line,
1399 message_summary *Msg,
1400 StrBuf *ConversionBuffer)
1402 wcsession *WCC = WC;
1406 CheckConvertBufs(WCC);
1408 totallen = StrLength(Line);
1409 Msg->from = NewStrBufPlain(NULL, totallen);
1410 len = StrBufExtract_NextToken(ConversionBuffer, Line, pos, '|');
1412 /* Handle senders with RFC2047 encoding */
1413 StrBuf_RFC822_2_Utf8(Msg->from,
1415 WCC->DefaultCharset,
1422 len = StrBufExtract_NextToken(ConversionBuffer, Line, pos, '|');
1424 ( ((WCC->CurRoom.QRFlags & QR_NETWORK)
1425 || ((strcasecmp(ChrPtr(ConversionBuffer), ChrPtr(WCC->serv_info->serv_nodename))
1426 && (strcasecmp(ChrPtr(ConversionBuffer), ChrPtr(WCC->serv_info->serv_fqdn))))))))
1428 StrBufAppendBufPlain(Msg->from, HKEY(" @ "), 0);
1429 StrBufAppendBuf(Msg->from, ConversionBuffer, 0);
1432 /* Internet address (not used)
1433 * StrBufExtract_token(Msg->inetaddr, Line, 4, '|');
1435 StrBufSkip_NTokenS(Line, pos, '|', 1);
1436 Msg->subj = NewStrBufPlain(NULL, totallen);
1438 FlushStrBuf(ConversionBuffer);
1439 /* we assume the subject is the last parameter inside of the list;
1440 * thus we don't use the tokenizer to fetch it, since it will hick up
1441 * on tokenizer chars inside of the subjects
1442 StrBufExtract_NextToken(ConversionBuffer, Line, pos, '|');
1445 if (*pos != StrBufNOTNULL) {
1446 len = totallen - (*pos - ChrPtr(Line));
1447 StrBufPlain(ConversionBuffer, *pos, len);
1448 *pos = StrBufNOTNULL;
1450 (*(ChrPtr(ConversionBuffer) + len - 1) == '|'))
1451 StrBufCutRight(ConversionBuffer, 1);
1455 StrBufAppendBufPlain(Msg->subj, _("(no subject)"), -1,0);
1457 StrBuf_RFC822_2_Utf8(Msg->subj,
1459 WCC->DefaultCharset,
1469 int mailview_GetParamsGetServerCall(SharedMessageStatus *Stat,
1470 void **ViewSpecific,
1477 DoTemplate(HKEY("msg_listview"),NULL,&NoCtx);
1482 int mailview_Cleanup(void **ViewSpecific)
1484 /* Note: wDumpContent() will output one additional </div> tag. */
1485 /* We ought to move this out into template */
1492 int json_GetParamsGetServerCall(SharedMessageStatus *Stat,
1493 void **ViewSpecific,
1500 Stat->defaultsortorder = 2;
1502 Stat->load_seen = 1;
1503 /* Generally using maxmsgs|startmsg is not required
1504 in mailbox view, but we have a 'safemode' for clients
1505 (*cough* Exploder) that simply can't handle too many */
1506 if (havebstr("maxmsgs")) Stat->maxmsgs = ibstr("maxmsgs");
1507 else Stat->maxmsgs = 9999999;
1508 if (havebstr("startmsg")) Stat->startmsg = lbstr("startmsg");
1509 snprintf(cmd, len, "MSGS %s|%s||1",
1510 (oper == do_search) ? "SEARCH" : "ALL",
1511 (oper == do_search) ? bstr("query") : ""
1516 int json_MessageListHdr(SharedMessageStatus *Stat, void **ViewSpecific)
1518 /* TODO: make a generic function */
1519 hprintf("HTTP/1.1 200 OK\r\n");
1520 hprintf("Content-type: application/json; charset=utf-8\r\n");
1521 hprintf("Server: %s / %s\r\n", PACKAGE_STRING, ChrPtr(WC->serv_info->serv_software));
1522 hprintf("Connection: close\r\n");
1523 hprintf("Pragma: no-cache\r\nCache-Control: no-store\r\nExpires:-1\r\n");
1528 int json_RenderView_or_Tail(SharedMessageStatus *Stat,
1529 void **ViewSpecific,
1532 DoTemplate(HKEY("mailsummary_json"),NULL, NULL);
1537 int json_Cleanup(void **ViewSpecific)
1539 /* Note: wDumpContent() will output one additional </div> tag. */
1540 /* We ought to move this out into template */
1549 InitModule_MSGRENDERERS
1552 RegisterCTX(CTX_MAILSUM);
1553 RegisterCTX(CTX_MIME_ATACH);
1554 RegisterReadLoopHandlerset(
1556 mailview_GetParamsGetServerCall,
1557 NULL, /* TODO: is this right? */
1559 ParseMessageListHeaders_Detail,
1564 RegisterReadLoopHandlerset(
1566 json_GetParamsGetServerCall,
1567 json_MessageListHdr,
1568 NULL, /* TODO: is this right? */
1569 ParseMessageListHeaders_Detail,
1571 json_RenderView_or_Tail,
1574 RegisterSortFunc(HKEY("date"),
1580 RegisterSortFunc(HKEY("subject"),
1586 RegisterSortFunc(HKEY("sender"),
1593 RegisterNamespace("SUMM:COUNT", 0, 0, tmplput_SUMM_COUNT, NULL, CTX_NONE);
1594 /* iterate over all known mails in WC->summ */
1595 RegisterIterator("MAIL:SUMM:MSGS", 0, NULL, iterate_get_mailsumm_All,
1596 NULL,NULL, CTX_MAILSUM, CTX_NONE, IT_NOFLAG);
1598 RegisterNamespace("MAIL:SUMM:EUID", 0, 1, tmplput_MAIL_SUMM_EUID, NULL, CTX_MAILSUM);
1599 RegisterNamespace("MAIL:SUMM:DATEBRIEF", 0, 0, tmplput_MAIL_SUMM_DATE_BRIEF, NULL, CTX_MAILSUM);
1600 RegisterNamespace("MAIL:SUMM:DATEFULL", 0, 0, tmplput_MAIL_SUMM_DATE_FULL, NULL, CTX_MAILSUM);
1601 RegisterNamespace("MAIL:SUMM:DATENO", 0, 0, tmplput_MAIL_SUMM_DATE_NO, NULL, CTX_MAILSUM);
1602 RegisterNamespace("MAIL:SUMM:N", 0, 0, tmplput_MAIL_SUMM_N, NULL, CTX_MAILSUM);
1603 RegisterNamespace("MAIL:SUMM:PERMALINK", 0, 0, tmplput_MAIL_SUMM_PERMALINK, NULL, CTX_MAILSUM);
1604 RegisterNamespace("MAIL:SUMM:FROM", 0, 2, tmplput_MAIL_SUMM_FROM, NULL, CTX_MAILSUM);
1605 RegisterNamespace("MAIL:SUMM:TO", 0, 2, tmplput_MAIL_SUMM_TO, NULL, CTX_MAILSUM);
1606 RegisterNamespace("MAIL:SUMM:SUBJECT", 0, 4, tmplput_MAIL_SUMM_SUBJECT, NULL, CTX_MAILSUM);
1607 RegisterNamespace("MAIL:SUMM:NTATACH", 0, 0, tmplput_MAIL_SUMM_NATTACH, NULL, CTX_MAILSUM);
1608 RegisterNamespace("MAIL:SUMM:CCCC", 0, 2, tmplput_MAIL_SUMM_CCCC, NULL, CTX_MAILSUM);
1609 RegisterNamespace("MAIL:SUMM:REPLYTO", 0, 2, tmplput_MAIL_SUMM_REPLYTO, NULL, CTX_MAILSUM);
1610 RegisterNamespace("MAIL:SUMM:H_NODE", 0, 2, tmplput_MAIL_SUMM_H_NODE, NULL, CTX_MAILSUM);
1611 RegisterNamespace("MAIL:SUMM:ALLRCPT", 0, 2, tmplput_MAIL_SUMM_ALLRCPT, NULL, CTX_MAILSUM);
1612 RegisterNamespace("MAIL:SUMM:ORGROOM", 0, 2, tmplput_MAIL_SUMM_ORGROOM, NULL, CTX_MAILSUM);
1613 RegisterNamespace("MAIL:SUMM:RFCA", 0, 2, tmplput_MAIL_SUMM_RFCA, NULL, CTX_MAILSUM);
1614 RegisterNamespace("MAIL:SUMM:OTHERNODE", 2, 0, tmplput_MAIL_SUMM_OTHERNODE, NULL, CTX_MAILSUM);
1615 RegisterNamespace("MAIL:SUMM:REFIDS", 0, 1, tmplput_MAIL_SUMM_REFIDS, NULL, CTX_MAILSUM);
1616 RegisterNamespace("MAIL:SUMM:INREPLYTO", 0, 2, tmplput_MAIL_SUMM_INREPLYTO, NULL, CTX_MAILSUM);
1617 RegisterNamespace("MAIL:BODY", 0, 2, tmplput_MAIL_BODY, NULL, CTX_MAILSUM);
1618 RegisterNamespace("MAIL:QUOTETEXT", 1, 2, tmplput_QUOTED_MAIL_BODY, NULL, CTX_NONE);
1619 RegisterNamespace("MAIL:EDITTEXT", 1, 2, tmplput_EDIT_MAIL_BODY, NULL, CTX_NONE);
1620 RegisterNamespace("MAIL:EDITWIKI", 1, 2, tmplput_EDIT_WIKI_BODY, NULL, CTX_NONE);
1621 RegisterConditional("COND:MAIL:SUMM:RFCA", 0, Conditional_MAIL_SUMM_RFCA, CTX_MAILSUM);
1622 RegisterConditional("COND:MAIL:SUMM:CCCC", 0, Conditional_MAIL_SUMM_CCCC, CTX_MAILSUM);
1623 RegisterConditional("COND:MAIL:SUMM:REPLYTO", 0, Conditional_MAIL_SUMM_REPLYTO, CTX_MAILSUM);
1624 RegisterConditional("COND:MAIL:SUMM:UNREAD", 0, Conditional_MAIL_SUMM_UNREAD, CTX_MAILSUM);
1625 RegisterConditional("COND:MAIL:SUMM:H_NODE", 0, Conditional_MAIL_SUMM_H_NODE, CTX_MAILSUM);
1626 RegisterConditional("COND:MAIL:SUMM:OTHERNODE", 0, Conditional_MAIL_SUMM_OTHERNODE, CTX_MAILSUM);
1627 RegisterConditional("COND:MAIL:SUMM:SUBJECT", 0, Conditional_MAIL_SUMM_SUBJECT, CTX_MAILSUM);
1628 RegisterConditional("COND:MAIL:ANON", 0, Conditional_ANONYMOUS_MESSAGE, CTX_MAILSUM);
1629 RegisterConditional("COND:MAIL:TO", 0, Conditional_MAIL_SUMM_TO, CTX_MAILSUM);
1630 RegisterConditional("COND:MAIL:SUBJ", 0, Conditional_MAIL_SUMM_SUBJ, CTX_MAILSUM);
1632 /* do we have mimetypes to iterate over? */
1633 RegisterConditional("COND:MAIL:MIME:ATTACH", 0, Conditional_MAIL_MIME_ALL, CTX_MAILSUM);
1634 RegisterConditional("COND:MAIL:MIME:ATTACH:SUBMESSAGES", 0, Conditional_MAIL_MIME_SUBMESSAGES, CTX_MAILSUM);
1635 RegisterConditional("COND:MAIL:MIME:ATTACH:LINKS", 0, Conditional_MAIL_MIME_ATTACHLINKS, CTX_MAILSUM);
1636 RegisterConditional("COND:MAIL:MIME:ATTACH:ATT", 0, Conditional_MAIL_MIME_ATTACH, CTX_MAILSUM);
1637 RegisterIterator("MAIL:MIME:ATTACH", 0, NULL, iterate_get_mime_All,
1638 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1639 RegisterIterator("MAIL:MIME:ATTACH:SUBMESSAGES", 0, NULL, iterate_get_mime_Submessages,
1640 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1641 RegisterIterator("MAIL:MIME:ATTACH:LINKS", 0, NULL, iterate_get_mime_AttachLinks,
1642 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1643 RegisterIterator("MAIL:MIME:ATTACH:ATT", 0, NULL, iterate_get_mime_Attachments,
1644 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM, IT_NOFLAG);
1646 /* Parts of a mime attachent */
1647 RegisterNamespace("MAIL:MIME:NAME", 0, 2, tmplput_MIME_Name, NULL, CTX_MIME_ATACH);
1648 RegisterNamespace("MAIL:MIME:FILENAME", 0, 2, tmplput_MIME_FileName, NULL, CTX_MIME_ATACH);
1649 RegisterNamespace("MAIL:MIME:PARTNUM", 0, 2, tmplput_MIME_PartNum, NULL, CTX_MIME_ATACH);
1650 RegisterNamespace("MAIL:MIME:MSGNUM", 0, 2, tmplput_MIME_MsgNum, NULL, CTX_MIME_ATACH);
1651 RegisterNamespace("MAIL:MIME:DISPOSITION", 0, 2, tmplput_MIME_Disposition, NULL, CTX_MIME_ATACH);
1652 RegisterNamespace("MAIL:MIME:CONTENTTYPE", 0, 2, tmplput_MIME_ContentType, NULL, CTX_MIME_ATACH);
1653 RegisterNamespace("MAIL:MIME:CHARSET", 0, 2, tmplput_MIME_Charset, NULL, CTX_MIME_ATACH);
1654 RegisterNamespace("MAIL:MIME:LENGTH", 0, 2, tmplput_MIME_Length, NULL, CTX_MIME_ATACH);
1655 RegisterNamespace("MAIL:MIME:DATA", 0, 2, tmplput_MIME_Data, NULL, CTX_MIME_ATACH);
1656 /* load the actual attachment into WC->attachments; no output!!! */
1657 RegisterNamespace("MAIL:MIME:LOADDATA", 0, 0, tmplput_MIME_LoadData, NULL, CTX_MIME_ATACH);
1659 /* iterate the WC->attachments; use the above tokens for their contents */
1660 RegisterIterator("MSG:ATTACHNAMES", 0, NULL, iterate_get_registered_Attachments,
1661 NULL, NULL, CTX_MIME_ATACH, CTX_NONE, IT_NOFLAG);
1663 RegisterNamespace("MSG:NATTACH", 0, 0, get_registered_Attachments_Count, NULL, CTX_NONE);
1665 /* mime renderers translate an attachment into webcit viewable html text */
1666 RegisterMimeRenderer(HKEY("message/rfc822"), render_MAIL, 0, 150);
1667 RegisterMimeRenderer(HKEY("text/x-vcard"), render_MIME_VCard, 1, 201);
1668 RegisterMimeRenderer(HKEY("text/vcard"), render_MIME_VCard, 1, 200);
1670 RegisterMimeRenderer(HKEY("text/calendar"), render_MIME_ICS, 1, 501);
1671 RegisterMimeRenderer(HKEY("application/ics"), render_MIME_ICS, 1, 500);
1673 RegisterMimeRenderer(HKEY("text/x-citadel-variformat"), render_MAIL_variformat, 1, 2);
1674 RegisterMimeRenderer(HKEY("text/plain"), render_MAIL_text_plain, 1, 3);
1675 RegisterMimeRenderer(HKEY("text"), render_MAIL_text_plain, 1, 1);
1676 RegisterMimeRenderer(HKEY("text/html"), render_MAIL_html, 1, 100);
1677 #ifdef HAVE_MARKDOWN
1678 RegisterMimeRenderer(HKEY("text/x-markdown"), render_MAIL_markdown, 1, 30);
1680 RegisterMimeRenderer(HKEY(""), render_MAIL_UNKNOWN, 0, 0);
1682 /* these headers are citserver replies to MSG4 and friends. one evaluator for each */
1683 RegisterMsgHdr(HKEY("nhdr"), examine_nhdr, 0);
1684 RegisterMsgHdr(HKEY("type"), examine_type, 0);
1685 RegisterMsgHdr(HKEY("from"), examine_from, 0);
1686 RegisterMsgHdr(HKEY("subj"), examine_subj, 0);
1687 RegisterMsgHdr(HKEY("msgn"), examine_msgn, 0);
1688 RegisterMsgHdr(HKEY("wefw"), examine_wefw, 0);
1689 RegisterMsgHdr(HKEY("cccc"), examine_cccc, 0);
1690 RegisterMsgHdr(HKEY("rep2"), examine_replyto, 0);
1691 RegisterMsgHdr(HKEY("hnod"), examine_hnod, 0);
1692 RegisterMsgHdr(HKEY("room"), examine_room, 0);
1693 RegisterMsgHdr(HKEY("rfca"), examine_rfca, 0);
1694 RegisterMsgHdr(HKEY("node"), examine_node, 0);
1695 RegisterMsgHdr(HKEY("rcpt"), examine_rcpt, 0);
1696 RegisterMsgHdr(HKEY("nvto"), examine_nvto, 0);
1697 RegisterMsgHdr(HKEY("time"), examine_time, 0);
1698 RegisterMsgHdr(HKEY("part"), examine_mime_part, 0);
1699 RegisterMsgHdr(HKEY("text"), examine_text, 1);
1700 /* these are the content-type headers we get infront of a message; put it into the same hash since it doesn't clash. */
1701 RegisterMsgHdr(HKEY("X-Citadel-MSG4-Partnum"), examine_msg4_partnum, 0);
1702 RegisterMsgHdr(HKEY("Content-type"), examine_content_type, 0);
1703 RegisterMsgHdr(HKEY("Content-length"), examine_content_lengh, 0);
1704 RegisterMsgHdr(HKEY("Content-transfer-encoding"), examine_content_encoding, 0); /* do we care? */
1705 RegisterMsgHdr(HKEY("charset"), examine_charset, 0);
1707 /* Don't care about these... */
1708 RegisterMsgHdr(HKEY("pref"), examine_pref, 0);
1709 RegisterMsgHdr(HKEY("suff"), examine_suff, 0);
1710 RegisterMsgHdr(HKEY("path"), examine_path, 0);
1714 InitModule2_MSGRENDERERS
1717 /* and finalize the anouncement to the server... */
1721 ServerStartModule_MSGRENDERERS
1724 MsgHeaderHandler = NewHash(1, NULL);
1725 MimeRenderHandler = NewHash(1, NULL);
1726 ReadLoopHandler = NewHash(1, NULL);
1730 ServerShutdownModule_MSGRENDERERS
1733 DeleteHash(&MsgHeaderHandler);
1734 DeleteHash(&MimeRenderHandler);
1735 DeleteHash(&ReadLoopHandler);
1741 SessionDestroyModule_MSGRENDERERS
1744 DeleteHash(&sess->attachments);
1745 FreeStrBuf(&sess->ConvertBuf1);
1746 FreeStrBuf(&sess->ConvertBuf2);