/*
- * Copyright (c) 1996-2012 by the citadel.org team
+ * Copyright (c) 1996-2017 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, version 3.
HashList *vcNames = NULL; /* todo: fill with the name strings */
vcField* vcfUnknown = NULL;
+/******************************************************************************
+ * initialize vcard structure *
+ ******************************************************************************/
+
void RegisterVCardToken(vcField* vf, StrBuf *name, int inTokenCount)
{
if (vf->Type == UnKnown) {
FreeStrBuf(&subStr);
}
+/******************************************************************************
+ * VCard template functions *
+ ******************************************************************************/
+
int preeval_vcard_item(WCTemplateToken *Token)
{
WCTemplputParams TPP;
TP->Tokens = Token;
searchFieldNo = GetTemplateTokenNumber(Target, TP, 0, 0);
if (searchFieldNo >= VCEnumCounter) {
- LogTemplateError(NULL, "VCardItem", ERR_PARM1, TP,
- "Invalid define");
+ LogTemplateError(NULL, "VCardItem", ERR_PARM1, TP, "Invalid define");
return 0;
}
return 1;
addrbookent *ab = (addrbookent*) CTX(CTX_VCARD);
if (t == NULL) {
- LogTemplateError(NULL, "VCard item", ERR_NAME, TP,
- "Missing context");
+ LogTemplateError(NULL, "VCard item", ERR_NAME, TP, "Missing context");
return;
}
long searchType;
long type = 0;
void *v;
- int rc = 0;
vcField *vf = (vcField*) Context;
+ int rc = 0;
memcpy(&type, key, sizeof(long));
searchType = GetTemplateTokenNumber(Target, TP, IT_ADDT_PARAM(0), 0);
if (vf->Type == searchType) {
addrbookent *ab = (addrbookent*) CTX(CTX_VCARD);
- if (GetHash(ab->VC, LKEY(vf->cval), &v) && v != NULL)
+ if (GetHash(ab->VC, LKEY(vf->cval), &v) && v != NULL) {
return 1;
+ }
}
return rc;
}
-
-
-
HashList *getContextVcard(StrBuf *Target, WCTemplputParams *TP)
{
vcField *vf = (vcField*) CTX(CTX_VCARD_TYPE);
}
}
-
int conditional_VC_Havetype(StrBuf *Target, WCTemplputParams *TP)
{
addrbookent *ab = (addrbookent*) CTX(CTX_VCARD);
return rc;
}
-wc_mime_attachment *load_vcard(message_summary *Msg)
-{
- HashPos *it;
- StrBuf *FoundCharset = NewStrBuf();
- StrBuf *Error;
- void *vMime;
- const char *Key;
- long len;
- wc_mime_attachment *Mime;
- wc_mime_attachment *VCMime = NULL;
-
- Msg->MsgBody = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
- memset(Msg->MsgBody, 0, sizeof(wc_mime_attachment));
- Msg->MsgBody->msgnum = Msg->msgnum;
-
- load_message(Msg, FoundCharset, &Error);
-
- FreeStrBuf(&FoundCharset);
- /* look up the vcard... */
- it = GetNewHashPos(Msg->AllAttach, 0);
- while (GetNextHashPos(Msg->AllAttach, it, &len, &Key, &vMime) &&
- (vMime != NULL))
- {
- Mime = (wc_mime_attachment*) vMime;
- if ((strcmp(ChrPtr(Mime->ContentType),
- "text/x-vcard") == 0) ||
- (strcmp(ChrPtr(Mime->ContentType),
- "text/vcard") == 0))
- {
- VCMime = Mime;
- break;
- }
- }
- DeleteHashPos(&it);
- if (VCMime == NULL)
- return NULL;
-
- if (VCMime->Data == NULL)
- MimeLoadData(VCMime);
- return VCMime;
-}
+/******************************************************************************
+ * parse one VCard *
+ ******************************************************************************/
void PutVcardItem(HashList *thisVC, vcField *thisField, StrBuf *ThisFieldStr, int is_qp, StrBuf *Swap)
{
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);
+ // 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);
+ extract_token(firsttoken, ChrPtr(thisname), 0, ';', sizeof firsttoken);
ntokens = num_tokens(ChrPtr(thisname), ';');
for (j=0, k=0; j < ntokens && k < 10; ++j) {
len = extract_token(buf, ChrPtr(thisname), j, ';', sizeof buf);
else if (!strcasecmp(buf, "encoding=base64")) {
is_b64 = 1;
}
- else{
+ else {
if (StrLength(thisVCToken) > 0) {
StrBufAppendBufPlain(thisVCToken, HKEY(";"), 0);
}
(vField != NULL)) {
vcField *thisField = (vcField *)vField;
StrBuf *ThisFieldStr = NULL;
- syslog(LOG_DEBUG, "got this token: %s, found: %s", ChrPtr(thisVCToken), thisField->STR.Key);
+ // syslog(LOG_DEBUG, "got this token: %s, found: %s", ChrPtr(thisVCToken), thisField->STR.Key);
switch (thisField->Type) {
case StringCluster: {
int j = 0;
while (thisField->Sub[j].STR.len > 0) {
StrBufExtract_NextToken(Buf, thisArray, &Pos, ';');
ThisFieldStr = NewStrBufDup(Buf);
-
PutVcardItem(VC, &thisField->Sub[j], ThisFieldStr, is_qp, Swap);
j++;
}
FreeStrBuf(&thisVCToken);
}
-void tmplput_VCARD_ITEM(StrBuf *Target, WCTemplputParams *TP)
-{
- addrbookent *ab = CTX(CTX_VCARD);
- int evc;
- void *vStr;
-
- evc = GetTemplateTokenNumber(Target, TP, 0, -1);
- if (evc != -1)
- {
- if (GetHash(ab->VC, IKEY(evc), &vStr))
- {
- StrBufAppendTemplate(Target, TP,
- (StrBuf*) vStr,
- 1);
- }
- }
-
-}
-
HashList *CtxGetVcardList(StrBuf *Target, WCTemplputParams *TP)
{
HashList *pb = CTX(CTX_VCARD_LIST);
return pb;
}
-void display_one_vcard (StrBuf *Target, addrbookent *ab, const char *tp_name, size_t tp_name_len)
-{
- WCTemplputParams *TP = NULL;
- WCTemplputParams SubTP;
-
- memset(&SubTP, 0, sizeof(WCTemplputParams));
- StackContext(TP, &SubTP, ab, CTX_VCARD, 0, NULL);
+/******************************************************************************
+ * Extract an embedded photo from a vCard for display on the client *
+ ******************************************************************************/
- DoTemplate(tp_name, tp_name_len, Target, &SubTP);
- UnStackContext(&SubTP);
-}
-
-/*
- * Extract an embedded photo from a vCard for display on the client
- */
void display_vcard_photo_img(void)
{
long msgnum = 0L;
free(photosrc);
}
+wc_mime_attachment *load_vcard(message_summary *Msg)
+{
+ HashPos *it;
+ StrBuf *FoundCharset = NewStrBuf();
+ StrBuf *Error;
+ void *vMime;
+ const char *Key;
+ long len;
+ wc_mime_attachment *Mime;
+ wc_mime_attachment *VCMime = NULL;
+
+ Msg->MsgBody = (wc_mime_attachment*) malloc(sizeof(wc_mime_attachment));
+ memset(Msg->MsgBody, 0, sizeof(wc_mime_attachment));
+ Msg->MsgBody->msgnum = Msg->msgnum;
+
+ load_message(Msg, FoundCharset, &Error);
+
+ FreeStrBuf(&FoundCharset);
+ /* look up the vcard... */
+ it = GetNewHashPos(Msg->AllAttach, 0);
+ while (GetNextHashPos(Msg->AllAttach, it, &len, &Key, &vMime) &&
+ (vMime != NULL))
+ {
+ Mime = (wc_mime_attachment*) vMime;
+ if ((strcmp(ChrPtr(Mime->ContentType),
+ "text/x-vcard") == 0) ||
+ (strcmp(ChrPtr(Mime->ContentType),
+ "text/vcard") == 0))
+ {
+ VCMime = Mime;
+ break;
+ }
+ }
+ DeleteHashPos(&it);
+ if (VCMime == NULL)
+ return NULL;
+
+ if (VCMime->Data == NULL)
+ MimeLoadData(VCMime);
+ return VCMime;
+}
+
/*
* Edit the vCard component of a MIME message.
* Supply the message number
FreeStrBuf(&Buf);
}
-
+/******************************************************************************
+ * Render Addressbooks *
+ ******************************************************************************/
typedef struct _vcardview_struct {
long is_singlecard;
int is_new,
int i)
{
+ wcsession *WCC = WC;
+ WCTemplputParams *TP = NULL;
+ WCTemplputParams SubTP;
vcardview_struct *VS;
wc_mime_attachment *VCMime = NULL;
struct vCard *v;
abEntry->name = NewStrBuf();
abEntry->VC = NewHash(0, lFlathash);
abEntry->ab_msgnum = Msg->msgnum;
- parse_vcard(WC->WBuf, v, abEntry->VC, VCMime);
- display_one_vcard(abEntry->name, abEntry, HKEY("vcard_list_name"));
+ parse_vcard(WCC->WBuf, v, abEntry->VC, VCMime);
+
+ memset(&SubTP, 0, sizeof(WCTemplputParams));
+ StackContext(TP, &SubTP, abEntry, CTX_VCARD, 0, NULL);
+
+ // No, don't display the name, it just shits all over the screen
+ // DoTemplate(HKEY("vcard_list_name"), WCC->WBuf, &SubTP);
+
+ UnStackContext(&SubTP);
if (StrLength(abEntry->name) == 0) {
StrBufPlain(abEntry->name, _("(no name)"), -1);
}
+ syslog(LOG_DEBUG, "abEntry->name : %s", ChrPtr(abEntry->name));
+
vcard_free(v);
Put(VS->addrbook, SKEY(abEntry->name), abEntry, deleteAbEnt);
}
if (num_ab > 1) {
- ///SortByHashKey(VS->addrbook, 0);
+ SortByHashKey(VS->addrbook, 1);
}
num_pages = (GetCount(VS->addrbook) / NAMESPERPAGE) + 1;
if (GetHashAt(VS->addrbook, tabfirst, &hklen1, &c1, &v1)) {
a1 = (addrbookent*) v1;
StrBufAppendBuf(headline, a1->name, 0);
-
+ StrBuf_Utf8StrCut(headline, 3);
if (GetHashAt(VS->addrbook, tablast, &hklen2, &c2, &v2)) {
a2 = (addrbookent*) v2;
StrBufAppendBufPlain(headline, HKEY(" - "), 0);
StrBufAppendBuf(headline, a2->name, 0);
+ StrBuf_Utf8StrCut(headline, 9);
}
}
tablabels[i] = headline;
DeleteHash(&headlines);
free(tablabels);
StrBufAppendBufPlain(WCC->WBuf, HKEY("</div>"), 0);/* closes: id=global */
- wDumpContent(1);
}
vcardview_struct *VS;
VS = (vcardview_struct*) *ViewSpecific;
- if (VS->is_singlecard)
- read_message(WC->WBuf, HKEY("view_message"), lbstr("startmsg"), NULL, &Mime);
- else
+ if (VS->is_singlecard) {
+ read_message(WC->WBuf, HKEY("view_message"), lbstr("startmsg"), NULL, &Mime, NULL);
+ }
+ else {
do_addrbook_view(VS); /* Render the address book */
+ }
return 0;
}
VS = (vcardview_struct*) *ViewSpecific;
wDumpContent(1);
- if ((VS != NULL) &&
- (VS->addrbook != NULL))
+ if ((VS != NULL) && (VS->addrbook != NULL)) {
DeleteHash(&VS->addrbook);
- if (VS != NULL)
+ }
+ if (VS != NULL) {
free(VS);
+ }
return 0;
}
{
wc_mime_attachment *Mime = (wc_mime_attachment *) CTX(CTX_MIME_ATACH);
wcsession *WCC = WC;
- if (StrLength(Mime->Data) == 0)
+ if (StrLength(Mime->Data) == 0) {
MimeLoadData(Mime);
+ }
if (StrLength(Mime->Data) > 0) {
struct vCard *v;
StrBuf *Buf;
v = VCardLoad(Mime->Data);
if (v != NULL) {
+ WCTemplputParams *TP = NULL;
+ WCTemplputParams SubTP;
addrbookent ab;
memset(&ab, 0, sizeof(addrbookent));
ab.ab_msgnum = Mime->msgnum;
parse_vcard(Target, v, ab.VC, Mime);
- display_one_vcard (Target, &ab, HKEY("vcard_msg_display"));
+
+ memset(&SubTP, 0, sizeof(WCTemplputParams));
+ StackContext(TP, &SubTP, &ab, CTX_VCARD, 0, NULL);
+
+ DoTemplate(HKEY("vcard_msg_display"), Target, &SubTP);
+ UnStackContext(&SubTP);
DeleteHash(&ab.VC);
vcard_free(v);
NULL,
vcard_LoadMsgFromServer,
vcard_RenderView_or_Tail,
- vcard_Cleanup);
+ vcard_Cleanup,
+ NULL);
RegisterIterator("MAIL:VCARDS", 0, NULL, CtxGetVcardList, NULL, NULL, CTX_VCARD, CTX_VCARD_LIST, IT_NOFLAG);