mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 03:02:22 -05:00
EWS: implement loadVTimezone for Exchange 2010
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1363 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
c644f792bb
commit
a51d910df6
@ -432,12 +432,21 @@ public abstract class EWSMethod extends PostMethod {
|
||||
protected byte[] mimeContent;
|
||||
protected Set<FieldUpdate> fieldUpdates;
|
||||
protected List<FileAttachment> attachments;
|
||||
protected List<String> fieldNames = new ArrayList<String>();
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "type: " + type + ' ' + super.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String put(String key, String value) {
|
||||
if (get(key) == null) {
|
||||
fieldNames.add(key);
|
||||
}
|
||||
return super.put(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write XML content to writer.
|
||||
*
|
||||
@ -448,18 +457,23 @@ public abstract class EWSMethod extends PostMethod {
|
||||
writer.write("<t:");
|
||||
writer.write(type);
|
||||
writer.write(">");
|
||||
for (Map.Entry<String, String> mapEntry : this.entrySet()) {
|
||||
if ("MeetingTimeZone".equals(mapEntry.getKey())) {
|
||||
// write ordered fields
|
||||
for (String key:fieldNames) {
|
||||
if ("MeetingTimeZone".equals(key)) {
|
||||
writer.write("<t:MeetingTimeZone TimeZoneName=\"");
|
||||
writer.write(StringUtil.xmlEncode(mapEntry.getValue()));
|
||||
writer.write(StringUtil.xmlEncode(get(key)));
|
||||
writer.write("\"></t:MeetingTimeZone>");
|
||||
} else if ("StartTimeZone".equals(key)) {
|
||||
writer.write("<t:StartTimeZone Id=\"");
|
||||
writer.write(StringUtil.xmlEncode(get(key)));
|
||||
writer.write("\"></t:StartTimeZone>");
|
||||
} else {
|
||||
writer.write("<t:");
|
||||
writer.write(mapEntry.getKey());
|
||||
writer.write(key);
|
||||
writer.write(">");
|
||||
writer.write(StringUtil.xmlEncode(mapEntry.getValue()));
|
||||
writer.write(StringUtil.xmlEncode(get(key)));
|
||||
writer.write("</t:");
|
||||
writer.write(mapEntry.getKey());
|
||||
writer.write(key);
|
||||
writer.write(">");
|
||||
}
|
||||
}
|
||||
@ -643,6 +657,7 @@ public abstract class EWSMethod extends PostMethod {
|
||||
&& !"NoError".equals(result)
|
||||
&& !"ErrorNameResolutionMultipleResults".equals(result)
|
||||
&& !"ErrorNameResolutionNoResults".equals(result)
|
||||
&& !"ErrorFolderExists".equals(result)
|
||||
) {
|
||||
errorDetail = result;
|
||||
}
|
||||
|
@ -625,8 +625,8 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
FolderPath path = new FolderPath(folderPath);
|
||||
EWSMethod.Item folder = new EWSMethod.Item();
|
||||
folder.type = "Folder";
|
||||
folder.put("DisplayName", path.folderName);
|
||||
folder.put("FolderClass", folderClass);
|
||||
folder.put("DisplayName", path.folderName);
|
||||
// TODO: handle properties
|
||||
CreateFolderMethod createFolderMethod = new CreateFolderMethod(getFolderId(path.parentPath), folder);
|
||||
executeMethod(createFolderMethod);
|
||||
@ -875,7 +875,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
|
||||
@Override
|
||||
public ItemResult createOrUpdate() throws IOException {
|
||||
byte[] itemContent = Base64.encodeBase64(vCalendar.toString().getBytes("UTF-8"));
|
||||
byte[] itemContent = Base64.encodeBase64(createMimeContent());
|
||||
|
||||
ItemResult itemResult = new ItemResult();
|
||||
EWSMethod createOrUpdateItemMethod;
|
||||
@ -1142,12 +1142,28 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
|
||||
@Override
|
||||
protected void loadVtimezone() {
|
||||
String timezoneId = getTimezoneidFromOptions();
|
||||
|
||||
try {
|
||||
String timezoneId = null;
|
||||
if ("Exchange2010".equals(serverVersion)) {
|
||||
GetUserConfigurationMethod getUserConfigurationMethod = new GetUserConfigurationMethod();
|
||||
executeMethod(getUserConfigurationMethod);
|
||||
EWSMethod.Item item = getUserConfigurationMethod.getResponseItem();
|
||||
if (item != null) {
|
||||
timezoneId = item.get("timezone");
|
||||
}
|
||||
} else {
|
||||
getTimezoneidFromOptions();
|
||||
}
|
||||
if (timezoneId != null) {
|
||||
createCalendarFolder("davmailtemp", null);
|
||||
EWSMethod.Item item = new EWSMethod.Item();
|
||||
item.type = "CalendarItem";
|
||||
if ("Exchange2010".equals(serverVersion)) {
|
||||
item.put("StartTimeZone", timezoneId);
|
||||
} else {
|
||||
item.put("MeetingTimeZone", timezoneId);
|
||||
}
|
||||
CreateItemMethod createItemMethod = new CreateItemMethod(MessageDisposition.SaveOnly, SendMeetingInvitations.SendToNone, getFolderId("davmailtemp"), item);
|
||||
executeMethod(createItemMethod);
|
||||
item = createItemMethod.getResponseItem();
|
||||
@ -1155,6 +1171,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
this.vTimezone = vCalendar.getVTimezone();
|
||||
// delete temporary folder
|
||||
deleteFolder("davmailtemp");
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn("Unable to get VTIMEZONE info: " + e, e);
|
||||
}
|
||||
|
@ -0,0 +1,87 @@
|
||||
/*
|
||||
* DavMail POP/IMAP/SMTP/CalDav/LDAP Exchange Gateway
|
||||
* Copyright (C) 2010 Mickael Guessant
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* as published by the Free Software Foundation; either version 2
|
||||
* of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
*/
|
||||
package davmail.exchange.ews;
|
||||
|
||||
import javax.xml.stream.XMLStreamConstants;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
import javax.xml.stream.XMLStreamReader;
|
||||
import java.io.IOException;
|
||||
import java.io.Writer;
|
||||
|
||||
/**
|
||||
* Get User Configuration method.
|
||||
*/
|
||||
public class GetUserConfigurationMethod extends EWSMethod {
|
||||
|
||||
/**
|
||||
* Get User Configuration method.
|
||||
*
|
||||
*/
|
||||
public GetUserConfigurationMethod() {
|
||||
super("UserConfiguration", "GetUserConfiguration");
|
||||
folderId = DistinguishedFolderId.getInstance(null, DistinguishedFolderId.Name.root);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeSoapBody(Writer writer) throws IOException {
|
||||
writer.write("<m:UserConfigurationName Name=\"OWA.UserOptions\">");
|
||||
folderId.write(writer);
|
||||
writer.write("</m:UserConfigurationName>");
|
||||
writer.write("<m:UserConfigurationProperties>All</m:UserConfigurationProperties>");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void handleCustom(XMLStreamReader reader) throws XMLStreamException {
|
||||
if (isStartTag(reader, "UserConfiguration")) {
|
||||
responseItems.add(handleUserConfiguration(reader));
|
||||
}
|
||||
}
|
||||
|
||||
private Item handleUserConfiguration(XMLStreamReader reader) throws XMLStreamException {
|
||||
Item responseItem = new Item();
|
||||
while (reader.hasNext() && !(isEndTag(reader, "UserConfiguration"))) {
|
||||
int event = reader.next();
|
||||
if (event == XMLStreamConstants.START_ELEMENT) {
|
||||
String tagLocalName = reader.getLocalName();
|
||||
if ("DictionaryEntry".equals(tagLocalName)) {
|
||||
handleDictionaryEntry(reader, responseItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
return responseItem;
|
||||
}
|
||||
|
||||
private void handleDictionaryEntry(XMLStreamReader reader, Item responseItem) throws XMLStreamException {
|
||||
String key = null;
|
||||
while (reader.hasNext() && !(isEndTag(reader, "DictionaryEntry"))) {
|
||||
int event = reader.next();
|
||||
if (event == XMLStreamConstants.START_ELEMENT) {
|
||||
String tagLocalName = reader.getLocalName();
|
||||
if ("Value".equals(tagLocalName)) {
|
||||
if (key == null) {
|
||||
key = reader.getElementText();
|
||||
} else {
|
||||
responseItem.put(key, reader.getElementText());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -178,6 +178,7 @@ public final class StringUtil {
|
||||
*/
|
||||
public static String xmlEncode(String name) {
|
||||
String result = name;
|
||||
if (name != null) {
|
||||
if (name.indexOf('&') >= 0) {
|
||||
result = AMP_PATTERN.matcher(result).replaceAll("&");
|
||||
}
|
||||
@ -187,6 +188,7 @@ public final class StringUtil {
|
||||
if (name.indexOf('>') >= 0) {
|
||||
result = GT_PATTERN.matcher(result).replaceAll(">");
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -66,4 +66,15 @@ public class TestEwsExchangeSession extends AbstractExchangeSessionTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetUserConfiguration() throws IOException {
|
||||
GetUserConfigurationMethod getUserConfigurationMethod = new GetUserConfigurationMethod();
|
||||
ewsSession.executeMethod(getUserConfigurationMethod);
|
||||
EWSMethod.Item item = getUserConfigurationMethod.getResponseItem();
|
||||
assertNotNull(item);
|
||||
}
|
||||
|
||||
public void testTimezone() {
|
||||
ewsSession.loadVtimezone();
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user