IMAP: Implement custom IMAP flags to keywords mapping in settings
git-svn-id: http://svn.code.sf.net/p/davmail/code/trunk@2051 3d1905a2-6b24-0410-a738-b14d5a86fcbd
This commit is contained in:
parent
0cf9f1ce80
commit
aa1898d138
|
@ -22,10 +22,7 @@ import davmail.ui.tray.DavGatewayTray;
|
|||
import org.apache.log4j.*;
|
||||
|
||||
import java.io.*;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.Properties;
|
||||
import java.util.TreeSet;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Settings facade.
|
||||
|
@ -465,6 +462,32 @@ public final class Settings {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all properties that are in the specified scope, that is, that start with '<scope>.'.
|
||||
*
|
||||
* @param scope start of property name
|
||||
* @return properties
|
||||
*/
|
||||
public static synchronized Properties getSubProperties(String scope) {
|
||||
final String keyStart;
|
||||
if (scope == null || scope.length() == 0) {
|
||||
keyStart = "";
|
||||
} else if (scope.endsWith(".")) {
|
||||
keyStart = scope;
|
||||
} else {
|
||||
keyStart = scope + '.';
|
||||
}
|
||||
Properties result = new Properties();
|
||||
for (Map.Entry entry : SETTINGS.entrySet()) {
|
||||
String key = (String)entry.getKey();
|
||||
if (key.startsWith(keyStart)) {
|
||||
String value = (String)entry.getValue();
|
||||
result.setProperty(key.substring(keyStart.length()), value);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set Log4J logging level for the category
|
||||
*
|
||||
|
|
|
@ -1472,39 +1472,58 @@ public abstract class ExchangeSession {
|
|||
|
||||
/**
|
||||
* Convert keyword value to IMAP flag.
|
||||
*
|
||||
* @param value keyword value
|
||||
* @return IMAP flag
|
||||
*/
|
||||
public String convertKeywordToFlag(String value) {
|
||||
String result = value;
|
||||
// convert flags to Thunderbird flags
|
||||
// first test for keyword in settings
|
||||
Properties flagSettings = Settings.getSubProperties("davmail.imapFlags");
|
||||
Enumeration flagSettingsEnum = flagSettings.propertyNames();
|
||||
while (flagSettingsEnum.hasMoreElements()) {
|
||||
String key = (String) flagSettingsEnum.nextElement();
|
||||
if (value.equalsIgnoreCase(flagSettings.getProperty(key))) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
ResourceBundle flagBundle = ResourceBundle.getBundle("imapflags");
|
||||
Enumeration<String> flagEnumeration = flagBundle.getKeys();
|
||||
while (flagEnumeration.hasMoreElements()) {
|
||||
String key = flagEnumeration.nextElement();
|
||||
Enumeration<String> flagBundleEnum = flagBundle.getKeys();
|
||||
while (flagBundleEnum.hasMoreElements()) {
|
||||
String key = flagBundleEnum.nextElement();
|
||||
if (value.equalsIgnoreCase(flagBundle.getString(key))) {
|
||||
result = key;
|
||||
return key;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
// fall back to raw value
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convert IMAP flag to keyword value.
|
||||
*
|
||||
* @param value IMAP flag
|
||||
* @return keyword value
|
||||
*/
|
||||
public String convertFlagToKeyword(String value) {
|
||||
String result = value;
|
||||
// convert flags to Thunderbird flags
|
||||
// first test for flag in settings
|
||||
Properties flagSettings = Settings.getSubProperties("davmail.imapFlags");
|
||||
String flagValue = flagSettings.getProperty(value);
|
||||
if (flagValue != null) {
|
||||
return flagValue;
|
||||
}
|
||||
|
||||
// fall back to predefined flags
|
||||
ResourceBundle flagBundle = ResourceBundle.getBundle("imapflags");
|
||||
try {
|
||||
result = flagBundle.getString(value);
|
||||
return flagBundle.getString(value);
|
||||
} catch (MissingResourceException e) {
|
||||
// ignore
|
||||
}
|
||||
|
||||
return result;
|
||||
// fall back to raw value
|
||||
return value;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue