Changeset 2321
- Timestamp:
- 07/12/07 13:17:05 (1 year ago)
- Files:
-
- plugins/moto-sync/motosync.py (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/moto-sync/motosync.py
r2320 r2321 1815 1815 # create a list [(contacttype, contact, is_pref)] 1816 1816 contacts = [] 1817 seen_pref = False # have we already seen a preferred contact?1817 pref_telephone = pref_email = 0 # number of preferred phone/email contacts 1818 1818 for elt in getElementsByTagNames(doc, set(['Telephone', 'EMail']), []): 1819 1819 content = getXMLField(elt, 'Content') 1820 is_pref = elt.hasAttribute('Preferred') and elt.getAttribute('Preferred') in ['1', 'true'] 1820 1821 if elt.tagName == 'Telephone': 1821 1822 # filter out any illegal characters from the phone number 1822 1823 content = filter(lambda c: c in TEL_NUM_DIGITS, content) 1824 pref_telephone += int(is_pref) 1823 1825 ical_types = elt.getAttribute('Location').split(';') 1824 1826 ical_types.extend(elt.getAttribute('Type').split(';')) 1825 is_pref = elt.hasAttribute('Preferred') and elt.getAttribute('Preferred') in ['1', 'true']1826 1827 moto_type = MOTO_CONTACT_DEFAULT 1827 1828 for t in ical_types: … … 1831 1832 break 1832 1833 else: # email 1833 is_pref = False1834 pref_email += int(is_pref) 1834 1835 moto_type = MOTO_CONTACT_EMAIL 1835 contacts.append((moto_type, content, is_pref and not seen_pref)) 1836 seen_pref = seen_pref or is_pref 1837 1838 # if none of the contacts were preffered, make one so 1839 if not seen_pref: 1840 # arbitrarily mark the first non-email contact as preferred 1841 for i in range(len(contacts)): 1842 (moto_type, content, _) = contacts[i] 1843 if moto_type != MOTO_CONTACT_EMAIL: 1844 contacts[i] = (moto_type, content, True) 1845 break 1846 else: 1847 # no non-email contacts, so just make the first email preferred 1848 (moto_type, content, _) = contacts[0] 1849 contacts[0] = (moto_type, content, True) 1836 contacts.append((moto_type, content, is_pref)) 1850 1837 1851 1838 # process addresses, create a hash from contacttype to address … … 1868 1855 # addresses for which there is no phone number are dropped 1869 1856 for (moto_type, contact, is_pref) in contacts: 1857 # the phone will only handle one preferred contact; if both telephone 1858 # and email contacts are preferred, make the emails non-preferred 1859 if moto_type == MOTO_CONTACT_EMAIL and pref_telephone > 0: 1860 is_pref = False 1870 1861 if moto_type == MOTO_CONTACT_EMAIL: 1871 1862 addr = None
