+void PutVcardItem(HashList *thisVC, vcField *thisField, StrBuf *ThisFieldStr, int is_qp, StrBuf *Swap)
+{
+ /* if we have some untagged QP, detect it here. */
+ if (is_qp || (strstr(ChrPtr(ThisFieldStr), "=?")!=NULL)){
+ StrBuf *b;
+ StrBuf_RFC822_to_Utf8(Swap, ThisFieldStr, NULL, NULL); /* default charset, current charset */
+ b = ThisFieldStr;
+ ThisFieldStr = Swap;
+ Swap = b;
+ FlushStrBuf(Swap);
+ }
+ Put(thisVC, LKEY(thisField->cval), ThisFieldStr, HFreeStrBuf);
+}
+/*
+ * 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, k;
+ char buf[20]; //SIZ];
+ int is_qp = 0;
+ int is_b64 = 0;
+ int ntokens, len;
+ StrBuf *thisname = NULL;
+ char firsttoken[20]; ///SIZ];
+ //void *V;
+ HashList *thisVC;
+ StrBuf *thisVCToken;
+ void *vField = NULL;
+
+ thisVC = NewHash(0, lFlathash);
+ Swap = NewStrBuf ();
+ thisname = NewStrBuf();
+ thisVCToken = NewStrBufPlain(NULL, 63);
+ for (i=0; i<(v->numprops); ++i) {
+ FlushStrBuf(thisVCToken);
+ is_qp = 0;
+ is_b64 = 0;
+ syslog(LOG_DEBUG, "i: %d oneprop: %s - value: %s", i, v->prop[i].name, v->prop[i].value);
+ StrBufPlain(thisname, v->prop[i].name, -1);
+ StrBufLowerCase(thisname);
+
+ /*len = */extract_token(firsttoken, ChrPtr(thisname), 0, ';', sizeof firsttoken);
+ ntokens = num_tokens(ChrPtr(thisname), ';');
+ for (j=0, k=0; j < ntokens && k < 10; ++j) {
+ ///int evc[10];
+
+ len = extract_token(buf, ChrPtr(thisname), j, ';', sizeof buf);
+ if (!strcasecmp(buf, "encoding=quoted-printable")) {
+ is_qp = 1;
+/* remove_token(thisname, j, ';');*/
+ }
+ else if (!strcasecmp(buf, "encoding=base64")) {
+ is_b64 = 1;
+/* remove_token(thisname, j, ';');*/
+ }
+ else{
+ if (StrLength(thisVCToken) > 0) {
+ StrBufAppendBufPlain(thisVCToken, HKEY(";"), 0);
+ }
+ StrBufAppendBufPlain(thisVCToken, buf, len, 0);
+ /*
+ if (GetHash(VCToEnum, buf, len, &V))
+ {
+ evc[k] = (int) V;
+
+ Put(VC, IKEY(evc), Val, HFreeStrBuf);
+
+ syslog(LOG_DEBUG, "[%ul] -> k: %d %s - %s", evc, k, buf, VCStr[evc[k]].Key);
+ k++;
+ }
+*/
+
+ }
+ }
+
+ vField = NULL;
+ if ((StrLength(thisVCToken) > 0) &&
+ GetHash(VCTokenToDefine, SKEY(thisVCToken), &vField) &&
+ (vField != NULL)) {
+ vcField *thisField = (vcField *)vField;
+ StrBuf *ThisFieldStr = NULL;
+ syslog(LOG_DEBUG, "got this token: %s, found: %s", ChrPtr(thisVCToken), thisField->STR.Key);
+ switch (thisField->Type) {
+ case StringCluster: {
+ int j = 0;
+ const char *Pos = NULL;
+ StrBuf *thisArray = NewStrBufPlain(v->prop[i].value, -1);
+ StrBuf *Buf = NewStrBufPlain(NULL, StrLength(thisArray));
+ while (thisField->Sub[j].STR.len > 0) {
+ StrBufExtract_NextToken(Buf, thisArray, &Pos, ';');
+ ThisFieldStr = NewStrBufDup(Buf);
+
+ PutVcardItem(thisVC, &thisField->Sub[j], ThisFieldStr, is_qp, Swap);
+ j++;
+ }
+ }
+ break;
+ case FlatString:
+ case PhoneNumber:
+ case EmailAddr:
+ case Street:
+ case Number:
+ case AliasFor:
+ /* copy over the payload into a StrBuf */
+ ThisFieldStr = NewStrBufPlain(v->prop[i].value, -1);
+ PutVcardItem(thisVC, thisField, ThisFieldStr, is_qp, Swap);
+
+ break;
+ case Base64BinaryAttachment:
+ case TerminateList:
+ break;
+ }
+
+ }
+ /* 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);
+
+ }
+#if 0
+ syslog(LOG_DEBUG, "-> firsttoken: %s thisname: %s Value: [%s][%s]",
+ firsttoken,
+ ChrPtr(thisname),
+ ChrPtr(Val),
+ v->prop[i].value);
+ if (GetHash(VCToEnum, firsttoken, strlen(firsttoken), &V))
+ {
+ eVC evc = (eVC) V;
+ Put(VC, IKEY(evc), Val, HFreeStrBuf);
+ syslog(LOG_DEBUG, "[%ul]\n", evc);
+ Val = NULL;
+ }
+ else
+ syslog(LOG_DEBUG, "[]\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, ")");
+ }
+ }
+ }
+
+ }
+*/
+#endif
+ FreeStrBuf(&Val);
+ ////free(thisname);
+ /// thisname = NULL;
+ }
+
+
+ {
+ WCTemplputParams *TP = NULL;
+ WCTemplputParams SubTP;
+ FlushStrBuf(Target);
+ StackContext(TP, &SubTP, thisVC, CTX_VCARD, 0, NULL);
+ {
+ DoTemplate(HKEY("vcard_msg_display"), Target, &SubTP);
+ }
+ UnStackContext(&SubTP);
+ }
+ printf("%s\n", ChrPtr(Target));
+ FreeStrBuf(&thisVCToken);
+ DeleteHash(&thisVC);/// todo
+}
+
+void tmplput_VCARD_ITEM(StrBuf *Target, WCTemplputParams *TP)
+{
+ HashList *VC = CTX(CTX_VCARD);
+ int 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;