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);
284 DestroyMimeParts(&Msg->MsgBody);
291 void RegisterMsgHdr(const char *HeaderName, long HdrNLen, ExamineMsgHeaderFunc evaluator, int type)
294 ev = (headereval*) malloc(sizeof(headereval));
295 ev->evaluator = evaluator;
297 Put(MsgHeaderHandler, HeaderName, HdrNLen, ev, NULL);
300 void RegisterMimeRenderer(const char *HeaderName, long HdrNLen, RenderMimeFunc MimeRenderer)
302 Put(MimeRenderHandler, HeaderName, HdrNLen, MimeRenderer, reference_free_handler);
306 /*----------------------------------------------------------------------------*/
309 void examine_nhdr(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
312 if (!strncasecmp(ChrPtr(HdrLine), "yes", 8))
316 void examine_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
318 Msg->format_type = StrToi(HdrLine);
322 void examine_from(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
324 FreeStrBuf(&Msg->from);
325 Msg->from = NewStrBufPlain(NULL, StrLength(HdrLine));
326 StrBuf_RFC822_to_Utf8(Msg->from, HdrLine, WC->DefaultCharset, FoundCharset);
328 void tmplput_MAIL_SUMM_FROM(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
330 message_summary *Msg = (message_summary*) Context;
331 StrBufAppendBuf(Target, Msg->from, 0);
332 lprintf(1,"%s", ChrPtr(Msg->from));
337 void examine_subj(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
339 FreeStrBuf(&Msg->subj);
340 Msg->subj = NewStrBufPlain(NULL, StrLength(HdrLine));
341 StrBuf_RFC822_to_Utf8(Msg->subj, HdrLine, WC->DefaultCharset, FoundCharset);
342 lprintf(1,"%s", ChrPtr(Msg->subj));
344 void tmplput_MAIL_SUMM_SUBJECT(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
345 {/////TODO: Fwd: and RE: filter!!
346 message_summary *Msg = (message_summary*) Context;
347 StrBufAppendBuf(Target, Msg->subj, 0);
351 void examine_msgn(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
353 FreeStrBuf(&Msg->reply_inreplyto);
354 Msg->reply_inreplyto = NewStrBufPlain(NULL, StrLength(HdrLine));
355 StrBuf_RFC822_to_Utf8(Msg->reply_inreplyto, HdrLine, WC->DefaultCharset, FoundCharset);
357 void tmplput_MAIL_SUMM_INREPLYTO(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
359 message_summary *Msg = (message_summary*) Context;
360 StrBufAppendBuf(Target, Msg->reply_inreplyto, 0);
364 void examine_wefw(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
366 FreeStrBuf(&Msg->reply_references);
367 Msg->reply_references = NewStrBufPlain(NULL, StrLength(HdrLine));
368 StrBuf_RFC822_to_Utf8(Msg->reply_references, HdrLine, WC->DefaultCharset, FoundCharset);
370 void tmplput_MAIL_SUMM_REFIDS(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
372 message_summary *Msg = (message_summary*) Context;
373 StrBufAppendBuf(Target, Msg->reply_references, 0);
377 void examine_cccc(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
379 FreeStrBuf(&Msg->cccc);
380 Msg->cccc = NewStrBufPlain(NULL, StrLength(HdrLine));
381 StrBuf_RFC822_to_Utf8(Msg->cccc, HdrLine, WC->DefaultCharset, FoundCharset);
382 if (Msg->AllRcpt == NULL)
383 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
384 if (StrLength(Msg->AllRcpt) > 0) {
385 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
387 StrBufAppendBuf(Msg->AllRcpt, Msg->cccc, 0);
389 void tmplput_MAIL_SUMM_CCCC(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
391 message_summary *Msg = (message_summary*) Context;
392 StrBufAppendBuf(Target, Msg->cccc, 0);
398 void examine_room(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
400 if ((StrLength(HdrLine) > 0) &&
401 (strcasecmp(ChrPtr(HdrLine), WC->wc_roomname))) {
402 FreeStrBuf(&Msg->Room);
403 Msg->Room = NewStrBufDup(HdrLine);
406 void tmplput_MAIL_SUMM_ORGROOM(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
408 message_summary *Msg = (message_summary*) Context;
409 StrBufAppendBuf(Target, Msg->Room, 0);
413 void examine_rfca(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
415 FreeStrBuf(&Msg->Rfca);
416 Msg->Rfca = NewStrBufDup(HdrLine);
418 void tmplput_MAIL_SUMM_RFCA(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
420 message_summary *Msg = (message_summary*) Context;
421 StrBufAppendBuf(Target, Msg->Rfca, 0);
425 void examine_node(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
427 if ( (StrLength(HdrLine) > 0) &&
428 ((WC->room_flags & QR_NETWORK)
429 || ((strcasecmp(ChrPtr(HdrLine), serv_info.serv_nodename)
430 && (strcasecmp(ChrPtr(HdrLine), serv_info.serv_fqdn)))))) {
431 FreeStrBuf(&Msg->OtherNode);
432 Msg->OtherNode = NewStrBufDup(HdrLine);
435 void tmplput_MAIL_SUMM_OTHERNODE(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
437 message_summary *Msg = (message_summary*) Context;
438 StrBufAppendBuf(Target, Msg->OtherNode, 0);
440 int Conditional_MAIL_SUMM_OTHERNODE(WCTemplateToken *Tokens, void *Context, int ContextType)
442 message_summary *Msg = (message_summary*) Context;
443 return StrLength(Msg->OtherNode) > 0;
447 void examine_rcpt(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
449 FreeStrBuf(&Msg->to);
450 Msg->to = NewStrBufPlain(NULL, StrLength(HdrLine));
451 StrBuf_RFC822_to_Utf8(Msg->to, HdrLine, WC->DefaultCharset, FoundCharset);
452 if (Msg->AllRcpt == NULL)
453 Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
454 if (StrLength(Msg->AllRcpt) > 0) {
455 StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
457 StrBufAppendBuf(Msg->AllRcpt, Msg->to, 0);
459 void tmplput_MAIL_SUMM_TO(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
461 message_summary *Msg = (message_summary*) Context;
462 StrBufAppendBuf(Target, Msg->to, 0);
464 void tmplput_MAIL_SUMM_ALLRCPT(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
466 message_summary *Msg = (message_summary*) Context;
467 StrBufAppendBuf(Target, Msg->AllRcpt, 0);
472 void examine_time(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
474 Msg->date = StrTol(HdrLine);
476 void tmplput_MAIL_SUMM_DATE_STR(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
479 message_summary *Msg = (message_summary*) Context;
480 webcit_fmt_date(datebuf, Msg->date, 1);
481 StrBufAppendBufPlain(Target, datebuf, -1, 0);
483 void tmplput_MAIL_SUMM_DATE_NO(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
485 message_summary *Msg = (message_summary*) Context;
486 StrBufAppendPrintf(Target, "%ld", Msg->date, 0);
491 void examine_mime_part(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
493 wc_mime_attachment *mime;
496 mime = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
497 memset(mime, 0, sizeof(wc_mime_attachment));
500 mime->Name = NewStrBuf();
501 StrBufExtract_token(mime->Name, HdrLine, 0, '|');
503 StrBufExtract_token(Buf, HdrLine, 1, '|');
504 StrBuf_RFC822_to_Utf8(mime->FileName, Buf, WC->DefaultCharset, FoundCharset);
506 mime->PartNum = NewStrBuf();
507 StrBufExtract_token(mime->PartNum, HdrLine, 2, '|');
509 mime->Disposition = NewStrBuf();
510 StrBufExtract_token(mime->Disposition, HdrLine, 3, '|');
512 mime->ContentType = NewStrBuf();
513 StrBufExtract_token(mime->ContentType, HdrLine, 4, '|');
515 mime->length = StrBufExtract_int(HdrLine, 5, '|');
517 StrBufTrim(mime->Name);
518 StrBufTrim(mime->FileName);
520 if ( (StrLength(mime->FileName) == 0) && (StrLength(mime->Name) > 0) ) {
521 StrBufAppendBuf(mime->FileName, mime->Name, 0);
524 if (!strcasecmp(ChrPtr(mime->ContentType), "message/rfc822")) {
525 if (Msg->Submessages == NULL)
526 Msg->Submessages = NewHash(1,NULL);
527 Put(Msg->Submessages, SKEY(mime->PartNum), mime->PartNum, reference_free_handler);
529 else if ((!strcasecmp(ChrPtr(mime->Disposition), "inline"))
530 && (!strncasecmp(ChrPtr(mime->ContentType), "image/", 6)) ){
531 if (Msg->AttachLinks == NULL)
532 Msg->AttachLinks = NewHash(1,NULL);
533 Put(Msg->AttachLinks, SKEY(mime->PartNum), mime->PartNum, reference_free_handler);
535 else if ((StrLength(mime->ContentType) > 0) &&
536 ( (!strcasecmp(ChrPtr(mime->Disposition), "attachment"))
537 || (!strcasecmp(ChrPtr(mime->Disposition), "inline"))
538 || (!strcasecmp(ChrPtr(mime->Disposition), ""))))
541 if (Msg->AttachLinks == NULL)
542 Msg->AttachLinks = NewHash(1,NULL);
543 Put(Msg->AttachLinks, SKEY(mime->PartNum), mime->PartNum, reference_free_handler);
544 if (strcasecmp(ChrPtr(mime->ContentType), "application/octet-stream") == 0) {
545 FlushStrBuf(mime->ContentType);
546 StrBufAppendBufPlain(mime->ContentType,
547 GuessMimeByFilename(SKEY(mime->FileName)),
552 /** begin handler prep ** */
553 if ( (!strcasecmp(ChrPtr(mime->ContentType), "text/x-vcard"))
554 || (!strcasecmp(ChrPtr(mime->ContentType), "text/vcard")) ) {
555 Msg->vcard_partnum_ref = mime;
557 else if ( (!strcasecmp(ChrPtr(mime->ContentType), "text/calendar"))
558 || (!strcasecmp(ChrPtr(mime->ContentType), "application/ics")) ) {
559 Msg->cal_partnum_ref = mime;
561 /** end handler prep ***/
566 void tmplput_MAIL_SUMM_NATTACH(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
568 message_summary *Msg = (message_summary*) Context;
569 StrBufAppendPrintf(Target, "%ld", GetCount(Msg->Attachments));
578 void examine_hnod(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
580 FreeStrBuf(&Msg->hnod);
581 Msg->hnod = NewStrBufPlain(NULL, StrLength(HdrLine));
582 StrBuf_RFC822_to_Utf8(Msg->hnod, HdrLine, WC->DefaultCharset, FoundCharset);
584 void tmplput_MAIL_SUMM_H_NODE(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
586 message_summary *Msg = (message_summary*) Context;
587 StrBufAppendBuf(Target, Msg->hnod, 0);
589 int Conditional_MAIL_SUMM_H_NODE(WCTemplateToken *Tokens, void *Context, int ContextType)
591 message_summary *Msg = (message_summary*) Context;
592 return StrLength(Msg->hnod) > 0;
597 void examine_text(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
598 {////TODO: read messages here
599 Msg->MsgBody.Data = NewStrBuf();
602 void examine_msg4_partnum(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
604 Msg->MsgBody.PartNum = NewStrBufDup(HdrLine);
605 StrBufTrim(Msg->MsgBody.PartNum);/////TODO: striplt == trim?
608 void examine_content_encoding(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
610 ////TODO: do we care?
613 void examine_content_lengh(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
615 Msg->MsgBody.length = StrTol(HdrLine);
616 Msg->MsgBody.size_known = 1;
619 void examine_content_type(message_summary *Msg, StrBuf *HdrLine, StrBuf *FoundCharset)
622 Msg->MsgBody.ContentType = NewStrBufDup(HdrLine);
623 StrBufTrim(Msg->MsgBody.ContentType);/////todo==striplt?
624 len = StrLength(Msg->MsgBody.ContentType);
625 for (i=0; i<len; ++i) {
626 if (!strncasecmp(ChrPtr(Msg->MsgBody.ContentType) + i, "charset=", 8)) {/// TODO: WHUT?
627 // safestrncpy(mime_charset, &mime_content_type[i+8],
628 /// sizeof mime_charset);
631 for (i=0; i<len; ++i) {
632 if (mime_content_type[i] == ';') {
633 mime_content_type[i] = 0;
637 len = strlen(mime_charset);
638 for (i=0; i<len; ++i) {
639 if (mime_charset[i] == ';') {
647 void tmplput_MAIL_SUMM_N(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
649 message_summary *Msg = (message_summary*) Context;
650 StrBufAppendPrintf(Target, "%ld", Msg->msgnum);
654 int Conditional_MAIL_SUMM_UNREAD(WCTemplateToken *Tokens, void *Context, int ContextType)
656 message_summary *Msg = (message_summary*) Context;
657 return Msg->is_new != 0;
662 /*----------------------------------------------------------------------------*/
665 void tmplput_MAIL_BODY(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
667 message_summary *Msg = (message_summary*) Context;
668 StrBufAppendBuf(Target, Msg->MsgBody.Data, 0);
672 void render_MAIL_variformat(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
674 /* Messages in legacy Citadel variformat get handled thusly... */
675 StrBuf *Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
676 FmOut(Target, "JUSTIFY", Mime->Data);
677 FreeStrBuf(&Mime->Data);
681 void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
684 const char *ptr, *pte;
685 const char *BufPtr = NULL;
686 StrBuf *Line = NewStrBuf();
687 StrBuf *Line1 = NewStrBuf();
688 StrBuf *Line2 = NewStrBuf();
689 StrBuf *Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
696 iconv_t ic = (iconv_t)(-1) ;
699 /* Boring old 80-column fixed format text gets handled this way... */
700 if ((strcasecmp(ChrPtr(Mime->Charset), "us-ascii") == 0) &&
701 (strcasecmp(ChrPtr(Mime->Charset), "UTF-8") == 0))
706 if (StrLength(Mime->Charset) != 0)
708 else if (StrLength(FoundCharset) > 0)
710 else if (StrLength(WC->DefaultCharset) > 0)
711 cs = WC->DefaultCharset;
716 ctdl_iconv_open("UTF-8", ChrPtr(cs), &ic);
717 if (ic == (iconv_t)(-1) ) {
718 lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
719 __FILE__, __LINE__, ChrPtr(Mime->Charset), strerror(errno));
725 while ((n = StrBufSipLine(Line, Mime->Data, &BufPtr), n >= 0) && !done)
731 len = StrLength(Line);
734 while ((ptr < pte) &&
743 if (i > 0) StrBufCutLeft(Line, i);
745 if (StrLength(Line) == 0)
748 for (i = bn; i < bq; i++)
749 StrBufAppendBufPlain(Target, HKEY("<blockquote>"), 0);
750 for (i = bq; i < bn; i++)
751 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
753 if (ConvertIt == 1) {
754 StrBufConvert(Line, Line1, &ic);
757 StrBufAppendBufPlain(Target, HKEY("<tt>"), 0);
758 UrlizeText(Line1, Line, Line2);
760 StrEscAppend(Target, Line1, NULL, 0, 0);
761 StrBufAppendBufPlain(Target, HKEY("</tt><br />\n"), 0);
765 for (i = 0; i < bn; i++)
766 StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
768 StrBufAppendBufPlain(Target, HKEY("</i><br />"), 0);
770 if (ic != (iconv_t)(-1) ) {
774 FreeStrBuf(&Mime->Data);
781 void render_MAIL_html(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
784 /* HTML is fun, but we've got to strip it first */
785 Buf = NewStrBufPlain(NULL, StrLength(Mime->Data));
786 output_html(ChrPtr(Mime->Charset),
787 (WC->wc_view == VIEW_WIKI ? 1 : 0),
788 StrToi(Mime->PartNum),
790 FreeStrBuf(&Mime->Data);
794 void render_MAIL_UNKNOWN(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
796 /* Unknown weirdness */
797 FlushStrBuf(Mime->Data);
798 StrBufAppendBufPlain(Mime->Data, _("I don't know how to display "), -1, 0);
799 StrBufAppendBuf(Mime->Data, Mime->ContentType, 0);
800 StrBufAppendBufPlain(Mime->Data, HKEY("<br />\n"), 0);
810 * Look for URL's embedded in a buffer and make them linkable. We use a
811 * target window in order to keep the Citadel session in its own window.
813 void UrlizeText(StrBuf* Target, StrBuf *Source, StrBuf *WrkBuf)
815 int len, UrlLen, Offset, TrailerLen;
816 const char *start, *end, *pos;
821 len = StrLength(Source);
822 end = ChrPtr(Source) + len;
823 for (pos = ChrPtr(Source); (pos < end) && (start == NULL); ++pos) {
824 if (!strncasecmp(pos, "http://", 7))
826 if (!strncasecmp(pos, "ftp://", 6))
831 StrBufAppendBuf(Target, Source, 0);
836 for (pos = ChrPtr(Source) + len; pos > start; --pos) {
837 if ( (!isprint(*pos))
856 UrlLen = end - start;
857 StrBufAppendBufPlain(WrkBuf, start, UrlLen, 0);
859 Offset = start - ChrPtr(Source);
861 StrBufAppendBufPlain(Target, ChrPtr(Source), Offset, 0);
862 StrBufAppendPrintf(Target, "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
863 LB, QU, ChrPtr(WrkBuf), QU, QU, TARGET,
864 QU, RB, ChrPtr(WrkBuf), LB, RB);
866 TrailerLen = len - (end - start);
868 StrBufAppendBufPlain(Target, end, TrailerLen, 0);
870 void url(char *buf, size_t bufsize)
872 int len, UrlLen, Offset, TrailerLen, outpos;
873 char *start, *end, *pos;
880 lprintf(1, "URL: content longer than buffer!");
884 for (pos = buf; (pos < end) && (start == NULL); ++pos) {
885 if (!strncasecmp(pos, "http://", 7))
887 if (!strncasecmp(pos, "ftp://", 6))
894 for (pos = buf+len; pos > start; --pos) {
895 if ( (!isprint(*pos))
914 UrlLen = end - start;
915 if (UrlLen > sizeof(urlbuf)){
916 lprintf(1, "URL: content longer than buffer!");
919 memcpy(urlbuf, start, UrlLen);
920 urlbuf[UrlLen] = '\0';
922 Offset = start - buf;
923 if ((Offset != 0) && (Offset < sizeof(outbuf)))
924 memcpy(outbuf, buf, Offset);
925 outpos = snprintf(&outbuf[Offset], sizeof(outbuf) - Offset,
926 "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
927 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
928 if (outpos >= sizeof(outbuf) - Offset) {
929 lprintf(1, "URL: content longer than buffer!");
933 TrailerLen = len - (end - start);
935 memcpy(outbuf + Offset + outpos, end, TrailerLen);
936 if (Offset + outpos + TrailerLen > bufsize) {
937 lprintf(1, "URL: content longer than buffer!");
940 memcpy (buf, outbuf, Offset + outpos + TrailerLen);
941 *(buf + Offset + outpos + TrailerLen) = '\0';
946 * \brief Turn a vCard "n" (name) field into something displayable.
947 * \param name the name field to convert
949 void vcard_n_prettyize(char *name)
954 original_name = strdup(name);
955 len = strlen(original_name);
956 for (i=0; i<5; ++i) {
958 if (original_name[len-1] == ' ') {
959 original_name[--len] = 0;
961 if (original_name[len-1] == ';') {
962 original_name[--len] = 0;
968 for (i=0; i<len; ++i) {
969 if (original_name[i] == ';') {
974 name[j++] = original_name[i];
985 * \brief preparse a vcard name
986 * display_vcard() calls this after parsing the textual vCard into
987 * our 'struct vCard' data object.
988 * This gets called instead of display_parsed_vcard() if we are only looking
989 * to extract the person's name instead of displaying the card.
990 * \param v the vcard to retrieve the name from
991 * \param storename where to put the name at
993 void fetchname_parsed_vcard(struct vCard *v, char *storename) {
996 strcpy(storename, "");
998 name = vcard_get_prop(v, "n", 1, 0, 0);
1000 strcpy(storename, name);
1001 /* vcard_n_prettyize(storename); */
1009 * \brief html print a vcard
1010 * display_vcard() calls this after parsing the textual vCard into
1011 * our 'struct vCard' data object.
1013 * Set 'full' to nonzero to display the full card, otherwise it will only
1014 * show a summary line.
1016 * This code is a bit ugly, so perhaps an explanation is due: we do this
1017 * in two passes through the vCard fields. On the first pass, we process
1018 * fields we understand, and then render them in a pretty fashion at the
1019 * end. Then we make a second pass, outputting all the fields we don't
1020 * understand in a simple two-column name/value format.
1021 * \param v the vCard to display
1022 * \param full display all items of the vcard?
1023 * \param msgnum Citadel message pointer
1025 void display_parsed_vcard(struct vCard *v, int full, long msgnum) {
1031 char *thisname, *thisvalue;
1032 char firsttoken[SIZ];
1041 strcpy(fullname, "");
1049 name = vcard_get_prop(v, "fn", 1, 0, 0);
1053 else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
1054 strcpy(fullname, name);
1055 vcard_n_prettyize(fullname);
1065 wprintf("<div align=center>"
1066 "<table bgcolor=#aaaaaa width=50%%>");
1067 for (pass=1; pass<=2; ++pass) {
1069 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
1071 thisname = strdup(v->prop[i].name);
1072 extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
1074 for (j=0; j<num_tokens(thisname, ';'); ++j) {
1075 extract_token(buf, thisname, j, ';', sizeof buf);
1076 if (!strcasecmp(buf, "encoding=quoted-printable")) {
1078 remove_token(thisname, j, ';');
1080 if (!strcasecmp(buf, "encoding=base64")) {
1082 remove_token(thisname, j, ';');
1086 len = strlen(v->prop[i].value);
1087 /* if we have some untagged QP, detect it here. */
1088 if (!is_qp && (strstr(v->prop[i].value, "=?")!=NULL))
1089 utf8ify_rfc822_string(v->prop[i].value);
1092 // %ff can become 6 bytes in utf8
1093 thisvalue = malloc(len * 2 + 3);
1094 j = CtdlDecodeQuotedPrintable(
1095 thisvalue, v->prop[i].value,
1100 // ff will become one byte..
1101 thisvalue = malloc(len + 50);
1103 thisvalue, v->prop[i].value,
1104 strlen(v->prop[i].value) );
1107 thisvalue = strdup(v->prop[i].value);
1110 /** Various fields we may encounter ***/
1112 /** N is name, but only if there's no FN already there */
1113 if (!strcasecmp(firsttoken, "n")) {
1114 if (IsEmptyStr(fullname)) {
1115 strcpy(fullname, thisvalue);
1116 vcard_n_prettyize(fullname);
1120 /** FN (full name) is a true 'display name' field */
1121 else if (!strcasecmp(firsttoken, "fn")) {
1122 strcpy(fullname, thisvalue);
1126 else if (!strcasecmp(firsttoken, "title")) {
1127 strcpy(title, thisvalue);
1131 else if (!strcasecmp(firsttoken, "org")) {
1132 strcpy(org, thisvalue);
1135 else if (!strcasecmp(firsttoken, "email")) {
1137 if (!IsEmptyStr(mailto)) strcat(mailto, "<br />");
1139 "<a href=\"display_enter"
1140 "?force_room=_MAIL_?recp=");
1142 len = strlen(mailto);
1143 urlesc(&mailto[len], SIZ - len, "\"");
1144 len = strlen(mailto);
1145 urlesc(&mailto[len], SIZ - len, fullname);
1146 len = strlen(mailto);
1147 urlesc(&mailto[len], SIZ - len, "\" <");
1148 len = strlen(mailto);
1149 urlesc(&mailto[len], SIZ - len, thisvalue);
1150 len = strlen(mailto);
1151 urlesc(&mailto[len], SIZ - len, ">");
1153 strcat(mailto, "\">");
1154 len = strlen(mailto);
1155 stresc(mailto+len, SIZ - len, thisvalue, 1, 1);
1156 strcat(mailto, "</A>");
1158 else if (!strcasecmp(firsttoken, "tel")) {
1159 if (!IsEmptyStr(phone)) strcat(phone, "<br />");
1160 strcat(phone, thisvalue);
1161 for (j=0; j<num_tokens(thisname, ';'); ++j) {
1162 extract_token(buf, thisname, j, ';', sizeof buf);
1163 if (!strcasecmp(buf, "tel"))
1165 else if (!strcasecmp(buf, "work"))
1166 strcat(phone, _(" (work)"));
1167 else if (!strcasecmp(buf, "home"))
1168 strcat(phone, _(" (home)"));
1169 else if (!strcasecmp(buf, "cell"))
1170 strcat(phone, _(" (cell)"));
1172 strcat(phone, " (");
1178 else if (!strcasecmp(firsttoken, "adr")) {
1180 wprintf("<TR><TD>");
1181 wprintf(_("Address:"));
1182 wprintf("</TD><TD>");
1183 for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
1184 extract_token(buf, thisvalue, j, ';', sizeof buf);
1185 if (!IsEmptyStr(buf)) {
1187 if (j<3) wprintf("<br />");
1191 wprintf("</TD></TR>\n");
1194 /* else if (!strcasecmp(firsttoken, "photo") && full && pass == 2) {
1195 // Only output on second pass
1196 wprintf("<tr><td>");
1197 wprintf(_("Photo:"));
1198 wprintf("</td><td>");
1199 wprintf("<img src=\"/vcardphoto/%ld/\" alt=\"Contact photo\"/>",msgnum);
1200 wprintf("</td></tr>\n");
1202 else if (!strcasecmp(firsttoken, "version")) {
1205 else if (!strcasecmp(firsttoken, "rev")) {
1208 else if (!strcasecmp(firsttoken, "label")) {
1213 /*** Don't show extra fields. They're ugly.
1215 wprintf("<TR><TD>");
1217 wprintf("</TD><TD>");
1219 wprintf("</TD></TR>\n");
1229 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
1230 "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
1231 "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
1232 "<FONT SIZE=+1><B>");
1234 wprintf("</B></FONT>");
1235 if (!IsEmptyStr(title)) {
1236 wprintf("<div align=right>");
1240 if (!IsEmptyStr(org)) {
1241 wprintf("<div align=right>");
1245 wprintf("</TD></TR>\n");
1247 if (!IsEmptyStr(phone)) {
1248 wprintf("<tr><td>");
1249 wprintf(_("Telephone:"));
1250 wprintf("</td><td>%s</td></tr>\n", phone);
1252 if (!IsEmptyStr(mailto)) {
1253 wprintf("<tr><td>");
1254 wprintf(_("E-mail:"));
1255 wprintf("</td><td>%s</td></tr>\n", mailto);
1261 wprintf("</table></div>\n");
1267 * \brief Display a textual vCard
1268 * (Converts to a vCard object and then calls the actual display function)
1269 * Set 'full' to nonzero to display the whole card instead of a one-liner.
1270 * Or, if "storename" is non-NULL, just store the person's name in that
1271 * buffer instead of displaying the card at all.
1272 * \param vcard_source the buffer containing the vcard text
1273 * \param alpha what???
1274 * \param full should we usse all lines?
1275 * \param storename where to store???
1276 * \param msgnum Citadel message pointer
1278 void display_vcard(char *vcard_source, char alpha, int full, char *storename,
1283 char this_alpha = 0;
1285 v = vcard_load(vcard_source);
1286 if (v == NULL) return;
1288 name = vcard_get_prop(v, "n", 1, 0, 0);
1290 utf8ify_rfc822_string(name);
1292 this_alpha = buf[0];
1295 if (storename != NULL) {
1296 fetchname_parsed_vcard(v, storename);
1298 else if ( (alpha == 0)
1299 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
1300 || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
1302 display_parsed_vcard(v, full,msgnum);
1320 * I wanna SEE that message!
1322 * msgnum Message number to display
1323 * printable_view Nonzero to display a printable view
1324 * section Optional for encapsulated message/rfc822 submessage
1326 void read_message(long msgnum, int printable_view, char *section) {
1327 struct wcsession *WCC = WC;
1330 StrBuf *FoundCharset;
1331 message_summary *Msg = NULL;
1335 struct attach_link *attach_links = NULL;
1336 int num_attach_links = 0;
1337 // char mime_submessages[256] = "";
1338 char reply_references[1024] = "";
1343 char vcard_partnum[256] = "";
1344 char cal_partnum[256] = "";
1345 char *part_source = NULL;
1346 char msg4_partnum[32] = "";
1348 //// strcpy(mime_submessages, "");
1351 serv_printf("MSG4 %ld|%s", msgnum, section);
1352 StrBuf_ServGetln(Buf);
1353 if (GetServerStatus(Buf, NULL) != 1) {
1354 wprintf("<strong>");
1355 wprintf(_("ERROR:"));
1356 wprintf("</strong> %s<br />\n", &buf[4]);
1360 svputlong("MsgPrintable", printable_view);
1361 /** begin everythingamundo table */
1364 Token = NewStrBuf();
1365 Msg = (message_summary *)malloc(sizeof(message_summary));
1366 memset(Msg, 0, sizeof(message_summary));
1367 FoundCharset = NewStrBuf();
1368 while ((StrBuf_ServGetln(Buf)>=0) && !Done) {
1369 if ( (StrLength(Buf)==3) &&
1370 !strcmp(ChrPtr(Buf), "000"))
1375 wprintf(_("unexpected end of message"));
1376 wprintf(" (1)</i><br /><br />\n");
1377 wprintf("</div>\n");
1380 DestroyMessageSummary(Msg);
1381 FreeStrBuf(&FoundCharset);
1389 case 0:/* Citadel Message Headers */
1390 if (StrLength(Buf) == 0) {
1394 StrBufExtract_token(Token, Buf, 0, '=');
1395 StrBufCutLeft(Buf, StrLength(Token) + 1);
1397 lprintf(1, ":: [%s] = [%s]\n", ChrPtr(Token), ChrPtr(Buf));
1398 if (GetHash(MsgHeaderHandler, SKEY(Token), &vHdr) &&
1400 Hdr = (headereval*)vHdr;
1401 Hdr->evaluator(Msg, Buf, FoundCharset);
1402 if (Hdr->Type == 1) {
1406 else lprintf(1, "don't know how to handle message header[%s]\n", ChrPtr(Token));
1408 case 1:/* Message Mime Header */
1409 if (StrLength(Buf) == 0) {
1411 if (Msg->MsgBody.ContentType == NULL)
1412 /* end of header or no header? */
1413 Msg->MsgBody.ContentType = NewStrBufPlain(HKEY("text/plain"));
1414 /* usual end of mime header */
1418 StrBufExtract_token(Token, Buf, 0, ':');
1419 if (StrLength(Token) > 0) {
1420 StrBufCutLeft(Buf, StrLength(Token) + 1);
1421 lprintf(1, ":: [%s] = [%s]\n", ChrPtr(Token), ChrPtr(Buf));
1422 if (GetHash(MsgHeaderHandler, SKEY(Token), &vHdr) &&
1424 Hdr = (headereval*)vHdr;
1425 Hdr->evaluator(Msg, Buf, FoundCharset);
1430 case 2: /* Message Body */
1432 if (Msg->MsgBody.size_known > 0) {
1433 StrBuf_ServGetBLOB(Msg->MsgBody.Data, Msg->MsgBody.length);
1435 /// todo: check next line, if not 000, append following lines
1438 if (StrLength(Msg->MsgBody.Data) > 0)
1439 StrBufAppendBufPlain(Msg->MsgBody.Data, "\n", 1, 0);
1440 StrBufAppendBuf(Msg->MsgBody.Data, Buf, 0);
1444 StrBufAppendBuf(Msg->MsgBody.Data, Buf, 0);
1449 /* strip the bare contenttype, so we ommit charset etc. */
1450 StrBufExtract_token(Buf, Msg->MsgBody.ContentType, 0, ';');
1452 if (GetHash(MimeRenderHandler, SKEY(Buf), &vHdr) &&
1454 RenderMimeFunc Render;
1455 Render = (RenderMimeFunc)vHdr;
1456 Render(&Msg->MsgBody, NULL, FoundCharset);
1460 if (StrLength(Msg->reply_references)> 0) {
1461 /* Trim down excessively long lists of thread references. We eliminate the
1462 * second one in the list so that the thread root remains intact.
1464 int rrtok = num_tokens(ChrPtr(Msg->reply_references), '|');
1465 int rrlen = StrLength(Msg->reply_references);
1466 if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
1467 remove_token(reply_references, 1, '|');////todo
1471 /* Generate a reply-to address */
1472 if (StrLength(Msg->Rfca) > 0) {
1473 if (Msg->reply_to == NULL)
1474 Msg->reply_to = NewStrBuf();
1475 if (StrLength(Msg->from) > 0) {
1476 StrBufPrintf(Msg->reply_to, "%s <%s>", ChrPtr(Msg->from), ChrPtr(Msg->Rfca));
1479 FlushStrBuf(Msg->reply_to);
1480 StrBufAppendBuf(Msg->reply_to, Msg->Rfca, 0);
1485 if ((StrLength(Msg->OtherNode)>0) &&
1486 (strcasecmp(ChrPtr(Msg->OtherNode), serv_info.serv_nodename)) &&
1487 (strcasecmp(ChrPtr(Msg->OtherNode), serv_info.serv_humannode)) )
1489 if (Msg->reply_to == NULL)
1490 Msg->reply_to = NewStrBuf();
1491 StrBufPrintf(Msg->reply_to,
1494 ChrPtr(Msg->OtherNode));
1497 if (Msg->reply_to == NULL)
1498 Msg->reply_to = NewStrBuf();
1499 FlushStrBuf(Msg->reply_to);
1500 StrBufAppendBuf(Msg->reply_to, Msg->from, 0);
1507 DoTemplate(HKEY("view_message"), NULL, Msg, CTX_MAILSUM);
1511 //// put message renderer lookup here.
1512 ///ENDBODY: /* If there are attached submessages, display them now... */
1514 /// if ( (!IsEmptyStr(mime_submessages)) && (!section[0]) ) {
1515 /// for (i=0; i<num_tokens(mime_submessages, '|'); ++i) {
1516 /// extract_token(buf, mime_submessages, i, '|', sizeof buf);
1517 /// /** use printable_view to suppress buttons */
1518 /// wprintf("<blockquote>");
1519 /// read_message(msgnum, 1, buf);
1520 /// wprintf("</blockquote>");
1525 /* Afterwards, offer links to download attachments 'n' such */
1526 if ( (num_attach_links > 0) && (!section[0]) ) {
1527 for (i=0; i<num_attach_links; ++i) {
1528 if (strcasecmp(attach_links[i].partnum, msg4_partnum)) {
1529 wprintf("%s", attach_links[i].html);
1534 /* Handler for vCard parts */
1535 if (!IsEmptyStr(vcard_partnum)) {
1536 part_source = load_mimepart(msgnum, vcard_partnum);
1537 if (part_source != NULL) {
1539 /** If it's my vCard I can edit it */
1540 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
1541 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
1542 || (WC->wc_view == VIEW_ADDRESSBOOK)
1544 wprintf("<a href=\"edit_vcard?msgnum=%ld&partnum=%s\">",
1545 msgnum, vcard_partnum);
1546 wprintf("[%s]</a>", _("edit"));
1549 /* In all cases, display the full card */
1550 display_vcard(part_source, 0, 1, NULL,msgnum);
1554 /* Handler for calendar parts */
1555 if (!IsEmptyStr(cal_partnum)) {
1556 part_source = load_mimepart(msgnum, cal_partnum);
1557 if (part_source != NULL) {
1558 cal_process_attachment(part_source, msgnum, cal_partnum);
1567 wprintf("</div>\n");
1569 /* end everythingamundo table */
1570 if (!printable_view) {
1571 wprintf("</div>\n");
1574 if (num_attach_links > 0) {
1577 DestroyMessageSummary(Msg);
1578 FreeStrBuf(&FoundCharset);
1586 * Unadorned HTML output of an individual message, suitable
1587 * for placing in a hidden iframe, for printing, or whatever
1589 * msgnum_as_string == Message number, as a string instead of as a long int
1591 void embed_message(void) {
1594 msgnum = StrTol(WC->UrlFragment1);
1595 read_message(msgnum, 0, "");
1600 * Printable view of a message
1602 * msgnum_as_string == Message number, as a string instead of as a long int
1604 void print_message(void) {
1607 msgnum = StrTol(WC->UrlFragment1);
1608 output_headers(0, 0, 0, 0, 0, 0);
1610 hprintf("Content-type: text/html\r\n"
1612 "Connection: close\r\n",
1616 wprintf("\r\n<html>\n<head><title>");
1617 escputs(WC->wc_fullname);
1618 wprintf("</title></head>\n"
1619 "<body onLoad=\" window.print(); window.close(); \">\n"
1622 read_message(msgnum, 1, "");
1624 wprintf("\n</body></html>\n\n");
1629 * Mobile browser view of message
1631 * @param msg_num_as_string Message number as a string instead of as a long int
1633 void mobile_message_view(void) {
1635 msgnum = StrTol(WC->UrlFragment1);
1636 output_headers(1, 0, 0, 0, 0, 1);
1638 do_template("msgcontrols", NULL);
1639 read_message(msgnum,1, "");
1644 * \brief Display a message's headers
1646 * \param msgnum_as_string Message number, as a string instead of as a long int
1648 void display_headers(void) {
1652 msgnum = StrTol(WC->UrlFragment1);
1653 output_headers(0, 0, 0, 0, 0, 0);
1655 hprintf("Content-type: text/plain\r\n"
1657 "Connection: close\r\n",
1661 serv_printf("MSG2 %ld|3", msgnum);
1662 serv_getln(buf, sizeof buf);
1663 if (buf[0] == '1') {
1664 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1665 wprintf("%s\n", buf);
1675 * \brief Read message in simple, JavaScript-embeddable form for 'forward'
1676 * or 'reply quoted' operations.
1678 * NOTE: it is VITALLY IMPORTANT that we output no single-quotes or linebreaks
1679 * in this function. Doing so would throw a JavaScript error in the
1680 * 'supplied text' argument to the editor.
1682 * \param msgnum Message number of the message we want to quote
1683 * \param forward_attachments Nonzero if we want attachments to be forwarded
1685 void pullquote_message(long msgnum, int forward_attachments, int include_headers) {
1687 char mime_partnum[256];
1688 char mime_filename[256];
1689 char mime_content_type[256];
1690 char mime_charset[256];
1691 char mime_disposition[256];
1693 char *attachments = NULL;
1695 int num_attachments = 0;
1696 struct wc_attachment *att, *aptr;
1697 char m_subject[1024];
1704 int format_type = 0;
1709 iconv_t ic = (iconv_t)(-1) ;
1710 char *ibuf; /**< Buffer of characters to be converted */
1711 char *obuf; /**< Buffer for converted characters */
1712 size_t ibuflen; /**< Length of input buffer */
1713 size_t obuflen; /**< Length of output buffer */
1714 char *osav; /**< Saved pointer to output buffer */
1720 strcpy(reply_to, "");
1721 strcpy(mime_content_type, "text/plain");
1722 strcpy(mime_charset, "us-ascii");
1724 serv_printf("MSG4 %ld", msgnum);
1725 serv_getln(buf, sizeof buf);
1726 if (buf[0] != '1') {
1727 wprintf(_("ERROR:"));
1728 wprintf("%s<br />", &buf[4]);
1732 strcpy(m_subject, "");
1734 while (serv_getln(buf, sizeof buf), strcasecmp(buf, "text")) {
1735 if (!strcmp(buf, "000")) {
1736 wprintf("%s (3)", _("unexpected end of message"));
1739 if (include_headers) {
1740 if (!strncasecmp(buf, "nhdr=yes", 8))
1744 if (!strncasecmp(buf, "type=", 5))
1745 format_type = atoi(&buf[5]);
1746 if (!strncasecmp(buf, "from=", 5)) {
1747 strcpy(from, &buf[5]);
1748 wprintf(_("from "));
1749 utf8ify_rfc822_string(from);
1752 if (!strncasecmp(buf, "subj=", 5)) {
1753 strcpy(m_subject, &buf[5]);
1755 if ((!strncasecmp(buf, "hnod=", 5))
1756 && (strcasecmp(&buf[5], serv_info.serv_humannode))) {
1757 wprintf("(%s) ", &buf[5]);
1759 if ((!strncasecmp(buf, "room=", 5))
1760 && (strcasecmp(&buf[5], WC->wc_roomname))
1761 && (!IsEmptyStr(&buf[5])) ) {
1763 wprintf("%s> ", &buf[5]);
1765 if (!strncasecmp(buf, "rfca=", 5)) {
1766 strcpy(rfca, &buf[5]);
1771 if (!strncasecmp(buf, "node=", 5)) {
1772 strcpy(node, &buf[5]);
1773 if ( ((WC->room_flags & QR_NETWORK)
1774 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
1775 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
1776 && (IsEmptyStr(rfca))
1778 wprintf("@%s ", &buf[5]);
1781 if (!strncasecmp(buf, "rcpt=", 5)) {
1783 strcpy(to, &buf[5]);
1784 utf8ify_rfc822_string(to);
1787 if (!strncasecmp(buf, "time=", 5)) {
1788 webcit_fmt_date(now, atol(&buf[5]), 0);
1789 wprintf("%s ", now);
1794 * Save attachment info for later. We can't start downloading them
1795 * yet because we're in the middle of a server transaction.
1797 if (!strncasecmp(buf, "part=", 5)) {
1798 ptr = malloc( (strlen(buf) + ((attachments != NULL) ? strlen(attachments) : 0)) ) ;
1801 sprintf(ptr, "%s%s\n",
1802 ((attachments != NULL) ? attachments : ""),
1807 lprintf(9, "attachments=<%s>\n", attachments);
1813 if (include_headers) {
1816 utf8ify_rfc822_string(m_subject);
1817 if (!IsEmptyStr(m_subject)) {
1818 wprintf(_("Subject:"));
1820 msgescputs(m_subject);
1831 * Learn the content type
1833 strcpy(mime_content_type, "text/plain");
1834 while (serv_getln(buf, sizeof buf), (!IsEmptyStr(buf))) {
1835 if (!strcmp(buf, "000")) {
1836 wprintf("%s (4)", _("unexpected end of message"));
1839 if (!strncasecmp(buf, "Content-type: ", 14)) {
1841 safestrncpy(mime_content_type, &buf[14],
1842 sizeof(mime_content_type));
1843 for (i=0; i<strlen(mime_content_type); ++i) {
1844 if (!strncasecmp(&mime_content_type[i], "charset=", 8)) {
1845 safestrncpy(mime_charset, &mime_content_type[i+8],
1846 sizeof mime_charset);
1849 len = strlen(mime_content_type);
1850 for (i=0; i<len; ++i) {
1851 if (mime_content_type[i] == ';') {
1852 mime_content_type[i] = 0;
1856 len = strlen(mime_charset);
1857 for (i=0; i<len; ++i) {
1858 if (mime_charset[i] == ';') {
1859 mime_charset[i] = 0;
1866 /** Set up a character set conversion if we need to (and if we can) */
1868 if ( (strcasecmp(mime_charset, "us-ascii"))
1869 && (strcasecmp(mime_charset, "UTF-8"))
1870 && (strcasecmp(mime_charset, ""))
1872 ctdl_iconv_open("UTF-8", mime_charset, &ic);
1873 if (ic == (iconv_t)(-1) ) {
1874 lprintf(5, "%s:%d iconv_open(%s, %s) failed: %s\n",
1875 __FILE__, __LINE__, "UTF-8", mime_charset, strerror(errno));
1880 /** Messages in legacy Citadel variformat get handled thusly... */
1881 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
1885 /* Boring old 80-column fixed format text gets handled this way... */
1886 else if (!strcasecmp(mime_content_type, "text/plain")) {
1887 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1890 if ((len > 0) && (buf[len-1] == '\n')) buf[--len] = 0;
1891 if ((len > 0) && (buf[len-1] == '\r')) buf[--len] = 0;
1894 if (ic != (iconv_t)(-1) ) {
1898 obuf = (char *) malloc(obuflen);
1900 iconv(ic, &ibuf, &ibuflen, &obuf, &obuflen);
1901 osav[SIZ-obuflen] = 0;
1902 safestrncpy(buf, osav, sizeof buf);
1908 while ((!IsEmptyStr(buf)) && (isspace(buf[len - 1])))
1911 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) )) {
1912 wprintf("<blockquote>");
1914 } else if ((bq == 1) &&
1915 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) ) {
1916 wprintf("</blockquote>");
1920 url(buf, sizeof(buf));
1922 wprintf("</tt><br />");
1924 wprintf("</i><br />");
1927 /** HTML just gets escaped and stuffed back into the editor */
1928 else if (!strcasecmp(mime_content_type, "text/html")) {
1929 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
1933 }//// TODO: charset? utf8?
1935 /** Unknown weirdness ... don't know how to handle this content type */
1937 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) { }
1941 /** end of body handler */
1944 * If there were attachments, we have to download them and insert them
1945 * into the attachment chain for the forwarded message we are composing.
1947 if ( (forward_attachments) && (num_attachments) ) {
1948 for (i=0; i<num_attachments; ++i) {
1949 extract_token(buf, attachments, i, '\n', sizeof buf);
1950 extract_token(mime_filename, buf, 1, '|', sizeof mime_filename);
1951 extract_token(mime_partnum, buf, 2, '|', sizeof mime_partnum);
1952 extract_token(mime_disposition, buf, 3, '|', sizeof mime_disposition);
1953 extract_token(mime_content_type, buf, 4, '|', sizeof mime_content_type);
1954 mime_length = extract_int(buf, 5);
1957 * tracing ... uncomment if necessary
1960 lprintf(9, "fwd filename: %s\n", mime_filename);
1961 lprintf(9, "fwd partnum : %s\n", mime_partnum);
1962 lprintf(9, "fwd conttype: %s\n", mime_content_type);
1963 lprintf(9, "fwd dispose : %s\n", mime_disposition);
1964 lprintf(9, "fwd length : %d\n", mime_length);
1966 if ( (!strcasecmp(mime_disposition, "inline"))
1967 || (!strcasecmp(mime_disposition, "attachment")) ) {
1969 /* Create an attachment struct from this mime part... */
1970 att = malloc(sizeof(struct wc_attachment));
1971 memset(att, 0, sizeof(struct wc_attachment));
1972 att->length = mime_length;
1973 strcpy(att->content_type, mime_content_type);
1974 strcpy(att->filename, mime_filename);
1976 att->data = load_mimepart(msgnum, mime_partnum);
1978 /* And add it to the list. */
1979 if (WC->first_attachment == NULL) {
1980 WC->first_attachment = att;
1983 aptr = WC->first_attachment;
1984 while (aptr->next != NULL) aptr = aptr->next;
1993 if (ic != (iconv_t)(-1) ) {
1998 if (attachments != NULL) {
2006 void EvaluateMimePart(message_summary *Sum, StrBuf *Buf)
2009 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
2010 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
2011 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
2012 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
2013 mime_length = extract_int(&buf[5], 5);
2015 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
2016 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
2017 strcpy(vcard_partnum, mime_partnum);
2022 message_summary *ReadOneMessageSummary(StrBuf *RawMessage, const char *DefaultSubject, long MsgNum)
2025 MsgPartEvaluatorFunc Eval;
2026 message_summary *Msg;
2035 serv_printf("MSG0 %ld|1", MsgNum); /* ask for headers only */
2037 StrBuf_ServGetln(Buf);
2038 if (GetServerStatus(Buf, NULL) == 1) {
2043 Msg = (message_summary*)malloc(sizeof(message_summary));
2044 memset(Msg, 0, sizeof(message_summary));
2045 while (len = StrBuf_ServGetln(Buf),
2047 strcmp(ChrPtr(Buf), "000")== 0)){
2049 ebuf = strchr(ChrPtr(Buf), '=');
2051 if (GetHash(MsgEvaluators, buf, nBuf, &vEval) && vEval != NULL) {
2052 Eval = (MsgPartEvaluatorFunc) vEval;
2053 StrBufCutLeft(Buf, nBuf + 1);
2056 else lprintf(1, "Don't know how to handle Message Headerline [%s]", ChrPtr(Buf));
2063 * \brief display the adressbook overview
2064 * \param msgnum the citadel message number
2065 * \param alpha what????
2067 void display_addressbook(long msgnum, char alpha) {
2069 /* char mime_partnum[SIZ]; */
2070 /* char mime_filename[SIZ]; */
2071 /* char mime_content_type[SIZ]; */
2072 ///char mime_disposition[SIZ];
2074 char vcard_partnum[SIZ];
2075 char *vcard_source = NULL;
2076 message_summary summ;////TODO: this will leak
2078 memset(&summ, 0, sizeof(summ));
2079 ///safestrncpy(summ.subj, _("(no subject)"), sizeof summ.subj);
2080 ///Load Message headers
2082 if (!IsEmptyStr(vcard_partnum)) {
2083 vcard_source = load_mimepart(msgnum, vcard_partnum);
2084 if (vcard_source != NULL) {
2086 /** Display the summary line */
2087 display_vcard(vcard_source, alpha, 0, NULL,msgnum);
2089 /** If it's my vCard I can edit it */
2090 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
2091 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))
2092 || (WC->wc_view == VIEW_ADDRESSBOOK)
2094 wprintf("<a href=\"edit_vcard?"
2095 "msgnum=%ld&partnum=%s\">",
2096 msgnum, vcard_partnum);
2097 wprintf("[%s]</a>", _("edit"));
2109 * \brief If it's an old "Firstname Lastname" style record, try to convert it.
2110 * \param namebuf name to analyze, reverse if nescessary
2112 void lastfirst_firstlast(char *namebuf) {
2113 char firstname[SIZ];
2117 if (namebuf == NULL) return;
2118 if (strchr(namebuf, ';') != NULL) return;
2120 i = num_tokens(namebuf, ' ');
2123 extract_token(lastname, namebuf, i-1, ' ', sizeof lastname);
2124 remove_token(namebuf, i-1, ' ');
2125 strcpy(firstname, namebuf);
2126 sprintf(namebuf, "%s; %s", lastname, firstname);
2130 * \brief fetch what??? name
2131 * \param msgnum the citadel message number
2132 * \param namebuf where to put the name in???
2134 void fetch_ab_name(message_summary *Msg, char *namebuf) {
2136 char mime_partnum[SIZ];
2137 char mime_filename[SIZ];
2138 char mime_content_type[SIZ];
2139 char mime_disposition[SIZ];
2141 char vcard_partnum[SIZ];
2142 char *vcard_source = NULL;
2144 message_summary summ;/// TODO this will lak
2146 if (namebuf == NULL) return;
2147 strcpy(namebuf, "");
2149 memset(&summ, 0, sizeof(summ));
2150 //////safestrncpy(summ.subj, "(no subject)", sizeof summ.subj);
2152 sprintf(buf, "MSG0 %ld|0", Msg->msgnum); /** unfortunately we need the mime info now */
2154 serv_getln(buf, sizeof buf);
2155 if (buf[0] != '1') return;
2157 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
2158 if (!strncasecmp(buf, "part=", 5)) {
2159 extract_token(mime_filename, &buf[5], 1, '|', sizeof mime_filename);
2160 extract_token(mime_partnum, &buf[5], 2, '|', sizeof mime_partnum);
2161 extract_token(mime_disposition, &buf[5], 3, '|', sizeof mime_disposition);
2162 extract_token(mime_content_type, &buf[5], 4, '|', sizeof mime_content_type);
2163 mime_length = extract_int(&buf[5], 5);
2165 if ( (!strcasecmp(mime_content_type, "text/x-vcard"))
2166 || (!strcasecmp(mime_content_type, "text/vcard")) ) {
2167 strcpy(vcard_partnum, mime_partnum);
2173 if (!IsEmptyStr(vcard_partnum)) {
2174 vcard_source = load_mimepart(Msg->msgnum, vcard_partnum);
2175 if (vcard_source != NULL) {
2177 /* Grab the name off the card */
2178 display_vcard(vcard_source, 0, 0, namebuf, Msg->msgnum);
2184 lastfirst_firstlast(namebuf);
2186 len = strlen(namebuf);
2187 for (i=0; i<len; ++i) {
2188 if (namebuf[i] != ';') return;
2190 strcpy(namebuf, _("(no name)"));
2196 * \brief Record compare function for sorting address book indices
2197 * \param ab1 adressbook one
2198 * \param ab2 adressbook two
2200 int abcmp(const void *ab1, const void *ab2) {
2202 (((const struct addrbookent *)ab1)->ab_name),
2203 (((const struct addrbookent *)ab2)->ab_name)
2209 * \brief Helper function for do_addrbook_view()
2210 * Converts a name into a three-letter tab label
2211 * \param tabbuf the tabbuffer to add name to
2212 * \param name the name to add to the tabbuffer
2214 void nametab(char *tabbuf, long len, char *name) {
2215 stresc(tabbuf, len, name, 0, 0);
2216 tabbuf[0] = toupper(tabbuf[0]);
2217 tabbuf[1] = tolower(tabbuf[1]);
2218 tabbuf[2] = tolower(tabbuf[2]);
2224 * \brief Render the address book using info we gathered during the scan
2225 * \param addrbook the addressbook to render
2226 * \param num_ab the number of the addressbook
2228 void do_addrbook_view(struct addrbookent *addrbook, int num_ab) {
2232 static int NAMESPERPAGE = 60;
2235 char tabfirst_label[64];
2237 char tablast_label[64];
2238 char this_tablabel[64];
2243 wprintf("<br /><br /><br /><div align=\"center\"><i>");
2244 wprintf(_("This address book is empty."));
2245 wprintf("</i></div>\n");
2250 qsort(addrbook, num_ab, sizeof(struct addrbookent), abcmp);
2253 num_pages = (num_ab / NAMESPERPAGE) + 1;
2255 tablabels = malloc(num_pages * sizeof (char *));
2256 if (tablabels == NULL) {
2257 wprintf("<br /><br /><br /><div align=\"center\"><i>");
2258 wprintf(_("An internal error has occurred."));
2259 wprintf("</i></div>\n");
2263 for (i=0; i<num_pages; ++i) {
2264 tabfirst = i * NAMESPERPAGE;
2265 tablast = tabfirst + NAMESPERPAGE - 1;
2266 if (tablast > (num_ab - 1)) tablast = (num_ab - 1);
2267 nametab(tabfirst_label, 64, addrbook[tabfirst].ab_name);
2268 nametab(tablast_label, 64, addrbook[tablast].ab_name);
2269 sprintf(this_tablabel, "%s - %s", tabfirst_label, tablast_label);
2270 tablabels[i] = strdup(this_tablabel);
2273 tabbed_dialog(num_pages, tablabels);
2276 for (i=0; i<num_ab; ++i) {
2278 if ((i / NAMESPERPAGE) != page) { /* New tab */
2279 page = (i / NAMESPERPAGE);
2281 wprintf("</tr></table>\n");
2282 end_tab(page-1, num_pages);
2284 begin_tab(page, num_pages);
2285 wprintf("<table border=0 cellspacing=0 cellpadding=3 width=100%%>\n");
2289 if ((displayed % 4) == 0) {
2290 if (displayed > 0) {
2294 wprintf("<tr bgcolor=\"#%s\">",
2295 (bg ? "DDDDDD" : "FFFFFF")
2301 wprintf("<a href=\"readfwd?startmsg=%ld?is_singlecard=1",
2302 addrbook[i].ab_msgnum);
2303 wprintf("?maxmsgs=1?is_summary=0?alpha=%s\">", bstr("alpha"));
2304 vcard_n_prettyize(addrbook[i].ab_name);
2305 escputs(addrbook[i].ab_name);
2306 wprintf("</a></td>\n");
2310 /* Placeholders for empty columns at end */
2311 if ((num_ab % 4) != 0) {
2312 for (i=0; i<(4-(num_ab % 4)); ++i) {
2313 wprintf("<td> </td>");
2317 wprintf("</tr></table>\n");
2318 end_tab((num_pages-1), num_pages);
2320 begin_tab(num_pages, num_pages);
2321 /* FIXME there ought to be something here */
2322 end_tab(num_pages, num_pages);
2324 for (i=0; i<num_pages; ++i) {
2333 * load message pointers from the server for a "read messages" operation
2335 * servcmd: the citadel command to send to the citserver
2336 * with_headers: also include some of the headers with the message numbers (more expensive)
2338 int load_msg_ptrs(char *servcmd, int with_headers)
2340 StrBuf* FoundCharset = NULL;
2341 struct wcsession *WCC = WC;
2342 message_summary *Msg;
2345 ///time_t datestamp;
2346 //char fullname[128];
2347 //char nodename[128];
2348 //char inetaddr[128];
2349 //char subject[1024];
2356 ////int num_summ_alloc = 0;
2358 if (WCC->summ != NULL) {
2359 if (WCC->summ != NULL)
2360 DeleteHash(&WCC->summ);
2362 WCC->summ = NewHash(1, Flathash);
2364 maxload = 1000;/// TODO
2368 StrBuf_ServGetln(Buf);
2369 if (GetServerStatus(Buf, NULL) != 1) {
2373 // TODO if (with_headers) { //// TODO: Have Attachments?
2375 while (len = StrBuf_ServGetln(Buf),
2377 strcmp(ChrPtr(Buf), "000")!= 0))
2379 if (nummsgs < maxload) {
2380 Msg = (message_summary*)malloc(sizeof(message_summary));
2381 memset(Msg, 0, sizeof(message_summary));
2383 Msg->msgnum = StrBufExtract_long(Buf, 0, '|');
2384 Msg->date = StrBufExtract_long(Buf, 1, '|');
2386 Msg->from = NewStrBufPlain(NULL, StrLength(Buf));
2387 StrBufExtract_token(Buf2, Buf, 2, '|');
2388 if (StrLength(Buf2) != 0) {
2389 /** Handle senders with RFC2047 encoding */
2390 StrBuf_RFC822_to_Utf8(Msg->from, Buf2, WCC->DefaultCharset, FoundCharset);
2394 StrBufExtract_token(Buf2, Buf, 3, '|');
2395 if ((StrLength(Buf2) !=0 ) &&
2396 ( ((WCC->room_flags & QR_NETWORK)
2397 || ((strcasecmp(ChrPtr(Buf2), serv_info.serv_nodename)
2398 && (strcasecmp(ChrPtr(Buf2), serv_info.serv_fqdn)))))))
2400 StrBufAppendBufPlain(Msg->from, HKEY(" @ "), 0);
2401 StrBufAppendBuf(Msg->from, Buf2, 0);
2405 StrBufExtract_token(Msg->inetaddr, Buf, 4, '|');
2408 Msg->subj = NewStrBufPlain(NULL, StrLength(Buf));
2409 StrBufExtract_token(Buf2, Buf, 5, '|');
2410 if (StrLength(Buf2) == 0)
2411 StrBufAppendBufPlain(Msg->subj, _("(no subj)"), 0, -1);
2413 StrBuf_RFC822_to_Utf8(Msg->subj, Buf2, WCC->DefaultCharset, FoundCharset);
2414 if ((StrLength(Msg->subj) > 75) &&
2415 (StrBuf_Utf8StrLen(Msg->subj) > 75)) {
2416 StrBuf_Utf8StrCut(Msg->subj, 72);
2417 StrBufAppendBufPlain(Msg->subj, HKEY("..."), 0);
2422 if ((StrLength(Msg->from) > 25) &&
2423 (StrBuf_Utf8StrLen(Msg->from) > 25)) {
2424 StrBuf_Utf8StrCut(Msg->from, 23);
2425 StrBufAppendBufPlain(Msg->from, HKEY("..."), 0);
2427 Put(WCC->summ, (const char*)&Msg->msgnum, sizeof(Msg->msgnum), Msg, DestroyMessageSummary);
2442 * command loop for reading messages
2444 * Set oper to "readnew" or "readold" or "readfwd" or "headers"
2446 void readloop(char *oper)
2449 message_summary *Msg;
2458 long *displayed_msgs = NULL;
2459 int num_displayed = 0;
2461 int is_addressbook = 0;
2462 int is_singlecard = 0;
2463 int is_calendar = 0;
2464 struct calview calv;
2469 int lowest_displayed = (-1);
2470 int highest_displayed = 0;
2471 struct addrbookent *addrbook = NULL;
2473 const StrBuf *sortby = NULL;
2475 int SortBy = eRDate;
2476 const StrBuf *sortpref_value;
2477 int bbs_reverse = 0;
2478 struct wcsession *WCC = WC; /* This is done to make it run faster; WC is a function */
2480 const char *HashKey;
2483 if (WCC->wc_view == VIEW_WIKI) {
2484 sprintf(buf, "wiki?room=%s&page=home", WCC->wc_roomname);
2489 startmsg = lbstr("startmsg");
2490 maxmsgs = ibstr("maxmsgs");
2491 is_summary = (ibstr("is_summary") && !WCC->is_mobile);
2492 if (maxmsgs == 0) maxmsgs = DEFAULT_MAXMSGS;
2494 sortpref_value = get_room_pref("sort");
2496 sortby = sbstr("sortby");
2497 if ( (!IsEmptyStr(ChrPtr(sortby))) &&
2498 (strcasecmp(ChrPtr(sortby), ChrPtr(sortpref_value)) != 0)) {
2499 set_room_pref("sort", NewStrBufDup(sortby), 1);
2500 sortpref_value = NULL;
2501 sortpref_value = sortby;
2504 SortBy = StrToESort(sortpref_value);
2505 /* message board sort */
2506 if (SortBy == eReverse) {
2513 output_headers(1, 1, 1, 0, 0, 0);
2516 * When in summary mode, always show ALL messages instead of just
2517 * new or old. Otherwise, show what the user asked for.
2519 if (!strcmp(oper, "readnew")) {
2520 strcpy(cmd, "MSGS NEW");
2522 else if (!strcmp(oper, "readold")) {
2523 strcpy(cmd, "MSGS OLD");
2525 else if (!strcmp(oper, "do_search")) {
2526 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2529 strcpy(cmd, "MSGS ALL");
2532 if ((WCC->wc_view == VIEW_MAILBOX) && (maxmsgs > 1) && !WCC->is_mobile) {
2534 if (!strcmp(oper, "do_search")) {
2535 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2538 strcpy(cmd, "MSGS ALL");
2542 if ((WCC->wc_view == VIEW_ADDRESSBOOK) && (maxmsgs > 1)) {
2544 if (!strcmp(oper, "do_search")) {
2545 snprintf(cmd, sizeof(cmd), "MSGS SEARCH|%s", bstr("query"));
2548 strcpy(cmd, "MSGS ALL");
2553 if (is_summary) { /**< fetch header summary */
2554 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
2555 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2556 (!strcmp(oper, "do_search") ? bstr("query") : "")
2561 if (WCC->is_mobile) {
2563 snprintf(cmd, sizeof(cmd), "MSGS %s|%s||1",
2564 (!strcmp(oper, "do_search") ? "SEARCH" : "ALL"),
2565 (!strcmp(oper, "do_search") ? bstr("query") : "")
2571 * Are we doing a summary view? If so, we need to know old messages
2572 * and new messages, so we can do that pretty boldface thing for the
2575 strcpy(old_msgs, "");
2576 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR) || WCC->is_mobile){
2578 serv_getln(buf, sizeof buf);
2579 if (buf[0] == '2') {
2580 strcpy(old_msgs, &buf[4]);
2584 is_singlecard = ibstr("is_singlecard");
2586 if (WCC->wc_default_view == VIEW_CALENDAR) { /**< calendar */
2588 strcpy(cmd, "MSGS ALL|||1");
2590 parse_calendar_view_request(&calv);
2592 if (WCC->wc_default_view == VIEW_TASKS) { /**< tasks */
2594 strcpy(cmd, "MSGS ALL");
2597 if (WCC->wc_default_view == VIEW_NOTES) { /**< notes */
2599 strcpy(cmd, "MSGS ALL");
2604 wprintf("<div id=\"new_notes_here\"></div>\n");
2607 nummsgs = load_msg_ptrs(cmd, (is_summary || WCC->is_mobile));
2610 if ((!is_tasks) && (!is_calendar) && (!is_notes) && (!is_addressbook)) {
2611 wprintf("<div align=\"center\"><br /><em>");
2612 if (!strcmp(oper, "readnew")) {
2613 wprintf(_("No new messages."));
2614 } else if (!strcmp(oper, "readold")) {
2615 wprintf(_("No old messages."));
2617 wprintf(_("No messages here."));
2619 wprintf("</em><br /></div>\n");
2625 if ((is_summary) || (WCC->wc_default_view == VIEW_CALENDAR) || WCC->is_mobile){
2627 message_summary *Msg;
2629 at = GetNewHashPos();
2630 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
2631 /** Are you a new message, or an old message? */
2632 Msg = (message_summary*) vMsg;
2634 if (is_msg_in_mset(old_msgs, Msg->msgnum)) {
2645 if (startmsg == 0L) {
2647 startmsg = WCC->msgarr[(nummsgs >= maxmsgs) ? (nummsgs - maxmsgs) : 0];
2650 startmsg = WCC->msgarr[0];
2654 if (is_summary || WCC->is_mobile) {
2655 SortByPayload(WCC->summ, SortFuncs[SortBy]);
2660 wprintf("<script language=\"javascript\" type=\"text/javascript\">"
2661 " document.onkeydown = CtdlMsgListKeyPress; "
2662 " if (document.layers) { "
2663 " document.captureEvents(Event.KEYPRESS); "
2668 /** note that Date and Delete are now in the same column */
2669 wprintf("<div id=\"message_list_hdr\">"
2670 "<div class=\"fix_scrollbar_bug\">"
2671 "<table cellspacing=0 style=\"width:100%%\">"
2674 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"
2675 "<th width=%d%%>%s <a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=%s\"><img border=\"0\" src=\"%s\" /></a> </th>\n"
2676 "<th width=%d%%>%s <a href=\"readfwd?startmsg=1?maxmsgs=9999999?is_summary=1?sortby=%s\"><img border=\"0\" src=\"%s\" /></a> \n"
2678 "<input type=\"submit\" name=\"delete_button\" id=\"delbutton\" "
2679 " onClick=\"CtdlDeleteSelectedMessages(event)\" "
2686 SortByStrings[SubjectInvertSortString[SortBy]],
2687 SortIcons[SortSubjectToIcon[SortBy]],
2688 SENDER_COL_WIDTH_PCT,
2690 SortByStrings[SenderInvertSortString[SortBy]],
2691 SortIcons[SortSenderToIcon[SortBy]],
2692 DATE_PLUS_BUTTONS_WIDTH_PCT,
2694 SortByStrings[DateInvertSortString[SortBy]],
2695 SortIcons[SortDateToIcon[SortBy]],
2698 wprintf("</table></div></div>\n");
2699 wprintf("<div id=\"message_list\">"
2701 "<div class=\"fix_scrollbar_bug\">\n"
2702 "<table class=\"mailbox_summary\" id=\"summary_headers\" "
2703 "cellspacing=0 style=\"width:100%%;-moz-user-select:none;\">"
2705 } else if (WCC->is_mobile) {
2706 wprintf("<div id=\"message_list\">");
2711 * Set the "is_bbview" variable if it appears that we are looking at
2712 * a classic bulletin board view.
2714 if ((!is_tasks) && (!is_calendar) && (!is_addressbook)
2715 && (!is_notes) && (!is_singlecard) && (!is_summary)) {
2720 * If we're not currently looking at ALL requested
2721 * messages, then display the selector bar
2724 /** begin bbview scroller */
2725 wprintf("<form name=\"msgomatictop\" class=\"selector_top\" > \n <p>");
2726 wprintf(_("Reading #"));//// TODO this isn't used, should it? : , lowest_displayed, highest_displayed);
2728 wprintf("<select name=\"whichones\" size=\"1\" "
2729 "OnChange=\"location.href=msgomatictop.whichones.options"
2730 "[selectedIndex].value\">\n");
2733 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2735 lo = b - maxmsgs + 2;
2737 wprintf("<option %s value="
2742 "%d-%d</option> \n",
2743 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2752 for (b=0; b<nummsgs; b = b + maxmsgs) {
2754 hi = b + maxmsgs + 1;
2755 if (hi > nummsgs) hi = nummsgs;
2756 wprintf("<option %s value="
2761 "%d-%d</option> \n",
2762 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
2771 wprintf("<option value=\"%s?startmsg=%ld"
2772 "&maxmsgs=9999999&is_summary=%d\">",
2774 WCC->msgarr[0], is_summary);
2776 wprintf("</option>");
2777 wprintf("</select> ");
2778 wprintf(_("of %d messages."), nummsgs);
2780 /** forward/reverse */
2781 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2782 "OnChange=\"location.href='%s?sortby=forward'\"",
2783 (bbs_reverse ? "" : "checked"),
2787 wprintf(_("oldest to newest"));
2788 wprintf(" ");
2790 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2791 "OnChange=\"location.href='%s?sortby=reverse'\"",
2792 (bbs_reverse ? "checked" : ""),
2796 wprintf(_("newest to oldest"));
2799 wprintf("</p></form>\n");
2800 /** end bbview scroller */
2803 at = GetNewHashPos();
2804 while (GetNextHashPos(WCC->summ, at, &HKLen, &HashKey, &vMsg)) {
2805 Msg = (message_summary*) vMsg;
2806 if ((Msg->msgnum >= startmsg) && (num_displayed < maxmsgs)) {
2808 /** Display the message */
2810 DoTemplate(HKEY("section_mailsummary"), NULL, Msg, CTX_MAILSUM);
2812 else if (is_addressbook) {
2813 fetch_ab_name(Msg, buf);
2815 addrbook = realloc(addrbook,
2816 (sizeof(struct addrbookent) * num_ab) );
2817 safestrncpy(addrbook[num_ab-1].ab_name, buf,
2818 sizeof(addrbook[num_ab-1].ab_name));
2819 addrbook[num_ab-1].ab_msgnum = Msg->msgnum;
2821 else if (is_calendar) {
2822 load_calendar_item(Msg, Msg->is_new, &calv);
2824 else if (is_tasks) {
2825 display_task(Msg, Msg->is_new);
2827 else if (is_notes) {
2828 display_note(Msg, Msg->is_new);
2829 } else if (WCC->is_mobile) {
2830 DoTemplate(HKEY("section_mailsummary"), NULL, Msg, CTX_MAILSUM);
2833 if (displayed_msgs == NULL) {
2834 displayed_msgs = malloc(sizeof(long) *
2835 (maxmsgs<nummsgs ? maxmsgs : nummsgs));
2837 displayed_msgs[num_displayed] = Msg->msgnum;
2840 if (lowest_displayed < 0) lowest_displayed = a;
2841 highest_displayed = a;
2849 if (displayed_msgs != NULL) {
2851 qsort(displayed_msgs, num_displayed, sizeof(long), longcmp_r);
2854 /** if we do a split bbview in the future, begin messages div here */
2856 for (a=0; a<num_displayed; ++a) {
2857 read_message(displayed_msgs[a], 0, "");
2860 /** if we do a split bbview in the future, end messages div here */
2862 free(displayed_msgs);
2863 displayed_msgs = NULL;
2868 "</div>\n"); /**< end of 'fix_scrollbar_bug' div */
2869 wprintf("</div>"); /**< end of 'message_list' div */
2871 /** Here's the grab-it-to-resize-the-message-list widget */
2872 wprintf("<div id=\"resize_msglist\" "
2873 "onMouseDown=\"CtdlResizeMsgListMouseDown(event)\">"
2874 "<div class=\"fix_scrollbar_bug\"> <hr>"
2878 wprintf("<div id=\"preview_pane\">"); /**< The preview pane will initially be empty */
2879 } else if (WCC->is_mobile) {
2884 * Bump these because although we're thinking in zero base, the user
2885 * is a drooling idiot and is thinking in one base.
2888 ++highest_displayed;
2891 * If we're not currently looking at ALL requested
2892 * messages, then display the selector bar
2895 /** begin bbview scroller */
2896 wprintf("<form name=\"msgomatic\" class=\"selector_bottom\" > \n <p>");
2897 wprintf(_("Reading #")); /// TODO: this isn't used: , lowest_displayed, highest_displayed);
2899 wprintf("<select name=\"whichones\" size=\"1\" "
2900 "OnChange=\"location.href=msgomatic.whichones.options"
2901 "[selectedIndex].value\">\n");
2904 for (b=nummsgs-1; b>=0; b = b - maxmsgs) {
2906 lo = b - maxmsgs + 2;
2908 wprintf("<option %s value="
2913 "%d-%d</option> \n",
2914 ((WCC->msgarr[lo-1] == startmsg) ? "selected" : ""),
2923 for (b=0; b<nummsgs; b = b + maxmsgs) {
2925 hi = b + maxmsgs + 1;
2926 if (hi > nummsgs) hi = nummsgs;
2927 wprintf("<option %s value="
2932 "%d-%d</option> \n",
2933 ((WCC->msgarr[b] == startmsg) ? "selected" : ""),
2942 wprintf("<option value=\"%s&startmsg=%ld"
2943 "&maxmsgs=9999999&is_summary=%d\">",
2945 WCC->msgarr[0], is_summary);
2947 wprintf("</option>");
2948 wprintf("</select> ");
2949 wprintf(_("of %d messages."), nummsgs);
2951 /** forward/reverse */
2952 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2953 "OnChange=\"location.href='%s&sortby=forward'\"",
2954 (bbs_reverse ? "" : "checked"),
2958 wprintf(_("oldest to newest"));
2959 wprintf(" ");
2960 wprintf("<input type=\"radio\" %s name=\"direction\" value=\"\""
2961 "OnChange=\"location.href='%s&sortby=reverse'\"",
2962 (bbs_reverse ? "checked" : ""),
2966 wprintf(_("newest to oldest"));
2969 wprintf("</p></form>\n");
2970 /** end bbview scroller */
2975 do_tasks_view(); /** Render the task list */
2979 render_calendar_view(&calv);
2982 if (is_addressbook) {
2983 do_addrbook_view(addrbook, num_ab); /** Render the address book */
2986 /** Note: wDumpContent() will output one additional </div> tag. */
2987 wprintf("</div>\n"); /** end of 'content' div */
2990 /** free the summary */
2991 if (WCC->summ != NULL) {
2992 DeleteHash(&WCC->summ);
2994 if (addrbook != NULL) free(addrbook);
2999 * Back end for post_message()
3000 * ... this is where the actual message gets transmitted to the server.
3002 void post_mime_to_server(void) {
3003 char top_boundary[SIZ];
3004 char alt_boundary[SIZ];
3005 int is_multipart = 0;
3007 struct wc_attachment *att;
3009 size_t encoded_length;
3010 size_t encoded_strlen;
3011 char *txtmail = NULL;
3013 sprintf(top_boundary, "Citadel--Multipart--%s--%04x--%04x",
3014 serv_info.serv_fqdn,
3018 sprintf(alt_boundary, "Citadel--Multipart--%s--%04x--%04x",
3019 serv_info.serv_fqdn,
3024 /* RFC2045 requires this, and some clients look for it... */
3025 serv_puts("MIME-Version: 1.0");
3026 serv_puts("X-Mailer: " PACKAGE_STRING);
3028 /* If there are attachments, we have to do multipart/mixed */
3029 if (WC->first_attachment != NULL) {
3034 /* Remember, serv_printf() appends an extra newline */
3035 serv_printf("Content-type: multipart/mixed; boundary=\"%s\"\n", top_boundary);
3036 serv_printf("This is a multipart message in MIME format.\n");
3037 serv_printf("--%s", top_boundary);
3040 /* Remember, serv_printf() appends an extra newline */
3041 serv_printf("Content-type: multipart/alternative; "
3042 "boundary=\"%s\"\n", alt_boundary);
3043 serv_printf("This is a multipart message in MIME format.\n");
3044 serv_printf("--%s", alt_boundary);
3046 serv_puts("Content-type: text/plain; charset=utf-8");
3047 serv_puts("Content-Transfer-Encoding: quoted-printable");
3049 txtmail = html_to_ascii(bstr("msgtext"), 0, 80, 0);
3050 text_to_server_qp(txtmail); /* Transmit message in quoted-printable encoding */
3053 serv_printf("--%s", alt_boundary);
3055 serv_puts("Content-type: text/html; charset=utf-8");
3056 serv_puts("Content-Transfer-Encoding: quoted-printable");
3058 serv_puts("<html><body>\r\n");
3059 text_to_server_qp(bstr("msgtext")); /* Transmit message in quoted-printable encoding */
3060 serv_puts("</body></html>\r\n");
3062 serv_printf("--%s--", alt_boundary);
3066 /* Add in the attachments */
3067 for (att = WC->first_attachment; att!=NULL; att=att->next) {
3069 encoded_length = ((att->length * 150) / 100);
3070 encoded = malloc(encoded_length);
3071 if (encoded == NULL) break;
3072 encoded_strlen = CtdlEncodeBase64(encoded, att->data, att->length, 1);
3074 serv_printf("--%s", top_boundary);
3075 serv_printf("Content-type: %s", att->content_type);
3076 serv_printf("Content-disposition: attachment; filename=\"%s\"", att->filename);
3077 serv_puts("Content-transfer-encoding: base64");
3079 serv_write(encoded, encoded_strlen);
3084 serv_printf("--%s--", top_boundary);
3092 * Post message (or don't post message)
3094 * Note regarding the "dont_post" variable:
3095 * A random value (actually, it's just a timestamp) is inserted as a hidden
3096 * field called "postseq" when the display_enter page is generated. This
3097 * value is checked when posting, using the static variable dont_post. If a
3098 * user attempts to post twice using the same dont_post value, the message is
3099 * discarded. This prevents the accidental double-saving of the same message
3100 * if the user happens to click the browser "back" button.
3102 void post_message(void)
3105 StrBuf *encoded_subject = NULL;
3106 static long dont_post = (-1L);
3107 struct wc_attachment *att, *aptr;
3108 int is_anonymous = 0;
3109 const StrBuf *display_name = NULL;
3110 struct wcsession *WCC = WC;
3112 if (havebstr("force_room")) {
3113 gotoroom(bstr("force_room"));
3116 if (havebstr("display_name")) {
3117 display_name = sbstr("display_name");
3118 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
3119 display_name = NULL;
3124 if (WCC->upload_length > 0) {
3126 lprintf(9, "%s:%d: we are uploading %d bytes\n", __FILE__, __LINE__, WCC->upload_length);
3127 /** There's an attachment. Save it to this struct... */
3128 att = malloc(sizeof(struct wc_attachment));
3129 memset(att, 0, sizeof(struct wc_attachment));
3130 att->length = WCC->upload_length;
3131 strcpy(att->content_type, WCC->upload_content_type);
3132 strcpy(att->filename, WCC->upload_filename);
3135 /** And add it to the list. */
3136 if (WCC->first_attachment == NULL) {
3137 WCC->first_attachment = att;
3140 aptr = WCC->first_attachment;
3141 while (aptr->next != NULL) aptr = aptr->next;
3146 * Mozilla sends a simple filename, which is what we want,
3147 * but Satan's Browser sends an entire pathname. Reduce
3148 * the path to just a filename if we need to.
3150 while (num_tokens(att->filename, '/') > 1) {
3151 remove_token(att->filename, 0, '/');
3153 while (num_tokens(att->filename, '\\') > 1) {
3154 remove_token(att->filename, 0, '\\');
3158 * Transfer control of this memory from the upload struct
3159 * to the attachment struct.
3161 att->data = WCC->upload;
3162 WCC->upload_length = 0;
3168 if (havebstr("cancel_button")) {
3169 sprintf(WCC->ImportantMessage,
3170 _("Cancelled. Message was not posted."));
3171 } else if (havebstr("attach_button")) {
3174 } else if (lbstr("postseq") == dont_post) {
3175 sprintf(WCC->ImportantMessage,
3176 _("Automatically cancelled because you have already "
3177 "saved this message."));
3179 const char CMD[] = "ENT0 1|%s|%d|4|%s|%s||%s|%s|%s|%s|%s";
3180 const StrBuf *Recp = NULL;
3181 const StrBuf *Cc = NULL;
3182 const StrBuf *Bcc = NULL;
3183 const StrBuf *Wikipage = NULL;
3184 const StrBuf *my_email_addr = NULL;
3185 StrBuf *CmdBuf = NULL;;
3186 StrBuf *references = NULL;
3188 if (havebstr("references"))
3190 const StrBuf *ref = sbstr("references");
3191 references = NewStrBufPlain(ChrPtr(ref), StrLength(ref));
3192 lprintf(9, "Converting: %s\n", ChrPtr(references));
3193 StrBufReplaceChars(references, '|', '!');
3194 lprintf(9, "Converted: %s\n", ChrPtr(references));
3196 if (havebstr("subject")) {
3199 * make enough room for the encoded string;
3200 * plus the QP header
3202 Subj = sbstr("subject");
3204 StrBufRFC2047encode(&encoded_subject, Subj);
3206 Recp = sbstr("recp");
3209 Wikipage = sbstr("wikipage");
3210 my_email_addr = sbstr("my_email_addr");
3212 CmdBuf = NewStrBufPlain(NULL,
3215 StrLength(encoded_subject) +
3218 StrLength(Wikipage) +
3219 StrLength(my_email_addr) +
3220 StrLength(references));
3222 StrBufPrintf(CmdBuf,
3226 ChrPtr(encoded_subject),
3227 ChrPtr(display_name),
3231 ChrPtr(my_email_addr),
3232 ChrPtr(references));
3233 FreeStrBuf(&references);
3235 lprintf(9, "%s\n", CmdBuf);
3236 serv_puts(ChrPtr(CmdBuf));
3237 serv_getln(buf, sizeof buf);
3238 FreeStrBuf(&CmdBuf);
3239 FreeStrBuf(&encoded_subject);
3240 if (buf[0] == '4') {
3241 post_mime_to_server();
3242 if ( (havebstr("recp"))
3243 || (havebstr("cc" ))
3244 || (havebstr("bcc" ))
3246 sprintf(WCC->ImportantMessage, _("Message has been sent.\n"));
3249 sprintf(WC->ImportantMessage, _("Message has been posted.\n"));
3251 dont_post = lbstr("postseq");
3253 lprintf(9, "%s:%d: server post error: %s\n", __FILE__, __LINE__, buf);
3254 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3260 free_attachments(WCC);
3263 * We may have been supplied with instructions regarding the location
3264 * to which we must return after posting. If found, go there.
3266 if (havebstr("return_to")) {
3267 http_redirect(bstr("return_to"));
3270 * If we were editing a page in a wiki room, go to that page now.
3272 else if (havebstr("wikipage")) {
3273 snprintf(buf, sizeof buf, "wiki?page=%s", bstr("wikipage"));
3277 * Otherwise, just go to the "read messages" loop.
3280 readloop("readnew");
3288 * \brief display the message entry screen
3290 void display_enter(void)
3295 const StrBuf *display_name = NULL;
3296 struct wc_attachment *att;
3297 int recipient_required = 0;
3298 int subject_required = 0;
3299 int recipient_bad = 0;
3300 int is_anonymous = 0;
3301 long existing_page = (-1L);
3302 struct wcsession *WCC = WC;
3306 if (havebstr("force_room")) {
3307 gotoroom(bstr("force_room"));
3310 display_name = sbstr("display_name");
3311 if (!strcmp(ChrPtr(display_name), "__ANONYMOUS__")) {
3312 display_name = NULL;
3316 /** First test to see whether this is a room that requires recipients to be entered */
3317 serv_puts("ENT0 0");
3318 serv_getln(buf, sizeof buf);
3320 if (!strncmp(buf, "570", 3)) { /** 570 means that we need a recipient here */
3321 recipient_required = 1;
3323 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
3324 sprintf(WCC->ImportantMessage, "%s", &buf[4]);
3325 readloop("readnew");
3329 /* Is the server strongly recommending that the user enter a message subject? */
3330 if ((buf[3] != '\0') && (buf[4] != '\0')) {
3331 subject_required = extract_int(&buf[4], 1);
3335 * Are we perhaps in an address book view? If so, then an "enter
3336 * message" command really means "add new entry."
3338 if (WCC->wc_default_view == VIEW_ADDRESSBOOK) {
3339 do_edit_vcard(-1, "", "", WCC->wc_roomname);
3344 * Are we perhaps in a calendar room? If so, then an "enter
3345 * message" command really means "add new calendar item."
3347 if (WCC->wc_default_view == VIEW_CALENDAR) {
3348 display_edit_event();
3353 * Are we perhaps in a tasks view? If so, then an "enter
3354 * message" command really means "add new task."
3356 if (WCC->wc_default_view == VIEW_TASKS) {
3357 display_edit_task();
3362 * Otherwise proceed normally.
3363 * Do a custom room banner with no navbar...
3365 output_headers(1, 1, 2, 0, 0, 0);
3366 wprintf("<div id=\"banner\">\n");
3367 embed_room_banner(NULL, navbar_none);
3368 wprintf("</div>\n");
3369 wprintf("<div id=\"content\">\n"
3370 "<div class=\"fix_scrollbar_bug message \">");
3372 /* Now check our actual recipients if there are any */
3373 if (recipient_required) {
3374 const StrBuf *Recp = NULL;
3375 const StrBuf *Cc = NULL;
3376 const StrBuf *Bcc = NULL;
3377 const StrBuf *Wikipage = NULL;
3378 StrBuf *CmdBuf = NULL;;
3379 const char CMD[] = "ENT0 0|%s|%d|0||%s||%s|%s|%s";
3381 Recp = sbstr("recp");
3384 Wikipage = sbstr("wikipage");
3386 CmdBuf = NewStrBufPlain(NULL,
3389 StrLength(display_name) +
3392 StrLength(Wikipage));
3394 StrBufPrintf(CmdBuf,
3398 ChrPtr(display_name),
3402 serv_puts(ChrPtr(CmdBuf));
3403 serv_getln(buf, sizeof buf);
3404 FreeStrBuf(&CmdBuf);
3406 if (!strncmp(buf, "570", 3)) { /** 570 means we have an invalid recipient listed */
3407 if (havebstr("recp") &&
3413 else if (buf[0] != '2') { /** Any other error means that we cannot continue */
3414 wprintf("<em>%s</em><br />\n", &buf[4]);
3419 /** If we got this far, we can display the message entry screen. */
3421 /* begin message entry screen */
3423 "enctype=\"multipart/form-data\" "
3425 "accept-charset=\"UTF-8\" "
3427 "name=\"enterform\""
3429 wprintf("<input type=\"hidden\" name=\"postseq\" value=\"%ld\">\n", now);
3430 if (WCC->wc_view == VIEW_WIKI) {
3431 wprintf("<input type=\"hidden\" name=\"wikipage\" value=\"%s\">\n", bstr("wikipage"));
3433 wprintf("<input type=\"hidden\" name=\"return_to\" value=\"%s\">\n", bstr("return_to"));
3434 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WCC->nonce);
3435 wprintf("<input type=\"hidden\" name=\"force_room\" value=\"");
3436 escputs(WCC->wc_roomname);
3438 wprintf("<input type=\"hidden\" name=\"references\" value=\"");
3439 escputs(bstr("references"));
3442 /** submit or cancel buttons */
3443 wprintf("<p class=\"send_edit_msg\">");
3444 wprintf("<input type=\"submit\" name=\"send_button\" value=\"");
3445 if (recipient_required) {
3446 wprintf(_("Send message"));
3448 wprintf(_("Post message"));
3451 "<input type=\"submit\" name=\"cancel_button\" value=\"%s\">\n", _("Cancel"));
3456 wprintf("<img src=\"static/newmess3_24x.gif\" class=\"imgedit\">");
3457 wprintf(" "); /** header bar */
3458 webcit_fmt_date(buf, now, 0);
3460 wprintf("\n"); /** header bar */
3462 wprintf("<table width=\"100%%\" class=\"edit_msg_table\">");
3464 wprintf("<th><label for=\"from_id\" > ");
3465 wprintf(_(" <I>from</I> "));
3466 wprintf("</label></th>");
3468 wprintf("<td colspan=\"2\">");
3470 /* Allow the user to select any of his valid screen names */
3472 wprintf("<select name=\"display_name\" size=1 id=\"from_id\">\n");
3475 serv_getln(buf, sizeof buf);
3476 if (buf[0] == '1') {
3477 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3478 wprintf("<option %s value=\"",
3479 ((!strcasecmp(bstr("display_name"), buf)) ? "selected" : "")
3484 wprintf("</option>\n");
3488 if (WCC->room_flags & QR_ANONOPT) {
3489 wprintf("<option %s value=\"__ANONYMOUS__\">%s</option>\n",
3490 ((!strcasecmp(bstr("__ANONYMOUS__"), WCC->wc_fullname)) ? "selected" : ""),
3495 wprintf("</select>\n");
3497 /* If this is an email (not a post), allow the user to select any of his
3498 * valid email addresses.
3500 if (recipient_required) {
3502 serv_getln(buf, sizeof buf);
3503 if (buf[0] == '1') {
3504 wprintf("<select name=\"my_email_addr\" size=1>\n");
3505 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3506 wprintf("<option value=\"");
3510 wprintf("></option>\n");
3512 wprintf("</select>\n");
3516 wprintf(_(" <I>in</I> "));
3517 escputs(WCC->wc_roomname);
3519 wprintf("</td></tr>");
3521 if (recipient_required) {
3525 wprintf("<tr><th><label for=\"recp_id\"> ");
3527 wprintf("</label></th>"
3528 "<td><input autocomplete=\"off\" type=\"text\" name=\"recp\" id=\"recp_id\" value=\"");
3529 ccraw = xbstr("recp", &len);
3530 copy = (char*) malloc(len * 2 + 1);
3531 memcpy(copy, ccraw, len + 1);
3532 utf8ify_rfc822_string(copy);
3535 wprintf("\" size=45 maxlength=1000 />");
3536 wprintf("<div class=\"auto_complete\" id=\"recp_name_choices\"></div>");
3537 wprintf("</td><td rowspan=\"3\" align=\"left\" valign=\"top\">");
3539 /** Pop open an address book -- begin **/
3541 "<a href=\"javascript:PopOpenAddressBook('recp_id|%s|cc_id|%s|bcc_id|%s');\" "
3543 "<img align=middle border=0 width=24 height=24 src=\"static/viewcontacts_24x.gif\">"
3545 _("To:"), _("CC:"), _("BCC:"),
3546 _("Contacts"), _("Contacts")
3548 /** Pop open an address book -- end **/
3550 wprintf("</td></tr>");
3552 wprintf("<tr><th><label for=\"cc_id\"> ");
3554 wprintf("</label></th>"
3555 "<td><input autocomplete=\"off\" type=\"text\" name=\"cc\" id=\"cc_id\" value=\"");
3556 ccraw = xbstr("cc", &len);
3557 copy = (char*) malloc(len * 2 + 1);
3558 memcpy(copy, ccraw, len + 1);
3559 utf8ify_rfc822_string(copy);
3562 wprintf("\" size=45 maxlength=1000 />");
3563 wprintf("<div class=\"auto_complete\" id=\"cc_name_choices\"></div>");
3564 wprintf("</td></tr>");
3566 wprintf("<tr><th><label for=\"bcc_id\"> ");
3568 wprintf("</label></th>"
3569 "<td><input autocomplete=\"off\" type=\"text\" name=\"bcc\" id=\"bcc_id\" value=\"");
3570 ccraw = xbstr("bcc", &len);
3571 copy = (char*) malloc(len * 2 + 1);
3572 memcpy(copy, ccraw, len + 1);
3573 utf8ify_rfc822_string(copy);
3576 wprintf("\" size=45 maxlength=1000 />");
3577 wprintf("<div class=\"auto_complete\" id=\"bcc_name_choices\"></div>");
3578 wprintf("</td></tr>");
3580 /** Initialize the autocomplete ajax helpers (found in wclib.js) */
3581 wprintf("<script type=\"text/javascript\"> \n"
3582 " activate_entmsg_autocompleters(); \n"
3588 wprintf("<tr><th><label for=\"subject_id\" > ");
3589 if (recipient_required || subject_required) {
3590 wprintf(_("Subject:"));
3593 wprintf(_("Subject (optional):"));
3595 wprintf("</label></th>"
3596 "<td colspan=\"2\">"
3597 "<input type=\"text\" name=\"subject\" id=\"subject_id\" value=\"");
3598 escputs(bstr("subject"));
3599 wprintf("\" size=45 maxlength=70>\n");
3600 wprintf("</td></tr>");
3602 wprintf("<tr><td colspan=\"3\">\n");
3604 wprintf("<textarea name=\"msgtext\" cols=\"80\" rows=\"15\">");
3606 /** If we're continuing from a previous edit, put our partially-composed message back... */
3607 msgescputs(bstr("msgtext"));
3609 /* If we're forwarding a message, insert it here... */
3610 if (lbstr("fwdquote") > 0L) {
3611 wprintf("<br><div align=center><i>");
3612 wprintf(_("--- forwarded message ---"));
3613 wprintf("</i></div><br>");
3614 pullquote_message(lbstr("fwdquote"), 1, 1);
3617 /** If we're replying quoted, insert the quote here... */
3618 else if (lbstr("replyquote") > 0L) {
3621 pullquote_message(lbstr("replyquote"), 0, 1);
3622 wprintf("</blockquote><br>");
3625 /** If we're editing a wiki page, insert the existing page here... */
3626 else if (WCC->wc_view == VIEW_WIKI) {
3627 safestrncpy(buf, bstr("wikipage"), sizeof buf);
3628 str_wiki_index(buf);
3629 existing_page = locate_message_by_uid(buf);
3630 if (existing_page >= 0L) {
3631 pullquote_message(existing_page, 1, 0);
3635 /** Insert our signature if appropriate... */
3636 if ( (WCC->is_mailbox) && !yesbstr("sig_inserted") ) {
3638 get_pref_yesno("use_sig", &UseSig, 0);
3641 const char *sig, *esig;
3643 get_preference("signature", &ebuf);
3645 StrBufEUid_unescapize(Sig, ebuf);
3647 esig = sig + StrLength(Sig);
3648 wprintf("<br>--<br>");
3649 while (sig <= esig) {
3653 else if (*sig == '<') {
3656 else if (*sig == '>') {
3659 else if (*sig == '&') {
3662 else if (*sig == '\"') {
3665 else if (*sig == '\'') {
3668 else /* since we're utf 8, is this a good idea? if (isprint(*sig))*/ {
3669 wprintf("%c", *sig);
3677 wprintf("</textarea>\n");
3679 /** Make sure we only insert our signature once */
3680 /** We don't care if it was there or not before, it needs to be there now. */
3681 wprintf("<input type=\"hidden\" name=\"sig_inserted\" value=\"yes\">\n");
3684 * The following template embeds the TinyMCE richedit control, and automatically
3685 * transforms the textarea into a richedit textarea.
3687 do_template("richedit", NULL);
3689 /** Enumerate any attachments which are already in place... */
3690 wprintf("<div class=\"attachment buttons\"><img src=\"static/diskette_24x.gif\" class=\"imgedit\" > ");
3691 wprintf(_("Attachments:"));
3693 wprintf("<select name=\"which_attachment\" size=1>");
3694 for (att = WCC->first_attachment; att != NULL; att = att->next) {
3695 wprintf("<option value=\"");
3696 urlescputs(att->filename);
3698 escputs(att->filename);
3699 /* wprintf(" (%s, %d bytes)",att->content_type,att->length); */
3700 wprintf("</option>\n");
3702 wprintf("</select>");
3704 /** Now offer the ability to attach additional files... */
3705 wprintf(" ");
3706 wprintf(_("Attach file:"));
3707 wprintf(" <input name=\"attachfile\" class=\"attachfile\" "
3708 "size=16 type=\"file\">\n "
3709 "<input type=\"submit\" name=\"attach_button\" value=\"%s\">\n", _("Add"));
3710 wprintf("</div>"); /* End of "attachment buttons" div */
3713 wprintf("</td></tr></table>");
3715 wprintf("</form>\n");
3716 wprintf("</div>\n"); /* end of "fix_scrollbar_bug" div */
3718 /* NOTE: address_book_popup() will close the "content" div. Don't close it here. */
3719 DONE: address_book_popup();
3725 * \brief delete a message
3727 void delete_msg(void)
3732 msgid = lbstr("msgid");
3734 if (WC->wc_is_trash) { /** Delete from Trash is a real delete */
3735 serv_printf("DELE %ld", msgid);
3737 else { /** Otherwise move it to Trash */
3738 serv_printf("MOVE %ld|_TRASH_|0", msgid);
3741 serv_getln(buf, sizeof buf);
3742 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3744 readloop("readnew");
3749 * \brief move a message to another folder
3756 msgid = lbstr("msgid");
3758 if (havebstr("move_button")) {
3759 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
3761 serv_getln(buf, sizeof buf);
3762 sprintf(WC->ImportantMessage, "%s", &buf[4]);
3764 sprintf(WC->ImportantMessage, (_("The message was not moved.")));
3767 readloop("readnew");
3775 * Confirm move of a message
3777 void confirm_move_msg(void)
3783 msgid = lbstr("msgid");
3786 output_headers(1, 1, 2, 0, 0, 0);
3787 wprintf("<div id=\"banner\">\n");
3789 wprintf(_("Confirm move of message"));
3791 wprintf("</div>\n");
3793 wprintf("<div id=\"content\" class=\"service\">\n");
3795 wprintf("<CENTER>");
3797 wprintf(_("Move this message to:"));
3798 wprintf("<br />\n");
3800 wprintf("<form METHOD=\"POST\" action=\"move_msg\">\n");
3801 wprintf("<input type=\"hidden\" name=\"nonce\" value=\"%d\">\n", WC->nonce);
3802 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n", bstr("msgid"));
3804 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
3806 serv_getln(buf, sizeof buf);
3807 if (buf[0] == '1') {
3808 while (serv_getln(buf, sizeof buf), strcmp(buf, "000")) {
3809 extract_token(targ, buf, 0, '|', sizeof targ);
3810 wprintf("<OPTION>");
3815 wprintf("</SELECT>\n");
3816 wprintf("<br />\n");
3818 wprintf("<INPUT TYPE=\"submit\" NAME=\"move_button\" VALUE=\"%s\">", _("Move"));
3820 wprintf("<INPUT TYPE=\"submit\" NAME=\"cancel_button\" VALUE=\"%s\">", _("Cancel"));
3821 wprintf("</form></CENTER>\n");
3823 wprintf("</CENTER>\n");
3827 void readnew(void) { readloop("readnew");}
3828 void readold(void) { readloop("readold");}
3829 void readfwd(void) { readloop("readfwd");}
3830 void headers(void) { readloop("headers");}
3831 void do_search(void) { readloop("do_search");}
3842 WebcitAddUrlHandler(HKEY("readnew"), readnew, 0);
3843 WebcitAddUrlHandler(HKEY("readold"), readold, 0);
3844 WebcitAddUrlHandler(HKEY("readfwd"), readfwd, 0);
3845 WebcitAddUrlHandler(HKEY("headers"), headers, 0);
3846 WebcitAddUrlHandler(HKEY("do_search"), do_search, 0);
3847 WebcitAddUrlHandler(HKEY("display_enter"), display_enter, 0);
3848 WebcitAddUrlHandler(HKEY("post"), post_message, 0);
3849 WebcitAddUrlHandler(HKEY("move_msg"), move_msg, 0);
3850 WebcitAddUrlHandler(HKEY("delete_msg"), delete_msg, 0);
3851 WebcitAddUrlHandler(HKEY("confirm_move_msg"), confirm_move_msg, 0);
3852 WebcitAddUrlHandler(HKEY("msg"), embed_message, NEED_URL|AJAX);
3853 WebcitAddUrlHandler(HKEY("printmsg"), print_message, NEED_URL);
3854 WebcitAddUrlHandler(HKEY("mobilemsg"), mobile_message_view, NEED_URL);
3855 WebcitAddUrlHandler(HKEY("msgheaders"), display_headers, NEED_URL);
3857 RegisterNamespace("MAIL:SUMM:DATESTR", 0, 0, tmplput_MAIL_SUMM_DATE_STR, CTX_MAILSUM);
3858 RegisterNamespace("MAIL:SUMM:DATENO", 0, 0, tmplput_MAIL_SUMM_DATE_NO, CTX_MAILSUM);
3859 RegisterNamespace("MAIL:SUMM:N", 0, 0, tmplput_MAIL_SUMM_N, CTX_MAILSUM);
3860 RegisterNamespace("MAIL:SUMM:FROM", 0, 2, tmplput_MAIL_SUMM_FROM, CTX_MAILSUM);
3861 RegisterNamespace("MAIL:SUMM:TO", 0, 2, tmplput_MAIL_SUMM_TO, CTX_MAILSUM);
3862 RegisterNamespace("MAIL:SUMM:SUBJECT", 0, 4, tmplput_MAIL_SUMM_SUBJECT, CTX_MAILSUM);
3863 RegisterNamespace("MAIL:SUMM:NATTACH", 0, 0, tmplput_MAIL_SUMM_NATTACH, CTX_MAILSUM);
3864 RegisterNamespace("MAIL:SUMM:CCCC", 0, 2, tmplput_MAIL_SUMM_CCCC, CTX_MAILSUM);
3865 RegisterNamespace("MAIL:SUMM:H_NODE", 0, 2, tmplput_MAIL_SUMM_H_NODE, CTX_MAILSUM);
3866 RegisterNamespace("MAIL:SUMM:ALLRCPT", 0, 2, tmplput_MAIL_SUMM_ALLRCPT, CTX_MAILSUM);
3867 RegisterNamespace("MAIL:SUMM:ORGROOM", 0, 2, tmplput_MAIL_SUMM_ORGROOM, CTX_MAILSUM);
3868 RegisterNamespace("MAIL:SUMM:RFCA", 0, 2, tmplput_MAIL_SUMM_RFCA, CTX_MAILSUM);
3869 RegisterNamespace("MAIL:SUMM:OTHERNODE", 2, 0, tmplput_MAIL_SUMM_OTHERNODE, CTX_MAILSUM);
3870 RegisterNamespace("MAIL:SUMM:REFIDS", 0, 0, tmplput_MAIL_SUMM_REFIDS, CTX_MAILSUM);
3871 RegisterNamespace("MAIL:SUMM:INREPLYTO", 0, 2, tmplput_MAIL_SUMM_INREPLYTO, CTX_MAILSUM);
3872 RegisterNamespace("MAIL:BODY", 0, 2, tmplput_MAIL_BODY, CTX_MAILSUM);
3876 RegisterMimeRenderer(HKEY("text/x-citadel-variformat"), render_MAIL_variformat);
3877 RegisterMimeRenderer(HKEY("text/plain"), render_MAIL_text_plain);
3878 RegisterMimeRenderer(HKEY("text"), render_MAIL_text_plain);
3879 RegisterMimeRenderer(HKEY("text/html"), render_MAIL_html);
3880 RegisterMimeRenderer(HKEY(""), render_MAIL_UNKNOWN);
3883 RegisterConditional(HKEY("COND:MAIL:SUMM:UNREAD"), 0, Conditional_MAIL_SUMM_UNREAD, CTX_MAILSUM);
3884 RegisterConditional(HKEY("COND:MAIL:SUMM:H_NODE"), 0, Conditional_MAIL_SUMM_H_NODE, CTX_MAILSUM);
3885 RegisterConditional(HKEY("COND:MAIL:SUMM:OTHERNODE"), 0, Conditional_MAIL_SUMM_OTHERNODE, CTX_MAILSUM);
3887 RegisterMsgHdr(HKEY("nhdr"), examine_nhdr, 0);
3888 RegisterMsgHdr(HKEY("type"), examine_type, 0);
3889 RegisterMsgHdr(HKEY("from"), examine_from, 0);
3890 RegisterMsgHdr(HKEY("subj"), examine_subj, 0);
3891 RegisterMsgHdr(HKEY("msgn"), examine_msgn, 0);
3892 RegisterMsgHdr(HKEY("wefw"), examine_wefw, 0);
3893 RegisterMsgHdr(HKEY("cccc"), examine_cccc, 0);
3894 RegisterMsgHdr(HKEY("hnod"), examine_hnod, 0);
3895 RegisterMsgHdr(HKEY("room"), examine_room, 0);
3896 RegisterMsgHdr(HKEY("rfca"), examine_rfca, 0);
3897 RegisterMsgHdr(HKEY("node"), examine_node, 0);
3898 RegisterMsgHdr(HKEY("rcpt"), examine_rcpt, 0);
3899 RegisterMsgHdr(HKEY("time"), examine_time, 0);
3900 RegisterMsgHdr(HKEY("part"), examine_mime_part, 0);
3901 RegisterMsgHdr(HKEY("text"), examine_text, 1);
3902 RegisterMsgHdr(HKEY("X-Citadel-MSG4-Partnum"), examine_msg4_partnum, 0);
3903 RegisterMsgHdr(HKEY("Content-type"), examine_content_type, 0);
3904 RegisterMsgHdr(HKEY("Content-length"), examine_content_lengh, 0);
3905 RegisterMsgHdr(HKEY("Content-transfer-encoding"), examine_content_encoding, 0);