From 7a3165947321f69248fde948dc154cbc50e4af12 Mon Sep 17 00:00:00 2001 From: mguessan Date: Thu, 21 Jul 2011 22:40:08 +0000 Subject: [PATCH] Caldav: new CRLF in urlcompname patch for EWS, use _x000D__x000A_ as encoded value git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1744 3d1905a2-6b24-0410-a738-b14d5a86fcbd --- .../davmail/exchange/ews/EwsExchangeSession.java | 3 +++ src/java/davmail/util/StringUtil.java | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/java/davmail/exchange/ews/EwsExchangeSession.java b/src/java/davmail/exchange/ews/EwsExchangeSession.java index 3948c64e..10e59054 100644 --- a/src/java/davmail/exchange/ews/EwsExchangeSession.java +++ b/src/java/davmail/exchange/ews/EwsExchangeSession.java @@ -1174,6 +1174,9 @@ public class EwsExchangeSession extends ExchangeSession { // workaround for missing urlcompname in Exchange 2010 if (itemName == null) { itemName = StringUtil.base64ToUrl(itemId.id) + ".EML"; + } else if (itemName.indexOf('\n') >= 0) { + // encode line feed + itemName = itemName.replaceAll("\n", "_x000D__x000A_"); } String instancetype = response.get(Field.get("instancetype").getResponseName()); boolean isrecurring = "true".equals(response.get(Field.get("isrecurring").getResponseName())); diff --git a/src/java/davmail/util/StringUtil.java b/src/java/davmail/util/StringUtil.java index 55634e12..9729571e 100644 --- a/src/java/davmail/util/StringUtil.java +++ b/src/java/davmail/util/StringUtil.java @@ -133,7 +133,8 @@ public final class StringUtil { private static final Pattern GT_PATTERN = Pattern.compile(">"); private static final Pattern QUOTE_PATTERN = Pattern.compile("\""); - private static final Pattern LF_PATTERN = Pattern.compile("\n"); + private static final Pattern CR_PATTERN = Pattern.compile("\r"); + private static final Pattern LF_PATTERN = Pattern.compile("\n"); private static final Pattern URLENCODED_AMP_PATTERN = Pattern.compile("%26"); @@ -142,6 +143,8 @@ public final class StringUtil { private static final Pattern ENCODED_GT_PATTERN = Pattern.compile(">"); private static final Pattern F8FF_PATTERN = Pattern.compile("_xF8FF_"); + private static final Pattern X0D0A_PATTERN = Pattern.compile("_x000D__x000A_"); + private static final Pattern PLUS_PATTERN = Pattern.compile("\\+"); private static final Pattern COLON_PATTERN = Pattern.compile(":"); private static final Pattern SLASH_PATTERN = Pattern.compile("/"); @@ -213,6 +216,12 @@ public final class StringUtil { if (result.indexOf('"') >= 0) { result = QUOTE_PATTERN.matcher(result).replaceAll("""); } + if (result.indexOf('\r') >=0) { + result = CR_PATTERN.matcher(result).replaceAll(" "); + } + if (result.indexOf('\n') >=0) { + result = LF_PATTERN.matcher(result).replaceAll(" "); + } } return result; } @@ -295,8 +304,8 @@ public final class StringUtil { if (result.indexOf('"') >= 0) { result = QUOTE_PATTERN.matcher(result).replaceAll("%22"); } - if (result.indexOf('\n') >= 0) { - result = LF_PATTERN.matcher(result).replaceAll("%0A"); + if (result.indexOf("_x000D__x000A_") >= 0) { + result = X0D0A_PATTERN.matcher(result).replaceAll("\r\n"); } return result; }