1
0
mirror of https://github.com/moparisthebest/davmail synced 2024-12-13 19:22:22 -05:00

Another fix from Dan Foody: improve dumpICS debug option

git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@771 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
mguessan 2009-10-07 20:53:21 +00:00
parent cb1efbe973
commit f5bafdbc6a
2 changed files with 37 additions and 5 deletions

View File

@ -162,7 +162,7 @@ public final class Settings {
public static String getLogFileDirectory() {
String logFilePath = getLogFilePath();
if (logFilePath == null || logFilePath.length() == 0) {
return "";
return ".";
}
int lastSlashIndex = logFilePath.lastIndexOf('/');
if (lastSlashIndex == -1) {
@ -171,7 +171,7 @@ public final class Settings {
if (lastSlashIndex >= 0) {
return logFilePath.substring(0, lastSlashIndex);
} else {
return "";
return ".";
}
}

View File

@ -1726,14 +1726,46 @@ public class ExchangeSession {
return event;
}
private static int dumpIndex = 1;
private static int dumpIndex;
private String defaultSound = "Basso";
protected void dumpICS(String icsBody, boolean fromServer, boolean after) {
String logFileDirectory = Settings.getLogFileDirectory();
// additional setting to activate ICS dump (not available in GUI)
if (Settings.getBooleanProperty("davmail.dumpICS")) {
int dumpMax = Settings.getIntProperty("davmail.dumpICS");
if (dumpMax > 0) {
if (dumpIndex > dumpMax) {
// Delete the oldest dump file
final int oldest = dumpIndex - dumpMax;
try {
File[] oldestFiles = (new File(logFileDirectory)).listFiles(new FilenameFilter() {
public boolean accept(File dir, String name) {
if (name.endsWith(".ics")) {
int dashIndex = name.indexOf('-');
if (dashIndex > 0) {
try {
int fileIndex = Integer.parseInt(name.substring(0, dashIndex));
return fileIndex < oldest;
} catch (NumberFormatException nfe) {
// ignore
}
}
}
return false;
}
});
for (File file : oldestFiles) {
//noinspection ResultOfMethodCallIgnored
file.delete();
}
} catch (Exception ex) {
LOGGER.warn("Error deleting ics dump: " + ex.getMessage());
}
}
StringBuilder filePath = new StringBuilder();
filePath.append(Settings.getLogFileDirectory()).append('/')
filePath.append(logFileDirectory).append('/')
.append(dumpIndex)
.append(after ? "-to" : "-from")
.append((after ^ fromServer) ? "-server" : "-client")