+/*
+ * html print a vcard
+ * display_vcard() calls this after parsing the textual vCard into
+ * our 'struct vCard' data object.
+ *
+ * Set 'full' to nonzero to display the full card, otherwise it will only
+ * show a summary line.
+ *
+ * This code is a bit ugly, so perhaps an explanation is due: we do this
+ * in two passes through the vCard fields. On the first pass, we process
+ * fields we understand, and then render them in a pretty fashion at the
+ * end. Then we make a second pass, outputting all the fields we don't
+ * understand in a simple two-column name/value format.
+ * v the vCard to display
+ * full display all items of the vcard?
+ * msgnum Citadel message pointer
+ */
+void parse_vcard(StrBuf *Target, struct vCard *v, HashList *VC, int full, wc_mime_attachment *Mime)
+{
+ StrBuf *Val = NULL;
+ StrBuf *Swap = NULL;
+ int i, j;
+ char buf[SIZ];
+ int is_qp = 0;
+ int is_b64 = 0;
+ StrBuf *thisname = NULL;
+ char firsttoken[SIZ];
+ void *V;
+
+ Swap = NewStrBuf ();
+ thisname = NewStrBuf();
+ for (i=0; i<(v->numprops); ++i) {
+ is_qp = 0;
+ is_b64 = 0;
+ StrBufPlain(thisname, v->prop[i].name, -1);
+ StrBufLowerCase(thisname);
+
+ /*len = */extract_token(firsttoken, ChrPtr(thisname), 0, ';', sizeof firsttoken);
+
+ for (j=0; j<num_tokens(ChrPtr(thisname), ';'); ++j) {
+ extract_token(buf, ChrPtr(thisname), j, ';', sizeof buf);
+ if (!strcasecmp(buf, "encoding=quoted-printable")) {
+ is_qp = 1;
+/* remove_token(thisname, j, ';');*/
+ }
+ if (!strcasecmp(buf, "encoding=base64")) {
+ is_b64 = 1;
+/* remove_token(thisname, j, ';');*/
+ }
+ }
+
+ /* copy over the payload into a StrBuf */
+ Val = NewStrBufPlain(v->prop[i].value, -1);
+
+ /* if we have some untagged QP, detect it here. */
+ if (is_qp || (strstr(v->prop[i].value, "=?")!=NULL)){
+ StrBuf *b;
+ StrBuf_RFC822_to_Utf8(Swap, Val, NULL, NULL); /* default charset, current charset */
+ b = Val;
+ Val = Swap;
+ Swap = b;
+ FlushStrBuf(Swap);
+ }
+ else if (is_b64) {
+ StrBufDecodeBase64(Val);
+
+ }
+ syslog(1, "%s [%s][%s]",
+ firsttoken,
+ ChrPtr(Val),
+ v->prop[i].value);
+ if (GetHash(VCToEnum, firsttoken, strlen(firsttoken), &V))
+ {
+ eVC evc = (eVC) V;
+ Put(VC, IKEY(evc), Val, HFreeStrBuf);
+ syslog(1, "[%ul]\n", evc);
+ Val = NULL;
+ }
+ else
+ syslog(1, "[]\n");
+/*
+TODO: check for layer II
+ else
+ {
+ long max = num_tokens(thisname, ';');
+ firsttoken[len] = '_';
+
+ for (j = 0; j < max; j++) {
+// firsttoken[len]
+
+ extract_token(buf, thisname, j, ';', sizeof (buf));
+ if (!strcasecmp(buf, "tel"))
+ strcat(phone, "");
+ else if (!strcasecmp(buf, "work"))
+ strcat(phone, _(" (work)"));
+ else if (!strcasecmp(buf, "home"))
+ strcat(phone, _(" (home)"));
+ else if (!strcasecmp(buf, "cell"))
+ strcat(phone, _(" (cell)"));
+ else {
+ strcat(phone, " (");
+ strcat(phone, buf);
+ strcat(phone, ")");
+ }
+ }
+ }
+
+ }
+*/
+
+ FreeStrBuf(&Val);
+ free(thisname);
+ thisname = NULL;
+ }
+
+}
+
+void tmplput_VCARD_ITEM(StrBuf *Target, WCTemplputParams *TP)
+{
+ HashList *VC = CTX;
+ eVC evc;
+ void *vStr;
+
+ evc = GetTemplateTokenNumber(Target, TP, 0, -1);
+ if (evc != -1)
+ {
+ if (GetHash(VC, IKEY(evc), &vStr))
+ {
+ StrBufAppendTemplate(Target, TP,
+ (StrBuf*) vStr,
+ 1);
+ }
+ }
+
+}
+
+void new_vcard (StrBuf *Target, struct vCard *v, int full, wc_mime_attachment *Mime)
+{
+ HashList *VC;
+ WCTemplputParams SubTP;
+
+ memset(&SubTP, 0, sizeof(WCTemplputParams));
+
+
+ VC = NewHash(0, Flathash);
+ parse_vcard(Target, v, VC, full, Mime);
+
+ SubTP.Filter.ContextType = CTX_VCARD;
+ SubTP.Context = VC;
+
+ DoTemplate(HKEY("test_vcard"), Target, &SubTP);
+ DeleteHash(&VC);
+}
+