2 * Copyright (c) 1996-2012 by the citadel.org team
4 * This program is open source software. You can redistribute it and/or
5 * modify it under the terms of the GNU General Public License, version 3.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
15 extern IcalEnumMap icalproperty_kind_map[];
17 HashList *IcalComponentMap = NULL;
18 CtxType CTX_ICAL = CTX_NONE;
20 void SortPregetMatter(HashList *Cals)
26 IcalEnumMap *SortMap[10];
29 const char *Next = NULL;
30 const StrBuf *SortVector;
35 SortVector = SBSTR("ICALSortVec");
36 if (SortVector == NULL)
39 for (i = 0; i < 10; i++) SortMap[i] = NULL;
41 while (StrBufExtract_NextToken(SortBy, SortVector, &Next, ':') > 0) {
42 GetHash(IcalComponentMap, SKEY(SortBy), &vSort);
43 Map = (IcalEnumMap*) vSort;
53 switch (SortMap[i - 1]->map) {
60 It = GetNewHashPos(Cals, 0);
61 while (GetNextHashPos(Cals, It, &KLen, &Key, &vCal)) {
63 Cal = (disp_cal*) vCal;
64 Cal->Status = icalcomponent_get_status(Cal->cal);
65 Cal->SortBy = Cal->cal;
68 while ((SortMap[i] != NULL) &&
69 (Cal->SortBy != NULL))
71 /****Cal->SortBy = icalcomponent_get_first_property(Cal->SortBy, SortMap[i++]->map); */
78 void tmplput_ICalItem(StrBuf *Target, WCTemplputParams *TP)
80 icalcomponent *cal = (icalcomponent *) CTX(CTX_ICAL);
82 icalproperty_kind Kind;
85 Kind = (icalproperty_kind) GetTemplateTokenNumber(Target, TP, 0, ICAL_ANY_PROPERTY);
86 p = icalcomponent_get_first_property(cal, Kind);
88 str = icalproperty_get_comment (p);
89 StrBufAppendTemplateStr(Target, TP, str, 1);
93 void tmplput_ICalDate(StrBuf *Target, WCTemplputParams *TP)
95 icalcomponent *cal = (icalcomponent *) CTX(CTX_ICAL);
97 icalproperty_kind Kind;
98 struct icaltimetype t;
102 Kind = (icalproperty_kind) GetTemplateTokenNumber(Target, TP, 0, ICAL_ANY_PROPERTY);
103 p = icalcomponent_get_first_property(cal, Kind);
106 t = icalproperty_get_dtend(p);
107 tt = icaltime_as_timet(t);
108 len = webcit_fmt_date(buf, 256, tt, DATEFMT_FULL);
109 StrBufAppendBufPlain(Target, buf, len, 0);
115 void render_MIME_ICS_TPL(wc_mime_attachment *Mime, StrBuf *RawData, StrBuf *FoundCharset)
119 WCTemplputParams SubTP;
122 if (StrLength(Mime->Data) == 0) {
125 if (StrLength(Mime->Data) > 0) {
126 cal = icalcomponent_new_from_string(ChrPtr(Mime->Data));
129 StrBufAppendPrintf(Mime->Data, _("There was an error parsing this calendar item."));
130 StrBufAppendPrintf(Mime->Data, "<br>\n");
134 memset(&SubTP, 0, sizeof(WCTemplputParams));
135 SubTP.Filter.ContextType = CTX_ICAL;
137 ///ical_dezonify(cal);
139 /* If the component has subcomponents, recurse through them. */
140 c = icalcomponent_get_first_component(cal, ICAL_ANY_COMPONENT);
142 SubTP.Context = (c != NULL) ? c : cal;
144 FlushStrBuf(Mime->Data);
145 DoTemplate(HKEY("ical_attachment_display"), Mime->Data, &SubTP);
147 // cal_process_object(Mime->Data, cal, 0, Mime->msgnum, ChrPtr(Mime->PartNum));
149 /* Free the memory we obtained from libical's constructor */
150 icalcomponent_free(cal);
152 void CreateIcalComponendKindLookup(void)
156 IcalComponentMap = NewHash (1, NULL);
157 while (icalproperty_kind_map[i].NameLen != 0) {
158 RegisterNS(icalproperty_kind_map[i].Name,
159 icalproperty_kind_map[i].NameLen,
165 Put(IcalComponentMap,
166 icalproperty_kind_map[i].Name,
167 icalproperty_kind_map[i].NameLen,
168 &icalproperty_kind_map[i],
169 reference_free_handler);
192 InitModule_ICAL_SUBST
196 for (i=0; icalproperty_kind_map[i].NameLen > 0; i++)
197 RegisterTokenParamDefine (
198 icalproperty_kind_map[i].Name,
199 icalproperty_kind_map[i].NameLen,
200 icalproperty_kind_map[i].map);
203 RegisterCTX(CTX_ICAL);
204 RegisterMimeRenderer(HKEY("text/calendar"), render_MIME_ICS_TPL, 1, 501);
205 RegisterMimeRenderer(HKEY("application/ics"), render_MIME_ICS_TPL, 1, 500);
206 CreateIcalComponendKindLookup ();
207 RegisterNamespace("ICAL:ITEM", 1, 2, tmplput_ICalItem, NULL, CTX_ICAL);
213 ServerShutdownModule_ICAL
216 DeleteHash(&IcalComponentMap);