4 * Functions which deal with the fetching and displaying of messages.
12 HashList *MsgHeaderHandler = NULL;
13 HashList *MsgEvaluators = NULL;
14 HashList *MimeRenderHandler = NULL;
16 #define SUBJ_COL_WIDTH_PCT 50 /**< Mailbox view column width */
17 #define SENDER_COL_WIDTH_PCT 30 /**< Mailbox view column width */
18 #define DATE_PLUS_BUTTONS_WIDTH_PCT 20 /**< Mailbox view column width */
20 void display_vcard(StrBuf *Target, const char *vcard_source, char alpha, int full, char *storename, long msgnum);
23 void display_enter(void);
24 int longcmp_r(const void *s1, const void *s2);
25 int summcmp_subj(const void *s1, const void *s2);
26 int summcmp_rsubj(const void *s1, const void *s2);
27 int summcmp_sender(const void *s1, const void *s2);
28 int summcmp_rsender(const void *s1, const void *s2);
29 int summcmp_date(const void *s1, const void *s2);
30 int summcmp_rdate(const void *s1, const void *s2);
32 /*----------------------------------------------------------------------------*/
35 typedef void (*MsgPartEvaluatorFunc)(message_summary *Sum, StrBuf *Buf);
45 typedef struct _headereval {
46 ExamineMsgHeaderFunc evaluator;
58 const char* SortIcons[3] = {
59 "static/up_pointer.gif",
60 "static/down_pointer.gif",
61 "static/sort_none.gif"
75 /* SortEnum to plain string representation */
76 static const char* SortByStrings[] = {
87 /* SortEnum to sort-Function Table */
88 const CompareFunc SortFuncs[eUnSet] = {
98 /* given a SortEnum, which icon should we choose? */
99 const int SortDateToIcon[eUnSet] = { eUp, eDown, eNone, eNone, eNone, eNone, eNone};
100 const int SortSubjectToIcon[eUnSet] = { eNone, eNone, eUp, eDown, eNone, eNone, eNone};
101 const int SortSenderToIcon[eUnSet] = { eNone, eNone, eNone, eNone, eUp, eDown, eNone};
103 /* given a SortEnum, which would be the "opposite" search option? */
104 const int DateInvertSortString[eUnSet] = { eRDate, eDate, eDate, eDate, eDate, eDate, eDate};
105 const int SubjectInvertSortString[eUnSet] = { eSubject, eSubject, eRSubject, eUnSet, eSubject, eSubject, eSubject};
106 const int SenderInvertSortString[eUnSet] = { eSender, eSender, eSender, eSender, eRSender, eUnSet, eSender};
112 * Address book entry (keep it short and sweet, it's just a quickie lookup
113 * which we can use to get to the real meat and bones later)
116 char ab_name[64]; /**< name string */
117 long ab_msgnum; /**< message number of address book entry */
120 /*----------------------------------------------------------------------------*/
123 * Translates sortoption String to its SortEnum representation
124 * returns the enum matching the string; defaults to RDate
127 int StrToESort (const StrBuf *sortby)
131 if (!IsEmptyStr(ChrPtr(sortby))) while (result < eUnSet){
132 if (!strcasecmp(ChrPtr(sortby),
133 SortByStrings[result]))
141 typedef int (*QSortFunction) (const void*, const void*);
144 * qsort() compatible function to compare two longs in descending order.
146 int longcmp_r(const void *s1, const void *s2) {
150 l1 = *(long *)GetSearchPayload(s1);
151 l2 = *(long *)GetSearchPayload(s2);
153 if (l1 > l2) return(-1);
154 if (l1 < l2) return(+1);
160 * qsort() compatible function to compare two message summary structs by ascending subject.
162 int summcmp_subj(const void *s1, const void *s2) {
163 message_summary *summ1;
164 message_summary *summ2;
166 summ1 = (message_summary *)GetSearchPayload(s1);
167 summ2 = (message_summary *)GetSearchPayload(s2);
168 return strcasecmp(ChrPtr(summ1->subj), ChrPtr(summ2->subj));
172 * qsort() compatible function to compare two message summary structs by descending subject.
174 int summcmp_rsubj(const void *s1, const void *s2) {
175 message_summary *summ1;
176 message_summary *summ2;
178 summ1 = (message_summary *)GetSearchPayload(s1);
179 summ2 = (message_summary *)GetSearchPayload(s2);
180 return strcasecmp(ChrPtr(summ2->subj), ChrPtr(summ1->subj));
184 * qsort() compatible function to compare two message summary structs by ascending sender.
186 int summcmp_sender(const void *s1, const void *s2) {
187 message_summary *summ1;
188 message_summary *summ2;
190 summ1 = (message_summary *)GetSearchPayload(s1);
191 summ2 = (message_summary *)GetSearchPayload(s2);
192 return strcasecmp(ChrPtr(summ1->from), ChrPtr(summ2->from));
196 * qsort() compatible function to compare two message summary structs by descending sender.
198 int summcmp_rsender(const void *s1, const void *s2) {
199 message_summary *summ1;
200 message_summary *summ2;
202 summ1 = (message_summary *)GetSearchPayload(s1);
203 summ2 = (message_summary *)GetSearchPayload(s2);
204 return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from));
208 * qsort() compatible function to compare two message summary structs by ascending date.
210 int summcmp_date(const void *s1, const void *s2) {
211 message_summary *summ1;
212 message_summary *summ2;
214 summ1 = (message_summary *)GetSearchPayload(s1);
215 summ2 = (message_summary *)GetSearchPayload(s2);
217 if (summ1->date < summ2->date) return -1;
218 else if (summ1->date > summ2->date) return +1;
223 * qsort() compatible function to compare two message summary structs by descending date.
225 int summcmp_rdate(const void *s1, const void *s2) {
226 message_summary *summ1;
227 message_summary *summ2;
229 summ1 = (message_summary *)GetSearchPayload(s1);
230 summ2 = (message_summary *)GetSearchPayload(s2);
232 if (summ1->date < summ2->date) return +1;
233 else if (summ1->date > summ2->date) return -1;
241 /*----------------------------------------------------------------------------*/
244 * message index functions
247 void DestroyMimeParts(wc_mime_attachment *Mime)
249 FreeStrBuf(&Mime->Name);
250 FreeStrBuf(&Mime->FileName);
251 FreeStrBuf(&Mime->PartNum);
252 FreeStrBuf(&Mime->Disposition);
253 FreeStrBuf(&Mime->ContentType);
254 FreeStrBuf(&Mime->Charset);
255 FreeStrBuf(&Mime->Data);
258 void DestroyMime(void *vMime)
260 wc_mime_attachment *Mime = (wc_mime_attachment*)vMime;
261 DestroyMimeParts(Mime);
265 void DestroyMessageSummary(void *vMsg)
267 message_summary *Msg = (message_summary*) vMsg;
269 FreeStrBuf(&Msg->from);
270 FreeStrBuf(&Msg->to);
271 FreeStrBuf(&Msg->subj);
272 FreeStrBuf(&Msg->reply_inreplyto);
273 FreeStrBuf(&Msg->reply_references);
274 FreeStrBuf(&Msg->cccc);
275 FreeStrBuf(&Msg->hnod);
276 FreeStrBuf(&Msg->AllRcpt);
277 FreeStrBuf(&Msg->Room);
278 FreeStrBuf(&Msg->Rfca);
279 FreeStrBuf(&Msg->OtherNode);
281 FreeStrBuf(&Msg->reply_to);
283 DeleteHash(&Msg->Attachments); /**< list of Accachments */
284 DeleteHash(&Msg->Submessages);
285 DeleteHash(&Msg->AttachLinks);
286 DeleteHash(&Msg->AllAttach);
288 DestroyMimeParts(&Msg->MsgBody);
295 void RegisterMsgHdr(const char *HeaderName, long HdrNLen, ExamineMsgHeaderFunc evaluator, int type)
298 ev = (headereval*) malloc(sizeof(headereval));
299 ev->evaluator = evaluator;
301 Put(MsgHeaderHandler, HeaderName, HdrNLen, ev, NULL);
304 void RegisterMimeRenderer(const char *HeaderName, long HdrNLen, RenderMimeFunc MimeRenderer)
306 Put(MimeRenderHandler, HeaderName, HdrNLen, MimeRenderer, reference_free_handler);
310 /*----------------------------------------------------------------------------*/
313 void examine_nhdr(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
316 if (!strncasecmp(ChrPtr(HdrLine), "yes", 8))
319 int Conditional_ANONYMOUS_MESSAGE(WCTemplateToken *Tokens, void *Context, int ContextType)
321 message_summary *Msg = (message_summary*) Context;
322 return Msg->nhdr != 0;
326 void examine_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
328 Msg->format_type = StrToi(HdrLine);
332 void examine_from(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
334 FreeStrBuf(&Msg->from);
335 Msg->from = NewStrBufPlain(NULL, StrLength(HdrLine));
336 StrBuf_RFC822_to_Utf8(Msg->from, HdrLine, WC->DefaultCharset, FoundCharset);
338 void tmplput_MAIL_SUMM_FROM(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
340 message_summary *Msg = (message_summary*) Context;
341 StrBufAppendBuf(Target, Msg->from, 0);
342 lprintf(1,"%s", ChrPtr(Msg->from));
347 void examine_subj(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
349 FreeStrBuf(&Msg->subj);
350 Msg->subj = NewStrBufPlain(NULL, StrLength(HdrLine));
351 StrBuf_RFC822_to_Utf8(Msg->subj, HdrLine, WC->DefaultCharset, FoundCharset);
352 lprintf(1,"%s", ChrPtr(Msg->subj));
354 void tmplput_MAIL_SUMM_SUBJECT(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
355 {/////TODO: Fwd: and RE: filter!!
356 message_summary *Msg = (message_summary*) Context;
357 StrBufAppendBuf(Target, Msg->subj, 0);
361 void examine_msgn(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
363 FreeStrBuf(&Msg->reply_inreplyto);
364 Msg->reply_inreplyto = NewStrBufPlain(NULL, StrLength(HdrLine));
365 StrBuf_RFC822_to_Utf8(Msg->reply_inreplyto, HdrLine, WC->DefaultCharset, FoundCharset);
367 void tmplput_MAIL_SUMM_INREPLYTO(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
369 message_summary *Msg = (message_summary*) Context;
370 StrBufAppendBuf(Target, Msg->reply_inreplyto, 0);
373 int Conditional_MAIL_SUMM_UNREAD(WCTemplateToken *Tokens, void *Context, int ContextType)
375 message_summary *Msg = (message_summary*) Context;
376 return Msg->is_new != 0;
379 void examine_wefw(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
381 FreeStrBuf(&Msg->reply_references);
382 Msg->reply_references = NewStrBufPlain(NULL, StrLength(HdrLine));
383 StrBuf_RFC822_to_Utf8(Msg->reply_references, HdrLine, WC->DefaultCharset, FoundCharset);
385 void tmplput_MAIL_SUMM_REFIDS(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
387 message_summary *Msg = (message_summary*) Context;
388 StrBufAppendBuf(Target, Msg->reply_references, 0);
392 void examine_cccc(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
394 FreeStrBuf(&Msg->cccc);
395 Msg->cccc = NewStrBufPlain(NULL, StrLength(HdrLine));
396 StrBuf_RFC822_to_Utf8(Msg->cccc, HdrLine, WC->DefaultCharset, FoundCharset);
397 if (Msg->AllRcpt == NULL)
398 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
399 if (StrLength(Msg->AllRcpt) > 0) {
400 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
402 StrBufAppendBuf(Msg->AllRcpt, Msg->cccc, 0);
404 void tmplput_MAIL_SUMM_CCCC(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
406 message_summary *Msg = (message_summary*) Context;
407 StrBufAppendBuf(Target, Msg->cccc, 0);
413 void examine_room(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
415 if ((StrLength(HdrLine) > 0) &&
416 (strcasecmp(ChrPtr(HdrLine), WC->wc_roomname))) {
417 FreeStrBuf(&Msg->Room);
418 Msg->Room = NewStrBufDup(HdrLine);
421 void tmplput_MAIL_SUMM_ORGROOM(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
423 message_summary *Msg = (message_summary*) Context;
424 StrBufAppendBuf(Target, Msg->Room, 0);
428 void examine_rfca(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
430 FreeStrBuf(&Msg->Rfca);
431 Msg->Rfca = NewStrBufDup(HdrLine);
433 void tmplput_MAIL_SUMM_RFCA(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
435 message_summary *Msg = (message_summary*) Context;
436 StrBufAppendBuf(Target, Msg->Rfca, 0);
440 void examine_node(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
442 if ( (StrLength(HdrLine) > 0) &&
443 ((WC->room_flags & QR_NETWORK)
444 || ((strcasecmp(ChrPtr(HdrLine), serv_info.serv_nodename)
445 && (strcasecmp(ChrPtr(HdrLine), serv_info.serv_fqdn)))))) {
446 FreeStrBuf(&Msg->OtherNode);
447 Msg->OtherNode = NewStrBufDup(HdrLine);
450 void tmplput_MAIL_SUMM_OTHERNODE(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
452 message_summary *Msg = (message_summary*) Context;
453 StrBufAppendBuf(Target, Msg->OtherNode, 0);
455 int Conditional_MAIL_SUMM_OTHERNODE(WCTemplateToken *Tokens, void *Context, int ContextType)
457 message_summary *Msg = (message_summary*) Context;
458 return StrLength(Msg->OtherNode) > 0;
462 void examine_rcpt(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
464 FreeStrBuf(&Msg->to);
465 Msg->to = NewStrBufPlain(NULL, StrLength(HdrLine));
466 StrBuf_RFC822_to_Utf8(Msg->to, HdrLine, WC->DefaultCharset, FoundCharset);
467 if (Msg->AllRcpt == NULL)
468 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
469 if (StrLength(Msg->AllRcpt) > 0) {
470 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
472 StrBufAppendBuf(Msg->AllRcpt, Msg->to, 0);
474 void tmplput_MAIL_SUMM_TO(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
476 message_summary *Msg = (message_summary*) Context;
477 StrBufAppendBuf(Target, Msg->to, 0);
479 void tmplput_MAIL_SUMM_ALLRCPT(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
481 message_summary *Msg = (message_summary*) Context;
482 StrBufAppendBuf(Target, Msg->AllRcpt, 0);
487 void examine_time(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
489 Msg->date = StrTol(HdrLine);
491 void tmplput_MAIL_SUMM_DATE_STR(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
494 message_summary *Msg = (message_summary*) Context;
495 webcit_fmt_date(datebuf, Msg->date, 1);
496 StrBufAppendBufPlain(Target, datebuf, -1, 0);
498 void tmplput_MAIL_SUMM_DATE_NO(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
500 message_summary *Msg = (message_summary*) Context;
501 StrBufAppendPrintf(Target, "%ld", Msg->date, 0);
506 void render_MAIL(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
510 void render_MIME_VCard(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
513 if (StrLength(Mime->Data) > 0) {
516 /** If it's my vCard I can edit it */
517 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
518 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
519 || (WC->wc_view == VIEW_ADDRESSBOOK)
521 StrBufAppendPrintf(Buf, "<a href=\"edit_vcard?msgnum=%ld&partnum=%s\">",
522 Mime->msgnum, ChrPtr(Mime->PartNum));
523 StrBufAppendPrintf(Buf, "[%s]</a>", _("edit"));
526 /* In all cases, display the full card */
527 display_vcard(Buf, ChrPtr(Mime->Data), 0, 1, NULL, Mime->msgnum);
528 FreeStrBuf(&Mime->Data);
533 void render_MIME_ICS(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
536 if (StrLength(Mime->Data) > 0) {
537 cal_process_attachment(Mime);
543 void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
545 wc_mime_attachment *mime;
549 mime = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
550 memset(mime, 0, sizeof(wc_mime_attachment));
551 mime->msgnum = Msg->msgnum;
554 mime->Name = NewStrBuf();
555 StrBufExtract_token(mime->Name, HdrLine, 0, '|');
557 StrBufExtract_token(Buf, HdrLine, 1, '|');
558 mime->FileName = NewStrBuf();
559 StrBuf_RFC822_to_Utf8(mime->FileName, Buf, WC->DefaultCharset, FoundCharset);
561 mime->PartNum = NewStrBuf();
562 StrBufExtract_token(mime->PartNum, HdrLine, 2, '|');
564 mime->Disposition = NewStrBuf();
565 StrBufExtract_token(mime->Disposition, HdrLine, 3, '|');
567 mime->ContentType = NewStrBuf();
568 StrBufExtract_token(mime->ContentType, HdrLine, 4, '|');
570 mime->length = StrBufExtract_int(HdrLine, 5, '|');
572 StrBufTrim(mime->Name);
573 StrBufTrim(mime->FileName);
575 if ( (StrLength(mime->FileName) == 0) && (StrLength(mime->Name) > 0) ) {
576 StrBufAppendBuf(mime->FileName, mime->Name, 0);
579 if (Msg->AllAttach == NULL)
580 Msg->AllAttach = NewHash(1,NULL);
581 Put(Msg->AllAttach, SKEY(mime->PartNum), mime, DestroyMime);
584 if (GetHash(MimeRenderHandler, SKEY(mime->ContentType), &vMimeRenderer) &&
585 vMimeRenderer != NULL)
587 mime->Renderer = (RenderMimeFunc) vMimeRenderer;
588 if (Msg->Submessages == NULL)
589 Msg->Submessages = NewHash(1,NULL);
590 Put(Msg->Submessages, SKEY(mime->PartNum), mime, reference_free_handler);
592 else if ((!strcasecmp(ChrPtr(mime->Disposition), "inline"))
593 && (!strncasecmp(ChrPtr(mime->ContentType), "image/", 6)) ){
594 if (Msg->AttachLinks == NULL)
595 Msg->AttachLinks = NewHash(1,NULL);
596 Put(Msg->AttachLinks, SKEY(mime->PartNum), mime, reference_free_handler);
598 else if ((StrLength(mime->ContentType) > 0) &&
599 ( (!strcasecmp(ChrPtr(mime->Disposition), "attachment"))
600 || (!strcasecmp(ChrPtr(mime->Disposition), "inline"))
601 || (!strcasecmp(ChrPtr(mime->Disposition), ""))))
603 if (Msg->AttachLinks == NULL)
604 Msg->AttachLinks = NewHash(1,NULL);
605 Put(Msg->AttachLinks, SKEY(mime->PartNum), mime, reference_free_handler);
606 if (strcasecmp(ChrPtr(mime->ContentType), "application/octet-stream") == 0) {
607 FlushStrBuf(mime->ContentType);
608 StrBufAppendBufPlain(mime->ContentType,
609 GuessMimeByFilename(SKEY(mime->FileName)),
617 void tmplput_MAIL_SUMM_NATTACH(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
619 message_summary *Msg = (message_summary*) Context;
620 StrBufAppendPrintf(Target, "%ld", GetCount(Msg->Attachments));
629 void examine_hnod(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
631 FreeStrBuf(&Msg->hnod);
632 Msg->hnod = NewStrBufPlain(NULL, StrLength(HdrLine));
633 StrBuf_RFC822_to_Utf8(Msg->hnod, HdrLine, WC->DefaultCharset, FoundCharset);
635 void tmplput_MAIL_SUMM_H_NODE(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
637 message_summary *Msg = (message_summary*) Context;
638 StrBufAppendBuf(Target, Msg->hnod, 0);
640 int Conditional_MAIL_SUMM_H_NODE(WCTemplateToken *Tokens, void *Context, int ContextType)
642 message_summary *Msg = (message_summary*) Context;
643 return StrLength(Msg->hnod) > 0;
648 void examine_text(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
649 {////TODO: read messages here
650 Msg->MsgBody.Data = NewStrBuf();
653 void examine_msg4_partnum(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
655 Msg->MsgBody.PartNum = NewStrBufDup(HdrLine);
656 StrBufTrim(Msg->MsgBody.PartNum);/////TODO: striplt == trim?
659 void examine_content_encoding(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
661 ////TODO: do we care?
664 void examine_content_lengh(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
666 Msg->MsgBody.length = StrTol(HdrLine);
667 Msg->MsgBody.size_known = 1;
670 void examine_content_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
673 Msg->MsgBody.ContentType = NewStrBufDup(HdrLine);
674 StrBufTrim(Msg->MsgBody.ContentType);/////todo==striplt?
675 len = StrLength(Msg->MsgBody.ContentType);
676 for (i=0; i<len; ++i) {
677 if (!strncasecmp(ChrPtr(Msg->MsgBody.ContentType) + i, "charset=", 8)) {/// TODO: WHUT?
678 // safestrncpy(mime_charset, &mime_content_type[i+8],
679 /// sizeof mime_charset);
682 for (i=0; i<len; ++i) {
683 if (mime_content_type[i] == ';') {
684 mime_content_type[i] = 0;
688 len = strlen(mime_charset);
689 for (i=0; i<len; ++i) {
690 if (mime_charset[i] == ';') {
698 void tmplput_MAIL_SUMM_N(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
700 message_summary *Msg = (message_summary*) Context;
701 StrBufAppendPrintf(Target, "%ld", Msg->msgnum);
706 int Conditional_MAIL_MIME_ALL(WCTemplateToken *Tokens, void *Context, int ContextType)
708 message_summary *Msg = (message_summary*) Context;
709 return GetCount(Msg->Attachments) > 0;
712 int Conditional_MAIL_MIME_SUBMESSAGES(WCTemplateToken *Tokens, void *Context, int ContextType)
714 message_summary *Msg = (message_summary*) Context;
715 return GetCount(Msg->Submessages) > 0;
718 int Conditional_MAIL_MIME_ATTACHLINKS(WCTemplateToken *Tokens, void *Context, int ContextType)
720 message_summary *Msg = (message_summary*) Context;
721 return GetCount(Msg->AttachLinks) > 0;
724 int Conditional_MAIL_MIME_ATTACH(WCTemplateToken *Tokens, void *Context, int ContextType)
726 message_summary *Msg = (message_summary*) Context;
727 return GetCount(Msg->AllAttach) > 0;
732 /*----------------------------------------------------------------------------*/
735 void tmplput_MAIL_BODY(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
737 message_summary *Msg = (message_summary*) Context;
738 StrBufAppendBuf(Target, Msg->MsgBody.Data, 0);
742 void render_MAIL_variformat(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
744 /* Messages in legacy Citadel variformat get handled thusly... */
745 StrBuf *Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
746 FmOut(Target, "JUSTIFY", Mime->Data);
747 FreeStrBuf(&Mime->Data);
751 void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
754 const char *ptr, *pte;
755 const char *BufPtr = NULL;
756 StrBuf *Line = NewStrBuf();
757 StrBuf *Line1 = NewStrBuf();
758 StrBuf *Line2 = NewStrBuf();
759 StrBuf *Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
766 iconv_t ic = (iconv_t)(-1) ;
769 /* Boring old 80-column fixed format text gets handled this way... */
770 if ((strcasecmp(ChrPtr(Mime->Charset), "us-ascii") == 0) &&
771 (strcasecmp(ChrPtr(Mime->Charset), "UTF-8") == 0))
776 if (StrLength(Mime->Charset) != 0)
778 else if (StrLength(FoundCharset) > 0)
780 else if (StrLength(WC->DefaultCharset) > 0)
781 cs = WC->DefaultCharset;
786 ctdl_iconv_open("UTF-8", ChrPtr(cs), &ic);
787 if (ic == (iconv_t)(-1) ) {
788 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
789 __FILE__, __LINE__, ChrPtr(Mime->Charset), strerror(errno));
795 while ((n = StrBufSipLine(Line, Mime->Data, &BufPtr), n >= 0) && !done)
801 len = StrLength(Line);
804 while ((ptr < pte) &&
813 if (i > 0) StrBufCutLeft(Line, i);
815 if (StrLength(Line) == 0)
818 for (i = bn; i < bq; i++)
819 StrBufAppendBufPlain(Target, HKEY("<blockquote>"), 0);
820 for (i = bq; i < bn; i++)
821 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
823 if (ConvertIt == 1) {
824 StrBufConvert(Line, Line1, &ic);
827 StrBufAppendBufPlain(Target, HKEY("<tt>"), 0);
828 UrlizeText(Line1, Line, Line2);
830 StrEscAppend(Target, Line1, NULL, 0, 0);
831 StrBufAppendBufPlain(Target, HKEY("</tt><br />\n"), 0);
835 for (i = 0; i < bn; i++)
836 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
838 StrBufAppendBufPlain(Target, HKEY("</i><br />"), 0);
840 if (ic != (iconv_t)(-1) ) {
844 FreeStrBuf(&Mime->Data);
851 void render_MAIL_html(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
854 /* HTML is fun, but we've got to strip it first */
855 Buf = NewStrBufPlain(NULL, StrLength(Mime->Data));
856 output_html(ChrPtr(Mime->Charset),
857 (WC->wc_view == VIEW_WIKI ? 1 : 0),
858 StrToi(Mime->PartNum),
860 FreeStrBuf(&Mime->Data);
864 void render_MAIL_UNKNOWN(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
866 /* Unknown weirdness */
867 FlushStrBuf(Mime->Data);
868 StrBufAppendBufPlain(Mime->Data, _("I don't know how to display "), -1, 0);
869 StrBufAppendBuf(Mime->Data, Mime->ContentType, 0);
870 StrBufAppendBufPlain(Mime->Data, HKEY("<br />\n"), 0);
878 HashList *iterate_get_mime_All(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
880 message_summary *Msg = (message_summary*) Context;
881 return Msg->Attachments;
883 HashList *iterate_get_mime_Submessages(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
885 message_summary *Msg = (message_summary*) Context;
886 return Msg->Submessages;
888 HashList *iterate_get_mime_AttachLinks(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
890 message_summary *Msg = (message_summary*) Context;
891 return Msg->AttachLinks;
893 HashList *iterate_get_mime_Attachments(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
895 message_summary *Msg = (message_summary*) Context;
896 return Msg->AllAttach;
899 void tmplput_MIME_Name(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
901 wc_mime_attachment *mime = (wc_mime_attachment*) Context;
902 StrBufAppendBuf(Target, mime->Name, 0);
905 void tmplput_MIME_FileName(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
907 wc_mime_attachment *mime = (wc_mime_attachment*) Context;
908 StrBufAppendBuf(Target, mime->FileName, 0);
911 void tmplput_MIME_PartNum(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
913 wc_mime_attachment *mime = (wc_mime_attachment*) Context;
914 StrBufAppendBuf(Target, mime->PartNum, 0);
917 void tmplput_MIME_MsgNum(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
919 wc_mime_attachment *mime = (wc_mime_attachment*) Context;
920 StrBufAppendPrintf(Target, "%ld", mime->msgnum);
923 void tmplput_MIME_Disposition(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
925 wc_mime_attachment *mime = (wc_mime_attachment*) Context;
926 StrBufAppendBuf(Target, mime->Disposition, 0);
929 void tmplput_MIME_ContentType(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
931 wc_mime_attachment *mime = (wc_mime_attachment*) Context;
932 StrBufAppendBuf(Target, mime->ContentType, 0);
935 void tmplput_MIME_Charset(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
937 wc_mime_attachment *mime = (wc_mime_attachment*) Context;
938 StrBufAppendBuf(Target, mime->Charset, 0);
941 void tmplput_MIME_Data(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
943 wc_mime_attachment *mime = (wc_mime_attachment*) Context;
944 if (mime->Renderer != NULL)
945 mime->Renderer(mime, NULL, NULL);
946 StrBufAppendBuf(Target, mime->Data, 0); /// TODO: check whether we need to load it now?
949 void tmplput_MIME_Length(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
951 wc_mime_attachment *mime = (wc_mime_attachment*) Context;
952 StrBufAppendPrintf(Target, "%ld", mime->length);
958 * Look for URL's embedded in a buffer and make them linkable. We use a
959 * target window in order to keep the Citadel session in its own window.
961 void UrlizeText(StrBuf* Target, StrBuf *Source, StrBuf *WrkBuf)
963 int len, UrlLen, Offset, TrailerLen;
964 const char *start, *end, *pos;
969 len = StrLength(Source);
970 end = ChrPtr(Source) + len;
971 for (pos = ChrPtr(Source); (pos < end) && (start == NULL); ++pos) {
972 if (!strncasecmp(pos, "http://", 7))
974 if (!strncasecmp(pos, "ftp://", 6))
979 StrBufAppendBuf(Target, Source, 0);
984 for (pos = ChrPtr(Source) + len; pos > start; --pos) {
985 if ( (!isprint(*pos))
1004 UrlLen = end - start;
1005 StrBufAppendBufPlain(WrkBuf, start, UrlLen, 0);
1007 Offset = start - ChrPtr(Source);
1009 StrBufAppendBufPlain(Target, ChrPtr(Source), Offset, 0);
1010 StrBufAppendPrintf(Target, "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
1011 LB, QU, ChrPtr(WrkBuf), QU, QU, TARGET,
1012 QU, RB, ChrPtr(WrkBuf), LB, RB);
1014 TrailerLen = len - (end - start);
1016 StrBufAppendBufPlain(Target, end, TrailerLen, 0);
1018 void url(char *buf, size_t bufsize)
1020 int len, UrlLen, Offset, TrailerLen, outpos;
1021 char *start, *end, *pos;
1027 if (len > bufsize) {
1028 lprintf(1, "URL: content longer than buffer!");
1032 for (pos = buf; (pos < end) && (start == NULL); ++pos) {
1033 if (!strncasecmp(pos, "http://", 7))
1035 if (!strncasecmp(pos, "ftp://", 6))
1042 for (pos = buf+len; pos > start; --pos) {
1043 if ( (!isprint(*pos))
1062 UrlLen = end - start;
1063 if (UrlLen > sizeof(urlbuf)){
1064 lprintf(1, "URL: content longer than buffer!");
1067 memcpy(urlbuf, start, UrlLen);
1068 urlbuf[UrlLen] = '\0';
1070 Offset = start - buf;
1071 if ((Offset != 0) && (Offset < sizeof(outbuf)))
1072 memcpy(outbuf, buf, Offset);
1073 outpos = snprintf(&outbuf[Offset], sizeof(outbuf) - Offset,
1074 "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
1075 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
1076 if (outpos >= sizeof(outbuf) - Offset) {
1077 lprintf(1, "URL: content longer than buffer!");
1081 TrailerLen = len - (end - start);
1083 memcpy(outbuf + Offset + outpos, end, TrailerLen);
1084 if (Offset + outpos + TrailerLen > bufsize) {
1085 lprintf(1, "URL: content longer than buffer!");
1088 memcpy (buf, outbuf, Offset + outpos + TrailerLen);
1089 *(buf + Offset + outpos + TrailerLen) = '\0';
1094 * \brief Turn a vCard "n" (name) field into something displayable.
1095 * \param name the name field to convert
1097 void vcard_n_prettyize(char *name)
1099 char *original_name;
1102 original_name = strdup(name);
1103 len = strlen(original_name);
1104 for (i=0; i<5; ++i) {
1106 if (original_name[len-1] == ' ') {
1107 original_name[--len] = 0;
1109 if (original_name[len-1] == ';') {
1110 original_name[--len] = 0;
1116 for (i=0; i<len; ++i) {
1117 if (original_name[i] == ';') {
1122 name[j++] = original_name[i];
1126 free(original_name);
1133 * \brief preparse a vcard name
1134 * display_vcard() calls this after parsing the textual vCard into
1135 * our 'struct vCard' data object.
1136 * This gets called instead of display_parsed_vcard() if we are only looking
1137 * to extract the person's name instead of displaying the card.
1138 * \param v the vcard to retrieve the name from
1139 * \param storename where to put the name at
1141 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
1144 strcpy(storename, "");
1146 name = vcard_get_prop(v, "n", 1, 0, 0);
1148 strcpy(storename, name);
1149 /* vcard_n_prettyize(storename); */
1157 * \brief html print a vcard
1158 * display_vcard() calls this after parsing the textual vCard into
1159 * our 'struct vCard' data object.
1161 * Set 'full' to nonzero to display the full card, otherwise it will only
1162 * show a summary line.
1164 * This code is a bit ugly, so perhaps an explanation is due: we do this
1165 * in two passes through the vCard fields. On the first pass, we process
1166 * fields we understand, and then render them in a pretty fashion at the
1167 * end. Then we make a second pass, outputting all the fields we don't
1168 * understand in a simple two-column name/value format.
1169 * \param v the vCard to display
1170 * \param full display all items of the vcard?
1171 * \param msgnum Citadel message pointer
1173 void display_parsed_vcard(StrBuf *Target, struct vCard *v, int full, long msgnum) {
1179 char *thisname, *thisvalue;
1180 char firsttoken[SIZ];
1189 strcpy(fullname, "");
1196 StrBufAppendPrintf(Target, "<TD>");
1197 name = vcard_get_prop(v, "fn", 1, 0, 0);
1199 StrEscAppend(Target, NULL, name, 0, 0);
1201 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
1202 strcpy(fullname, name);
1203 vcard_n_prettyize(fullname);
1204 StrEscAppend(Target, NULL, fullname, 0, 0);
1207 StrBufAppendPrintf(Target, " ");
1209 StrBufAppendPrintf(Target, "</TD>");
1213 StrBufAppendPrintf(Target, "<div align=center>"
1214 "<table bgcolor=#aaaaaa width=50%%>");
1215 for (pass=1; pass<=2; ++pass) {
1217 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
1219 thisname = strdup(v->prop[i].name);
1220 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
1222 for (j=0; j<num_tokens(thisname, ';'); ++j) {
1223 extract_token(buf, thisname, j, ';', sizeof buf);
1224 if (!strcasecmp(buf, "encoding=quoted-printable")) {
1226 remove_token(thisname, j, ';');
1228 if (!strcasecmp(buf, "encoding=base64")) {
1230 remove_token(thisname, j, ';');
1234 len = strlen(v->prop[i].value);
1235 /* if we have some untagged QP, detect it here. */
1236 if (!is_qp && (strstr(v->prop[i].value, "=?")!=NULL))
1237 utf8ify_rfc822_string(v->prop[i].value);
1240 // %ff can become 6 bytes in utf8
1241 thisvalue = malloc(len * 2 + 3);
1242 j = CtdlDecodeQuotedPrintable(
1243 thisvalue, v->prop[i].value,
1248 // ff will become one byte..
1249 thisvalue = malloc(len + 50);
1251 thisvalue, v->prop[i].value,
1252 strlen(v->prop[i].value) );
1255 thisvalue = strdup(v->prop[i].value);
1258 /** Various fields we may encounter ***/
1260 /** N is name, but only if there's no FN already there */
1261 if (!strcasecmp(firsttoken, "n")) {
1262 if (IsEmptyStr(fullname)) {
1263 strcpy(fullname, thisvalue);
1264 vcard_n_prettyize(fullname);
1268 /** FN (full name) is a true 'display name' field */
1269 else if (!strcasecmp(firsttoken, "fn")) {
1270 strcpy(fullname, thisvalue);
1274 else if (!strcasecmp(firsttoken, "title")) {
1275 strcpy(title, thisvalue);
1279 else if (!strcasecmp(firsttoken, "org")) {
1280 strcpy(org, thisvalue);
1283 else if (!strcasecmp(firsttoken, "email")) {
1285 if (!IsEmptyStr(mailto)) strcat(mailto, "<br />");
1287 "<a href=\"display_enter"
1288 "?force_room=_MAIL_?recp=");
1290 len = strlen(mailto);
1291 urlesc(&mailto[len], SIZ - len, "\"");
1292 len = strlen(mailto);
1293 urlesc(&mailto[len], SIZ - len, fullname);
1294 len = strlen(mailto);
1295 urlesc(&mailto[len], SIZ - len, "\" <");
1296 len = strlen(mailto);
1297 urlesc(&mailto[len], SIZ - len, thisvalue);
1298 len = strlen(mailto);
1299 urlesc(&mailto[len], SIZ - len, ">");
1301 strcat(mailto, "\">");
1302 len = strlen(mailto);
1303 stresc(mailto+len, SIZ - len, thisvalue, 1, 1);
1304 strcat(mailto, "</A>");
1306 else if (!strcasecmp(firsttoken, "tel")) {
1307 if (!IsEmptyStr(phone)) strcat(phone, "<br />");
1308 strcat(phone, thisvalue);
1309 for (j=0; j<num_tokens(thisname, ';'); ++j) {
1310 extract_token(buf, thisname, j, ';', sizeof buf);
1311 if (!strcasecmp(buf, "tel"))
1313 else if (!strcasecmp(buf, "work"))
1314 strcat(phone, _(" (work)"));
1315 else if (!strcasecmp(buf, "home"))
1316 strcat(phone, _(" (home)"));
1317 else if (!strcasecmp(buf, "cell"))
1318 strcat(phone, _(" (cell)"));
1320 strcat(phone, " (");
1326 else if (!strcasecmp(firsttoken, "adr")) {
1328 StrBufAppendPrintf(Target, "<TR><TD>");
1329 StrBufAppendPrintf(Target, _("Address:"));
1330 StrBufAppendPrintf(Target, "</TD><TD>");
1331 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
1332 extract_token(buf, thisvalue, j, ';', sizeof buf);
1333 if (!IsEmptyStr(buf)) {
1334 StrEscAppend(Target, NULL, buf, 0, 0);
1335 if (j<3) StrBufAppendPrintf(Target, "<br />");
1336 else StrBufAppendPrintf(Target, " ");
1339 StrBufAppendPrintf(Target, "</TD></TR>\n");
1342 /* else if (!strcasecmp(firsttoken, "photo") && full && pass == 2) {
1343 // Only output on second pass
1344 StrBufAppendPrintf(Target, "<tr><td>");
1345 StrBufAppendPrintf(Target, _("Photo:"));
1346 StrBufAppendPrintf(Target, "</td><td>");
1347 StrBufAppendPrintf(Target, "<img src=\"/vcardphoto/%ld/\" alt=\"Contact photo\"/>",msgnum);
1348 StrBufAppendPrintf(Target, "</td></tr>\n");
1350 else if (!strcasecmp(firsttoken, "version")) {
1353 else if (!strcasecmp(firsttoken, "rev")) {
1356 else if (!strcasecmp(firsttoken, "label")) {
1361 /*** Don't show extra fields. They're ugly.
1363 StrBufAppendPrintf(Target, "<TR><TD>");
1364 StrEscAppend(Target, NULL, thisname, 0, 0);
1365 StrBufAppendPrintf(Target, "</TD><TD>");
1366 StrEscAppend(Target, NULL, thisvalue, 0, 0);
1367 StrBufAppendPrintf(Target, "</TD></TR>\n");
1377 StrBufAppendPrintf(Target, "<TR BGCOLOR=\"#AAAAAA\">"
1378 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
1379 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
1380 "<FONT SIZE=+1><B>");
1381 StrEscAppend(Target, NULL, fullname, 0, 0);
1382 StrBufAppendPrintf(Target, "</B></FONT>");
1383 if (!IsEmptyStr(title)) {
1384 StrBufAppendPrintf(Target, "<div align=right>");
1385 StrEscAppend(Target, NULL, title, 0, 0);
1386 StrBufAppendPrintf(Target, "</div>");
1388 if (!IsEmptyStr(org)) {
1389 StrBufAppendPrintf(Target, "<div align=right>");
1390 StrEscAppend(Target, NULL, org, 0, 0);
1391 StrBufAppendPrintf(Target, "</div>");
1393 StrBufAppendPrintf(Target, "</TD></TR>\n");
1395 if (!IsEmptyStr(phone)) {
1396 StrBufAppendPrintf(Target, "<tr><td>");
1397 StrBufAppendPrintf(Target, _("Telephone:"));
1398 StrBufAppendPrintf(Target, "</td><td>%s</td></tr>\n", phone);
1400 if (!IsEmptyStr(mailto)) {
1401 StrBufAppendPrintf(Target, "<tr><td>");
1402 StrBufAppendPrintf(Target, _("E-mail:"));
1403 StrBufAppendPrintf(Target, "</td><td>%s</td></tr>\n", mailto);
1409 StrBufAppendPrintf(Target, "</table></div>\n");
1415 * \brief Display a textual vCard
1416 * (Converts to a vCard object and then calls the actual display function)
1417 * Set 'full' to nonzero to display the whole card instead of a one-liner.
1418 * Or, if "storename" is non-NULL, just store the person's name in that
1419 * buffer instead of displaying the card at all.
1420 * \param vcard_source the buffer containing the vcard text
1421 * \param alpha what???
1422 * \param full should we usse all lines?
1423 * \param storename where to store???
1424 * \param msgnum Citadel message pointer
1426 void display_vcard(StrBuf *Target, const char *vcard_source, char alpha, int full, char *storename,
1431 char this_alpha = 0;
1433 v = vcard_load((char*)vcard_source); ///TODO
1435 if (v == NULL) return;
1437 name = vcard_get_prop(v, "n", 1, 0, 0);
1439 utf8ify_rfc822_string(name);
1441 this_alpha = buf[0];
1444 if (storename != NULL) {
1445 fetchname_parsed_vcard(v, storename);
1447 else if ( (alpha == 0)
1448 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
1449 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
1451 display_parsed_vcard(Target, v, full,msgnum);
1469 * I wanna SEE that message!
1471 * msgnum Message number to display
1472 * printable_view Nonzero to display a printable view
1473 * section Optional for encapsulated message/rfc822 submessage
1475 void read_message(long msgnum, int printable_view, char *section) {
1476 struct wcsession *WCC = WC;
1479 StrBuf *FoundCharset;
1480 message_summary *Msg = NULL;
1484 struct attach_link *attach_links = NULL;
1485 int num_attach_links = 0;
1486 // char mime_submessages[256] = "";
1487 char reply_references[1024] = "";
1491 char vcard_partnum[256] = "";
1492 char cal_partnum[256] = "";
1493 char *part_source = NULL;
1494 char msg4_partnum[32] = "";
1496 //// strcpy(mime_submessages, "");
1499 serv_printf("MSG4 %ld|%s", msgnum, section);
1500 StrBuf_ServGetln(Buf);
1501 if (GetServerStatus(Buf, NULL) != 1) {
1502 wprintf("<strong>");
1503 wprintf(_("ERROR:"));
1504 wprintf("</strong> %s<br />\n", &buf[4]);
1508 svputlong("MsgPrintable", printable_view);
1509 /** begin everythingamundo table */
1512 Token = NewStrBuf();
1513 Msg = (message_summary *)malloc(sizeof(message_summary));
1514 memset(Msg, 0, sizeof(message_summary));
1515 Msg->msgnum = msgnum;
1516 FoundCharset = NewStrBuf();
1517 while ((StrBuf_ServGetln(Buf)>=0) && !Done) {
1518 if ( (StrLength(Buf)==3) &&
1519 !strcmp(ChrPtr(Buf), "000"))
1524 wprintf(_("unexpected end of message"));
1525 wprintf(" (1)</i><br /><br />\n");
1526 wprintf("</div>\n");
1529 DestroyMessageSummary(Msg);
1530 FreeStrBuf(&FoundCharset);
1538 case 0:/* Citadel Message Headers */
1539 if (StrLength(Buf) == 0) {
1543 StrBufExtract_token(Token, Buf, 0, '=');
1544 StrBufCutLeft(Buf, StrLength(Token) + 1);
1546 lprintf(1, ":: [%s] = [%s]\n", ChrPtr(Token), ChrPtr(Buf));
1547 if (GetHash(MsgHeaderHandler, SKEY(Token), &vHdr) &&
1549 Hdr = (headereval*)vHdr;
1550 Hdr->evaluator(Msg, Buf, FoundCharset);
1551 if (Hdr->Type == 1) {
1555 else lprintf(1, "don't know how to handle message header[%s]\n", ChrPtr(Token));
1557 case 1:/* Message Mime Header */
1558 if (StrLength(Buf) == 0) {
1560 if (Msg->MsgBody.ContentType == NULL)
1561 /* end of header or no header? */
1562 Msg->MsgBody.ContentType = NewStrBufPlain(HKEY("text/plain"));
1563 /* usual end of mime header */
1567 StrBufExtract_token(Token, Buf, 0, ':');
1568 if (StrLength(Token) > 0) {
1569 StrBufCutLeft(Buf, StrLength(Token) + 1);
1570 lprintf(1, ":: [%s] = [%s]\n", ChrPtr(Token), ChrPtr(Buf));
1571 if (GetHash(MsgHeaderHandler, SKEY(Token), &vHdr) &&
1573 Hdr = (headereval*)vHdr;
1574 Hdr->evaluator(Msg, Buf, FoundCharset);
1579 case 2: /* Message Body */
1581 if (Msg->MsgBody.size_known > 0) {
1582 StrBuf_ServGetBLOB(Msg->MsgBody.Data, Msg->MsgBody.length);
1584 /// todo: check next line, if not 000, append following lines
1587 if (StrLength(Msg->MsgBody.Data) > 0)
1588 StrBufAppendBufPlain(Msg->MsgBody.Data, "\n", 1, 0);
1589 StrBufAppendBuf(Msg->MsgBody.Data, Buf, 0);
1593 StrBufAppendBuf(Msg->MsgBody.Data, Buf, 0);
1598 /* strip the bare contenttype, so we ommit charset etc. */
1599 StrBufExtract_token(Buf, Msg->MsgBody.ContentType, 0, ';');
1601 if (GetHash(MimeRenderHandler, SKEY(Buf), &vHdr) &&
1603 RenderMimeFunc Render;
1604 Render = (RenderMimeFunc)vHdr;
1605 Render(&Msg->MsgBody, NULL, FoundCharset);
1609 if (StrLength(Msg->reply_references)> 0) {
1610 /* Trim down excessively long lists of thread references. We eliminate the
1611 * second one in the list so that the thread root remains intact.
1613 int rrtok = num_tokens(ChrPtr(Msg->reply_references), '|');
1614 int rrlen = StrLength(Msg->reply_references);
1615 if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
1616 remove_token(reply_references, 1, '|');////todo
1620 /* Generate a reply-to address */
1621 if (StrLength(Msg->Rfca) > 0) {
1622 if (Msg->reply_to == NULL)
1623 Msg->reply_to = NewStrBuf();
1624 if (StrLength(Msg->from) > 0) {
1625 StrBufPrintf(Msg->reply_to, "%s <%s>", ChrPtr(Msg->from), ChrPtr(Msg->Rfca));
1628 FlushStrBuf(Msg->reply_to);
1629 StrBufAppendBuf(Msg->reply_to, Msg->Rfca, 0);
1634 if ((StrLength(Msg->OtherNode)>0) &&
1635 (strcasecmp(ChrPtr(Msg->OtherNode), serv_info.serv_nodename)) &&
1636 (strcasecmp(ChrPtr(Msg->OtherNode), serv_info.serv_humannode)) )
1638 if (Msg->reply_to == NULL)
1639 Msg->reply_to = NewStrBuf();
1640 StrBufPrintf(Msg->reply_to,
1643 ChrPtr(Msg->OtherNode));
1646 if (Msg->reply_to == NULL)
1647 Msg->reply_to = NewStrBuf();
1648 FlushStrBuf(Msg->reply_to);
1649 StrBufAppendBuf(Msg->reply_to, Msg->from, 0);
1652 DoTemplate(HKEY("view_message"), NULL, Msg, CTX_MAILSUM);
1656 //// put message renderer lookup here.
1657 ///ENDBODY: /* If there are attached submessages, display them now... */
1659 /// if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
1660 /// for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
1661 /// extract_token(buf, mime_submessages, i, '|', sizeof buf);
1662 /// /** use printable_view to suppress buttons */
1663 /// wprintf("<blockquote>");
1664 /// read_message(msgnum, 1, buf);
1665 /// wprintf("</blockquote>");
1670 /* Afterwards, offer links to download attachments 'n' such */
1671 if ( (num_attach_links > 0) && (!section[0]) ) {
1672 for (i=0; i<num_attach_links; ++i) {
1673 if (strcasecmp(attach_links[i].partnum, msg4_partnum)) {
1674 wprintf("%s", attach_links[i].html);
1679 /* Handler for vCard parts */
1680 if (!IsEmptyStr(vcard_partnum)) {
1681 part_source = load_mimepart(msgnum, vcard_partnum);
1682 if (part_source != NULL) {
1684 /** If it's my vCard I can edit it */
1685 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1686 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1687 || (WC->wc_view == VIEW_ADDRESSBOOK)
1689 wprintf("<a href=\"edit_vcard?msgnum=%ld&partnum=%s\">",
1690 msgnum, vcard_partnum);
1691 wprintf("[%s]</a>", _("edit"));
1694 /* In all cases, display the full card */
1695 display_vcard(WC->WBuf, part_source, 0, 1, NULL,msgnum);
1699 /* Handler for calendar parts */
1700 if (!IsEmptyStr(cal_partnum)) {
1708 wprintf("</div>\n");
1710 /* end everythingamundo table */
1711 if (!printable_view) {
1712 wprintf("</div>\n");
1715 if (num_attach_links > 0) {
1718 DestroyMessageSummary(Msg);
1719 FreeStrBuf(&FoundCharset);
1727 * Unadorned HTML output of an individual message, suitable
1728 * for placing in a hidden iframe, for printing, or whatever
1730 * msgnum_as_string == Message number, as a string instead of as a long int
1732 void embed_message(void) {
1735 msgnum = StrTol(WC->UrlFragment1);
1736 read_message(msgnum, 0, "");
1741 * Printable view of a message
1743 * msgnum_as_string == Message number, as a string instead of as a long int
1745 void print_message(void) {
1748 msgnum = StrTol(WC->UrlFragment1);
1749 output_headers(0, 0, 0, 0, 0, 0);
1751 hprintf("Content-type: text/html\r\n"
1753 "Connection: close\r\n",
1757 wprintf("\r\n<html>\n<head><title>");
1758 escputs(WC->wc_fullname);
1759 wprintf("</title></head>\n"
1760 "<body onLoad=\" window.print(); window.close(); \">\n"
1763 read_message(msgnum, 1, "");
1765 wprintf("\n</body></html>\n\n");
1770 * Mobile browser view of message
1772 * @param msg_num_as_string Message number as a string instead of as a long int
1774 void mobile_message_view(void) {
1776 msgnum = StrTol(WC->UrlFragment1);
1777 output_headers(1, 0, 0, 0, 0, 1);
1779 do_template("msgcontrols", NULL);
1780 read_message(msgnum,1, "");
1785 * \brief Display a message's headers
1787 * \param msgnum_as_string Message number, as a string instead of as a long int
1789 void display_headers(void) {
1793 msgnum = StrTol(WC->UrlFragment1);
1794 output_headers(0, 0, 0, 0, 0, 0);
1796 hprintf("Content-type: text/plain\r\n"
1798 "Connection: close\r\n",
1802 serv_printf("MSG2 %ld|3", msgnum);
1803 serv_getln(buf, sizeof buf);
1804 if (buf[0] == '1') {
1805 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1806 wprintf("%s\n", buf);
1816 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
1817 * or 'reply quoted' operations.
1819 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1820 * in this function. Doing so would throw a JavaScript error in the
1821 * 'supplied text' argument to the editor.
1823 * \param msgnum Message number of the message we want to quote
1824 * \param forward_attachments Nonzero if we want attachments to be forwarded
1826 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
1828 char mime_partnum[256];
1829 char mime_filename[256];
1830 char mime_content_type[256];
1831 char mime_charset[256];
1832 char mime_disposition[256];
1834 char *attachments = NULL;
1836 int num_attachments = 0;
1837 struct wc_attachment *att, *aptr;
1838 char m_subject[1024];
1845 int format_type = 0;
1850 iconv_t ic = (iconv_t)(-1) ;
1851 char *ibuf; /**< Buffer of characters to be converted */
1852 char *obuf; /**< Buffer for converted characters */
1853 size_t ibuflen; /**< Length of input buffer */
1854 size_t obuflen; /**< Length of output buffer */
1855 char *osav; /**< Saved pointer to output buffer */
1861 strcpy(reply_to, "");
1862 strcpy(mime_content_type, "text/plain");
1863 strcpy(mime_charset, "us-ascii");
1865 serv_printf("MSG4 %ld", msgnum);
1866 serv_getln(buf, sizeof buf);
1867 if (buf[0] != '1') {
1868 wprintf(_("ERROR:"));
1869 wprintf("%s<br />", &buf[4]);
1873 strcpy(m_subject, "");
1875 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1876 if (!strcmp(buf, "000")) {
1877 wprintf("%s (3)", _("unexpected end of message"));
1880 if (include_headers) {
1881 if (!strncasecmp(buf, "nhdr=yes", 8))
1885 if (!strncasecmp(buf, "type=", 5))
1886 format_type = atoi(&buf[5]);
1887 if (!strncasecmp(buf, "from=", 5)) {
1888 strcpy(from, &buf[5]);
1889 wprintf(_("from "));
1890 utf8ify_rfc822_string(from);
1893 if (!strncasecmp(buf, "subj=", 5)) {
1894 strcpy(m_subject, &buf[5]);
1896 if ((!strncasecmp(buf, "hnod=", 5))
1897 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1898 wprintf("(%s) ", &buf[5]);
1900 if ((!strncasecmp(buf, "room=", 5))
1901 && (strcasecmp(&buf[5], WC->wc_roomname))
1902 && (!IsEmptyStr(&buf[5])) ) {
1904 wprintf("%s> ", &buf[5]);
1906 if (!strncasecmp(buf, "rfca=", 5)) {
1907 strcpy(rfca, &buf[5]);
1912 if (!strncasecmp(buf, "node=", 5)) {
1913 strcpy(node, &buf[5]);
1914 if ( ((WC->room_flags & QR_NETWORK)
1915 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1916 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1917 && (IsEmptyStr(rfca))
1919 wprintf("@%s ", &buf[5]);
1922 if (!strncasecmp(buf, "rcpt=", 5)) {
1924 strcpy(to, &buf[5]);
1925 utf8ify_rfc822_string(to);
1928 if (!strncasecmp(buf, "time=", 5)) {
1929 webcit_fmt_date(now, atol(&buf[5]), 0);
1930 wprintf("%s ", now);
1935 * Save attachment info for later. We can't start downloading them
1936 * yet because we're in the middle of a server transaction.
1938 if (!strncasecmp(buf, "part=", 5)) {
1939 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
1942 sprintf(ptr, "%s%s\n",
1943 ((attachments != NULL) ? attachments : ""),
1948 lprintf(9, "attachments=<%s>\n", attachments);
1954 if (include_headers) {
1957 utf8ify_rfc822_string(m_subject);
1958 if (!IsEmptyStr(m_subject)) {
1959 wprintf(_("Subject:"));
1961 msgescputs(m_subject);
1972 * Learn the content type
1974 strcpy(mime_content_type, "text/plain");
1975 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
1976 if (!strcmp(buf, "000")) {
1977 wprintf("%s (4)", _("unexpected end of message"));
1980 if (!strncasecmp(buf, "Content-type: ", 14)) {
1982 safestrncpy(mime_content_type, &buf[14],
1983 sizeof(mime_content_type));
1984 for (i=0; i<strlen(mime_content_type); ++i) {
1985 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1986 safestrncpy(mime_charset, &mime_content_type[i+8],
1987 sizeof mime_charset);
1990 len = strlen(mime_content_type);
1991 for (i=0; i<len; ++i) {
1992 if (mime_content_type[i] == ';') {
1993 mime_content_type[i] = 0;
1997 len = strlen(mime_charset);
1998 for (i=0; i<len; ++i) {
1999 if (mime_charset[i] == ';') {
2000 mime_charset[i] = 0;
2007 /** Set up a character set conversion if we need to (and if we can) */
2009 if ( (strcasecmp(mime_charset, "us-ascii"))
2010 && (strcasecmp(mime_charset, "UTF-8"))
2011 && (strcasecmp(mime_charset, ""))
2013 ctdl_iconv_open("UTF-8", mime_charset, &ic);
2014 if (ic == (iconv_t)(-1) ) {
2015 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
2016 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
2021 /** Messages in legacy Citadel variformat get handled thusly... */
2022 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
2026 /* Boring old 80-column fixed format text gets handled this way... */
2027 else if (!strcasecmp(mime_content_type, "text/plain")) {
2028 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2031 if ((len > 0) && (buf[len-1] == '\n')) buf[--len] = 0;
2032 if ((len > 0) && (buf[len-1] == '\r')) buf[--len] = 0;
2035 if (ic != (iconv_t)(-1) ) {
2039 obuf = (char *) malloc(obuflen);
2041 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
2042 osav[SIZ-obuflen] = 0;
2043 safestrncpy(buf, osav, sizeof buf);
2049 while ((!IsEmptyStr(buf)) && (isspace(buf[len - 1])))
2052 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
2053 wprintf("<blockquote>");
2055 } else if ((bq == 1) &&
2056 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
2057 wprintf("</blockquote>");
2061 url(buf, sizeof(buf));
2063 wprintf("</tt><br />");
2065 wprintf("</i><br />");
2068 /** HTML just gets escaped and stuffed back into the editor */
2069 else if (!strcasecmp(mime_content_type, "text/html")) {
2070 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2074 }//// TODO: charset? utf8?
2076 /** Unknown weirdness ... don't know how to handle this content type */
2078 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
2082 /** end of body handler */
2085 * If there were attachments, we have to download them and insert them
2086 * into the attachment chain for the forwarded message we are composing.
2088 if ( (forward_attachments) && (num_attachments) ) {
2089 for (i=0; i<num_attachments; ++i) {
2090 extract_token(buf, attachments, i, '\n', sizeof buf);
2091 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
2092 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
2093 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
2094 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
2095 mime_length = extract_int(buf, 5);
2098 * tracing ... uncomment if necessary
2101 lprintf(9, "fwd filename: %s\n", mime_filename);
2102 lprintf(9, "fwd partnum : %s\n", mime_partnum);
2103 lprintf(9, "fwd conttype: %s\n", mime_content_type);
2104 lprintf(9, "fwd dispose : %s\n", mime_disposition);
2105 lprintf(9, "fwd length : %d\n", mime_length);
2107 if ( (!strcasecmp(mime_disposition, "inline"))
2108 || (!strcasecmp(mime_disposition, "attachment")) ) {
2110 /* Create an attachment struct from this mime part... */
2111 att = malloc(sizeof(struct wc_attachment));
2112 memset(att, 0, sizeof(struct wc_attachment));
2113 att->length = mime_length;
2114 strcpy(att->content_type, mime_content_type);
2115 strcpy(att->filename, mime_filename);
2117 att->data = load_mimepart(msgnum, mime_partnum);
2119 /* And add it to the list. */
2120 if (WC->first_attachment == NULL) {
2121 WC->first_attachment = att;
2124 aptr = WC->first_attachment;
2125 while (aptr->next != NULL) aptr = aptr->next;
2134 if (ic != (iconv_t)(-1) ) {
2139 if (attachments != NULL) {
2147 void EvaluateMimePart(message_summary *Sum, StrBuf *Buf)
2150 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
2151 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
2152 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
2153 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
2154 mime_length = extract_int(&buf[5], 5);
2156 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
2157 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
2158 strcpy(vcard_partnum, mime_partnum);
2163 message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSubject, long MsgNum)
2166 MsgPartEvaluatorFunc Eval;
2167 message_summary *Msg;
2176 serv_printf("MSG0 %ld|1", MsgNum); /* ask for headers only */
2178 StrBuf_ServGetln(Buf);
2179 if (GetServerStatus(Buf, NULL) == 1) {
2184 Msg = (message_summary*)malloc(sizeof(message_summary));
2185 memset(Msg, 0, sizeof(message_summary));
2186 while (len = StrBuf_ServGetln(Buf),
2188 strcmp(ChrPtr(Buf), "000")== 0)){
2190 ebuf = strchr(ChrPtr(Buf), '=');
2192 if (GetHash(MsgEvaluators, buf, nBuf, &vEval) && vEval != NULL) {
2193 Eval = (MsgPartEvaluatorFunc) vEval;
2194 StrBufCutLeft(Buf, nBuf + 1);
2197 else lprintf(1, "Don't know how to handle Message Headerline [%s]", ChrPtr(Buf));
2204 * \brief display the adressbook overview
2205 * \param msgnum the citadel message number
2206 * \param alpha what????
2208 void display_addressbook(long msgnum, char alpha) {
2210 /* char mime_partnum[SIZ]; */
2211 /* char mime_filename[SIZ]; */
2212 /* char mime_content_type[SIZ]; */
2213 ///char mime_disposition[SIZ];
2215 char vcard_partnum[SIZ];
2216 char *vcard_source = NULL;
2217 message_summary summ;////TODO: this will leak
2219 memset(&summ, 0, sizeof(summ));
2220 ///safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
2221 ///Load Message headers
2223 if (!IsEmptyStr(vcard_partnum)) {
2224 vcard_source = load_mimepart(msgnum, vcard_partnum);
2225 if (vcard_source != NULL) {
2227 /** Display the summary line */
2228 display_vcard(WC->WBuf, vcard_source, alpha, 0, NULL,msgnum);
2230 /** If it's my vCard I can edit it */
2231 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
2232 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
2233 || (WC->wc_view == VIEW_ADDRESSBOOK)
2235 wprintf("<a href=\"edit_vcard?"
2236 "msgnum=%ld&partnum=%s\">",
2237 msgnum, vcard_partnum);
2238 wprintf("[%s]</a>", _("edit"));
2250 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
2251 * \param namebuf name to analyze, reverse if nescessary
2253 void lastfirst_firstlast(char *namebuf) {
2254 char firstname[SIZ];
2258 if (namebuf == NULL) return;
2259 if (strchr(namebuf, ';') != NULL) return;
2261 i = num_tokens(namebuf, ' ');
2264 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
2265 remove_token(namebuf, i-1, ' ');
2266 strcpy(firstname, namebuf);
2267 sprintf(namebuf, "%s; %s", lastname, firstname);
2271 * \brief fetch what??? name
2272 * \param msgnum the citadel message number
2273 * \param namebuf where to put the name in???
2275 void fetch_ab_name(message_summary *Msg, char *namebuf) {
2277 char mime_partnum[SIZ];
2278 char mime_filename[SIZ];
2279 char mime_content_type[SIZ];
2280 char mime_disposition[SIZ];
2282 char vcard_partnum[SIZ];
2283 char *vcard_source = NULL;
2285 message_summary summ;/// TODO this will lak
2287 if (namebuf == NULL) return;
2288 strcpy(namebuf, "");
2290 memset(&summ, 0, sizeof(summ));
2291 //////safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
2293 sprintf(buf, "MSG0 %ld|0", Msg->msgnum); /** unfortunately we need the mime info now */
2295 serv_getln(buf, sizeof buf);
2296 if (buf[0] != '1') return;
2298 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2299 if (!strncasecmp(buf, "part=", 5)) {
2300 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
2301 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
2302 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
2303 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
2304 mime_length = extract_int(&buf[5], 5);
2306 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
2307 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
2308 strcpy(vcard_partnum, mime_partnum);
2314 if (!IsEmptyStr(vcard_partnum)) {
2315 vcard_source = load_mimepart(Msg->msgnum, vcard_partnum);
2316 if (vcard_source != NULL) {
2318 /* Grab the name off the card */
2319 display_vcard(WC->WBuf, vcard_source, 0, 0, namebuf, Msg->msgnum);
2325 lastfirst_firstlast(namebuf);
2327 len = strlen(namebuf);
2328 for (i=0; i<len; ++i) {
2329 if (namebuf[i] != ';') return;
2331 strcpy(namebuf, _("(no name)"));
2337 * \brief Record compare function for sorting address book indices
2338 * \param ab1 adressbook one
2339 * \param ab2 adressbook two
2341 int abcmp(const void *ab1, const void *ab2) {
2343 (((const struct addrbookent *)ab1)->ab_name),
2344 (((const struct addrbookent *)ab2)->ab_name)
2350 * \brief Helper function for do_addrbook_view()
2351 * Converts a name into a three-letter tab label
2352 * \param tabbuf the tabbuffer to add name to
2353 * \param name the name to add to the tabbuffer
2355 void nametab(char *tabbuf, long len, char *name) {
2356 stresc(tabbuf, len, name, 0, 0);
2357 tabbuf[0] = toupper(tabbuf[0]);
2358 tabbuf[1] = tolower(tabbuf[1]);
2359 tabbuf[2] = tolower(tabbuf[2]);
2365 * \brief Render the address book using info we gathered during the scan
2366 * \param addrbook the addressbook to render
2367 * \param num_ab the number of the addressbook
2369 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
2373 static int NAMESPERPAGE = 60;
2376 char tabfirst_label[64];
2378 char tablast_label[64];
2379 char this_tablabel[64];
2384 wprintf("<br /><br /><br /><div align=\"center\"><i>");
2385 wprintf(_("This address book is empty."));
2386 wprintf("</i></div>\n");
2391 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
2394 num_pages = (num_ab / NAMESPERPAGE) + 1;
2396 tablabels = malloc(num_pages * sizeof (char *));
2397 if (tablabels == NULL) {
2398 wprintf("<br /><br /><br /><div align=\"center\"><i>");
2399 wprintf(_("An internal error has occurred."));
2400 wprintf("</i></div>\n");
2404 for (i=0; i<num_pages; ++i) {
2405 tabfirst = i * NAMESPERPAGE;
2406 tablast = tabfirst + NAMESPERPAGE - 1;
2407 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
2408 nametab(tabfirst_label, 64, addrbook[tabfirst].ab_name);
2409 nametab(tablast_label, 64, addrbook[tablast].ab_name);
2410 sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
2411 tablabels[i] = strdup(this_tablabel);
2414 tabbed_dialog(num_pages, tablabels);
2417 for (i=0; i<num_ab; ++i) {
2419 if ((i / NAMESPERPAGE) != page) { /* New tab */
2420 page = (i / NAMESPERPAGE);
2422 wprintf("</tr></table>\n");
2423 end_tab(page-1, num_pages);
2425 begin_tab(page, num_pages);
2426 wprintf("<table border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
2430 if ((displayed % 4) == 0) {
2431 if (displayed > 0) {
2435 wprintf("<tr bgcolor=\"#%s\">",
2436 (bg ? "DDDDDD" : "FFFFFF")
2442 wprintf("<a href=\"readfwd?startmsg=%ld?is_singlecard=1",
2443 addrbook[i].ab_msgnum);
2444 wprintf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
2445 vcard_n_prettyize(addrbook[i].ab_name);
2446 escputs(addrbook[i].ab_name);
2447 wprintf("</a></td>\n");
2451 /* Placeholders for empty columns at end */
2452 if ((num_ab % 4) != 0) {
2453 for (i=0; i<(4-(num_ab % 4)); ++i) {
2454 wprintf("<td> </td>");
2458 wprintf("</tr></table>\n");
2459 end_tab((num_pages-1), num_pages);
2461 begin_tab(num_pages, num_pages);
2462 /* FIXME there ought to be something here */
2463 end_tab(num_pages, num_pages);
2465 for (i=0; i<num_pages; ++i) {
2474 * load message pointers from the server for a "read messages" operation
2476 * servcmd: the citadel command to send to the citserver
2477 * with_headers: also include some of the headers with the message numbers (more expensive)
2479 int load_msg_ptrs(char *servcmd, int with_headers)
2481 StrBuf* FoundCharset = NULL;
2482 struct wcsession *WCC = WC;
2483 message_summary *Msg;
2486 ///time_t datestamp;
2487 //char fullname[128];
2488 //char nodename[128];
2489 //char inetaddr[128];
2490 //char subject[1024];
2497 ////int num_summ_alloc = 0;
2499 if (WCC->summ != NULL) {
2500 if (WCC->summ != NULL)
2501 DeleteHash(&WCC->summ);
2503 WCC->summ = NewHash(1, Flathash);
2505 maxload = 1000;/// TODO
2509 StrBuf_ServGetln(Buf);
2510 if (GetServerStatus(Buf, NULL) != 1) {
2514 // TODO if (with_headers) { //// TODO: Have Attachments?
2516 while (len = StrBuf_ServGetln(Buf),
2518 strcmp(ChrPtr(Buf), "000")!= 0))
2520 if (nummsgs < maxload) {
2521 Msg = (message_summary*)malloc(sizeof(message_summary));
2522 memset(Msg, 0, sizeof(message_summary));
2524 Msg->msgnum = StrBufExtract_long(Buf, 0, '|');
2525 Msg->date = StrBufExtract_long(Buf, 1, '|');
2527 Msg->from = NewStrBufPlain(NULL, StrLength(Buf));
2528 StrBufExtract_token(Buf2, Buf, 2, '|');
2529 if (StrLength(Buf2) != 0) {
2530 /** Handle senders with RFC2047 encoding */
2531 StrBuf_RFC822_to_Utf8(Msg->from, Buf2, WCC->DefaultCharset, FoundCharset);
2535 StrBufExtract_token(Buf2, Buf, 3, '|');
2536 if ((StrLength(Buf2) !=0 ) &&
2537 ( ((WCC->room_flags & QR_NETWORK)
2538 || ((strcasecmp(ChrPtr(Buf2), serv_info.serv_nodename)
2539 && (strcasecmp(ChrPtr(Buf2), serv_info.serv_fqdn)))))))
2541 StrBufAppendBufPlain(Msg->from, HKEY(" @ "), 0);
2542 StrBufAppendBuf(Msg->from, Buf2, 0);
2546 StrBufExtract_token(Msg->inetaddr, Buf, 4, '|');
2549 Msg->subj = NewStrBufPlain(NULL, StrLength(Buf));
2550 StrBufExtract_token(Buf2, Buf, 5, '|');
2551 if (StrLength(Buf2) == 0)
2552 StrBufAppendBufPlain(Msg->subj, _("(no subj)"), 0, -1);
2554 StrBuf_RFC822_to_Utf8(Msg->subj, Buf2, WCC->DefaultCharset, FoundCharset);
2555 if ((StrLength(Msg->subj) > 75) &&
2556 (StrBuf_Utf8StrLen(Msg->subj) > 75)) {
2557 StrBuf_Utf8StrCut(Msg->subj, 72);
2558 StrBufAppendBufPlain(Msg->subj, HKEY("..."), 0);
2563 if ((StrLength(Msg->from) > 25) &&
2564 (StrBuf_Utf8StrLen(Msg->from) > 25)) {
2565 StrBuf_Utf8StrCut(Msg->from, 23);
2566 StrBufAppendBufPlain(Msg->from, HKEY("..."), 0);
2568 Put(WCC->summ, (const char*)&Msg->msgnum, sizeof(Msg->msgnum), Msg, DestroyMessageSummary);
2583 * command loop for reading messages
2585 * Set oper to "readnew" or "readold" or "readfwd" or "headers"
2587 void readloop(char *oper)
2590 message_summary *Msg;
2599 long *displayed_msgs = NULL;
2600 int num_displayed = 0;
2602 int is_addressbook = 0;
2603 int is_singlecard = 0;
2604 int is_calendar = 0;
2605 struct calview calv;
2610 int lowest_displayed = (-1);
2611 int highest_displayed = 0;
2612 struct addrbookent *addrbook = NULL;
2614 const StrBuf *sortby = NULL;
2616 int SortBy = eRDate;
2617 const StrBuf *sortpref_value;
2618 int bbs_reverse = 0;
2619 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
2621 const char *HashKey;
2624 if (WCC->wc_view == VIEW_WIKI) {
2625 sprintf(buf, "wiki?room=%s&page=home", WCC->wc_roomname);
2630 startmsg = lbstr("startmsg");
2631 maxmsgs = ibstr("maxmsgs");
2632 is_summary = (ibstr("is_summary") && !WCC->is_mobile);
2633 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
2635 sortpref_value = get_room_pref("sort");
2637 sortby = sbstr("sortby");
2638 if ( (!IsEmptyStr(ChrPtr(sortby))) &&
2639 (strcasecmp(ChrPtr(sortby), ChrPtr(sortpref_value)) != 0)) {
2640 set_room_pref("sort", NewStrBufDup(sortby), 1);
2641 sortpref_value = NULL;
2642 sortpref_value = sortby;
2645 SortBy = StrToESort(sortpref_value);
2646 /* message board sort */
2647 if (SortBy == eReverse) {
2654 output_headers(1, 1, 1, 0, 0, 0);
2657 * When in summary mode, always show ALL messages instead of just
2658 * new or old. Otherwise, show what the user asked for.
2660 if (!strcmp(oper, "readnew")) {
2661 strcpy(cmd, "MSGS NEW");
2663 else if (!strcmp(oper, "readold")) {
2664 strcpy(cmd, "MSGS OLD");
2666 else if (!strcmp(oper, "do_search")) {
2667 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2670 strcpy(cmd, "MSGS ALL");
2673 if ((WCC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1) && !WCC->is_mobile) {
2675 if (!strcmp(oper, "do_search")) {
2676 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2679 strcpy(cmd, "MSGS ALL");
2683 if ((WCC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2685 if (!strcmp(oper, "do_search")) {
2686 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2689 strcpy(cmd, "MSGS ALL");
2694 if (is_summary) { /**< fetch header summary */
2695 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
2696 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2697 (!strcmp(oper, "do_search") ? bstr("query") : "")
2702 if (WCC->is_mobile) {
2704 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
2705 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2706 (!strcmp(oper, "do_search") ? bstr("query") : "")
2712 * Are we doing a summary view? If so, we need to know old messages
2713 * and new messages, so we can do that pretty boldface thing for the
2716 strcpy(old_msgs, "");
2717 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR) || WCC->is_mobile){
2719 serv_getln(buf, sizeof buf);
2720 if (buf[0] == '2') {
2721 strcpy(old_msgs, &buf[4]);
2725 is_singlecard = ibstr("is_singlecard");
2727 if (WCC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
2729 strcpy(cmd, "MSGS ALL|||1");
2731 parse_calendar_view_request(&calv);
2733 if (WCC->wc_default_view == VIEW_TASKS) { /**< tasks */
2735 strcpy(cmd, "MSGS ALL");
2738 if (WCC->wc_default_view == VIEW_NOTES) { /**< notes */
2740 strcpy(cmd, "MSGS ALL");
2745 wprintf("<div id=\"new_notes_here\"></div>\n");
2748 nummsgs = load_msg_ptrs(cmd, (is_summary || WCC->is_mobile));
2751 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2752 wprintf("<div align=\"center\"><br /><em>");
2753 if (!strcmp(oper, "readnew")) {
2754 wprintf(_("No new messages."));
2755 } else if (!strcmp(oper, "readold")) {
2756 wprintf(_("No old messages."));
2758 wprintf(_("No messages here."));
2760 wprintf("</em><br /></div>\n");
2766 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR) || WCC->is_mobile){
2768 message_summary *Msg;
2770 at = GetNewHashPos();
2771 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
2772 /** Are you a new message, or an old message? */
2773 Msg = (message_summary*) vMsg;
2775 if (is_msg_in_mset(old_msgs, Msg->msgnum)) {
2786 if (startmsg == 0L) {
2788 startmsg = WCC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2791 startmsg = WCC->msgarr[0];
2795 if (is_summary || WCC->is_mobile) {
2796 SortByPayload(WCC->summ, SortFuncs[SortBy]);
2801 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2802 " document.onkeydown = CtdlMsgListKeyPress; "
2803 " if (document.layers) { "
2804 " document.captureEvents(Event.KEYPRESS); "
2809 /** note that Date and Delete are now in the same column */
2810 wprintf("<div id=\"message_list_hdr\">"
2811 "<div class=\"fix_scrollbar_bug\">"
2812 "<table cellspacing=0 style=\"width:100%%\">"
2815 wprintf("<th width=%d%%>%s <a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=%s\"><img border=\"0\" src=\"%s\" /></a> </th>\n"
2816 "<th width=%d%%>%s <a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=%s\"><img border=\"0\" src=\"%s\" /></a> </th>\n"
2817 "<th width=%d%%>%s <a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=%s\"><img border=\"0\" src=\"%s\" /></a> \n"
2819 "<input type=\"submit\" name=\"delete_button\" id=\"delbutton\" "
2820 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2827 SortByStrings[SubjectInvertSortString[SortBy]],
2828 SortIcons[SortSubjectToIcon[SortBy]],
2829 SENDER_COL_WIDTH_PCT,
2831 SortByStrings[SenderInvertSortString[SortBy]],
2832 SortIcons[SortSenderToIcon[SortBy]],
2833 DATE_PLUS_BUTTONS_WIDTH_PCT,
2835 SortByStrings[DateInvertSortString[SortBy]],
2836 SortIcons[SortDateToIcon[SortBy]],
2839 wprintf("</table></div></div>\n");
2840 wprintf("<div id=\"message_list\">"
2842 "<div class=\"fix_scrollbar_bug\">\n"
2843 "<table class=\"mailbox_summary\" id=\"summary_headers\" "
2844 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2846 } else if (WCC->is_mobile) {
2847 wprintf("<div id=\"message_list\">");
2852 * Set the "is_bbview" variable if it appears that we are looking at
2853 * a classic bulletin board view.
2855 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2856 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2861 * If we're not currently looking at ALL requested
2862 * messages, then display the selector bar
2865 /** begin bbview scroller */
2866 wprintf("<form name=\"msgomatictop\" class=\"selector_top\" > \n <p>");
2867 wprintf(_("Reading #"));//// TODO this isn't used, should it? : , lowest_displayed, highest_displayed);
2869 wprintf("<select name=\"whichones\" size=\"1\" "
2870 "OnChange=\"location.href=msgomatictop.whichones.options"
2871 "[selectedIndex].value\">\n");
2874 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2876 lo = b - maxmsgs + 2;
2878 wprintf("<option %s value="
2883 "%d-%d</option> \n",
2884 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2893 for (b=0; b<nummsgs; b = b + maxmsgs) {
2895 hi = b + maxmsgs + 1;
2896 if (hi > nummsgs) hi = nummsgs;
2897 wprintf("<option %s value="
2902 "%d-%d</option> \n",
2903 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
2912 wprintf("<option value=\"%s?startmsg=%ld"
2913 "&maxmsgs=9999999&is_summary=%d\">",
2915 WCC->msgarr[0], is_summary);
2917 wprintf("</option>");
2918 wprintf("</select> ");
2919 wprintf(_("of %d messages."), nummsgs);
2921 /** forward/reverse */
2922 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2923 "OnChange=\"location.href='%s?sortby=forward'\"",
2924 (bbs_reverse ? "" : "checked"),
2928 wprintf(_("oldest to newest"));
2929 wprintf(" ");
2931 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2932 "OnChange=\"location.href='%s?sortby=reverse'\"",
2933 (bbs_reverse ? "checked" : ""),
2937 wprintf(_("newest to oldest"));
2940 wprintf("</p></form>\n");
2941 /** end bbview scroller */
2944 at = GetNewHashPos();
2945 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
2946 Msg = (message_summary*) vMsg;
2947 if ((Msg->msgnum >= startmsg) && (num_displayed < maxmsgs)) {
2949 /** Display the message */
2951 DoTemplate(HKEY("section_mailsummary"), NULL, Msg, CTX_MAILSUM);
2953 else if (is_addressbook) {
2954 fetch_ab_name(Msg, buf);
2956 addrbook = realloc(addrbook,
2957 (sizeof(struct addrbookent) * num_ab) );
2958 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2959 sizeof(addrbook[num_ab-1].ab_name));
2960 addrbook[num_ab-1].ab_msgnum = Msg->msgnum;
2962 else if (is_calendar) {
2963 load_calendar_item(Msg, Msg->is_new, &calv);
2965 else if (is_tasks) {
2966 display_task(Msg, Msg->is_new);
2968 else if (is_notes) {
2969 display_note(Msg, Msg->is_new);
2970 } else if (WCC->is_mobile) {
2971 DoTemplate(HKEY("section_mailsummary"), NULL, Msg, CTX_MAILSUM);
2974 if (displayed_msgs == NULL) {
2975 displayed_msgs = malloc(sizeof(long) *
2976 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2978 displayed_msgs[num_displayed] = Msg->msgnum;
2981 if (lowest_displayed < 0) lowest_displayed = a;
2982 highest_displayed = a;
2990 if (displayed_msgs != NULL) {
2992 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2995 /** if we do a split bbview in the future, begin messages div here */
2997 for (a=0; a<num_displayed; ++a) {
2998 read_message(displayed_msgs[a], 0, "");
3001 /** if we do a split bbview in the future, end messages div here */
3003 free(displayed_msgs);
3004 displayed_msgs = NULL;
3009 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
3010 wprintf("</div>"); /**< end of 'message_list' div */
3012 /** Here's the grab-it-to-resize-the-message-list widget */
3013 wprintf("<div id=\"resize_msglist\" "
3014 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
3015 "<div class=\"fix_scrollbar_bug\"> <hr>"
3019 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
3020 } else if (WCC->is_mobile) {
3025 * Bump these because although we're thinking in zero base, the user
3026 * is a drooling idiot and is thinking in one base.
3029 ++highest_displayed;
3032 * If we're not currently looking at ALL requested
3033 * messages, then display the selector bar
3036 /** begin bbview scroller */
3037 wprintf("<form name=\"msgomatic\" class=\"selector_bottom\" > \n <p>");
3038 wprintf(_("Reading #")); /// TODO: this isn't used: , lowest_displayed, highest_displayed);
3040 wprintf("<select name=\"whichones\" size=\"1\" "
3041 "OnChange=\"location.href=msgomatic.whichones.options"
3042 "[selectedIndex].value\">\n");
3045 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
3047 lo = b - maxmsgs + 2;
3049 wprintf("<option %s value="
3054 "%d-%d</option> \n",
3055 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
3064 for (b=0; b<nummsgs; b = b + maxmsgs) {
3066 hi = b + maxmsgs + 1;
3067 if (hi > nummsgs) hi = nummsgs;
3068 wprintf("<option %s value="
3073 "%d-%d</option> \n",
3074 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
3083 wprintf("<option value=\"%s&startmsg=%ld"
3084 "&maxmsgs=9999999&is_summary=%d\">",
3086 WCC->msgarr[0], is_summary);
3088 wprintf("</option>");
3089 wprintf("</select> ");
3090 wprintf(_("of %d messages."), nummsgs);
3092 /** forward/reverse */
3093 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
3094 "OnChange=\"location.href='%s&sortby=forward'\"",
3095 (bbs_reverse ? "" : "checked"),
3099 wprintf(_("oldest to newest"));
3100 wprintf(" ");
3101 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
3102 "OnChange=\"location.href='%s&sortby=reverse'\"",
3103 (bbs_reverse ? "checked" : ""),
3107 wprintf(_("newest to oldest"));
3110 wprintf("</p></form>\n");
3111 /** end bbview scroller */
3116 do_tasks_view(); /** Render the task list */
3120 render_calendar_view(&calv);
3123 if (is_addressbook) {
3124 do_addrbook_view(addrbook, num_ab); /** Render the address book */
3127 /** Note: wDumpContent() will output one additional </div> tag. */
3128 wprintf("</div>\n"); /** end of 'content' div */
3131 /** free the summary */
3132 if (WCC->summ != NULL) {
3133 DeleteHash(&WCC->summ);
3135 if (addrbook != NULL) free(addrbook);
3140 * Back end for post_message()
3141 * ... this is where the actual message gets transmitted to the server.
3143 void post_mime_to_server(void) {
3144 char top_boundary[SIZ];
3145 char alt_boundary[SIZ];
3146 int is_multipart = 0;
3148 struct wc_attachment *att;
3150 size_t encoded_length;
3151 size_t encoded_strlen;
3152 char *txtmail = NULL;
3154 sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
3155 serv_info.serv_fqdn,
3159 sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x",
3160 serv_info.serv_fqdn,
3165 /* RFC2045 requires this, and some clients look for it... */
3166 serv_puts("MIME-Version: 1.0");
3167 serv_puts("X-Mailer: " PACKAGE_STRING);
3169 /* If there are attachments, we have to do multipart/mixed */
3170 if (WC->first_attachment != NULL) {
3175 /* Remember, serv_printf() appends an extra newline */
3176 serv_printf("Content-type: multipart/mixed; boundary=\"%s\"\n", top_boundary);
3177 serv_printf("This is a multipart message in MIME format.\n");
3178 serv_printf("--%s", top_boundary);
3181 /* Remember, serv_printf() appends an extra newline */
3182 serv_printf("Content-type: multipart/alternative; "
3183 "boundary=\"%s\"\n", alt_boundary);
3184 serv_printf("This is a multipart message in MIME format.\n");
3185 serv_printf("--%s", alt_boundary);
3187 serv_puts("Content-type: text/plain; charset=utf-8");
3188 serv_puts("Content-Transfer-Encoding: quoted-printable");
3190 txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
3191 text_to_server_qp(txtmail); /* Transmit message in quoted-printable encoding */
3194 serv_printf("--%s", alt_boundary);
3196 serv_puts("Content-type: text/html; charset=utf-8");
3197 serv_puts("Content-Transfer-Encoding: quoted-printable");
3199 serv_puts("<html><body>\r\n");
3200 text_to_server_qp(bstr("msgtext")); /* Transmit message in quoted-printable encoding */
3201 serv_puts("</body></html>\r\n");
3203 serv_printf("--%s--", alt_boundary);
3207 /* Add in the attachments */
3208 for (att = WC->first_attachment; att!=NULL; att=att->next) {
3210 encoded_length = ((att->length * 150) / 100);
3211 encoded = malloc(encoded_length);
3212 if (encoded == NULL) break;
3213 encoded_strlen = CtdlEncodeBase64(encoded, att->data, att->length, 1);
3215 serv_printf("--%s", top_boundary);
3216 serv_printf("Content-type: %s", att->content_type);
3217 serv_printf("Content-disposition: attachment; filename=\"%s\"", att->filename);
3218 serv_puts("Content-transfer-encoding: base64");
3220 serv_write(encoded, encoded_strlen);
3225 serv_printf("--%s--", top_boundary);
3233 * Post message (or don't post message)
3235 * Note regarding the "dont_post" variable:
3236 * A random value (actually, it's just a timestamp) is inserted as a hidden
3237 * field called "postseq" when the display_enter page is generated. This
3238 * value is checked when posting, using the static variable dont_post. If a
3239 * user attempts to post twice using the same dont_post value, the message is
3240 * discarded. This prevents the accidental double-saving of the same message
3241 * if the user happens to click the browser "back" button.
3243 void post_message(void)
3246 StrBuf *encoded_subject = NULL;
3247 static long dont_post = (-1L);
3248 struct wc_attachment *att, *aptr;
3249 int is_anonymous = 0;
3250 const StrBuf *display_name = NULL;
3251 struct wcsession *WCC = WC;
3253 if (havebstr("force_room")) {
3254 gotoroom(bstr("force_room"));
3257 if (havebstr("display_name")) {
3258 display_name = sbstr("display_name");
3259 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
3260 display_name = NULL;
3265 if (WCC->upload_length > 0) {
3267 lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WCC->upload_length);
3268 /** There's an attachment. Save it to this struct... */
3269 att = malloc(sizeof(struct wc_attachment));
3270 memset(att, 0, sizeof(struct wc_attachment));
3271 att->length = WCC->upload_length;
3272 strcpy(att->content_type, WCC->upload_content_type);
3273 strcpy(att->filename, WCC->upload_filename);
3276 /** And add it to the list. */
3277 if (WCC->first_attachment == NULL) {
3278 WCC->first_attachment = att;
3281 aptr = WCC->first_attachment;
3282 while (aptr->next != NULL) aptr = aptr->next;
3287 * Mozilla sends a simple filename, which is what we want,
3288 * but Satan's Browser sends an entire pathname. Reduce
3289 * the path to just a filename if we need to.
3291 while (num_tokens(att->filename, '/') > 1) {
3292 remove_token(att->filename, 0, '/');
3294 while (num_tokens(att->filename, '\\') > 1) {
3295 remove_token(att->filename, 0, '\\');
3299 * Transfer control of this memory from the upload struct
3300 * to the attachment struct.
3302 att->data = WCC->upload;
3303 WCC->upload_length = 0;
3309 if (havebstr("cancel_button")) {
3310 sprintf(WCC->ImportantMessage,
3311 _("Cancelled. Message was not posted."));
3312 } else if (havebstr("attach_button")) {
3315 } else if (lbstr("postseq") == dont_post) {
3316 sprintf(WCC->ImportantMessage,
3317 _("Automatically cancelled because you have already "
3318 "saved this message."));
3320 const char CMD[] = "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s|%s";
3321 const StrBuf *Recp = NULL;
3322 const StrBuf *Cc = NULL;
3323 const StrBuf *Bcc = NULL;
3324 const StrBuf *Wikipage = NULL;
3325 const StrBuf *my_email_addr = NULL;
3326 StrBuf *CmdBuf = NULL;;
3327 StrBuf *references = NULL;
3329 if (havebstr("references"))
3331 const StrBuf *ref = sbstr("references");
3332 references = NewStrBufPlain(ChrPtr(ref), StrLength(ref));
3333 lprintf(9, "Converting: %s\n", ChrPtr(references));
3334 StrBufReplaceChars(references, '|', '!');
3335 lprintf(9, "Converted: %s\n", ChrPtr(references));
3337 if (havebstr("subject")) {
3340 * make enough room for the encoded string;
3341 * plus the QP header
3343 Subj = sbstr("subject");
3345 StrBufRFC2047encode(&encoded_subject, Subj);
3347 Recp = sbstr("recp");
3350 Wikipage = sbstr("wikipage");
3351 my_email_addr = sbstr("my_email_addr");
3353 CmdBuf = NewStrBufPlain(NULL,
3356 StrLength(encoded_subject) +
3359 StrLength(Wikipage) +
3360 StrLength(my_email_addr) +
3361 StrLength(references));
3363 StrBufPrintf(CmdBuf,
3367 ChrPtr(encoded_subject),
3368 ChrPtr(display_name),
3372 ChrPtr(my_email_addr),
3373 ChrPtr(references));
3374 FreeStrBuf(&references);
3376 lprintf(9, "%s\n", CmdBuf);
3377 serv_puts(ChrPtr(CmdBuf));
3378 serv_getln(buf, sizeof buf);
3379 FreeStrBuf(&CmdBuf);
3380 FreeStrBuf(&encoded_subject);
3381 if (buf[0] == '4') {
3382 post_mime_to_server();
3383 if ( (havebstr("recp"))
3384 || (havebstr("cc" ))
3385 || (havebstr("bcc" ))
3387 sprintf(WCC->ImportantMessage, _("Message has been sent.\n"));
3390 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
3392 dont_post = lbstr("postseq");
3394 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, buf);
3395 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3401 free_attachments(WCC);
3404 * We may have been supplied with instructions regarding the location
3405 * to which we must return after posting. If found, go there.
3407 if (havebstr("return_to")) {
3408 http_redirect(bstr("return_to"));
3411 * If we were editing a page in a wiki room, go to that page now.
3413 else if (havebstr("wikipage")) {
3414 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
3418 * Otherwise, just go to the "read messages" loop.
3421 readloop("readnew");
3429 * \brief display the message entry screen
3431 void display_enter(void)
3436 const StrBuf *display_name = NULL;
3437 struct wc_attachment *att;
3438 int recipient_required = 0;
3439 int subject_required = 0;
3440 int recipient_bad = 0;
3441 int is_anonymous = 0;
3442 long existing_page = (-1L);
3443 struct wcsession *WCC = WC;
3447 if (havebstr("force_room")) {
3448 gotoroom(bstr("force_room"));
3451 display_name = sbstr("display_name");
3452 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
3453 display_name = NULL;
3457 /** First test to see whether this is a room that requires recipients to be entered */
3458 serv_puts("ENT0 0");
3459 serv_getln(buf, sizeof buf);
3461 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
3462 recipient_required = 1;
3464 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
3465 sprintf(WCC->ImportantMessage, "%s", &buf[4]);
3466 readloop("readnew");
3470 /* Is the server strongly recommending that the user enter a message subject? */
3471 if ((buf[3] != '\0') && (buf[4] != '\0')) {
3472 subject_required = extract_int(&buf[4], 1);
3476 * Are we perhaps in an address book view? If so, then an "enter
3477 * message" command really means "add new entry."
3479 if (WCC->wc_default_view == VIEW_ADDRESSBOOK) {
3480 do_edit_vcard(-1, "", "", WCC->wc_roomname);
3485 * Are we perhaps in a calendar room? If so, then an "enter
3486 * message" command really means "add new calendar item."
3488 if (WCC->wc_default_view == VIEW_CALENDAR) {
3489 display_edit_event();
3494 * Are we perhaps in a tasks view? If so, then an "enter
3495 * message" command really means "add new task."
3497 if (WCC->wc_default_view == VIEW_TASKS) {
3498 display_edit_task();
3503 * Otherwise proceed normally.
3504 * Do a custom room banner with no navbar...
3506 output_headers(1, 1, 2, 0, 0, 0);
3507 wprintf("<div id=\"banner\">\n");
3508 embed_room_banner(NULL, navbar_none);
3509 wprintf("</div>\n");
3510 wprintf("<div id=\"content\">\n"
3511 "<div class=\"fix_scrollbar_bug message \">");
3513 /* Now check our actual recipients if there are any */
3514 if (recipient_required) {
3515 const StrBuf *Recp = NULL;
3516 const StrBuf *Cc = NULL;
3517 const StrBuf *Bcc = NULL;
3518 const StrBuf *Wikipage = NULL;
3519 StrBuf *CmdBuf = NULL;;
3520 const char CMD[] = "ENT0 0|%s|%d|0||%s||%s|%s|%s";
3522 Recp = sbstr("recp");
3525 Wikipage = sbstr("wikipage");
3527 CmdBuf = NewStrBufPlain(NULL,
3530 StrLength(display_name) +
3533 StrLength(Wikipage));
3535 StrBufPrintf(CmdBuf,
3539 ChrPtr(display_name),
3543 serv_puts(ChrPtr(CmdBuf));
3544 serv_getln(buf, sizeof buf);
3545 FreeStrBuf(&CmdBuf);
3547 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
3548 if (havebstr("recp") &&
3554 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
3555 wprintf("<em>%s</em><br />\n", &buf[4]);/// -> important message
3560 /** If we got this far, we can display the message entry screen. */
3562 /* begin message entry screen */
3564 "enctype=\"multipart/form-data\" "
3566 "accept-charset=\"UTF-8\" "
3568 "name=\"enterform\""
3570 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
3571 if (WCC->wc_view == VIEW_WIKI) {
3572 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
3574 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
3575 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WCC->nonce);
3576 wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
3577 escputs(WCC->wc_roomname);
3579 wprintf("<input type=\"hidden\" name=\"references\" value=\"");
3580 escputs(bstr("references"));
3583 /** submit or cancel buttons */
3584 wprintf("<p class=\"send_edit_msg\">");
3585 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
3586 if (recipient_required) {
3587 wprintf(_("Send message"));
3589 wprintf(_("Post message"));
3592 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3597 wprintf("<img src=\"static/newmess3_24x.gif\" class=\"imgedit\">");
3598 wprintf(" "); /** header bar */
3599 webcit_fmt_date(buf, now, 0);
3601 wprintf("\n"); /** header bar */
3603 wprintf("<table width=\"100%%\" class=\"edit_msg_table\">");
3605 wprintf("<th><label for=\"from_id\" > ");
3606 wprintf(_(" <I>from</I> "));
3607 wprintf("</label></th>");
3609 wprintf("<td colspan=\"2\">");
3611 /* Allow the user to select any of his valid screen names */
3613 wprintf("<select name=\"display_name\" size=1 id=\"from_id\">\n");
3616 serv_getln(buf, sizeof buf);
3617 if (buf[0] == '1') {
3618 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3619 wprintf("<option %s value=\"",
3620 ((!strcasecmp(bstr("display_name"), buf)) ? "selected" : "")
3625 wprintf("</option>\n");
3629 if (WCC->room_flags & QR_ANONOPT) {
3630 wprintf("<option %s value=\"__ANONYMOUS__\">%s</option>\n",
3631 ((!strcasecmp(bstr("__ANONYMOUS__"), WCC->wc_fullname)) ? "selected" : ""),
3636 wprintf("</select>\n");
3638 /* If this is an email (not a post), allow the user to select any of his
3639 * valid email addresses.
3641 if (recipient_required) {
3643 serv_getln(buf, sizeof buf);
3644 if (buf[0] == '1') {
3645 wprintf("<select name=\"my_email_addr\" size=1>\n");
3646 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3647 wprintf("<option value=\"");
3651 wprintf("></option>\n");
3653 wprintf("</select>\n");
3657 wprintf(_(" <I>in</I> "));
3658 escputs(WCC->wc_roomname);
3660 wprintf("</td></tr>");
3662 if (recipient_required) {
3666 wprintf("<tr><th><label for=\"recp_id\"> ");
3668 wprintf("</label></th>"
3669 "<td><input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
3670 ccraw = xbstr("recp", &len);
3671 copy = (char*) malloc(len * 2 + 1);
3672 memcpy(copy, ccraw, len + 1);
3673 utf8ify_rfc822_string(copy);
3676 wprintf("\" size=45 maxlength=1000 />");
3677 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
3678 wprintf("</td><td rowspan=\"3\" align=\"left\" valign=\"top\">");
3680 /** Pop open an address book -- begin **/
3682 "<a href=\"javascript:PopOpenAddressBook('recp_id|%s|cc_id|%s|bcc_id|%s');\" "
3684 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
3686 _("To:"), _("CC:"), _("BCC:"),
3687 _("Contacts"), _("Contacts")
3689 /** Pop open an address book -- end **/
3691 wprintf("</td></tr>");
3693 wprintf("<tr><th><label for=\"cc_id\"> ");
3695 wprintf("</label></th>"
3696 "<td><input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
3697 ccraw = xbstr("cc", &len);
3698 copy = (char*) malloc(len * 2 + 1);
3699 memcpy(copy, ccraw, len + 1);
3700 utf8ify_rfc822_string(copy);
3703 wprintf("\" size=45 maxlength=1000 />");
3704 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
3705 wprintf("</td></tr>");
3707 wprintf("<tr><th><label for=\"bcc_id\"> ");
3709 wprintf("</label></th>"
3710 "<td><input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
3711 ccraw = xbstr("bcc", &len);
3712 copy = (char*) malloc(len * 2 + 1);
3713 memcpy(copy, ccraw, len + 1);
3714 utf8ify_rfc822_string(copy);
3717 wprintf("\" size=45 maxlength=1000 />");
3718 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
3719 wprintf("</td></tr>");
3721 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
3722 wprintf("<script type=\"text/javascript\"> \n"
3723 " activate_entmsg_autocompleters(); \n"
3729 wprintf("<tr><th><label for=\"subject_id\" > ");
3730 if (recipient_required || subject_required) {
3731 wprintf(_("Subject:"));
3734 wprintf(_("Subject (optional):"));
3736 wprintf("</label></th>"
3737 "<td colspan=\"2\">"
3738 "<input type=\"text\" name=\"subject\" id=\"subject_id\" value=\"");
3739 escputs(bstr("subject"));
3740 wprintf("\" size=45 maxlength=70>\n");
3741 wprintf("</td></tr>");
3743 wprintf("<tr><td colspan=\"3\">\n");
3745 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
3747 /** If we're continuing from a previous edit, put our partially-composed message back... */
3748 msgescputs(bstr("msgtext"));
3750 /* If we're forwarding a message, insert it here... */
3751 if (lbstr("fwdquote") > 0L) {
3752 wprintf("<br><div align=center><i>");
3753 wprintf(_("--- forwarded message ---"));
3754 wprintf("</i></div><br>");
3755 pullquote_message(lbstr("fwdquote"), 1, 1);
3758 /** If we're replying quoted, insert the quote here... */
3759 else if (lbstr("replyquote") > 0L) {
3762 pullquote_message(lbstr("replyquote"), 0, 1);
3763 wprintf("</blockquote><br>");
3766 /** If we're editing a wiki page, insert the existing page here... */
3767 else if (WCC->wc_view == VIEW_WIKI) {
3768 safestrncpy(buf, bstr("wikipage"), sizeof buf);
3769 str_wiki_index(buf);
3770 existing_page = locate_message_by_uid(buf);
3771 if (existing_page >= 0L) {
3772 pullquote_message(existing_page, 1, 0);
3776 /** Insert our signature if appropriate... */
3777 if ( (WCC->is_mailbox) && !yesbstr("sig_inserted") ) {
3779 get_pref_yesno("use_sig", &UseSig, 0);
3782 const char *sig, *esig;
3784 get_preference("signature", &ebuf);
3786 StrBufEUid_unescapize(Sig, ebuf);
3788 esig = sig + StrLength(Sig);
3789 wprintf("<br>--<br>");
3790 while (sig <= esig) {
3794 else if (*sig == '<') {
3797 else if (*sig == '>') {
3800 else if (*sig == '&') {
3803 else if (*sig == '\"') {
3806 else if (*sig == '\'') {
3809 else /* since we're utf 8, is this a good idea? if (isprint(*sig))*/ {
3810 wprintf("%c", *sig);
3818 wprintf("</textarea>\n");
3820 /** Make sure we only insert our signature once */
3821 /** We don't care if it was there or not before, it needs to be there now. */
3822 wprintf("<input type=\"hidden\" name=\"sig_inserted\" value=\"yes\">\n");
3825 * The following template embeds the TinyMCE richedit control, and automatically
3826 * transforms the textarea into a richedit textarea.
3828 do_template("richedit", NULL);
3830 /** Enumerate any attachments which are already in place... */
3831 wprintf("<div class=\"attachment buttons\"><img src=\"static/diskette_24x.gif\" class=\"imgedit\" > ");
3832 wprintf(_("Attachments:"));
3834 wprintf("<select name=\"which_attachment\" size=1>");
3835 for (att = WCC->first_attachment; att != NULL; att = att->next) {
3836 wprintf("<option value=\"");
3837 urlescputs(att->filename);
3839 escputs(att->filename);
3840 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
3841 wprintf("</option>\n");
3843 wprintf("</select>");
3845 /** Now offer the ability to attach additional files... */
3846 wprintf(" ");
3847 wprintf(_("Attach file:"));
3848 wprintf(" <input name=\"attachfile\" class=\"attachfile\" "
3849 "size=16 type=\"file\">\n "
3850 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
3851 wprintf("</div>"); /* End of "attachment buttons" div */
3854 wprintf("</td></tr></table>");
3856 wprintf("</form>\n");
3857 wprintf("</div>\n"); /* end of "fix_scrollbar_bug" div */
3859 /* NOTE: address_book_popup() will close the "content" div. Don't close it here. */
3860 DONE: address_book_popup();
3866 * \brief delete a message
3868 void delete_msg(void)
3873 msgid = lbstr("msgid");
3875 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
3876 serv_printf("DELE %ld", msgid);
3878 else { /** Otherwise move it to Trash */
3879 serv_printf("MOVE %ld|_TRASH_|0", msgid);
3882 serv_getln(buf, sizeof buf);
3883 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3885 readloop("readnew");
3890 * \brief move a message to another folder
3897 msgid = lbstr("msgid");
3899 if (havebstr("move_button")) {
3900 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
3902 serv_getln(buf, sizeof buf);
3903 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3905 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
3908 readloop("readnew");
3916 * Confirm move of a message
3918 void confirm_move_msg(void)
3924 msgid = lbstr("msgid");
3927 output_headers(1, 1, 2, 0, 0, 0);
3928 wprintf("<div id=\"banner\">\n");
3930 wprintf(_("Confirm move of message"));
3932 wprintf("</div>\n");
3934 wprintf("<div id=\"content\" class=\"service\">\n");
3936 wprintf("<CENTER>");
3938 wprintf(_("Move this message to:"));
3939 wprintf("<br />\n");
3941 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
3942 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
3943 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
3945 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
3947 serv_getln(buf, sizeof buf);
3948 if (buf[0] == '1') {
3949 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3950 extract_token(targ, buf, 0, '|', sizeof targ);
3951 wprintf("<OPTION>");
3956 wprintf("</SELECT>\n");
3957 wprintf("<br />\n");
3959 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
3961 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
3962 wprintf("</form></CENTER>\n");
3964 wprintf("</CENTER>\n");
3968 void readnew(void) { readloop("readnew");}
3969 void readold(void) { readloop("readold");}
3970 void readfwd(void) { readloop("readfwd");}
3971 void headers(void) { readloop("headers");}
3972 void do_search(void) { readloop("do_search");}
3983 WebcitAddUrlHandler(HKEY("readnew"), readnew, 0);
3984 WebcitAddUrlHandler(HKEY("readold"), readold, 0);
3985 WebcitAddUrlHandler(HKEY("readfwd"), readfwd, 0);
3986 WebcitAddUrlHandler(HKEY("headers"), headers, 0);
3987 WebcitAddUrlHandler(HKEY("do_search"), do_search, 0);
3988 WebcitAddUrlHandler(HKEY("display_enter"), display_enter, 0);
3989 WebcitAddUrlHandler(HKEY("post"), post_message, 0);
3990 WebcitAddUrlHandler(HKEY("move_msg"), move_msg, 0);
3991 WebcitAddUrlHandler(HKEY("delete_msg"), delete_msg, 0);
3992 WebcitAddUrlHandler(HKEY("confirm_move_msg"), confirm_move_msg, 0);
3993 WebcitAddUrlHandler(HKEY("msg"), embed_message, NEED_URL|AJAX);
3994 WebcitAddUrlHandler(HKEY("printmsg"), print_message, NEED_URL);
3995 WebcitAddUrlHandler(HKEY("mobilemsg"), mobile_message_view, NEED_URL);
3996 WebcitAddUrlHandler(HKEY("msgheaders"), display_headers, NEED_URL);
3998 RegisterNamespace("MAIL:SUMM:DATESTR", 0, 0, tmplput_MAIL_SUMM_DATE_STR, CTX_MAILSUM);
3999 RegisterNamespace("MAIL:SUMM:DATENO", 0, 0, tmplput_MAIL_SUMM_DATE_NO, CTX_MAILSUM);
4000 RegisterNamespace("MAIL:SUMM:N", 0, 0, tmplput_MAIL_SUMM_N, CTX_MAILSUM);
4001 RegisterNamespace("MAIL:SUMM:FROM", 0, 2, tmplput_MAIL_SUMM_FROM, CTX_MAILSUM);
4002 RegisterNamespace("MAIL:SUMM:TO", 0, 2, tmplput_MAIL_SUMM_TO, CTX_MAILSUM);
4003 RegisterNamespace("MAIL:SUMM:SUBJECT", 0, 4, tmplput_MAIL_SUMM_SUBJECT, CTX_MAILSUM);
4004 RegisterNamespace("MAIL:SUMM:NTATACH", 0, 0, tmplput_MAIL_SUMM_NATTACH, CTX_MAILSUM);
4005 RegisterNamespace("MAIL:SUMM:CCCC", 0, 2, tmplput_MAIL_SUMM_CCCC, CTX_MAILSUM);
4006 RegisterNamespace("MAIL:SUMM:H_NODE", 0, 2, tmplput_MAIL_SUMM_H_NODE, CTX_MAILSUM);
4007 RegisterNamespace("MAIL:SUMM:ALLRCPT", 0, 2, tmplput_MAIL_SUMM_ALLRCPT, CTX_MAILSUM);
4008 RegisterNamespace("MAIL:SUMM:ORGROOM", 0, 2, tmplput_MAIL_SUMM_ORGROOM, CTX_MAILSUM);
4009 RegisterNamespace("MAIL:SUMM:RFCA", 0, 2, tmplput_MAIL_SUMM_RFCA, CTX_MAILSUM);
4010 RegisterNamespace("MAIL:SUMM:OTHERNODE", 2, 0, tmplput_MAIL_SUMM_OTHERNODE, CTX_MAILSUM);
4011 RegisterNamespace("MAIL:SUMM:REFIDS", 0, 0, tmplput_MAIL_SUMM_REFIDS, CTX_MAILSUM);
4012 RegisterNamespace("MAIL:SUMM:INREPLYTO", 0, 2, tmplput_MAIL_SUMM_INREPLYTO, CTX_MAILSUM);
4013 RegisterNamespace("MAIL:BODY", 0, 2, tmplput_MAIL_BODY, CTX_MAILSUM);
4016 RegisterConditional(HKEY("COND:MAIL:SUMM:UNREAD"), 0, Conditional_MAIL_SUMM_UNREAD, CTX_MAILSUM);
4017 RegisterConditional(HKEY("COND:MAIL:SUMM:H_NODE"), 0, Conditional_MAIL_SUMM_H_NODE, CTX_MAILSUM);
4018 RegisterConditional(HKEY("COND:MAIL:SUMM:OTHERNODE"), 0, Conditional_MAIL_SUMM_OTHERNODE, CTX_MAILSUM);
4019 RegisterConditional(HKEY("COND:MAIL:ANON"), 0, Conditional_ANONYMOUS_MESSAGE, CTX_MAILSUM);
4021 RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH"), 0, Conditional_MAIL_MIME_ALL, CTX_MAILSUM);
4022 RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:SUBMESSAGES"), 0, Conditional_MAIL_MIME_SUBMESSAGES, CTX_MAILSUM);
4023 RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:LINKS"), 0, Conditional_MAIL_MIME_ATTACHLINKS, CTX_MAILSUM);
4024 RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:ATT"), 0, Conditional_MAIL_MIME_ATTACH, CTX_MAILSUM);
4026 RegisterIterator("MAIL:MIME:ATTACH", 0, NULL, iterate_get_mime_All,
4027 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM);
4028 RegisterIterator("MAIL:MIME:ATTACH:SUBMESSAGES", 0, NULL, iterate_get_mime_Submessages,
4029 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM);
4030 RegisterIterator("MAIL:MIME:ATTACH:LINKS", 0, NULL, iterate_get_mime_AttachLinks,
4031 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM);
4032 RegisterIterator("MAIL:MIME:ATTACH:ATT", 0, NULL, iterate_get_mime_Attachments,
4033 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM);
4035 RegisterNamespace("MAIL:MIME:NAME", 0, 2, tmplput_MIME_Name, CTX_MIME_ATACH);
4036 RegisterNamespace("MAIL:MIME:FILENAME", 0, 2, tmplput_MIME_FileName, CTX_MIME_ATACH);
4037 RegisterNamespace("MAIL:MIME:PARTNUM", 0, 2, tmplput_MIME_PartNum, CTX_MIME_ATACH);
4038 RegisterNamespace("MAIL:MIME:MSGNUM", 0, 2, tmplput_MIME_MsgNum, CTX_MIME_ATACH);
4039 RegisterNamespace("MAIL:MIME:DISPOSITION", 0, 2, tmplput_MIME_Disposition, CTX_MIME_ATACH);
4040 RegisterNamespace("MAIL:MIME:CONTENTTYPE", 0, 2, tmplput_MIME_ContentType, CTX_MIME_ATACH);
4041 RegisterNamespace("MAIL:MIME:CHARSET", 0, 2, tmplput_MIME_Charset, CTX_MIME_ATACH);
4042 RegisterNamespace("MAIL:MIME:LENGTH", 0, 2, tmplput_MIME_Length, CTX_MIME_ATACH);
4043 RegisterNamespace("MAIL:MIME:DATA", 0, 2, tmplput_MIME_Data, CTX_MIME_ATACH);
4047 RegisterMimeRenderer(HKEY("message/rfc822"), render_MAIL);
4048 RegisterMimeRenderer(HKEY("text/x-vcard"), render_MIME_VCard);
4049 RegisterMimeRenderer(HKEY("text/vcard"), render_MIME_VCard);
4050 RegisterMimeRenderer(HKEY("text/calendar"), render_MIME_ICS);
4051 RegisterMimeRenderer(HKEY("application/ics"), render_MIME_ICS);
4053 RegisterMimeRenderer(HKEY("text/x-citadel-variformat"), render_MAIL_variformat);
4054 RegisterMimeRenderer(HKEY("text/plain"), render_MAIL_text_plain);
4055 RegisterMimeRenderer(HKEY("text"), render_MAIL_text_plain);
4056 RegisterMimeRenderer(HKEY("text/html"), render_MAIL_html);
4057 RegisterMimeRenderer(HKEY(""), render_MAIL_UNKNOWN);
4059 RegisterMsgHdr(HKEY("nhdr"), examine_nhdr, 0);
4060 RegisterMsgHdr(HKEY("type"), examine_type, 0);
4061 RegisterMsgHdr(HKEY("from"), examine_from, 0);
4062 RegisterMsgHdr(HKEY("subj"), examine_subj, 0);
4063 RegisterMsgHdr(HKEY("msgn"), examine_msgn, 0);
4064 RegisterMsgHdr(HKEY("wefw"), examine_wefw, 0);
4065 RegisterMsgHdr(HKEY("cccc"), examine_cccc, 0);
4066 RegisterMsgHdr(HKEY("hnod"), examine_hnod, 0);
4067 RegisterMsgHdr(HKEY("room"), examine_room, 0);
4068 RegisterMsgHdr(HKEY("rfca"), examine_rfca, 0);
4069 RegisterMsgHdr(HKEY("node"), examine_node, 0);
4070 RegisterMsgHdr(HKEY("rcpt"), examine_rcpt, 0);
4071 RegisterMsgHdr(HKEY("time"), examine_time, 0);
4072 RegisterMsgHdr(HKEY("part"), examine_mime_part, 0);
4073 RegisterMsgHdr(HKEY("text"), examine_text, 1);
4074 RegisterMsgHdr(HKEY("X-Citadel-MSG4-Partnum"), examine_msg4_partnum, 0);
4075 RegisterMsgHdr(HKEY("Content-type"), examine_content_type, 0);
4076 RegisterMsgHdr(HKEY("Content-length"), examine_content_lengh, 0);
4077 RegisterMsgHdr(HKEY("Content-transfer-encoding"), examine_content_encoding, 0);