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 org.apache.log4j.*;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.util.Enumeration;
|
import java.util.*;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.Properties;
|
|
||||||
import java.util.TreeSet;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Settings facade.
|
* 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
|
* Set Log4J logging level for the category
|
||||||
*
|
*
|
||||||
|
|
|
@ -187,13 +187,13 @@ public abstract class ExchangeSession {
|
||||||
if (preAuthUsername == null) {
|
if (preAuthUsername == null) {
|
||||||
// Searches for the delimiter in configured username for the pre-auth user.
|
// Searches for the delimiter in configured username for the pre-auth user.
|
||||||
// The double-quote is not allowed inside email addresses anyway.
|
// The double-quote is not allowed inside email addresses anyway.
|
||||||
int doubleQuoteIndex = this.userName.indexOf('"');
|
int doubleQuoteIndex = this.userName.indexOf('"');
|
||||||
if (doubleQuoteIndex > 0) {
|
if (doubleQuoteIndex > 0) {
|
||||||
preAuthUsername = this.userName.substring(0, doubleQuoteIndex);
|
preAuthUsername = this.userName.substring(0, doubleQuoteIndex);
|
||||||
this.userName = this.userName.substring(doubleQuoteIndex + 1);
|
this.userName = this.userName.substring(doubleQuoteIndex + 1);
|
||||||
} else {
|
} else {
|
||||||
// No doublequote: the pre-auth user is the full username, or it is not used at all.
|
// No doublequote: the pre-auth user is the full username, or it is not used at all.
|
||||||
preAuthUsername = this.userName;
|
preAuthUsername = this.userName;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -513,7 +513,7 @@ public abstract class ExchangeSession {
|
||||||
|
|
||||||
protected HttpMethod postLogonMethod(HttpClient httpClient, HttpMethod logonMethod, String userName, String password) throws IOException {
|
protected HttpMethod postLogonMethod(HttpClient httpClient, HttpMethod logonMethod, String userName, String password) throws IOException {
|
||||||
|
|
||||||
setAuthFormFields(logonMethod, httpClient, password);
|
setAuthFormFields(logonMethod, httpClient, password);
|
||||||
|
|
||||||
// add exchange 2010 PBack cookie in compatibility mode
|
// add exchange 2010 PBack cookie in compatibility mode
|
||||||
httpClient.getState().addCookie(new Cookie(httpClient.getHostConfiguration().getHost(), "PBack", "0", "/", null, false));
|
httpClient.getState().addCookie(new Cookie(httpClient.getHostConfiguration().getHost(), "PBack", "0", "/", null, false));
|
||||||
|
@ -1472,39 +1472,58 @@ public abstract class ExchangeSession {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert keyword value to IMAP flag.
|
* Convert keyword value to IMAP flag.
|
||||||
|
*
|
||||||
* @param value keyword value
|
* @param value keyword value
|
||||||
* @return IMAP flag
|
* @return IMAP flag
|
||||||
*/
|
*/
|
||||||
public String convertKeywordToFlag(String value) {
|
public String convertKeywordToFlag(String value) {
|
||||||
String result = value;
|
// first test for keyword in settings
|
||||||
// convert flags to Thunderbird flags
|
Properties flagSettings = Settings.getSubProperties("davmail.imapFlags");
|
||||||
ResourceBundle flagBundle = ResourceBundle.getBundle("imapflags");
|
Enumeration flagSettingsEnum = flagSettings.propertyNames();
|
||||||
Enumeration<String> flagEnumeration = flagBundle.getKeys();
|
while (flagSettingsEnum.hasMoreElements()) {
|
||||||
while (flagEnumeration.hasMoreElements()) {
|
String key = (String) flagSettingsEnum.nextElement();
|
||||||
String key = flagEnumeration.nextElement();
|
if (value.equalsIgnoreCase(flagSettings.getProperty(key))) {
|
||||||
if (value.equalsIgnoreCase(flagBundle.getString(key))) {
|
return key;
|
||||||
result = key;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
|
ResourceBundle flagBundle = ResourceBundle.getBundle("imapflags");
|
||||||
|
Enumeration<String> flagBundleEnum = flagBundle.getKeys();
|
||||||
|
while (flagBundleEnum.hasMoreElements()) {
|
||||||
|
String key = flagBundleEnum.nextElement();
|
||||||
|
if (value.equalsIgnoreCase(flagBundle.getString(key))) {
|
||||||
|
return key;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fall back to raw value
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert IMAP flag to keyword value.
|
* Convert IMAP flag to keyword value.
|
||||||
|
*
|
||||||
* @param value IMAP flag
|
* @param value IMAP flag
|
||||||
* @return keyword value
|
* @return keyword value
|
||||||
*/
|
*/
|
||||||
public String convertFlagToKeyword(String value) {
|
public String convertFlagToKeyword(String value) {
|
||||||
String result = value;
|
// first test for flag in settings
|
||||||
// convert flags to Thunderbird flags
|
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");
|
ResourceBundle flagBundle = ResourceBundle.getBundle("imapflags");
|
||||||
try {
|
try {
|
||||||
result = flagBundle.getString(value);
|
return flagBundle.getString(value);
|
||||||
} catch (MissingResourceException e) {
|
} catch (MissingResourceException e) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
// fall back to raw value
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -1668,8 +1687,8 @@ public abstract class ExchangeSession {
|
||||||
*
|
*
|
||||||
* @return imap uid list
|
* @return imap uid list
|
||||||
*/
|
*/
|
||||||
public TreeMap<Long,String> getImapFlagMap() {
|
public TreeMap<Long, String> getImapFlagMap() {
|
||||||
TreeMap<Long,String> imapFlagMap = new TreeMap<Long,String>();
|
TreeMap<Long, String> imapFlagMap = new TreeMap<Long, String>();
|
||||||
for (ExchangeSession.Message message : messages) {
|
for (ExchangeSession.Message message : messages) {
|
||||||
imapFlagMap.put(message.getImapUid(), message.getImapFlags());
|
imapFlagMap.put(message.getImapUid(), message.getImapFlags());
|
||||||
}
|
}
|
||||||
|
@ -1864,7 +1883,7 @@ public abstract class ExchangeSession {
|
||||||
buffer.append("$Forwarded ");
|
buffer.append("$Forwarded ");
|
||||||
}
|
}
|
||||||
if (keywords != null) {
|
if (keywords != null) {
|
||||||
for (String keyword:keywords.split(",")) {
|
for (String keyword : keywords.split(",")) {
|
||||||
buffer.append(convertKeywordToFlag(keyword)).append(" ");
|
buffer.append(convertKeywordToFlag(keyword)).append(" ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1891,7 +1910,7 @@ public abstract class ExchangeSession {
|
||||||
mimeBody.reset();
|
mimeBody.reset();
|
||||||
// workaround for Exchange 2003 ActiveSync bug
|
// workaround for Exchange 2003 ActiveSync bug
|
||||||
if (mimeMessage.getHeader("MAIL FROM") != null) {
|
if (mimeMessage.getHeader("MAIL FROM") != null) {
|
||||||
mimeBody = (SharedByteArrayInputStream)mimeMessage.getRawInputStream();
|
mimeBody = (SharedByteArrayInputStream) mimeMessage.getRawInputStream();
|
||||||
mimeMessage = new MimeMessage(null, mimeBody);
|
mimeMessage = new MimeMessage(null, mimeBody);
|
||||||
mimeBody.reset();
|
mimeBody.reset();
|
||||||
}
|
}
|
||||||
|
@ -1913,7 +1932,7 @@ public abstract class ExchangeSession {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Enumeration getMatchingHeaderLines(String[] headerNames) throws MessagingException, IOException {
|
public Enumeration getMatchingHeaderLines(String[] headerNames) throws MessagingException, IOException {
|
||||||
Enumeration result = null;
|
Enumeration result = null;
|
||||||
if (mimeMessage == null) {
|
if (mimeMessage == null) {
|
||||||
// message not loaded, try to get headers only
|
// message not loaded, try to get headers only
|
||||||
InputStream headers = getMimeHeaders();
|
InputStream headers = getMimeHeaders();
|
||||||
|
@ -2780,7 +2799,7 @@ public abstract class ExchangeSession {
|
||||||
}
|
}
|
||||||
return andCondition;
|
return andCondition;
|
||||||
} catch (ParseException e) {
|
} catch (ParseException e) {
|
||||||
throw new IOException(e+" "+e.getMessage());
|
throw new IOException(e + " " + e.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue