Addressbook plugin improvements

View: New views
1 Messages — Rating Filter:   Alert me  

Addressbook plugin improvements

by Geert Janssens :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi,

I have been looking into many LDAP based address book programs to find one
that can replace our database base solution. So far find Luma to have the
best balance between flexibility and user-friendliness.

While playing around with it, I stumbled upon two bugs, for which I have added
a fix in the attached diff.

1. The addressBox is not properly reset when switching contacts.
----------------------------------------------------------------
To reproduce:
* Select a contact in the addressbook plugin
* Click on the Phone/Address tab
* Select "Other" in the addressBox
* Now select another contact
=> The addressBox will continue to display "Other" while the address actually
being displayed is the "Business" address

Fix: reset the addressBox to "Business" when changing contacts

2. Addresses are not submitted to LDAP in an RFC 2252 compliant way
-------------------------------------------------------------------
RFC 2252 requires a specific syntax for attributes of type "Postal Address"
(freely translated):
- newlines should be replaced with $-signs
- existing $-signs in the address should be encoded in hex notation ('\24')
- existing \-characters in the address should equally be encoded (as '\5c'
or '\5C')
Luma currently doesn't do this.

Fix: convert the address before displaying it in the addressEdit widget, or
before saving a changed address entry.
Addresses that are already in LDAP with newlines will continue to work with
this fix without modification. Any changes to such an already existing
address will convert it into the compliant format. New addresses will be sent
to LDAP in the compliant format.

Hopefully this patch is useful.

Regards,

Geert Janssens

[AddressbookWidget.py.diff]

Index: lib/luma/plugins/addressbook/AddressbookWidget.py
===================================================================
--- lib/luma/plugins/addressbook/AddressbookWidget.py (revision 748)
+++ lib/luma/plugins/addressbook/AddressbookWidget.py (working copy)
@@ -205,6 +205,7 @@
                 self.birthDateEdit.setDate(QDate(int(tmpList[0]), int(tmpList[1]), int(tmpList[2])))
                 
         self.addressID = 0
+        self.addressBox.setCurrentItem(0)
         self.initAddress(0, False)
         self.ENABLE_SAVE = True
         self.setSaveButton()
@@ -388,21 +389,38 @@
                 
 ###############################################################################
 
+    def ldap2Gui(self, address):
+        address=address.replace('$','\n')
+        address=address.replace('\\24','$')
+        address=address.replace('\\5C','\\5c')
+        address=address.replace('\\5c','\\')
+        
+        return address
+###############################################################################
+
+    def gui2Ldap(self, address):
+        address=address.replace('\\','\\5c')
+        address=address.replace('$','\\24')
+        address=address.replace('\n','$')
+        
+        return address
+###############################################################################
+
     def initAddress(self, id, saveValue=True):
-        # The order os the attributes resembles the order of apearance in the widget
+        # The order of the attributes resembles the order of apearance in the widget
         addressType = ['postalAddress', 'homePostalAddress', 'otherPostalAddress']
         
         if saveValue:
             if self.dataObject.isAttributeAllowed(addressType[self.addressID]):
                 value = unicode(self.addressEdit.text())
                 if not (value==''):
-                    self.dataObject.addAttributeValue(addressType[self.addressID], [value], True)
+                    self.dataObject.addAttributeValue(addressType[self.addressID], [self.gui2Ldap(value)], True)
         
         self.addressID = id
         self.addressEdit.clear()
         if self.dataObject.hasAttribute(addressType[id]):
             tmpAddress = self.dataObject.getAttributeValue(addressType[id], 0)
-            self.addressEdit.setText(tmpAddress)
+            self.addressEdit.setText(self.ldap2Gui(tmpAddress))
         
         
 ###############################################################################
@@ -582,7 +600,7 @@
         if addressType[id] in self.allowedAttributes:
             value = unicode(self.addressEdit.text())
             if not('' == value):
-                self.dataObject.addAttributeValue(addressType[id], [value], True)
+                self.dataObject.addAttributeValue(addressType[id], [self.gui2Ldap(value)], True)
             else:
                 self.dataObject.deleteAttribute(addressType[id])
         


-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Luma-devel mailing list
Luma-devel@...
https://lists.sourceforge.net/lists/listinfo/luma-devel
LightInTheBox - Buy quality products at wholesale price!