mirror of
https://github.com/moparisthebest/davmail
synced 2024-12-13 03:02:22 -05:00
EWS: implement loadVtimezone, get user timezone id from OWA settings
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1353 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
b582494bc2
commit
93d528704d
@ -2672,7 +2672,7 @@ public abstract class ExchangeSession {
|
||||
|| line.indexOf(']') == -1)) {
|
||||
}
|
||||
if (line != null) {
|
||||
int start = line.toLowerCase().indexOf('[') + 1;
|
||||
int start = line.indexOf('[') + 1;
|
||||
int end = line.indexOf(']', start);
|
||||
result = line.substring(start, end);
|
||||
}
|
||||
|
@ -305,6 +305,14 @@ public class VCalendar extends VObject {
|
||||
return property.getValue().equalsIgnoreCase("mailto:" + email);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return VTimezone object
|
||||
* @return VTimezone
|
||||
*/
|
||||
public VObject getVTimezone() {
|
||||
return vTimezone;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert X-CALENDARSERVER-ACCESS to CLASS.
|
||||
* see http://svn.calendarserver.org/repository/calendarserver/CalendarServer/trunk/doc/Extensions/caldav-privateevents.txt
|
||||
|
@ -55,7 +55,7 @@ public class VObject {
|
||||
type = beginProperty.getValue();
|
||||
String endLine = "END:" + type;
|
||||
String line = reader.readLine();
|
||||
while (line != null && !endLine.equals(line)) {
|
||||
while (line != null && !line.startsWith(endLine)) {
|
||||
handleLine(line, reader);
|
||||
line = reader.readLine();
|
||||
}
|
||||
|
@ -88,8 +88,8 @@ public abstract class EWSMethod extends PostMethod {
|
||||
/**
|
||||
* Build EWS method
|
||||
*
|
||||
* @param itemType item type
|
||||
* @param methodName method name
|
||||
* @param itemType item type
|
||||
* @param methodName method name
|
||||
* @param responseCollectionName item response collection name
|
||||
*/
|
||||
public EWSMethod(String itemType, String methodName, String responseCollectionName) {
|
||||
@ -374,7 +374,7 @@ public abstract class EWSMethod extends PostMethod {
|
||||
|
||||
protected void writeIndexedPageItemView(Writer writer) throws IOException {
|
||||
if (maxCount > 0) {
|
||||
writer.write("<m:IndexedPageItemView MaxEntriesReturned=\"");
|
||||
writer.write("<m:IndexedPageItemView MaxEntriesReturned=\"");
|
||||
writer.write(String.valueOf(maxCount));
|
||||
writer.write("\" Offset=\"0\" BasePoint=\"Beginning\"/>");
|
||||
}
|
||||
@ -404,7 +404,8 @@ public abstract class EWSMethod extends PostMethod {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Exchange server version, Exchange2010 or Exchange2007_SP1
|
||||
* Get Exchange server version, Exchange2010 or Exchange2007_SP1
|
||||
*
|
||||
* @return server version
|
||||
*/
|
||||
public String getServerVersion() {
|
||||
@ -413,6 +414,7 @@ public abstract class EWSMethod extends PostMethod {
|
||||
|
||||
/**
|
||||
* Set Exchange server version, Exchange2010 or Exchange2007_SP1
|
||||
*
|
||||
* @param serverVersion server version
|
||||
*/
|
||||
public void setServerVersion(String serverVersion) {
|
||||
@ -447,13 +449,19 @@ public abstract class EWSMethod extends PostMethod {
|
||||
writer.write(type);
|
||||
writer.write(">");
|
||||
for (Map.Entry<String, String> mapEntry : this.entrySet()) {
|
||||
writer.write("<t:");
|
||||
writer.write(mapEntry.getKey());
|
||||
writer.write(">");
|
||||
writer.write(StringUtil.xmlEncode(mapEntry.getValue()));
|
||||
writer.write("</t:");
|
||||
writer.write(mapEntry.getKey());
|
||||
writer.write(">");
|
||||
if ("MeetingTimeZone".equals(mapEntry.getKey())) {
|
||||
writer.write("<t:MeetingTimeZone TimeZoneName=\"");
|
||||
writer.write(StringUtil.xmlEncode(mapEntry.getValue()));
|
||||
writer.write("\"></t:MeetingTimeZone>");
|
||||
} else {
|
||||
writer.write("<t:");
|
||||
writer.write(mapEntry.getKey());
|
||||
writer.write(">");
|
||||
writer.write(StringUtil.xmlEncode(mapEntry.getValue()));
|
||||
writer.write("</t:");
|
||||
writer.write(mapEntry.getKey());
|
||||
writer.write(">");
|
||||
}
|
||||
}
|
||||
if (mimeContent != null) {
|
||||
writer.write("<t:MimeContent>");
|
||||
@ -801,7 +809,7 @@ public abstract class EWSMethod extends PostMethod {
|
||||
while (reader.hasNext()) {
|
||||
reader.next();
|
||||
handleErrors(reader);
|
||||
if (serverVersion == null && isStartTag(reader,"ServerVersionInfo")) {
|
||||
if (serverVersion == null && isStartTag(reader, "ServerVersionInfo")) {
|
||||
String majorVersion = getAttributeValue(reader, "MajorVersion");
|
||||
if ("14".equals(majorVersion)) {
|
||||
serverVersion = "Exchange2010";
|
||||
|
@ -22,6 +22,7 @@ import davmail.exception.DavMailAuthenticationException;
|
||||
import davmail.exception.DavMailException;
|
||||
import davmail.exception.HttpNotFoundException;
|
||||
import davmail.exchange.ExchangeSession;
|
||||
import davmail.exchange.VCalendar;
|
||||
import davmail.http.DavGatewayHttpClientFacade;
|
||||
import davmail.util.IOUtil;
|
||||
import davmail.util.StringUtil;
|
||||
@ -30,7 +31,9 @@ import org.apache.commons.httpclient.HttpMethod;
|
||||
import org.apache.commons.httpclient.HttpStatus;
|
||||
import org.apache.commons.httpclient.methods.GetMethod;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
@ -604,7 +607,7 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
GetFolderMethod getFolderMethod = new GetFolderMethod(BaseShape.ID_ONLY, folderId, FOLDER_PROPERTIES);
|
||||
executeMethod(getFolderMethod);
|
||||
EWSMethod.Item item = getFolderMethod.getResponseItem();
|
||||
Folder folder = null;
|
||||
Folder folder;
|
||||
if (item != null) {
|
||||
folder = buildFolder(folderId.mailbox, item);
|
||||
folder.folderPath = folderPath;
|
||||
@ -1135,7 +1138,60 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
|
||||
@Override
|
||||
protected void loadVtimezone() {
|
||||
throw new UnsupportedOperationException();
|
||||
String timezoneId = getTimezoneidFromOptions();
|
||||
try {
|
||||
deleteFolder("davmailtemp");
|
||||
createCalendarFolder("davmailtemp", null);
|
||||
EWSMethod.Item item = new EWSMethod.Item();
|
||||
item.type = "CalendarItem";
|
||||
item.put("MeetingTimeZone", timezoneId);
|
||||
CreateItemMethod createItemMethod = new CreateItemMethod(MessageDisposition.SaveOnly, SendMeetingInvitations.SendToNone, getFolderId("davmailtemp"), item);
|
||||
executeMethod(createItemMethod);
|
||||
item = createItemMethod.getResponseItem();
|
||||
VCalendar vCalendar = new VCalendar(getContent(new ItemId(item)), email, null);
|
||||
this.vTimezone = vCalendar.getVTimezone();
|
||||
// delete temporary folder
|
||||
deleteFolder("davmailtemp");
|
||||
} catch (IOException e) {
|
||||
LOGGER.warn("Unable to get VTIMEZONE info: " + e, e);
|
||||
}
|
||||
}
|
||||
|
||||
protected static final String TMZN = "tblTmZn";
|
||||
|
||||
protected String getTimezoneidFromOptions() {
|
||||
String result = null;
|
||||
// get user mail URL from html body
|
||||
BufferedReader optionsPageReader = null;
|
||||
GetMethod optionsMethod = new GetMethod("/owa/?ae=Options&t=Regional");
|
||||
try {
|
||||
DavGatewayHttpClientFacade.executeGetMethod(httpClient, optionsMethod, false);
|
||||
optionsPageReader = new BufferedReader(new InputStreamReader(optionsMethod.getResponseBodyAsStream()));
|
||||
String line;
|
||||
// find email
|
||||
//noinspection StatementWithEmptyBody
|
||||
while ((line = optionsPageReader.readLine()) != null
|
||||
&& (line.indexOf(TMZN) == -1)) {
|
||||
}
|
||||
if (line != null) {
|
||||
int start = line.indexOf("oV=\"") + 4;
|
||||
int end = line.indexOf('\"', start);
|
||||
result = line.substring(start, end);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("Error parsing options page at " + optionsMethod.getPath());
|
||||
} finally {
|
||||
if (optionsPageReader != null) {
|
||||
try {
|
||||
optionsPageReader.close();
|
||||
} catch (IOException e) {
|
||||
LOGGER.error("Error parsing options page at " + optionsMethod.getPath());
|
||||
}
|
||||
}
|
||||
optionsMethod.releaseConnection();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@ -1274,11 +1330,12 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
return contact;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, ExchangeSession.Contact> galFind(Condition condition, Set<String> returningAttributes, int sizeLimit) throws IOException {
|
||||
Map<String, ExchangeSession.Contact> contacts = new HashMap<String, ExchangeSession.Contact>();
|
||||
if (condition instanceof MultiCondition) {
|
||||
List<Condition> conditions = ((MultiCondition) condition).getConditions();
|
||||
Operator operator = ((MultiCondition) condition).getOperator();
|
||||
List<Condition> conditions = ((ExchangeSession.MultiCondition) condition).getConditions();
|
||||
Operator operator = ((ExchangeSession.MultiCondition) condition).getOperator();
|
||||
if (operator == Operator.Or) {
|
||||
for (Condition innerCondition : conditions) {
|
||||
contacts.putAll(galFind(innerCondition, returningAttributes, sizeLimit));
|
||||
@ -1292,9 +1349,9 @@ public class EwsExchangeSession extends ExchangeSession {
|
||||
}
|
||||
}
|
||||
} else if (condition instanceof AttributeCondition) {
|
||||
String mappedAttributeName = GALFIND_ATTRIBUTE_MAP.get(((AttributeCondition) condition).getAttributeName());
|
||||
String mappedAttributeName = GALFIND_ATTRIBUTE_MAP.get(((ExchangeSession.AttributeCondition) condition).getAttributeName());
|
||||
if (mappedAttributeName != null) {
|
||||
String value = ((AttributeCondition) condition).getValue().toLowerCase();
|
||||
String value = ((ExchangeSession.AttributeCondition) condition).getValue().toLowerCase();
|
||||
Operator operator = ((AttributeCondition) condition).getOperator();
|
||||
String searchValue = value;
|
||||
if (mappedAttributeName.startsWith("EmailAddress")) {
|
||||
|
@ -86,10 +86,16 @@ public class TestExchangeSessionCalendar extends AbstractExchangeSessionTestCase
|
||||
}
|
||||
|
||||
public void testSearchCalendar() throws IOException {
|
||||
List<ExchangeSession.Event> events = session.getAllEvents("/users/" + session.getEmail() + "/calendar/test");
|
||||
List<ExchangeSession.Event> events = null;
|
||||
try {
|
||||
events = session.getAllEvents("/users/" + session.getEmail() + "/calendar");
|
||||
for (ExchangeSession.Event event:events) {
|
||||
System.out.println(event.getBody());
|
||||
}
|
||||
} catch (IOException e) {
|
||||
System.out.println(e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetFreeBusyData() throws IOException, MessagingException {
|
||||
|
Loading…
Reference in New Issue
Block a user