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_enter(void);
21 int longcmp_r(const void *s1, const void *s2);
22 int summcmp_subj(const void *s1, const void *s2);
23 int summcmp_rsubj(const void *s1, const void *s2);
24 int summcmp_sender(const void *s1, const void *s2);
25 int summcmp_rsender(const void *s1, const void *s2);
26 int summcmp_date(const void *s1, const void *s2);
27 int summcmp_rdate(const void *s1, const void *s2);
29 /*----------------------------------------------------------------------------*/
32 typedef void (*MsgPartEvaluatorFunc)(message_summary *Sum, StrBuf *Buf);
42 typedef struct _headereval {
43 ExamineMsgHeaderFunc evaluator;
55 const char* SortIcons[3] = {
56 "static/up_pointer.gif",
57 "static/down_pointer.gif",
58 "static/sort_none.gif"
72 /* SortEnum to plain string representation */
73 static const char* SortByStrings[] = {
84 /* SortEnum to sort-Function Table */
85 const CompareFunc SortFuncs[eUnSet] = {
95 /* given a SortEnum, which icon should we choose? */
96 const int SortDateToIcon[eUnSet] = { eUp, eDown, eNone, eNone, eNone, eNone, eNone};
97 const int SortSubjectToIcon[eUnSet] = { eNone, eNone, eUp, eDown, eNone, eNone, eNone};
98 const int SortSenderToIcon[eUnSet] = { eNone, eNone, eNone, eNone, eUp, eDown, eNone};
100 /* given a SortEnum, which would be the "opposite" search option? */
101 const int DateInvertSortString[eUnSet] = { eRDate, eDate, eDate, eDate, eDate, eDate, eDate};
102 const int SubjectInvertSortString[eUnSet] = { eSubject, eSubject, eRSubject, eUnSet, eSubject, eSubject, eSubject};
103 const int SenderInvertSortString[eUnSet] = { eSender, eSender, eSender, eSender, eRSender, eUnSet, eSender};
109 * Address book entry (keep it short and sweet, it's just a quickie lookup
110 * which we can use to get to the real meat and bones later)
113 char ab_name[64]; /**< name string */
114 long ab_msgnum; /**< message number of address book entry */
117 /*----------------------------------------------------------------------------*/
120 * Translates sortoption String to its SortEnum representation
121 * returns the enum matching the string; defaults to RDate
124 int StrToESort (const StrBuf *sortby)
128 if (!IsEmptyStr(ChrPtr(sortby))) while (result < eUnSet){
129 if (!strcasecmp(ChrPtr(sortby),
130 SortByStrings[result]))
138 typedef int (*QSortFunction) (const void*, const void*);
141 * qsort() compatible function to compare two longs in descending order.
143 int longcmp_r(const void *s1, const void *s2) {
147 l1 = *(long *)GetSearchPayload(s1);
148 l2 = *(long *)GetSearchPayload(s2);
150 if (l1 > l2) return(-1);
151 if (l1 < l2) return(+1);
157 * qsort() compatible function to compare two message summary structs by ascending subject.
159 int summcmp_subj(const void *s1, const void *s2) {
160 message_summary *summ1;
161 message_summary *summ2;
163 summ1 = (message_summary *)GetSearchPayload(s1);
164 summ2 = (message_summary *)GetSearchPayload(s2);
165 return strcasecmp(ChrPtr(summ1->subj), ChrPtr(summ2->subj));
169 * qsort() compatible function to compare two message summary structs by descending subject.
171 int summcmp_rsubj(const void *s1, const void *s2) {
172 message_summary *summ1;
173 message_summary *summ2;
175 summ1 = (message_summary *)GetSearchPayload(s1);
176 summ2 = (message_summary *)GetSearchPayload(s2);
177 return strcasecmp(ChrPtr(summ2->subj), ChrPtr(summ1->subj));
181 * qsort() compatible function to compare two message summary structs by ascending sender.
183 int summcmp_sender(const void *s1, const void *s2) {
184 message_summary *summ1;
185 message_summary *summ2;
187 summ1 = (message_summary *)GetSearchPayload(s1);
188 summ2 = (message_summary *)GetSearchPayload(s2);
189 return strcasecmp(ChrPtr(summ1->from), ChrPtr(summ2->from));
193 * qsort() compatible function to compare two message summary structs by descending sender.
195 int summcmp_rsender(const void *s1, const void *s2) {
196 message_summary *summ1;
197 message_summary *summ2;
199 summ1 = (message_summary *)GetSearchPayload(s1);
200 summ2 = (message_summary *)GetSearchPayload(s2);
201 return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from));
205 * qsort() compatible function to compare two message summary structs by ascending date.
207 int summcmp_date(const void *s1, const void *s2) {
208 message_summary *summ1;
209 message_summary *summ2;
211 summ1 = (message_summary *)GetSearchPayload(s1);
212 summ2 = (message_summary *)GetSearchPayload(s2);
214 if (summ1->date < summ2->date) return -1;
215 else if (summ1->date > summ2->date) return +1;
220 * qsort() compatible function to compare two message summary structs by descending date.
222 int summcmp_rdate(const void *s1, const void *s2) {
223 message_summary *summ1;
224 message_summary *summ2;
226 summ1 = (message_summary *)GetSearchPayload(s1);
227 summ2 = (message_summary *)GetSearchPayload(s2);
229 if (summ1->date < summ2->date) return +1;
230 else if (summ1->date > summ2->date) return -1;
238 /*----------------------------------------------------------------------------*/
241 * message index functions
244 void DestroyMimeParts(wc_mime_attachment *Mime)
246 FreeStrBuf(&Mime->Name);
247 FreeStrBuf(&Mime->FileName);
248 FreeStrBuf(&Mime->PartNum);
249 FreeStrBuf(&Mime->Disposition);
250 FreeStrBuf(&Mime->ContentType);
251 FreeStrBuf(&Mime->Charset);
252 FreeStrBuf(&Mime->Data);
255 void DestroyMime(void *vMime)
257 wc_mime_attachment *Mime = (wc_mime_attachment*)vMime;
258 DestroyMimeParts(Mime);
262 void DestroyMessageSummary(void *vMsg)
264 message_summary *Msg = (message_summary*) vMsg;
266 FreeStrBuf(&Msg->from);
267 FreeStrBuf(&Msg->to);
268 FreeStrBuf(&Msg->subj);
269 FreeStrBuf(&Msg->reply_inreplyto);
270 FreeStrBuf(&Msg->reply_references);
271 FreeStrBuf(&Msg->cccc);
272 FreeStrBuf(&Msg->hnod);
273 FreeStrBuf(&Msg->AllRcpt);
274 FreeStrBuf(&Msg->Room);
275 FreeStrBuf(&Msg->Rfca);
276 FreeStrBuf(&Msg->OtherNode);
278 FreeStrBuf(&Msg->reply_to);
280 DeleteHash(&Msg->Attachments); /**< list of Accachments */
281 DeleteHash(&Msg->Submessages);
282 DeleteHash(&Msg->AttachLinks);
283 DeleteHash(&Msg->AllAttach);
285 DestroyMimeParts(&Msg->MsgBody);
292 void RegisterMsgHdr(const char *HeaderName, long HdrNLen, ExamineMsgHeaderFunc evaluator, int type)
295 ev = (headereval*) malloc(sizeof(headereval));
296 ev->evaluator = evaluator;
298 Put(MsgHeaderHandler, HeaderName, HdrNLen, ev, NULL);
301 void RegisterMimeRenderer(const char *HeaderName, long HdrNLen, RenderMimeFunc MimeRenderer)
303 Put(MimeRenderHandler, HeaderName, HdrNLen, MimeRenderer, reference_free_handler);
307 /*----------------------------------------------------------------------------*/
310 void examine_nhdr(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
313 if (!strncasecmp(ChrPtr(HdrLine), "yes", 8))
317 void examine_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
319 Msg->format_type = StrToi(HdrLine);
323 void examine_from(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
325 FreeStrBuf(&Msg->from);
326 Msg->from = NewStrBufPlain(NULL, StrLength(HdrLine));
327 StrBuf_RFC822_to_Utf8(Msg->from, HdrLine, WC->DefaultCharset, FoundCharset);
329 void tmplput_MAIL_SUMM_FROM(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
331 message_summary *Msg = (message_summary*) Context;
332 StrBufAppendBuf(Target, Msg->from, 0);
333 lprintf(1,"%s", ChrPtr(Msg->from));
338 void examine_subj(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
340 FreeStrBuf(&Msg->subj);
341 Msg->subj = NewStrBufPlain(NULL, StrLength(HdrLine));
342 StrBuf_RFC822_to_Utf8(Msg->subj, HdrLine, WC->DefaultCharset, FoundCharset);
343 lprintf(1,"%s", ChrPtr(Msg->subj));
345 void tmplput_MAIL_SUMM_SUBJECT(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
346 {/////TODO: Fwd: and RE: filter!!
347 message_summary *Msg = (message_summary*) Context;
348 StrBufAppendBuf(Target, Msg->subj, 0);
352 void examine_msgn(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
354 FreeStrBuf(&Msg->reply_inreplyto);
355 Msg->reply_inreplyto = NewStrBufPlain(NULL, StrLength(HdrLine));
356 StrBuf_RFC822_to_Utf8(Msg->reply_inreplyto, HdrLine, WC->DefaultCharset, FoundCharset);
358 void tmplput_MAIL_SUMM_INREPLYTO(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
360 message_summary *Msg = (message_summary*) Context;
361 StrBufAppendBuf(Target, Msg->reply_inreplyto, 0);
364 int Conditional_MAIL_SUMM_UNREAD(WCTemplateToken *Tokens, void *Context, int ContextType)
366 message_summary *Msg = (message_summary*) Context;
367 return Msg->is_new != 0;
370 void examine_wefw(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
372 FreeStrBuf(&Msg->reply_references);
373 Msg->reply_references = NewStrBufPlain(NULL, StrLength(HdrLine));
374 StrBuf_RFC822_to_Utf8(Msg->reply_references, HdrLine, WC->DefaultCharset, FoundCharset);
376 void tmplput_MAIL_SUMM_REFIDS(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
378 message_summary *Msg = (message_summary*) Context;
379 StrBufAppendBuf(Target, Msg->reply_references, 0);
383 void examine_cccc(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
385 FreeStrBuf(&Msg->cccc);
386 Msg->cccc = NewStrBufPlain(NULL, StrLength(HdrLine));
387 StrBuf_RFC822_to_Utf8(Msg->cccc, HdrLine, WC->DefaultCharset, FoundCharset);
388 if (Msg->AllRcpt == NULL)
389 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
390 if (StrLength(Msg->AllRcpt) > 0) {
391 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
393 StrBufAppendBuf(Msg->AllRcpt, Msg->cccc, 0);
395 void tmplput_MAIL_SUMM_CCCC(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
397 message_summary *Msg = (message_summary*) Context;
398 StrBufAppendBuf(Target, Msg->cccc, 0);
404 void examine_room(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
406 if ((StrLength(HdrLine) > 0) &&
407 (strcasecmp(ChrPtr(HdrLine), WC->wc_roomname))) {
408 FreeStrBuf(&Msg->Room);
409 Msg->Room = NewStrBufDup(HdrLine);
412 void tmplput_MAIL_SUMM_ORGROOM(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
414 message_summary *Msg = (message_summary*) Context;
415 StrBufAppendBuf(Target, Msg->Room, 0);
419 void examine_rfca(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
421 FreeStrBuf(&Msg->Rfca);
422 Msg->Rfca = NewStrBufDup(HdrLine);
424 void tmplput_MAIL_SUMM_RFCA(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
426 message_summary *Msg = (message_summary*) Context;
427 StrBufAppendBuf(Target, Msg->Rfca, 0);
431 void examine_node(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
433 if ( (StrLength(HdrLine) > 0) &&
434 ((WC->room_flags & QR_NETWORK)
435 || ((strcasecmp(ChrPtr(HdrLine), serv_info.serv_nodename)
436 && (strcasecmp(ChrPtr(HdrLine), serv_info.serv_fqdn)))))) {
437 FreeStrBuf(&Msg->OtherNode);
438 Msg->OtherNode = NewStrBufDup(HdrLine);
441 void tmplput_MAIL_SUMM_OTHERNODE(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
443 message_summary *Msg = (message_summary*) Context;
444 StrBufAppendBuf(Target, Msg->OtherNode, 0);
446 int Conditional_MAIL_SUMM_OTHERNODE(WCTemplateToken *Tokens, void *Context, int ContextType)
448 message_summary *Msg = (message_summary*) Context;
449 return StrLength(Msg->OtherNode) > 0;
453 void examine_rcpt(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
455 FreeStrBuf(&Msg->to);
456 Msg->to = NewStrBufPlain(NULL, StrLength(HdrLine));
457 StrBuf_RFC822_to_Utf8(Msg->to, HdrLine, WC->DefaultCharset, FoundCharset);
458 if (Msg->AllRcpt == NULL)
459 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
460 if (StrLength(Msg->AllRcpt) > 0) {
461 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
463 StrBufAppendBuf(Msg->AllRcpt, Msg->to, 0);
465 void tmplput_MAIL_SUMM_TO(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
467 message_summary *Msg = (message_summary*) Context;
468 StrBufAppendBuf(Target, Msg->to, 0);
470 void tmplput_MAIL_SUMM_ALLRCPT(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
472 message_summary *Msg = (message_summary*) Context;
473 StrBufAppendBuf(Target, Msg->AllRcpt, 0);
478 void examine_time(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
480 Msg->date = StrTol(HdrLine);
482 void tmplput_MAIL_SUMM_DATE_STR(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
485 message_summary *Msg = (message_summary*) Context;
486 webcit_fmt_date(datebuf, Msg->date, 1);
487 StrBufAppendBufPlain(Target, datebuf, -1, 0);
489 void tmplput_MAIL_SUMM_DATE_NO(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
491 message_summary *Msg = (message_summary*) Context;
492 StrBufAppendPrintf(Target, "%ld", Msg->date, 0);
497 void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
499 wc_mime_attachment *mime;
502 mime = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
503 memset(mime, 0, sizeof(wc_mime_attachment));
506 mime->Name = NewStrBuf();
507 StrBufExtract_token(mime->Name, HdrLine, 0, '|');
509 StrBufExtract_token(Buf, HdrLine, 1, '|');
510 mime->FileName = NewStrBuf();
511 StrBuf_RFC822_to_Utf8(mime->FileName, Buf, WC->DefaultCharset, FoundCharset);
513 mime->PartNum = NewStrBuf();
514 StrBufExtract_token(mime->PartNum, HdrLine, 2, '|');
516 mime->Disposition = NewStrBuf();
517 StrBufExtract_token(mime->Disposition, HdrLine, 3, '|');
519 mime->ContentType = NewStrBuf();
520 StrBufExtract_token(mime->ContentType, HdrLine, 4, '|');
522 mime->length = StrBufExtract_int(HdrLine, 5, '|');
524 StrBufTrim(mime->Name);
525 StrBufTrim(mime->FileName);
527 if ( (StrLength(mime->FileName) == 0) && (StrLength(mime->Name) > 0) ) {
528 StrBufAppendBuf(mime->FileName, mime->Name, 0);
531 if (Msg->AllAttach == NULL)
532 Msg->AllAttach = NewHash(1,NULL);
533 Put(Msg->AllAttach, SKEY(mime->PartNum), mime, DestroyMime);
535 if (!strcasecmp(ChrPtr(mime->ContentType), "message/rfc822")) {
536 if (Msg->Submessages == NULL)
537 Msg->Submessages = NewHash(1,NULL);
538 Put(Msg->Submessages, SKEY(mime->PartNum), mime, reference_free_handler);
540 else if ((!strcasecmp(ChrPtr(mime->Disposition), "inline"))
541 && (!strncasecmp(ChrPtr(mime->ContentType), "image/", 6)) ){
542 if (Msg->AttachLinks == NULL)
543 Msg->AttachLinks = NewHash(1,NULL);
544 Put(Msg->AttachLinks, SKEY(mime->PartNum), mime, reference_free_handler);
546 else if ((StrLength(mime->ContentType) > 0) &&
547 ( (!strcasecmp(ChrPtr(mime->Disposition), "attachment"))
548 || (!strcasecmp(ChrPtr(mime->Disposition), "inline"))
549 || (!strcasecmp(ChrPtr(mime->Disposition), ""))))
552 if (Msg->AttachLinks == NULL)
553 Msg->AttachLinks = NewHash(1,NULL);
554 Put(Msg->AttachLinks, SKEY(mime->PartNum), mime, reference_free_handler);
555 if (strcasecmp(ChrPtr(mime->ContentType), "application/octet-stream") == 0) {
556 FlushStrBuf(mime->ContentType);
557 StrBufAppendBufPlain(mime->ContentType,
558 GuessMimeByFilename(SKEY(mime->FileName)),
563 /** begin handler prep ** */
564 if ( (!strcasecmp(ChrPtr(mime->ContentType), "text/x-vcard"))
565 || (!strcasecmp(ChrPtr(mime->ContentType), "text/vcard")) ) {
566 Msg->vcard_partnum_ref = mime;
568 else if ( (!strcasecmp(ChrPtr(mime->ContentType), "text/calendar"))
569 || (!strcasecmp(ChrPtr(mime->ContentType), "application/ics")) ) {
570 Msg->cal_partnum_ref = mime;
572 /** end handler prep ***/
577 void tmplput_MAIL_SUMM_NATTACH(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
579 message_summary *Msg = (message_summary*) Context;
580 StrBufAppendPrintf(Target, "%ld", GetCount(Msg->Attachments));
589 void examine_hnod(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
591 FreeStrBuf(&Msg->hnod);
592 Msg->hnod = NewStrBufPlain(NULL, StrLength(HdrLine));
593 StrBuf_RFC822_to_Utf8(Msg->hnod, HdrLine, WC->DefaultCharset, FoundCharset);
595 void tmplput_MAIL_SUMM_H_NODE(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
597 message_summary *Msg = (message_summary*) Context;
598 StrBufAppendBuf(Target, Msg->hnod, 0);
600 int Conditional_MAIL_SUMM_H_NODE(WCTemplateToken *Tokens, void *Context, int ContextType)
602 message_summary *Msg = (message_summary*) Context;
603 return StrLength(Msg->hnod) > 0;
608 void examine_text(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
609 {////TODO: read messages here
610 Msg->MsgBody.Data = NewStrBuf();
613 void examine_msg4_partnum(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
615 Msg->MsgBody.PartNum = NewStrBufDup(HdrLine);
616 StrBufTrim(Msg->MsgBody.PartNum);/////TODO: striplt == trim?
619 void examine_content_encoding(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
621 ////TODO: do we care?
624 void examine_content_lengh(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
626 Msg->MsgBody.length = StrTol(HdrLine);
627 Msg->MsgBody.size_known = 1;
630 void examine_content_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
633 Msg->MsgBody.ContentType = NewStrBufDup(HdrLine);
634 StrBufTrim(Msg->MsgBody.ContentType);/////todo==striplt?
635 len = StrLength(Msg->MsgBody.ContentType);
636 for (i=0; i<len; ++i) {
637 if (!strncasecmp(ChrPtr(Msg->MsgBody.ContentType) + i, "charset=", 8)) {/// TODO: WHUT?
638 // safestrncpy(mime_charset, &mime_content_type[i+8],
639 /// sizeof mime_charset);
642 for (i=0; i<len; ++i) {
643 if (mime_content_type[i] == ';') {
644 mime_content_type[i] = 0;
648 len = strlen(mime_charset);
649 for (i=0; i<len; ++i) {
650 if (mime_charset[i] == ';') {
658 void tmplput_MAIL_SUMM_N(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
660 message_summary *Msg = (message_summary*) Context;
661 StrBufAppendPrintf(Target, "%ld", Msg->msgnum);
666 int Conditional_MAIL_MIME_ALL(WCTemplateToken *Tokens, void *Context, int ContextType)
668 message_summary *Msg = (message_summary*) Context;
669 return GetCount(Msg->Attachments) > 0;
672 int Conditional_MAIL_MIME_SUBMESSAGES(WCTemplateToken *Tokens, void *Context, int ContextType)
674 message_summary *Msg = (message_summary*) Context;
675 return GetCount(Msg->Submessages) > 0;
678 int Conditional_MAIL_MIME_ATTACHLINKS(WCTemplateToken *Tokens, void *Context, int ContextType)
680 message_summary *Msg = (message_summary*) Context;
681 return GetCount(Msg->AttachLinks) > 0;
684 int Conditional_MAIL_MIME_ATTACH(WCTemplateToken *Tokens, void *Context, int ContextType)
686 message_summary *Msg = (message_summary*) Context;
687 return GetCount(Msg->AllAttach) > 0;
692 /*----------------------------------------------------------------------------*/
695 void tmplput_MAIL_BODY(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
697 message_summary *Msg = (message_summary*) Context;
698 StrBufAppendBuf(Target, Msg->MsgBody.Data, 0);
702 void render_MAIL_variformat(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
704 /* Messages in legacy Citadel variformat get handled thusly... */
705 StrBuf *Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
706 FmOut(Target, "JUSTIFY", Mime->Data);
707 FreeStrBuf(&Mime->Data);
711 void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
714 const char *ptr, *pte;
715 const char *BufPtr = NULL;
716 StrBuf *Line = NewStrBuf();
717 StrBuf *Line1 = NewStrBuf();
718 StrBuf *Line2 = NewStrBuf();
719 StrBuf *Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
726 iconv_t ic = (iconv_t)(-1) ;
729 /* Boring old 80-column fixed format text gets handled this way... */
730 if ((strcasecmp(ChrPtr(Mime->Charset), "us-ascii") == 0) &&
731 (strcasecmp(ChrPtr(Mime->Charset), "UTF-8") == 0))
736 if (StrLength(Mime->Charset) != 0)
738 else if (StrLength(FoundCharset) > 0)
740 else if (StrLength(WC->DefaultCharset) > 0)
741 cs = WC->DefaultCharset;
746 ctdl_iconv_open("UTF-8", ChrPtr(cs), &ic);
747 if (ic == (iconv_t)(-1) ) {
748 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
749 __FILE__, __LINE__, ChrPtr(Mime->Charset), strerror(errno));
755 while ((n = StrBufSipLine(Line, Mime->Data, &BufPtr), n >= 0) && !done)
761 len = StrLength(Line);
764 while ((ptr < pte) &&
773 if (i > 0) StrBufCutLeft(Line, i);
775 if (StrLength(Line) == 0)
778 for (i = bn; i < bq; i++)
779 StrBufAppendBufPlain(Target, HKEY("<blockquote>"), 0);
780 for (i = bq; i < bn; i++)
781 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
783 if (ConvertIt == 1) {
784 StrBufConvert(Line, Line1, &ic);
787 StrBufAppendBufPlain(Target, HKEY("<tt>"), 0);
788 UrlizeText(Line1, Line, Line2);
790 StrEscAppend(Target, Line1, NULL, 0, 0);
791 StrBufAppendBufPlain(Target, HKEY("</tt><br />\n"), 0);
795 for (i = 0; i < bn; i++)
796 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
798 StrBufAppendBufPlain(Target, HKEY("</i><br />"), 0);
800 if (ic != (iconv_t)(-1) ) {
804 FreeStrBuf(&Mime->Data);
811 void render_MAIL_html(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
814 /* HTML is fun, but we've got to strip it first */
815 Buf = NewStrBufPlain(NULL, StrLength(Mime->Data));
816 output_html(ChrPtr(Mime->Charset),
817 (WC->wc_view == VIEW_WIKI ? 1 : 0),
818 StrToi(Mime->PartNum),
820 FreeStrBuf(&Mime->Data);
824 void render_MAIL_UNKNOWN(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
826 /* Unknown weirdness */
827 FlushStrBuf(Mime->Data);
828 StrBufAppendBufPlain(Mime->Data, _("I don't know how to display "), -1, 0);
829 StrBufAppendBuf(Mime->Data, Mime->ContentType, 0);
830 StrBufAppendBufPlain(Mime->Data, HKEY("<br />\n"), 0);
838 HashList *iterate_get_mime_All(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
840 message_summary *Msg = (message_summary*) Context;
841 return Msg->Attachments;
843 HashList *iterate_get_mime_Submessages(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
845 message_summary *Msg = (message_summary*) Context;
846 return Msg->Submessages;
848 HashList *iterate_get_mime_AttachLinks(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
850 message_summary *Msg = (message_summary*) Context;
851 return Msg->AttachLinks;
853 HashList *iterate_get_mime_Attachments(StrBuf *Target, int nArgs, WCTemplateToken *Tokens, void *Context, int ContextType)
855 message_summary *Msg = (message_summary*) Context;
856 return Msg->AllAttach;
859 void tmplput_MIME_Name(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
861 wc_mime_attachment *mime = (wc_mime_attachment*) Context;
862 StrBufAppendBuf(Target, mime->Name, 0);
865 void tmplput_MIME_FileName(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
867 wc_mime_attachment *mime = (wc_mime_attachment*) Context;
868 StrBufAppendBuf(Target, mime->FileName, 0);
871 void tmplput_MIME_PartNum(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
873 wc_mime_attachment *mime = (wc_mime_attachment*) Context;
874 StrBufAppendBuf(Target, mime->PartNum, 0);
877 void tmplput_MIME_MsgNum(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
879 wc_mime_attachment *mime = (wc_mime_attachment*) Context;
880 StrBufAppendPrintf(Target, "%ld", mime->msgnum);
883 void tmplput_MIME_Disposition(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
885 wc_mime_attachment *mime = (wc_mime_attachment*) Context;
886 StrBufAppendBuf(Target, mime->Disposition, 0);
889 void tmplput_MIME_ContentType(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
891 wc_mime_attachment *mime = (wc_mime_attachment*) Context;
892 StrBufAppendBuf(Target, mime->ContentType, 0);
895 void tmplput_MIME_Charset(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
897 wc_mime_attachment *mime = (wc_mime_attachment*) Context;
898 StrBufAppendBuf(Target, mime->Charset, 0);
901 void tmplput_MIME_Data(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
903 wc_mime_attachment *mime = (wc_mime_attachment*) Context;
904 StrBufAppendBuf(Target, mime->Data, 0); /// TODO: check whether we need to load it now?
907 void tmplput_MIME_Length(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
909 wc_mime_attachment *mime = (wc_mime_attachment*) Context;
910 StrBufAppendPrintf(Target, "%ld", mime->length);
916 * Look for URL's embedded in a buffer and make them linkable. We use a
917 * target window in order to keep the Citadel session in its own window.
919 void UrlizeText(StrBuf* Target, StrBuf *Source, StrBuf *WrkBuf)
921 int len, UrlLen, Offset, TrailerLen;
922 const char *start, *end, *pos;
927 len = StrLength(Source);
928 end = ChrPtr(Source) + len;
929 for (pos = ChrPtr(Source); (pos < end) && (start == NULL); ++pos) {
930 if (!strncasecmp(pos, "http://", 7))
932 if (!strncasecmp(pos, "ftp://", 6))
937 StrBufAppendBuf(Target, Source, 0);
942 for (pos = ChrPtr(Source) + len; pos > start; --pos) {
943 if ( (!isprint(*pos))
962 UrlLen = end - start;
963 StrBufAppendBufPlain(WrkBuf, start, UrlLen, 0);
965 Offset = start - ChrPtr(Source);
967 StrBufAppendBufPlain(Target, ChrPtr(Source), Offset, 0);
968 StrBufAppendPrintf(Target, "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
969 LB, QU, ChrPtr(WrkBuf), QU, QU, TARGET,
970 QU, RB, ChrPtr(WrkBuf), LB, RB);
972 TrailerLen = len - (end - start);
974 StrBufAppendBufPlain(Target, end, TrailerLen, 0);
976 void url(char *buf, size_t bufsize)
978 int len, UrlLen, Offset, TrailerLen, outpos;
979 char *start, *end, *pos;
986 lprintf(1, "URL: content longer than buffer!");
990 for (pos = buf; (pos < end) && (start == NULL); ++pos) {
991 if (!strncasecmp(pos, "http://", 7))
993 if (!strncasecmp(pos, "ftp://", 6))
1000 for (pos = buf+len; pos > start; --pos) {
1001 if ( (!isprint(*pos))
1020 UrlLen = end - start;
1021 if (UrlLen > sizeof(urlbuf)){
1022 lprintf(1, "URL: content longer than buffer!");
1025 memcpy(urlbuf, start, UrlLen);
1026 urlbuf[UrlLen] = '\0';
1028 Offset = start - buf;
1029 if ((Offset != 0) && (Offset < sizeof(outbuf)))
1030 memcpy(outbuf, buf, Offset);
1031 outpos = snprintf(&outbuf[Offset], sizeof(outbuf) - Offset,
1032 "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
1033 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
1034 if (outpos >= sizeof(outbuf) - Offset) {
1035 lprintf(1, "URL: content longer than buffer!");
1039 TrailerLen = len - (end - start);
1041 memcpy(outbuf + Offset + outpos, end, TrailerLen);
1042 if (Offset + outpos + TrailerLen > bufsize) {
1043 lprintf(1, "URL: content longer than buffer!");
1046 memcpy (buf, outbuf, Offset + outpos + TrailerLen);
1047 *(buf + Offset + outpos + TrailerLen) = '\0';
1052 * \brief Turn a vCard "n" (name) field into something displayable.
1053 * \param name the name field to convert
1055 void vcard_n_prettyize(char *name)
1057 char *original_name;
1060 original_name = strdup(name);
1061 len = strlen(original_name);
1062 for (i=0; i<5; ++i) {
1064 if (original_name[len-1] == ' ') {
1065 original_name[--len] = 0;
1067 if (original_name[len-1] == ';') {
1068 original_name[--len] = 0;
1074 for (i=0; i<len; ++i) {
1075 if (original_name[i] == ';') {
1080 name[j++] = original_name[i];
1084 free(original_name);
1091 * \brief preparse a vcard name
1092 * display_vcard() calls this after parsing the textual vCard into
1093 * our 'struct vCard' data object.
1094 * This gets called instead of display_parsed_vcard() if we are only looking
1095 * to extract the person's name instead of displaying the card.
1096 * \param v the vcard to retrieve the name from
1097 * \param storename where to put the name at
1099 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
1102 strcpy(storename, "");
1104 name = vcard_get_prop(v, "n", 1, 0, 0);
1106 strcpy(storename, name);
1107 /* vcard_n_prettyize(storename); */
1115 * \brief html print a vcard
1116 * display_vcard() calls this after parsing the textual vCard into
1117 * our 'struct vCard' data object.
1119 * Set 'full' to nonzero to display the full card, otherwise it will only
1120 * show a summary line.
1122 * This code is a bit ugly, so perhaps an explanation is due: we do this
1123 * in two passes through the vCard fields. On the first pass, we process
1124 * fields we understand, and then render them in a pretty fashion at the
1125 * end. Then we make a second pass, outputting all the fields we don't
1126 * understand in a simple two-column name/value format.
1127 * \param v the vCard to display
1128 * \param full display all items of the vcard?
1129 * \param msgnum Citadel message pointer
1131 void display_parsed_vcard(struct vCard *v, int full, long msgnum) {
1137 char *thisname, *thisvalue;
1138 char firsttoken[SIZ];
1147 strcpy(fullname, "");
1155 name = vcard_get_prop(v, "fn", 1, 0, 0);
1159 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
1160 strcpy(fullname, name);
1161 vcard_n_prettyize(fullname);
1171 wprintf("<div align=center>"
1172 "<table bgcolor=#aaaaaa width=50%%>");
1173 for (pass=1; pass<=2; ++pass) {
1175 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
1177 thisname = strdup(v->prop[i].name);
1178 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
1180 for (j=0; j<num_tokens(thisname, ';'); ++j) {
1181 extract_token(buf, thisname, j, ';', sizeof buf);
1182 if (!strcasecmp(buf, "encoding=quoted-printable")) {
1184 remove_token(thisname, j, ';');
1186 if (!strcasecmp(buf, "encoding=base64")) {
1188 remove_token(thisname, j, ';');
1192 len = strlen(v->prop[i].value);
1193 /* if we have some untagged QP, detect it here. */
1194 if (!is_qp && (strstr(v->prop[i].value, "=?")!=NULL))
1195 utf8ify_rfc822_string(v->prop[i].value);
1198 // %ff can become 6 bytes in utf8
1199 thisvalue = malloc(len * 2 + 3);
1200 j = CtdlDecodeQuotedPrintable(
1201 thisvalue, v->prop[i].value,
1206 // ff will become one byte..
1207 thisvalue = malloc(len + 50);
1209 thisvalue, v->prop[i].value,
1210 strlen(v->prop[i].value) );
1213 thisvalue = strdup(v->prop[i].value);
1216 /** Various fields we may encounter ***/
1218 /** N is name, but only if there's no FN already there */
1219 if (!strcasecmp(firsttoken, "n")) {
1220 if (IsEmptyStr(fullname)) {
1221 strcpy(fullname, thisvalue);
1222 vcard_n_prettyize(fullname);
1226 /** FN (full name) is a true 'display name' field */
1227 else if (!strcasecmp(firsttoken, "fn")) {
1228 strcpy(fullname, thisvalue);
1232 else if (!strcasecmp(firsttoken, "title")) {
1233 strcpy(title, thisvalue);
1237 else if (!strcasecmp(firsttoken, "org")) {
1238 strcpy(org, thisvalue);
1241 else if (!strcasecmp(firsttoken, "email")) {
1243 if (!IsEmptyStr(mailto)) strcat(mailto, "<br />");
1245 "<a href=\"display_enter"
1246 "?force_room=_MAIL_?recp=");
1248 len = strlen(mailto);
1249 urlesc(&mailto[len], SIZ - len, "\"");
1250 len = strlen(mailto);
1251 urlesc(&mailto[len], SIZ - len, fullname);
1252 len = strlen(mailto);
1253 urlesc(&mailto[len], SIZ - len, "\" <");
1254 len = strlen(mailto);
1255 urlesc(&mailto[len], SIZ - len, thisvalue);
1256 len = strlen(mailto);
1257 urlesc(&mailto[len], SIZ - len, ">");
1259 strcat(mailto, "\">");
1260 len = strlen(mailto);
1261 stresc(mailto+len, SIZ - len, thisvalue, 1, 1);
1262 strcat(mailto, "</A>");
1264 else if (!strcasecmp(firsttoken, "tel")) {
1265 if (!IsEmptyStr(phone)) strcat(phone, "<br />");
1266 strcat(phone, thisvalue);
1267 for (j=0; j<num_tokens(thisname, ';'); ++j) {
1268 extract_token(buf, thisname, j, ';', sizeof buf);
1269 if (!strcasecmp(buf, "tel"))
1271 else if (!strcasecmp(buf, "work"))
1272 strcat(phone, _(" (work)"));
1273 else if (!strcasecmp(buf, "home"))
1274 strcat(phone, _(" (home)"));
1275 else if (!strcasecmp(buf, "cell"))
1276 strcat(phone, _(" (cell)"));
1278 strcat(phone, " (");
1284 else if (!strcasecmp(firsttoken, "adr")) {
1286 wprintf("<TR><TD>");
1287 wprintf(_("Address:"));
1288 wprintf("</TD><TD>");
1289 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
1290 extract_token(buf, thisvalue, j, ';', sizeof buf);
1291 if (!IsEmptyStr(buf)) {
1293 if (j<3) wprintf("<br />");
1297 wprintf("</TD></TR>\n");
1300 /* else if (!strcasecmp(firsttoken, "photo") && full && pass == 2) {
1301 // Only output on second pass
1302 wprintf("<tr><td>");
1303 wprintf(_("Photo:"));
1304 wprintf("</td><td>");
1305 wprintf("<img src=\"/vcardphoto/%ld/\" alt=\"Contact photo\"/>",msgnum);
1306 wprintf("</td></tr>\n");
1308 else if (!strcasecmp(firsttoken, "version")) {
1311 else if (!strcasecmp(firsttoken, "rev")) {
1314 else if (!strcasecmp(firsttoken, "label")) {
1319 /*** Don't show extra fields. They're ugly.
1321 wprintf("<TR><TD>");
1323 wprintf("</TD><TD>");
1325 wprintf("</TD></TR>\n");
1335 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
1336 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
1337 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
1338 "<FONT SIZE=+1><B>");
1340 wprintf("</B></FONT>");
1341 if (!IsEmptyStr(title)) {
1342 wprintf("<div align=right>");
1346 if (!IsEmptyStr(org)) {
1347 wprintf("<div align=right>");
1351 wprintf("</TD></TR>\n");
1353 if (!IsEmptyStr(phone)) {
1354 wprintf("<tr><td>");
1355 wprintf(_("Telephone:"));
1356 wprintf("</td><td>%s</td></tr>\n", phone);
1358 if (!IsEmptyStr(mailto)) {
1359 wprintf("<tr><td>");
1360 wprintf(_("E-mail:"));
1361 wprintf("</td><td>%s</td></tr>\n", mailto);
1367 wprintf("</table></div>\n");
1373 * \brief Display a textual vCard
1374 * (Converts to a vCard object and then calls the actual display function)
1375 * Set 'full' to nonzero to display the whole card instead of a one-liner.
1376 * Or, if "storename" is non-NULL, just store the person's name in that
1377 * buffer instead of displaying the card at all.
1378 * \param vcard_source the buffer containing the vcard text
1379 * \param alpha what???
1380 * \param full should we usse all lines?
1381 * \param storename where to store???
1382 * \param msgnum Citadel message pointer
1384 void display_vcard(char *vcard_source, char alpha, int full, char *storename,
1389 char this_alpha = 0;
1391 v = vcard_load(vcard_source);
1392 if (v == NULL) return;
1394 name = vcard_get_prop(v, "n", 1, 0, 0);
1396 utf8ify_rfc822_string(name);
1398 this_alpha = buf[0];
1401 if (storename != NULL) {
1402 fetchname_parsed_vcard(v, storename);
1404 else if ( (alpha == 0)
1405 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
1406 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
1408 display_parsed_vcard(v, full,msgnum);
1426 * I wanna SEE that message!
1428 * msgnum Message number to display
1429 * printable_view Nonzero to display a printable view
1430 * section Optional for encapsulated message/rfc822 submessage
1432 void read_message(long msgnum, int printable_view, char *section) {
1433 struct wcsession *WCC = WC;
1436 StrBuf *FoundCharset;
1437 message_summary *Msg = NULL;
1441 struct attach_link *attach_links = NULL;
1442 int num_attach_links = 0;
1443 // char mime_submessages[256] = "";
1444 char reply_references[1024] = "";
1449 char vcard_partnum[256] = "";
1450 char cal_partnum[256] = "";
1451 char *part_source = NULL;
1452 char msg4_partnum[32] = "";
1454 //// strcpy(mime_submessages, "");
1457 serv_printf("MSG4 %ld|%s", msgnum, section);
1458 StrBuf_ServGetln(Buf);
1459 if (GetServerStatus(Buf, NULL) != 1) {
1460 wprintf("<strong>");
1461 wprintf(_("ERROR:"));
1462 wprintf("</strong> %s<br />\n", &buf[4]);
1466 svputlong("MsgPrintable", printable_view);
1467 /** begin everythingamundo table */
1470 Token = NewStrBuf();
1471 Msg = (message_summary *)malloc(sizeof(message_summary));
1472 memset(Msg, 0, sizeof(message_summary));
1473 FoundCharset = NewStrBuf();
1474 while ((StrBuf_ServGetln(Buf)>=0) && !Done) {
1475 if ( (StrLength(Buf)==3) &&
1476 !strcmp(ChrPtr(Buf), "000"))
1481 wprintf(_("unexpected end of message"));
1482 wprintf(" (1)</i><br /><br />\n");
1483 wprintf("</div>\n");
1486 DestroyMessageSummary(Msg);
1487 FreeStrBuf(&FoundCharset);
1495 case 0:/* Citadel Message Headers */
1496 if (StrLength(Buf) == 0) {
1500 StrBufExtract_token(Token, Buf, 0, '=');
1501 StrBufCutLeft(Buf, StrLength(Token) + 1);
1503 lprintf(1, ":: [%s] = [%s]\n", ChrPtr(Token), ChrPtr(Buf));
1504 if (GetHash(MsgHeaderHandler, SKEY(Token), &vHdr) &&
1506 Hdr = (headereval*)vHdr;
1507 Hdr->evaluator(Msg, Buf, FoundCharset);
1508 if (Hdr->Type == 1) {
1512 else lprintf(1, "don't know how to handle message header[%s]\n", ChrPtr(Token));
1514 case 1:/* Message Mime Header */
1515 if (StrLength(Buf) == 0) {
1517 if (Msg->MsgBody.ContentType == NULL)
1518 /* end of header or no header? */
1519 Msg->MsgBody.ContentType = NewStrBufPlain(HKEY("text/plain"));
1520 /* usual end of mime header */
1524 StrBufExtract_token(Token, Buf, 0, ':');
1525 if (StrLength(Token) > 0) {
1526 StrBufCutLeft(Buf, StrLength(Token) + 1);
1527 lprintf(1, ":: [%s] = [%s]\n", ChrPtr(Token), ChrPtr(Buf));
1528 if (GetHash(MsgHeaderHandler, SKEY(Token), &vHdr) &&
1530 Hdr = (headereval*)vHdr;
1531 Hdr->evaluator(Msg, Buf, FoundCharset);
1536 case 2: /* Message Body */
1538 if (Msg->MsgBody.size_known > 0) {
1539 StrBuf_ServGetBLOB(Msg->MsgBody.Data, Msg->MsgBody.length);
1541 /// todo: check next line, if not 000, append following lines
1544 if (StrLength(Msg->MsgBody.Data) > 0)
1545 StrBufAppendBufPlain(Msg->MsgBody.Data, "\n", 1, 0);
1546 StrBufAppendBuf(Msg->MsgBody.Data, Buf, 0);
1550 StrBufAppendBuf(Msg->MsgBody.Data, Buf, 0);
1555 /* strip the bare contenttype, so we ommit charset etc. */
1556 StrBufExtract_token(Buf, Msg->MsgBody.ContentType, 0, ';');
1558 if (GetHash(MimeRenderHandler, SKEY(Buf), &vHdr) &&
1560 RenderMimeFunc Render;
1561 Render = (RenderMimeFunc)vHdr;
1562 Render(&Msg->MsgBody, NULL, FoundCharset);
1566 if (StrLength(Msg->reply_references)> 0) {
1567 /* Trim down excessively long lists of thread references. We eliminate the
1568 * second one in the list so that the thread root remains intact.
1570 int rrtok = num_tokens(ChrPtr(Msg->reply_references), '|');
1571 int rrlen = StrLength(Msg->reply_references);
1572 if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
1573 remove_token(reply_references, 1, '|');////todo
1577 /* Generate a reply-to address */
1578 if (StrLength(Msg->Rfca) > 0) {
1579 if (Msg->reply_to == NULL)
1580 Msg->reply_to = NewStrBuf();
1581 if (StrLength(Msg->from) > 0) {
1582 StrBufPrintf(Msg->reply_to, "%s <%s>", ChrPtr(Msg->from), ChrPtr(Msg->Rfca));
1585 FlushStrBuf(Msg->reply_to);
1586 StrBufAppendBuf(Msg->reply_to, Msg->Rfca, 0);
1591 if ((StrLength(Msg->OtherNode)>0) &&
1592 (strcasecmp(ChrPtr(Msg->OtherNode), serv_info.serv_nodename)) &&
1593 (strcasecmp(ChrPtr(Msg->OtherNode), serv_info.serv_humannode)) )
1595 if (Msg->reply_to == NULL)
1596 Msg->reply_to = NewStrBuf();
1597 StrBufPrintf(Msg->reply_to,
1600 ChrPtr(Msg->OtherNode));
1603 if (Msg->reply_to == NULL)
1604 Msg->reply_to = NewStrBuf();
1605 FlushStrBuf(Msg->reply_to);
1606 StrBufAppendBuf(Msg->reply_to, Msg->from, 0);
1613 DoTemplate(HKEY("view_message"), NULL, Msg, CTX_MAILSUM);
1617 //// put message renderer lookup here.
1618 ///ENDBODY: /* If there are attached submessages, display them now... */
1620 /// if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
1621 /// for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
1622 /// extract_token(buf, mime_submessages, i, '|', sizeof buf);
1623 /// /** use printable_view to suppress buttons */
1624 /// wprintf("<blockquote>");
1625 /// read_message(msgnum, 1, buf);
1626 /// wprintf("</blockquote>");
1631 /* Afterwards, offer links to download attachments 'n' such */
1632 if ( (num_attach_links > 0) && (!section[0]) ) {
1633 for (i=0; i<num_attach_links; ++i) {
1634 if (strcasecmp(attach_links[i].partnum, msg4_partnum)) {
1635 wprintf("%s", attach_links[i].html);
1640 /* Handler for vCard parts */
1641 if (!IsEmptyStr(vcard_partnum)) {
1642 part_source = load_mimepart(msgnum, vcard_partnum);
1643 if (part_source != NULL) {
1645 /** If it's my vCard I can edit it */
1646 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1647 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1648 || (WC->wc_view == VIEW_ADDRESSBOOK)
1650 wprintf("<a href=\"edit_vcard?msgnum=%ld&partnum=%s\">",
1651 msgnum, vcard_partnum);
1652 wprintf("[%s]</a>", _("edit"));
1655 /* In all cases, display the full card */
1656 display_vcard(part_source, 0, 1, NULL,msgnum);
1660 /* Handler for calendar parts */
1661 if (!IsEmptyStr(cal_partnum)) {
1662 part_source = load_mimepart(msgnum, cal_partnum);
1663 if (part_source != NULL) {
1664 cal_process_attachment(part_source, msgnum, cal_partnum);
1673 wprintf("</div>\n");
1675 /* end everythingamundo table */
1676 if (!printable_view) {
1677 wprintf("</div>\n");
1680 if (num_attach_links > 0) {
1683 DestroyMessageSummary(Msg);
1684 FreeStrBuf(&FoundCharset);
1692 * Unadorned HTML output of an individual message, suitable
1693 * for placing in a hidden iframe, for printing, or whatever
1695 * msgnum_as_string == Message number, as a string instead of as a long int
1697 void embed_message(void) {
1700 msgnum = StrTol(WC->UrlFragment1);
1701 read_message(msgnum, 0, "");
1706 * Printable view of a message
1708 * msgnum_as_string == Message number, as a string instead of as a long int
1710 void print_message(void) {
1713 msgnum = StrTol(WC->UrlFragment1);
1714 output_headers(0, 0, 0, 0, 0, 0);
1716 hprintf("Content-type: text/html\r\n"
1718 "Connection: close\r\n",
1722 wprintf("\r\n<html>\n<head><title>");
1723 escputs(WC->wc_fullname);
1724 wprintf("</title></head>\n"
1725 "<body onLoad=\" window.print(); window.close(); \">\n"
1728 read_message(msgnum, 1, "");
1730 wprintf("\n</body></html>\n\n");
1735 * Mobile browser view of message
1737 * @param msg_num_as_string Message number as a string instead of as a long int
1739 void mobile_message_view(void) {
1741 msgnum = StrTol(WC->UrlFragment1);
1742 output_headers(1, 0, 0, 0, 0, 1);
1744 do_template("msgcontrols", NULL);
1745 read_message(msgnum,1, "");
1750 * \brief Display a message's headers
1752 * \param msgnum_as_string Message number, as a string instead of as a long int
1754 void display_headers(void) {
1758 msgnum = StrTol(WC->UrlFragment1);
1759 output_headers(0, 0, 0, 0, 0, 0);
1761 hprintf("Content-type: text/plain\r\n"
1763 "Connection: close\r\n",
1767 serv_printf("MSG2 %ld|3", msgnum);
1768 serv_getln(buf, sizeof buf);
1769 if (buf[0] == '1') {
1770 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1771 wprintf("%s\n", buf);
1781 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
1782 * or 'reply quoted' operations.
1784 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1785 * in this function. Doing so would throw a JavaScript error in the
1786 * 'supplied text' argument to the editor.
1788 * \param msgnum Message number of the message we want to quote
1789 * \param forward_attachments Nonzero if we want attachments to be forwarded
1791 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
1793 char mime_partnum[256];
1794 char mime_filename[256];
1795 char mime_content_type[256];
1796 char mime_charset[256];
1797 char mime_disposition[256];
1799 char *attachments = NULL;
1801 int num_attachments = 0;
1802 struct wc_attachment *att, *aptr;
1803 char m_subject[1024];
1810 int format_type = 0;
1815 iconv_t ic = (iconv_t)(-1) ;
1816 char *ibuf; /**< Buffer of characters to be converted */
1817 char *obuf; /**< Buffer for converted characters */
1818 size_t ibuflen; /**< Length of input buffer */
1819 size_t obuflen; /**< Length of output buffer */
1820 char *osav; /**< Saved pointer to output buffer */
1826 strcpy(reply_to, "");
1827 strcpy(mime_content_type, "text/plain");
1828 strcpy(mime_charset, "us-ascii");
1830 serv_printf("MSG4 %ld", msgnum);
1831 serv_getln(buf, sizeof buf);
1832 if (buf[0] != '1') {
1833 wprintf(_("ERROR:"));
1834 wprintf("%s<br />", &buf[4]);
1838 strcpy(m_subject, "");
1840 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1841 if (!strcmp(buf, "000")) {
1842 wprintf("%s (3)", _("unexpected end of message"));
1845 if (include_headers) {
1846 if (!strncasecmp(buf, "nhdr=yes", 8))
1850 if (!strncasecmp(buf, "type=", 5))
1851 format_type = atoi(&buf[5]);
1852 if (!strncasecmp(buf, "from=", 5)) {
1853 strcpy(from, &buf[5]);
1854 wprintf(_("from "));
1855 utf8ify_rfc822_string(from);
1858 if (!strncasecmp(buf, "subj=", 5)) {
1859 strcpy(m_subject, &buf[5]);
1861 if ((!strncasecmp(buf, "hnod=", 5))
1862 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1863 wprintf("(%s) ", &buf[5]);
1865 if ((!strncasecmp(buf, "room=", 5))
1866 && (strcasecmp(&buf[5], WC->wc_roomname))
1867 && (!IsEmptyStr(&buf[5])) ) {
1869 wprintf("%s> ", &buf[5]);
1871 if (!strncasecmp(buf, "rfca=", 5)) {
1872 strcpy(rfca, &buf[5]);
1877 if (!strncasecmp(buf, "node=", 5)) {
1878 strcpy(node, &buf[5]);
1879 if ( ((WC->room_flags & QR_NETWORK)
1880 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1881 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1882 && (IsEmptyStr(rfca))
1884 wprintf("@%s ", &buf[5]);
1887 if (!strncasecmp(buf, "rcpt=", 5)) {
1889 strcpy(to, &buf[5]);
1890 utf8ify_rfc822_string(to);
1893 if (!strncasecmp(buf, "time=", 5)) {
1894 webcit_fmt_date(now, atol(&buf[5]), 0);
1895 wprintf("%s ", now);
1900 * Save attachment info for later. We can't start downloading them
1901 * yet because we're in the middle of a server transaction.
1903 if (!strncasecmp(buf, "part=", 5)) {
1904 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
1907 sprintf(ptr, "%s%s\n",
1908 ((attachments != NULL) ? attachments : ""),
1913 lprintf(9, "attachments=<%s>\n", attachments);
1919 if (include_headers) {
1922 utf8ify_rfc822_string(m_subject);
1923 if (!IsEmptyStr(m_subject)) {
1924 wprintf(_("Subject:"));
1926 msgescputs(m_subject);
1937 * Learn the content type
1939 strcpy(mime_content_type, "text/plain");
1940 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
1941 if (!strcmp(buf, "000")) {
1942 wprintf("%s (4)", _("unexpected end of message"));
1945 if (!strncasecmp(buf, "Content-type: ", 14)) {
1947 safestrncpy(mime_content_type, &buf[14],
1948 sizeof(mime_content_type));
1949 for (i=0; i<strlen(mime_content_type); ++i) {
1950 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1951 safestrncpy(mime_charset, &mime_content_type[i+8],
1952 sizeof mime_charset);
1955 len = strlen(mime_content_type);
1956 for (i=0; i<len; ++i) {
1957 if (mime_content_type[i] == ';') {
1958 mime_content_type[i] = 0;
1962 len = strlen(mime_charset);
1963 for (i=0; i<len; ++i) {
1964 if (mime_charset[i] == ';') {
1965 mime_charset[i] = 0;
1972 /** Set up a character set conversion if we need to (and if we can) */
1974 if ( (strcasecmp(mime_charset, "us-ascii"))
1975 && (strcasecmp(mime_charset, "UTF-8"))
1976 && (strcasecmp(mime_charset, ""))
1978 ctdl_iconv_open("UTF-8", mime_charset, &ic);
1979 if (ic == (iconv_t)(-1) ) {
1980 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
1981 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
1986 /** Messages in legacy Citadel variformat get handled thusly... */
1987 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1991 /* Boring old 80-column fixed format text gets handled this way... */
1992 else if (!strcasecmp(mime_content_type, "text/plain")) {
1993 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1996 if ((len > 0) && (buf[len-1] == '\n')) buf[--len] = 0;
1997 if ((len > 0) && (buf[len-1] == '\r')) buf[--len] = 0;
2000 if (ic != (iconv_t)(-1) ) {
2004 obuf = (char *) malloc(obuflen);
2006 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
2007 osav[SIZ-obuflen] = 0;
2008 safestrncpy(buf, osav, sizeof buf);
2014 while ((!IsEmptyStr(buf)) && (isspace(buf[len - 1])))
2017 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
2018 wprintf("<blockquote>");
2020 } else if ((bq == 1) &&
2021 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
2022 wprintf("</blockquote>");
2026 url(buf, sizeof(buf));
2028 wprintf("</tt><br />");
2030 wprintf("</i><br />");
2033 /** HTML just gets escaped and stuffed back into the editor */
2034 else if (!strcasecmp(mime_content_type, "text/html")) {
2035 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2039 }//// TODO: charset? utf8?
2041 /** Unknown weirdness ... don't know how to handle this content type */
2043 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
2047 /** end of body handler */
2050 * If there were attachments, we have to download them and insert them
2051 * into the attachment chain for the forwarded message we are composing.
2053 if ( (forward_attachments) && (num_attachments) ) {
2054 for (i=0; i<num_attachments; ++i) {
2055 extract_token(buf, attachments, i, '\n', sizeof buf);
2056 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
2057 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
2058 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
2059 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
2060 mime_length = extract_int(buf, 5);
2063 * tracing ... uncomment if necessary
2066 lprintf(9, "fwd filename: %s\n", mime_filename);
2067 lprintf(9, "fwd partnum : %s\n", mime_partnum);
2068 lprintf(9, "fwd conttype: %s\n", mime_content_type);
2069 lprintf(9, "fwd dispose : %s\n", mime_disposition);
2070 lprintf(9, "fwd length : %d\n", mime_length);
2072 if ( (!strcasecmp(mime_disposition, "inline"))
2073 || (!strcasecmp(mime_disposition, "attachment")) ) {
2075 /* Create an attachment struct from this mime part... */
2076 att = malloc(sizeof(struct wc_attachment));
2077 memset(att, 0, sizeof(struct wc_attachment));
2078 att->length = mime_length;
2079 strcpy(att->content_type, mime_content_type);
2080 strcpy(att->filename, mime_filename);
2082 att->data = load_mimepart(msgnum, mime_partnum);
2084 /* And add it to the list. */
2085 if (WC->first_attachment == NULL) {
2086 WC->first_attachment = att;
2089 aptr = WC->first_attachment;
2090 while (aptr->next != NULL) aptr = aptr->next;
2099 if (ic != (iconv_t)(-1) ) {
2104 if (attachments != NULL) {
2112 void EvaluateMimePart(message_summary *Sum, StrBuf *Buf)
2115 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
2116 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
2117 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
2118 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
2119 mime_length = extract_int(&buf[5], 5);
2121 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
2122 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
2123 strcpy(vcard_partnum, mime_partnum);
2128 message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSubject, long MsgNum)
2131 MsgPartEvaluatorFunc Eval;
2132 message_summary *Msg;
2141 serv_printf("MSG0 %ld|1", MsgNum); /* ask for headers only */
2143 StrBuf_ServGetln(Buf);
2144 if (GetServerStatus(Buf, NULL) == 1) {
2149 Msg = (message_summary*)malloc(sizeof(message_summary));
2150 memset(Msg, 0, sizeof(message_summary));
2151 while (len = StrBuf_ServGetln(Buf),
2153 strcmp(ChrPtr(Buf), "000")== 0)){
2155 ebuf = strchr(ChrPtr(Buf), '=');
2157 if (GetHash(MsgEvaluators, buf, nBuf, &vEval) && vEval != NULL) {
2158 Eval = (MsgPartEvaluatorFunc) vEval;
2159 StrBufCutLeft(Buf, nBuf + 1);
2162 else lprintf(1, "Don't know how to handle Message Headerline [%s]", ChrPtr(Buf));
2169 * \brief display the adressbook overview
2170 * \param msgnum the citadel message number
2171 * \param alpha what????
2173 void display_addressbook(long msgnum, char alpha) {
2175 /* char mime_partnum[SIZ]; */
2176 /* char mime_filename[SIZ]; */
2177 /* char mime_content_type[SIZ]; */
2178 ///char mime_disposition[SIZ];
2180 char vcard_partnum[SIZ];
2181 char *vcard_source = NULL;
2182 message_summary summ;////TODO: this will leak
2184 memset(&summ, 0, sizeof(summ));
2185 ///safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
2186 ///Load Message headers
2188 if (!IsEmptyStr(vcard_partnum)) {
2189 vcard_source = load_mimepart(msgnum, vcard_partnum);
2190 if (vcard_source != NULL) {
2192 /** Display the summary line */
2193 display_vcard(vcard_source, alpha, 0, NULL,msgnum);
2195 /** If it's my vCard I can edit it */
2196 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
2197 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
2198 || (WC->wc_view == VIEW_ADDRESSBOOK)
2200 wprintf("<a href=\"edit_vcard?"
2201 "msgnum=%ld&partnum=%s\">",
2202 msgnum, vcard_partnum);
2203 wprintf("[%s]</a>", _("edit"));
2215 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
2216 * \param namebuf name to analyze, reverse if nescessary
2218 void lastfirst_firstlast(char *namebuf) {
2219 char firstname[SIZ];
2223 if (namebuf == NULL) return;
2224 if (strchr(namebuf, ';') != NULL) return;
2226 i = num_tokens(namebuf, ' ');
2229 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
2230 remove_token(namebuf, i-1, ' ');
2231 strcpy(firstname, namebuf);
2232 sprintf(namebuf, "%s; %s", lastname, firstname);
2236 * \brief fetch what??? name
2237 * \param msgnum the citadel message number
2238 * \param namebuf where to put the name in???
2240 void fetch_ab_name(message_summary *Msg, char *namebuf) {
2242 char mime_partnum[SIZ];
2243 char mime_filename[SIZ];
2244 char mime_content_type[SIZ];
2245 char mime_disposition[SIZ];
2247 char vcard_partnum[SIZ];
2248 char *vcard_source = NULL;
2250 message_summary summ;/// TODO this will lak
2252 if (namebuf == NULL) return;
2253 strcpy(namebuf, "");
2255 memset(&summ, 0, sizeof(summ));
2256 //////safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
2258 sprintf(buf, "MSG0 %ld|0", Msg->msgnum); /** unfortunately we need the mime info now */
2260 serv_getln(buf, sizeof buf);
2261 if (buf[0] != '1') return;
2263 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2264 if (!strncasecmp(buf, "part=", 5)) {
2265 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
2266 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
2267 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
2268 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
2269 mime_length = extract_int(&buf[5], 5);
2271 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
2272 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
2273 strcpy(vcard_partnum, mime_partnum);
2279 if (!IsEmptyStr(vcard_partnum)) {
2280 vcard_source = load_mimepart(Msg->msgnum, vcard_partnum);
2281 if (vcard_source != NULL) {
2283 /* Grab the name off the card */
2284 display_vcard(vcard_source, 0, 0, namebuf, Msg->msgnum);
2290 lastfirst_firstlast(namebuf);
2292 len = strlen(namebuf);
2293 for (i=0; i<len; ++i) {
2294 if (namebuf[i] != ';') return;
2296 strcpy(namebuf, _("(no name)"));
2302 * \brief Record compare function for sorting address book indices
2303 * \param ab1 adressbook one
2304 * \param ab2 adressbook two
2306 int abcmp(const void *ab1, const void *ab2) {
2308 (((const struct addrbookent *)ab1)->ab_name),
2309 (((const struct addrbookent *)ab2)->ab_name)
2315 * \brief Helper function for do_addrbook_view()
2316 * Converts a name into a three-letter tab label
2317 * \param tabbuf the tabbuffer to add name to
2318 * \param name the name to add to the tabbuffer
2320 void nametab(char *tabbuf, long len, char *name) {
2321 stresc(tabbuf, len, name, 0, 0);
2322 tabbuf[0] = toupper(tabbuf[0]);
2323 tabbuf[1] = tolower(tabbuf[1]);
2324 tabbuf[2] = tolower(tabbuf[2]);
2330 * \brief Render the address book using info we gathered during the scan
2331 * \param addrbook the addressbook to render
2332 * \param num_ab the number of the addressbook
2334 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
2338 static int NAMESPERPAGE = 60;
2341 char tabfirst_label[64];
2343 char tablast_label[64];
2344 char this_tablabel[64];
2349 wprintf("<br /><br /><br /><div align=\"center\"><i>");
2350 wprintf(_("This address book is empty."));
2351 wprintf("</i></div>\n");
2356 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
2359 num_pages = (num_ab / NAMESPERPAGE) + 1;
2361 tablabels = malloc(num_pages * sizeof (char *));
2362 if (tablabels == NULL) {
2363 wprintf("<br /><br /><br /><div align=\"center\"><i>");
2364 wprintf(_("An internal error has occurred."));
2365 wprintf("</i></div>\n");
2369 for (i=0; i<num_pages; ++i) {
2370 tabfirst = i * NAMESPERPAGE;
2371 tablast = tabfirst + NAMESPERPAGE - 1;
2372 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
2373 nametab(tabfirst_label, 64, addrbook[tabfirst].ab_name);
2374 nametab(tablast_label, 64, addrbook[tablast].ab_name);
2375 sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
2376 tablabels[i] = strdup(this_tablabel);
2379 tabbed_dialog(num_pages, tablabels);
2382 for (i=0; i<num_ab; ++i) {
2384 if ((i / NAMESPERPAGE) != page) { /* New tab */
2385 page = (i / NAMESPERPAGE);
2387 wprintf("</tr></table>\n");
2388 end_tab(page-1, num_pages);
2390 begin_tab(page, num_pages);
2391 wprintf("<table border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
2395 if ((displayed % 4) == 0) {
2396 if (displayed > 0) {
2400 wprintf("<tr bgcolor=\"#%s\">",
2401 (bg ? "DDDDDD" : "FFFFFF")
2407 wprintf("<a href=\"readfwd?startmsg=%ld?is_singlecard=1",
2408 addrbook[i].ab_msgnum);
2409 wprintf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
2410 vcard_n_prettyize(addrbook[i].ab_name);
2411 escputs(addrbook[i].ab_name);
2412 wprintf("</a></td>\n");
2416 /* Placeholders for empty columns at end */
2417 if ((num_ab % 4) != 0) {
2418 for (i=0; i<(4-(num_ab % 4)); ++i) {
2419 wprintf("<td> </td>");
2423 wprintf("</tr></table>\n");
2424 end_tab((num_pages-1), num_pages);
2426 begin_tab(num_pages, num_pages);
2427 /* FIXME there ought to be something here */
2428 end_tab(num_pages, num_pages);
2430 for (i=0; i<num_pages; ++i) {
2439 * load message pointers from the server for a "read messages" operation
2441 * servcmd: the citadel command to send to the citserver
2442 * with_headers: also include some of the headers with the message numbers (more expensive)
2444 int load_msg_ptrs(char *servcmd, int with_headers)
2446 StrBuf* FoundCharset = NULL;
2447 struct wcsession *WCC = WC;
2448 message_summary *Msg;
2451 ///time_t datestamp;
2452 //char fullname[128];
2453 //char nodename[128];
2454 //char inetaddr[128];
2455 //char subject[1024];
2462 ////int num_summ_alloc = 0;
2464 if (WCC->summ != NULL) {
2465 if (WCC->summ != NULL)
2466 DeleteHash(&WCC->summ);
2468 WCC->summ = NewHash(1, Flathash);
2470 maxload = 1000;/// TODO
2474 StrBuf_ServGetln(Buf);
2475 if (GetServerStatus(Buf, NULL) != 1) {
2479 // TODO if (with_headers) { //// TODO: Have Attachments?
2481 while (len = StrBuf_ServGetln(Buf),
2483 strcmp(ChrPtr(Buf), "000")!= 0))
2485 if (nummsgs < maxload) {
2486 Msg = (message_summary*)malloc(sizeof(message_summary));
2487 memset(Msg, 0, sizeof(message_summary));
2489 Msg->msgnum = StrBufExtract_long(Buf, 0, '|');
2490 Msg->date = StrBufExtract_long(Buf, 1, '|');
2492 Msg->from = NewStrBufPlain(NULL, StrLength(Buf));
2493 StrBufExtract_token(Buf2, Buf, 2, '|');
2494 if (StrLength(Buf2) != 0) {
2495 /** Handle senders with RFC2047 encoding */
2496 StrBuf_RFC822_to_Utf8(Msg->from, Buf2, WCC->DefaultCharset, FoundCharset);
2500 StrBufExtract_token(Buf2, Buf, 3, '|');
2501 if ((StrLength(Buf2) !=0 ) &&
2502 ( ((WCC->room_flags & QR_NETWORK)
2503 || ((strcasecmp(ChrPtr(Buf2), serv_info.serv_nodename)
2504 && (strcasecmp(ChrPtr(Buf2), serv_info.serv_fqdn)))))))
2506 StrBufAppendBufPlain(Msg->from, HKEY(" @ "), 0);
2507 StrBufAppendBuf(Msg->from, Buf2, 0);
2511 StrBufExtract_token(Msg->inetaddr, Buf, 4, '|');
2514 Msg->subj = NewStrBufPlain(NULL, StrLength(Buf));
2515 StrBufExtract_token(Buf2, Buf, 5, '|');
2516 if (StrLength(Buf2) == 0)
2517 StrBufAppendBufPlain(Msg->subj, _("(no subj)"), 0, -1);
2519 StrBuf_RFC822_to_Utf8(Msg->subj, Buf2, WCC->DefaultCharset, FoundCharset);
2520 if ((StrLength(Msg->subj) > 75) &&
2521 (StrBuf_Utf8StrLen(Msg->subj) > 75)) {
2522 StrBuf_Utf8StrCut(Msg->subj, 72);
2523 StrBufAppendBufPlain(Msg->subj, HKEY("..."), 0);
2528 if ((StrLength(Msg->from) > 25) &&
2529 (StrBuf_Utf8StrLen(Msg->from) > 25)) {
2530 StrBuf_Utf8StrCut(Msg->from, 23);
2531 StrBufAppendBufPlain(Msg->from, HKEY("..."), 0);
2533 Put(WCC->summ, (const char*)&Msg->msgnum, sizeof(Msg->msgnum), Msg, DestroyMessageSummary);
2548 * command loop for reading messages
2550 * Set oper to "readnew" or "readold" or "readfwd" or "headers"
2552 void readloop(char *oper)
2555 message_summary *Msg;
2564 long *displayed_msgs = NULL;
2565 int num_displayed = 0;
2567 int is_addressbook = 0;
2568 int is_singlecard = 0;
2569 int is_calendar = 0;
2570 struct calview calv;
2575 int lowest_displayed = (-1);
2576 int highest_displayed = 0;
2577 struct addrbookent *addrbook = NULL;
2579 const StrBuf *sortby = NULL;
2581 int SortBy = eRDate;
2582 const StrBuf *sortpref_value;
2583 int bbs_reverse = 0;
2584 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
2586 const char *HashKey;
2589 if (WCC->wc_view == VIEW_WIKI) {
2590 sprintf(buf, "wiki?room=%s&page=home", WCC->wc_roomname);
2595 startmsg = lbstr("startmsg");
2596 maxmsgs = ibstr("maxmsgs");
2597 is_summary = (ibstr("is_summary") && !WCC->is_mobile);
2598 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
2600 sortpref_value = get_room_pref("sort");
2602 sortby = sbstr("sortby");
2603 if ( (!IsEmptyStr(ChrPtr(sortby))) &&
2604 (strcasecmp(ChrPtr(sortby), ChrPtr(sortpref_value)) != 0)) {
2605 set_room_pref("sort", NewStrBufDup(sortby), 1);
2606 sortpref_value = NULL;
2607 sortpref_value = sortby;
2610 SortBy = StrToESort(sortpref_value);
2611 /* message board sort */
2612 if (SortBy == eReverse) {
2619 output_headers(1, 1, 1, 0, 0, 0);
2622 * When in summary mode, always show ALL messages instead of just
2623 * new or old. Otherwise, show what the user asked for.
2625 if (!strcmp(oper, "readnew")) {
2626 strcpy(cmd, "MSGS NEW");
2628 else if (!strcmp(oper, "readold")) {
2629 strcpy(cmd, "MSGS OLD");
2631 else if (!strcmp(oper, "do_search")) {
2632 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2635 strcpy(cmd, "MSGS ALL");
2638 if ((WCC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1) && !WCC->is_mobile) {
2640 if (!strcmp(oper, "do_search")) {
2641 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2644 strcpy(cmd, "MSGS ALL");
2648 if ((WCC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2650 if (!strcmp(oper, "do_search")) {
2651 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2654 strcpy(cmd, "MSGS ALL");
2659 if (is_summary) { /**< fetch header summary */
2660 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
2661 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2662 (!strcmp(oper, "do_search") ? bstr("query") : "")
2667 if (WCC->is_mobile) {
2669 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
2670 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2671 (!strcmp(oper, "do_search") ? bstr("query") : "")
2677 * Are we doing a summary view? If so, we need to know old messages
2678 * and new messages, so we can do that pretty boldface thing for the
2681 strcpy(old_msgs, "");
2682 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR) || WCC->is_mobile){
2684 serv_getln(buf, sizeof buf);
2685 if (buf[0] == '2') {
2686 strcpy(old_msgs, &buf[4]);
2690 is_singlecard = ibstr("is_singlecard");
2692 if (WCC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
2694 strcpy(cmd, "MSGS ALL|||1");
2696 parse_calendar_view_request(&calv);
2698 if (WCC->wc_default_view == VIEW_TASKS) { /**< tasks */
2700 strcpy(cmd, "MSGS ALL");
2703 if (WCC->wc_default_view == VIEW_NOTES) { /**< notes */
2705 strcpy(cmd, "MSGS ALL");
2710 wprintf("<div id=\"new_notes_here\"></div>\n");
2713 nummsgs = load_msg_ptrs(cmd, (is_summary || WCC->is_mobile));
2716 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2717 wprintf("<div align=\"center\"><br /><em>");
2718 if (!strcmp(oper, "readnew")) {
2719 wprintf(_("No new messages."));
2720 } else if (!strcmp(oper, "readold")) {
2721 wprintf(_("No old messages."));
2723 wprintf(_("No messages here."));
2725 wprintf("</em><br /></div>\n");
2731 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR) || WCC->is_mobile){
2733 message_summary *Msg;
2735 at = GetNewHashPos();
2736 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
2737 /** Are you a new message, or an old message? */
2738 Msg = (message_summary*) vMsg;
2740 if (is_msg_in_mset(old_msgs, Msg->msgnum)) {
2751 if (startmsg == 0L) {
2753 startmsg = WCC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2756 startmsg = WCC->msgarr[0];
2760 if (is_summary || WCC->is_mobile) {
2761 SortByPayload(WCC->summ, SortFuncs[SortBy]);
2766 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2767 " document.onkeydown = CtdlMsgListKeyPress; "
2768 " if (document.layers) { "
2769 " document.captureEvents(Event.KEYPRESS); "
2774 /** note that Date and Delete are now in the same column */
2775 wprintf("<div id=\"message_list_hdr\">"
2776 "<div class=\"fix_scrollbar_bug\">"
2777 "<table cellspacing=0 style=\"width:100%%\">"
2780 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"
2781 "<th width=%d%%>%s <a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=%s\"><img border=\"0\" src=\"%s\" /></a> </th>\n"
2782 "<th width=%d%%>%s <a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=%s\"><img border=\"0\" src=\"%s\" /></a> \n"
2784 "<input type=\"submit\" name=\"delete_button\" id=\"delbutton\" "
2785 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2792 SortByStrings[SubjectInvertSortString[SortBy]],
2793 SortIcons[SortSubjectToIcon[SortBy]],
2794 SENDER_COL_WIDTH_PCT,
2796 SortByStrings[SenderInvertSortString[SortBy]],
2797 SortIcons[SortSenderToIcon[SortBy]],
2798 DATE_PLUS_BUTTONS_WIDTH_PCT,
2800 SortByStrings[DateInvertSortString[SortBy]],
2801 SortIcons[SortDateToIcon[SortBy]],
2804 wprintf("</table></div></div>\n");
2805 wprintf("<div id=\"message_list\">"
2807 "<div class=\"fix_scrollbar_bug\">\n"
2808 "<table class=\"mailbox_summary\" id=\"summary_headers\" "
2809 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2811 } else if (WCC->is_mobile) {
2812 wprintf("<div id=\"message_list\">");
2817 * Set the "is_bbview" variable if it appears that we are looking at
2818 * a classic bulletin board view.
2820 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2821 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2826 * If we're not currently looking at ALL requested
2827 * messages, then display the selector bar
2830 /** begin bbview scroller */
2831 wprintf("<form name=\"msgomatictop\" class=\"selector_top\" > \n <p>");
2832 wprintf(_("Reading #"));//// TODO this isn't used, should it? : , lowest_displayed, highest_displayed);
2834 wprintf("<select name=\"whichones\" size=\"1\" "
2835 "OnChange=\"location.href=msgomatictop.whichones.options"
2836 "[selectedIndex].value\">\n");
2839 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2841 lo = b - maxmsgs + 2;
2843 wprintf("<option %s value="
2848 "%d-%d</option> \n",
2849 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2858 for (b=0; b<nummsgs; b = b + maxmsgs) {
2860 hi = b + maxmsgs + 1;
2861 if (hi > nummsgs) hi = nummsgs;
2862 wprintf("<option %s value="
2867 "%d-%d</option> \n",
2868 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
2877 wprintf("<option value=\"%s?startmsg=%ld"
2878 "&maxmsgs=9999999&is_summary=%d\">",
2880 WCC->msgarr[0], is_summary);
2882 wprintf("</option>");
2883 wprintf("</select> ");
2884 wprintf(_("of %d messages."), nummsgs);
2886 /** forward/reverse */
2887 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2888 "OnChange=\"location.href='%s?sortby=forward'\"",
2889 (bbs_reverse ? "" : "checked"),
2893 wprintf(_("oldest to newest"));
2894 wprintf(" ");
2896 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2897 "OnChange=\"location.href='%s?sortby=reverse'\"",
2898 (bbs_reverse ? "checked" : ""),
2902 wprintf(_("newest to oldest"));
2905 wprintf("</p></form>\n");
2906 /** end bbview scroller */
2909 at = GetNewHashPos();
2910 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
2911 Msg = (message_summary*) vMsg;
2912 if ((Msg->msgnum >= startmsg) && (num_displayed < maxmsgs)) {
2914 /** Display the message */
2916 DoTemplate(HKEY("section_mailsummary"), NULL, Msg, CTX_MAILSUM);
2918 else if (is_addressbook) {
2919 fetch_ab_name(Msg, buf);
2921 addrbook = realloc(addrbook,
2922 (sizeof(struct addrbookent) * num_ab) );
2923 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2924 sizeof(addrbook[num_ab-1].ab_name));
2925 addrbook[num_ab-1].ab_msgnum = Msg->msgnum;
2927 else if (is_calendar) {
2928 load_calendar_item(Msg, Msg->is_new, &calv);
2930 else if (is_tasks) {
2931 display_task(Msg, Msg->is_new);
2933 else if (is_notes) {
2934 display_note(Msg, Msg->is_new);
2935 } else if (WCC->is_mobile) {
2936 DoTemplate(HKEY("section_mailsummary"), NULL, Msg, CTX_MAILSUM);
2939 if (displayed_msgs == NULL) {
2940 displayed_msgs = malloc(sizeof(long) *
2941 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2943 displayed_msgs[num_displayed] = Msg->msgnum;
2946 if (lowest_displayed < 0) lowest_displayed = a;
2947 highest_displayed = a;
2955 if (displayed_msgs != NULL) {
2957 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2960 /** if we do a split bbview in the future, begin messages div here */
2962 for (a=0; a<num_displayed; ++a) {
2963 read_message(displayed_msgs[a], 0, "");
2966 /** if we do a split bbview in the future, end messages div here */
2968 free(displayed_msgs);
2969 displayed_msgs = NULL;
2974 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
2975 wprintf("</div>"); /**< end of 'message_list' div */
2977 /** Here's the grab-it-to-resize-the-message-list widget */
2978 wprintf("<div id=\"resize_msglist\" "
2979 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
2980 "<div class=\"fix_scrollbar_bug\"> <hr>"
2984 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
2985 } else if (WCC->is_mobile) {
2990 * Bump these because although we're thinking in zero base, the user
2991 * is a drooling idiot and is thinking in one base.
2994 ++highest_displayed;
2997 * If we're not currently looking at ALL requested
2998 * messages, then display the selector bar
3001 /** begin bbview scroller */
3002 wprintf("<form name=\"msgomatic\" class=\"selector_bottom\" > \n <p>");
3003 wprintf(_("Reading #")); /// TODO: this isn't used: , lowest_displayed, highest_displayed);
3005 wprintf("<select name=\"whichones\" size=\"1\" "
3006 "OnChange=\"location.href=msgomatic.whichones.options"
3007 "[selectedIndex].value\">\n");
3010 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
3012 lo = b - maxmsgs + 2;
3014 wprintf("<option %s value="
3019 "%d-%d</option> \n",
3020 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
3029 for (b=0; b<nummsgs; b = b + maxmsgs) {
3031 hi = b + maxmsgs + 1;
3032 if (hi > nummsgs) hi = nummsgs;
3033 wprintf("<option %s value="
3038 "%d-%d</option> \n",
3039 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
3048 wprintf("<option value=\"%s&startmsg=%ld"
3049 "&maxmsgs=9999999&is_summary=%d\">",
3051 WCC->msgarr[0], is_summary);
3053 wprintf("</option>");
3054 wprintf("</select> ");
3055 wprintf(_("of %d messages."), nummsgs);
3057 /** forward/reverse */
3058 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
3059 "OnChange=\"location.href='%s&sortby=forward'\"",
3060 (bbs_reverse ? "" : "checked"),
3064 wprintf(_("oldest to newest"));
3065 wprintf(" ");
3066 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
3067 "OnChange=\"location.href='%s&sortby=reverse'\"",
3068 (bbs_reverse ? "checked" : ""),
3072 wprintf(_("newest to oldest"));
3075 wprintf("</p></form>\n");
3076 /** end bbview scroller */
3081 do_tasks_view(); /** Render the task list */
3085 render_calendar_view(&calv);
3088 if (is_addressbook) {
3089 do_addrbook_view(addrbook, num_ab); /** Render the address book */
3092 /** Note: wDumpContent() will output one additional </div> tag. */
3093 wprintf("</div>\n"); /** end of 'content' div */
3096 /** free the summary */
3097 if (WCC->summ != NULL) {
3098 DeleteHash(&WCC->summ);
3100 if (addrbook != NULL) free(addrbook);
3105 * Back end for post_message()
3106 * ... this is where the actual message gets transmitted to the server.
3108 void post_mime_to_server(void) {
3109 char top_boundary[SIZ];
3110 char alt_boundary[SIZ];
3111 int is_multipart = 0;
3113 struct wc_attachment *att;
3115 size_t encoded_length;
3116 size_t encoded_strlen;
3117 char *txtmail = NULL;
3119 sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
3120 serv_info.serv_fqdn,
3124 sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x",
3125 serv_info.serv_fqdn,
3130 /* RFC2045 requires this, and some clients look for it... */
3131 serv_puts("MIME-Version: 1.0");
3132 serv_puts("X-Mailer: " PACKAGE_STRING);
3134 /* If there are attachments, we have to do multipart/mixed */
3135 if (WC->first_attachment != NULL) {
3140 /* Remember, serv_printf() appends an extra newline */
3141 serv_printf("Content-type: multipart/mixed; boundary=\"%s\"\n", top_boundary);
3142 serv_printf("This is a multipart message in MIME format.\n");
3143 serv_printf("--%s", top_boundary);
3146 /* Remember, serv_printf() appends an extra newline */
3147 serv_printf("Content-type: multipart/alternative; "
3148 "boundary=\"%s\"\n", alt_boundary);
3149 serv_printf("This is a multipart message in MIME format.\n");
3150 serv_printf("--%s", alt_boundary);
3152 serv_puts("Content-type: text/plain; charset=utf-8");
3153 serv_puts("Content-Transfer-Encoding: quoted-printable");
3155 txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
3156 text_to_server_qp(txtmail); /* Transmit message in quoted-printable encoding */
3159 serv_printf("--%s", alt_boundary);
3161 serv_puts("Content-type: text/html; charset=utf-8");
3162 serv_puts("Content-Transfer-Encoding: quoted-printable");
3164 serv_puts("<html><body>\r\n");
3165 text_to_server_qp(bstr("msgtext")); /* Transmit message in quoted-printable encoding */
3166 serv_puts("</body></html>\r\n");
3168 serv_printf("--%s--", alt_boundary);
3172 /* Add in the attachments */
3173 for (att = WC->first_attachment; att!=NULL; att=att->next) {
3175 encoded_length = ((att->length * 150) / 100);
3176 encoded = malloc(encoded_length);
3177 if (encoded == NULL) break;
3178 encoded_strlen = CtdlEncodeBase64(encoded, att->data, att->length, 1);
3180 serv_printf("--%s", top_boundary);
3181 serv_printf("Content-type: %s", att->content_type);
3182 serv_printf("Content-disposition: attachment; filename=\"%s\"", att->filename);
3183 serv_puts("Content-transfer-encoding: base64");
3185 serv_write(encoded, encoded_strlen);
3190 serv_printf("--%s--", top_boundary);
3198 * Post message (or don't post message)
3200 * Note regarding the "dont_post" variable:
3201 * A random value (actually, it's just a timestamp) is inserted as a hidden
3202 * field called "postseq" when the display_enter page is generated. This
3203 * value is checked when posting, using the static variable dont_post. If a
3204 * user attempts to post twice using the same dont_post value, the message is
3205 * discarded. This prevents the accidental double-saving of the same message
3206 * if the user happens to click the browser "back" button.
3208 void post_message(void)
3211 StrBuf *encoded_subject = NULL;
3212 static long dont_post = (-1L);
3213 struct wc_attachment *att, *aptr;
3214 int is_anonymous = 0;
3215 const StrBuf *display_name = NULL;
3216 struct wcsession *WCC = WC;
3218 if (havebstr("force_room")) {
3219 gotoroom(bstr("force_room"));
3222 if (havebstr("display_name")) {
3223 display_name = sbstr("display_name");
3224 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
3225 display_name = NULL;
3230 if (WCC->upload_length > 0) {
3232 lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WCC->upload_length);
3233 /** There's an attachment. Save it to this struct... */
3234 att = malloc(sizeof(struct wc_attachment));
3235 memset(att, 0, sizeof(struct wc_attachment));
3236 att->length = WCC->upload_length;
3237 strcpy(att->content_type, WCC->upload_content_type);
3238 strcpy(att->filename, WCC->upload_filename);
3241 /** And add it to the list. */
3242 if (WCC->first_attachment == NULL) {
3243 WCC->first_attachment = att;
3246 aptr = WCC->first_attachment;
3247 while (aptr->next != NULL) aptr = aptr->next;
3252 * Mozilla sends a simple filename, which is what we want,
3253 * but Satan's Browser sends an entire pathname. Reduce
3254 * the path to just a filename if we need to.
3256 while (num_tokens(att->filename, '/') > 1) {
3257 remove_token(att->filename, 0, '/');
3259 while (num_tokens(att->filename, '\\') > 1) {
3260 remove_token(att->filename, 0, '\\');
3264 * Transfer control of this memory from the upload struct
3265 * to the attachment struct.
3267 att->data = WCC->upload;
3268 WCC->upload_length = 0;
3274 if (havebstr("cancel_button")) {
3275 sprintf(WCC->ImportantMessage,
3276 _("Cancelled. Message was not posted."));
3277 } else if (havebstr("attach_button")) {
3280 } else if (lbstr("postseq") == dont_post) {
3281 sprintf(WCC->ImportantMessage,
3282 _("Automatically cancelled because you have already "
3283 "saved this message."));
3285 const char CMD[] = "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s|%s";
3286 const StrBuf *Recp = NULL;
3287 const StrBuf *Cc = NULL;
3288 const StrBuf *Bcc = NULL;
3289 const StrBuf *Wikipage = NULL;
3290 const StrBuf *my_email_addr = NULL;
3291 StrBuf *CmdBuf = NULL;;
3292 StrBuf *references = NULL;
3294 if (havebstr("references"))
3296 const StrBuf *ref = sbstr("references");
3297 references = NewStrBufPlain(ChrPtr(ref), StrLength(ref));
3298 lprintf(9, "Converting: %s\n", ChrPtr(references));
3299 StrBufReplaceChars(references, '|', '!');
3300 lprintf(9, "Converted: %s\n", ChrPtr(references));
3302 if (havebstr("subject")) {
3305 * make enough room for the encoded string;
3306 * plus the QP header
3308 Subj = sbstr("subject");
3310 StrBufRFC2047encode(&encoded_subject, Subj);
3312 Recp = sbstr("recp");
3315 Wikipage = sbstr("wikipage");
3316 my_email_addr = sbstr("my_email_addr");
3318 CmdBuf = NewStrBufPlain(NULL,
3321 StrLength(encoded_subject) +
3324 StrLength(Wikipage) +
3325 StrLength(my_email_addr) +
3326 StrLength(references));
3328 StrBufPrintf(CmdBuf,
3332 ChrPtr(encoded_subject),
3333 ChrPtr(display_name),
3337 ChrPtr(my_email_addr),
3338 ChrPtr(references));
3339 FreeStrBuf(&references);
3341 lprintf(9, "%s\n", CmdBuf);
3342 serv_puts(ChrPtr(CmdBuf));
3343 serv_getln(buf, sizeof buf);
3344 FreeStrBuf(&CmdBuf);
3345 FreeStrBuf(&encoded_subject);
3346 if (buf[0] == '4') {
3347 post_mime_to_server();
3348 if ( (havebstr("recp"))
3349 || (havebstr("cc" ))
3350 || (havebstr("bcc" ))
3352 sprintf(WCC->ImportantMessage, _("Message has been sent.\n"));
3355 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
3357 dont_post = lbstr("postseq");
3359 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, buf);
3360 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3366 free_attachments(WCC);
3369 * We may have been supplied with instructions regarding the location
3370 * to which we must return after posting. If found, go there.
3372 if (havebstr("return_to")) {
3373 http_redirect(bstr("return_to"));
3376 * If we were editing a page in a wiki room, go to that page now.
3378 else if (havebstr("wikipage")) {
3379 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
3383 * Otherwise, just go to the "read messages" loop.
3386 readloop("readnew");
3394 * \brief display the message entry screen
3396 void display_enter(void)
3401 const StrBuf *display_name = NULL;
3402 struct wc_attachment *att;
3403 int recipient_required = 0;
3404 int subject_required = 0;
3405 int recipient_bad = 0;
3406 int is_anonymous = 0;
3407 long existing_page = (-1L);
3408 struct wcsession *WCC = WC;
3412 if (havebstr("force_room")) {
3413 gotoroom(bstr("force_room"));
3416 display_name = sbstr("display_name");
3417 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
3418 display_name = NULL;
3422 /** First test to see whether this is a room that requires recipients to be entered */
3423 serv_puts("ENT0 0");
3424 serv_getln(buf, sizeof buf);
3426 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
3427 recipient_required = 1;
3429 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
3430 sprintf(WCC->ImportantMessage, "%s", &buf[4]);
3431 readloop("readnew");
3435 /* Is the server strongly recommending that the user enter a message subject? */
3436 if ((buf[3] != '\0') && (buf[4] != '\0')) {
3437 subject_required = extract_int(&buf[4], 1);
3441 * Are we perhaps in an address book view? If so, then an "enter
3442 * message" command really means "add new entry."
3444 if (WCC->wc_default_view == VIEW_ADDRESSBOOK) {
3445 do_edit_vcard(-1, "", "", WCC->wc_roomname);
3450 * Are we perhaps in a calendar room? If so, then an "enter
3451 * message" command really means "add new calendar item."
3453 if (WCC->wc_default_view == VIEW_CALENDAR) {
3454 display_edit_event();
3459 * Are we perhaps in a tasks view? If so, then an "enter
3460 * message" command really means "add new task."
3462 if (WCC->wc_default_view == VIEW_TASKS) {
3463 display_edit_task();
3468 * Otherwise proceed normally.
3469 * Do a custom room banner with no navbar...
3471 output_headers(1, 1, 2, 0, 0, 0);
3472 wprintf("<div id=\"banner\">\n");
3473 embed_room_banner(NULL, navbar_none);
3474 wprintf("</div>\n");
3475 wprintf("<div id=\"content\">\n"
3476 "<div class=\"fix_scrollbar_bug message \">");
3478 /* Now check our actual recipients if there are any */
3479 if (recipient_required) {
3480 const StrBuf *Recp = NULL;
3481 const StrBuf *Cc = NULL;
3482 const StrBuf *Bcc = NULL;
3483 const StrBuf *Wikipage = NULL;
3484 StrBuf *CmdBuf = NULL;;
3485 const char CMD[] = "ENT0 0|%s|%d|0||%s||%s|%s|%s";
3487 Recp = sbstr("recp");
3490 Wikipage = sbstr("wikipage");
3492 CmdBuf = NewStrBufPlain(NULL,
3495 StrLength(display_name) +
3498 StrLength(Wikipage));
3500 StrBufPrintf(CmdBuf,
3504 ChrPtr(display_name),
3508 serv_puts(ChrPtr(CmdBuf));
3509 serv_getln(buf, sizeof buf);
3510 FreeStrBuf(&CmdBuf);
3512 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
3513 if (havebstr("recp") &&
3519 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
3520 wprintf("<em>%s</em><br />\n", &buf[4]);
3525 /** If we got this far, we can display the message entry screen. */
3527 /* begin message entry screen */
3529 "enctype=\"multipart/form-data\" "
3531 "accept-charset=\"UTF-8\" "
3533 "name=\"enterform\""
3535 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
3536 if (WCC->wc_view == VIEW_WIKI) {
3537 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
3539 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
3540 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WCC->nonce);
3541 wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
3542 escputs(WCC->wc_roomname);
3544 wprintf("<input type=\"hidden\" name=\"references\" value=\"");
3545 escputs(bstr("references"));
3548 /** submit or cancel buttons */
3549 wprintf("<p class=\"send_edit_msg\">");
3550 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
3551 if (recipient_required) {
3552 wprintf(_("Send message"));
3554 wprintf(_("Post message"));
3557 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3562 wprintf("<img src=\"static/newmess3_24x.gif\" class=\"imgedit\">");
3563 wprintf(" "); /** header bar */
3564 webcit_fmt_date(buf, now, 0);
3566 wprintf("\n"); /** header bar */
3568 wprintf("<table width=\"100%%\" class=\"edit_msg_table\">");
3570 wprintf("<th><label for=\"from_id\" > ");
3571 wprintf(_(" <I>from</I> "));
3572 wprintf("</label></th>");
3574 wprintf("<td colspan=\"2\">");
3576 /* Allow the user to select any of his valid screen names */
3578 wprintf("<select name=\"display_name\" size=1 id=\"from_id\">\n");
3581 serv_getln(buf, sizeof buf);
3582 if (buf[0] == '1') {
3583 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3584 wprintf("<option %s value=\"",
3585 ((!strcasecmp(bstr("display_name"), buf)) ? "selected" : "")
3590 wprintf("</option>\n");
3594 if (WCC->room_flags & QR_ANONOPT) {
3595 wprintf("<option %s value=\"__ANONYMOUS__\">%s</option>\n",
3596 ((!strcasecmp(bstr("__ANONYMOUS__"), WCC->wc_fullname)) ? "selected" : ""),
3601 wprintf("</select>\n");
3603 /* If this is an email (not a post), allow the user to select any of his
3604 * valid email addresses.
3606 if (recipient_required) {
3608 serv_getln(buf, sizeof buf);
3609 if (buf[0] == '1') {
3610 wprintf("<select name=\"my_email_addr\" size=1>\n");
3611 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3612 wprintf("<option value=\"");
3616 wprintf("></option>\n");
3618 wprintf("</select>\n");
3622 wprintf(_(" <I>in</I> "));
3623 escputs(WCC->wc_roomname);
3625 wprintf("</td></tr>");
3627 if (recipient_required) {
3631 wprintf("<tr><th><label for=\"recp_id\"> ");
3633 wprintf("</label></th>"
3634 "<td><input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
3635 ccraw = xbstr("recp", &len);
3636 copy = (char*) malloc(len * 2 + 1);
3637 memcpy(copy, ccraw, len + 1);
3638 utf8ify_rfc822_string(copy);
3641 wprintf("\" size=45 maxlength=1000 />");
3642 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
3643 wprintf("</td><td rowspan=\"3\" align=\"left\" valign=\"top\">");
3645 /** Pop open an address book -- begin **/
3647 "<a href=\"javascript:PopOpenAddressBook('recp_id|%s|cc_id|%s|bcc_id|%s');\" "
3649 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
3651 _("To:"), _("CC:"), _("BCC:"),
3652 _("Contacts"), _("Contacts")
3654 /** Pop open an address book -- end **/
3656 wprintf("</td></tr>");
3658 wprintf("<tr><th><label for=\"cc_id\"> ");
3660 wprintf("</label></th>"
3661 "<td><input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
3662 ccraw = xbstr("cc", &len);
3663 copy = (char*) malloc(len * 2 + 1);
3664 memcpy(copy, ccraw, len + 1);
3665 utf8ify_rfc822_string(copy);
3668 wprintf("\" size=45 maxlength=1000 />");
3669 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
3670 wprintf("</td></tr>");
3672 wprintf("<tr><th><label for=\"bcc_id\"> ");
3674 wprintf("</label></th>"
3675 "<td><input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
3676 ccraw = xbstr("bcc", &len);
3677 copy = (char*) malloc(len * 2 + 1);
3678 memcpy(copy, ccraw, len + 1);
3679 utf8ify_rfc822_string(copy);
3682 wprintf("\" size=45 maxlength=1000 />");
3683 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
3684 wprintf("</td></tr>");
3686 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
3687 wprintf("<script type=\"text/javascript\"> \n"
3688 " activate_entmsg_autocompleters(); \n"
3694 wprintf("<tr><th><label for=\"subject_id\" > ");
3695 if (recipient_required || subject_required) {
3696 wprintf(_("Subject:"));
3699 wprintf(_("Subject (optional):"));
3701 wprintf("</label></th>"
3702 "<td colspan=\"2\">"
3703 "<input type=\"text\" name=\"subject\" id=\"subject_id\" value=\"");
3704 escputs(bstr("subject"));
3705 wprintf("\" size=45 maxlength=70>\n");
3706 wprintf("</td></tr>");
3708 wprintf("<tr><td colspan=\"3\">\n");
3710 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
3712 /** If we're continuing from a previous edit, put our partially-composed message back... */
3713 msgescputs(bstr("msgtext"));
3715 /* If we're forwarding a message, insert it here... */
3716 if (lbstr("fwdquote") > 0L) {
3717 wprintf("<br><div align=center><i>");
3718 wprintf(_("--- forwarded message ---"));
3719 wprintf("</i></div><br>");
3720 pullquote_message(lbstr("fwdquote"), 1, 1);
3723 /** If we're replying quoted, insert the quote here... */
3724 else if (lbstr("replyquote") > 0L) {
3727 pullquote_message(lbstr("replyquote"), 0, 1);
3728 wprintf("</blockquote><br>");
3731 /** If we're editing a wiki page, insert the existing page here... */
3732 else if (WCC->wc_view == VIEW_WIKI) {
3733 safestrncpy(buf, bstr("wikipage"), sizeof buf);
3734 str_wiki_index(buf);
3735 existing_page = locate_message_by_uid(buf);
3736 if (existing_page >= 0L) {
3737 pullquote_message(existing_page, 1, 0);
3741 /** Insert our signature if appropriate... */
3742 if ( (WCC->is_mailbox) && !yesbstr("sig_inserted") ) {
3744 get_pref_yesno("use_sig", &UseSig, 0);
3747 const char *sig, *esig;
3749 get_preference("signature", &ebuf);
3751 StrBufEUid_unescapize(Sig, ebuf);
3753 esig = sig + StrLength(Sig);
3754 wprintf("<br>--<br>");
3755 while (sig <= esig) {
3759 else if (*sig == '<') {
3762 else if (*sig == '>') {
3765 else if (*sig == '&') {
3768 else if (*sig == '\"') {
3771 else if (*sig == '\'') {
3774 else /* since we're utf 8, is this a good idea? if (isprint(*sig))*/ {
3775 wprintf("%c", *sig);
3783 wprintf("</textarea>\n");
3785 /** Make sure we only insert our signature once */
3786 /** We don't care if it was there or not before, it needs to be there now. */
3787 wprintf("<input type=\"hidden\" name=\"sig_inserted\" value=\"yes\">\n");
3790 * The following template embeds the TinyMCE richedit control, and automatically
3791 * transforms the textarea into a richedit textarea.
3793 do_template("richedit", NULL);
3795 /** Enumerate any attachments which are already in place... */
3796 wprintf("<div class=\"attachment buttons\"><img src=\"static/diskette_24x.gif\" class=\"imgedit\" > ");
3797 wprintf(_("Attachments:"));
3799 wprintf("<select name=\"which_attachment\" size=1>");
3800 for (att = WCC->first_attachment; att != NULL; att = att->next) {
3801 wprintf("<option value=\"");
3802 urlescputs(att->filename);
3804 escputs(att->filename);
3805 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
3806 wprintf("</option>\n");
3808 wprintf("</select>");
3810 /** Now offer the ability to attach additional files... */
3811 wprintf(" ");
3812 wprintf(_("Attach file:"));
3813 wprintf(" <input name=\"attachfile\" class=\"attachfile\" "
3814 "size=16 type=\"file\">\n "
3815 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
3816 wprintf("</div>"); /* End of "attachment buttons" div */
3819 wprintf("</td></tr></table>");
3821 wprintf("</form>\n");
3822 wprintf("</div>\n"); /* end of "fix_scrollbar_bug" div */
3824 /* NOTE: address_book_popup() will close the "content" div. Don't close it here. */
3825 DONE: address_book_popup();
3831 * \brief delete a message
3833 void delete_msg(void)
3838 msgid = lbstr("msgid");
3840 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
3841 serv_printf("DELE %ld", msgid);
3843 else { /** Otherwise move it to Trash */
3844 serv_printf("MOVE %ld|_TRASH_|0", msgid);
3847 serv_getln(buf, sizeof buf);
3848 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3850 readloop("readnew");
3855 * \brief move a message to another folder
3862 msgid = lbstr("msgid");
3864 if (havebstr("move_button")) {
3865 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
3867 serv_getln(buf, sizeof buf);
3868 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3870 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
3873 readloop("readnew");
3881 * Confirm move of a message
3883 void confirm_move_msg(void)
3889 msgid = lbstr("msgid");
3892 output_headers(1, 1, 2, 0, 0, 0);
3893 wprintf("<div id=\"banner\">\n");
3895 wprintf(_("Confirm move of message"));
3897 wprintf("</div>\n");
3899 wprintf("<div id=\"content\" class=\"service\">\n");
3901 wprintf("<CENTER>");
3903 wprintf(_("Move this message to:"));
3904 wprintf("<br />\n");
3906 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
3907 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
3908 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
3910 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
3912 serv_getln(buf, sizeof buf);
3913 if (buf[0] == '1') {
3914 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3915 extract_token(targ, buf, 0, '|', sizeof targ);
3916 wprintf("<OPTION>");
3921 wprintf("</SELECT>\n");
3922 wprintf("<br />\n");
3924 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
3926 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
3927 wprintf("</form></CENTER>\n");
3929 wprintf("</CENTER>\n");
3933 void readnew(void) { readloop("readnew");}
3934 void readold(void) { readloop("readold");}
3935 void readfwd(void) { readloop("readfwd");}
3936 void headers(void) { readloop("headers");}
3937 void do_search(void) { readloop("do_search");}
3948 WebcitAddUrlHandler(HKEY("readnew"), readnew, 0);
3949 WebcitAddUrlHandler(HKEY("readold"), readold, 0);
3950 WebcitAddUrlHandler(HKEY("readfwd"), readfwd, 0);
3951 WebcitAddUrlHandler(HKEY("headers"), headers, 0);
3952 WebcitAddUrlHandler(HKEY("do_search"), do_search, 0);
3953 WebcitAddUrlHandler(HKEY("display_enter"), display_enter, 0);
3954 WebcitAddUrlHandler(HKEY("post"), post_message, 0);
3955 WebcitAddUrlHandler(HKEY("move_msg"), move_msg, 0);
3956 WebcitAddUrlHandler(HKEY("delete_msg"), delete_msg, 0);
3957 WebcitAddUrlHandler(HKEY("confirm_move_msg"), confirm_move_msg, 0);
3958 WebcitAddUrlHandler(HKEY("msg"), embed_message, NEED_URL|AJAX);
3959 WebcitAddUrlHandler(HKEY("printmsg"), print_message, NEED_URL);
3960 WebcitAddUrlHandler(HKEY("mobilemsg"), mobile_message_view, NEED_URL);
3961 WebcitAddUrlHandler(HKEY("msgheaders"), display_headers, NEED_URL);
3963 RegisterNamespace("MAIL:SUMM:DATESTR", 0, 0, tmplput_MAIL_SUMM_DATE_STR, CTX_MAILSUM);
3964 RegisterNamespace("MAIL:SUMM:DATENO", 0, 0, tmplput_MAIL_SUMM_DATE_NO, CTX_MAILSUM);
3965 RegisterNamespace("MAIL:SUMM:N", 0, 0, tmplput_MAIL_SUMM_N, CTX_MAILSUM);
3966 RegisterNamespace("MAIL:SUMM:FROM", 0, 2, tmplput_MAIL_SUMM_FROM, CTX_MAILSUM);
3967 RegisterNamespace("MAIL:SUMM:TO", 0, 2, tmplput_MAIL_SUMM_TO, CTX_MAILSUM);
3968 RegisterNamespace("MAIL:SUMM:SUBJECT", 0, 4, tmplput_MAIL_SUMM_SUBJECT, CTX_MAILSUM);
3969 RegisterNamespace("MAIL:SUMM:NATTACH", 0, 0, tmplput_MAIL_SUMM_NATTACH, CTX_MAILSUM);
3970 RegisterNamespace("MAIL:SUMM:CCCC", 0, 2, tmplput_MAIL_SUMM_CCCC, CTX_MAILSUM);
3971 RegisterNamespace("MAIL:SUMM:H_NODE", 0, 2, tmplput_MAIL_SUMM_H_NODE, CTX_MAILSUM);
3972 RegisterNamespace("MAIL:SUMM:ALLRCPT", 0, 2, tmplput_MAIL_SUMM_ALLRCPT, CTX_MAILSUM);
3973 RegisterNamespace("MAIL:SUMM:ORGROOM", 0, 2, tmplput_MAIL_SUMM_ORGROOM, CTX_MAILSUM);
3974 RegisterNamespace("MAIL:SUMM:RFCA", 0, 2, tmplput_MAIL_SUMM_RFCA, CTX_MAILSUM);
3975 RegisterNamespace("MAIL:SUMM:OTHERNODE", 2, 0, tmplput_MAIL_SUMM_OTHERNODE, CTX_MAILSUM);
3976 RegisterNamespace("MAIL:SUMM:REFIDS", 0, 0, tmplput_MAIL_SUMM_REFIDS, CTX_MAILSUM);
3977 RegisterNamespace("MAIL:SUMM:INREPLYTO", 0, 2, tmplput_MAIL_SUMM_INREPLYTO, CTX_MAILSUM);
3978 RegisterNamespace("MAIL:BODY", 0, 2, tmplput_MAIL_BODY, CTX_MAILSUM);
3981 RegisterConditional(HKEY("COND:MAIL:SUMM:UNREAD"), 0, Conditional_MAIL_SUMM_UNREAD, CTX_MAILSUM);
3982 RegisterConditional(HKEY("COND:MAIL:SUMM:H_NODE"), 0, Conditional_MAIL_SUMM_H_NODE, CTX_MAILSUM);
3983 RegisterConditional(HKEY("COND:MAIL:SUMM:OTHERNODE"), 0, Conditional_MAIL_SUMM_OTHERNODE, CTX_MAILSUM);
3985 RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH"), 0, Conditional_MAIL_MIME_ALL, CTX_MAILSUM);
3986 RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:SUBMESSAGES"), 0, Conditional_MAIL_MIME_SUBMESSAGES, CTX_MAILSUM);
3987 RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:LINKS"), 0, Conditional_MAIL_MIME_ATTACHLINKS, CTX_MAILSUM);
3988 RegisterConditional(HKEY("COND:MAIL:MIME:ATTACH:ATT"), 0, Conditional_MAIL_MIME_ATTACH, CTX_MAILSUM);
3991 RegisterIterator("MAIL:MIME:ATTACH", 0, NULL, iterate_get_mime_All,
3992 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM);
3993 RegisterIterator("MAIL:MIME:ATTACH:SUBMESSAGES", 0, NULL, iterate_get_mime_Submessages,
3994 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM);
3995 RegisterIterator("MAIL:MIME:ATTACH:LINKS", 0, NULL, iterate_get_mime_AttachLinks,
3996 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM);
3997 RegisterIterator("MAIL:MIME:ATTACH:ATT", 0, NULL, iterate_get_mime_Attachments,
3998 NULL, NULL, CTX_MIME_ATACH, CTX_MAILSUM);
4000 RegisterNamespace("MAIL:MIME:NAME", 0, 2, tmplput_MIME_Name, CTX_MIME_ATACH);
4001 RegisterNamespace("MAIL:MIME:FILENAME", 0, 2, tmplput_MIME_FileName, CTX_MIME_ATACH);
4002 RegisterNamespace("MAIL:MIME:PARTNUM", 0, 2, tmplput_MIME_PartNum, CTX_MIME_ATACH);
4003 RegisterNamespace("MAIL:MIME:MSGNUM", 0, 2, tmplput_MIME_MsgNum, CTX_MIME_ATACH);
4004 RegisterNamespace("MAIL:MIME:DISPOSITION", 0, 2, tmplput_MIME_Disposition, CTX_MIME_ATACH);
4005 RegisterNamespace("MAIL:MIME:CONTENTTYPE", 0, 2, tmplput_MIME_ContentType, CTX_MIME_ATACH);
4006 RegisterNamespace("MAIL:MIME:CHARSET", 0, 2, tmplput_MIME_Charset, CTX_MIME_ATACH);
4007 RegisterNamespace("MAIL:MIME:LENGTH", 0, 2, tmplput_MIME_Length, CTX_MIME_ATACH);
4008 RegisterNamespace("MAIL:MIME:DATA", 0, 2, tmplput_MIME_Data, CTX_MIME_ATACH);
4012 RegisterMimeRenderer(HKEY("text/x-citadel-variformat"), render_MAIL_variformat);
4013 RegisterMimeRenderer(HKEY("text/plain"), render_MAIL_text_plain);
4014 RegisterMimeRenderer(HKEY("text"), render_MAIL_text_plain);
4015 RegisterMimeRenderer(HKEY("text/html"), render_MAIL_html);
4016 RegisterMimeRenderer(HKEY(""), render_MAIL_UNKNOWN);
4018 RegisterMsgHdr(HKEY("nhdr"), examine_nhdr, 0);
4019 RegisterMsgHdr(HKEY("type"), examine_type, 0);
4020 RegisterMsgHdr(HKEY("from"), examine_from, 0);
4021 RegisterMsgHdr(HKEY("subj"), examine_subj, 0);
4022 RegisterMsgHdr(HKEY("msgn"), examine_msgn, 0);
4023 RegisterMsgHdr(HKEY("wefw"), examine_wefw, 0);
4024 RegisterMsgHdr(HKEY("cccc"), examine_cccc, 0);
4025 RegisterMsgHdr(HKEY("hnod"), examine_hnod, 0);
4026 RegisterMsgHdr(HKEY("room"), examine_room, 0);
4027 RegisterMsgHdr(HKEY("rfca"), examine_rfca, 0);
4028 RegisterMsgHdr(HKEY("node"), examine_node, 0);
4029 RegisterMsgHdr(HKEY("rcpt"), examine_rcpt, 0);
4030 RegisterMsgHdr(HKEY("time"), examine_time, 0);
4031 RegisterMsgHdr(HKEY("part"), examine_mime_part, 0);
4032 RegisterMsgHdr(HKEY("text"), examine_text, 1);
4033 RegisterMsgHdr(HKEY("X-Citadel-MSG4-Partnum"), examine_msg4_partnum, 0);
4034 RegisterMsgHdr(HKEY("Content-type"), examine_content_type, 0);
4035 RegisterMsgHdr(HKEY("Content-length"), examine_content_lengh, 0);
4036 RegisterMsgHdr(HKEY("Content-transfer-encoding"), examine_content_encoding, 0);