Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read IMPP fields in a vcard #105

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions khard/carddav_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,30 @@ def add_phone_number(self, type, number):
label_obj.group = group_name
label_obj.value = custom_types[0]

def get_impp_addresses(self):
"""
: returns: dict of type and IMPP address list
:rtype: dict(str, list(str))
"""
impp_dict = {}
for child in self.vcard.getChildren():

if child.name == "IMPP":

# Retrieve the IMPP type and address
type, address = child.value.split(":")

try:
impp_dict[type].append( address )
except KeyError:
impp_dict[type] = [ address ]

# sort IMPP address list
for impp_list in impp_dict.values():
impp_list.sort()

return impp_dict

def get_email_addresses(self):
"""
: returns: dict of type and email address list
Expand Down Expand Up @@ -1379,6 +1403,15 @@ def print_vcard(self, show_address_book=True, show_uid=True):
strings += helpers.convert_to_yaml(
type, email_list, 4, -1, False)

# IMPP addresses
if len(self.get_impp_addresses().keys()) > 0:
strings.append("IMPP")
for type, impp_list in sorted(
self.get_impp_addresses().items(),
key=lambda k: k[0].lower()):
strings += helpers.convert_to_yaml(
type, impp_list, 4, -1, False)

# post addresses
if len(self.get_post_addresses().keys()) > 0:
strings.append("Address")
Expand Down