-void display_enter(void);
-int longcmp_r(const void *s1, const void *s2);
-int summcmp_subj(const void *s1, const void *s2);
-int summcmp_rsubj(const void *s1, const void *s2);
-int summcmp_sender(const void *s1, const void *s2);
-int summcmp_rsender(const void *s1, const void *s2);
-int summcmp_date(const void *s1, const void *s2);
-int summcmp_rdate(const void *s1, const void *s2);
-
-/*----------------------------------------------------------------------------*/
-
-
-typedef void (*MsgPartEvaluatorFunc)(message_summary *Sum, StrBuf *Buf);
-
-
-struct attach_link {
- char partnum[32];
- char html[1024];
-};
-
-
-
-typedef struct _headereval {
- ExamineMsgHeaderFunc evaluator;
- int Type;
-} headereval;
-
-
-
-enum {
- eUp,
- eDown,
- eNone
-};
-
-const char* SortIcons[3] = {
- "static/up_pointer.gif",
- "static/down_pointer.gif",
- "static/sort_none.gif"
-};
-
-enum {/// SortByEnum
- eDate,
- eRDate,
- eSubject,
- eRSubject,
- eSender,
- eRSender,
- eReverse,
- eUnSet
-};
-
-/* SortEnum to plain string representation */
-static const char* SortByStrings[] = {
- "date",
- "rdate",
- "subject",
- "rsubject",
- "sender",
- "rsender",
- "reverse",
- "unset"
-};
-
-/* SortEnum to sort-Function Table */
-const CompareFunc SortFuncs[eUnSet] = {
- summcmp_date,
- summcmp_rdate,
- summcmp_subj,
- summcmp_rsubj,
- summcmp_sender,
- summcmp_rsender,
- summcmp_rdate
-};
-
-/* given a SortEnum, which icon should we choose? */
-const int SortDateToIcon[eUnSet] = { eUp, eDown, eNone, eNone, eNone, eNone, eNone};
-const int SortSubjectToIcon[eUnSet] = { eNone, eNone, eUp, eDown, eNone, eNone, eNone};
-const int SortSenderToIcon[eUnSet] = { eNone, eNone, eNone, eNone, eUp, eDown, eNone};
-
-/* given a SortEnum, which would be the "opposite" search option? */
-const int DateInvertSortString[eUnSet] = { eRDate, eDate, eDate, eDate, eDate, eDate, eDate};
-const int SubjectInvertSortString[eUnSet] = { eSubject, eSubject, eRSubject, eUnSet, eSubject, eSubject, eSubject};
-const int SenderInvertSortString[eUnSet] = { eSender, eSender, eSender, eSender, eRSender, eUnSet, eSender};
-
-
-
-
-/*
- * Address book entry (keep it short and sweet, it's just a quickie lookup
- * which we can use to get to the real meat and bones later)
- */
-struct addrbookent {
- char ab_name[64]; /**< name string */
- long ab_msgnum; /**< message number of address book entry */
-};
-
-/*----------------------------------------------------------------------------*/
-
-/*
- * Translates sortoption String to its SortEnum representation
- * returns the enum matching the string; defaults to RDate
- */
-//SortByEnum
-int StrToESort (const StrBuf *sortby)
-{////todoo: hash
- int result = eDate;
-
- if (!IsEmptyStr(ChrPtr(sortby))) while (result < eUnSet){
- if (!strcasecmp(ChrPtr(sortby),
- SortByStrings[result]))
- return result;
- result ++;
- }
- return eRDate;
-}
-
-
-typedef int (*QSortFunction) (const void*, const void*);
-
-/*
- * qsort() compatible function to compare two longs in descending order.
- */
-int longcmp_r(const void *s1, const void *s2) {
- long l1;
- long l2;
-
- l1 = *(long *)GetSearchPayload(s1);
- l2 = *(long *)GetSearchPayload(s2);
-
- if (l1 > l2) return(-1);
- if (l1 < l2) return(+1);
- return(0);
-}
-
-
-/*
- * qsort() compatible function to compare two message summary structs by ascending subject.
- */
-int summcmp_subj(const void *s1, const void *s2) {
- message_summary *summ1;
- message_summary *summ2;
-
- summ1 = (message_summary *)GetSearchPayload(s1);
- summ2 = (message_summary *)GetSearchPayload(s2);
- return strcasecmp(ChrPtr(summ1->subj), ChrPtr(summ2->subj));
-}
-
-/*
- * qsort() compatible function to compare two message summary structs by descending subject.
- */
-int summcmp_rsubj(const void *s1, const void *s2) {
- message_summary *summ1;
- message_summary *summ2;
-
- summ1 = (message_summary *)GetSearchPayload(s1);
- summ2 = (message_summary *)GetSearchPayload(s2);
- return strcasecmp(ChrPtr(summ2->subj), ChrPtr(summ1->subj));
-}
-
-/*
- * qsort() compatible function to compare two message summary structs by ascending sender.
- */
-int summcmp_sender(const void *s1, const void *s2) {
- message_summary *summ1;
- message_summary *summ2;
-
- summ1 = (message_summary *)GetSearchPayload(s1);
- summ2 = (message_summary *)GetSearchPayload(s2);
- return strcasecmp(ChrPtr(summ1->from), ChrPtr(summ2->from));
-}
-
-/*
- * qsort() compatible function to compare two message summary structs by descending sender.
- */
-int summcmp_rsender(const void *s1, const void *s2) {
- message_summary *summ1;
- message_summary *summ2;
-
- summ1 = (message_summary *)GetSearchPayload(s1);
- summ2 = (message_summary *)GetSearchPayload(s2);
- return strcasecmp(ChrPtr(summ2->from), ChrPtr(summ1->from));
-}
-
-/*
- * qsort() compatible function to compare two message summary structs by ascending date.
- */
-int summcmp_date(const void *s1, const void *s2) {
- message_summary *summ1;
- message_summary *summ2;
-
- summ1 = (message_summary *)GetSearchPayload(s1);
- summ2 = (message_summary *)GetSearchPayload(s2);
-
- if (summ1->date < summ2->date) return -1;
- else if (summ1->date > summ2->date) return +1;
- else return 0;
-}
-
-/*
- * qsort() compatible function to compare two message summary structs by descending date.
- */
-int summcmp_rdate(const void *s1, const void *s2) {
- message_summary *summ1;
- message_summary *summ2;
-
- summ1 = (message_summary *)GetSearchPayload(s1);
- summ2 = (message_summary *)GetSearchPayload(s2);
-
- if (summ1->date < summ2->date) return +1;
- else if (summ1->date > summ2->date) return -1;
- else return 0;
-}
-
-
-
-
-
-/*----------------------------------------------------------------------------*/
-
-/**
- * message index functions
- */
-
-
-
-
-void DestroyMessageSummary(void *vMsg)
-{
- message_summary *Msg = (message_summary*) vMsg;
-
- FreeStrBuf(&Msg->from);
- FreeStrBuf(&Msg->to);
- FreeStrBuf(&Msg->subj);
- FreeStrBuf(&Msg->reply_inreplyto);
- FreeStrBuf(&Msg->reply_references);
- FreeStrBuf(&Msg->cccc);
- FreeStrBuf(&Msg->hnod);
- FreeStrBuf(&Msg->AllRcpt);
- FreeStrBuf(&Msg->Room);
- FreeStrBuf(&Msg->Rfca);
- FreeStrBuf(&Msg->OtherNode);
-
- free(Msg);
-}
-
-
-
-void RegisterMsgHdr(const char *HeaderName, long HdrNLen, ExamineMsgHeaderFunc evaluator, int type)
-{
- headereval *ev;
- ev = (headereval*) malloc(sizeof(headereval));
- ev->evaluator = evaluator;
- ev->Type = type;
- Put(MsgHeaderHandler, HeaderName, HdrNLen, ev, NULL);
-}
-
-void RegisterMimeRenderer(const char *HeaderName, long HdrNLen, RenderMimeFunc MimeRenderer)
-{
- Put(MimeRenderHandler, HeaderName, HdrNLen, MimeRenderer, reference_free_handler);
-
-}
-
-/*----------------------------------------------------------------------------*/
-
-
-void examine_nhdr(message_summary *Msg, StrBuf *HdrLine)
-{
- Msg->nhdr = 0;
- if (!strncasecmp(ChrPtr(HdrLine), "yes", 8))
- Msg->nhdr = 1;
-}
-
-void examine_type(message_summary *Msg, StrBuf *HdrLine)
-{
- Msg->format_type = StrToi(HdrLine);
-
-}
-
-void examine_from(message_summary *Msg, StrBuf *HdrLine)
-{
- FreeStrBuf(&Msg->from);
- Msg->from = NewStrBufPlain(NULL, StrLength(HdrLine));
- StrBuf_RFC822_to_Utf8(Msg->from, HdrLine, WC->DefaultCharset);
-}
-void tmplput_MAIL_SUMM_FROM(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
-{
- message_summary *Msg = (message_summary*) Context;
- StrBufAppendBuf(Target, Msg->from, 0);
- lprintf(1,"%s", ChrPtr(Msg->from));
-}
-
-
-
-void examine_subj(message_summary *Msg, StrBuf *HdrLine)
-{
- FreeStrBuf(&Msg->subj);
- Msg->subj = NewStrBufPlain(NULL, StrLength(HdrLine));
- StrBuf_RFC822_to_Utf8(Msg->subj, HdrLine, WC->DefaultCharset);
- lprintf(1,"%s", ChrPtr(Msg->subj));
-}
-void tmplput_MAIL_SUMM_SUBJECT(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
-{/////TODO: Fwd: and RE: filter!!
- message_summary *Msg = (message_summary*) Context;
- StrBufAppendBuf(Target, Msg->subj, 0);
-}
-
-
-void examine_msgn(message_summary *Msg, StrBuf *HdrLine)
-{
- FreeStrBuf(&Msg->reply_inreplyto);
- Msg->reply_inreplyto = NewStrBufPlain(NULL, StrLength(HdrLine));
- StrBuf_RFC822_to_Utf8(Msg->reply_inreplyto, HdrLine, WC->DefaultCharset);
-}
-void tmplput_MAIL_SUMM_INREPLYTO(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
-{
- message_summary *Msg = (message_summary*) Context;
- StrBufAppendBuf(Target, Msg->reply_inreplyto, 0);
-}
-
-
-void examine_wefw(message_summary *Msg, StrBuf *HdrLine)
-{
- FreeStrBuf(&Msg->reply_references);
- Msg->reply_references = NewStrBufPlain(NULL, StrLength(HdrLine));
- StrBuf_RFC822_to_Utf8(Msg->reply_references, HdrLine, WC->DefaultCharset);
-}
-void tmplput_MAIL_SUMM_REFIDS(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
-{
- message_summary *Msg = (message_summary*) Context;
- StrBufAppendBuf(Target, Msg->reply_references, 0);
-}
-
-
-void examine_cccc(message_summary *Msg, StrBuf *HdrLine)
-{
- FreeStrBuf(&Msg->cccc);
- Msg->cccc = NewStrBufPlain(NULL, StrLength(HdrLine));
- StrBuf_RFC822_to_Utf8(Msg->cccc, HdrLine, WC->DefaultCharset);
- if (Msg->AllRcpt == NULL)
- Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
- if (StrLength(Msg->AllRcpt) > 0) {
- StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
- }
- StrBufAppendBuf(Msg->AllRcpt, Msg->cccc, 0);
-}
-void tmplput_MAIL_SUMM_CCCC(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
-{
- message_summary *Msg = (message_summary*) Context;
- StrBufAppendBuf(Target, Msg->cccc, 0);
-}
-
-
-
-
-void examine_room(message_summary *Msg, StrBuf *HdrLine)
-{
- if ((StrLength(HdrLine) > 0) &&
- (strcasecmp(ChrPtr(HdrLine), WC->wc_roomname))) {
- FreeStrBuf(&Msg->Room);
- Msg->Room = NewStrBufDup(HdrLine);
- }
-}
-void tmplput_MAIL_SUMM_ORGROOM(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
-{
- message_summary *Msg = (message_summary*) Context;
- StrBufAppendBuf(Target, Msg->Room, 0);
-}
-
-
-void examine_rfca(message_summary *Msg, StrBuf *HdrLine)
-{
- FreeStrBuf(&Msg->Rfca);
- Msg->Rfca = NewStrBufDup(HdrLine);
-}
-void tmplput_MAIL_SUMM_RFCA(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
-{
- message_summary *Msg = (message_summary*) Context;
- StrBufAppendBuf(Target, Msg->Rfca, 0);
-}
-
-
-void examine_node(message_summary *Msg, StrBuf *HdrLine)
-{
- if ( (StrLength(HdrLine) > 0) &&
- ((WC->room_flags & QR_NETWORK)
- || ((strcasecmp(ChrPtr(HdrLine), serv_info.serv_nodename)
- && (strcasecmp(ChrPtr(HdrLine), serv_info.serv_fqdn)))))) {
- FreeStrBuf(&Msg->OtherNode);
- Msg->OtherNode = NewStrBufDup(HdrLine);
- }
-}
-void tmplput_MAIL_SUMM_OTHERNODE(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
-{
- message_summary *Msg = (message_summary*) Context;
- StrBufAppendBuf(Target, Msg->OtherNode, 0);
-}
-int Conditional_MAIL_SUMM_OTHERNODE(WCTemplateToken *Tokens, void *Context, int ContextType)
-{
- message_summary *Msg = (message_summary*) Context;
- return StrLength(Msg->OtherNode) > 0;
-}
-
-
-void examine_rcpt(message_summary *Msg, StrBuf *HdrLine)
-{
- FreeStrBuf(&Msg->to);
- Msg->to = NewStrBufPlain(NULL, StrLength(HdrLine));
- StrBuf_RFC822_to_Utf8(Msg->to, HdrLine, WC->DefaultCharset);
- if (Msg->AllRcpt == NULL)
- Msg->AllRcpt = NewStrBufPlain(NULL, StrLength(HdrLine));
- if (StrLength(Msg->AllRcpt) > 0) {
- StrBufAppendBufPlain(Msg->AllRcpt, HKEY(", "), 0);
- }
- StrBufAppendBuf(Msg->AllRcpt, Msg->to, 0);
-}
-void tmplput_MAIL_SUMM_TO(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
-{
- message_summary *Msg = (message_summary*) Context;
- StrBufAppendBuf(Target, Msg->to, 0);
-}
-void tmplput_MAIL_SUMM_ALLRCPT(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
-{
- message_summary *Msg = (message_summary*) Context;
- StrBufAppendBuf(Target, Msg->AllRcpt, 0);
-}
-
-
-
-void examine_time(message_summary *Msg, StrBuf *HdrLine)
-{
- Msg->date = StrTol(HdrLine);
-}
-void tmplput_MAIL_SUMM_DATE_STR(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
-{
- char datebuf[64];
- message_summary *Msg = (message_summary*) Context;
- webcit_fmt_date(datebuf, Msg->date, 1);
- StrBufAppendBufPlain(Target, datebuf, -1, 0);
-}
-void tmplput_MAIL_SUMM_DATE_NO(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
-{
- message_summary *Msg = (message_summary*) Context;
- StrBufAppendPrintf(Target, "%ld", Msg->date, 0);
-}
-
-
-
-void examine_mime_part(message_summary *Msg, StrBuf *HdrLine)
-{
- wc_mime_attachment *mime;
- StrBuf *Buf;
-
- mime = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
- memset(mime, 0, sizeof(wc_mime_attachment));
- Buf=NewStrBuf();
-
- mime->Name = NewStrBuf();
- StrBufExtract_token(mime->Name, HdrLine, 0, '|');
- StrBufExtract_token(Buf, HdrLine, 1, '|');
- StrBuf_RFC822_to_Utf8(mime->FileName, Buf, WC->DefaultCharset);
- mime->PartNum = NewStrBuf();
- StrBufExtract_token(mime->PartNum, HdrLine, 2, '|');
- mime->Disposition = NewStrBuf();
- StrBufExtract_token(mime->Disposition, HdrLine, 3, '|');
- mime->ContentType = NewStrBuf();
- StrBufExtract_token(mime->ContentType, HdrLine, 4, '|');
- mime->length = StrBufExtract_int(HdrLine, 5, '|');
-
- StrBufTrim(mime->Name);
- StrBufTrim(mime->FileName);
- if ( (StrLength(mime->FileName) == 0) && (StrLength(mime->Name) > 0) ) {
- StrBufAppendBuf(mime->FileName, mime->Name, 0);
- }
-
- if (!strcasecmp(ChrPtr(mime->ContentType), "message/rfc822")) {
- if (Msg->Submessages == NULL)
- Msg->Submessages = NewHash(1,NULL);
- Put(Msg->Submessages, SKEY(mime->PartNum), mime->PartNum, reference_free_handler);
- }
- else if ((!strcasecmp(ChrPtr(mime->Disposition), "inline"))
- && (!strncasecmp(ChrPtr(mime->ContentType), "image/", 6)) ){
- if (Msg->AttachLinks == NULL)
- Msg->AttachLinks = NewHash(1,NULL);
- Put(Msg->AttachLinks, SKEY(mime->PartNum), mime->PartNum, reference_free_handler);
- }
- else if ((StrLength(mime->ContentType) > 0) &&
- ( (!strcasecmp(ChrPtr(mime->Disposition), "attachment"))
- || (!strcasecmp(ChrPtr(mime->Disposition), "inline"))
- || (!strcasecmp(ChrPtr(mime->Disposition), ""))))
- {
-
- if (Msg->AttachLinks == NULL)
- Msg->AttachLinks = NewHash(1,NULL);
- Put(Msg->AttachLinks, SKEY(mime->PartNum), mime->PartNum, reference_free_handler);
- if (strcasecmp(ChrPtr(mime->ContentType), "application/octet-stream") == 0) {
- FlushStrBuf(mime->ContentType);
- StrBufAppendBufPlain(mime->ContentType,
- GuessMimeByFilename(SKEY(mime->FileName)),
- -1, 0);
- }
- }
-
- /** begin handler prep ** */
- if ( (!strcasecmp(ChrPtr(mime->ContentType), "text/x-vcard"))
- || (!strcasecmp(ChrPtr(mime->ContentType), "text/vcard")) ) {
- Msg->vcard_partnum_ref = mime;
- }
- else if ( (!strcasecmp(ChrPtr(mime->ContentType), "text/calendar"))
- || (!strcasecmp(ChrPtr(mime->ContentType), "application/ics")) ) {
- Msg->cal_partnum_ref = mime;
- }
- /** end handler prep ***/
-}
-void tmplput_MAIL_SUMM_NATTACH(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
-{
- message_summary *Msg = (message_summary*) Context;
- StrBufAppendPrintf(Target, "%ld", GetCount(Msg->Attachments));
-}
-
-
-
-
-
-
-
-void examine_hnod(message_summary *Msg, StrBuf *HdrLine)
-{
- FreeStrBuf(&Msg->hnod);
- Msg->hnod = NewStrBufPlain(NULL, StrLength(HdrLine));
- StrBuf_RFC822_to_Utf8(Msg->hnod, HdrLine, WC->DefaultCharset);
-}
-void tmplput_MAIL_SUMM_H_NODE(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
-{
- message_summary *Msg = (message_summary*) Context;
- StrBufAppendBuf(Target, Msg->hnod, 0);
-}
-int Conditional_MAIL_SUMM_H_NODE(WCTemplateToken *Tokens, void *Context, int ContextType)
-{
- message_summary *Msg = (message_summary*) Context;
- return StrLength(Msg->hnod) > 0;
-}
-
-
-
-void examine_text(message_summary *Msg, StrBuf *HdrLine)
-{////TODO: read messages here
- Msg->MsgBody.Data = NewStrBuf();
-}
-
-void examine_msg4_partnum(message_summary *Msg, StrBuf *HdrLine)
-{
- Msg->MsgBody.PartNum = NewStrBufDup(HdrLine);
- StrBufTrim(Msg->MsgBody.PartNum);/////TODO: striplt == trim?
-}
-
-void examine_content_encoding(message_summary *Msg, StrBuf *HdrLine)
-{
-////TODO: do we care?
-}
-
-void examine_content_lengh(message_summary *Msg, StrBuf *HdrLine)
-{
- Msg->MsgBody.length = StrTol(HdrLine);
-}
-
-void examine_content_type(message_summary *Msg, StrBuf *HdrLine)
-{////TODO
- int len, i;
- Msg->MsgBody.ContentType = NewStrBufDup(HdrLine);
- StrBufTrim(Msg->MsgBody.ContentType);/////todo==striplt?
- len = StrLength(Msg->MsgBody.ContentType);
- for (i=0; i<len; ++i) {
- if (!strncasecmp(ChrPtr(Msg->MsgBody.ContentType) + i, "charset=", 8)) {/// TODO: WHUT?
-// safestrncpy(mime_charset, &mime_content_type[i+8],
- /// sizeof mime_charset);
- }
- }/****
- for (i=0; i<len; ++i) {
- if (mime_content_type[i] == ';') {
- mime_content_type[i] = 0;
- len = i - 1;
- }
- }
- len = strlen(mime_charset);
- for (i=0; i<len; ++i) {
- if (mime_charset[i] == ';') {
- mime_charset[i] = 0;
- len = i - 1;
- }
- }
- */
-}
-
-void tmplput_MAIL_SUMM_N(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
-{
- message_summary *Msg = (message_summary*) Context;
- StrBufAppendPrintf(Target, "%ld", Msg->msgnum);
-}
-
-
-int Conditional_MAIL_SUMM_UNREAD(WCTemplateToken *Tokens, void *Context, int ContextType)
-{
- message_summary *Msg = (message_summary*) Context;
- return Msg->is_new != 0;
-}
-
-
-
-/*----------------------------------------------------------------------------*/
-
-
-void tmplput_MAIL_BODY(StrBuf *Target, int nArgs, WCTemplateToken *Token, void *Context, int ContextType)
-{
- message_summary *Msg = (message_summary*) Context;
- StrBufAppendBuf(Target, Msg->MsgBody.Data, 0);
-}
-
-
-void render_MAIL_variformat(wc_mime_attachment *Mime, StrBuf *RawData)
-{
- /* Messages in legacy Citadel variformat get handled thusly... */
- fmout("JUSTIFY");///todo: this won't work that way.
-
-}
-
-void render_MAIL_text_plain(wc_mime_attachment *Mime, StrBuf *RawData)
-{
- const char *ptr, *pte;
- const char *BufPtr = NULL;
- StrBuf *Line = NewStrBuf();
- StrBuf *Line1 = NewStrBuf();
- StrBuf *Line2 = NewStrBuf();
- StrBuf *Target = NewStrBufPlain(NULL, StrLength(Mime->Data));
- int ConvertIt = 1;
- int bn = 0;
- int bq = 0;
- int i;
- long len;
-#ifdef HAVE_ICONV
- iconv_t ic = (iconv_t)(-1) ;
-#endif
-
- /* Boring old 80-column fixed format text gets handled this way... */
- if ((strcasecmp(ChrPtr(Mime->Charset), "us-ascii") == 0) &&
- (strcasecmp(ChrPtr(Mime->Charset), "UTF-8") == 0))
- ConvertIt = 0;
-
-#ifdef HAVE_ICONV
- if (ConvertIt) {
- ctdl_iconv_open("UTF-8", ChrPtr(Mime->Charset), &ic);
- if (ic == (iconv_t)(-1) ) {
- lprintf(5, "%s:%d iconv_open(UTF-8, %s) failed: %s\n",
- __FILE__, __LINE__, ChrPtr(Mime->Charset), strerror(errno));
- }
- }
-#endif
-
- while (StrBufSipLine(Line, Mime->Data, &BufPtr) > 0)
- {
- bq = 0;
- i = 0;
-
- ptr = ChrPtr(Line);
- len = StrLength(Line);
- pte = ptr + len;
-
- while ((ptr < pte) &&
- ((*ptr == '>') ||
- isspace(*ptr)))
- {
- if (*ptr == '>')
- bq++;
- ptr ++;
- i++;
- }
- if (i > 0) StrBufCutLeft(Line, i);
-
- if (StrLength(Line) == 0)
- continue;
-
- for (i = bn; i < bq; i++)
- StrBufAppendBufPlain(Target, HKEY("<blockquote>"), 0);
- for (i = bq; i < bn; i++)
- StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
-
- StrBufAppendBufPlain(Target, HKEY("<tt>"), 0);
- UrlizeText(Line1, Line, Line2);
-
- StrEscAppend(Target, Line1, NULL, 0, 0);
- StrBufAppendBufPlain(Target, HKEY("</tt><br />\n"), 0);
- bn = bq;
- }
-
- for (i = bq; i < bn; i++)
- StrBufAppendBufPlain(Target, HKEY("</blockquote>"), 0);
-
- StrBufAppendBufPlain(Target, HKEY("</i><br />"), 0);
-#ifdef HAVE_ICONV
- if (ic != (iconv_t)(-1) ) {
- iconv_close(ic);
- }
-#endif
- FreeStrBuf(&Mime->Data);
- Mime->Data = Target;
-
-}
-
-void render_MAIL_html(wc_mime_attachment *Mime, StrBuf *RawData)
-{
- StrBuf *Buf;
- /* HTML is fun, but we've got to strip it first */
- Buf = NewStrBufPlain(NULL, StrLength(Mime->Data));
- output_html(ChrPtr(Mime->Charset),
- (WC->wc_view == VIEW_WIKI ? 1 : 0),
- StrToi(Mime->PartNum),
- Mime->Data, Buf);
- FreeStrBuf(&Mime->Data);
- Mime->Data = Buf;
-}
-
-void render_MAIL_UNKNOWN(wc_mime_attachment *Mime, StrBuf *RawData)
-{
- /* Unknown weirdness */
-//// wprintf(_("I don't know how to display %s"), Msg->MsgBody->ContentType);
- wprintf("<br />\n");
-}
-
-
-
-
-
-
-
-/*
- * Look for URL's embedded in a buffer and make them linkable. We use a
- * target window in order to keep the Citadel session in its own window.
- */
-void UrlizeText(StrBuf* Target, StrBuf *Source, StrBuf *WrkBuf)
-{
- int len, UrlLen, Offset, TrailerLen;
- const char *start, *end, *pos;
-
- FlushStrBuf(Target);
-
- start = NULL;
- len = StrLength(Source);
- end = ChrPtr(Source) + len;
- for (pos = ChrPtr(Source); (pos < end) && (start == NULL); ++pos) {
- if (!strncasecmp(pos, "http://", 7))
- start = pos;
- if (!strncasecmp(pos, "ftp://", 6))
- start = pos;
- }
-
- if (start == NULL) {
- StrBufAppendBuf(Target, Source, 0);
- return;
- }
- FlushStrBuf(WrkBuf);
-
- for (pos = ChrPtr(Source) + len; pos > start; --pos) {
- if ( (!isprint(*pos))
- || (isspace(*pos))
- || (*pos == '{')
- || (*pos == '}')
- || (*pos == '|')
- || (*pos == '\\')
- || (*pos == '^')
- || (*pos == '[')
- || (*pos == ']')
- || (*pos == '`')
- || (*pos == '<')
- || (*pos == '>')
- || (*pos == '(')
- || (*pos == ')')
- ) {
- end = pos;
- }
- }
-
- UrlLen = end - start;
- StrBufAppendBufPlain(WrkBuf, start, UrlLen, 0);
-
- Offset = start - ChrPtr(Source);
- if (Offset != 0)
- StrBufAppendBufPlain(Target, ChrPtr(Source), Offset, 0);
- StrBufAppendPrintf(Target, "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
- LB, QU, ChrPtr(WrkBuf), QU, QU, TARGET,
- QU, RB, ChrPtr(WrkBuf), LB, RB);
-
- TrailerLen = len - (end - start);
- if (TrailerLen > 0)
- StrBufAppendBufPlain(Target, end, TrailerLen, 0);
-}
-void url(char *buf, size_t bufsize)
-{
- int len, UrlLen, Offset, TrailerLen, outpos;
- char *start, *end, *pos;
- char urlbuf[SIZ];
- char outbuf[SIZ];
-
- start = NULL;
- len = strlen(buf);
- if (len > bufsize) {
- lprintf(1, "URL: content longer than buffer!");
- return;
- }
- end = buf + len;
- for (pos = buf; (pos < end) && (start == NULL); ++pos) {
- if (!strncasecmp(pos, "http://", 7))
- start = pos;
- if (!strncasecmp(pos, "ftp://", 6))
- start = pos;
- }
-
- if (start == NULL)
- return;
-
- for (pos = buf+len; pos > start; --pos) {
- if ( (!isprint(*pos))
- || (isspace(*pos))
- || (*pos == '{')
- || (*pos == '}')
- || (*pos == '|')
- || (*pos == '\\')
- || (*pos == '^')
- || (*pos == '[')
- || (*pos == ']')
- || (*pos == '`')
- || (*pos == '<')
- || (*pos == '>')
- || (*pos == '(')
- || (*pos == ')')
- ) {
- end = pos;
- }
- }
-
- UrlLen = end - start;
- if (UrlLen > sizeof(urlbuf)){
- lprintf(1, "URL: content longer than buffer!");
- return;
- }
- memcpy(urlbuf, start, UrlLen);
- urlbuf[UrlLen] = '\0';
-
- Offset = start - buf;
- if ((Offset != 0) && (Offset < sizeof(outbuf)))
- memcpy(outbuf, buf, Offset);
- outpos = snprintf(&outbuf[Offset], sizeof(outbuf) - Offset,
- "%ca href=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
- LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
- if (outpos >= sizeof(outbuf) - Offset) {
- lprintf(1, "URL: content longer than buffer!");
- return;
- }
-
- TrailerLen = len - (end - start);
- if (TrailerLen > 0)
- memcpy(outbuf + Offset + outpos, end, TrailerLen);
- if (Offset + outpos + TrailerLen > bufsize) {
- lprintf(1, "URL: content longer than buffer!");
- return;
- }
- memcpy (buf, outbuf, Offset + outpos + TrailerLen);
- *(buf + Offset + outpos + TrailerLen) = '\0';
-}
-
-
-/**
- * \brief Turn a vCard "n" (name) field into something displayable.
- * \param name the name field to convert
- */
-void vcard_n_prettyize(char *name)
-{
- char *original_name;
- int i, j, len;
-
- original_name = strdup(name);
- len = strlen(original_name);
- for (i=0; i<5; ++i) {
- if (len > 0) {
- if (original_name[len-1] == ' ') {
- original_name[--len] = 0;
- }
- if (original_name[len-1] == ';') {
- original_name[--len] = 0;
- }
- }
- }
- strcpy(name, "");
- j=0;
- for (i=0; i<len; ++i) {
- if (original_name[i] == ';') {
- name[j++] = ',';
- name[j++] = ' ';
- }
- else {
- name[j++] = original_name[i];
- }
- }
- name[j] = '\0';
- free(original_name);
-}
-
-
-
-
-/**
- * \brief preparse a vcard name
- * display_vcard() calls this after parsing the textual vCard into
- * our 'struct vCard' data object.
- * This gets called instead of display_parsed_vcard() if we are only looking
- * to extract the person's name instead of displaying the card.
- * \param v the vcard to retrieve the name from
- * \param storename where to put the name at
- */
-void fetchname_parsed_vcard(struct vCard *v, char *storename) {
- char *name;
-
- strcpy(storename, "");
-
- name = vcard_get_prop(v, "n", 1, 0, 0);
- if (name != NULL) {
- strcpy(storename, name);
- /* vcard_n_prettyize(storename); */
- }
-
-}
-
-
-
-/**
- * \brief html print a vcard
- * display_vcard() calls this after parsing the textual vCard into
- * our 'struct vCard' data object.
- *
- * Set 'full' to nonzero to display the full card, otherwise it will only
- * show a summary line.
- *
- * This code is a bit ugly, so perhaps an explanation is due: we do this
- * in two passes through the vCard fields. On the first pass, we process
- * fields we understand, and then render them in a pretty fashion at the
- * end. Then we make a second pass, outputting all the fields we don't
- * understand in a simple two-column name/value format.
- * \param v the vCard to display
- * \param full display all items of the vcard?
- * \param msgnum Citadel message pointer
- */
-void display_parsed_vcard(struct vCard *v, int full, long msgnum) {
- int i, j;
- char buf[SIZ];
- char *name;
- int is_qp = 0;
- int is_b64 = 0;
- char *thisname, *thisvalue;
- char firsttoken[SIZ];
- int pass;
-
- char fullname[SIZ];
- char title[SIZ];
- char org[SIZ];
- char phone[SIZ];
- char mailto[SIZ];
-
- strcpy(fullname, "");
- strcpy(phone, "");
- strcpy(mailto, "");
- strcpy(title, "");
- strcpy(org, "");
-
- if (!full) {
- wprintf("<TD>");
- name = vcard_get_prop(v, "fn", 1, 0, 0);
- if (name != NULL) {
- escputs(name);
- }
- else if (name = vcard_get_prop(v, "n", 1, 0, 0), name != NULL) {
- strcpy(fullname, name);
- vcard_n_prettyize(fullname);
- escputs(fullname);
- }
- else {
- wprintf(" ");
- }
- wprintf("</TD>");
- return;
- }
-
- wprintf("<div align=center>"
- "<table bgcolor=#aaaaaa width=50%%>");
- for (pass=1; pass<=2; ++pass) {
-
- if (v->numprops) for (i=0; i<(v->numprops); ++i) {
- int len;
- thisname = strdup(v->prop[i].name);
- extract_token(firsttoken, thisname, 0, ';', sizeof firsttoken);
-
- for (j=0; j<num_tokens(thisname, ';'); ++j) {
- extract_token(buf, thisname, j, ';', sizeof buf);
- if (!strcasecmp(buf, "encoding=quoted-printable")) {
- is_qp = 1;
- remove_token(thisname, j, ';');
- }
- if (!strcasecmp(buf, "encoding=base64")) {
- is_b64 = 1;
- remove_token(thisname, j, ';');
- }
- }
-
- len = strlen(v->prop[i].value);
- /* if we have some untagged QP, detect it here. */
- if (!is_qp && (strstr(v->prop[i].value, "=?")!=NULL))
- utf8ify_rfc822_string(v->prop[i].value);
-
- if (is_qp) {
- // %ff can become 6 bytes in utf8
- thisvalue = malloc(len * 2 + 3);
- j = CtdlDecodeQuotedPrintable(
- thisvalue, v->prop[i].value,
- len);
- thisvalue[j] = 0;
- }
- else if (is_b64) {
- // ff will become one byte..
- thisvalue = malloc(len + 50);
- CtdlDecodeBase64(
- thisvalue, v->prop[i].value,
- strlen(v->prop[i].value) );
- }
- else {
- thisvalue = strdup(v->prop[i].value);
- }
-
- /** Various fields we may encounter ***/
-
- /** N is name, but only if there's no FN already there */
- if (!strcasecmp(firsttoken, "n")) {
- if (IsEmptyStr(fullname)) {
- strcpy(fullname, thisvalue);
- vcard_n_prettyize(fullname);
- }
- }
-
- /** FN (full name) is a true 'display name' field */
- else if (!strcasecmp(firsttoken, "fn")) {
- strcpy(fullname, thisvalue);
- }
-
- /** title */
- else if (!strcasecmp(firsttoken, "title")) {
- strcpy(title, thisvalue);
- }
-
- /** organization */
- else if (!strcasecmp(firsttoken, "org")) {
- strcpy(org, thisvalue);
- }
-
- else if (!strcasecmp(firsttoken, "email")) {
- size_t len;
- if (!IsEmptyStr(mailto)) strcat(mailto, "<br />");
- strcat(mailto,
- "<a href=\"display_enter"
- "?force_room=_MAIL_?recp=");
-
- len = strlen(mailto);
- urlesc(&mailto[len], SIZ - len, "\"");
- len = strlen(mailto);
- urlesc(&mailto[len], SIZ - len, fullname);
- len = strlen(mailto);
- urlesc(&mailto[len], SIZ - len, "\" <");
- len = strlen(mailto);
- urlesc(&mailto[len], SIZ - len, thisvalue);
- len = strlen(mailto);
- urlesc(&mailto[len], SIZ - len, ">");
-
- strcat(mailto, "\">");
- len = strlen(mailto);
- stresc(mailto+len, SIZ - len, thisvalue, 1, 1);
- strcat(mailto, "</A>");
- }
- else if (!strcasecmp(firsttoken, "tel")) {
- if (!IsEmptyStr(phone)) strcat(phone, "<br />");
- strcat(phone, thisvalue);
- for (j=0; j<num_tokens(thisname, ';'); ++j) {
- extract_token(buf, thisname, j, ';', sizeof buf);
- if (!strcasecmp(buf, "tel"))
- strcat(phone, "");
- else if (!strcasecmp(buf, "work"))
- strcat(phone, _(" (work)"));
- else if (!strcasecmp(buf, "home"))
- strcat(phone, _(" (home)"));
- else if (!strcasecmp(buf, "cell"))
- strcat(phone, _(" (cell)"));
- else {
- strcat(phone, " (");
- strcat(phone, buf);
- strcat(phone, ")");
- }
- }
- }
- else if (!strcasecmp(firsttoken, "adr")) {
- if (pass == 2) {
- wprintf("<TR><TD>");
- wprintf(_("Address:"));
- wprintf("</TD><TD>");
- for (j=0; j<num_tokens(thisvalue, ';'); ++j) {
- extract_token(buf, thisvalue, j, ';', sizeof buf);
- if (!IsEmptyStr(buf)) {
- escputs(buf);
- if (j<3) wprintf("<br />");
- else wprintf(" ");
- }
- }
- wprintf("</TD></TR>\n");
- }
- }
- /* else if (!strcasecmp(firsttoken, "photo") && full && pass == 2) {
- // Only output on second pass
- wprintf("<tr><td>");
- wprintf(_("Photo:"));
- wprintf("</td><td>");
- wprintf("<img src=\"/vcardphoto/%ld/\" alt=\"Contact photo\"/>",msgnum);
- wprintf("</td></tr>\n");
- } */
- else if (!strcasecmp(firsttoken, "version")) {
- /* ignore */
- }
- else if (!strcasecmp(firsttoken, "rev")) {
- /* ignore */
- }
- else if (!strcasecmp(firsttoken, "label")) {
- /* ignore */
- }
- else {
-
- /*** Don't show extra fields. They're ugly.
- if (pass == 2) {
- wprintf("<TR><TD>");
- escputs(thisname);
- wprintf("</TD><TD>");
- escputs(thisvalue);
- wprintf("</TD></TR>\n");
- }
- ***/
- }
-
- free(thisname);
- free(thisvalue);
- }
-
- if (pass == 1) {
- wprintf("<TR BGCOLOR=\"#AAAAAA\">"
- "<TD COLSPAN=2 BGCOLOR=\"#FFFFFF\">"
- "<IMG ALIGN=CENTER src=\"static/viewcontacts_48x.gif\">"
- "<FONT SIZE=+1><B>");
- escputs(fullname);
- wprintf("</B></FONT>");
- if (!IsEmptyStr(title)) {
- wprintf("<div align=right>");
- escputs(title);
- wprintf("</div>");
- }
- if (!IsEmptyStr(org)) {
- wprintf("<div align=right>");
- escputs(org);
- wprintf("</div>");
- }
- wprintf("</TD></TR>\n");
-
- if (!IsEmptyStr(phone)) {
- wprintf("<tr><td>");
- wprintf(_("Telephone:"));
- wprintf("</td><td>%s</td></tr>\n", phone);
- }
- if (!IsEmptyStr(mailto)) {
- wprintf("<tr><td>");
- wprintf(_("E-mail:"));
- wprintf("</td><td>%s</td></tr>\n", mailto);
- }
- }
-
- }
-
- wprintf("</table></div>\n");
-}
-
-
-
-/**
- * \brief Display a textual vCard
- * (Converts to a vCard object and then calls the actual display function)
- * Set 'full' to nonzero to display the whole card instead of a one-liner.
- * Or, if "storename" is non-NULL, just store the person's name in that
- * buffer instead of displaying the card at all.
- * \param vcard_source the buffer containing the vcard text
- * \param alpha what???
- * \param full should we usse all lines?
- * \param storename where to store???
- * \param msgnum Citadel message pointer
- */
-void display_vcard(char *vcard_source, char alpha, int full, char *storename,
- long msgnum) {
- struct vCard *v;
- char *name;
- char buf[SIZ];
- char this_alpha = 0;
-
- v = vcard_load(vcard_source);
- if (v == NULL) return;
-
- name = vcard_get_prop(v, "n", 1, 0, 0);
- if (name != NULL) {
- utf8ify_rfc822_string(name);
- strcpy(buf, name);
- this_alpha = buf[0];
- }
-
- if (storename != NULL) {
- fetchname_parsed_vcard(v, storename);
- }
- else if ( (alpha == 0)
- || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
- || ((!isalpha(alpha)) && (!isalpha(this_alpha)))
- ) {
- display_parsed_vcard(v, full,msgnum);
- }
-
- vcard_free(v);
-}
-
-
-