diff --git a/imap/http_carddav.c b/imap/http_carddav.c index 07b3439b53..12bdba7450 100644 --- a/imap/http_carddav.c +++ b/imap/http_carddav.c @@ -1366,6 +1366,7 @@ static int carddav_put(struct transaction_t *txn, void *obj, char *type = NULL, *subtype = NULL; struct param *params = NULL; const char *want_ver = NULL; + int error_count = 0; /* Sanity check Content-Type */ const char **hdr = spool_getheader(txn->req_hdrs, "Content-Type"); @@ -1444,6 +1445,12 @@ static int carddav_put(struct transaction_t *txn, void *obj, goto done; } + error_count = vcardcomponent_count_errors(vcard); + if (error_count) { + /* Remove all X-LIC-ERROR properties */ + vcardcomponent_strip_errors(vcard); + } + /* Sanity check vCard data */ vcardproperty *prop; const char *uid = NULL, *fullname = NULL; @@ -1532,7 +1539,15 @@ static int carddav_put(struct transaction_t *txn, void *obj, if (txn->error.precond) return HTTP_FORBIDDEN; - return carddav_store_resource(txn, vcard, mailbox, resource, db); + int ret = carddav_store_resource(txn, vcard, mailbox, resource, db); + + if (error_count && !(flags & PREFER_REP)) { + /* vCard data has been rewritten - don't return validators */ + txn->resp_body.lastmod = 0; + txn->resp_body.etag = NULL; + } + + return ret; } /* Perform a bulk import */ @@ -2183,7 +2198,7 @@ static int propfind_addrdata(const xmlChar *name, xmlNsPtr ns, /* Translate between vCard versions */ vcard = fctx->obj; - if (!vcard) vcard = fctx->obj = vcardparser_parse_string(data); + if (!vcard) vcard = fctx->obj = vcard_parse_string_x(data); if (want_ver == 4) vcard_to_v4_x(vcard); else vcard_to_v3_x(vcard); @@ -2193,7 +2208,7 @@ static int propfind_addrdata(const xmlChar *name, xmlNsPtr ns, /* Limit returned properties */ vcard = fctx->obj; - if (!vcard) vcard = fctx->obj = vcardparser_parse_string(data); + if (!vcard) vcard = fctx->obj = vcard_parse_string_x(data); prune_properties(vcard, partial); } diff --git a/imap/index.c b/imap/index.c index 0b30ecf87e..7762ad6bcf 100644 --- a/imap/index.c +++ b/imap/index.c @@ -5516,7 +5516,7 @@ static int extract_vcardbuf(struct buf *raw, charset_t charset, int encoding, vcardbuf = raw; } - vcard = vcardcomponent_new_from_string(buf_cstring(vcardbuf)); + vcard = vcard_parse_string_x(buf_cstring(vcardbuf)); if (!vcard) { r = IMAP_INTERNAL; goto done; diff --git a/imap/vcard_support.c b/imap/vcard_support.c index 6c250b4453..7d6f97bf7f 100644 --- a/imap/vcard_support.c +++ b/imap/vcard_support.c @@ -452,7 +452,12 @@ EXPORTED void vcard_to_v4(struct vparse_card *vcard) EXPORTED vcardcomponent *vcard_parse_string_x(const char *str) { - return vcardcomponent_new_from_string(str); + vcardcomponent *vcard = vcardcomponent_new_from_string(str); + + /* Remove all X-LIC-ERROR properties */ + if (vcard) vcardcomponent_strip_errors(vcard); + + return vcard; } EXPORTED vcardcomponent *vcard_parse_buf_x(const struct buf *buf) @@ -476,10 +481,9 @@ EXPORTED vcardcomponent *record_to_vcard_x(struct mailbox *mailbox, struct buf buf = BUF_INITIALIZER; vcardcomponent *vcard = NULL; - /* Load message containing the resource and parse vcard data */ + /* Load message containing the resource and parse vCard data */ if (!mailbox_map_record(mailbox, record, &buf)) { - vcard = vcardcomponent_new_from_string(buf_cstring(&buf) + - record->header_size); + vcard = vcard_parse_string_x(buf_cstring(&buf) + record->header_size); buf_free(&buf); }