ICAL: some work on adding ical items into templates
authorWilfried Goesgens <dothebart@citadel.org>
Mon, 3 Sep 2012 21:26:51 +0000 (23:26 +0200)
committerWilfried Goesgens <dothebart@citadel.org>
Mon, 3 Sep 2012 21:26:51 +0000 (23:26 +0200)
webcit/ical_subst.c
webcit/msg_renderers.c
webcit/static/t/ical/attachment/display.html [new file with mode: 0644]

index aceb56c2816fc5d395db745c29e2464287375f6b..32b7382e9bdf26822d4f070104178c991cf45101 100644 (file)
@@ -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, "<br>\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 
index 8de9f45d53be633716ea8ad3daf4c5ff730c6479..312640bdc807dac489b55ee706430848d46741cc 100644 (file)
@@ -1565,8 +1565,10 @@ InitModule_MSGRENDERERS
        RegisterMimeRenderer(HKEY("message/rfc822"), render_MAIL, 0, 150);
        RegisterMimeRenderer(HKEY("text/x-vcard"), render_MIME_VCard, 1, 201);
        RegisterMimeRenderer(HKEY("text/vcard"), render_MIME_VCard, 1, 200);
+/*
        RegisterMimeRenderer(HKEY("text/calendar"), render_MIME_ICS, 1, 501);
        RegisterMimeRenderer(HKEY("application/ics"), render_MIME_ICS, 1, 500);
+*/
        RegisterMimeRenderer(HKEY("text/x-citadel-variformat"), render_MAIL_variformat, 1, 2);
        RegisterMimeRenderer(HKEY("text/plain"), render_MAIL_text_plain, 1, 3);
        RegisterMimeRenderer(HKEY("text"), render_MAIL_text_plain, 1, 1);
diff --git a/webcit/static/t/ical/attachment/display.html b/webcit/static/t/ical/attachment/display.html
new file mode 100644 (file)
index 0000000..f5a3c51
--- /dev/null
@@ -0,0 +1,14 @@
+abc
+
+<?ICAL:ITEM(#"ICAL_SUMMARY_PROPERTY", "X")>
+
+cde
+
+<?ICAL:ITEM(#"ICAL_LOCATION_PROPERTY", "X")>
+
+efg
+
+
+<?ICAL:ITEM(#"ICAL_DESCRIPTION_PROPERTY", "X")>
+
+hij