X-Git-Url: https://code.citadel.org/?a=blobdiff_plain;f=webcit%2Fvcard_edit.c;h=9327ec291e6f7795169c3c8bbe42392f888db640;hb=9af5bf001a19bdd83b54921599dc8aa2a626f2a5;hp=d5cbe0b3553be8e6a546dc8dee9bb4ac57be689d;hpb=b1fafce2cecccc2126b0c9bb3b1054df48afc4c0;p=citadel.git diff --git a/webcit/vcard_edit.c b/webcit/vcard_edit.c index d5cbe0b35..9327ec291 100644 --- a/webcit/vcard_edit.c +++ b/webcit/vcard_edit.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996-2012 by the citadel.org team + * Copyright (c) 1996-2020 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. @@ -212,8 +212,7 @@ int preeval_vcard_item(WCTemplateToken *Token) 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; @@ -236,8 +235,7 @@ void tmpl_vcard_context_item(StrBuf *Target, WCTemplputParams *TP) 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; } @@ -318,16 +316,17 @@ int filter_VC_ByType(const char* key, long len, void *Context, StrBuf *Target, W 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; } @@ -390,6 +389,16 @@ int conditional_VC_Havetype(StrBuf *Target, WCTemplputParams *TP) return rc; } + +/* Returns 1 to suppress the "email" fields in the vCard editor, if we're editing a user's contact info. + * Returns 0 to present those fields, if we're editing a vCard in an address book. + */ +int conditional_VC_SuppressEmailFields(StrBuf *Target, WCTemplputParams *TP) +{ + return(atoi(bstr("suppress_email"))); +} + + /****************************************************************************** * parse one VCard * ******************************************************************************/ @@ -426,11 +435,11 @@ void parse_vcard(StrBuf *Target, struct vCard *v, HashList *VC, wc_mime_attachme 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); @@ -440,7 +449,7 @@ void parse_vcard(StrBuf *Target, struct vCard *v, HashList *VC, wc_mime_attachme else if (!strcasecmp(buf, "encoding=base64")) { is_b64 = 1; } - else{ + else { if (StrLength(thisVCToken) > 0) { StrBufAppendBufPlain(thisVCToken, HKEY(";"), 0); } @@ -454,7 +463,7 @@ void parse_vcard(StrBuf *Target, struct vCard *v, HashList *VC, wc_mime_attachme (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; @@ -464,7 +473,6 @@ void parse_vcard(StrBuf *Target, struct vCard *v, HashList *VC, wc_mime_attachme 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++; } @@ -925,18 +933,23 @@ int vcard_LoadMsgFromServer(SharedMessageStatus *Stat, abEntry->name = NewStrBuf(); abEntry->VC = NewHash(0, lFlathash); abEntry->ab_msgnum = Msg->msgnum; + parse_vcard(WCC->WBuf, v, abEntry->VC, VCMime); memset(&SubTP, 0, sizeof(WCTemplputParams)); StackContext(TP, &SubTP, abEntry, CTX_VCARD, 0, NULL); - DoTemplate(HKEY("vcard_list_name"), WCC->WBuf, &SubTP); + // 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); @@ -1029,10 +1042,12 @@ int vcard_RenderView_or_Tail(SharedMessageStatus *Stat, void **ViewSpecific, lon 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; } @@ -1042,11 +1057,12 @@ int vcard_Cleanup(void **ViewSpecific) 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; } @@ -1055,8 +1071,9 @@ void render_MIME_VCard(StrBuf *Target, WCTemplputParams *TP, StrBuf *FoundCharse { 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; @@ -1147,7 +1164,8 @@ InitModule_VCARD 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); @@ -1172,7 +1190,9 @@ InitModule_VCARD REGISTERTokenParamDefine(TerminateList); REGISTERTokenParamDefine(Address); - RegisterConditional("VC:HAVE:TYPE", 1, conditional_VC_Havetype, CTX_VCARD); + RegisterConditional("VC:HAVE:TYPE", 1, conditional_VC_Havetype, CTX_VCARD); + RegisterConditional("COND:VC:SUPPRESS_EMAIL_FIELDS", 1, conditional_VC_SuppressEmailFields, CTX_VCARD); + RegisterFilteredIterator("VC:TYPE", 1, DefineToToken, NULL, NULL, NULL, filter_VC_ByType, CTX_VCARD_TYPE, CTX_VCARD, IT_NOFLAG); RegisterFilteredIterator("VC:TYPE:ITEMS", 0, NULL, getContextVcard, NULL, NULL, filter_VC_ByContextType, CTX_STRBUF, CTX_VCARD_TYPE, IT_NOFLAG);