Contact photo set via JMAP doesn't show up in iOS Contacts (vCard 4 export escapes comma in data: URI)

Issue Description

Contact photos that are set through JMAP don’t show up in iOS Contacts (CardDAV). Photos set on the iPhone show up fine everywhere, including in the JMAP client.

I set the photo with a webmail client that writes the card via JMAP (ContactCard with a media entry, kind “photo”, uri “data:image/jpeg;base64,…”). When the same card is fetched over CardDAV as vCard 4.0, the comma in the data URI is escaped, so the URI is no longer valid and iOS drops the photo.

Expected Behavior

The PHOTO data URI should be written as is, without text escaping:

PHOTO;MEDIATYPE=image/jpeg:data:image/jpeg;base64,/9j/4AAQSk…

As far as I understand RFC 6350, comma escaping applies to text values, not URI values. The PHOTO example in section 6.2.4 has the comma unescaped: RFC 6350: vCard Format Specification | RFC Editor

Actual Behavior

vCard 4.0 (default):

VERSION:4.0
PHOTO;MEDIATYPE=image/jpeg;PROP-ID=photo:data:image/jpeg;base64,/9j/4AAQSk…

The comma after “base64” comes out as “,”. iOS shows no photo for the contact.

With “Accept: text/vcard; version=3.0” the same card is fine:

VERSION:3.0
PHOTO;MEDIATYPE=image/jpeg;PROP-ID=photo;ENCODING=b;TYPE=JPEG:/9j/4AAQSkZJR…

Reproduction Steps

  1. Create or update a contact via JMAP with a photo:
    media: { “photo”: { “kind”: “photo”, “mediaType”: “image/jpeg”, “uri”: “data:image/jpeg;base64,” } }
  2. Fetch the card over CardDAV without an Accept header (or as vCard 4.0).
  3. Look at the PHOTO line: the comma in the data URI is escaped as “,”.
  4. Sync the address book to an iPhone: the contact has no photo.
  5. For comparison, fetch the same card with “Accept: text/vcard; version=3.0”: the PHOTO line is correct.
  6. Setting the photo on the iPhone instead (uploaded as vCard 3 with ENCODING=b) works on both sides.

Stalwart Version

v0.16.x

Installation Method

Binary (Linux)

Database Backend

RocksDB

Blob Storage

RocksDB

Search Engine

Internal

Directory Backend

Internal

I have reviewed the documentation and FAQ and confirm that my issue is NOT addressed there.

on

I have searched this support forum (open and closed topics) and confirm this is not a duplicate.

on

I understand that topics in this category are triaged by a bot first but a human reply will follow up. If I’d prefer a human-only reply, I’ll add the no-ai tag to my topic.

on

This isn’t covered in the current docs. A community member or staff member will follow up.

This is an automated reply from the Stalwart Help Bot. Other community members may follow up if this answer is incomplete or wrong.

Apple is not specifying the vCard version so Stalwart defaults to v4. In your settings set vCardVersion to 3.

Thanks, that explains why Apple gets v4. I’ll set vCardVersion to 3 as a workaround.

One thing remains though: the v4 output itself is still invalid. PHOTO is a URI value, and RFC 6350 only escapes commas in TEXT values, so the comma in “data:image/jpeg;base64,…” must not become “,”. Any client that does ask for vCard 4 will still get a broken photo. Might be worth fixing in the v4 serializer.

Other pieces of software are affected by this bug (e.g. GitHub - jdreinhardt/DAVe: CalDAV web client with support for Baikal and Radicale · GitHub )

I tracked the issue down to this line: stalwart/crates/calcard/src/vcard/rkyv_writer.rs at 47df4c0baeb88d83424dfda6aa7cf6040706999e · stalwartlabs/stalwart · GitHub

If the fix is accepted (removing the backslash before the comma), I’d be happy to contribute it

The escaped comma in the v4 output is intentional. RFC 6350 section 3.4 says a comma in a property value MUST be escaped, “even for properties that don’t allow multiple instances”, and Stalwart follows that (and the errata) for every value, URIs included. A v4 parser is expected to unescape the value before reading the data: URI, so base64\, is valid vCard 4.0 even though the examples later in the RFC leave it out.

The photos go missing in iOS because it fetches cards without saying which version it wants, so it gets v4 and doesn’t unescape the comma. Setting vCardVersion to 3 is the fix for that, not just a workaround, and it’s what I’d recommend for anyone syncing with Apple clients.

@GauBen thanks for the offer and for tracking down the line. We’re keeping the escaping as it is, so no PR is needed there. If DAVe can’t request vCard 3, the place to fix it is DAVe’s parser, which should unescape the value before it uses the URI.

Thank you for clarification, I was not aware of the errata and you are absolutely right and Stalwart behaves 100% correct.

Congrats on milestone 1.0 by the way!