DAV: fix from audit

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1100 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-06-21 09:38:24 +00:00
parent 878f30818e
commit dc6051da1a
2 changed files with 50 additions and 30 deletions

View File

@ -1564,7 +1564,7 @@ public abstract class ExchangeSession {
public abstract class Event extends Item { public abstract class Event extends Item {
/** /**
* {@inheritDoc} * @inheritDoc
*/ */
public Event(String messageUrl, String contentClass, String itemBody, String etag, String noneMatch) { public Event(String messageUrl, String contentClass, String itemBody, String etag, String noneMatch) {
super(messageUrl, contentClass, itemBody, etag, noneMatch); super(messageUrl, contentClass, itemBody, etag, noneMatch);

View File

@ -41,8 +41,9 @@ import org.apache.jackrabbit.webdav.client.methods.CopyMethod;
import org.apache.jackrabbit.webdav.client.methods.MoveMethod; import org.apache.jackrabbit.webdav.client.methods.MoveMethod;
import org.apache.jackrabbit.webdav.client.methods.PropFindMethod; import org.apache.jackrabbit.webdav.client.methods.PropFindMethod;
import org.apache.jackrabbit.webdav.client.methods.PropPatchMethod; import org.apache.jackrabbit.webdav.client.methods.PropPatchMethod;
import org.apache.jackrabbit.webdav.property.*; import org.apache.jackrabbit.webdav.property.DavProperty;
import org.apache.jackrabbit.webdav.xml.Namespace; import org.apache.jackrabbit.webdav.property.DavPropertyNameSet;
import org.apache.jackrabbit.webdav.property.DavPropertySet;
import javax.mail.MessagingException; import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage; import javax.mail.internet.MimeMessage;
@ -119,7 +120,7 @@ public class DavExchangeSession extends ExchangeSession {
// caldav path // caldav path
} else if (folderName.startsWith(USERS)) { } else if (folderName.startsWith(USERS)) {
// get requested principal // get requested principal
String principal = null; String principal;
String localPath; String localPath;
int principalIndex = folderName.indexOf('/', USERS.length()); int principalIndex = folderName.indexOf('/', USERS.length());
if (principalIndex >= 0) { if (principalIndex >= 0) {
@ -129,9 +130,9 @@ public class DavExchangeSession extends ExchangeSession {
localPath = inboxName + localPath.substring(LOWER_CASE_INBOX.length()); localPath = inboxName + localPath.substring(LOWER_CASE_INBOX.length());
} else if (localPath.startsWith(CALENDAR)) { } else if (localPath.startsWith(CALENDAR)) {
localPath = calendarName + localPath.substring(CALENDAR.length()); localPath = calendarName + localPath.substring(CALENDAR.length());
} else if (localPath.startsWith(CONTACTS) ) { } else if (localPath.startsWith(CONTACTS)) {
localPath = contactsName + localPath.substring(CONTACTS.length()); localPath = contactsName + localPath.substring(CONTACTS.length());
} else if (localPath.startsWith(ADDRESSBOOK) ) { } else if (localPath.startsWith(ADDRESSBOOK)) {
localPath = contactsName + localPath.substring(ADDRESSBOOK.length()); localPath = contactsName + localPath.substring(ADDRESSBOOK.length());
} }
} else { } else {
@ -168,6 +169,7 @@ public class DavExchangeSession extends ExchangeSession {
* @throws IOException on error * @throws IOException on error
* @deprecated user getFolderPath instead * @deprecated user getFolderPath instead
*/ */
@Override
public String buildCalendarPath(String principal, String folderName) throws IOException { public String buildCalendarPath(String principal, String folderName) throws IOException {
StringBuilder buffer = new StringBuilder(); StringBuilder buffer = new StringBuilder();
// other user calendar => replace principal folder name in mailPath // other user calendar => replace principal folder name in mailPath
@ -424,8 +426,7 @@ public class DavExchangeSession extends ExchangeSession {
@Override @Override
public void appendTo(StringBuilder buffer) { public void appendTo(StringBuilder buffer) {
boolean first = true; buffer.append("(Not ");
buffer.append("( Not ");
condition.appendTo(buffer); condition.appendTo(buffer);
buffer.append(')'); buffer.append(')');
} }
@ -445,7 +446,7 @@ public class DavExchangeSession extends ExchangeSession {
} }
protected static class AttributeCondition extends ExchangeSession.AttributeCondition { protected static class AttributeCondition extends ExchangeSession.AttributeCondition {
protected boolean isIntValue = false; protected boolean isIntValue;
protected AttributeCondition(String attributeName, Operator operator, String value) { protected AttributeCondition(String attributeName, Operator operator, String value) {
super(attributeName, operator, value); super(attributeName, operator, value);
@ -511,12 +512,12 @@ public class DavExchangeSession extends ExchangeSession {
} }
@Override @Override
public MultiCondition and(Condition... condition) { public ExchangeSession.MultiCondition and(Condition... condition) {
return new MultiCondition(Operator.And, condition); return new MultiCondition(Operator.And, condition);
} }
@Override @Override
public MultiCondition or(Condition... condition) { public ExchangeSession.MultiCondition or(Condition... condition) {
return new MultiCondition(Operator.Or, condition); return new MultiCondition(Operator.Or, condition);
} }
@ -584,6 +585,9 @@ public class DavExchangeSession extends ExchangeSession {
return new MonoCondition(attributeName, Operator.IsFalse); return new MonoCondition(attributeName, Operator.IsFalse);
} }
/**
* @inheritDoc
*/
public class Contact extends ExchangeSession.Contact { public class Contact extends ExchangeSession.Contact {
/** /**
* Build Contact instance from multistatusResponse info * Build Contact instance from multistatusResponse info
@ -708,6 +712,12 @@ public class DavExchangeSession extends ExchangeSession {
return list; return list;
} }
/**
* Create or update contact
*
* @return action result
* @throws IOException on error
*/
public ItemResult createOrUpdate() throws IOException { public ItemResult createOrUpdate() throws IOException {
int status = 0; int status = 0;
PropPatchMethod propPatchMethod = new PropPatchMethod(URIUtil.encodePath(href), buildProperties()); PropPatchMethod propPatchMethod = new PropPatchMethod(URIUtil.encodePath(href), buildProperties());
@ -763,6 +773,9 @@ public class DavExchangeSession extends ExchangeSession {
} }
/**
* @inheritDoc
*/
public class Event extends ExchangeSession.Event { public class Event extends ExchangeSession.Event {
/** /**
* Build Event instance from response info. * Build Event instance from response info.
@ -778,6 +791,10 @@ public class DavExchangeSession extends ExchangeSession {
displayName = getPropertyIfExists(properties, "displayname"); displayName = getPropertyIfExists(properties, "displayname");
} }
/**
* @inheritDoc
*/
public Event(String messageUrl, String contentClass, String itemBody, String etag, String noneMatch) { public Event(String messageUrl, String contentClass, String itemBody, String etag, String noneMatch) {
super(messageUrl, contentClass, itemBody, etag, noneMatch); super(messageUrl, contentClass, itemBody, etag, noneMatch);
} }
@ -788,7 +805,7 @@ public class DavExchangeSession extends ExchangeSession {
* @param mimeInputStream mime message input stream * @param mimeInputStream mime message input stream
* @return mime message ics attachment body * @return mime message ics attachment body
* @throws IOException on error * @throws IOException on error
* @throws javax.mail.MessagingException on error * @throws MessagingException on error
*/ */
protected String getICS(InputStream mimeInputStream) throws IOException, MessagingException { protected String getICS(InputStream mimeInputStream) throws IOException, MessagingException {
String result; String result;
@ -875,6 +892,10 @@ public class DavExchangeSession extends ExchangeSession {
return result; return result;
} }
/**
* @inheritDoc
*/
@Override
protected ItemResult createOrUpdate(byte[] messageContent) throws IOException { protected ItemResult createOrUpdate(byte[] messageContent) throws IOException {
PutMethod putmethod = new PutMethod(URIUtil.encodePath(href)); PutMethod putmethod = new PutMethod(URIUtil.encodePath(href));
putmethod.setRequestHeader("Translate", "f"); putmethod.setRequestHeader("Translate", "f");
@ -1045,6 +1066,7 @@ public class DavExchangeSession extends ExchangeSession {
/** /**
* @inheritDoc * @inheritDoc
*/ */
@Override
public void createFolder(String folderName, String folderClass) throws IOException { public void createFolder(String folderName, String folderClass) throws IOException {
String folderPath = getFolderPath(folderName); String folderPath = getFolderPath(folderName);
ArrayList<DavConstants> list = new ArrayList<DavConstants>(); ArrayList<DavConstants> list = new ArrayList<DavConstants>();
@ -1205,7 +1227,7 @@ public class DavExchangeSession extends ExchangeSession {
return events; return events;
} }
public MultiStatusResponse[] searchItems(String folderName, List<String> attributes, Condition condition) throws IOException { protected MultiStatusResponse[] searchItems(String folderName, List<String> attributes, Condition condition) throws IOException {
String folderUrl = getFolderPath(folderName); String folderUrl = getFolderPath(folderName);
StringBuilder searchRequest = new StringBuilder(); StringBuilder searchRequest = new StringBuilder();
searchRequest.append("SELECT ") searchRequest.append("SELECT ")
@ -1319,8 +1341,7 @@ public class DavExchangeSession extends ExchangeSession {
@Override @Override
public ItemResult internalCreateOrUpdateEvent(String messageUrl, String contentClass, String icsBody, String etag, String noneMatch) throws IOException { public ItemResult internalCreateOrUpdateEvent(String messageUrl, String contentClass, String icsBody, String etag, String noneMatch) throws IOException {
Event event = new Event(messageUrl, contentClass, icsBody, etag, noneMatch); return new Event(messageUrl, contentClass, icsBody, etag, noneMatch).createOrUpdate();
return event.createOrUpdate();
} }
/** /**
@ -1329,7 +1350,7 @@ public class DavExchangeSession extends ExchangeSession {
@Override @Override
protected void loadVtimezone() { protected void loadVtimezone() {
try { try {
VTimezone vTimezone = new VTimezone(); VTimezone userTimezone = new VTimezone();
// create temporary folder // create temporary folder
String folderPath = getFolderPath("davmailtemp"); String folderPath = getFolderPath("davmailtemp");
createCalendarFolder(folderPath); createCalendarFolder(folderPath);
@ -1354,9 +1375,9 @@ public class DavExchangeSession extends ExchangeSession {
propertyList.add(Field.createDavProperty("outlookmessageclass", "IPM.Appointment")); propertyList.add(Field.createDavProperty("outlookmessageclass", "IPM.Appointment"));
propertyList.add(Field.createDavProperty("instancetype", "0")); propertyList.add(Field.createDavProperty("instancetype", "0"));
// get forced timezone id from settings // get forced timezone id from settings
vTimezone.timezoneId = Settings.getProperty("davmail.timezoneId"); userTimezone.timezoneId = Settings.getProperty("davmail.timezoneId");
if (vTimezone.timezoneId != null) { if (userTimezone.timezoneId != null) {
propertyList.add(Field.createDavProperty("timezoneid", vTimezone.timezoneId)); propertyList.add(Field.createDavProperty("timezoneid", userTimezone.timezoneId));
} }
String patchMethodUrl = URIUtil.encodePath(folderPath) + '/' + UUID.randomUUID().toString() + ".EML"; String patchMethodUrl = URIUtil.encodePath(folderPath) + '/' + UUID.randomUUID().toString() + ".EML";
PropPatchMethod patchMethod = new PropPatchMethod(URIUtil.encodePath(patchMethodUrl), propertyList); PropPatchMethod patchMethod = new PropPatchMethod(URIUtil.encodePath(patchMethodUrl), propertyList);
@ -1375,10 +1396,10 @@ public class DavExchangeSession extends ExchangeSession {
getMethod.setRequestHeader("Translate", "f"); getMethod.setRequestHeader("Translate", "f");
try { try {
httpClient.executeMethod(getMethod); httpClient.executeMethod(getMethod);
vTimezone.timezoneBody = "BEGIN:VTIMEZONE" + userTimezone.timezoneBody = "BEGIN:VTIMEZONE" +
StringUtil.getToken(getMethod.getResponseBodyAsString(), "BEGIN:VTIMEZONE", "END:VTIMEZONE") + StringUtil.getToken(getMethod.getResponseBodyAsString(), "BEGIN:VTIMEZONE", "END:VTIMEZONE") +
"END:VTIMEZONE\r\n"; "END:VTIMEZONE\r\n";
vTimezone.timezoneId = StringUtil.getToken(vTimezone.timezoneBody, "TZID:", "\r\n"); userTimezone.timezoneId = StringUtil.getToken(userTimezone.timezoneBody, "TZID:", "\r\n");
} finally { } finally {
getMethod.releaseConnection(); getMethod.releaseConnection();
} }
@ -1386,7 +1407,7 @@ public class DavExchangeSession extends ExchangeSession {
// delete temporary folder // delete temporary folder
deleteFolder("davmailtemp"); deleteFolder("davmailtemp");
this.vTimezone = vTimezone; this.vTimezone = userTimezone;
} catch (IOException e) { } catch (IOException e) {
LOGGER.warn("Unable to get VTIMEZONE info: " + e, e); LOGGER.warn("Unable to get VTIMEZONE info: " + e, e);
} }
@ -1394,8 +1415,7 @@ public class DavExchangeSession extends ExchangeSession {
@Override @Override
protected ItemResult internalCreateOrUpdateContact(String messageUrl, String contentClass, String icsBody, String etag, String noneMatch) throws IOException { protected ItemResult internalCreateOrUpdateContact(String messageUrl, String contentClass, String icsBody, String etag, String noneMatch) throws IOException {
Contact contact = new Contact(messageUrl, contentClass, icsBody, etag, noneMatch); return new Contact(messageUrl, contentClass, icsBody, etag, noneMatch).createOrUpdate();
return contact.createOrUpdate();
} }
protected List<DavConstants> buildProperties(Map<String, String> properties) { protected List<DavConstants> buildProperties(Map<String, String> properties) {
@ -1516,7 +1536,7 @@ public class DavExchangeSession extends ExchangeSession {
*/ */
@Override @Override
public void deleteMessage(Message message) throws IOException { public void deleteMessage(Message message) throws IOException {
LOGGER.debug("Delete " + message.permanentUrl + " (" + message.messageUrl + ")"); LOGGER.debug("Delete " + message.permanentUrl + " (" + message.messageUrl + ')');
DavGatewayHttpClientFacade.executeDeleteMethod(httpClient, message.permanentUrl); DavGatewayHttpClientFacade.executeDeleteMethod(httpClient, message.permanentUrl);
} }
@ -1554,7 +1574,7 @@ public class DavExchangeSession extends ExchangeSession {
*/ */
@Override @Override
protected BufferedReader getContentReader(Message message) throws IOException { protected BufferedReader getContentReader(Message message) throws IOException {
BufferedReader reader = null; BufferedReader reader;
try { try {
reader = getContentReader(message, message.messageUrl); reader = getContentReader(message, message.messageUrl);
} catch (HttpNotFoundException e) { } catch (HttpNotFoundException e) {
@ -1565,12 +1585,12 @@ public class DavExchangeSession extends ExchangeSession {
} }
protected BufferedReader getContentReader(Message message, String url) throws IOException { protected BufferedReader getContentReader(Message message, String url) throws IOException {
final GetMethod method = new GetMethod(URIUtil.encodePath(message.permanentUrl)); final GetMethod method = new GetMethod(URIUtil.encodePath(url));
method.setRequestHeader("Content-Type", "text/xml; charset=utf-8"); method.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
method.setRequestHeader("Translate", "f"); method.setRequestHeader("Translate", "f");
method.setRequestHeader("Accept-Encoding", "gzip"); method.setRequestHeader("Accept-Encoding", "gzip");
BufferedReader reader = null; BufferedReader reader;
try { try {
DavGatewayHttpClientFacade.executeGetMethod(httpClient, method, true); DavGatewayHttpClientFacade.executeGetMethod(httpClient, method, true);
InputStreamReader inputStreamReader; InputStreamReader inputStreamReader;