/*
- * Copyright (c) 1996-2011 by the citadel.org team
+ * Copyright (c) 1996-2012 by the citadel.org team
*
* This program is open source software. You can redistribute it and/or
- * modify it under the terms of the GNU General Public License as
- * published by the Free Software Foundation; either version 3 of the
- * License, or (at your option) any later version.
+ * modify it under the terms of the GNU General Public License, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include "webcit.h"
extern IcalEnumMap icalproperty_kind_map[];
HashList *IcalComponentMap = NULL;
-
+CtxType CTX_ICAL = CTX_NONE;
#if 0
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;
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