diff --git a/khard/carddav_object.py b/khard/carddav_object.py index 38729803..361b5f95 100644 --- a/khard/carddav_object.py +++ b/khard/carddav_object.py @@ -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 @@ -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")