X-Git-Url: https://code.citadel.org/?p=citadel.git;a=blobdiff_plain;f=webcit%2Fical_subst.c;fp=webcit%2Fical_subst.c;h=32b7382e9bdf26822d4f070104178c991cf45101;hp=aceb56c2816fc5d395db745c29e2464287375f6b;hb=4b3f4300c703d75b6f48661212be26d25eff2927;hpb=82f8cebefd325c7eb8b98c6025bd43633fa9cd90 diff --git a/webcit/ical_subst.c b/webcit/ical_subst.c index aceb56c28..32b7382e9 100644 --- a/webcit/ical_subst.c +++ b/webcit/ical_subst.c @@ -77,9 +77,78 @@ void SortPregetMatter(HashList *Cals) void tmplput_ICalItem(StrBuf *Target, WCTemplputParams *TP) { + icalcomponent *cal = (icalcomponent *) CTX(CTX_ICAL); + icalproperty *p; + icalproperty_kind Kind; + const char *str; + + Kind = (icalproperty_kind) GetTemplateTokenNumber(Target, TP, 0, ICAL_ANY_PROPERTY); + p = icalcomponent_get_first_property(cal, Kind); + if (p != NULL) { + str = icalproperty_get_comment (p); + StrBufAppendTemplateStr(Target, TP, str, 1); + } +} +void tmplput_ICalDate(StrBuf *Target, WCTemplputParams *TP) +{ + icalcomponent *cal = (icalcomponent *) CTX(CTX_ICAL); + icalproperty *p; + icalproperty_kind Kind; + const char *str; + struct icaltimetype t; + time_t tt; + + Kind = (icalproperty_kind) GetTemplateTokenNumber(Target, TP, 0, ICAL_ANY_PROPERTY); + p = icalcomponent_get_first_property(cal, Kind); + if (p != NULL) { + long len; + t = icalproperty_get_dtend(p); + tt = icaltime_as_timet(t); + len = webcit_fmt_date(buf, 256, tt, DATEFMT_FULL); + StrBufAppendBufPlain(Target, buf, len, 0); + } } + + +void render_MIME_ICS_TPL(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset) +{ + icalcomponent *cal; + icalcomponent *c; + WCTemplputParams SubTP; + + + if (StrLength(Mime->Data) == 0) { + MimeLoadData(Mime); + } + if (StrLength(Mime->Data) > 0) { + cal = icalcomponent_new_from_string(ChrPtr(Mime->Data)); + } + if (cal == NULL) { + StrBufAppendPrintf(Mime->Data, _("There was an error parsing this calendar item.")); + StrBufAppendPrintf(Mime->Data, "
\n"); + return; + } + + memset(&SubTP, 0, sizeof(WCTemplputParams)); + SubTP.Filter.ContextType = CTX_ICAL; + + ical_dezonify(cal); + + /* If the component has subcomponents, recurse through them. */ + c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT); + + SubTP.Context = (c != NULL) ? c : cal; + + FlushStrBuf(Mime->Data); + DoTemplate(HKEY("ical_attachment_display"), Mime->Data, &SubTP); + + cal_process_object(Mime->Data, cal, 0, Mime->msgnum, ChrPtr(Mime->PartNum)); + + /* Free the memory we obtained from libical's constructor */ + icalcomponent_free(cal); +} void CreateIcalComponendKindLookup(void) { int i = 0; @@ -123,9 +192,21 @@ void InitModule_ICAL_SUBST (void) { + int i; + for (i=0; icalproperty_kind_map[i].NameLen > 0; i++) + RegisterTokenParamDefine ( + icalproperty_kind_map[i].Name, + icalproperty_kind_map[i].NameLen, + icalproperty_kind_map[i].map); + + RegisterCTX(CTX_ICAL); + RegisterMimeRenderer(HKEY("text/calendar"), render_MIME_ICS_TPL, 1, 501); + RegisterMimeRenderer(HKEY("application/ics"), render_MIME_ICS_TPL, 1, 500); CreateIcalComponendKindLookup (); + RegisterNamespace("ICAL:ITEM", 1, 2, tmplput_ICalItem, NULL, CTX_ICAL); + } void