import ImageOps
import StringIO
import datetime
+import re
from pygobject import *
from ctypes import *
# -----------------------------------------------------------------------
- def add_url(self, contact, url, unique = ''):
+ def add_url(self, contact, str, unique = ''):
"""Add a new URL to the set of URLs for the given contact."""
- unique = unique or url
+ urls = re.findall('(?:(?:ftp|https?):\/\/|\\bwww\.|\\bftp\.)[,\w\.\-\/@:%?&=%+#~_$\*]+[\w=\/&=+#]', str, re.I | re.S)
+ updated = False
+ for url in urls:
+ updated = self._add_url(contact, url, unique or url) or updated
+
+ return updated
+
+
+ # -----------------------------------------------------------------------
+ def _add_url(self, contact, url, unique):
+ """Do the work of adding a unique URL to a contact."""
+
url_attr = None
ai = GList.new(ebook.e_contact_get_attributes(hash(contact), E_CONTACT_HOMEPAGE_URL))
while ai.has_next():
elif existing.find(unique) > -1:
url_attr = attr
break
-
+
if not url_attr:
ai.add()
url_attr = EVCardAttribute()
url_attr.group = ''
url_attr.name = 'URL'
-
+
val = GList()
print "Setting URL for [%s] to [%s]" % (contact.get_name(), url)
val.set(create_string_buffer(url))