From f6649d7217bcb26f21af259b2f66b1cc940719f6 Mon Sep 17 00:00:00 2001 From: mguessan Date: Mon, 14 Sep 2009 21:16:15 +0000 Subject: [PATCH] OSX: crazy workaround from Dan Foody to fix attendee search on OSX Snow Leopard git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@717 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- .../davmail/exchange/ExchangeSession.java | 21 +++++++++++-- src/java/davmail/ldap/LdapConnection.java | 31 +++++++++++++------ 2 files changed, 40 insertions(+), 12 deletions(-) diff --git a/src/java/davmail/exchange/ExchangeSession.java b/src/java/davmail/exchange/ExchangeSession.java index cf49041c..86125a23 100644 --- a/src/java/davmail/exchange/ExchangeSession.java +++ b/src/java/davmail/exchange/ExchangeSession.java @@ -1924,6 +1924,8 @@ public class ExchangeSession { } else if (organizer != null && line.startsWith("ATTENDEE") && line.contains(organizer)) { // Ignore organizer as attendee continue; + } else if (!fromServer && line.startsWith("ATTENDEE")) { + line = replaceIcal4Principal(line); } result.writeLine(line); @@ -1938,6 +1940,20 @@ public class ExchangeSession { return result.toString(); } + /** + * Replace iCal4 (Snow Leopard) principal paths with mailto expression + * + * @param value attendee value or ics line + * @return fixed value + */ + protected String replaceIcal4Principal(String value) { + if (value.contains("/principals/__uuids__/")) { + return value.replaceAll("/principals/__uuids__/([^/]*)__AT__([^/]*)/", "mailto:$1@$2"); + } else { + return value; + } + } + protected String fixTimezoneId(String line, String validTimezoneId) { int startIndex = line.indexOf("TZID="); int endIndex = line.indexOf(':', startIndex + 5); @@ -2113,6 +2129,7 @@ public class ExchangeSession { if (colonIndex >= 0) { value = value.substring(colonIndex + 1); } + value = replaceIcal4Principal(value); if ("ORGANIZER".equals(key)) { organizer = value; // exclude current user and invalid values from recipients @@ -2418,7 +2435,7 @@ public class ExchangeSession { // sub calendar folder => append sub folder name int index = folderName.indexOf('/'); if (index >= 0) { - buffer.append(folderName.substring(index)); + buffer.append(folderName.substring(index)); } // replace 'inbox' folder name with i18n name } else if ("inbox".equals(folderName)) { @@ -2793,7 +2810,7 @@ public class ExchangeSession { * @throws IOException on error */ public FreeBusy getFreebusy(String attendee, String startDateValue, String endDateValue) throws IOException { - + attendee = replaceIcal4Principal(attendee); if (attendee.startsWith("mailto:")) { attendee = attendee.substring("mailto:".length()); } diff --git a/src/java/davmail/ldap/LdapConnection.java b/src/java/davmail/ldap/LdapConnection.java index 2b51029e..6af28d9d 100644 --- a/src/java/davmail/ldap/LdapConnection.java +++ b/src/java/davmail/ldap/LdapConnection.java @@ -76,7 +76,6 @@ public class LdapConnection extends AbstractConnection { static final HashMap ATTRIBUTE_MAP = new HashMap(); static { - ATTRIBUTE_MAP.put("apple-generateduid", "AN"); ATTRIBUTE_MAP.put("uid", "AN"); ATTRIBUTE_MAP.put("mail", "EM"); ATTRIBUTE_MAP.put("cn", "DN"); @@ -170,7 +169,7 @@ public class LdapConnection extends AbstractConnection { "urn:uuid:%(guid)s" + "" + "principalPath" + - "/principals/users/%(email)s/" + + "/principals/__uuids__/%(guid)s/" + "" + "" + "" + @@ -787,10 +786,6 @@ public class LdapConnection extends AbstractConnection { } } } else { - // iCal: copy uid to apple-generateduid - if (returningAttributes.contains("apple-generateduid") && person.get("uid") != null) { - person.put("apple-generateduid", person.get("uid")); - } // convert Contact entries for (Map.Entry entry : person.entrySet()) { String contactAttribute = entry.getKey(); @@ -808,10 +803,12 @@ public class LdapConnection extends AbstractConnection { } } + + // TODO: fix for iCal4/iCal3 // iCal: copy cn to sn - if (iCalSearch && ldapPerson.get("cn") != null && returningAttributes.contains("sn")) { - ldapPerson.put("sn", ldapPerson.get("cn")); - } + //if (iCalSearch && ldapPerson.get("cn") != null && returningAttributes.contains("sn")) { + // ldapPerson.put("sn", ldapPerson.get("cn")); + //} // Process all attributes which have static mappings @@ -828,15 +825,29 @@ public class LdapConnection extends AbstractConnection { if (needObjectClasses) { ldapPerson.put("objectClass", PERSON_OBJECT_CLASSES); } + + // iCal: copy email to apple-generateduid, encode @ + if (returnAllAttributes || returningAttributes.contains("apple-generateduid")) { + String mail = (String) ldapPerson.get("mail"); + if (mail != null) { + ldapPerson.put("apple-generateduid", mail.replaceAll("@", "__AT__")); + } else { + // failover, should not happen + ldapPerson.put("apple-generateduid", ldapPerson.get("uid")); + } + } + // iCal: replace current user alias with login name if (session.getAlias().equals(ldapPerson.get("uid"))) { if (returningAttributes.contains("uidnumber")) { ldapPerson.put("uidnumber", userName); } - if (returningAttributes.contains("apple-generateduid")) { + // TODO: check if this breaks iCal3 +/* if (returningAttributes.contains("apple-generateduid")) { ldapPerson.put("apple-generateduid", userName); ldapPerson.put("uid", userName); } +*/ } DavGatewayTray.debug(new BundleMessage("LOG_LDAP_REQ_SEARCH_SEND_PERSON", currentMessageId, ldapPerson.get("uid"), baseContext, ldapPerson)); sendEntry(currentMessageId, "uid=" + ldapPerson.get("uid") + baseContext, ldapPerson);