+void tmplput_ICalDate(StrBuf *Target, WCTemplputParams *TP)
+{
+ icalcomponent *cal = (icalcomponent *) CTX(CTX_ICAL);
+ icalproperty *p;
+ icalproperty_kind Kind;
+ struct icaltimetype t;
+ time_t tt;
+ char buf[256];
+
+ 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 tmplput_CtxICalPropertyDate(StrBuf *Target, WCTemplputParams *TP)
+{
+ icalproperty *p = (icalproperty *) CTX(CTX_ICALPROPERTY);
+ struct icaltimetype t;
+ time_t tt;
+ char buf[256];
+
+ long len;
+ t = icalproperty_get_dtend(p);
+ tt = icaltime_as_timet(t);
+ len = webcit_fmt_date(buf, sizeof(buf), tt, DATEFMT_FULL);
+ StrBufAppendBufPlain(Target, buf, len, 0);
+}
+
+
+
+void render_MIME_ICS_TPL(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharset)
+{
+ wc_mime_attachment *Mime = CTX(CTX_MIME_ATACH);
+ icalproperty_method the_method = ICAL_METHOD_NONE;
+ icalproperty *method = NULL;
+ icalcomponent *cal = NULL;
+ icalcomponent *c = NULL;
+ WCTemplputParams SubTP;
+ WCTemplputParams SuperTP;
+
+ static int divcount = 0;
+
+ 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, "<br>\n");
+ return;
+ }
+
+ putlbstr("divname", ++divcount);
+
+
+ putbstr("cal_partnum", NewStrBufDup(Mime->PartNum));
+ putlbstr("msgnum", Mime->msgnum);
+
+ memset(&SubTP, 0, sizeof(WCTemplputParams));
+ memset(&SuperTP, 0, sizeof(WCTemplputParams));
+
+ /*//ical_dezonify(cal); */
+
+ /* If the component has subcomponents, recurse through them. */
+ c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT);
+ c = (c != NULL) ? c : cal;
+
+ method = icalcomponent_get_first_property(cal, ICAL_METHOD_PROPERTY);
+ if (method != NULL) {
+ the_method = icalproperty_get_method(method);
+ }
+
+ StackContext (TP,
+ &SuperTP,
+ &the_method,
+ CTX_ICALMETHOD,
+ 0,
+ TP->Tokens);
+
+ StackContext (&SuperTP,
+ &SubTP,
+ c,
+ CTX_ICAL,
+ 0,
+ SuperTP.Tokens);
+ FlushStrBuf(Mime->Data);
+/// DoTemplate(HKEY("ical_attachment_display"), Mime->Data, &SubTP);
+ DoTemplate(HKEY("ical_edit"), Mime->Data, &SubTP);
+
+ /*/ cal_process_object(Mime->Data, cal, 0, Mime->msgnum, ChrPtr(Mime->PartNum)); */
+
+ /* Free the memory we obtained from libical's constructor */
+ StrBufPlain(Mime->ContentType, HKEY("text/html"));
+ StrBufAppendPrintf(WC->trailing_javascript,
+ "eventEditAllDay(); \n"
+ "RecurrenceShowHide(); \n"
+ "EnableOrDisableCheckButton(); \n"
+ );
+
+ UnStackContext(&SuperTP);
+ UnStackContext(&SubTP);
+ icalcomponent_free(cal);
+}