Enhancements from audit

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@536 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2009-04-23 20:53:22 +00:00
parent ce864c36c6
commit 05d46b754d
8 changed files with 55 additions and 57 deletions

View File

@ -127,7 +127,6 @@ public class DavGateway {
}
public static String getReleasedVersion() {
long start = System.currentTimeMillis();
String version = null;
BufferedReader versionReader = null;
HttpClient httpClient = DavGatewayHttpClientFacade.getInstance();
@ -151,7 +150,6 @@ public class DavGateway {
}
getMethod.releaseConnection();
}
System.out.println("Elapsed time: "+(System.currentTimeMillis()-start)+" ms");
return version;
}
}

View File

@ -528,14 +528,14 @@ public class CaldavConnection extends AbstractConnection {
CaldavResponse response = new CaldavResponse(HttpStatus.SC_MULTI_STATUS);
response.startMultistatus();
response.startResponse(URIUtil.encodePath("/principals/" + prefix + "/" + principal));
response.startResponse(URIUtil.encodePath("/principals/" + prefix + '/' + principal));
response.startPropstat();
if (request.hasProperty("calendar-home-set")) {
if ("users".equals(prefix)) {
response.appendProperty("C:calendar-home-set", "<D:href>/users/" + actualPrincipal + "/calendar</D:href>");
} else {
response.appendProperty("C:calendar-home-set", "<D:href>" + prefix + "/" + actualPrincipal + "</D:href>");
response.appendProperty("C:calendar-home-set", "<D:href>" + prefix + '/' + actualPrincipal + "</D:href>");
}
}
@ -620,7 +620,7 @@ public class CaldavConnection extends AbstractConnection {
.append("DTSTART:").append(valueMap.get("DTSTART")).append("").append((char) 13).append((char) 10)
.append("DTEND:").append(valueMap.get("DTEND")).append("").append((char) 13).append((char) 10)
.append("UID:").append(valueMap.get("UID")).append("").append((char) 13).append((char) 10)
.append(attendeeKeyMap.get(attendee)).append(":").append(attendee).append("").append((char) 13).append((char) 10);
.append(attendeeKeyMap.get(attendee)).append(':').append(attendee).append("").append((char) 13).append((char) 10);
entry.getValue().appendTo(ics);
ics.append("END:VFREEBUSY").append((char) 13).append((char) 10)
.append("END:VCALENDAR");
@ -663,7 +663,7 @@ public class CaldavConnection extends AbstractConnection {
public void sendUnauthorized() throws IOException {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("WWW-Authenticate", "Basic realm=\"" + Settings.getProperty("davmail.url") + "\"");
headers.put("WWW-Authenticate", "Basic realm=\"" + Settings.getProperty("davmail.url") + '\"');
sendHttpResponse(HttpStatus.SC_UNAUTHORIZED, headers);
}
@ -686,7 +686,7 @@ public class CaldavConnection extends AbstractConnection {
}
public void sendHttpResponse(int status, Map<String, String> headers, String contentType, byte[] content, boolean keepAlive) throws IOException {
sendClient("HTTP/1.1 " + status + " " + HttpStatus.getStatusText(status));
sendClient("HTTP/1.1 " + status + ' ' + HttpStatus.getStatusText(status));
sendClient("Server: DavMail Gateway");
sendClient("DAV: 1, 2, 3, access-control, calendar-access, ticket, calendar-schedule, calendarserver-private-events");
SimpleDateFormat formatter = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.ENGLISH);
@ -860,7 +860,7 @@ public class CaldavConnection extends AbstractConnection {
if (subFolder == null || subFolder.length() == 0) {
return path;
} else {
return path + "/" + subFolder;
return path + '/' + subFolder;
}
}
@ -987,7 +987,7 @@ public class CaldavConnection extends AbstractConnection {
@Override
public String toString() {
return command + " " + path + " Depth: " + depth + "\n" + body;
return command + ' ' + path + " Depth: " + depth + '\n' + body;
}
/**

View File

@ -400,7 +400,7 @@ public class ExchangeSession {
} else {
// failover for Exchange 2007 : build standard mailbox link with email
buildEmail(method);
mailPath = "/exchange/" + email + "/";
mailPath = "/exchange/" + email + '/';
LOGGER.debug("Current user email is " + email + ", mailPath is " + mailPath);
}
} catch (IOException e) {
@ -503,7 +503,7 @@ public class ExchangeSession {
* @throws IOException when unable to create message
*/
public void createMessage(String folderUrl, String messageName, HashMap<String, String> properties, String messageBody) throws IOException {
String messageUrl = URIUtil.encodePathQuery(folderUrl + "/" + messageName + ".EML");
String messageUrl = URIUtil.encodePathQuery(folderUrl + '/' + messageName + ".EML");
PropPatchMethod patchMethod;
// create the message first as draft
if (properties.containsKey("draft")) {
@ -512,7 +512,7 @@ public class ExchangeSession {
// update message with blind carbon copy and other flags
int statusCode = httpClient.executeMethod(patchMethod);
if (statusCode != HttpStatus.SC_MULTI_STATUS) {
throw new IOException("Unable to create message " + messageUrl + ": " + statusCode + " " + patchMethod.getStatusLine());
throw new IOException("Unable to create message " + messageUrl + ": " + statusCode + ' ' + patchMethod.getStatusLine());
}
} finally {
@ -529,7 +529,7 @@ public class ExchangeSession {
int code = httpClient.executeMethod(putmethod);
if (code != HttpStatus.SC_OK && code != HttpStatus.SC_CREATED) {
throw new IOException("Unable to create message " + messageUrl + ": " + code + " " + putmethod.getStatusLine());
throw new IOException("Unable to create message " + messageUrl + ": " + code + ' ' + putmethod.getStatusLine());
}
} finally {
putmethod.releaseConnection();
@ -542,7 +542,7 @@ public class ExchangeSession {
// update message with blind carbon copy and other flags
int statusCode = httpClient.executeMethod(patchMethod);
if (statusCode != HttpStatus.SC_MULTI_STATUS) {
throw new IOException("Unable to patch message " + messageUrl + ": " + statusCode + " " + patchMethod.getStatusLine());
throw new IOException("Unable to patch message " + messageUrl + ": " + statusCode + ' ' + patchMethod.getStatusLine());
}
} finally {
@ -807,7 +807,7 @@ public class ExchangeSession {
createMessage(draftsUrl, messageName, properties, mailBuffer.toString());
String tempUrl = draftsUrl + "/" + messageName + ".EML";
String tempUrl = draftsUrl + '/' + messageName + ".EML";
MoveMethod method = new MoveMethod(URIUtil.encodePath(tempUrl), URIUtil.encodePath(sendmsgUrl), true);
int status = DavGatewayHttpClientFacade.executeHttpMethod(httpClient, method);
if (status != HttpStatus.SC_OK) {
@ -867,7 +867,7 @@ public class ExchangeSession {
Folder newFolder = getFolder(currentFolder.folderName);
if (currentFolder.contenttag == null || !currentFolder.contenttag.equals(newFolder.contenttag)) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Contenttag changed on " + currentFolder.folderName + " "
LOGGER.debug("Contenttag changed on " + currentFolder.folderName + ' '
+ currentFolder.contenttag + " => " + newFolder.contenttag + ", reloading messages");
}
newFolder.loadMessages();
@ -928,8 +928,8 @@ public class ExchangeSession {
}
public void moveToTrash(String encodedPath, String encodedMessageName) throws IOException {
String source = encodedPath + "/" + encodedMessageName;
String destination = URIUtil.encodePath(deleteditemsUrl) + "/" + encodedMessageName;
String source = encodedPath + '/' + encodedMessageName;
String destination = URIUtil.encodePath(deleteditemsUrl) + '/' + encodedMessageName;
LOGGER.debug("Deleting : " + source + " to " + destination);
MoveMethod method = new MoveMethod(source, destination, false);
method.addRequestHeader("Allow-rename", "t");
@ -1261,7 +1261,7 @@ public class ExchangeSession {
}
public Event getEvent(String path, String eventName) throws IOException {
String eventPath = URIUtil.encodePath(path + "/" + eventName);
String eventPath = URIUtil.encodePath(path + '/' + eventName);
MultiStatusResponse[] responses = DavGatewayHttpClientFacade.executePropFindMethod(httpClient, eventPath, 0, EVENT_REQUEST_PROPERTIES);
if (responses.length == 0) {
throw new IOException("Unable to get calendar event");
@ -1419,7 +1419,7 @@ public class ExchangeSession {
}
public int sendEvent(String icsBody) throws IOException {
String messageUrl = URIUtil.encodePathQuery(draftsUrl + "/" + UUID.randomUUID().toString() + ".EML");
String messageUrl = URIUtil.encodePathQuery(draftsUrl + '/' + UUID.randomUUID().toString() + ".EML");
int status = internalCreateOrUpdateEvent(messageUrl, "urn:content-classes:calendarmessage", icsBody, null, null).status;
if (status != HttpStatus.SC_CREATED) {
return status;
@ -1434,7 +1434,7 @@ public class ExchangeSession {
}
public EventResult createOrUpdateEvent(String path, String eventName, String icsBody, String etag, String noneMatch) throws IOException {
String messageUrl = URIUtil.encodePath(path + "/" + eventName);
String messageUrl = URIUtil.encodePath(path + '/' + eventName);
return internalCreateOrUpdateEvent(messageUrl, "urn:content-classes:appointment", icsBody, etag, noneMatch);
}
@ -1604,7 +1604,7 @@ public class ExchangeSession {
LOGGER.warn("Overwritten event " + messageUrl);
}
} else if (status != HttpURLConnection.HTTP_CREATED) {
LOGGER.warn("Unable to create or update message " + status + " " + putmethod.getStatusLine());
LOGGER.warn("Unable to create or update message " + status + ' ' + putmethod.getStatusLine());
}
}
} finally {
@ -1624,7 +1624,7 @@ public class ExchangeSession {
}
public int deleteEvent(String path, String eventName) throws IOException {
String eventPath = URIUtil.encodePath(path + "/" + eventName);
String eventPath = URIUtil.encodePath(path + '/' + eventName);
int status;
if (inboxUrl.endsWith(path)) {
// do not delete calendar messages, mark read and processed
@ -1716,7 +1716,7 @@ public class ExchangeSession {
if (principal != null && !alias.equals(principal) && !email.equals(principal)) {
int index = mailPath.lastIndexOf('/', mailPath.length() - 2);
if (index >= 0 && mailPath.endsWith("/")) {
buffer.append(mailPath.substring(0, index + 1)).append(principal).append("/");
buffer.append(mailPath.substring(0, index + 1)).append(principal).append('/');
} else {
throw new IOException("Invalid mail path: " + mailPath);
}
@ -1864,7 +1864,7 @@ public class ExchangeSession {
*/
public Map<String, Map<String, String>> galFind(String searchAttribute, String searchValue) throws IOException {
Map<String, Map<String, String>> results;
GetMethod getMethod = new GetMethod(URIUtil.encodePathQuery("/public/?Cmd=galfind&" + searchAttribute + "=" + searchValue));
GetMethod getMethod = new GetMethod(URIUtil.encodePathQuery("/public/?Cmd=galfind&" + searchAttribute + '=' + searchValue));
try {
int status = httpClient.executeMethod(getMethod);
if (status != HttpStatus.SC_OK) {
@ -1874,7 +1874,7 @@ public class ExchangeSession {
} finally {
getMethod.releaseConnection();
}
LOGGER.debug("galfind " + searchAttribute + "=" + searchValue + ": " + results.size() + " result(s)");
LOGGER.debug("galfind " + searchAttribute + '=' + searchValue + ": " + results.size() + " result(s)");
return results;
}
@ -2032,7 +2032,7 @@ public class ExchangeSession {
public void appendTo(StringBuilder buffer) {
for (Map.Entry<String, StringBuilder> entry : busyMap.entrySet()) {
buffer.append("FREEBUSY;FBTYPE=").append(entry.getKey())
.append(":").append(entry.getValue()).append((char) 13).append((char) 10);
.append(':').append(entry.getValue()).append((char) 13).append((char) 10);
}
}
}

View File

@ -114,13 +114,13 @@ public class ImapConnection extends AbstractConnection {
boolean recursive = folderQuery.endsWith("*");
List<ExchangeSession.Folder> folders = session.getSubFolders(folderQuery.substring(0, folderQuery.length() - 1), recursive);
for (ExchangeSession.Folder folder : folders) {
sendClient("* " + command + " (" + folder.getFlags() + ") \"/\" \"" + BASE64MailboxEncoder.encode(folder.folderUrl) + "\"");
sendClient("* " + command + " (" + folder.getFlags() + ") \"/\" \"" + BASE64MailboxEncoder.encode(folder.folderUrl) + '\"');
}
sendClient(commandId + " OK " + command + " completed");
} else {
ExchangeSession.Folder folder = session.getFolder(folderQuery);
if (folder != null) {
sendClient("* " + command + " (" + folder.getFlags() + ") \"/\" \"" + BASE64MailboxEncoder.encode(folder.folderUrl) + "\"");
sendClient("* " + command + " (" + folder.getFlags() + ") \"/\" \"" + BASE64MailboxEncoder.encode(folder.folderUrl) + '\"');
sendClient(commandId + " OK " + command + " completed");
} else {
sendClient(commandId + " NO Folder not found");
@ -141,9 +141,9 @@ public class ImapConnection extends AbstractConnection {
sendClient("* " + currentFolder.size() + " RECENT");
sendClient("* OK [UIDVALIDITY 1]");
if (currentFolder.size() == 0) {
sendClient("* OK [UIDNEXT " + 1 + "]");
sendClient("* OK [UIDNEXT " + 1 + ']');
} else {
sendClient("* OK [UIDNEXT " + currentFolder.getUidNext() + "]");
sendClient("* OK [UIDNEXT " + currentFolder.getUidNext() + ']');
}
sendClient("* FLAGS (\\Answered \\Deleted \\Draft \\Flagged \\Seen $Forwarded Junk)");
sendClient("* OK [PERMANENTFLAGS (\\Answered \\Deleted \\Draft \\Flagged \\Seen $Forwarded Junk \\*)]");
@ -383,10 +383,10 @@ public class ImapConnection extends AbstractConnection {
while (parametersTokens.hasMoreTokens()) {
String token = parametersTokens.nextToken();
if ("MESSAGES".equalsIgnoreCase(token)) {
answer.append("MESSAGES ").append(folder.size()).append(" ");
answer.append("MESSAGES ").append(folder.size()).append(' ');
}
if ("RECENT".equalsIgnoreCase(token)) {
answer.append("RECENT ").append(folder.size()).append(" ");
answer.append("RECENT ").append(folder.size()).append(' ');
}
if ("UIDNEXT".equalsIgnoreCase(token)) {
if (folder.size() == 0) {
@ -395,7 +395,7 @@ public class ImapConnection extends AbstractConnection {
if (folder.size() == 0) {
answer.append("UIDNEXT 1 ");
} else {
answer.append("UIDNEXT ").append(folder.getUidNext()).append(" ");
answer.append("UIDNEXT ").append(folder.getUidNext()).append(' ');
}
}
@ -404,10 +404,10 @@ public class ImapConnection extends AbstractConnection {
answer.append("UIDVALIDITY 1 ");
}
if ("UNSEEN".equalsIgnoreCase(token)) {
answer.append("UNSEEN ").append(folder.unreadCount).append(" ");
answer.append("UNSEEN ").append(folder.unreadCount).append(' ');
}
}
sendClient("* STATUS " + encodedFolderName + " (" + answer.toString().trim() + ")");
sendClient("* STATUS " + encodedFolderName + " (" + answer.toString().trim() + ')');
sendClient(commandId + " OK " + command + " completed");
} catch (HttpException e) {
sendClient(commandId + " NO folder not found");
@ -464,7 +464,7 @@ public class ImapConnection extends AbstractConnection {
while (paramTokens.hasMoreTokens()) {
String param = paramTokens.nextToken();
if ("FLAGS".equals(param)) {
buffer.append(" FLAGS (").append(message.getImapFlags()).append(")");
buffer.append(" FLAGS (").append(message.getImapFlags()).append(')');
} else if ("BODYSTRUCTURE".equals(param)) {
if (parameters.indexOf("BODY.") >= 0) {
// Apple Mail: send structure with body, need exact RFC822.SIZE
@ -481,7 +481,7 @@ public class ImapConnection extends AbstractConnection {
dateParser.setTimeZone(ExchangeSession.GMT_TIMEZONE);
Date date = dateParser.parse(message.date);
SimpleDateFormat dateFormatter = new SimpleDateFormat("dd-MMM-yyyy HH:mm:ss Z", Locale.ENGLISH);
buffer.append(" INTERNALDATE \"").append(dateFormatter.format(date)).append("\"");
buffer.append(" INTERNALDATE \"").append(dateFormatter.format(date)).append('\"');
} catch (ParseException e) {
throw new IOException("Invalid date: " + message.date);
}
@ -496,7 +496,7 @@ public class ImapConnection extends AbstractConnection {
} else {
buffer.append(" BODY[HEADER.FIELDS ()] {");
}
buffer.append(baos.size()).append("}");
buffer.append(baos.size()).append('}');
sendClient(buffer.toString());
os.write(baos.toByteArray());
os.flush();
@ -528,12 +528,12 @@ public class ImapConnection extends AbstractConnection {
// Apple Mail: need to build full bodystructure
appendBodyStructure(buffer, baos);
}
buffer.append(" RFC822.SIZE ").append(rfc822size).append(" ").append("BODY[]");
buffer.append(" RFC822.SIZE ").append(rfc822size).append(' ').append("BODY[]");
// partial
if (startIndex > 0) {
buffer.append('<').append(startIndex).append('>');
}
buffer.append(" {").append(baos.size()).append("}");
buffer.append(" {").append(baos.size()).append('}');
sendClient(buffer.toString());
os.write(baos.toByteArray());
os.flush();
@ -541,7 +541,7 @@ public class ImapConnection extends AbstractConnection {
}
}
}
buffer.append(")");
buffer.append(')');
sendClient(buffer.toString());
}
@ -551,7 +551,7 @@ public class ImapConnection extends AbstractConnection {
MimeMessage mimeMessage = new MimeMessage(null, new ByteArrayInputStream(baos.toByteArray()));
Object mimeBody = mimeMessage.getContent();
if (mimeBody instanceof MimeMultipart) {
buffer.append("(");
buffer.append('(');
MimeMultipart multiPart = (MimeMultipart) mimeBody;
for (int i = 0; i < multiPart.getCount(); i++) {
@ -589,7 +589,7 @@ public class ImapConnection extends AbstractConnection {
buffer.append(contentType.substring(slashIndex + 1).toUpperCase()).append("\" ()");
} else {
// extended content type
buffer.append(contentType.substring(slashIndex + 1, semiColonIndex).trim().toUpperCase()).append("\"");
buffer.append(contentType.substring(slashIndex + 1, semiColonIndex).trim().toUpperCase()).append('\"');
int charsetindex = contentType.indexOf("charset=");
if (charsetindex >= 0) {
buffer.append(" (\"CHARSET\" ");
@ -602,7 +602,7 @@ public class ImapConnection extends AbstractConnection {
if (!charSet.endsWith("\"")) {
buffer.append('"');
}
buffer.append(")");
buffer.append(')');
} else {
buffer.append(" ()");
}
@ -619,7 +619,7 @@ public class ImapConnection extends AbstractConnection {
if (value == null) {
buffer.append(" NIL");
} else {
buffer.append(" \"").append(value.toUpperCase()).append("\"");
buffer.append(" \"").append(value.toUpperCase()).append('\"');
}
}
@ -697,9 +697,9 @@ public class ImapConnection extends AbstractConnection {
String headerName = tokens.nextToken().toLowerCase();
String value = tokens.nextToken();
if ("message-id".equals(headerName) && !value.startsWith("<")) {
value = "<" + value + ">";
value = '<' + value + '>';
}
conditions.append(operator).append("\"urn:schemas:mailheader:").append(headerName).append("\"='").append(value).append("'");
conditions.append(operator).append("\"urn:schemas:mailheader:").append(headerName).append("\"='").append(value).append('\'');
} else if ("UID".equals(token)) {
String range = tokens.nextToken();
if ("1:*".equals(range)) {
@ -715,7 +715,7 @@ public class ImapConnection extends AbstractConnection {
dateFormatter.setTimeZone(ExchangeSession.GMT_TIMEZONE);
try {
Date date = parser.parse(tokens.nextToken());
conditions.append(operator).append("\"urn:schemas:httpmail:datereceived\"<'").append(dateFormatter.format(date)).append("'");
conditions.append(operator).append("\"urn:schemas:httpmail:datereceived\"<'").append(dateFormatter.format(date)).append('\'');
} catch (ParseException e) {
throw new IOException("Invalid search parameters");
}
@ -751,11 +751,11 @@ public class ImapConnection extends AbstractConnection {
} else if ("SENTBEFORE".equals(token)) {
conditions.append("\"urn:schemas:httpmail:date\" < '")
.append(dateFormatter.format(startDate))
.append("'");
.append('\'');
} else if ("SENTSINCE".equals(token)) {
conditions.append("\"urn:schemas:httpmail:date\" >= '")
.append(dateFormatter.format(startDate))
.append("'");
.append('\'');
}
}
@ -993,7 +993,7 @@ public class ImapConnection extends AbstractConnection {
ExchangeSession.Message message = currentFolder.get(currentIndex++);
long uid = message.getImapUid();
if (uid < startUid || uid > endUid) {
throw new RuntimeException("Message uid " + uid + " not in range " + startUid + ":" + endUid);
throw new RuntimeException("Message uid " + uid + " not in range " + startUid + ':' + endUid);
}
return message;
}

View File

@ -144,7 +144,7 @@ public class LdapConnection extends AbstractConnection {
"</plist>";
static {
STATIC_ATTRIBUTE_MAP.put("apple-serviceslocator", COMPUTER_GUID + ":" + VIRTUALHOST_GUID + ":calendar");
STATIC_ATTRIBUTE_MAP.put("apple-serviceslocator", COMPUTER_GUID + ':' + VIRTUALHOST_GUID + ":calendar");
}
static final HashSet<String> EXTENDED_ATTRIBUTES = new HashSet<String>();

View File

@ -134,7 +134,7 @@ public class PopConnection extends AbstractConnection {
try {
int messageNumber = Integer.valueOf(token);
ExchangeSession.Message message = messages.get(messageNumber - 1);
sendOK("" + messageNumber + " " + message.size);
sendOK("" + messageNumber + ' ' + message.size);
} catch (NumberFormatException e) {
sendERR("Invalid message index: " + token);
} catch (IndexOutOfBoundsException e) {
@ -176,7 +176,7 @@ public class PopConnection extends AbstractConnection {
DavGatewayTray.warn(new BundleMessage("LOG_CLIENT_CLOSED_CONNECTION"), e);
} catch (Exception e) {
DavGatewayTray.error(new BundleMessage("LOG_ERROR_RETRIEVING_MESSAGE"), e);
sendERR("error retreiving message " + e + " " + e.getMessage());
sendERR("error retreiving message " + e + ' ' + e.getMessage());
}
} else {
sendERR("invalid message index");

View File

@ -120,7 +120,7 @@ public class SmtpConnection extends AbstractConnection {
} catch (Exception e) {
DavGatewayTray.error(e);
state = State.AUTHENTICATED;
sendClient("451 Error : " + e + " " + e.getMessage());
sendClient("451 Error : " + e + ' ' + e.getMessage());
}
} else {

View File

@ -44,7 +44,7 @@ public class AboutFrame extends JFrame {
jEditorPane = new JEditorPane();
HTMLEditorKit htmlEditorKit = new HTMLEditorKit();
StyleSheet stylesheet = htmlEditorKit.getStyleSheet();
stylesheet.addRule("body { font-size:small;font-family: " + jEditorPane.getFont().getFamily() + "}");
stylesheet.addRule("body { font-size:small;font-family: " + jEditorPane.getFont().getFamily() + '}');
jEditorPane.setEditorKit(htmlEditorKit);
jEditorPane.setContentType("text/html");
jEditorPane.setText(getContent(null));