Example #1
0
 def update( self, event ):
     entry = {}
     for collection in self.attributes:
         for x,attr in collection[1]:
             tmp = polymer.encode.decode_ui( self._stuff[attr].GetValue() ).encode('utf-8')
             if tmp=='':
                 tmp = None
             if tmp is None:
                 if attr in self._entry:
                     entry[attr] = tmp
             else:
                 entry[attr] = tmp
     acap = wx.GetApp().connection( self.GetParent().uri )
     acap.store( self.GetParent().uri.path + self._entryname, entry )
Example #2
0
 def importer( self, event ):
     import infotrope.acap
     email_addresses = []
     pref_email_address = None
     if u'EMAIL' in self.vcf.contentsByName:
         for email in [ self.vcf.contents[x] for x in self.vcf.contentsByName['EMAIL'] ]:
             if u'TYPE' in email.params:
                 if u'INTERNET' in email.params[u'TYPE']:
                     email_addresses.append( email.value )
                     if u'PREF' in email.params[u'TYPE']:
                         pref_email_address = email.value
     if len(email_addresses):
         if pref_email_address is None:
             pref_email_address = email_addresses[0]
         acap = wx.GetApp().acap_home()
         srt = 'SEARCH "/addressbook/~/" DEPTH 0 RETURN ("*") ' + ('OR ' * (len(email_addresses)-1)) + ' '.join(['OR PREFIX "addressbook.Email" "i;octet" {%d+}\r\n%s\x00 EQUAL "addressbook.Email" "i;octet" "%s"' % ( len(x)+1, x, x ) for x in email_addresses])
         srch = infotrope.acap.search( srt, connection=acap, ret=["*"] )
         srch.send()
         cand = {}
         def stock( cand, a, x ):
             cand[a] = x.value.encode( 'utf-8' )
         def stock_multi( cand, a, x ):
             if a not in cand:
                 cand[a] = []
             cand[a].append( x.value.encode( 'utf-8' ) )
         def type_map( cand, a, x, inet=False ):
             if u'TYPE' in x.params:
                 if inet and u'INTERNET' not in x.params[u'TYPE']:
                     return
                 if u'PREF' in x.params[u'TYPE']:
                     cand[a] = x.value.encode( 'utf-8' ) + '\0'.join( [''] + [ z.encode('utf-8').lower() for z in x.params[u'TYPE'] if z!=u'PREF' and z!=u'INTERNET' ] )
                     return
                 if a+'Other' not in cand:
                     cand[a+'Other'] = []
                 cand[a+'Other'].append( x.value.encode( 'utf-8' ) + '\0'.join( [''] + [ z.encode('utf-8').lower() for z in x.params[u'TYPE'] if z!=u'PREF' and z!=u'INTERNET' ] ) )
         def type_map_inet( cand, a, x ):
             type_map( cand, a, x, True )
         mapping = {
             'FN': ( 'addressbook.CommonName', stock ),
             'BDAY': ( 'addressbook.Bday', stock ),
             'TEL': ('addressbook.Telephone', type_map ),
             'EMAIL': ('addressbook.Email', type_map_inet ),
             'MAILER': ('addressbook.Mailer', stock ),
             'TITLE': ('addressbook.Title', stock ),
             'ROLE': ('addressbook.Role', stock ),
             'ORG': ('addressbook.Organization', stock ),
             'CATEGORIES': ('addressbook.Categories', stock_multi ),
             'NOTE': ('addressbook.Note', stock ),
             'URL': ('addressbook.HomePage', stock )
             }
         for attr in self.vcf.contents:
             if attr.name in mapping:
                 mapping[attr.name][1]( cand, mapping[attr.name][0], attr )
         t,r,s = srch.wait()
         en = None
         if r.lower()=='ok':
             en = srch[0]
             ename = srch.entries()[0]
         if en is None:
             entrypath = '/addressbook/~/Polymer_' + pref_email_address
         else:
             entrypath = ename
         for xattr in en:
             if xattr in cand:
                 if isinstance(en[xattr]['value'],list):
                     if en[xattr]['value'] == cand[xattr]:
                         del cand[xattr]
         acap.store( entrypath, cand )
Example #3
0
 def delete( self, event ):
     acap = wx.GetApp().connection( self.GetParent().uri )
     p = self.GetParent().uri.path
     if p[-1] != '/':
         p += '/'
     acap.store( p + self._entryname, {'entry':None} )