iCloud to Outlook Contact conversion
At work, we need to more or less wipe all iphones clear and put them under control of a new MDM. That significantly limits what the users can do with their phones, but should strengthen security.
/* German Title: iCloud Kontakte in Outlook importieren */
The trouble is that some people have hundreds of contacts stored locally on their phones, which have been synched to their iCloud. While this is highly questionable from a GDPR point of view, that makes ist rather easy to export the contacts in vcf format as vcards.
The downside: Outlook only reads the first entry in the file. And the character encoding did not match our Outlook settings, so it screwed up the German umlauts.
So I needed to do two things:
- split the one large vcf file into over a hundred individual ones
- fix the character encoding, so it does not break the umlauts
Pretty easy to do so with a few lines of Python code:
import os
def split_vcf(file_path):
with open(file_path, 'r', encoding='utf-8') as file:
vcf_content = file.read()
vcards = vcf_content.split('END:VCARD')
vcards = [vcard + 'END:VCARD' for vcard in vcards if vcard.strip()]
output_dir = 'split_vcards'
os.makedirs(output_dir, exist_ok=True)
for i, vcard in enumerate(vcards):
output_file = os.path.join(output_dir, f'{i+1}.vcf')
with open(output_file, 'w', encoding='cp1252') as file:
file.write(vcard)
if __name__ == '__main__':
split_vcf('iCloud-vCards.vcf')
That will read a file "iCloud-vCards.vcf" and split the entries into individual files in a "split_vcards" subdirecrory. While changing the encoding from utf-8 to "Western European (Windows)", i.e. cp1252.
It still does a few strange things like not setting the preferred telephone automatically, but all in all, nothing appears to get lost.