Fixes from audit

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@1192 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2010-07-18 19:56:47 +00:00
parent f1075c57e7
commit e407485e9b
9 changed files with 189 additions and 99 deletions

View File

@ -561,6 +561,7 @@ public class DavExchangeSession extends ExchangeSession {
* *
* @param multiStatusResponse response * @param multiStatusResponse response
* @throws URIException on error * @throws URIException on error
* @throws DavMailException on error
*/ */
public Contact(MultiStatusResponse multiStatusResponse) throws URIException, DavMailException { public Contact(MultiStatusResponse multiStatusResponse) throws URIException, DavMailException {
setHref(URIUtil.decode(multiStatusResponse.getHref())); setHref(URIUtil.decode(multiStatusResponse.getHref()));
@ -590,10 +591,9 @@ public class DavExchangeSession extends ExchangeSession {
ArrayList<DavConstants> list = new ArrayList<DavConstants>(); ArrayList<DavConstants> list = new ArrayList<DavConstants>();
for (Map.Entry<String, String> entry : entrySet()) { for (Map.Entry<String, String> entry : entrySet()) {
String key = entry.getKey(); String key = entry.getKey();
if (key.startsWith("email") || key.equals("private")) { if (key.startsWith("email") || "private".equals(key)) {
key = "write" + key; list.add(Field.createDavProperty("write" + key, entry.getValue()));
} } else if (!"photo".equals(key)) {
if (!"photo".equals(key)) {
list.add(Field.createDavProperty(key, entry.getValue())); list.add(Field.createDavProperty(key, entry.getValue()));
} }
} }
@ -625,6 +625,7 @@ public class DavExchangeSession extends ExchangeSession {
try { try {
status = httpClient.executeMethod(propPatchMethod); status = httpClient.executeMethod(propPatchMethod);
if (status == HttpStatus.SC_MULTI_STATUS) { if (status == HttpStatus.SC_MULTI_STATUS) {
//noinspection VariableNotUsedInsideIf
if (etag == null) { if (etag == null) {
status = HttpStatus.SC_CREATED; status = HttpStatus.SC_CREATED;
LOGGER.debug("Created contact " + getHref()); LOGGER.debug("Created contact " + getHref());
@ -810,6 +811,7 @@ public class DavExchangeSession extends ExchangeSession {
try { try {
status = httpClient.executeMethod(putmethod); status = httpClient.executeMethod(putmethod);
if (status == HttpURLConnection.HTTP_OK) { if (status == HttpURLConnection.HTTP_OK) {
//noinspection VariableNotUsedInsideIf
if (etag != null) { if (etag != null) {
LOGGER.debug("Updated event " + getHref()); LOGGER.debug("Updated event " + getHref());
} else { } else {
@ -1221,7 +1223,7 @@ public class DavExchangeSession extends ExchangeSession {
} }
contactPhoto = new ContactPhoto(); contactPhoto = new ContactPhoto();
contactPhoto.type = "image/jpeg"; contactPhoto.contentType = "image/jpeg";
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream partInputStream = inputStream; InputStream partInputStream = inputStream;

View File

@ -958,7 +958,7 @@ public class EwsExchangeSession extends ExchangeSession {
contactPhoto = new ContactPhoto(); contactPhoto = new ContactPhoto();
contactPhoto.content = getAttachmentMethod.getResponseItem().get("Content"); contactPhoto.content = getAttachmentMethod.getResponseItem().get("Content");
contactPhoto.type = attachment.contentType; contactPhoto.contentType = attachment.contentType;
} }
} }

View File

@ -109,9 +109,8 @@ public class NTLMv2Scheme implements AuthScheme {
/** /**
* Deprecated. * Deprecated.
*
* @deprecated
*/ */
@Deprecated
public String getID() { public String getID() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@ -145,8 +144,8 @@ public class NTLMv2Scheme implements AuthScheme {
* are not valid or not applicable for this authentication scheme * are not valid or not applicable for this authentication scheme
* @throws AuthenticationException if authorization string cannot * @throws AuthenticationException if authorization string cannot
* be generated due to an authentication failure * be generated due to an authentication failure
* @deprecated
*/ */
@Deprecated
public String authenticate(final Credentials credentials, String method, String uri) throws AuthenticationException { public String authenticate(final Credentials credentials, String method, String uri) throws AuthenticationException {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }

View File

@ -257,7 +257,7 @@ public class LdapConnection extends AbstractConnection {
} }
// LDAP version // LDAP version
static final int LDAP_VERSION2 = 0x02; // static final int LDAP_VERSION2 = 0x02;
static final int LDAP_VERSION3 = 0x03; static final int LDAP_VERSION3 = 0x03;
// LDAP request operations // LDAP request operations
@ -282,10 +282,10 @@ public class LdapConnection extends AbstractConnection {
// LDAP filter operators (only LDAP_FILTER_SUBSTRINGS is supported) // LDAP filter operators (only LDAP_FILTER_SUBSTRINGS is supported)
static final int LDAP_FILTER_SUBSTRINGS = 0xa4; static final int LDAP_FILTER_SUBSTRINGS = 0xa4;
static final int LDAP_FILTER_GE = 0xa5; //static final int LDAP_FILTER_GE = 0xa5;
static final int LDAP_FILTER_LE = 0xa6; //static final int LDAP_FILTER_LE = 0xa6;
static final int LDAP_FILTER_PRESENT = 0x87; static final int LDAP_FILTER_PRESENT = 0x87;
static final int LDAP_FILTER_APPROX = 0xa8; //static final int LDAP_FILTER_APPROX = 0xa8;
static final int LDAP_FILTER_EQUALITY = 0xa3; static final int LDAP_FILTER_EQUALITY = 0xa3;
// LDAP filter mode (only startsWith supported by galfind) // LDAP filter mode (only startsWith supported by galfind)
@ -300,8 +300,8 @@ public class LdapConnection extends AbstractConnection {
// LDAP search scope // LDAP search scope
static final int SCOPE_BASE_OBJECT = 0; static final int SCOPE_BASE_OBJECT = 0;
static final int SCOPE_ONE_LEVEL = 1; //static final int SCOPE_ONE_LEVEL = 1;
static final int SCOPE_SUBTREE = 2; //static final int SCOPE_SUBTREE = 2;
/** /**
* For some unknow reaseon parseIntWithTag is private ! * For some unknow reaseon parseIntWithTag is private !
@ -846,7 +846,6 @@ public class LdapConnection extends AbstractConnection {
*/ */
public ExchangeSession.Condition getContactSearchFilter() { public ExchangeSession.Condition getContactSearchFilter() {
ExchangeSession.MultiCondition condition; ExchangeSession.MultiCondition condition;
String op;
if (type == LDAP_FILTER_OR) { if (type == LDAP_FILTER_OR) {
condition = session.or(); condition = session.or();
@ -1099,10 +1098,6 @@ public class LdapConnection extends AbstractConnection {
DavGatewayTray.error(new BundleMessage("LOG_LDAP_UNSUPPORTED_FILTER", "nested simple filters")); DavGatewayTray.error(new BundleMessage("LOG_LDAP_UNSUPPORTED_FILTER", "nested simple filters"));
} }
public String getAttributeName() {
return attributeName;
}
public String getGalFindAttributeName() { public String getGalFindAttributeName() {
return CRITERIA_MAP.get(attributeName); return CRITERIA_MAP.get(attributeName);
} }
@ -1287,6 +1282,7 @@ public class LdapConnection extends AbstractConnection {
* Search users in contacts folder * Search users in contacts folder
* *
* @param condition search filter * @param condition search filter
* @param returningAttributes requested attributes
* @return List of users * @return List of users
* @throws IOException on error * @throws IOException on error
*/ */

View File

@ -0,0 +1,94 @@
/*
* 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;
import davmail.AbstractDavMailTestCase;
import davmail.Settings;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.*;
/**
* Test Exchange session calendar features .
*/
@SuppressWarnings({"UseOfSystemOutOrSystemErr"})
public class TestExchangeSessionCalendar extends AbstractDavMailTestCase {
public void testGetVtimezone() {
ExchangeSession.VTimezone timezone = session.getVTimezone();
assertNotNull(timezone.timezoneId);
assertNotNull(timezone.timezoneBody);
}
public void testDumpVtimezones() throws IOException {
Properties properties = new Properties() {
@Override
public synchronized Enumeration<Object> keys() {
Enumeration keysEnumeration = super.keys();
TreeSet<String> sortedKeySet = new TreeSet<String>();
while (keysEnumeration.hasMoreElements()) {
sortedKeySet.add((String) keysEnumeration.nextElement());
}
final Iterator<String> sortedKeysIterator = sortedKeySet.iterator();
return new Enumeration<Object>() {
public boolean hasMoreElements() {
return sortedKeysIterator.hasNext();
}
public Object nextElement() {
return sortedKeysIterator.next();
}
};
}
};
for (int i = 1; i < 100; i++) {
Settings.setProperty("davmail.timezoneId", String.valueOf(i));
ExchangeSession.VTimezone timezone = session.getVTimezone();
if (timezone.timezoneId != null) {
properties.put(timezone.timezoneId.replaceAll("\\\\", ""), String.valueOf(i));
System.out.println(timezone.timezoneId + '=' + i);
}
session.vTimezone = null;
}
FileOutputStream fileOutputStream = null;
try {
fileOutputStream = new FileOutputStream("timezoneids.properties");
properties.store(fileOutputStream, "Timezone ids");
} finally {
if (fileOutputStream != null) {
try {
fileOutputStream.close();
} catch (IOException e) {
// ignore
}
}
}
}
public void testSearchCalendar() throws IOException {
List<ExchangeSession.Event> events = session.getAllEvents("/users/" + session.getEmail() + "/calendar/test");
for (ExchangeSession.Event event:events) {
System.out.println(event.getBody());
}
}
}

View File

@ -106,6 +106,8 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase
vCardWriter.appendProperty("X-MANAGER", "manager"); vCardWriter.appendProperty("X-MANAGER", "manager");
vCardWriter.appendProperty("X-SPOUSE", "spousecn"); vCardWriter.appendProperty("X-SPOUSE", "spousecn");
vCardWriter.appendProperty("CLASS", "PRIVATE");
// add photo // add photo
ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteArrayOutputStream baos = new ByteArrayOutputStream();
InputStream partInputStream = new FileInputStream("src/data/anonymous.jpg"); InputStream partInputStream = new FileInputStream("src/data/anonymous.jpg");
@ -187,6 +189,8 @@ public class TestExchangeSessionContact extends AbstractExchangeSessionTestCase
assertEquals("spousecn", contact.get("spousecn")); assertEquals("spousecn", contact.get("spousecn"));
assertEquals("keywords", contact.get("keywords")); assertEquals("keywords", contact.get("keywords"));
assertEquals("1", contact.get("private"));
assertNotNull(session.getContactPhoto(contact)); assertNotNull(session.getContactPhoto(contact));
} }
} }

View File

@ -87,7 +87,7 @@ public class TestExchangeSessionFolder extends AbstractExchangeSessionTestCase {
public void testFolderAccent() throws IOException { public void testFolderAccent() throws IOException {
String folderName = "testé"; String folderName = "testé";
session.createMessageFolder(folderName); session.createMessageFolder(folderName);
ExchangeSession.Folder folder = session.getFolder(folderName); ExchangeSession.Folder folder = session.getFolder(folderName);
assertNotNull(folder); assertNotNull(folder);

View File

@ -18,20 +18,15 @@
*/ */
package davmail.exchange.dav; package davmail.exchange.dav;
import davmail.BundleMessage;
import davmail.Settings;
import davmail.exchange.AbstractExchangeSessionTestCase; import davmail.exchange.AbstractExchangeSessionTestCase;
import davmail.exchange.ExchangeSession;
import davmail.ui.tray.DavGatewayTray;
import org.apache.commons.codec.binary.Base64; import org.apache.commons.codec.binary.Base64;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.httpclient.HttpStatus;
import org.apache.jackrabbit.webdav.MultiStatusResponse; import org.apache.jackrabbit.webdav.MultiStatusResponse;
import org.apache.jackrabbit.webdav.property.DavProperty; import org.apache.jackrabbit.webdav.property.DavProperty;
import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.util.*; import java.util.HashSet;
import java.util.Set;
/** /**
* Webdav specific unit tests * Webdav specific unit tests
@ -40,11 +35,18 @@ import java.util.*;
public class TestDavExchangeSession extends AbstractExchangeSessionTestCase { public class TestDavExchangeSession extends AbstractExchangeSessionTestCase {
DavExchangeSession davSession; DavExchangeSession davSession;
/**
* @inheritDoc
*/
@Override
public void setUp() throws IOException { public void setUp() throws IOException {
super.setUp(); super.setUp();
davSession = ((DavExchangeSession) session); davSession = ((DavExchangeSession) session);
} }
/**
* Test exchange folder path mapping
*/
public void testGetFolderPath() { public void testGetFolderPath() {
String mailPath = davSession.getFolderPath(""); String mailPath = davSession.getFolderPath("");
String rootPath = davSession.getFolderPath("/users/"); String rootPath = davSession.getFolderPath("/users/");
@ -101,6 +103,11 @@ public class TestDavExchangeSession extends AbstractExchangeSessionTestCase {
assertEquals(mailPath + "Contacts", davSession.getFolderPath("/users/" + davSession.getEmail() + "/Contacts")); assertEquals(mailPath + "Contacts", davSession.getFolderPath("/users/" + davSession.getEmail() + "/Contacts"));
} }
/**
* Get main category list
*
* @throws IOException on error
*/
public void testGetCategoryList() throws IOException { public void testGetCategoryList() throws IOException {
Set<String> attributes = new HashSet<String>(); Set<String> attributes = new HashSet<String>();
attributes.add("permanenturl"); attributes.add("permanenturl");
@ -108,9 +115,14 @@ public class TestDavExchangeSession extends AbstractExchangeSessionTestCase {
MultiStatusResponse[] responses = davSession.searchItems("/users/" + davSession.getEmail() + "/calendar", attributes, davSession.and(davSession.isFalse("isfolder"), davSession.equals("messageclass", "IPM.Configuration.CategoryList")), DavExchangeSession.FolderQueryTraversal.Shallow); MultiStatusResponse[] responses = davSession.searchItems("/users/" + davSession.getEmail() + "/calendar", attributes, davSession.and(davSession.isFalse("isfolder"), davSession.equals("messageclass", "IPM.Configuration.CategoryList")), DavExchangeSession.FolderQueryTraversal.Shallow);
String value = (String) responses[0].getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("roamingxmlstream")).getValue(); String value = (String) responses[0].getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("roamingxmlstream")).getValue();
String propertyList = new String(Base64.decodeBase64(value.getBytes()), "UTF-8"); String propertyList = new String(Base64.decodeBase64(value.getBytes()), "UTF-8");
System.out.println(propertyList);
} }
/**
* Find calendar options
*
* @throws IOException on error
*/
public void testGetCalendarOptions() throws IOException { public void testGetCalendarOptions() throws IOException {
Set<String> attributes = new HashSet<String>(); Set<String> attributes = new HashSet<String>();
attributes.add("permanenturl"); attributes.add("permanenturl");
@ -118,9 +130,14 @@ public class TestDavExchangeSession extends AbstractExchangeSessionTestCase {
MultiStatusResponse[] responses = davSession.searchItems("/users/" + davSession.getEmail() + "/calendar", attributes, davSession.and(davSession.isFalse("isfolder"), davSession.equals("messageclass", "IPM.Configuration.Calendar")), DavExchangeSession.FolderQueryTraversal.Shallow); MultiStatusResponse[] responses = davSession.searchItems("/users/" + davSession.getEmail() + "/calendar", attributes, davSession.and(davSession.isFalse("isfolder"), davSession.equals("messageclass", "IPM.Configuration.Calendar")), DavExchangeSession.FolderQueryTraversal.Shallow);
String value = (String) responses[0].getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("roamingxmlstream")).getValue(); String value = (String) responses[0].getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("roamingxmlstream")).getValue();
String propertyList = new String(Base64.decodeBase64(value.getBytes()), "UTF-8"); String propertyList = new String(Base64.decodeBase64(value.getBytes()), "UTF-8");
System.out.println(propertyList);
} }
/**
* Retrieve all hidden items
*
* @throws IOException on error
*/
public void testAllHidden() throws IOException { public void testAllHidden() throws IOException {
Set<String> attributes = new HashSet<String>(); Set<String> attributes = new HashSet<String>();
attributes.add("messageclass"); attributes.add("messageclass");
@ -128,7 +145,7 @@ public class TestDavExchangeSession extends AbstractExchangeSessionTestCase {
attributes.add("roamingxmlstream"); attributes.add("roamingxmlstream");
attributes.add("displayname"); attributes.add("displayname");
MultiStatusResponse[] responses = davSession.searchItems("/users/" + davSession.getEmail() + "/", attributes, davSession.and(davSession.isTrue("ishidden")), DavExchangeSession.FolderQueryTraversal.Deep); MultiStatusResponse[] responses = davSession.searchItems("/users/" + davSession.getEmail() + '/', attributes, davSession.and(davSession.isTrue("ishidden")), DavExchangeSession.FolderQueryTraversal.Deep);
for (MultiStatusResponse response : responses) { for (MultiStatusResponse response : responses) {
System.out.println(response.getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("messageclass")).getValue() + ": " System.out.println(response.getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("messageclass")).getValue() + ": "
+ response.getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("displayname")).getValue()); + response.getProperties(HttpStatus.SC_OK).get(Field.getPropertyName("displayname")).getValue());
@ -141,6 +158,11 @@ public class TestDavExchangeSession extends AbstractExchangeSessionTestCase {
} }
} }
/**
* Search in non ipm subtree
*
* @throws IOException on error
*/
public void testNonIpmSubtree() throws IOException { public void testNonIpmSubtree() throws IOException {
Set<String> attributes = new HashSet<String>(); Set<String> attributes = new HashSet<String>();
attributes.add("messageclass"); attributes.add("messageclass");
@ -163,72 +185,7 @@ public class TestDavExchangeSession extends AbstractExchangeSessionTestCase {
if (roamingdictionaryProperty != null) { if (roamingdictionaryProperty != null) {
System.out.println("roamingdictionary: " + new String(Base64.decodeBase64(((String) roamingdictionaryProperty.getValue()).getBytes()), "UTF-8")); System.out.println("roamingdictionary: " + new String(Base64.decodeBase64(((String) roamingdictionaryProperty.getValue()).getBytes()), "UTF-8"));
} }
} }
} }
public void testGetVtimezone() {
ExchangeSession.VTimezone timezone = davSession.getVTimezone();
assertNotNull(timezone.timezoneId);
assertNotNull(timezone.timezoneBody);
System.out.println(timezone.timezoneId);
System.out.println(timezone.timezoneBody);
}
public void testDumpVtimezones() {
Properties properties = new Properties() {
@Override
public synchronized Enumeration<Object> keys() {
Enumeration keysEnumeration = super.keys();
TreeSet<String> sortedKeySet = new TreeSet<String>();
while (keysEnumeration.hasMoreElements()) {
sortedKeySet.add((String) keysEnumeration.nextElement());
}
final Iterator<String> sortedKeysIterator = sortedKeySet.iterator();
return new Enumeration<Object>() {
public boolean hasMoreElements() {
return sortedKeysIterator.hasNext();
}
public Object nextElement() {
return sortedKeysIterator.next();
}
};
}
};
for (int i = 1; i < 100; i++) {
Settings.setProperty("davmail.timezoneId", String.valueOf(i));
ExchangeSession.VTimezone timezone = davSession.getVTimezone();
if (timezone.timezoneId != null) {
properties.put(timezone.timezoneId.replaceAll("\\\\", ""), String.valueOf(i));
System.out.println(timezone.timezoneId + '=' + i);
}
davSession.vTimezone = null;
}
FileOutputStream fileOutputStream = null;
try {
fileOutputStream = new FileOutputStream("timezoneids.properties");
properties.store(fileOutputStream, "Timezone ids");
} catch (IOException e) {
System.err.println(e);
} finally {
if (fileOutputStream != null) {
try {
fileOutputStream.close();
} catch (IOException e) {
System.err.println(e);
}
}
}
}
public void testSearchCalendar() throws IOException {
List<ExchangeSession.Event> events = davSession.searchEvents("/users/" + davSession.getEmail() + "/calendar/test", ExchangeSession.ITEM_PROPERTIES, null);
for (ExchangeSession.Event event:events) {
System.out.println(event.getBody());
}
}
} }

View File

@ -0,0 +1,38 @@
/*
* 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 davmail.exchange.AbstractExchangeSessionTestCase;
import java.io.IOException;
/**
* Webdav specific unit tests
*/
@SuppressWarnings({"UseOfSystemOutOrSystemErr"})
public class TestEwsExchangeSession extends AbstractExchangeSessionTestCase {
EwsExchangeSession ewsSession;
public void setUp() throws IOException {
super.setUp();
ewsSession = ((EwsExchangeSession) session);
}
}