Skip to content

Commit

Permalink
vCard: strip any X-LIC-ERR properties
Browse files Browse the repository at this point in the history
Also, don't return ETag on CardDAV PUT if we stripped
  • Loading branch information
ksmurchison committed Nov 28, 2023
1 parent b999819 commit a039365
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
21 changes: 18 additions & 3 deletions imap/http_carddav.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion imap/index.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 8 additions & 4 deletions imap/vcard_support.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
}

Expand Down

0 comments on commit a039365

Please sign in to comment.