mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 11:12:22 -05:00
EWS: fix folder name ampersand encoding issue
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1268 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
30faeaea21
commit
efeaec5935
@ -18,6 +18,7 @@
|
|||||||
*/
|
*/
|
||||||
package davmail.exchange.ews;
|
package davmail.exchange.ews;
|
||||||
|
|
||||||
|
import davmail.util.StringUtil;
|
||||||
import org.apache.commons.codec.binary.Base64;
|
import org.apache.commons.codec.binary.Base64;
|
||||||
import org.apache.commons.httpclient.Header;
|
import org.apache.commons.httpclient.Header;
|
||||||
import org.apache.commons.httpclient.HttpConnection;
|
import org.apache.commons.httpclient.HttpConnection;
|
||||||
@ -410,7 +411,7 @@ public abstract class EWSMethod extends PostMethod {
|
|||||||
writer.write("<t:");
|
writer.write("<t:");
|
||||||
writer.write(mapEntry.getKey());
|
writer.write(mapEntry.getKey());
|
||||||
writer.write(">");
|
writer.write(">");
|
||||||
writer.write(mapEntry.getValue());
|
writer.write(StringUtil.xmlEncode(mapEntry.getValue()));
|
||||||
writer.write("</t:");
|
writer.write("</t:");
|
||||||
writer.write(mapEntry.getKey());
|
writer.write(mapEntry.getKey());
|
||||||
writer.write(">");
|
writer.write(">");
|
||||||
|
@ -496,7 +496,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
protected Folder buildFolder(EWSMethod.Item item) {
|
protected Folder buildFolder(EWSMethod.Item item) {
|
||||||
Folder folder = new Folder();
|
Folder folder = new Folder();
|
||||||
folder.folderId = new FolderId(item);
|
folder.folderId = new FolderId(item);
|
||||||
folder.displayName = item.get(Field.get("urlcompname").getResponseName());
|
folder.displayName = StringUtil.urlDecodeAmpersand(item.get(Field.get("urlcompname").getResponseName()));
|
||||||
folder.folderClass = item.get(Field.get("folderclass").getResponseName());
|
folder.folderClass = item.get(Field.get("folderclass").getResponseName());
|
||||||
folder.etag = item.get(Field.get("lastmodified").getResponseName());
|
folder.etag = item.get(Field.get("lastmodified").getResponseName());
|
||||||
folder.ctag = item.get(Field.get("ctag").getResponseName());
|
folder.ctag = item.get(Field.get("ctag").getResponseName());
|
||||||
@ -1112,7 +1112,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
|||||||
parentFolderId,
|
parentFolderId,
|
||||||
FOLDER_PROPERTIES,
|
FOLDER_PROPERTIES,
|
||||||
new TwoOperandExpression(TwoOperandExpression.Operator.IsEqualTo,
|
new TwoOperandExpression(TwoOperandExpression.Operator.IsEqualTo,
|
||||||
Field.get("urlcompname"), folderName)
|
Field.get("urlcompname"), StringUtil.urlEncodeAmpersand(folderName))
|
||||||
);
|
);
|
||||||
executeMethod(findFolderMethod);
|
executeMethod(findFolderMethod);
|
||||||
EWSMethod.Item item = findFolderMethod.getResponseItem();
|
EWSMethod.Item item = findFolderMethod.getResponseItem();
|
||||||
|
@ -129,12 +129,42 @@ public final class StringUtil {
|
|||||||
private static final Pattern LT_PATTERN = Pattern.compile("<");
|
private static final Pattern LT_PATTERN = Pattern.compile("<");
|
||||||
private static final Pattern GT_PATTERN = Pattern.compile(">");
|
private static final Pattern GT_PATTERN = Pattern.compile(">");
|
||||||
|
|
||||||
|
private static final Pattern URLENCODED_AMP_PATTERN = Pattern.compile("%26");
|
||||||
|
|
||||||
private static final Pattern ENCODED_AMP_PATTERN = Pattern.compile("&");
|
private static final Pattern ENCODED_AMP_PATTERN = Pattern.compile("&");
|
||||||
private static final Pattern ENCODED_LT_PATTERN = Pattern.compile("<");
|
private static final Pattern ENCODED_LT_PATTERN = Pattern.compile("<");
|
||||||
private static final Pattern ENCODED_GT_PATTERN = Pattern.compile(">");
|
private static final Pattern ENCODED_GT_PATTERN = Pattern.compile(">");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Need to encode xml for iCal
|
* Encode & to %26 for urlcompname.
|
||||||
|
*
|
||||||
|
* @param name decoded name
|
||||||
|
* @return name encoded name
|
||||||
|
*/
|
||||||
|
public static String urlEncodeAmpersand(String name) {
|
||||||
|
String result = name;
|
||||||
|
if (name.indexOf('&') >= 0) {
|
||||||
|
result = AMP_PATTERN.matcher(result).replaceAll("%26");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decode %26 to & for urlcompname.
|
||||||
|
*
|
||||||
|
* @param name decoded name
|
||||||
|
* @return name encoded name
|
||||||
|
*/
|
||||||
|
public static String urlDecodeAmpersand(String name) {
|
||||||
|
String result = name;
|
||||||
|
if (name.indexOf("%26") >= 0) {
|
||||||
|
result = URLENCODED_AMP_PATTERN.matcher(result).replaceAll("&");
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Need to encode xml for iCal.
|
||||||
*
|
*
|
||||||
* @param name decoded name
|
* @param name decoded name
|
||||||
* @return name encoded name
|
* @return name encoded name
|
||||||
|
@ -105,4 +105,17 @@ public class TestExchangeSessionFolder extends AbstractExchangeSessionTestCase {
|
|||||||
assertEquals(folderName, folder.folderPath);
|
assertEquals(folderName, folder.folderPath);
|
||||||
session.deleteFolder(folderName);
|
session.deleteFolder(folderName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSpecialFolderCharacter() throws IOException {
|
||||||
|
String folderName = "Special & accenté";
|
||||||
|
session.deleteFolder(folderName);
|
||||||
|
session.createMessageFolder(folderName);
|
||||||
|
ExchangeSession.Folder folder = session.getFolder(folderName);
|
||||||
|
assertNotNull(folder);
|
||||||
|
assertEquals(folderName, folder.displayName);
|
||||||
|
assertEquals(folderName, folder.folderPath);
|
||||||
|
session.deleteFolder(folderName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -57,4 +57,9 @@ public class StringUtilTest extends TestCase {
|
|||||||
assertEquals(">", StringUtil.xmlDecode(">"));
|
assertEquals(">", StringUtil.xmlDecode(">"));
|
||||||
assertEquals("<test>", StringUtil.xmlEncode("<test>"));
|
assertEquals("<test>", StringUtil.xmlEncode("<test>"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testUrlEncodeAmpersand() {
|
||||||
|
assertEquals("%26", StringUtil.urlEncodeAmpersand("&"));
|
||||||
|
assertEquals("&", StringUtil.urlDecodeAmpersand("%26"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user